hw.c 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258
  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 <linux/module.h>
  19. #include <linux/time.h>
  20. #include <linux/bitops.h>
  21. #include <linux/etherdevice.h>
  22. #include <linux/gpio.h>
  23. #include <asm/unaligned.h>
  24. #include "hw.h"
  25. #include "hw-ops.h"
  26. #include "ar9003_mac.h"
  27. #include "ar9003_mci.h"
  28. #include "ar9003_phy.h"
  29. #include "ath9k.h"
  30. static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
  31. MODULE_AUTHOR("Atheros Communications");
  32. MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
  33. MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
  34. MODULE_LICENSE("Dual BSD/GPL");
  35. static void ath9k_hw_set_clockrate(struct ath_hw *ah)
  36. {
  37. struct ath_common *common = ath9k_hw_common(ah);
  38. struct ath9k_channel *chan = ah->curchan;
  39. unsigned int clockrate;
  40. /* AR9287 v1.3+ uses async FIFO and runs the MAC at 117 MHz */
  41. if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah))
  42. clockrate = 117;
  43. else if (!chan) /* should really check for CCK instead */
  44. clockrate = ATH9K_CLOCK_RATE_CCK;
  45. else if (IS_CHAN_2GHZ(chan))
  46. clockrate = ATH9K_CLOCK_RATE_2GHZ_OFDM;
  47. else if (ah->caps.hw_caps & ATH9K_HW_CAP_FASTCLOCK)
  48. clockrate = ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM;
  49. else
  50. clockrate = ATH9K_CLOCK_RATE_5GHZ_OFDM;
  51. if (chan) {
  52. if (IS_CHAN_HT40(chan))
  53. clockrate *= 2;
  54. if (IS_CHAN_HALF_RATE(chan))
  55. clockrate /= 2;
  56. if (IS_CHAN_QUARTER_RATE(chan))
  57. clockrate /= 4;
  58. }
  59. common->clockrate = clockrate;
  60. }
  61. static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
  62. {
  63. struct ath_common *common = ath9k_hw_common(ah);
  64. return usecs * common->clockrate;
  65. }
  66. bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
  67. {
  68. int i;
  69. BUG_ON(timeout < AH_TIME_QUANTUM);
  70. for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
  71. if ((REG_READ(ah, reg) & mask) == val)
  72. return true;
  73. udelay(AH_TIME_QUANTUM);
  74. }
  75. ath_dbg(ath9k_hw_common(ah), ANY,
  76. "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
  77. timeout, reg, REG_READ(ah, reg), mask, val);
  78. return false;
  79. }
  80. EXPORT_SYMBOL(ath9k_hw_wait);
  81. void ath9k_hw_synth_delay(struct ath_hw *ah, struct ath9k_channel *chan,
  82. int hw_delay)
  83. {
  84. hw_delay /= 10;
  85. if (IS_CHAN_HALF_RATE(chan))
  86. hw_delay *= 2;
  87. else if (IS_CHAN_QUARTER_RATE(chan))
  88. hw_delay *= 4;
  89. udelay(hw_delay + BASE_ACTIVATE_DELAY);
  90. }
  91. void ath9k_hw_write_array(struct ath_hw *ah, const struct ar5416IniArray *array,
  92. int column, unsigned int *writecnt)
  93. {
  94. int r;
  95. ENABLE_REGWRITE_BUFFER(ah);
  96. for (r = 0; r < array->ia_rows; r++) {
  97. REG_WRITE(ah, INI_RA(array, r, 0),
  98. INI_RA(array, r, column));
  99. DO_DELAY(*writecnt);
  100. }
  101. REGWRITE_BUFFER_FLUSH(ah);
  102. }
  103. void ath9k_hw_read_array(struct ath_hw *ah, u32 array[][2], int size)
  104. {
  105. u32 *tmp_reg_list, *tmp_data;
  106. int i;
  107. tmp_reg_list = kmalloc(size * sizeof(u32), GFP_KERNEL);
  108. if (!tmp_reg_list) {
  109. dev_err(ah->dev, "%s: tmp_reg_list: alloc filed\n", __func__);
  110. return;
  111. }
  112. tmp_data = kmalloc(size * sizeof(u32), GFP_KERNEL);
  113. if (!tmp_data) {
  114. dev_err(ah->dev, "%s tmp_data: alloc filed\n", __func__);
  115. goto error_tmp_data;
  116. }
  117. for (i = 0; i < size; i++)
  118. tmp_reg_list[i] = array[i][0];
  119. REG_READ_MULTI(ah, tmp_reg_list, tmp_data, size);
  120. for (i = 0; i < size; i++)
  121. array[i][1] = tmp_data[i];
  122. kfree(tmp_data);
  123. error_tmp_data:
  124. kfree(tmp_reg_list);
  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 (IS_CHAN_HT40PLUS(chan)) {
  196. centers->synth_center =
  197. chan->channel + HT40_CHANNEL_CENTER_SHIFT;
  198. extoff = 1;
  199. } else {
  200. centers->synth_center =
  201. chan->channel - HT40_CHANNEL_CENTER_SHIFT;
  202. extoff = -1;
  203. }
  204. centers->ctl_center =
  205. centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
  206. /* 25 MHz spacing is supported by hw but not on upper layers */
  207. centers->ext_center =
  208. centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
  209. }
  210. /******************/
  211. /* Chip Revisions */
  212. /******************/
  213. static void ath9k_hw_read_revisions(struct ath_hw *ah)
  214. {
  215. u32 val;
  216. if (ah->get_mac_revision)
  217. ah->hw_version.macRev = ah->get_mac_revision();
  218. switch (ah->hw_version.devid) {
  219. case AR5416_AR9100_DEVID:
  220. ah->hw_version.macVersion = AR_SREV_VERSION_9100;
  221. break;
  222. case AR9300_DEVID_AR9330:
  223. ah->hw_version.macVersion = AR_SREV_VERSION_9330;
  224. if (!ah->get_mac_revision) {
  225. val = REG_READ(ah, AR_SREV);
  226. ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
  227. }
  228. return;
  229. case AR9300_DEVID_AR9340:
  230. ah->hw_version.macVersion = AR_SREV_VERSION_9340;
  231. return;
  232. case AR9300_DEVID_QCA955X:
  233. ah->hw_version.macVersion = AR_SREV_VERSION_9550;
  234. return;
  235. case AR9300_DEVID_AR953X:
  236. ah->hw_version.macVersion = AR_SREV_VERSION_9531;
  237. return;
  238. case AR9300_DEVID_QCA956X:
  239. ah->hw_version.macVersion = AR_SREV_VERSION_9561;
  240. }
  241. val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
  242. if (val == 0xFF) {
  243. val = REG_READ(ah, AR_SREV);
  244. ah->hw_version.macVersion =
  245. (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
  246. ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
  247. if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
  248. ah->is_pciexpress = true;
  249. else
  250. ah->is_pciexpress = (val &
  251. AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
  252. } else {
  253. if (!AR_SREV_9100(ah))
  254. ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
  255. ah->hw_version.macRev = val & AR_SREV_REVISION;
  256. if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
  257. ah->is_pciexpress = true;
  258. }
  259. }
  260. /************************************/
  261. /* HW Attach, Detach, Init Routines */
  262. /************************************/
  263. static void ath9k_hw_disablepcie(struct ath_hw *ah)
  264. {
  265. if (!AR_SREV_5416(ah))
  266. return;
  267. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
  268. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  269. REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
  270. REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
  271. REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
  272. REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
  273. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  274. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  275. REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
  276. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  277. }
  278. /* This should work for all families including legacy */
  279. static bool ath9k_hw_chip_test(struct ath_hw *ah)
  280. {
  281. struct ath_common *common = ath9k_hw_common(ah);
  282. u32 regAddr[2] = { AR_STA_ID0 };
  283. u32 regHold[2];
  284. static const u32 patternData[4] = {
  285. 0x55555555, 0xaaaaaaaa, 0x66666666, 0x99999999
  286. };
  287. int i, j, loop_max;
  288. if (!AR_SREV_9300_20_OR_LATER(ah)) {
  289. loop_max = 2;
  290. regAddr[1] = AR_PHY_BASE + (8 << 2);
  291. } else
  292. loop_max = 1;
  293. for (i = 0; i < loop_max; i++) {
  294. u32 addr = regAddr[i];
  295. u32 wrData, rdData;
  296. regHold[i] = REG_READ(ah, addr);
  297. for (j = 0; j < 0x100; j++) {
  298. wrData = (j << 16) | j;
  299. REG_WRITE(ah, addr, wrData);
  300. rdData = REG_READ(ah, addr);
  301. if (rdData != wrData) {
  302. ath_err(common,
  303. "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
  304. addr, wrData, rdData);
  305. return false;
  306. }
  307. }
  308. for (j = 0; j < 4; j++) {
  309. wrData = patternData[j];
  310. REG_WRITE(ah, addr, wrData);
  311. rdData = REG_READ(ah, addr);
  312. if (wrData != rdData) {
  313. ath_err(common,
  314. "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
  315. addr, wrData, rdData);
  316. return false;
  317. }
  318. }
  319. REG_WRITE(ah, regAddr[i], regHold[i]);
  320. }
  321. udelay(100);
  322. return true;
  323. }
  324. static void ath9k_hw_init_config(struct ath_hw *ah)
  325. {
  326. struct ath_common *common = ath9k_hw_common(ah);
  327. ah->config.dma_beacon_response_time = 1;
  328. ah->config.sw_beacon_response_time = 6;
  329. ah->config.cwm_ignore_extcca = 0;
  330. ah->config.analog_shiftreg = 1;
  331. ah->config.rx_intr_mitigation = true;
  332. if (AR_SREV_9300_20_OR_LATER(ah)) {
  333. ah->config.rimt_last = 500;
  334. ah->config.rimt_first = 2000;
  335. } else {
  336. ah->config.rimt_last = 250;
  337. ah->config.rimt_first = 700;
  338. }
  339. if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
  340. ah->config.pll_pwrsave = 7;
  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. if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
  360. if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
  361. ((AR_SREV_9160(ah) || AR_SREV_9280(ah) || AR_SREV_9287(ah)) &&
  362. !ah->is_pciexpress)) {
  363. ah->config.serialize_regmode = SER_REG_MODE_ON;
  364. } else {
  365. ah->config.serialize_regmode = SER_REG_MODE_OFF;
  366. }
  367. }
  368. ath_dbg(common, RESET, "serialize_regmode is %d\n",
  369. ah->config.serialize_regmode);
  370. if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
  371. ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
  372. else
  373. ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
  374. }
  375. static void ath9k_hw_init_defaults(struct ath_hw *ah)
  376. {
  377. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  378. regulatory->country_code = CTRY_DEFAULT;
  379. regulatory->power_limit = MAX_RATE_POWER;
  380. ah->hw_version.magic = AR5416_MAGIC;
  381. ah->hw_version.subvendorid = 0;
  382. ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE |
  383. AR_STA_ID1_MCAST_KSRCH;
  384. if (AR_SREV_9100(ah))
  385. ah->sta_id1_defaults |= AR_STA_ID1_AR9100_BA_FIX;
  386. ah->slottime = ATH9K_SLOT_TIME_9;
  387. ah->globaltxtimeout = (u32) -1;
  388. ah->power_mode = ATH9K_PM_UNDEFINED;
  389. ah->htc_reset_init = true;
  390. ah->tpc_enabled = false;
  391. ah->ani_function = ATH9K_ANI_ALL;
  392. if (!AR_SREV_9300_20_OR_LATER(ah))
  393. ah->ani_function &= ~ATH9K_ANI_MRC_CCK;
  394. if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
  395. ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
  396. else
  397. ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
  398. }
  399. static int ath9k_hw_init_macaddr(struct ath_hw *ah)
  400. {
  401. struct ath_common *common = ath9k_hw_common(ah);
  402. u32 sum;
  403. int i;
  404. u16 eeval;
  405. static const u32 EEP_MAC[] = { EEP_MAC_LSW, EEP_MAC_MID, EEP_MAC_MSW };
  406. sum = 0;
  407. for (i = 0; i < 3; i++) {
  408. eeval = ah->eep_ops->get_eeprom(ah, EEP_MAC[i]);
  409. sum += eeval;
  410. common->macaddr[2 * i] = eeval >> 8;
  411. common->macaddr[2 * i + 1] = eeval & 0xff;
  412. }
  413. if (!is_valid_ether_addr(common->macaddr)) {
  414. ath_err(common,
  415. "eeprom contains invalid mac address: %pM\n",
  416. common->macaddr);
  417. random_ether_addr(common->macaddr);
  418. ath_err(common,
  419. "random mac address will be used: %pM\n",
  420. common->macaddr);
  421. }
  422. return 0;
  423. }
  424. static int ath9k_hw_post_init(struct ath_hw *ah)
  425. {
  426. struct ath_common *common = ath9k_hw_common(ah);
  427. int ecode;
  428. if (common->bus_ops->ath_bus_type != ATH_USB) {
  429. if (!ath9k_hw_chip_test(ah))
  430. return -ENODEV;
  431. }
  432. if (!AR_SREV_9300_20_OR_LATER(ah)) {
  433. ecode = ar9002_hw_rf_claim(ah);
  434. if (ecode != 0)
  435. return ecode;
  436. }
  437. ecode = ath9k_hw_eeprom_init(ah);
  438. if (ecode != 0)
  439. return ecode;
  440. ath_dbg(ath9k_hw_common(ah), CONFIG, "Eeprom VER: %d, REV: %d\n",
  441. ah->eep_ops->get_eeprom_ver(ah),
  442. ah->eep_ops->get_eeprom_rev(ah));
  443. ath9k_hw_ani_init(ah);
  444. /*
  445. * EEPROM needs to be initialized before we do this.
  446. * This is required for regulatory compliance.
  447. */
  448. if (AR_SREV_9300_20_OR_LATER(ah)) {
  449. u16 regdmn = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
  450. if ((regdmn & 0xF0) == CTL_FCC) {
  451. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_FCC_2GHZ;
  452. ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_FCC_5GHZ;
  453. }
  454. }
  455. return 0;
  456. }
  457. static int ath9k_hw_attach_ops(struct ath_hw *ah)
  458. {
  459. if (!AR_SREV_9300_20_OR_LATER(ah))
  460. return ar9002_hw_attach_ops(ah);
  461. ar9003_hw_attach_ops(ah);
  462. return 0;
  463. }
  464. /* Called for all hardware families */
  465. static int __ath9k_hw_init(struct ath_hw *ah)
  466. {
  467. struct ath_common *common = ath9k_hw_common(ah);
  468. int r = 0;
  469. ath9k_hw_read_revisions(ah);
  470. switch (ah->hw_version.macVersion) {
  471. case AR_SREV_VERSION_5416_PCI:
  472. case AR_SREV_VERSION_5416_PCIE:
  473. case AR_SREV_VERSION_9160:
  474. case AR_SREV_VERSION_9100:
  475. case AR_SREV_VERSION_9280:
  476. case AR_SREV_VERSION_9285:
  477. case AR_SREV_VERSION_9287:
  478. case AR_SREV_VERSION_9271:
  479. case AR_SREV_VERSION_9300:
  480. case AR_SREV_VERSION_9330:
  481. case AR_SREV_VERSION_9485:
  482. case AR_SREV_VERSION_9340:
  483. case AR_SREV_VERSION_9462:
  484. case AR_SREV_VERSION_9550:
  485. case AR_SREV_VERSION_9565:
  486. case AR_SREV_VERSION_9531:
  487. case AR_SREV_VERSION_9561:
  488. break;
  489. default:
  490. ath_err(common,
  491. "Mac Chip Rev 0x%02x.%x is not supported by this driver\n",
  492. ah->hw_version.macVersion, ah->hw_version.macRev);
  493. return -EOPNOTSUPP;
  494. }
  495. /*
  496. * Read back AR_WA into a permanent copy and set bits 14 and 17.
  497. * We need to do this to avoid RMW of this register. We cannot
  498. * read the reg when chip is asleep.
  499. */
  500. if (AR_SREV_9300_20_OR_LATER(ah)) {
  501. ah->WARegVal = REG_READ(ah, AR_WA);
  502. ah->WARegVal |= (AR_WA_D3_L1_DISABLE |
  503. AR_WA_ASPM_TIMER_BASED_DISABLE);
  504. }
  505. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
  506. ath_err(common, "Couldn't reset chip\n");
  507. return -EIO;
  508. }
  509. if (AR_SREV_9565(ah)) {
  510. ah->WARegVal |= AR_WA_BIT22;
  511. REG_WRITE(ah, AR_WA, ah->WARegVal);
  512. }
  513. ath9k_hw_init_defaults(ah);
  514. ath9k_hw_init_config(ah);
  515. r = ath9k_hw_attach_ops(ah);
  516. if (r)
  517. return r;
  518. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
  519. ath_err(common, "Couldn't wakeup chip\n");
  520. return -EIO;
  521. }
  522. if (AR_SREV_9271(ah) || AR_SREV_9100(ah) || AR_SREV_9340(ah) ||
  523. AR_SREV_9330(ah) || AR_SREV_9550(ah))
  524. ah->is_pciexpress = false;
  525. ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
  526. ath9k_hw_init_cal_settings(ah);
  527. if (!ah->is_pciexpress)
  528. ath9k_hw_disablepcie(ah);
  529. r = ath9k_hw_post_init(ah);
  530. if (r)
  531. return r;
  532. ath9k_hw_init_mode_gain_regs(ah);
  533. r = ath9k_hw_fill_cap_info(ah);
  534. if (r)
  535. return r;
  536. r = ath9k_hw_init_macaddr(ah);
  537. if (r) {
  538. ath_err(common, "Failed to initialize MAC address\n");
  539. return r;
  540. }
  541. ath9k_hw_init_hang_checks(ah);
  542. common->state = ATH_HW_INITIALIZED;
  543. return 0;
  544. }
  545. int ath9k_hw_init(struct ath_hw *ah)
  546. {
  547. int ret;
  548. struct ath_common *common = ath9k_hw_common(ah);
  549. /* These are all the AR5008/AR9001/AR9002/AR9003 hardware family of chipsets */
  550. switch (ah->hw_version.devid) {
  551. case AR5416_DEVID_PCI:
  552. case AR5416_DEVID_PCIE:
  553. case AR5416_AR9100_DEVID:
  554. case AR9160_DEVID_PCI:
  555. case AR9280_DEVID_PCI:
  556. case AR9280_DEVID_PCIE:
  557. case AR9285_DEVID_PCIE:
  558. case AR9287_DEVID_PCI:
  559. case AR9287_DEVID_PCIE:
  560. case AR2427_DEVID_PCIE:
  561. case AR9300_DEVID_PCIE:
  562. case AR9300_DEVID_AR9485_PCIE:
  563. case AR9300_DEVID_AR9330:
  564. case AR9300_DEVID_AR9340:
  565. case AR9300_DEVID_QCA955X:
  566. case AR9300_DEVID_AR9580:
  567. case AR9300_DEVID_AR9462:
  568. case AR9485_DEVID_AR1111:
  569. case AR9300_DEVID_AR9565:
  570. case AR9300_DEVID_AR953X:
  571. case AR9300_DEVID_QCA956X:
  572. break;
  573. default:
  574. if (common->bus_ops->ath_bus_type == ATH_USB)
  575. break;
  576. ath_err(common, "Hardware device ID 0x%04x not supported\n",
  577. ah->hw_version.devid);
  578. return -EOPNOTSUPP;
  579. }
  580. ret = __ath9k_hw_init(ah);
  581. if (ret) {
  582. ath_err(common,
  583. "Unable to initialize hardware; initialization status: %d\n",
  584. ret);
  585. return ret;
  586. }
  587. ath_dynack_init(ah);
  588. return 0;
  589. }
  590. EXPORT_SYMBOL(ath9k_hw_init);
  591. static void ath9k_hw_init_qos(struct ath_hw *ah)
  592. {
  593. ENABLE_REGWRITE_BUFFER(ah);
  594. REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
  595. REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
  596. REG_WRITE(ah, AR_QOS_NO_ACK,
  597. SM(2, AR_QOS_NO_ACK_TWO_BIT) |
  598. SM(5, AR_QOS_NO_ACK_BIT_OFF) |
  599. SM(0, AR_QOS_NO_ACK_BYTE_OFF));
  600. REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
  601. REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
  602. REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
  603. REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
  604. REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
  605. REGWRITE_BUFFER_FLUSH(ah);
  606. }
  607. u32 ar9003_get_pll_sqsum_dvc(struct ath_hw *ah)
  608. {
  609. struct ath_common *common = ath9k_hw_common(ah);
  610. int i = 0;
  611. REG_CLR_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
  612. udelay(100);
  613. REG_SET_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
  614. while ((REG_READ(ah, PLL4) & PLL4_MEAS_DONE) == 0) {
  615. udelay(100);
  616. if (WARN_ON_ONCE(i >= 100)) {
  617. ath_err(common, "PLL4 meaurement not done\n");
  618. break;
  619. }
  620. i++;
  621. }
  622. return (REG_READ(ah, PLL3) & SQSUM_DVC_MASK) >> 3;
  623. }
  624. EXPORT_SYMBOL(ar9003_get_pll_sqsum_dvc);
  625. static void ath9k_hw_init_pll(struct ath_hw *ah,
  626. struct ath9k_channel *chan)
  627. {
  628. u32 pll;
  629. pll = ath9k_hw_compute_pll_control(ah, chan);
  630. if (AR_SREV_9485(ah) || AR_SREV_9565(ah)) {
  631. /* program BB PLL ki and kd value, ki=0x4, kd=0x40 */
  632. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  633. AR_CH0_BB_DPLL2_PLL_PWD, 0x1);
  634. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  635. AR_CH0_DPLL2_KD, 0x40);
  636. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  637. AR_CH0_DPLL2_KI, 0x4);
  638. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
  639. AR_CH0_BB_DPLL1_REFDIV, 0x5);
  640. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
  641. AR_CH0_BB_DPLL1_NINI, 0x58);
  642. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
  643. AR_CH0_BB_DPLL1_NFRAC, 0x0);
  644. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  645. AR_CH0_BB_DPLL2_OUTDIV, 0x1);
  646. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  647. AR_CH0_BB_DPLL2_LOCAL_PLL, 0x1);
  648. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  649. AR_CH0_BB_DPLL2_EN_NEGTRIG, 0x1);
  650. /* program BB PLL phase_shift to 0x6 */
  651. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
  652. AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x6);
  653. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  654. AR_CH0_BB_DPLL2_PLL_PWD, 0x0);
  655. udelay(1000);
  656. } else if (AR_SREV_9330(ah)) {
  657. u32 ddr_dpll2, pll_control2, kd;
  658. if (ah->is_clk_25mhz) {
  659. ddr_dpll2 = 0x18e82f01;
  660. pll_control2 = 0xe04a3d;
  661. kd = 0x1d;
  662. } else {
  663. ddr_dpll2 = 0x19e82f01;
  664. pll_control2 = 0x886666;
  665. kd = 0x3d;
  666. }
  667. /* program DDR PLL ki and kd value */
  668. REG_WRITE(ah, AR_CH0_DDR_DPLL2, ddr_dpll2);
  669. /* program DDR PLL phase_shift */
  670. REG_RMW_FIELD(ah, AR_CH0_DDR_DPLL3,
  671. AR_CH0_DPLL3_PHASE_SHIFT, 0x1);
  672. REG_WRITE(ah, AR_RTC_PLL_CONTROL,
  673. pll | AR_RTC_9300_PLL_BYPASS);
  674. udelay(1000);
  675. /* program refdiv, nint, frac to RTC register */
  676. REG_WRITE(ah, AR_RTC_PLL_CONTROL2, pll_control2);
  677. /* program BB PLL kd and ki value */
  678. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KD, kd);
  679. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KI, 0x06);
  680. /* program BB PLL phase_shift */
  681. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
  682. AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x1);
  683. } else if (AR_SREV_9340(ah) || AR_SREV_9550(ah) || AR_SREV_9531(ah) ||
  684. AR_SREV_9561(ah)) {
  685. u32 regval, pll2_divint, pll2_divfrac, refdiv;
  686. REG_WRITE(ah, AR_RTC_PLL_CONTROL,
  687. pll | AR_RTC_9300_SOC_PLL_BYPASS);
  688. udelay(1000);
  689. REG_SET_BIT(ah, AR_PHY_PLL_MODE, 0x1 << 16);
  690. udelay(100);
  691. if (ah->is_clk_25mhz) {
  692. if (AR_SREV_9531(ah) || AR_SREV_9561(ah)) {
  693. pll2_divint = 0x1c;
  694. pll2_divfrac = 0xa3d2;
  695. refdiv = 1;
  696. } else {
  697. pll2_divint = 0x54;
  698. pll2_divfrac = 0x1eb85;
  699. refdiv = 3;
  700. }
  701. } else {
  702. if (AR_SREV_9340(ah)) {
  703. pll2_divint = 88;
  704. pll2_divfrac = 0;
  705. refdiv = 5;
  706. } else {
  707. pll2_divint = 0x11;
  708. pll2_divfrac = (AR_SREV_9531(ah) ||
  709. AR_SREV_9561(ah)) ?
  710. 0x26665 : 0x26666;
  711. refdiv = 1;
  712. }
  713. }
  714. regval = REG_READ(ah, AR_PHY_PLL_MODE);
  715. if (AR_SREV_9531(ah) || AR_SREV_9561(ah))
  716. regval |= (0x1 << 22);
  717. else
  718. regval |= (0x1 << 16);
  719. REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
  720. udelay(100);
  721. REG_WRITE(ah, AR_PHY_PLL_CONTROL, (refdiv << 27) |
  722. (pll2_divint << 18) | pll2_divfrac);
  723. udelay(100);
  724. regval = REG_READ(ah, AR_PHY_PLL_MODE);
  725. if (AR_SREV_9340(ah))
  726. regval = (regval & 0x80071fff) |
  727. (0x1 << 30) |
  728. (0x1 << 13) |
  729. (0x4 << 26) |
  730. (0x18 << 19);
  731. else if (AR_SREV_9531(ah) || AR_SREV_9561(ah)) {
  732. regval = (regval & 0x01c00fff) |
  733. (0x1 << 31) |
  734. (0x2 << 29) |
  735. (0xa << 25) |
  736. (0x1 << 19);
  737. if (AR_SREV_9531(ah))
  738. regval |= (0x6 << 12);
  739. } else
  740. regval = (regval & 0x80071fff) |
  741. (0x3 << 30) |
  742. (0x1 << 13) |
  743. (0x4 << 26) |
  744. (0x60 << 19);
  745. REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
  746. if (AR_SREV_9531(ah) || AR_SREV_9561(ah))
  747. REG_WRITE(ah, AR_PHY_PLL_MODE,
  748. REG_READ(ah, AR_PHY_PLL_MODE) & 0xffbfffff);
  749. else
  750. REG_WRITE(ah, AR_PHY_PLL_MODE,
  751. REG_READ(ah, AR_PHY_PLL_MODE) & 0xfffeffff);
  752. udelay(1000);
  753. }
  754. if (AR_SREV_9565(ah))
  755. pll |= 0x40000;
  756. REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
  757. if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah) ||
  758. AR_SREV_9550(ah))
  759. udelay(1000);
  760. /* Switch the core clock for ar9271 to 117Mhz */
  761. if (AR_SREV_9271(ah)) {
  762. udelay(500);
  763. REG_WRITE(ah, 0x50040, 0x304);
  764. }
  765. udelay(RTC_PLL_SETTLE_DELAY);
  766. REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
  767. }
  768. static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
  769. enum nl80211_iftype opmode)
  770. {
  771. u32 sync_default = AR_INTR_SYNC_DEFAULT;
  772. u32 imr_reg = AR_IMR_TXERR |
  773. AR_IMR_TXURN |
  774. AR_IMR_RXERR |
  775. AR_IMR_RXORN |
  776. AR_IMR_BCNMISC;
  777. if (AR_SREV_9340(ah) || AR_SREV_9550(ah) || AR_SREV_9531(ah) ||
  778. AR_SREV_9561(ah))
  779. sync_default &= ~AR_INTR_SYNC_HOST1_FATAL;
  780. if (AR_SREV_9300_20_OR_LATER(ah)) {
  781. imr_reg |= AR_IMR_RXOK_HP;
  782. if (ah->config.rx_intr_mitigation)
  783. imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
  784. else
  785. imr_reg |= AR_IMR_RXOK_LP;
  786. } else {
  787. if (ah->config.rx_intr_mitigation)
  788. imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
  789. else
  790. imr_reg |= AR_IMR_RXOK;
  791. }
  792. if (ah->config.tx_intr_mitigation)
  793. imr_reg |= AR_IMR_TXINTM | AR_IMR_TXMINTR;
  794. else
  795. imr_reg |= AR_IMR_TXOK;
  796. ENABLE_REGWRITE_BUFFER(ah);
  797. REG_WRITE(ah, AR_IMR, imr_reg);
  798. ah->imrs2_reg |= AR_IMR_S2_GTT;
  799. REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
  800. if (!AR_SREV_9100(ah)) {
  801. REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
  802. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, sync_default);
  803. REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
  804. }
  805. REGWRITE_BUFFER_FLUSH(ah);
  806. if (AR_SREV_9300_20_OR_LATER(ah)) {
  807. REG_WRITE(ah, AR_INTR_PRIO_ASYNC_ENABLE, 0);
  808. REG_WRITE(ah, AR_INTR_PRIO_ASYNC_MASK, 0);
  809. REG_WRITE(ah, AR_INTR_PRIO_SYNC_ENABLE, 0);
  810. REG_WRITE(ah, AR_INTR_PRIO_SYNC_MASK, 0);
  811. }
  812. }
  813. static void ath9k_hw_set_sifs_time(struct ath_hw *ah, u32 us)
  814. {
  815. u32 val = ath9k_hw_mac_to_clks(ah, us - 2);
  816. val = min(val, (u32) 0xFFFF);
  817. REG_WRITE(ah, AR_D_GBL_IFS_SIFS, val);
  818. }
  819. void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
  820. {
  821. u32 val = ath9k_hw_mac_to_clks(ah, us);
  822. val = min(val, (u32) 0xFFFF);
  823. REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
  824. }
  825. void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
  826. {
  827. u32 val = ath9k_hw_mac_to_clks(ah, us);
  828. val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
  829. REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
  830. }
  831. void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
  832. {
  833. u32 val = ath9k_hw_mac_to_clks(ah, us);
  834. val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
  835. REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
  836. }
  837. static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
  838. {
  839. if (tu > 0xFFFF) {
  840. ath_dbg(ath9k_hw_common(ah), XMIT, "bad global tx timeout %u\n",
  841. tu);
  842. ah->globaltxtimeout = (u32) -1;
  843. return false;
  844. } else {
  845. REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
  846. ah->globaltxtimeout = tu;
  847. return true;
  848. }
  849. }
  850. void ath9k_hw_init_global_settings(struct ath_hw *ah)
  851. {
  852. struct ath_common *common = ath9k_hw_common(ah);
  853. const struct ath9k_channel *chan = ah->curchan;
  854. int acktimeout, ctstimeout, ack_offset = 0;
  855. int slottime;
  856. int sifstime;
  857. int rx_lat = 0, tx_lat = 0, eifs = 0;
  858. u32 reg;
  859. ath_dbg(ath9k_hw_common(ah), RESET, "ah->misc_mode 0x%x\n",
  860. ah->misc_mode);
  861. if (!chan)
  862. return;
  863. if (ah->misc_mode != 0)
  864. REG_SET_BIT(ah, AR_PCU_MISC, ah->misc_mode);
  865. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  866. rx_lat = 41;
  867. else
  868. rx_lat = 37;
  869. tx_lat = 54;
  870. if (IS_CHAN_5GHZ(chan))
  871. sifstime = 16;
  872. else
  873. sifstime = 10;
  874. if (IS_CHAN_HALF_RATE(chan)) {
  875. eifs = 175;
  876. rx_lat *= 2;
  877. tx_lat *= 2;
  878. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  879. tx_lat += 11;
  880. sifstime = 32;
  881. ack_offset = 16;
  882. slottime = 13;
  883. } else if (IS_CHAN_QUARTER_RATE(chan)) {
  884. eifs = 340;
  885. rx_lat = (rx_lat * 4) - 1;
  886. tx_lat *= 4;
  887. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  888. tx_lat += 22;
  889. sifstime = 64;
  890. ack_offset = 32;
  891. slottime = 21;
  892. } else {
  893. if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
  894. eifs = AR_D_GBL_IFS_EIFS_ASYNC_FIFO;
  895. reg = AR_USEC_ASYNC_FIFO;
  896. } else {
  897. eifs = REG_READ(ah, AR_D_GBL_IFS_EIFS)/
  898. common->clockrate;
  899. reg = REG_READ(ah, AR_USEC);
  900. }
  901. rx_lat = MS(reg, AR_USEC_RX_LAT);
  902. tx_lat = MS(reg, AR_USEC_TX_LAT);
  903. slottime = ah->slottime;
  904. }
  905. /* As defined by IEEE 802.11-2007 17.3.8.6 */
  906. slottime += 3 * ah->coverage_class;
  907. acktimeout = slottime + sifstime + ack_offset;
  908. ctstimeout = acktimeout;
  909. /*
  910. * Workaround for early ACK timeouts, add an offset to match the
  911. * initval's 64us ack timeout value. Use 48us for the CTS timeout.
  912. * This was initially only meant to work around an issue with delayed
  913. * BA frames in some implementations, but it has been found to fix ACK
  914. * timeout issues in other cases as well.
  915. */
  916. if (IS_CHAN_2GHZ(chan) &&
  917. !IS_CHAN_HALF_RATE(chan) && !IS_CHAN_QUARTER_RATE(chan)) {
  918. acktimeout += 64 - sifstime - ah->slottime;
  919. ctstimeout += 48 - sifstime - ah->slottime;
  920. }
  921. if (ah->dynack.enabled) {
  922. acktimeout = ah->dynack.ackto;
  923. ctstimeout = acktimeout;
  924. slottime = (acktimeout - 3) / 2;
  925. } else {
  926. ah->dynack.ackto = acktimeout;
  927. }
  928. ath9k_hw_set_sifs_time(ah, sifstime);
  929. ath9k_hw_setslottime(ah, slottime);
  930. ath9k_hw_set_ack_timeout(ah, acktimeout);
  931. ath9k_hw_set_cts_timeout(ah, ctstimeout);
  932. if (ah->globaltxtimeout != (u32) -1)
  933. ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
  934. REG_WRITE(ah, AR_D_GBL_IFS_EIFS, ath9k_hw_mac_to_clks(ah, eifs));
  935. REG_RMW(ah, AR_USEC,
  936. (common->clockrate - 1) |
  937. SM(rx_lat, AR_USEC_RX_LAT) |
  938. SM(tx_lat, AR_USEC_TX_LAT),
  939. AR_USEC_TX_LAT | AR_USEC_RX_LAT | AR_USEC_USEC);
  940. }
  941. EXPORT_SYMBOL(ath9k_hw_init_global_settings);
  942. void ath9k_hw_deinit(struct ath_hw *ah)
  943. {
  944. struct ath_common *common = ath9k_hw_common(ah);
  945. if (common->state < ATH_HW_INITIALIZED)
  946. return;
  947. ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
  948. }
  949. EXPORT_SYMBOL(ath9k_hw_deinit);
  950. /*******/
  951. /* INI */
  952. /*******/
  953. u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
  954. {
  955. u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
  956. if (IS_CHAN_2GHZ(chan))
  957. ctl |= CTL_11G;
  958. else
  959. ctl |= CTL_11A;
  960. return ctl;
  961. }
  962. /****************************************/
  963. /* Reset and Channel Switching Routines */
  964. /****************************************/
  965. static inline void ath9k_hw_set_dma(struct ath_hw *ah)
  966. {
  967. struct ath_common *common = ath9k_hw_common(ah);
  968. int txbuf_size;
  969. ENABLE_REGWRITE_BUFFER(ah);
  970. /*
  971. * set AHB_MODE not to do cacheline prefetches
  972. */
  973. if (!AR_SREV_9300_20_OR_LATER(ah))
  974. REG_SET_BIT(ah, AR_AHB_MODE, AR_AHB_PREFETCH_RD_EN);
  975. /*
  976. * let mac dma reads be in 128 byte chunks
  977. */
  978. REG_RMW(ah, AR_TXCFG, AR_TXCFG_DMASZ_128B, AR_TXCFG_DMASZ_MASK);
  979. REGWRITE_BUFFER_FLUSH(ah);
  980. /*
  981. * Restore TX Trigger Level to its pre-reset value.
  982. * The initial value depends on whether aggregation is enabled, and is
  983. * adjusted whenever underruns are detected.
  984. */
  985. if (!AR_SREV_9300_20_OR_LATER(ah))
  986. REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
  987. ENABLE_REGWRITE_BUFFER(ah);
  988. /*
  989. * let mac dma writes be in 128 byte chunks
  990. */
  991. REG_RMW(ah, AR_RXCFG, AR_RXCFG_DMASZ_128B, AR_RXCFG_DMASZ_MASK);
  992. /*
  993. * Setup receive FIFO threshold to hold off TX activities
  994. */
  995. REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
  996. if (AR_SREV_9300_20_OR_LATER(ah)) {
  997. REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_HP, 0x1);
  998. REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_LP, 0x1);
  999. ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
  1000. ah->caps.rx_status_len);
  1001. }
  1002. /*
  1003. * reduce the number of usable entries in PCU TXBUF to avoid
  1004. * wrap around issues.
  1005. */
  1006. if (AR_SREV_9285(ah)) {
  1007. /* For AR9285 the number of Fifos are reduced to half.
  1008. * So set the usable tx buf size also to half to
  1009. * avoid data/delimiter underruns
  1010. */
  1011. txbuf_size = AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE;
  1012. } else if (AR_SREV_9340_13_OR_LATER(ah)) {
  1013. /* Uses fewer entries for AR934x v1.3+ to prevent rx overruns */
  1014. txbuf_size = AR_9340_PCU_TXBUF_CTRL_USABLE_SIZE;
  1015. } else {
  1016. txbuf_size = AR_PCU_TXBUF_CTRL_USABLE_SIZE;
  1017. }
  1018. if (!AR_SREV_9271(ah))
  1019. REG_WRITE(ah, AR_PCU_TXBUF_CTRL, txbuf_size);
  1020. REGWRITE_BUFFER_FLUSH(ah);
  1021. if (AR_SREV_9300_20_OR_LATER(ah))
  1022. ath9k_hw_reset_txstatus_ring(ah);
  1023. }
  1024. static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
  1025. {
  1026. u32 mask = AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC;
  1027. u32 set = AR_STA_ID1_KSRCH_MODE;
  1028. ENABLE_REG_RMW_BUFFER(ah);
  1029. switch (opmode) {
  1030. case NL80211_IFTYPE_ADHOC:
  1031. if (!AR_SREV_9340_13(ah)) {
  1032. set |= AR_STA_ID1_ADHOC;
  1033. REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
  1034. break;
  1035. }
  1036. /* fall through */
  1037. case NL80211_IFTYPE_MESH_POINT:
  1038. case NL80211_IFTYPE_AP:
  1039. set |= AR_STA_ID1_STA_AP;
  1040. /* fall through */
  1041. case NL80211_IFTYPE_STATION:
  1042. REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
  1043. break;
  1044. default:
  1045. if (!ah->is_monitoring)
  1046. set = 0;
  1047. break;
  1048. }
  1049. REG_RMW(ah, AR_STA_ID1, set, mask);
  1050. REG_RMW_BUFFER_FLUSH(ah);
  1051. }
  1052. void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
  1053. u32 *coef_mantissa, u32 *coef_exponent)
  1054. {
  1055. u32 coef_exp, coef_man;
  1056. for (coef_exp = 31; coef_exp > 0; coef_exp--)
  1057. if ((coef_scaled >> coef_exp) & 0x1)
  1058. break;
  1059. coef_exp = 14 - (coef_exp - COEF_SCALE_S);
  1060. coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
  1061. *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
  1062. *coef_exponent = coef_exp - 16;
  1063. }
  1064. /* AR9330 WAR:
  1065. * call external reset function to reset WMAC if:
  1066. * - doing a cold reset
  1067. * - we have pending frames in the TX queues.
  1068. */
  1069. static bool ath9k_hw_ar9330_reset_war(struct ath_hw *ah, int type)
  1070. {
  1071. int i, npend = 0;
  1072. for (i = 0; i < AR_NUM_QCU; i++) {
  1073. npend = ath9k_hw_numtxpending(ah, i);
  1074. if (npend)
  1075. break;
  1076. }
  1077. if (ah->external_reset &&
  1078. (npend || type == ATH9K_RESET_COLD)) {
  1079. int reset_err = 0;
  1080. ath_dbg(ath9k_hw_common(ah), RESET,
  1081. "reset MAC via external reset\n");
  1082. reset_err = ah->external_reset();
  1083. if (reset_err) {
  1084. ath_err(ath9k_hw_common(ah),
  1085. "External reset failed, err=%d\n",
  1086. reset_err);
  1087. return false;
  1088. }
  1089. REG_WRITE(ah, AR_RTC_RESET, 1);
  1090. }
  1091. return true;
  1092. }
  1093. static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
  1094. {
  1095. u32 rst_flags;
  1096. u32 tmpReg;
  1097. if (AR_SREV_9100(ah)) {
  1098. REG_RMW_FIELD(ah, AR_RTC_DERIVED_CLK,
  1099. AR_RTC_DERIVED_CLK_PERIOD, 1);
  1100. (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
  1101. }
  1102. ENABLE_REGWRITE_BUFFER(ah);
  1103. if (AR_SREV_9300_20_OR_LATER(ah)) {
  1104. REG_WRITE(ah, AR_WA, ah->WARegVal);
  1105. udelay(10);
  1106. }
  1107. REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
  1108. AR_RTC_FORCE_WAKE_ON_INT);
  1109. if (AR_SREV_9100(ah)) {
  1110. rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
  1111. AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
  1112. } else {
  1113. tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
  1114. if (AR_SREV_9340(ah))
  1115. tmpReg &= AR9340_INTR_SYNC_LOCAL_TIMEOUT;
  1116. else
  1117. tmpReg &= AR_INTR_SYNC_LOCAL_TIMEOUT |
  1118. AR_INTR_SYNC_RADM_CPL_TIMEOUT;
  1119. if (tmpReg) {
  1120. u32 val;
  1121. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
  1122. val = AR_RC_HOSTIF;
  1123. if (!AR_SREV_9300_20_OR_LATER(ah))
  1124. val |= AR_RC_AHB;
  1125. REG_WRITE(ah, AR_RC, val);
  1126. } else if (!AR_SREV_9300_20_OR_LATER(ah))
  1127. REG_WRITE(ah, AR_RC, AR_RC_AHB);
  1128. rst_flags = AR_RTC_RC_MAC_WARM;
  1129. if (type == ATH9K_RESET_COLD)
  1130. rst_flags |= AR_RTC_RC_MAC_COLD;
  1131. }
  1132. if (AR_SREV_9330(ah)) {
  1133. if (!ath9k_hw_ar9330_reset_war(ah, type))
  1134. return false;
  1135. }
  1136. if (ath9k_hw_mci_is_enabled(ah))
  1137. ar9003_mci_check_gpm_offset(ah);
  1138. REG_WRITE(ah, AR_RTC_RC, rst_flags);
  1139. REGWRITE_BUFFER_FLUSH(ah);
  1140. if (AR_SREV_9300_20_OR_LATER(ah))
  1141. udelay(50);
  1142. else if (AR_SREV_9100(ah))
  1143. mdelay(10);
  1144. else
  1145. udelay(100);
  1146. REG_WRITE(ah, AR_RTC_RC, 0);
  1147. if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
  1148. ath_dbg(ath9k_hw_common(ah), RESET, "RTC stuck in MAC reset\n");
  1149. return false;
  1150. }
  1151. if (!AR_SREV_9100(ah))
  1152. REG_WRITE(ah, AR_RC, 0);
  1153. if (AR_SREV_9100(ah))
  1154. udelay(50);
  1155. return true;
  1156. }
  1157. static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
  1158. {
  1159. ENABLE_REGWRITE_BUFFER(ah);
  1160. if (AR_SREV_9300_20_OR_LATER(ah)) {
  1161. REG_WRITE(ah, AR_WA, ah->WARegVal);
  1162. udelay(10);
  1163. }
  1164. REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
  1165. AR_RTC_FORCE_WAKE_ON_INT);
  1166. if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
  1167. REG_WRITE(ah, AR_RC, AR_RC_AHB);
  1168. REG_WRITE(ah, AR_RTC_RESET, 0);
  1169. REGWRITE_BUFFER_FLUSH(ah);
  1170. udelay(2);
  1171. if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
  1172. REG_WRITE(ah, AR_RC, 0);
  1173. REG_WRITE(ah, AR_RTC_RESET, 1);
  1174. if (!ath9k_hw_wait(ah,
  1175. AR_RTC_STATUS,
  1176. AR_RTC_STATUS_M,
  1177. AR_RTC_STATUS_ON,
  1178. AH_WAIT_TIMEOUT)) {
  1179. ath_dbg(ath9k_hw_common(ah), RESET, "RTC not waking up\n");
  1180. return false;
  1181. }
  1182. return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
  1183. }
  1184. static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
  1185. {
  1186. bool ret = false;
  1187. if (AR_SREV_9300_20_OR_LATER(ah)) {
  1188. REG_WRITE(ah, AR_WA, ah->WARegVal);
  1189. udelay(10);
  1190. }
  1191. REG_WRITE(ah, AR_RTC_FORCE_WAKE,
  1192. AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
  1193. if (!ah->reset_power_on)
  1194. type = ATH9K_RESET_POWER_ON;
  1195. switch (type) {
  1196. case ATH9K_RESET_POWER_ON:
  1197. ret = ath9k_hw_set_reset_power_on(ah);
  1198. if (ret)
  1199. ah->reset_power_on = true;
  1200. break;
  1201. case ATH9K_RESET_WARM:
  1202. case ATH9K_RESET_COLD:
  1203. ret = ath9k_hw_set_reset(ah, type);
  1204. break;
  1205. default:
  1206. break;
  1207. }
  1208. return ret;
  1209. }
  1210. static bool ath9k_hw_chip_reset(struct ath_hw *ah,
  1211. struct ath9k_channel *chan)
  1212. {
  1213. int reset_type = ATH9K_RESET_WARM;
  1214. if (AR_SREV_9280(ah)) {
  1215. if (ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
  1216. reset_type = ATH9K_RESET_POWER_ON;
  1217. else
  1218. reset_type = ATH9K_RESET_COLD;
  1219. } else if (ah->chip_fullsleep || REG_READ(ah, AR_Q_TXE) ||
  1220. (REG_READ(ah, AR_CR) & AR_CR_RXE))
  1221. reset_type = ATH9K_RESET_COLD;
  1222. if (!ath9k_hw_set_reset_reg(ah, reset_type))
  1223. return false;
  1224. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  1225. return false;
  1226. ah->chip_fullsleep = false;
  1227. if (AR_SREV_9330(ah))
  1228. ar9003_hw_internal_regulator_apply(ah);
  1229. ath9k_hw_init_pll(ah, chan);
  1230. return true;
  1231. }
  1232. static bool ath9k_hw_channel_change(struct ath_hw *ah,
  1233. struct ath9k_channel *chan)
  1234. {
  1235. struct ath_common *common = ath9k_hw_common(ah);
  1236. struct ath9k_hw_capabilities *pCap = &ah->caps;
  1237. bool band_switch = false, mode_diff = false;
  1238. u8 ini_reloaded = 0;
  1239. u32 qnum;
  1240. int r;
  1241. if (pCap->hw_caps & ATH9K_HW_CAP_FCC_BAND_SWITCH) {
  1242. u32 flags_diff = chan->channelFlags ^ ah->curchan->channelFlags;
  1243. band_switch = !!(flags_diff & CHANNEL_5GHZ);
  1244. mode_diff = !!(flags_diff & ~CHANNEL_HT);
  1245. }
  1246. for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
  1247. if (ath9k_hw_numtxpending(ah, qnum)) {
  1248. ath_dbg(common, QUEUE,
  1249. "Transmit frames pending on queue %d\n", qnum);
  1250. return false;
  1251. }
  1252. }
  1253. if (!ath9k_hw_rfbus_req(ah)) {
  1254. ath_err(common, "Could not kill baseband RX\n");
  1255. return false;
  1256. }
  1257. if (band_switch || mode_diff) {
  1258. ath9k_hw_mark_phy_inactive(ah);
  1259. udelay(5);
  1260. if (band_switch)
  1261. ath9k_hw_init_pll(ah, chan);
  1262. if (ath9k_hw_fast_chan_change(ah, chan, &ini_reloaded)) {
  1263. ath_err(common, "Failed to do fast channel change\n");
  1264. return false;
  1265. }
  1266. }
  1267. ath9k_hw_set_channel_regs(ah, chan);
  1268. r = ath9k_hw_rf_set_freq(ah, chan);
  1269. if (r) {
  1270. ath_err(common, "Failed to set channel\n");
  1271. return false;
  1272. }
  1273. ath9k_hw_set_clockrate(ah);
  1274. ath9k_hw_apply_txpower(ah, chan, false);
  1275. ath9k_hw_set_delta_slope(ah, chan);
  1276. ath9k_hw_spur_mitigate_freq(ah, chan);
  1277. if (band_switch || ini_reloaded)
  1278. ah->eep_ops->set_board_values(ah, chan);
  1279. ath9k_hw_init_bb(ah, chan);
  1280. ath9k_hw_rfbus_done(ah);
  1281. if (band_switch || ini_reloaded) {
  1282. ah->ah_flags |= AH_FASTCC;
  1283. ath9k_hw_init_cal(ah, chan);
  1284. ah->ah_flags &= ~AH_FASTCC;
  1285. }
  1286. return true;
  1287. }
  1288. static void ath9k_hw_apply_gpio_override(struct ath_hw *ah)
  1289. {
  1290. u32 gpio_mask = ah->gpio_mask;
  1291. int i;
  1292. for (i = 0; gpio_mask; i++, gpio_mask >>= 1) {
  1293. if (!(gpio_mask & 1))
  1294. continue;
  1295. ath9k_hw_cfg_output(ah, i, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
  1296. ath9k_hw_set_gpio(ah, i, !!(ah->gpio_val & BIT(i)));
  1297. }
  1298. }
  1299. void ath9k_hw_check_nav(struct ath_hw *ah)
  1300. {
  1301. struct ath_common *common = ath9k_hw_common(ah);
  1302. u32 val;
  1303. val = REG_READ(ah, AR_NAV);
  1304. if (val != 0xdeadbeef && val > 0x7fff) {
  1305. ath_dbg(common, BSTUCK, "Abnormal NAV: 0x%x\n", val);
  1306. REG_WRITE(ah, AR_NAV, 0);
  1307. }
  1308. }
  1309. EXPORT_SYMBOL(ath9k_hw_check_nav);
  1310. bool ath9k_hw_check_alive(struct ath_hw *ah)
  1311. {
  1312. int count = 50;
  1313. u32 reg, last_val;
  1314. if (AR_SREV_9300(ah))
  1315. return !ath9k_hw_detect_mac_hang(ah);
  1316. if (AR_SREV_9285_12_OR_LATER(ah))
  1317. return true;
  1318. last_val = REG_READ(ah, AR_OBS_BUS_1);
  1319. do {
  1320. reg = REG_READ(ah, AR_OBS_BUS_1);
  1321. if (reg != last_val)
  1322. return true;
  1323. udelay(1);
  1324. last_val = reg;
  1325. if ((reg & 0x7E7FFFEF) == 0x00702400)
  1326. continue;
  1327. switch (reg & 0x7E000B00) {
  1328. case 0x1E000000:
  1329. case 0x52000B00:
  1330. case 0x18000B00:
  1331. continue;
  1332. default:
  1333. return true;
  1334. }
  1335. } while (count-- > 0);
  1336. return false;
  1337. }
  1338. EXPORT_SYMBOL(ath9k_hw_check_alive);
  1339. static void ath9k_hw_init_mfp(struct ath_hw *ah)
  1340. {
  1341. /* Setup MFP options for CCMP */
  1342. if (AR_SREV_9280_20_OR_LATER(ah)) {
  1343. /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
  1344. * frames when constructing CCMP AAD. */
  1345. REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
  1346. 0xc7ff);
  1347. if (AR_SREV_9271(ah) || AR_DEVID_7010(ah))
  1348. ah->sw_mgmt_crypto_tx = true;
  1349. else
  1350. ah->sw_mgmt_crypto_tx = false;
  1351. ah->sw_mgmt_crypto_rx = false;
  1352. } else if (AR_SREV_9160_10_OR_LATER(ah)) {
  1353. /* Disable hardware crypto for management frames */
  1354. REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
  1355. AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
  1356. REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
  1357. AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
  1358. ah->sw_mgmt_crypto_tx = true;
  1359. ah->sw_mgmt_crypto_rx = true;
  1360. } else {
  1361. ah->sw_mgmt_crypto_tx = true;
  1362. ah->sw_mgmt_crypto_rx = true;
  1363. }
  1364. }
  1365. static void ath9k_hw_reset_opmode(struct ath_hw *ah,
  1366. u32 macStaId1, u32 saveDefAntenna)
  1367. {
  1368. struct ath_common *common = ath9k_hw_common(ah);
  1369. ENABLE_REGWRITE_BUFFER(ah);
  1370. REG_RMW(ah, AR_STA_ID1, macStaId1
  1371. | AR_STA_ID1_RTS_USE_DEF
  1372. | ah->sta_id1_defaults,
  1373. ~AR_STA_ID1_SADH_MASK);
  1374. ath_hw_setbssidmask(common);
  1375. REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
  1376. ath9k_hw_write_associd(ah);
  1377. REG_WRITE(ah, AR_ISR, ~0);
  1378. REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
  1379. REGWRITE_BUFFER_FLUSH(ah);
  1380. ath9k_hw_set_operating_mode(ah, ah->opmode);
  1381. }
  1382. static void ath9k_hw_init_queues(struct ath_hw *ah)
  1383. {
  1384. int i;
  1385. ENABLE_REGWRITE_BUFFER(ah);
  1386. for (i = 0; i < AR_NUM_DCU; i++)
  1387. REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
  1388. REGWRITE_BUFFER_FLUSH(ah);
  1389. ah->intr_txqs = 0;
  1390. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  1391. ath9k_hw_resettxqueue(ah, i);
  1392. }
  1393. /*
  1394. * For big endian systems turn on swapping for descriptors
  1395. */
  1396. static void ath9k_hw_init_desc(struct ath_hw *ah)
  1397. {
  1398. struct ath_common *common = ath9k_hw_common(ah);
  1399. if (AR_SREV_9100(ah)) {
  1400. u32 mask;
  1401. mask = REG_READ(ah, AR_CFG);
  1402. if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
  1403. ath_dbg(common, RESET, "CFG Byte Swap Set 0x%x\n",
  1404. mask);
  1405. } else {
  1406. mask = INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
  1407. REG_WRITE(ah, AR_CFG, mask);
  1408. ath_dbg(common, RESET, "Setting CFG 0x%x\n",
  1409. REG_READ(ah, AR_CFG));
  1410. }
  1411. } else {
  1412. if (common->bus_ops->ath_bus_type == ATH_USB) {
  1413. /* Configure AR9271 target WLAN */
  1414. if (AR_SREV_9271(ah))
  1415. REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
  1416. else
  1417. REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
  1418. }
  1419. #ifdef __BIG_ENDIAN
  1420. else if (AR_SREV_9330(ah) || AR_SREV_9340(ah) ||
  1421. AR_SREV_9550(ah) || AR_SREV_9531(ah) ||
  1422. AR_SREV_9561(ah))
  1423. REG_RMW(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB, 0);
  1424. else
  1425. REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
  1426. #endif
  1427. }
  1428. }
  1429. /*
  1430. * Fast channel change:
  1431. * (Change synthesizer based on channel freq without resetting chip)
  1432. */
  1433. static int ath9k_hw_do_fastcc(struct ath_hw *ah, struct ath9k_channel *chan)
  1434. {
  1435. struct ath_common *common = ath9k_hw_common(ah);
  1436. struct ath9k_hw_capabilities *pCap = &ah->caps;
  1437. int ret;
  1438. if (AR_SREV_9280(ah) && common->bus_ops->ath_bus_type == ATH_PCI)
  1439. goto fail;
  1440. if (ah->chip_fullsleep)
  1441. goto fail;
  1442. if (!ah->curchan)
  1443. goto fail;
  1444. if (chan->channel == ah->curchan->channel)
  1445. goto fail;
  1446. if ((ah->curchan->channelFlags | chan->channelFlags) &
  1447. (CHANNEL_HALF | CHANNEL_QUARTER))
  1448. goto fail;
  1449. /*
  1450. * If cross-band fcc is not supoprted, bail out if channelFlags differ.
  1451. */
  1452. if (!(pCap->hw_caps & ATH9K_HW_CAP_FCC_BAND_SWITCH) &&
  1453. ((chan->channelFlags ^ ah->curchan->channelFlags) & ~CHANNEL_HT))
  1454. goto fail;
  1455. if (!ath9k_hw_check_alive(ah))
  1456. goto fail;
  1457. /*
  1458. * For AR9462, make sure that calibration data for
  1459. * re-using are present.
  1460. */
  1461. if (AR_SREV_9462(ah) && (ah->caldata &&
  1462. (!test_bit(TXIQCAL_DONE, &ah->caldata->cal_flags) ||
  1463. !test_bit(TXCLCAL_DONE, &ah->caldata->cal_flags) ||
  1464. !test_bit(RTT_DONE, &ah->caldata->cal_flags))))
  1465. goto fail;
  1466. ath_dbg(common, RESET, "FastChannelChange for %d -> %d\n",
  1467. ah->curchan->channel, chan->channel);
  1468. ret = ath9k_hw_channel_change(ah, chan);
  1469. if (!ret)
  1470. goto fail;
  1471. if (ath9k_hw_mci_is_enabled(ah))
  1472. ar9003_mci_2g5g_switch(ah, false);
  1473. ath9k_hw_loadnf(ah, ah->curchan);
  1474. ath9k_hw_start_nfcal(ah, true);
  1475. if (AR_SREV_9271(ah))
  1476. ar9002_hw_load_ani_reg(ah, chan);
  1477. return 0;
  1478. fail:
  1479. return -EINVAL;
  1480. }
  1481. u32 ath9k_hw_get_tsf_offset(struct timespec *last, struct timespec *cur)
  1482. {
  1483. struct timespec ts;
  1484. s64 usec;
  1485. if (!cur) {
  1486. getrawmonotonic(&ts);
  1487. cur = &ts;
  1488. }
  1489. usec = cur->tv_sec * 1000000ULL + cur->tv_nsec / 1000;
  1490. usec -= last->tv_sec * 1000000ULL + last->tv_nsec / 1000;
  1491. return (u32) usec;
  1492. }
  1493. EXPORT_SYMBOL(ath9k_hw_get_tsf_offset);
  1494. int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
  1495. struct ath9k_hw_cal_data *caldata, bool fastcc)
  1496. {
  1497. struct ath_common *common = ath9k_hw_common(ah);
  1498. u32 saveLedState;
  1499. u32 saveDefAntenna;
  1500. u32 macStaId1;
  1501. u64 tsf = 0;
  1502. s64 usec = 0;
  1503. int r;
  1504. bool start_mci_reset = false;
  1505. bool save_fullsleep = ah->chip_fullsleep;
  1506. if (ath9k_hw_mci_is_enabled(ah)) {
  1507. start_mci_reset = ar9003_mci_start_reset(ah, chan);
  1508. if (start_mci_reset)
  1509. return 0;
  1510. }
  1511. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  1512. return -EIO;
  1513. if (ah->curchan && !ah->chip_fullsleep)
  1514. ath9k_hw_getnf(ah, ah->curchan);
  1515. ah->caldata = caldata;
  1516. if (caldata && (chan->channel != caldata->channel ||
  1517. chan->channelFlags != caldata->channelFlags)) {
  1518. /* Operating channel changed, reset channel calibration data */
  1519. memset(caldata, 0, sizeof(*caldata));
  1520. ath9k_init_nfcal_hist_buffer(ah, chan);
  1521. } else if (caldata) {
  1522. clear_bit(PAPRD_PACKET_SENT, &caldata->cal_flags);
  1523. }
  1524. ah->noise = ath9k_hw_getchan_noise(ah, chan, chan->noisefloor);
  1525. if (fastcc) {
  1526. r = ath9k_hw_do_fastcc(ah, chan);
  1527. if (!r)
  1528. return r;
  1529. }
  1530. if (ath9k_hw_mci_is_enabled(ah))
  1531. ar9003_mci_stop_bt(ah, save_fullsleep);
  1532. saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
  1533. if (saveDefAntenna == 0)
  1534. saveDefAntenna = 1;
  1535. macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
  1536. /* Save TSF before chip reset, a cold reset clears it */
  1537. tsf = ath9k_hw_gettsf64(ah);
  1538. usec = ktime_to_us(ktime_get_raw());
  1539. saveLedState = REG_READ(ah, AR_CFG_LED) &
  1540. (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
  1541. AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
  1542. ath9k_hw_mark_phy_inactive(ah);
  1543. ah->paprd_table_write_done = false;
  1544. /* Only required on the first reset */
  1545. if (AR_SREV_9271(ah) && ah->htc_reset_init) {
  1546. REG_WRITE(ah,
  1547. AR9271_RESET_POWER_DOWN_CONTROL,
  1548. AR9271_RADIO_RF_RST);
  1549. udelay(50);
  1550. }
  1551. if (!ath9k_hw_chip_reset(ah, chan)) {
  1552. ath_err(common, "Chip reset failed\n");
  1553. return -EINVAL;
  1554. }
  1555. /* Only required on the first reset */
  1556. if (AR_SREV_9271(ah) && ah->htc_reset_init) {
  1557. ah->htc_reset_init = false;
  1558. REG_WRITE(ah,
  1559. AR9271_RESET_POWER_DOWN_CONTROL,
  1560. AR9271_GATE_MAC_CTL);
  1561. udelay(50);
  1562. }
  1563. /* Restore TSF */
  1564. usec = ktime_to_us(ktime_get_raw()) - usec;
  1565. ath9k_hw_settsf64(ah, tsf + usec);
  1566. if (AR_SREV_9280_20_OR_LATER(ah))
  1567. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
  1568. if (!AR_SREV_9300_20_OR_LATER(ah))
  1569. ar9002_hw_enable_async_fifo(ah);
  1570. r = ath9k_hw_process_ini(ah, chan);
  1571. if (r)
  1572. return r;
  1573. ath9k_hw_set_rfmode(ah, chan);
  1574. if (ath9k_hw_mci_is_enabled(ah))
  1575. ar9003_mci_reset(ah, false, IS_CHAN_2GHZ(chan), save_fullsleep);
  1576. /*
  1577. * Some AR91xx SoC devices frequently fail to accept TSF writes
  1578. * right after the chip reset. When that happens, write a new
  1579. * value after the initvals have been applied, with an offset
  1580. * based on measured time difference
  1581. */
  1582. if (AR_SREV_9100(ah) && (ath9k_hw_gettsf64(ah) < tsf)) {
  1583. tsf += 1500;
  1584. ath9k_hw_settsf64(ah, tsf);
  1585. }
  1586. ath9k_hw_init_mfp(ah);
  1587. ath9k_hw_set_delta_slope(ah, chan);
  1588. ath9k_hw_spur_mitigate_freq(ah, chan);
  1589. ah->eep_ops->set_board_values(ah, chan);
  1590. ath9k_hw_reset_opmode(ah, macStaId1, saveDefAntenna);
  1591. r = ath9k_hw_rf_set_freq(ah, chan);
  1592. if (r)
  1593. return r;
  1594. ath9k_hw_set_clockrate(ah);
  1595. ath9k_hw_init_queues(ah);
  1596. ath9k_hw_init_interrupt_masks(ah, ah->opmode);
  1597. ath9k_hw_ani_cache_ini_regs(ah);
  1598. ath9k_hw_init_qos(ah);
  1599. if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
  1600. ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
  1601. ath9k_hw_init_global_settings(ah);
  1602. if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
  1603. REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
  1604. AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
  1605. REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
  1606. AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
  1607. REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
  1608. AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
  1609. }
  1610. REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PRESERVE_SEQNUM);
  1611. ath9k_hw_set_dma(ah);
  1612. if (!ath9k_hw_mci_is_enabled(ah))
  1613. REG_WRITE(ah, AR_OBS, 8);
  1614. ENABLE_REG_RMW_BUFFER(ah);
  1615. if (ah->config.rx_intr_mitigation) {
  1616. REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, ah->config.rimt_last);
  1617. REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, ah->config.rimt_first);
  1618. }
  1619. if (ah->config.tx_intr_mitigation) {
  1620. REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_LAST, 300);
  1621. REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_FIRST, 750);
  1622. }
  1623. REG_RMW_BUFFER_FLUSH(ah);
  1624. ath9k_hw_init_bb(ah, chan);
  1625. if (caldata) {
  1626. clear_bit(TXIQCAL_DONE, &caldata->cal_flags);
  1627. clear_bit(TXCLCAL_DONE, &caldata->cal_flags);
  1628. }
  1629. if (!ath9k_hw_init_cal(ah, chan))
  1630. return -EIO;
  1631. if (ath9k_hw_mci_is_enabled(ah) && ar9003_mci_end_reset(ah, chan, caldata))
  1632. return -EIO;
  1633. ENABLE_REGWRITE_BUFFER(ah);
  1634. ath9k_hw_restore_chainmask(ah);
  1635. REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
  1636. REGWRITE_BUFFER_FLUSH(ah);
  1637. ath9k_hw_gen_timer_start_tsf2(ah);
  1638. ath9k_hw_init_desc(ah);
  1639. if (ath9k_hw_btcoex_is_enabled(ah))
  1640. ath9k_hw_btcoex_enable(ah);
  1641. if (ath9k_hw_mci_is_enabled(ah))
  1642. ar9003_mci_check_bt(ah);
  1643. if (AR_SREV_9300_20_OR_LATER(ah)) {
  1644. ath9k_hw_loadnf(ah, chan);
  1645. ath9k_hw_start_nfcal(ah, true);
  1646. }
  1647. if (AR_SREV_9300_20_OR_LATER(ah))
  1648. ar9003_hw_bb_watchdog_config(ah);
  1649. if (ah->config.hw_hang_checks & HW_PHYRESTART_CLC_WAR)
  1650. ar9003_hw_disable_phy_restart(ah);
  1651. ath9k_hw_apply_gpio_override(ah);
  1652. if (AR_SREV_9565(ah) && common->bt_ant_diversity)
  1653. REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV, AR_BTCOEX_WL_LNADIV_FORCE_ON);
  1654. if (ah->hw->conf.radar_enabled) {
  1655. /* set HW specific DFS configuration */
  1656. ah->radar_conf.ext_channel = IS_CHAN_HT40(chan);
  1657. ath9k_hw_set_radar_params(ah);
  1658. }
  1659. return 0;
  1660. }
  1661. EXPORT_SYMBOL(ath9k_hw_reset);
  1662. /******************************/
  1663. /* Power Management (Chipset) */
  1664. /******************************/
  1665. /*
  1666. * Notify Power Mgt is disabled in self-generated frames.
  1667. * If requested, force chip to sleep.
  1668. */
  1669. static void ath9k_set_power_sleep(struct ath_hw *ah)
  1670. {
  1671. REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  1672. if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
  1673. REG_CLR_BIT(ah, AR_TIMER_MODE, 0xff);
  1674. REG_CLR_BIT(ah, AR_NDP2_TIMER_MODE, 0xff);
  1675. REG_CLR_BIT(ah, AR_SLP32_INC, 0xfffff);
  1676. /* xxx Required for WLAN only case ? */
  1677. REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN, 0);
  1678. udelay(100);
  1679. }
  1680. /*
  1681. * Clear the RTC force wake bit to allow the
  1682. * mac to go to sleep.
  1683. */
  1684. REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
  1685. if (ath9k_hw_mci_is_enabled(ah))
  1686. udelay(100);
  1687. if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
  1688. REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
  1689. /* Shutdown chip. Active low */
  1690. if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah)) {
  1691. REG_CLR_BIT(ah, AR_RTC_RESET, AR_RTC_RESET_EN);
  1692. udelay(2);
  1693. }
  1694. /* Clear Bit 14 of AR_WA after putting chip into Full Sleep mode. */
  1695. if (AR_SREV_9300_20_OR_LATER(ah))
  1696. REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
  1697. }
  1698. /*
  1699. * Notify Power Management is enabled in self-generating
  1700. * frames. If request, set power mode of chip to
  1701. * auto/normal. Duration in units of 128us (1/8 TU).
  1702. */
  1703. static void ath9k_set_power_network_sleep(struct ath_hw *ah)
  1704. {
  1705. struct ath9k_hw_capabilities *pCap = &ah->caps;
  1706. REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  1707. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  1708. /* Set WakeOnInterrupt bit; clear ForceWake bit */
  1709. REG_WRITE(ah, AR_RTC_FORCE_WAKE,
  1710. AR_RTC_FORCE_WAKE_ON_INT);
  1711. } else {
  1712. /* When chip goes into network sleep, it could be waken
  1713. * up by MCI_INT interrupt caused by BT's HW messages
  1714. * (LNA_xxx, CONT_xxx) which chould be in a very fast
  1715. * rate (~100us). This will cause chip to leave and
  1716. * re-enter network sleep mode frequently, which in
  1717. * consequence will have WLAN MCI HW to generate lots of
  1718. * SYS_WAKING and SYS_SLEEPING messages which will make
  1719. * BT CPU to busy to process.
  1720. */
  1721. if (ath9k_hw_mci_is_enabled(ah))
  1722. REG_CLR_BIT(ah, AR_MCI_INTERRUPT_RX_MSG_EN,
  1723. AR_MCI_INTERRUPT_RX_HW_MSG_MASK);
  1724. /*
  1725. * Clear the RTC force wake bit to allow the
  1726. * mac to go to sleep.
  1727. */
  1728. REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
  1729. if (ath9k_hw_mci_is_enabled(ah))
  1730. udelay(30);
  1731. }
  1732. /* Clear Bit 14 of AR_WA after putting chip into Net Sleep mode. */
  1733. if (AR_SREV_9300_20_OR_LATER(ah))
  1734. REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
  1735. }
  1736. static bool ath9k_hw_set_power_awake(struct ath_hw *ah)
  1737. {
  1738. u32 val;
  1739. int i;
  1740. /* Set Bits 14 and 17 of AR_WA before powering on the chip. */
  1741. if (AR_SREV_9300_20_OR_LATER(ah)) {
  1742. REG_WRITE(ah, AR_WA, ah->WARegVal);
  1743. udelay(10);
  1744. }
  1745. if ((REG_READ(ah, AR_RTC_STATUS) &
  1746. AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
  1747. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
  1748. return false;
  1749. }
  1750. if (!AR_SREV_9300_20_OR_LATER(ah))
  1751. ath9k_hw_init_pll(ah, NULL);
  1752. }
  1753. if (AR_SREV_9100(ah))
  1754. REG_SET_BIT(ah, AR_RTC_RESET,
  1755. AR_RTC_RESET_EN);
  1756. REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
  1757. AR_RTC_FORCE_WAKE_EN);
  1758. if (AR_SREV_9100(ah))
  1759. mdelay(10);
  1760. else
  1761. udelay(50);
  1762. for (i = POWER_UP_TIME / 50; i > 0; i--) {
  1763. val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
  1764. if (val == AR_RTC_STATUS_ON)
  1765. break;
  1766. udelay(50);
  1767. REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
  1768. AR_RTC_FORCE_WAKE_EN);
  1769. }
  1770. if (i == 0) {
  1771. ath_err(ath9k_hw_common(ah),
  1772. "Failed to wakeup in %uus\n",
  1773. POWER_UP_TIME / 20);
  1774. return false;
  1775. }
  1776. if (ath9k_hw_mci_is_enabled(ah))
  1777. ar9003_mci_set_power_awake(ah);
  1778. REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  1779. return true;
  1780. }
  1781. bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
  1782. {
  1783. struct ath_common *common = ath9k_hw_common(ah);
  1784. int status = true;
  1785. static const char *modes[] = {
  1786. "AWAKE",
  1787. "FULL-SLEEP",
  1788. "NETWORK SLEEP",
  1789. "UNDEFINED"
  1790. };
  1791. if (ah->power_mode == mode)
  1792. return status;
  1793. ath_dbg(common, RESET, "%s -> %s\n",
  1794. modes[ah->power_mode], modes[mode]);
  1795. switch (mode) {
  1796. case ATH9K_PM_AWAKE:
  1797. status = ath9k_hw_set_power_awake(ah);
  1798. break;
  1799. case ATH9K_PM_FULL_SLEEP:
  1800. if (ath9k_hw_mci_is_enabled(ah))
  1801. ar9003_mci_set_full_sleep(ah);
  1802. ath9k_set_power_sleep(ah);
  1803. ah->chip_fullsleep = true;
  1804. break;
  1805. case ATH9K_PM_NETWORK_SLEEP:
  1806. ath9k_set_power_network_sleep(ah);
  1807. break;
  1808. default:
  1809. ath_err(common, "Unknown power mode %u\n", mode);
  1810. return false;
  1811. }
  1812. ah->power_mode = mode;
  1813. /*
  1814. * XXX: If this warning never comes up after a while then
  1815. * simply keep the ATH_DBG_WARN_ON_ONCE() but make
  1816. * ath9k_hw_setpower() return type void.
  1817. */
  1818. if (!(ah->ah_flags & AH_UNPLUGGED))
  1819. ATH_DBG_WARN_ON_ONCE(!status);
  1820. return status;
  1821. }
  1822. EXPORT_SYMBOL(ath9k_hw_setpower);
  1823. /*******************/
  1824. /* Beacon Handling */
  1825. /*******************/
  1826. void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
  1827. {
  1828. int flags = 0;
  1829. ENABLE_REGWRITE_BUFFER(ah);
  1830. switch (ah->opmode) {
  1831. case NL80211_IFTYPE_ADHOC:
  1832. REG_SET_BIT(ah, AR_TXCFG,
  1833. AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
  1834. case NL80211_IFTYPE_MESH_POINT:
  1835. case NL80211_IFTYPE_AP:
  1836. REG_WRITE(ah, AR_NEXT_TBTT_TIMER, next_beacon);
  1837. REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, next_beacon -
  1838. TU_TO_USEC(ah->config.dma_beacon_response_time));
  1839. REG_WRITE(ah, AR_NEXT_SWBA, next_beacon -
  1840. TU_TO_USEC(ah->config.sw_beacon_response_time));
  1841. flags |=
  1842. AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
  1843. break;
  1844. default:
  1845. ath_dbg(ath9k_hw_common(ah), BEACON,
  1846. "%s: unsupported opmode: %d\n", __func__, ah->opmode);
  1847. return;
  1848. break;
  1849. }
  1850. REG_WRITE(ah, AR_BEACON_PERIOD, beacon_period);
  1851. REG_WRITE(ah, AR_DMA_BEACON_PERIOD, beacon_period);
  1852. REG_WRITE(ah, AR_SWBA_PERIOD, beacon_period);
  1853. REGWRITE_BUFFER_FLUSH(ah);
  1854. REG_SET_BIT(ah, AR_TIMER_MODE, flags);
  1855. }
  1856. EXPORT_SYMBOL(ath9k_hw_beaconinit);
  1857. void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
  1858. const struct ath9k_beacon_state *bs)
  1859. {
  1860. u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
  1861. struct ath9k_hw_capabilities *pCap = &ah->caps;
  1862. struct ath_common *common = ath9k_hw_common(ah);
  1863. ENABLE_REGWRITE_BUFFER(ah);
  1864. REG_WRITE(ah, AR_NEXT_TBTT_TIMER, bs->bs_nexttbtt);
  1865. REG_WRITE(ah, AR_BEACON_PERIOD, bs->bs_intval);
  1866. REG_WRITE(ah, AR_DMA_BEACON_PERIOD, bs->bs_intval);
  1867. REGWRITE_BUFFER_FLUSH(ah);
  1868. REG_RMW_FIELD(ah, AR_RSSI_THR,
  1869. AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
  1870. beaconintval = bs->bs_intval;
  1871. if (bs->bs_sleepduration > beaconintval)
  1872. beaconintval = bs->bs_sleepduration;
  1873. dtimperiod = bs->bs_dtimperiod;
  1874. if (bs->bs_sleepduration > dtimperiod)
  1875. dtimperiod = bs->bs_sleepduration;
  1876. if (beaconintval == dtimperiod)
  1877. nextTbtt = bs->bs_nextdtim;
  1878. else
  1879. nextTbtt = bs->bs_nexttbtt;
  1880. ath_dbg(common, BEACON, "next DTIM %d\n", bs->bs_nextdtim);
  1881. ath_dbg(common, BEACON, "next beacon %d\n", nextTbtt);
  1882. ath_dbg(common, BEACON, "beacon period %d\n", beaconintval);
  1883. ath_dbg(common, BEACON, "DTIM period %d\n", dtimperiod);
  1884. ENABLE_REGWRITE_BUFFER(ah);
  1885. REG_WRITE(ah, AR_NEXT_DTIM, bs->bs_nextdtim - SLEEP_SLOP);
  1886. REG_WRITE(ah, AR_NEXT_TIM, nextTbtt - SLEEP_SLOP);
  1887. REG_WRITE(ah, AR_SLEEP1,
  1888. SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
  1889. | AR_SLEEP1_ASSUME_DTIM);
  1890. if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
  1891. beacontimeout = (BEACON_TIMEOUT_VAL << 3);
  1892. else
  1893. beacontimeout = MIN_BEACON_TIMEOUT_VAL;
  1894. REG_WRITE(ah, AR_SLEEP2,
  1895. SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
  1896. REG_WRITE(ah, AR_TIM_PERIOD, beaconintval);
  1897. REG_WRITE(ah, AR_DTIM_PERIOD, dtimperiod);
  1898. REGWRITE_BUFFER_FLUSH(ah);
  1899. REG_SET_BIT(ah, AR_TIMER_MODE,
  1900. AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
  1901. AR_DTIM_TIMER_EN);
  1902. /* TSF Out of Range Threshold */
  1903. REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
  1904. }
  1905. EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
  1906. /*******************/
  1907. /* HW Capabilities */
  1908. /*******************/
  1909. static u8 fixup_chainmask(u8 chip_chainmask, u8 eeprom_chainmask)
  1910. {
  1911. eeprom_chainmask &= chip_chainmask;
  1912. if (eeprom_chainmask)
  1913. return eeprom_chainmask;
  1914. else
  1915. return chip_chainmask;
  1916. }
  1917. /**
  1918. * ath9k_hw_dfs_tested - checks if DFS has been tested with used chipset
  1919. * @ah: the atheros hardware data structure
  1920. *
  1921. * We enable DFS support upstream on chipsets which have passed a series
  1922. * of tests. The testing requirements are going to be documented. Desired
  1923. * test requirements are documented at:
  1924. *
  1925. * http://wireless.kernel.org/en/users/Drivers/ath9k/dfs
  1926. *
  1927. * Once a new chipset gets properly tested an individual commit can be used
  1928. * to document the testing for DFS for that chipset.
  1929. */
  1930. static bool ath9k_hw_dfs_tested(struct ath_hw *ah)
  1931. {
  1932. switch (ah->hw_version.macVersion) {
  1933. /* for temporary testing DFS with 9280 */
  1934. case AR_SREV_VERSION_9280:
  1935. /* AR9580 will likely be our first target to get testing on */
  1936. case AR_SREV_VERSION_9580:
  1937. return true;
  1938. default:
  1939. return false;
  1940. }
  1941. }
  1942. int ath9k_hw_fill_cap_info(struct ath_hw *ah)
  1943. {
  1944. struct ath9k_hw_capabilities *pCap = &ah->caps;
  1945. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  1946. struct ath_common *common = ath9k_hw_common(ah);
  1947. u16 eeval;
  1948. u8 ant_div_ctl1, tx_chainmask, rx_chainmask;
  1949. eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
  1950. regulatory->current_rd = eeval;
  1951. if (ah->opmode != NL80211_IFTYPE_AP &&
  1952. ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
  1953. if (regulatory->current_rd == 0x64 ||
  1954. regulatory->current_rd == 0x65)
  1955. regulatory->current_rd += 5;
  1956. else if (regulatory->current_rd == 0x41)
  1957. regulatory->current_rd = 0x43;
  1958. ath_dbg(common, REGULATORY, "regdomain mapped to 0x%x\n",
  1959. regulatory->current_rd);
  1960. }
  1961. eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
  1962. if (eeval & AR5416_OPFLAGS_11A) {
  1963. if (ah->disable_5ghz)
  1964. ath_warn(common, "disabling 5GHz band\n");
  1965. else
  1966. pCap->hw_caps |= ATH9K_HW_CAP_5GHZ;
  1967. }
  1968. if (eeval & AR5416_OPFLAGS_11G) {
  1969. if (ah->disable_2ghz)
  1970. ath_warn(common, "disabling 2GHz band\n");
  1971. else
  1972. pCap->hw_caps |= ATH9K_HW_CAP_2GHZ;
  1973. }
  1974. if ((pCap->hw_caps & (ATH9K_HW_CAP_2GHZ | ATH9K_HW_CAP_5GHZ)) == 0) {
  1975. ath_err(common, "both bands are disabled\n");
  1976. return -EINVAL;
  1977. }
  1978. if (AR_SREV_9485(ah) ||
  1979. AR_SREV_9285(ah) ||
  1980. AR_SREV_9330(ah) ||
  1981. AR_SREV_9565(ah))
  1982. pCap->chip_chainmask = 1;
  1983. else if (!AR_SREV_9280_20_OR_LATER(ah))
  1984. pCap->chip_chainmask = 7;
  1985. else if (!AR_SREV_9300_20_OR_LATER(ah) ||
  1986. AR_SREV_9340(ah) ||
  1987. AR_SREV_9462(ah) ||
  1988. AR_SREV_9531(ah))
  1989. pCap->chip_chainmask = 3;
  1990. else
  1991. pCap->chip_chainmask = 7;
  1992. pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
  1993. /*
  1994. * For AR9271 we will temporarilly uses the rx chainmax as read from
  1995. * the EEPROM.
  1996. */
  1997. if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
  1998. !(eeval & AR5416_OPFLAGS_11A) &&
  1999. !(AR_SREV_9271(ah)))
  2000. /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
  2001. pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
  2002. else if (AR_SREV_9100(ah))
  2003. pCap->rx_chainmask = 0x7;
  2004. else
  2005. /* Use rx_chainmask from EEPROM. */
  2006. pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
  2007. pCap->tx_chainmask = fixup_chainmask(pCap->chip_chainmask, pCap->tx_chainmask);
  2008. pCap->rx_chainmask = fixup_chainmask(pCap->chip_chainmask, pCap->rx_chainmask);
  2009. ah->txchainmask = pCap->tx_chainmask;
  2010. ah->rxchainmask = pCap->rx_chainmask;
  2011. ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
  2012. /* enable key search for every frame in an aggregate */
  2013. if (AR_SREV_9300_20_OR_LATER(ah))
  2014. ah->misc_mode |= AR_PCU_ALWAYS_PERFORM_KEYSEARCH;
  2015. common->crypt_caps |= ATH_CRYPT_CAP_CIPHER_AESCCM;
  2016. if (ah->hw_version.devid != AR2427_DEVID_PCIE)
  2017. pCap->hw_caps |= ATH9K_HW_CAP_HT;
  2018. else
  2019. pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
  2020. if (AR_SREV_9271(ah))
  2021. pCap->num_gpio_pins = AR9271_NUM_GPIO;
  2022. else if (AR_DEVID_7010(ah))
  2023. pCap->num_gpio_pins = AR7010_NUM_GPIO;
  2024. else if (AR_SREV_9300_20_OR_LATER(ah))
  2025. pCap->num_gpio_pins = AR9300_NUM_GPIO;
  2026. else if (AR_SREV_9287_11_OR_LATER(ah))
  2027. pCap->num_gpio_pins = AR9287_NUM_GPIO;
  2028. else if (AR_SREV_9285_12_OR_LATER(ah))
  2029. pCap->num_gpio_pins = AR9285_NUM_GPIO;
  2030. else if (AR_SREV_9280_20_OR_LATER(ah))
  2031. pCap->num_gpio_pins = AR928X_NUM_GPIO;
  2032. else
  2033. pCap->num_gpio_pins = AR_NUM_GPIO;
  2034. if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah))
  2035. pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
  2036. else
  2037. pCap->rts_aggr_limit = (8 * 1024);
  2038. #ifdef CONFIG_ATH9K_RFKILL
  2039. ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
  2040. if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
  2041. ah->rfkill_gpio =
  2042. MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
  2043. ah->rfkill_polarity =
  2044. MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
  2045. pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
  2046. }
  2047. #endif
  2048. if (AR_SREV_9271(ah) || AR_SREV_9300_20_OR_LATER(ah))
  2049. pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
  2050. else
  2051. pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
  2052. if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
  2053. pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
  2054. else
  2055. pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
  2056. if (AR_SREV_9300_20_OR_LATER(ah)) {
  2057. pCap->hw_caps |= ATH9K_HW_CAP_EDMA | ATH9K_HW_CAP_FASTCLOCK;
  2058. if (!AR_SREV_9330(ah) && !AR_SREV_9485(ah) &&
  2059. !AR_SREV_9561(ah) && !AR_SREV_9565(ah))
  2060. pCap->hw_caps |= ATH9K_HW_CAP_LDPC;
  2061. pCap->rx_hp_qdepth = ATH9K_HW_RX_HP_QDEPTH;
  2062. pCap->rx_lp_qdepth = ATH9K_HW_RX_LP_QDEPTH;
  2063. pCap->rx_status_len = sizeof(struct ar9003_rxs);
  2064. pCap->tx_desc_len = sizeof(struct ar9003_txc);
  2065. pCap->txs_len = sizeof(struct ar9003_txs);
  2066. } else {
  2067. pCap->tx_desc_len = sizeof(struct ath_desc);
  2068. if (AR_SREV_9280_20(ah))
  2069. pCap->hw_caps |= ATH9K_HW_CAP_FASTCLOCK;
  2070. }
  2071. if (AR_SREV_9300_20_OR_LATER(ah))
  2072. pCap->hw_caps |= ATH9K_HW_CAP_RAC_SUPPORTED;
  2073. if (AR_SREV_9561(ah))
  2074. ah->ent_mode = 0x3BDA000;
  2075. else if (AR_SREV_9300_20_OR_LATER(ah))
  2076. ah->ent_mode = REG_READ(ah, AR_ENT_OTP);
  2077. if (AR_SREV_9287_11_OR_LATER(ah) || AR_SREV_9271(ah))
  2078. pCap->hw_caps |= ATH9K_HW_CAP_SGI_20;
  2079. if (AR_SREV_9285(ah)) {
  2080. if (ah->eep_ops->get_eeprom(ah, EEP_MODAL_VER) >= 3) {
  2081. ant_div_ctl1 =
  2082. ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
  2083. if ((ant_div_ctl1 & 0x1) && ((ant_div_ctl1 >> 3) & 0x1)) {
  2084. pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
  2085. ath_info(common, "Enable LNA combining\n");
  2086. }
  2087. }
  2088. }
  2089. if (AR_SREV_9300_20_OR_LATER(ah)) {
  2090. if (ah->eep_ops->get_eeprom(ah, EEP_CHAIN_MASK_REDUCE))
  2091. pCap->hw_caps |= ATH9K_HW_CAP_APM;
  2092. }
  2093. if (AR_SREV_9330(ah) || AR_SREV_9485(ah) || AR_SREV_9565(ah)) {
  2094. ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
  2095. if ((ant_div_ctl1 >> 0x6) == 0x3) {
  2096. pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
  2097. ath_info(common, "Enable LNA combining\n");
  2098. }
  2099. }
  2100. if (ath9k_hw_dfs_tested(ah))
  2101. pCap->hw_caps |= ATH9K_HW_CAP_DFS;
  2102. tx_chainmask = pCap->tx_chainmask;
  2103. rx_chainmask = pCap->rx_chainmask;
  2104. while (tx_chainmask || rx_chainmask) {
  2105. if (tx_chainmask & BIT(0))
  2106. pCap->max_txchains++;
  2107. if (rx_chainmask & BIT(0))
  2108. pCap->max_rxchains++;
  2109. tx_chainmask >>= 1;
  2110. rx_chainmask >>= 1;
  2111. }
  2112. if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
  2113. if (!(ah->ent_mode & AR_ENT_OTP_49GHZ_DISABLE))
  2114. pCap->hw_caps |= ATH9K_HW_CAP_MCI;
  2115. if (AR_SREV_9462_20_OR_LATER(ah))
  2116. pCap->hw_caps |= ATH9K_HW_CAP_RTT;
  2117. }
  2118. if (AR_SREV_9300_20_OR_LATER(ah) &&
  2119. ah->eep_ops->get_eeprom(ah, EEP_PAPRD))
  2120. pCap->hw_caps |= ATH9K_HW_CAP_PAPRD;
  2121. #ifdef CONFIG_ATH9K_WOW
  2122. if (AR_SREV_9462_20_OR_LATER(ah) || AR_SREV_9565_11_OR_LATER(ah))
  2123. ah->wow.max_patterns = MAX_NUM_PATTERN;
  2124. else
  2125. ah->wow.max_patterns = MAX_NUM_PATTERN_LEGACY;
  2126. #endif
  2127. return 0;
  2128. }
  2129. /****************************/
  2130. /* GPIO / RFKILL / Antennae */
  2131. /****************************/
  2132. static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
  2133. u32 gpio, u32 type)
  2134. {
  2135. int addr;
  2136. u32 gpio_shift, tmp;
  2137. if (gpio > 11)
  2138. addr = AR_GPIO_OUTPUT_MUX3;
  2139. else if (gpio > 5)
  2140. addr = AR_GPIO_OUTPUT_MUX2;
  2141. else
  2142. addr = AR_GPIO_OUTPUT_MUX1;
  2143. gpio_shift = (gpio % 6) * 5;
  2144. if (AR_SREV_9280_20_OR_LATER(ah)
  2145. || (addr != AR_GPIO_OUTPUT_MUX1)) {
  2146. REG_RMW(ah, addr, (type << gpio_shift),
  2147. (0x1f << gpio_shift));
  2148. } else {
  2149. tmp = REG_READ(ah, addr);
  2150. tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
  2151. tmp &= ~(0x1f << gpio_shift);
  2152. tmp |= (type << gpio_shift);
  2153. REG_WRITE(ah, addr, tmp);
  2154. }
  2155. }
  2156. void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
  2157. {
  2158. u32 gpio_shift;
  2159. BUG_ON(gpio >= ah->caps.num_gpio_pins);
  2160. if (AR_DEVID_7010(ah)) {
  2161. gpio_shift = gpio;
  2162. REG_RMW(ah, AR7010_GPIO_OE,
  2163. (AR7010_GPIO_OE_AS_INPUT << gpio_shift),
  2164. (AR7010_GPIO_OE_MASK << gpio_shift));
  2165. return;
  2166. }
  2167. gpio_shift = gpio << 1;
  2168. REG_RMW(ah,
  2169. AR_GPIO_OE_OUT,
  2170. (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
  2171. (AR_GPIO_OE_OUT_DRV << gpio_shift));
  2172. }
  2173. EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
  2174. u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
  2175. {
  2176. #define MS_REG_READ(x, y) \
  2177. (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
  2178. if (gpio >= ah->caps.num_gpio_pins)
  2179. return 0xffffffff;
  2180. if (AR_DEVID_7010(ah)) {
  2181. u32 val;
  2182. val = REG_READ(ah, AR7010_GPIO_IN);
  2183. return (MS(val, AR7010_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) == 0;
  2184. } else if (AR_SREV_9300_20_OR_LATER(ah))
  2185. return (MS(REG_READ(ah, AR_GPIO_IN), AR9300_GPIO_IN_VAL) &
  2186. AR_GPIO_BIT(gpio)) != 0;
  2187. else if (AR_SREV_9271(ah))
  2188. return MS_REG_READ(AR9271, gpio) != 0;
  2189. else if (AR_SREV_9287_11_OR_LATER(ah))
  2190. return MS_REG_READ(AR9287, gpio) != 0;
  2191. else if (AR_SREV_9285_12_OR_LATER(ah))
  2192. return MS_REG_READ(AR9285, gpio) != 0;
  2193. else if (AR_SREV_9280_20_OR_LATER(ah))
  2194. return MS_REG_READ(AR928X, gpio) != 0;
  2195. else
  2196. return MS_REG_READ(AR, gpio) != 0;
  2197. }
  2198. EXPORT_SYMBOL(ath9k_hw_gpio_get);
  2199. void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
  2200. u32 ah_signal_type)
  2201. {
  2202. u32 gpio_shift;
  2203. if (AR_DEVID_7010(ah)) {
  2204. gpio_shift = gpio;
  2205. REG_RMW(ah, AR7010_GPIO_OE,
  2206. (AR7010_GPIO_OE_AS_OUTPUT << gpio_shift),
  2207. (AR7010_GPIO_OE_MASK << gpio_shift));
  2208. return;
  2209. }
  2210. ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
  2211. gpio_shift = 2 * gpio;
  2212. REG_RMW(ah,
  2213. AR_GPIO_OE_OUT,
  2214. (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
  2215. (AR_GPIO_OE_OUT_DRV << gpio_shift));
  2216. }
  2217. EXPORT_SYMBOL(ath9k_hw_cfg_output);
  2218. void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
  2219. {
  2220. if (AR_DEVID_7010(ah)) {
  2221. val = val ? 0 : 1;
  2222. REG_RMW(ah, AR7010_GPIO_OUT, ((val&1) << gpio),
  2223. AR_GPIO_BIT(gpio));
  2224. return;
  2225. }
  2226. if (AR_SREV_9271(ah))
  2227. val = ~val;
  2228. if ((1 << gpio) & AR_GPIO_OE_OUT_MASK)
  2229. REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
  2230. AR_GPIO_BIT(gpio));
  2231. else
  2232. gpio_set_value(gpio, val & 1);
  2233. }
  2234. EXPORT_SYMBOL(ath9k_hw_set_gpio);
  2235. void ath9k_hw_request_gpio(struct ath_hw *ah, u32 gpio, const char *label)
  2236. {
  2237. if (gpio >= ah->caps.num_gpio_pins)
  2238. return;
  2239. gpio_request_one(gpio, GPIOF_DIR_OUT | GPIOF_INIT_LOW, label);
  2240. }
  2241. EXPORT_SYMBOL(ath9k_hw_request_gpio);
  2242. void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
  2243. {
  2244. REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
  2245. }
  2246. EXPORT_SYMBOL(ath9k_hw_setantenna);
  2247. /*********************/
  2248. /* General Operation */
  2249. /*********************/
  2250. u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
  2251. {
  2252. u32 bits = REG_READ(ah, AR_RX_FILTER);
  2253. u32 phybits = REG_READ(ah, AR_PHY_ERR);
  2254. if (phybits & AR_PHY_ERR_RADAR)
  2255. bits |= ATH9K_RX_FILTER_PHYRADAR;
  2256. if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
  2257. bits |= ATH9K_RX_FILTER_PHYERR;
  2258. return bits;
  2259. }
  2260. EXPORT_SYMBOL(ath9k_hw_getrxfilter);
  2261. void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
  2262. {
  2263. u32 phybits;
  2264. ENABLE_REGWRITE_BUFFER(ah);
  2265. if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
  2266. bits |= ATH9K_RX_FILTER_CONTROL_WRAPPER;
  2267. REG_WRITE(ah, AR_RX_FILTER, bits);
  2268. phybits = 0;
  2269. if (bits & ATH9K_RX_FILTER_PHYRADAR)
  2270. phybits |= AR_PHY_ERR_RADAR;
  2271. if (bits & ATH9K_RX_FILTER_PHYERR)
  2272. phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
  2273. REG_WRITE(ah, AR_PHY_ERR, phybits);
  2274. if (phybits)
  2275. REG_SET_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
  2276. else
  2277. REG_CLR_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
  2278. REGWRITE_BUFFER_FLUSH(ah);
  2279. }
  2280. EXPORT_SYMBOL(ath9k_hw_setrxfilter);
  2281. bool ath9k_hw_phy_disable(struct ath_hw *ah)
  2282. {
  2283. if (ath9k_hw_mci_is_enabled(ah))
  2284. ar9003_mci_bt_gain_ctrl(ah);
  2285. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
  2286. return false;
  2287. ath9k_hw_init_pll(ah, NULL);
  2288. ah->htc_reset_init = true;
  2289. return true;
  2290. }
  2291. EXPORT_SYMBOL(ath9k_hw_phy_disable);
  2292. bool ath9k_hw_disable(struct ath_hw *ah)
  2293. {
  2294. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  2295. return false;
  2296. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
  2297. return false;
  2298. ath9k_hw_init_pll(ah, NULL);
  2299. return true;
  2300. }
  2301. EXPORT_SYMBOL(ath9k_hw_disable);
  2302. static int get_antenna_gain(struct ath_hw *ah, struct ath9k_channel *chan)
  2303. {
  2304. enum eeprom_param gain_param;
  2305. if (IS_CHAN_2GHZ(chan))
  2306. gain_param = EEP_ANTENNA_GAIN_2G;
  2307. else
  2308. gain_param = EEP_ANTENNA_GAIN_5G;
  2309. return ah->eep_ops->get_eeprom(ah, gain_param);
  2310. }
  2311. void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan,
  2312. bool test)
  2313. {
  2314. struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
  2315. struct ieee80211_channel *channel;
  2316. int chan_pwr, new_pwr, max_gain;
  2317. int ant_gain, ant_reduction = 0;
  2318. if (!chan)
  2319. return;
  2320. channel = chan->chan;
  2321. chan_pwr = min_t(int, channel->max_power * 2, MAX_RATE_POWER);
  2322. new_pwr = min_t(int, chan_pwr, reg->power_limit);
  2323. max_gain = chan_pwr - new_pwr + channel->max_antenna_gain * 2;
  2324. ant_gain = get_antenna_gain(ah, chan);
  2325. if (ant_gain > max_gain)
  2326. ant_reduction = ant_gain - max_gain;
  2327. ah->eep_ops->set_txpower(ah, chan,
  2328. ath9k_regd_get_ctl(reg, chan),
  2329. ant_reduction, new_pwr, test);
  2330. }
  2331. void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test)
  2332. {
  2333. struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
  2334. struct ath9k_channel *chan = ah->curchan;
  2335. struct ieee80211_channel *channel = chan->chan;
  2336. reg->power_limit = min_t(u32, limit, MAX_RATE_POWER);
  2337. if (test)
  2338. channel->max_power = MAX_RATE_POWER / 2;
  2339. ath9k_hw_apply_txpower(ah, chan, test);
  2340. if (test)
  2341. channel->max_power = DIV_ROUND_UP(reg->max_power_level, 2);
  2342. }
  2343. EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
  2344. void ath9k_hw_setopmode(struct ath_hw *ah)
  2345. {
  2346. ath9k_hw_set_operating_mode(ah, ah->opmode);
  2347. }
  2348. EXPORT_SYMBOL(ath9k_hw_setopmode);
  2349. void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
  2350. {
  2351. REG_WRITE(ah, AR_MCAST_FIL0, filter0);
  2352. REG_WRITE(ah, AR_MCAST_FIL1, filter1);
  2353. }
  2354. EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
  2355. void ath9k_hw_write_associd(struct ath_hw *ah)
  2356. {
  2357. struct ath_common *common = ath9k_hw_common(ah);
  2358. REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
  2359. REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
  2360. ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
  2361. }
  2362. EXPORT_SYMBOL(ath9k_hw_write_associd);
  2363. #define ATH9K_MAX_TSF_READ 10
  2364. u64 ath9k_hw_gettsf64(struct ath_hw *ah)
  2365. {
  2366. u32 tsf_lower, tsf_upper1, tsf_upper2;
  2367. int i;
  2368. tsf_upper1 = REG_READ(ah, AR_TSF_U32);
  2369. for (i = 0; i < ATH9K_MAX_TSF_READ; i++) {
  2370. tsf_lower = REG_READ(ah, AR_TSF_L32);
  2371. tsf_upper2 = REG_READ(ah, AR_TSF_U32);
  2372. if (tsf_upper2 == tsf_upper1)
  2373. break;
  2374. tsf_upper1 = tsf_upper2;
  2375. }
  2376. WARN_ON( i == ATH9K_MAX_TSF_READ );
  2377. return (((u64)tsf_upper1 << 32) | tsf_lower);
  2378. }
  2379. EXPORT_SYMBOL(ath9k_hw_gettsf64);
  2380. void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
  2381. {
  2382. REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
  2383. REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
  2384. }
  2385. EXPORT_SYMBOL(ath9k_hw_settsf64);
  2386. void ath9k_hw_reset_tsf(struct ath_hw *ah)
  2387. {
  2388. if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
  2389. AH_TSF_WRITE_TIMEOUT))
  2390. ath_dbg(ath9k_hw_common(ah), RESET,
  2391. "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
  2392. REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
  2393. }
  2394. EXPORT_SYMBOL(ath9k_hw_reset_tsf);
  2395. void ath9k_hw_set_tsfadjust(struct ath_hw *ah, bool set)
  2396. {
  2397. if (set)
  2398. ah->misc_mode |= AR_PCU_TX_ADD_TSF;
  2399. else
  2400. ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
  2401. }
  2402. EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
  2403. void ath9k_hw_set11nmac2040(struct ath_hw *ah, struct ath9k_channel *chan)
  2404. {
  2405. u32 macmode;
  2406. if (IS_CHAN_HT40(chan) && !ah->config.cwm_ignore_extcca)
  2407. macmode = AR_2040_JOINED_RX_CLEAR;
  2408. else
  2409. macmode = 0;
  2410. REG_WRITE(ah, AR_2040_MODE, macmode);
  2411. }
  2412. /* HW Generic timers configuration */
  2413. static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
  2414. {
  2415. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2416. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2417. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2418. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2419. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2420. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2421. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2422. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2423. {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
  2424. {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
  2425. AR_NDP2_TIMER_MODE, 0x0002},
  2426. {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
  2427. AR_NDP2_TIMER_MODE, 0x0004},
  2428. {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
  2429. AR_NDP2_TIMER_MODE, 0x0008},
  2430. {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
  2431. AR_NDP2_TIMER_MODE, 0x0010},
  2432. {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
  2433. AR_NDP2_TIMER_MODE, 0x0020},
  2434. {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
  2435. AR_NDP2_TIMER_MODE, 0x0040},
  2436. {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
  2437. AR_NDP2_TIMER_MODE, 0x0080}
  2438. };
  2439. /* HW generic timer primitives */
  2440. u32 ath9k_hw_gettsf32(struct ath_hw *ah)
  2441. {
  2442. return REG_READ(ah, AR_TSF_L32);
  2443. }
  2444. EXPORT_SYMBOL(ath9k_hw_gettsf32);
  2445. void ath9k_hw_gen_timer_start_tsf2(struct ath_hw *ah)
  2446. {
  2447. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  2448. if (timer_table->tsf2_enabled) {
  2449. REG_SET_BIT(ah, AR_DIRECT_CONNECT, AR_DC_AP_STA_EN);
  2450. REG_SET_BIT(ah, AR_RESET_TSF, AR_RESET_TSF2_ONCE);
  2451. }
  2452. }
  2453. struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
  2454. void (*trigger)(void *),
  2455. void (*overflow)(void *),
  2456. void *arg,
  2457. u8 timer_index)
  2458. {
  2459. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  2460. struct ath_gen_timer *timer;
  2461. if ((timer_index < AR_FIRST_NDP_TIMER) ||
  2462. (timer_index >= ATH_MAX_GEN_TIMER))
  2463. return NULL;
  2464. if ((timer_index > AR_FIRST_NDP_TIMER) &&
  2465. !AR_SREV_9300_20_OR_LATER(ah))
  2466. return NULL;
  2467. timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
  2468. if (timer == NULL)
  2469. return NULL;
  2470. /* allocate a hardware generic timer slot */
  2471. timer_table->timers[timer_index] = timer;
  2472. timer->index = timer_index;
  2473. timer->trigger = trigger;
  2474. timer->overflow = overflow;
  2475. timer->arg = arg;
  2476. if ((timer_index > AR_FIRST_NDP_TIMER) && !timer_table->tsf2_enabled) {
  2477. timer_table->tsf2_enabled = true;
  2478. ath9k_hw_gen_timer_start_tsf2(ah);
  2479. }
  2480. return timer;
  2481. }
  2482. EXPORT_SYMBOL(ath_gen_timer_alloc);
  2483. void ath9k_hw_gen_timer_start(struct ath_hw *ah,
  2484. struct ath_gen_timer *timer,
  2485. u32 timer_next,
  2486. u32 timer_period)
  2487. {
  2488. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  2489. u32 mask = 0;
  2490. timer_table->timer_mask |= BIT(timer->index);
  2491. /*
  2492. * Program generic timer registers
  2493. */
  2494. REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
  2495. timer_next);
  2496. REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
  2497. timer_period);
  2498. REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
  2499. gen_tmr_configuration[timer->index].mode_mask);
  2500. if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
  2501. /*
  2502. * Starting from AR9462, each generic timer can select which tsf
  2503. * to use. But we still follow the old rule, 0 - 7 use tsf and
  2504. * 8 - 15 use tsf2.
  2505. */
  2506. if ((timer->index < AR_GEN_TIMER_BANK_1_LEN))
  2507. REG_CLR_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
  2508. (1 << timer->index));
  2509. else
  2510. REG_SET_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
  2511. (1 << timer->index));
  2512. }
  2513. if (timer->trigger)
  2514. mask |= SM(AR_GENTMR_BIT(timer->index),
  2515. AR_IMR_S5_GENTIMER_TRIG);
  2516. if (timer->overflow)
  2517. mask |= SM(AR_GENTMR_BIT(timer->index),
  2518. AR_IMR_S5_GENTIMER_THRESH);
  2519. REG_SET_BIT(ah, AR_IMR_S5, mask);
  2520. if ((ah->imask & ATH9K_INT_GENTIMER) == 0) {
  2521. ah->imask |= ATH9K_INT_GENTIMER;
  2522. ath9k_hw_set_interrupts(ah);
  2523. }
  2524. }
  2525. EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
  2526. void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
  2527. {
  2528. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  2529. /* Clear generic timer enable bits. */
  2530. REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
  2531. gen_tmr_configuration[timer->index].mode_mask);
  2532. if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
  2533. /*
  2534. * Need to switch back to TSF if it was using TSF2.
  2535. */
  2536. if ((timer->index >= AR_GEN_TIMER_BANK_1_LEN)) {
  2537. REG_CLR_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
  2538. (1 << timer->index));
  2539. }
  2540. }
  2541. /* Disable both trigger and thresh interrupt masks */
  2542. REG_CLR_BIT(ah, AR_IMR_S5,
  2543. (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
  2544. SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
  2545. timer_table->timer_mask &= ~BIT(timer->index);
  2546. if (timer_table->timer_mask == 0) {
  2547. ah->imask &= ~ATH9K_INT_GENTIMER;
  2548. ath9k_hw_set_interrupts(ah);
  2549. }
  2550. }
  2551. EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
  2552. void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
  2553. {
  2554. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  2555. /* free the hardware generic timer slot */
  2556. timer_table->timers[timer->index] = NULL;
  2557. kfree(timer);
  2558. }
  2559. EXPORT_SYMBOL(ath_gen_timer_free);
  2560. /*
  2561. * Generic Timer Interrupts handling
  2562. */
  2563. void ath_gen_timer_isr(struct ath_hw *ah)
  2564. {
  2565. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  2566. struct ath_gen_timer *timer;
  2567. unsigned long trigger_mask, thresh_mask;
  2568. unsigned int index;
  2569. /* get hardware generic timer interrupt status */
  2570. trigger_mask = ah->intr_gen_timer_trigger;
  2571. thresh_mask = ah->intr_gen_timer_thresh;
  2572. trigger_mask &= timer_table->timer_mask;
  2573. thresh_mask &= timer_table->timer_mask;
  2574. for_each_set_bit(index, &thresh_mask, ARRAY_SIZE(timer_table->timers)) {
  2575. timer = timer_table->timers[index];
  2576. if (!timer)
  2577. continue;
  2578. if (!timer->overflow)
  2579. continue;
  2580. trigger_mask &= ~BIT(index);
  2581. timer->overflow(timer->arg);
  2582. }
  2583. for_each_set_bit(index, &trigger_mask, ARRAY_SIZE(timer_table->timers)) {
  2584. timer = timer_table->timers[index];
  2585. if (!timer)
  2586. continue;
  2587. if (!timer->trigger)
  2588. continue;
  2589. timer->trigger(timer->arg);
  2590. }
  2591. }
  2592. EXPORT_SYMBOL(ath_gen_timer_isr);
  2593. /********/
  2594. /* HTC */
  2595. /********/
  2596. static struct {
  2597. u32 version;
  2598. const char * name;
  2599. } ath_mac_bb_names[] = {
  2600. /* Devices with external radios */
  2601. { AR_SREV_VERSION_5416_PCI, "5416" },
  2602. { AR_SREV_VERSION_5416_PCIE, "5418" },
  2603. { AR_SREV_VERSION_9100, "9100" },
  2604. { AR_SREV_VERSION_9160, "9160" },
  2605. /* Single-chip solutions */
  2606. { AR_SREV_VERSION_9280, "9280" },
  2607. { AR_SREV_VERSION_9285, "9285" },
  2608. { AR_SREV_VERSION_9287, "9287" },
  2609. { AR_SREV_VERSION_9271, "9271" },
  2610. { AR_SREV_VERSION_9300, "9300" },
  2611. { AR_SREV_VERSION_9330, "9330" },
  2612. { AR_SREV_VERSION_9340, "9340" },
  2613. { AR_SREV_VERSION_9485, "9485" },
  2614. { AR_SREV_VERSION_9462, "9462" },
  2615. { AR_SREV_VERSION_9550, "9550" },
  2616. { AR_SREV_VERSION_9565, "9565" },
  2617. { AR_SREV_VERSION_9531, "9531" },
  2618. };
  2619. /* For devices with external radios */
  2620. static struct {
  2621. u16 version;
  2622. const char * name;
  2623. } ath_rf_names[] = {
  2624. { 0, "5133" },
  2625. { AR_RAD5133_SREV_MAJOR, "5133" },
  2626. { AR_RAD5122_SREV_MAJOR, "5122" },
  2627. { AR_RAD2133_SREV_MAJOR, "2133" },
  2628. { AR_RAD2122_SREV_MAJOR, "2122" }
  2629. };
  2630. /*
  2631. * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
  2632. */
  2633. static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
  2634. {
  2635. int i;
  2636. for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
  2637. if (ath_mac_bb_names[i].version == mac_bb_version) {
  2638. return ath_mac_bb_names[i].name;
  2639. }
  2640. }
  2641. return "????";
  2642. }
  2643. /*
  2644. * Return the RF name. "????" is returned if the RF is unknown.
  2645. * Used for devices with external radios.
  2646. */
  2647. static const char *ath9k_hw_rf_name(u16 rf_version)
  2648. {
  2649. int i;
  2650. for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
  2651. if (ath_rf_names[i].version == rf_version) {
  2652. return ath_rf_names[i].name;
  2653. }
  2654. }
  2655. return "????";
  2656. }
  2657. void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
  2658. {
  2659. int used;
  2660. /* chipsets >= AR9280 are single-chip */
  2661. if (AR_SREV_9280_20_OR_LATER(ah)) {
  2662. used = scnprintf(hw_name, len,
  2663. "Atheros AR%s Rev:%x",
  2664. ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
  2665. ah->hw_version.macRev);
  2666. }
  2667. else {
  2668. used = scnprintf(hw_name, len,
  2669. "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
  2670. ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
  2671. ah->hw_version.macRev,
  2672. ath9k_hw_rf_name((ah->hw_version.analog5GhzRev
  2673. & AR_RADIO_SREV_MAJOR)),
  2674. ah->hw_version.phyRev);
  2675. }
  2676. hw_name[used] = '\0';
  2677. }
  2678. EXPORT_SYMBOL(ath9k_hw_name);