hw.c 71 KB

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