hw.c 73 KB

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