hw.c 74 KB

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