hw.c 74 KB

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