hw.c 78 KB

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