hw.c 70 KB

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