hw.c 72 KB

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