hw.c 79 KB

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