hw.c 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589
  1. /*
  2. * Copyright (c) 2008-2009 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/io.h>
  17. #include <asm/unaligned.h>
  18. #include "hw.h"
  19. #include "hw-ops.h"
  20. #include "rc.h"
  21. #include "ar5008_initvals.h"
  22. #include "ar9001_initvals.h"
  23. #include "ar9002_initvals.h"
  24. #define ATH9K_CLOCK_RATE_CCK 22
  25. #define ATH9K_CLOCK_RATE_5GHZ_OFDM 40
  26. #define ATH9K_CLOCK_RATE_2GHZ_OFDM 44
  27. static void ar9002_hw_attach_ops(struct ath_hw *ah);
  28. static void ar9003_hw_attach_ops(struct ath_hw *ah);
  29. static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
  30. MODULE_AUTHOR("Atheros Communications");
  31. MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
  32. MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
  33. MODULE_LICENSE("Dual BSD/GPL");
  34. static int __init ath9k_init(void)
  35. {
  36. return 0;
  37. }
  38. module_init(ath9k_init);
  39. static void __exit ath9k_exit(void)
  40. {
  41. return;
  42. }
  43. module_exit(ath9k_exit);
  44. /* Private hardware callbacks */
  45. static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
  46. {
  47. ath9k_hw_private_ops(ah)->init_cal_settings(ah);
  48. }
  49. static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
  50. {
  51. ath9k_hw_private_ops(ah)->init_mode_regs(ah);
  52. }
  53. static bool ath9k_hw_macversion_supported(struct ath_hw *ah)
  54. {
  55. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  56. return priv_ops->macversion_supported(ah->hw_version.macVersion);
  57. }
  58. static u32 ath9k_hw_compute_pll_control(struct ath_hw *ah,
  59. struct ath9k_channel *chan)
  60. {
  61. return ath9k_hw_private_ops(ah)->compute_pll_control(ah, chan);
  62. }
  63. /********************/
  64. /* Helper Functions */
  65. /********************/
  66. static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs)
  67. {
  68. struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
  69. if (!ah->curchan) /* should really check for CCK instead */
  70. return usecs *ATH9K_CLOCK_RATE_CCK;
  71. if (conf->channel->band == IEEE80211_BAND_2GHZ)
  72. return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
  73. return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM;
  74. }
  75. static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
  76. {
  77. struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
  78. if (conf_is_ht40(conf))
  79. return ath9k_hw_mac_clks(ah, usecs) * 2;
  80. else
  81. return ath9k_hw_mac_clks(ah, usecs);
  82. }
  83. bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
  84. {
  85. int i;
  86. BUG_ON(timeout < AH_TIME_QUANTUM);
  87. for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
  88. if ((REG_READ(ah, reg) & mask) == val)
  89. return true;
  90. udelay(AH_TIME_QUANTUM);
  91. }
  92. ath_print(ath9k_hw_common(ah), ATH_DBG_ANY,
  93. "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
  94. timeout, reg, REG_READ(ah, reg), mask, val);
  95. return false;
  96. }
  97. EXPORT_SYMBOL(ath9k_hw_wait);
  98. u32 ath9k_hw_reverse_bits(u32 val, u32 n)
  99. {
  100. u32 retval;
  101. int i;
  102. for (i = 0, retval = 0; i < n; i++) {
  103. retval = (retval << 1) | (val & 1);
  104. val >>= 1;
  105. }
  106. return retval;
  107. }
  108. bool ath9k_get_channel_edges(struct ath_hw *ah,
  109. u16 flags, u16 *low,
  110. u16 *high)
  111. {
  112. struct ath9k_hw_capabilities *pCap = &ah->caps;
  113. if (flags & CHANNEL_5GHZ) {
  114. *low = pCap->low_5ghz_chan;
  115. *high = pCap->high_5ghz_chan;
  116. return true;
  117. }
  118. if ((flags & CHANNEL_2GHZ)) {
  119. *low = pCap->low_2ghz_chan;
  120. *high = pCap->high_2ghz_chan;
  121. return true;
  122. }
  123. return false;
  124. }
  125. u16 ath9k_hw_computetxtime(struct ath_hw *ah,
  126. u8 phy, int kbps,
  127. u32 frameLen, u16 rateix,
  128. bool shortPreamble)
  129. {
  130. u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
  131. if (kbps == 0)
  132. return 0;
  133. switch (phy) {
  134. case WLAN_RC_PHY_CCK:
  135. phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
  136. if (shortPreamble)
  137. phyTime >>= 1;
  138. numBits = frameLen << 3;
  139. txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
  140. break;
  141. case WLAN_RC_PHY_OFDM:
  142. if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
  143. bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
  144. numBits = OFDM_PLCP_BITS + (frameLen << 3);
  145. numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
  146. txTime = OFDM_SIFS_TIME_QUARTER
  147. + OFDM_PREAMBLE_TIME_QUARTER
  148. + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
  149. } else if (ah->curchan &&
  150. IS_CHAN_HALF_RATE(ah->curchan)) {
  151. bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
  152. numBits = OFDM_PLCP_BITS + (frameLen << 3);
  153. numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
  154. txTime = OFDM_SIFS_TIME_HALF +
  155. OFDM_PREAMBLE_TIME_HALF
  156. + (numSymbols * OFDM_SYMBOL_TIME_HALF);
  157. } else {
  158. bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
  159. numBits = OFDM_PLCP_BITS + (frameLen << 3);
  160. numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
  161. txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
  162. + (numSymbols * OFDM_SYMBOL_TIME);
  163. }
  164. break;
  165. default:
  166. ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
  167. "Unknown phy %u (rate ix %u)\n", phy, rateix);
  168. txTime = 0;
  169. break;
  170. }
  171. return txTime;
  172. }
  173. EXPORT_SYMBOL(ath9k_hw_computetxtime);
  174. void ath9k_hw_get_channel_centers(struct ath_hw *ah,
  175. struct ath9k_channel *chan,
  176. struct chan_centers *centers)
  177. {
  178. int8_t extoff;
  179. if (!IS_CHAN_HT40(chan)) {
  180. centers->ctl_center = centers->ext_center =
  181. centers->synth_center = chan->channel;
  182. return;
  183. }
  184. if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
  185. (chan->chanmode == CHANNEL_G_HT40PLUS)) {
  186. centers->synth_center =
  187. chan->channel + HT40_CHANNEL_CENTER_SHIFT;
  188. extoff = 1;
  189. } else {
  190. centers->synth_center =
  191. chan->channel - HT40_CHANNEL_CENTER_SHIFT;
  192. extoff = -1;
  193. }
  194. centers->ctl_center =
  195. centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
  196. /* 25 MHz spacing is supported by hw but not on upper layers */
  197. centers->ext_center =
  198. centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
  199. }
  200. /******************/
  201. /* Chip Revisions */
  202. /******************/
  203. static void ath9k_hw_read_revisions(struct ath_hw *ah)
  204. {
  205. u32 val;
  206. val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
  207. if (val == 0xFF) {
  208. val = REG_READ(ah, AR_SREV);
  209. ah->hw_version.macVersion =
  210. (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
  211. ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
  212. ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
  213. } else {
  214. if (!AR_SREV_9100(ah))
  215. ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
  216. ah->hw_version.macRev = val & AR_SREV_REVISION;
  217. if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
  218. ah->is_pciexpress = true;
  219. }
  220. }
  221. static int ath9k_hw_get_radiorev(struct ath_hw *ah)
  222. {
  223. u32 val;
  224. int i;
  225. REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
  226. for (i = 0; i < 8; i++)
  227. REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
  228. val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
  229. val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
  230. return ath9k_hw_reverse_bits(val, 8);
  231. }
  232. /************************************/
  233. /* HW Attach, Detach, Init Routines */
  234. /************************************/
  235. static void ath9k_hw_disablepcie(struct ath_hw *ah)
  236. {
  237. if (AR_SREV_9100(ah))
  238. return;
  239. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
  240. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  241. REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
  242. REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
  243. REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
  244. REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
  245. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  246. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  247. REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
  248. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  249. }
  250. /* This should work for all families including legacy */
  251. static bool ath9k_hw_chip_test(struct ath_hw *ah)
  252. {
  253. struct ath_common *common = ath9k_hw_common(ah);
  254. u32 regAddr[2] = { AR_STA_ID0 };
  255. u32 regHold[2];
  256. u32 patternData[4] = { 0x55555555,
  257. 0xaaaaaaaa,
  258. 0x66666666,
  259. 0x99999999 };
  260. int i, j, loop_max;
  261. if (!AR_SREV_9300_20_OR_LATER(ah)) {
  262. loop_max = 2;
  263. regAddr[1] = AR_PHY_BASE + (8 << 2);
  264. } else
  265. loop_max = 1;
  266. for (i = 0; i < loop_max; i++) {
  267. u32 addr = regAddr[i];
  268. u32 wrData, rdData;
  269. regHold[i] = REG_READ(ah, addr);
  270. for (j = 0; j < 0x100; j++) {
  271. wrData = (j << 16) | j;
  272. REG_WRITE(ah, addr, wrData);
  273. rdData = REG_READ(ah, addr);
  274. if (rdData != wrData) {
  275. ath_print(common, ATH_DBG_FATAL,
  276. "address test failed "
  277. "addr: 0x%08x - wr:0x%08x != "
  278. "rd:0x%08x\n",
  279. addr, wrData, rdData);
  280. return false;
  281. }
  282. }
  283. for (j = 0; j < 4; j++) {
  284. wrData = patternData[j];
  285. REG_WRITE(ah, addr, wrData);
  286. rdData = REG_READ(ah, addr);
  287. if (wrData != rdData) {
  288. ath_print(common, ATH_DBG_FATAL,
  289. "address test failed "
  290. "addr: 0x%08x - wr:0x%08x != "
  291. "rd:0x%08x\n",
  292. addr, wrData, rdData);
  293. return false;
  294. }
  295. }
  296. REG_WRITE(ah, regAddr[i], regHold[i]);
  297. }
  298. udelay(100);
  299. return true;
  300. }
  301. static void ath9k_hw_init_config(struct ath_hw *ah)
  302. {
  303. int i;
  304. ah->config.dma_beacon_response_time = 2;
  305. ah->config.sw_beacon_response_time = 10;
  306. ah->config.additional_swba_backoff = 0;
  307. ah->config.ack_6mb = 0x0;
  308. ah->config.cwm_ignore_extcca = 0;
  309. ah->config.pcie_powersave_enable = 0;
  310. ah->config.pcie_clock_req = 0;
  311. ah->config.pcie_waen = 0;
  312. ah->config.analog_shiftreg = 1;
  313. ah->config.ofdm_trig_low = 200;
  314. ah->config.ofdm_trig_high = 500;
  315. ah->config.cck_trig_high = 200;
  316. ah->config.cck_trig_low = 100;
  317. /*
  318. * For now ANI is disabled for AR9003, it is still
  319. * being tested.
  320. */
  321. if (!AR_SREV_9300_20_OR_LATER(ah))
  322. ah->config.enable_ani = 1;
  323. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  324. ah->config.spurchans[i][0] = AR_NO_SPUR;
  325. ah->config.spurchans[i][1] = AR_NO_SPUR;
  326. }
  327. if (ah->hw_version.devid != AR2427_DEVID_PCIE)
  328. ah->config.ht_enable = 1;
  329. else
  330. ah->config.ht_enable = 0;
  331. ah->config.rx_intr_mitigation = true;
  332. /*
  333. * We need this for PCI devices only (Cardbus, PCI, miniPCI)
  334. * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
  335. * This means we use it for all AR5416 devices, and the few
  336. * minor PCI AR9280 devices out there.
  337. *
  338. * Serialization is required because these devices do not handle
  339. * well the case of two concurrent reads/writes due to the latency
  340. * involved. During one read/write another read/write can be issued
  341. * on another CPU while the previous read/write may still be working
  342. * on our hardware, if we hit this case the hardware poops in a loop.
  343. * We prevent this by serializing reads and writes.
  344. *
  345. * This issue is not present on PCI-Express devices or pre-AR5416
  346. * devices (legacy, 802.11abg).
  347. */
  348. if (num_possible_cpus() > 1)
  349. ah->config.serialize_regmode = SER_REG_MODE_AUTO;
  350. }
  351. static void ath9k_hw_init_defaults(struct ath_hw *ah)
  352. {
  353. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  354. regulatory->country_code = CTRY_DEFAULT;
  355. regulatory->power_limit = MAX_RATE_POWER;
  356. regulatory->tp_scale = ATH9K_TP_SCALE_MAX;
  357. ah->hw_version.magic = AR5416_MAGIC;
  358. ah->hw_version.subvendorid = 0;
  359. ah->ah_flags = 0;
  360. if (!AR_SREV_9100(ah))
  361. ah->ah_flags = AH_USE_EEPROM;
  362. ah->atim_window = 0;
  363. ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
  364. ah->beacon_interval = 100;
  365. ah->enable_32kHz_clock = DONT_USE_32KHZ;
  366. ah->slottime = (u32) -1;
  367. ah->globaltxtimeout = (u32) -1;
  368. ah->power_mode = ATH9K_PM_UNDEFINED;
  369. }
  370. static int ath9k_hw_rf_claim(struct ath_hw *ah)
  371. {
  372. u32 val;
  373. REG_WRITE(ah, AR_PHY(0), 0x00000007);
  374. val = ath9k_hw_get_radiorev(ah);
  375. switch (val & AR_RADIO_SREV_MAJOR) {
  376. case 0:
  377. val = AR_RAD5133_SREV_MAJOR;
  378. break;
  379. case AR_RAD5133_SREV_MAJOR:
  380. case AR_RAD5122_SREV_MAJOR:
  381. case AR_RAD2133_SREV_MAJOR:
  382. case AR_RAD2122_SREV_MAJOR:
  383. break;
  384. default:
  385. ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
  386. "Radio Chip Rev 0x%02X not supported\n",
  387. val & AR_RADIO_SREV_MAJOR);
  388. return -EOPNOTSUPP;
  389. }
  390. ah->hw_version.analog5GhzRev = val;
  391. return 0;
  392. }
  393. static int ath9k_hw_init_macaddr(struct ath_hw *ah)
  394. {
  395. struct ath_common *common = ath9k_hw_common(ah);
  396. u32 sum;
  397. int i;
  398. u16 eeval;
  399. sum = 0;
  400. for (i = 0; i < 3; i++) {
  401. eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
  402. sum += eeval;
  403. common->macaddr[2 * i] = eeval >> 8;
  404. common->macaddr[2 * i + 1] = eeval & 0xff;
  405. }
  406. if (sum == 0 || sum == 0xffff * 3)
  407. return -EADDRNOTAVAIL;
  408. return 0;
  409. }
  410. static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
  411. {
  412. u32 rxgain_type;
  413. if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
  414. rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
  415. if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
  416. INIT_INI_ARRAY(&ah->iniModesRxGain,
  417. ar9280Modes_backoff_13db_rxgain_9280_2,
  418. ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
  419. else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
  420. INIT_INI_ARRAY(&ah->iniModesRxGain,
  421. ar9280Modes_backoff_23db_rxgain_9280_2,
  422. ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
  423. else
  424. INIT_INI_ARRAY(&ah->iniModesRxGain,
  425. ar9280Modes_original_rxgain_9280_2,
  426. ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
  427. } else {
  428. INIT_INI_ARRAY(&ah->iniModesRxGain,
  429. ar9280Modes_original_rxgain_9280_2,
  430. ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
  431. }
  432. }
  433. static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
  434. {
  435. u32 txgain_type;
  436. if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
  437. txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
  438. if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
  439. INIT_INI_ARRAY(&ah->iniModesTxGain,
  440. ar9280Modes_high_power_tx_gain_9280_2,
  441. ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
  442. else
  443. INIT_INI_ARRAY(&ah->iniModesTxGain,
  444. ar9280Modes_original_tx_gain_9280_2,
  445. ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
  446. } else {
  447. INIT_INI_ARRAY(&ah->iniModesTxGain,
  448. ar9280Modes_original_tx_gain_9280_2,
  449. ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
  450. }
  451. }
  452. static int ath9k_hw_post_init(struct ath_hw *ah)
  453. {
  454. int ecode;
  455. if (!AR_SREV_9271(ah)) {
  456. if (!ath9k_hw_chip_test(ah))
  457. return -ENODEV;
  458. }
  459. ecode = ath9k_hw_rf_claim(ah);
  460. if (ecode != 0)
  461. return ecode;
  462. ecode = ath9k_hw_eeprom_init(ah);
  463. if (ecode != 0)
  464. return ecode;
  465. ath_print(ath9k_hw_common(ah), ATH_DBG_CONFIG,
  466. "Eeprom VER: %d, REV: %d\n",
  467. ah->eep_ops->get_eeprom_ver(ah),
  468. ah->eep_ops->get_eeprom_rev(ah));
  469. ecode = ath9k_hw_rf_alloc_ext_banks(ah);
  470. if (ecode) {
  471. ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
  472. "Failed allocating banks for "
  473. "external radio\n");
  474. return ecode;
  475. }
  476. if (!AR_SREV_9100(ah)) {
  477. ath9k_hw_ani_setup(ah);
  478. ath9k_hw_ani_init(ah);
  479. }
  480. return 0;
  481. }
  482. static bool ar9002_hw_macversion_supported(u32 macversion)
  483. {
  484. switch (macversion) {
  485. case AR_SREV_VERSION_5416_PCI:
  486. case AR_SREV_VERSION_5416_PCIE:
  487. case AR_SREV_VERSION_9160:
  488. case AR_SREV_VERSION_9100:
  489. case AR_SREV_VERSION_9280:
  490. case AR_SREV_VERSION_9285:
  491. case AR_SREV_VERSION_9287:
  492. case AR_SREV_VERSION_9271:
  493. return true;
  494. default:
  495. break;
  496. }
  497. return false;
  498. }
  499. static bool ar9003_hw_macversion_supported(u32 macversion)
  500. {
  501. switch (macversion) {
  502. case AR_SREV_VERSION_9300:
  503. return true;
  504. default:
  505. break;
  506. }
  507. return false;
  508. }
  509. static void ar9002_hw_init_cal_settings(struct ath_hw *ah)
  510. {
  511. if (AR_SREV_9160_10_OR_LATER(ah)) {
  512. if (AR_SREV_9280_10_OR_LATER(ah)) {
  513. ah->iq_caldata.calData = &iq_cal_single_sample;
  514. ah->adcgain_caldata.calData =
  515. &adc_gain_cal_single_sample;
  516. ah->adcdc_caldata.calData =
  517. &adc_dc_cal_single_sample;
  518. ah->adcdc_calinitdata.calData =
  519. &adc_init_dc_cal;
  520. } else {
  521. ah->iq_caldata.calData = &iq_cal_multi_sample;
  522. ah->adcgain_caldata.calData =
  523. &adc_gain_cal_multi_sample;
  524. ah->adcdc_caldata.calData =
  525. &adc_dc_cal_multi_sample;
  526. ah->adcdc_calinitdata.calData =
  527. &adc_init_dc_cal;
  528. }
  529. ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
  530. }
  531. }
  532. static void ar9002_hw_init_mode_regs(struct ath_hw *ah)
  533. {
  534. if (AR_SREV_9271(ah)) {
  535. INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271,
  536. ARRAY_SIZE(ar9271Modes_9271), 6);
  537. INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271,
  538. ARRAY_SIZE(ar9271Common_9271), 2);
  539. INIT_INI_ARRAY(&ah->iniCommon_normal_cck_fir_coeff_9271,
  540. ar9271Common_normal_cck_fir_coeff_9271,
  541. ARRAY_SIZE(ar9271Common_normal_cck_fir_coeff_9271), 2);
  542. INIT_INI_ARRAY(&ah->iniCommon_japan_2484_cck_fir_coeff_9271,
  543. ar9271Common_japan_2484_cck_fir_coeff_9271,
  544. ARRAY_SIZE(ar9271Common_japan_2484_cck_fir_coeff_9271), 2);
  545. INIT_INI_ARRAY(&ah->iniModes_9271_1_0_only,
  546. ar9271Modes_9271_1_0_only,
  547. ARRAY_SIZE(ar9271Modes_9271_1_0_only), 6);
  548. INIT_INI_ARRAY(&ah->iniModes_9271_ANI_reg, ar9271Modes_9271_ANI_reg,
  549. ARRAY_SIZE(ar9271Modes_9271_ANI_reg), 6);
  550. INIT_INI_ARRAY(&ah->iniModes_high_power_tx_gain_9271,
  551. ar9271Modes_high_power_tx_gain_9271,
  552. ARRAY_SIZE(ar9271Modes_high_power_tx_gain_9271), 6);
  553. INIT_INI_ARRAY(&ah->iniModes_normal_power_tx_gain_9271,
  554. ar9271Modes_normal_power_tx_gain_9271,
  555. ARRAY_SIZE(ar9271Modes_normal_power_tx_gain_9271), 6);
  556. return;
  557. }
  558. if (AR_SREV_9287_11_OR_LATER(ah)) {
  559. INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1,
  560. ARRAY_SIZE(ar9287Modes_9287_1_1), 6);
  561. INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1,
  562. ARRAY_SIZE(ar9287Common_9287_1_1), 2);
  563. if (ah->config.pcie_clock_req)
  564. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  565. ar9287PciePhy_clkreq_off_L1_9287_1_1,
  566. ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2);
  567. else
  568. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  569. ar9287PciePhy_clkreq_always_on_L1_9287_1_1,
  570. ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1),
  571. 2);
  572. } else if (AR_SREV_9287_10_OR_LATER(ah)) {
  573. INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0,
  574. ARRAY_SIZE(ar9287Modes_9287_1_0), 6);
  575. INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0,
  576. ARRAY_SIZE(ar9287Common_9287_1_0), 2);
  577. if (ah->config.pcie_clock_req)
  578. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  579. ar9287PciePhy_clkreq_off_L1_9287_1_0,
  580. ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2);
  581. else
  582. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  583. ar9287PciePhy_clkreq_always_on_L1_9287_1_0,
  584. ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0),
  585. 2);
  586. } else if (AR_SREV_9285_12_OR_LATER(ah)) {
  587. INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
  588. ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
  589. INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
  590. ARRAY_SIZE(ar9285Common_9285_1_2), 2);
  591. if (ah->config.pcie_clock_req) {
  592. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  593. ar9285PciePhy_clkreq_off_L1_9285_1_2,
  594. ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
  595. } else {
  596. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  597. ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
  598. ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
  599. 2);
  600. }
  601. } else if (AR_SREV_9285_10_OR_LATER(ah)) {
  602. INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
  603. ARRAY_SIZE(ar9285Modes_9285), 6);
  604. INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
  605. ARRAY_SIZE(ar9285Common_9285), 2);
  606. if (ah->config.pcie_clock_req) {
  607. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  608. ar9285PciePhy_clkreq_off_L1_9285,
  609. ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
  610. } else {
  611. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  612. ar9285PciePhy_clkreq_always_on_L1_9285,
  613. ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
  614. }
  615. } else if (AR_SREV_9280_20_OR_LATER(ah)) {
  616. INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
  617. ARRAY_SIZE(ar9280Modes_9280_2), 6);
  618. INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
  619. ARRAY_SIZE(ar9280Common_9280_2), 2);
  620. if (ah->config.pcie_clock_req) {
  621. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  622. ar9280PciePhy_clkreq_off_L1_9280,
  623. ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
  624. } else {
  625. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  626. ar9280PciePhy_clkreq_always_on_L1_9280,
  627. ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
  628. }
  629. INIT_INI_ARRAY(&ah->iniModesAdditional,
  630. ar9280Modes_fast_clock_9280_2,
  631. ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
  632. } else if (AR_SREV_9280_10_OR_LATER(ah)) {
  633. INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
  634. ARRAY_SIZE(ar9280Modes_9280), 6);
  635. INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
  636. ARRAY_SIZE(ar9280Common_9280), 2);
  637. } else if (AR_SREV_9160_10_OR_LATER(ah)) {
  638. INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
  639. ARRAY_SIZE(ar5416Modes_9160), 6);
  640. INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
  641. ARRAY_SIZE(ar5416Common_9160), 2);
  642. INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
  643. ARRAY_SIZE(ar5416Bank0_9160), 2);
  644. INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
  645. ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
  646. INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
  647. ARRAY_SIZE(ar5416Bank1_9160), 2);
  648. INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
  649. ARRAY_SIZE(ar5416Bank2_9160), 2);
  650. INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
  651. ARRAY_SIZE(ar5416Bank3_9160), 3);
  652. INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
  653. ARRAY_SIZE(ar5416Bank6_9160), 3);
  654. INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
  655. ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
  656. INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
  657. ARRAY_SIZE(ar5416Bank7_9160), 2);
  658. if (AR_SREV_9160_11(ah)) {
  659. INIT_INI_ARRAY(&ah->iniAddac,
  660. ar5416Addac_91601_1,
  661. ARRAY_SIZE(ar5416Addac_91601_1), 2);
  662. } else {
  663. INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
  664. ARRAY_SIZE(ar5416Addac_9160), 2);
  665. }
  666. } else if (AR_SREV_9100_OR_LATER(ah)) {
  667. INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
  668. ARRAY_SIZE(ar5416Modes_9100), 6);
  669. INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
  670. ARRAY_SIZE(ar5416Common_9100), 2);
  671. INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
  672. ARRAY_SIZE(ar5416Bank0_9100), 2);
  673. INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
  674. ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
  675. INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
  676. ARRAY_SIZE(ar5416Bank1_9100), 2);
  677. INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
  678. ARRAY_SIZE(ar5416Bank2_9100), 2);
  679. INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
  680. ARRAY_SIZE(ar5416Bank3_9100), 3);
  681. INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
  682. ARRAY_SIZE(ar5416Bank6_9100), 3);
  683. INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
  684. ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
  685. INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
  686. ARRAY_SIZE(ar5416Bank7_9100), 2);
  687. INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
  688. ARRAY_SIZE(ar5416Addac_9100), 2);
  689. } else {
  690. INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
  691. ARRAY_SIZE(ar5416Modes), 6);
  692. INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
  693. ARRAY_SIZE(ar5416Common), 2);
  694. INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
  695. ARRAY_SIZE(ar5416Bank0), 2);
  696. INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
  697. ARRAY_SIZE(ar5416BB_RfGain), 3);
  698. INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
  699. ARRAY_SIZE(ar5416Bank1), 2);
  700. INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
  701. ARRAY_SIZE(ar5416Bank2), 2);
  702. INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
  703. ARRAY_SIZE(ar5416Bank3), 3);
  704. INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
  705. ARRAY_SIZE(ar5416Bank6), 3);
  706. INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
  707. ARRAY_SIZE(ar5416Bank6TPC), 3);
  708. INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
  709. ARRAY_SIZE(ar5416Bank7), 2);
  710. INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
  711. ARRAY_SIZE(ar5416Addac), 2);
  712. }
  713. }
  714. static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
  715. {
  716. if (AR_SREV_9287_11_OR_LATER(ah))
  717. INIT_INI_ARRAY(&ah->iniModesRxGain,
  718. ar9287Modes_rx_gain_9287_1_1,
  719. ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
  720. else if (AR_SREV_9287_10(ah))
  721. INIT_INI_ARRAY(&ah->iniModesRxGain,
  722. ar9287Modes_rx_gain_9287_1_0,
  723. ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6);
  724. else if (AR_SREV_9280_20(ah))
  725. ath9k_hw_init_rxgain_ini(ah);
  726. if (AR_SREV_9287_11_OR_LATER(ah)) {
  727. INIT_INI_ARRAY(&ah->iniModesTxGain,
  728. ar9287Modes_tx_gain_9287_1_1,
  729. ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
  730. } else if (AR_SREV_9287_10(ah)) {
  731. INIT_INI_ARRAY(&ah->iniModesTxGain,
  732. ar9287Modes_tx_gain_9287_1_0,
  733. ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6);
  734. } else if (AR_SREV_9280_20(ah)) {
  735. ath9k_hw_init_txgain_ini(ah);
  736. } else if (AR_SREV_9285_12_OR_LATER(ah)) {
  737. u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
  738. /* txgain table */
  739. if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
  740. if (AR_SREV_9285E_20(ah)) {
  741. INIT_INI_ARRAY(&ah->iniModesTxGain,
  742. ar9285Modes_XE2_0_high_power,
  743. ARRAY_SIZE(
  744. ar9285Modes_XE2_0_high_power), 6);
  745. } else {
  746. INIT_INI_ARRAY(&ah->iniModesTxGain,
  747. ar9285Modes_high_power_tx_gain_9285_1_2,
  748. ARRAY_SIZE(
  749. ar9285Modes_high_power_tx_gain_9285_1_2), 6);
  750. }
  751. } else {
  752. if (AR_SREV_9285E_20(ah)) {
  753. INIT_INI_ARRAY(&ah->iniModesTxGain,
  754. ar9285Modes_XE2_0_normal_power,
  755. ARRAY_SIZE(
  756. ar9285Modes_XE2_0_normal_power), 6);
  757. } else {
  758. INIT_INI_ARRAY(&ah->iniModesTxGain,
  759. ar9285Modes_original_tx_gain_9285_1_2,
  760. ARRAY_SIZE(
  761. ar9285Modes_original_tx_gain_9285_1_2), 6);
  762. }
  763. }
  764. }
  765. }
  766. static void ath9k_hw_init_eeprom_fix(struct ath_hw *ah)
  767. {
  768. struct base_eep_header *pBase = &(ah->eeprom.def.baseEepHeader);
  769. struct ath_common *common = ath9k_hw_common(ah);
  770. ah->need_an_top2_fixup = (ah->hw_version.devid == AR9280_DEVID_PCI) &&
  771. (ah->eep_map != EEP_MAP_4KBITS) &&
  772. ((pBase->version & 0xff) > 0x0a) &&
  773. (pBase->pwdclkind == 0);
  774. if (ah->need_an_top2_fixup)
  775. ath_print(common, ATH_DBG_EEPROM,
  776. "needs fixup for AR_AN_TOP2 register\n");
  777. }
  778. static void ath9k_hw_attach_ops(struct ath_hw *ah)
  779. {
  780. if (AR_SREV_9300_20_OR_LATER(ah))
  781. ar9003_hw_attach_ops(ah);
  782. else
  783. ar9002_hw_attach_ops(ah);
  784. }
  785. /* Called for all hardware families */
  786. static int __ath9k_hw_init(struct ath_hw *ah)
  787. {
  788. struct ath_common *common = ath9k_hw_common(ah);
  789. int r = 0;
  790. if (ah->hw_version.devid == AR5416_AR9100_DEVID)
  791. ah->hw_version.macVersion = AR_SREV_VERSION_9100;
  792. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
  793. ath_print(common, ATH_DBG_FATAL,
  794. "Couldn't reset chip\n");
  795. return -EIO;
  796. }
  797. ath9k_hw_init_defaults(ah);
  798. ath9k_hw_init_config(ah);
  799. ath9k_hw_attach_ops(ah);
  800. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
  801. ath_print(common, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
  802. return -EIO;
  803. }
  804. if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
  805. if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
  806. (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
  807. ah->config.serialize_regmode =
  808. SER_REG_MODE_ON;
  809. } else {
  810. ah->config.serialize_regmode =
  811. SER_REG_MODE_OFF;
  812. }
  813. }
  814. ath_print(common, ATH_DBG_RESET, "serialize_regmode is %d\n",
  815. ah->config.serialize_regmode);
  816. if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
  817. ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
  818. else
  819. ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
  820. if (!ath9k_hw_macversion_supported(ah)) {
  821. ath_print(common, ATH_DBG_FATAL,
  822. "Mac Chip Rev 0x%02x.%x is not supported by "
  823. "this driver\n", ah->hw_version.macVersion,
  824. ah->hw_version.macRev);
  825. return -EOPNOTSUPP;
  826. }
  827. if (AR_SREV_9100(ah)) {
  828. ah->iq_caldata.calData = &iq_cal_multi_sample;
  829. ah->supp_cals = IQ_MISMATCH_CAL;
  830. ah->is_pciexpress = false;
  831. }
  832. if (AR_SREV_9271(ah))
  833. ah->is_pciexpress = false;
  834. ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
  835. ath9k_hw_init_cal_settings(ah);
  836. ah->ani_function = ATH9K_ANI_ALL;
  837. if (AR_SREV_9280_10_OR_LATER(ah) && !AR_SREV_9300_20_OR_LATER(ah))
  838. ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
  839. ath9k_hw_init_mode_regs(ah);
  840. if (ah->is_pciexpress)
  841. ath9k_hw_configpcipowersave(ah, 0, 0);
  842. else
  843. ath9k_hw_disablepcie(ah);
  844. /* Support for Japan ch.14 (2484) spread */
  845. if (AR_SREV_9287_11_OR_LATER(ah)) {
  846. INIT_INI_ARRAY(&ah->iniCckfirNormal,
  847. ar9287Common_normal_cck_fir_coeff_92871_1,
  848. ARRAY_SIZE(ar9287Common_normal_cck_fir_coeff_92871_1), 2);
  849. INIT_INI_ARRAY(&ah->iniCckfirJapan2484,
  850. ar9287Common_japan_2484_cck_fir_coeff_92871_1,
  851. ARRAY_SIZE(ar9287Common_japan_2484_cck_fir_coeff_92871_1), 2);
  852. }
  853. r = ath9k_hw_post_init(ah);
  854. if (r)
  855. return r;
  856. ath9k_hw_init_mode_gain_regs(ah);
  857. r = ath9k_hw_fill_cap_info(ah);
  858. if (r)
  859. return r;
  860. ath9k_hw_init_eeprom_fix(ah);
  861. r = ath9k_hw_init_macaddr(ah);
  862. if (r) {
  863. ath_print(common, ATH_DBG_FATAL,
  864. "Failed to initialize MAC address\n");
  865. return r;
  866. }
  867. if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
  868. ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
  869. else
  870. ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
  871. ath9k_init_nfcal_hist_buffer(ah);
  872. common->state = ATH_HW_INITIALIZED;
  873. return 0;
  874. }
  875. int ath9k_hw_init(struct ath_hw *ah)
  876. {
  877. int ret;
  878. struct ath_common *common = ath9k_hw_common(ah);
  879. /* These are all the AR5008/AR9001/AR9002 hardware family of chipsets */
  880. switch (ah->hw_version.devid) {
  881. case AR5416_DEVID_PCI:
  882. case AR5416_DEVID_PCIE:
  883. case AR5416_AR9100_DEVID:
  884. case AR9160_DEVID_PCI:
  885. case AR9280_DEVID_PCI:
  886. case AR9280_DEVID_PCIE:
  887. case AR9285_DEVID_PCIE:
  888. case AR9287_DEVID_PCI:
  889. case AR9287_DEVID_PCIE:
  890. case AR2427_DEVID_PCIE:
  891. case AR9300_DEVID_PCIE:
  892. break;
  893. default:
  894. if (common->bus_ops->ath_bus_type == ATH_USB)
  895. break;
  896. ath_print(common, ATH_DBG_FATAL,
  897. "Hardware device ID 0x%04x not supported\n",
  898. ah->hw_version.devid);
  899. return -EOPNOTSUPP;
  900. }
  901. ret = __ath9k_hw_init(ah);
  902. if (ret) {
  903. ath_print(common, ATH_DBG_FATAL,
  904. "Unable to initialize hardware; "
  905. "initialization status: %d\n", ret);
  906. return ret;
  907. }
  908. return 0;
  909. }
  910. EXPORT_SYMBOL(ath9k_hw_init);
  911. static void ath9k_hw_init_qos(struct ath_hw *ah)
  912. {
  913. REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
  914. REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
  915. REG_WRITE(ah, AR_QOS_NO_ACK,
  916. SM(2, AR_QOS_NO_ACK_TWO_BIT) |
  917. SM(5, AR_QOS_NO_ACK_BIT_OFF) |
  918. SM(0, AR_QOS_NO_ACK_BYTE_OFF));
  919. REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
  920. REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
  921. REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
  922. REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
  923. REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
  924. }
  925. static void ath9k_hw_init_pll(struct ath_hw *ah,
  926. struct ath9k_channel *chan)
  927. {
  928. u32 pll = ath9k_hw_compute_pll_control(ah, chan);
  929. REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
  930. /* Switch the core clock for ar9271 to 117Mhz */
  931. if (AR_SREV_9271(ah)) {
  932. udelay(500);
  933. REG_WRITE(ah, 0x50040, 0x304);
  934. }
  935. udelay(RTC_PLL_SETTLE_DELAY);
  936. REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
  937. }
  938. static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
  939. enum nl80211_iftype opmode)
  940. {
  941. u32 imr_reg = AR_IMR_TXERR |
  942. AR_IMR_TXURN |
  943. AR_IMR_RXERR |
  944. AR_IMR_RXORN |
  945. AR_IMR_BCNMISC;
  946. if (ah->config.rx_intr_mitigation)
  947. imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
  948. else
  949. imr_reg |= AR_IMR_RXOK;
  950. imr_reg |= AR_IMR_TXOK;
  951. if (opmode == NL80211_IFTYPE_AP)
  952. imr_reg |= AR_IMR_MIB;
  953. REG_WRITE(ah, AR_IMR, imr_reg);
  954. ah->imrs2_reg |= AR_IMR_S2_GTT;
  955. REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
  956. if (!AR_SREV_9100(ah)) {
  957. REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
  958. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
  959. REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
  960. }
  961. }
  962. static void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
  963. {
  964. u32 val = ath9k_hw_mac_to_clks(ah, us);
  965. val = min(val, (u32) 0xFFFF);
  966. REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
  967. }
  968. static void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
  969. {
  970. u32 val = ath9k_hw_mac_to_clks(ah, us);
  971. val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
  972. REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
  973. }
  974. static void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
  975. {
  976. u32 val = ath9k_hw_mac_to_clks(ah, us);
  977. val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
  978. REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
  979. }
  980. static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
  981. {
  982. if (tu > 0xFFFF) {
  983. ath_print(ath9k_hw_common(ah), ATH_DBG_XMIT,
  984. "bad global tx timeout %u\n", tu);
  985. ah->globaltxtimeout = (u32) -1;
  986. return false;
  987. } else {
  988. REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
  989. ah->globaltxtimeout = tu;
  990. return true;
  991. }
  992. }
  993. void ath9k_hw_init_global_settings(struct ath_hw *ah)
  994. {
  995. struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
  996. int acktimeout;
  997. int slottime;
  998. int sifstime;
  999. ath_print(ath9k_hw_common(ah), ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
  1000. ah->misc_mode);
  1001. if (ah->misc_mode != 0)
  1002. REG_WRITE(ah, AR_PCU_MISC,
  1003. REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
  1004. if (conf->channel && conf->channel->band == IEEE80211_BAND_5GHZ)
  1005. sifstime = 16;
  1006. else
  1007. sifstime = 10;
  1008. /* As defined by IEEE 802.11-2007 17.3.8.6 */
  1009. slottime = ah->slottime + 3 * ah->coverage_class;
  1010. acktimeout = slottime + sifstime;
  1011. /*
  1012. * Workaround for early ACK timeouts, add an offset to match the
  1013. * initval's 64us ack timeout value.
  1014. * This was initially only meant to work around an issue with delayed
  1015. * BA frames in some implementations, but it has been found to fix ACK
  1016. * timeout issues in other cases as well.
  1017. */
  1018. if (conf->channel && conf->channel->band == IEEE80211_BAND_2GHZ)
  1019. acktimeout += 64 - sifstime - ah->slottime;
  1020. ath9k_hw_setslottime(ah, slottime);
  1021. ath9k_hw_set_ack_timeout(ah, acktimeout);
  1022. ath9k_hw_set_cts_timeout(ah, acktimeout);
  1023. if (ah->globaltxtimeout != (u32) -1)
  1024. ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
  1025. }
  1026. EXPORT_SYMBOL(ath9k_hw_init_global_settings);
  1027. void ath9k_hw_deinit(struct ath_hw *ah)
  1028. {
  1029. struct ath_common *common = ath9k_hw_common(ah);
  1030. if (common->state < ATH_HW_INITIALIZED)
  1031. goto free_hw;
  1032. if (!AR_SREV_9100(ah))
  1033. ath9k_hw_ani_disable(ah);
  1034. ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
  1035. free_hw:
  1036. ath9k_hw_rf_free_ext_banks(ah);
  1037. }
  1038. EXPORT_SYMBOL(ath9k_hw_deinit);
  1039. /*******/
  1040. /* INI */
  1041. /*******/
  1042. u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
  1043. {
  1044. u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
  1045. if (IS_CHAN_B(chan))
  1046. ctl |= CTL_11B;
  1047. else if (IS_CHAN_G(chan))
  1048. ctl |= CTL_11G;
  1049. else
  1050. ctl |= CTL_11A;
  1051. return ctl;
  1052. }
  1053. /****************************************/
  1054. /* Reset and Channel Switching Routines */
  1055. /****************************************/
  1056. static inline void ath9k_hw_set_dma(struct ath_hw *ah)
  1057. {
  1058. u32 regval;
  1059. /*
  1060. * set AHB_MODE not to do cacheline prefetches
  1061. */
  1062. regval = REG_READ(ah, AR_AHB_MODE);
  1063. REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
  1064. /*
  1065. * let mac dma reads be in 128 byte chunks
  1066. */
  1067. regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
  1068. REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
  1069. /*
  1070. * Restore TX Trigger Level to its pre-reset value.
  1071. * The initial value depends on whether aggregation is enabled, and is
  1072. * adjusted whenever underruns are detected.
  1073. */
  1074. REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
  1075. /*
  1076. * let mac dma writes be in 128 byte chunks
  1077. */
  1078. regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
  1079. REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
  1080. /*
  1081. * Setup receive FIFO threshold to hold off TX activities
  1082. */
  1083. REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
  1084. /*
  1085. * reduce the number of usable entries in PCU TXBUF to avoid
  1086. * wrap around issues.
  1087. */
  1088. if (AR_SREV_9285(ah)) {
  1089. /* For AR9285 the number of Fifos are reduced to half.
  1090. * So set the usable tx buf size also to half to
  1091. * avoid data/delimiter underruns
  1092. */
  1093. REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
  1094. AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
  1095. } else if (!AR_SREV_9271(ah)) {
  1096. REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
  1097. AR_PCU_TXBUF_CTRL_USABLE_SIZE);
  1098. }
  1099. }
  1100. static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
  1101. {
  1102. u32 val;
  1103. val = REG_READ(ah, AR_STA_ID1);
  1104. val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
  1105. switch (opmode) {
  1106. case NL80211_IFTYPE_AP:
  1107. REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
  1108. | AR_STA_ID1_KSRCH_MODE);
  1109. REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
  1110. break;
  1111. case NL80211_IFTYPE_ADHOC:
  1112. case NL80211_IFTYPE_MESH_POINT:
  1113. REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
  1114. | AR_STA_ID1_KSRCH_MODE);
  1115. REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
  1116. break;
  1117. case NL80211_IFTYPE_STATION:
  1118. case NL80211_IFTYPE_MONITOR:
  1119. REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
  1120. break;
  1121. }
  1122. }
  1123. void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
  1124. u32 *coef_mantissa, u32 *coef_exponent)
  1125. {
  1126. u32 coef_exp, coef_man;
  1127. for (coef_exp = 31; coef_exp > 0; coef_exp--)
  1128. if ((coef_scaled >> coef_exp) & 0x1)
  1129. break;
  1130. coef_exp = 14 - (coef_exp - COEF_SCALE_S);
  1131. coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
  1132. *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
  1133. *coef_exponent = coef_exp - 16;
  1134. }
  1135. static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
  1136. {
  1137. u32 rst_flags;
  1138. u32 tmpReg;
  1139. if (AR_SREV_9100(ah)) {
  1140. u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
  1141. val &= ~AR_RTC_DERIVED_CLK_PERIOD;
  1142. val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
  1143. REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
  1144. (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
  1145. }
  1146. REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
  1147. AR_RTC_FORCE_WAKE_ON_INT);
  1148. if (AR_SREV_9100(ah)) {
  1149. rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
  1150. AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
  1151. } else {
  1152. tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
  1153. if (tmpReg &
  1154. (AR_INTR_SYNC_LOCAL_TIMEOUT |
  1155. AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
  1156. u32 val;
  1157. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
  1158. val = AR_RC_HOSTIF;
  1159. if (!AR_SREV_9300_20_OR_LATER(ah))
  1160. val |= AR_RC_AHB;
  1161. REG_WRITE(ah, AR_RC, val);
  1162. } else if (!AR_SREV_9300_20_OR_LATER(ah))
  1163. REG_WRITE(ah, AR_RC, AR_RC_AHB);
  1164. rst_flags = AR_RTC_RC_MAC_WARM;
  1165. if (type == ATH9K_RESET_COLD)
  1166. rst_flags |= AR_RTC_RC_MAC_COLD;
  1167. }
  1168. REG_WRITE(ah, AR_RTC_RC, rst_flags);
  1169. udelay(50);
  1170. REG_WRITE(ah, AR_RTC_RC, 0);
  1171. if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
  1172. ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
  1173. "RTC stuck in MAC reset\n");
  1174. return false;
  1175. }
  1176. if (!AR_SREV_9100(ah))
  1177. REG_WRITE(ah, AR_RC, 0);
  1178. if (AR_SREV_9100(ah))
  1179. udelay(50);
  1180. return true;
  1181. }
  1182. static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
  1183. {
  1184. REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
  1185. AR_RTC_FORCE_WAKE_ON_INT);
  1186. if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
  1187. REG_WRITE(ah, AR_RC, AR_RC_AHB);
  1188. REG_WRITE(ah, AR_RTC_RESET, 0);
  1189. if (!AR_SREV_9300_20_OR_LATER(ah))
  1190. udelay(2);
  1191. if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
  1192. REG_WRITE(ah, AR_RC, 0);
  1193. REG_WRITE(ah, AR_RTC_RESET, 1);
  1194. if (!ath9k_hw_wait(ah,
  1195. AR_RTC_STATUS,
  1196. AR_RTC_STATUS_M,
  1197. AR_RTC_STATUS_ON,
  1198. AH_WAIT_TIMEOUT)) {
  1199. ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
  1200. "RTC not waking up\n");
  1201. return false;
  1202. }
  1203. ath9k_hw_read_revisions(ah);
  1204. return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
  1205. }
  1206. static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
  1207. {
  1208. REG_WRITE(ah, AR_RTC_FORCE_WAKE,
  1209. AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
  1210. switch (type) {
  1211. case ATH9K_RESET_POWER_ON:
  1212. return ath9k_hw_set_reset_power_on(ah);
  1213. case ATH9K_RESET_WARM:
  1214. case ATH9K_RESET_COLD:
  1215. return ath9k_hw_set_reset(ah, type);
  1216. default:
  1217. return false;
  1218. }
  1219. }
  1220. static bool ath9k_hw_chip_reset(struct ath_hw *ah,
  1221. struct ath9k_channel *chan)
  1222. {
  1223. if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
  1224. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
  1225. return false;
  1226. } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
  1227. return false;
  1228. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  1229. return false;
  1230. ah->chip_fullsleep = false;
  1231. ath9k_hw_init_pll(ah, chan);
  1232. ath9k_hw_set_rfmode(ah, chan);
  1233. return true;
  1234. }
  1235. static bool ath9k_hw_channel_change(struct ath_hw *ah,
  1236. struct ath9k_channel *chan)
  1237. {
  1238. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  1239. struct ath_common *common = ath9k_hw_common(ah);
  1240. struct ieee80211_channel *channel = chan->chan;
  1241. u32 qnum;
  1242. int r;
  1243. for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
  1244. if (ath9k_hw_numtxpending(ah, qnum)) {
  1245. ath_print(common, ATH_DBG_QUEUE,
  1246. "Transmit frames pending on "
  1247. "queue %d\n", qnum);
  1248. return false;
  1249. }
  1250. }
  1251. if (!ath9k_hw_rfbus_req(ah)) {
  1252. ath_print(common, ATH_DBG_FATAL,
  1253. "Could not kill baseband RX\n");
  1254. return false;
  1255. }
  1256. ath9k_hw_set_channel_regs(ah, chan);
  1257. r = ath9k_hw_rf_set_freq(ah, chan);
  1258. if (r) {
  1259. ath_print(common, ATH_DBG_FATAL,
  1260. "Failed to set channel\n");
  1261. return false;
  1262. }
  1263. ah->eep_ops->set_txpower(ah, chan,
  1264. ath9k_regd_get_ctl(regulatory, chan),
  1265. channel->max_antenna_gain * 2,
  1266. channel->max_power * 2,
  1267. min((u32) MAX_RATE_POWER,
  1268. (u32) regulatory->power_limit));
  1269. ath9k_hw_rfbus_done(ah);
  1270. if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
  1271. ath9k_hw_set_delta_slope(ah, chan);
  1272. ath9k_hw_spur_mitigate_freq(ah, chan);
  1273. if (!chan->oneTimeCalsDone)
  1274. chan->oneTimeCalsDone = true;
  1275. return true;
  1276. }
  1277. int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
  1278. bool bChannelChange)
  1279. {
  1280. struct ath_common *common = ath9k_hw_common(ah);
  1281. u32 saveLedState;
  1282. struct ath9k_channel *curchan = ah->curchan;
  1283. u32 saveDefAntenna;
  1284. u32 macStaId1;
  1285. u64 tsf = 0;
  1286. int i, r;
  1287. ah->txchainmask = common->tx_chainmask;
  1288. ah->rxchainmask = common->rx_chainmask;
  1289. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  1290. return -EIO;
  1291. if (curchan && !ah->chip_fullsleep)
  1292. ath9k_hw_getnf(ah, curchan);
  1293. if (bChannelChange &&
  1294. (ah->chip_fullsleep != true) &&
  1295. (ah->curchan != NULL) &&
  1296. (chan->channel != ah->curchan->channel) &&
  1297. ((chan->channelFlags & CHANNEL_ALL) ==
  1298. (ah->curchan->channelFlags & CHANNEL_ALL)) &&
  1299. !(AR_SREV_9280(ah) || IS_CHAN_A_5MHZ_SPACED(chan) ||
  1300. IS_CHAN_A_5MHZ_SPACED(ah->curchan))) {
  1301. if (ath9k_hw_channel_change(ah, chan)) {
  1302. ath9k_hw_loadnf(ah, ah->curchan);
  1303. ath9k_hw_start_nfcal(ah);
  1304. return 0;
  1305. }
  1306. }
  1307. saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
  1308. if (saveDefAntenna == 0)
  1309. saveDefAntenna = 1;
  1310. macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
  1311. /* For chips on which RTC reset is done, save TSF before it gets cleared */
  1312. if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
  1313. tsf = ath9k_hw_gettsf64(ah);
  1314. saveLedState = REG_READ(ah, AR_CFG_LED) &
  1315. (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
  1316. AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
  1317. ath9k_hw_mark_phy_inactive(ah);
  1318. /* Only required on the first reset */
  1319. if (AR_SREV_9271(ah) && ah->htc_reset_init) {
  1320. REG_WRITE(ah,
  1321. AR9271_RESET_POWER_DOWN_CONTROL,
  1322. AR9271_RADIO_RF_RST);
  1323. udelay(50);
  1324. }
  1325. if (!ath9k_hw_chip_reset(ah, chan)) {
  1326. ath_print(common, ATH_DBG_FATAL, "Chip reset failed\n");
  1327. return -EINVAL;
  1328. }
  1329. /* Only required on the first reset */
  1330. if (AR_SREV_9271(ah) && ah->htc_reset_init) {
  1331. ah->htc_reset_init = false;
  1332. REG_WRITE(ah,
  1333. AR9271_RESET_POWER_DOWN_CONTROL,
  1334. AR9271_GATE_MAC_CTL);
  1335. udelay(50);
  1336. }
  1337. /* Restore TSF */
  1338. if (tsf && AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
  1339. ath9k_hw_settsf64(ah, tsf);
  1340. if (AR_SREV_9280_10_OR_LATER(ah))
  1341. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
  1342. r = ath9k_hw_process_ini(ah, chan);
  1343. if (r)
  1344. return r;
  1345. /* Setup MFP options for CCMP */
  1346. if (AR_SREV_9280_20_OR_LATER(ah)) {
  1347. /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
  1348. * frames when constructing CCMP AAD. */
  1349. REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
  1350. 0xc7ff);
  1351. ah->sw_mgmt_crypto = false;
  1352. } else if (AR_SREV_9160_10_OR_LATER(ah)) {
  1353. /* Disable hardware crypto for management frames */
  1354. REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
  1355. AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
  1356. REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
  1357. AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
  1358. ah->sw_mgmt_crypto = true;
  1359. } else
  1360. ah->sw_mgmt_crypto = true;
  1361. if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
  1362. ath9k_hw_set_delta_slope(ah, chan);
  1363. ath9k_hw_spur_mitigate_freq(ah, chan);
  1364. ah->eep_ops->set_board_values(ah, chan);
  1365. REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
  1366. REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
  1367. | macStaId1
  1368. | AR_STA_ID1_RTS_USE_DEF
  1369. | (ah->config.
  1370. ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
  1371. | ah->sta_id1_defaults);
  1372. ath9k_hw_set_operating_mode(ah, ah->opmode);
  1373. ath_hw_setbssidmask(common);
  1374. REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
  1375. ath9k_hw_write_associd(ah);
  1376. REG_WRITE(ah, AR_ISR, ~0);
  1377. REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
  1378. r = ath9k_hw_rf_set_freq(ah, chan);
  1379. if (r)
  1380. return r;
  1381. for (i = 0; i < AR_NUM_DCU; i++)
  1382. REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
  1383. ah->intr_txqs = 0;
  1384. for (i = 0; i < ah->caps.total_queues; i++)
  1385. ath9k_hw_resettxqueue(ah, i);
  1386. ath9k_hw_init_interrupt_masks(ah, ah->opmode);
  1387. ath9k_hw_init_qos(ah);
  1388. if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
  1389. ath9k_enable_rfkill(ah);
  1390. ath9k_hw_init_global_settings(ah);
  1391. if (AR_SREV_9287_12_OR_LATER(ah)) {
  1392. REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
  1393. AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
  1394. REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
  1395. AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
  1396. REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
  1397. AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
  1398. REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
  1399. REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
  1400. REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
  1401. AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
  1402. REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
  1403. AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
  1404. }
  1405. if (AR_SREV_9287_12_OR_LATER(ah)) {
  1406. REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
  1407. AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
  1408. }
  1409. REG_WRITE(ah, AR_STA_ID1,
  1410. REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
  1411. ath9k_hw_set_dma(ah);
  1412. REG_WRITE(ah, AR_OBS, 8);
  1413. if (ah->config.rx_intr_mitigation) {
  1414. REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
  1415. REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
  1416. }
  1417. ath9k_hw_init_bb(ah, chan);
  1418. if (!ath9k_hw_init_cal(ah, chan))
  1419. return -EIO;
  1420. ath9k_hw_restore_chainmask(ah);
  1421. REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
  1422. /*
  1423. * For big endian systems turn on swapping for descriptors
  1424. */
  1425. if (AR_SREV_9100(ah)) {
  1426. u32 mask;
  1427. mask = REG_READ(ah, AR_CFG);
  1428. if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
  1429. ath_print(common, ATH_DBG_RESET,
  1430. "CFG Byte Swap Set 0x%x\n", mask);
  1431. } else {
  1432. mask =
  1433. INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
  1434. REG_WRITE(ah, AR_CFG, mask);
  1435. ath_print(common, ATH_DBG_RESET,
  1436. "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
  1437. }
  1438. } else {
  1439. /* Configure AR9271 target WLAN */
  1440. if (AR_SREV_9271(ah))
  1441. REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
  1442. #ifdef __BIG_ENDIAN
  1443. else
  1444. REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
  1445. #endif
  1446. }
  1447. if (ah->btcoex_hw.enabled)
  1448. ath9k_hw_btcoex_enable(ah);
  1449. return 0;
  1450. }
  1451. EXPORT_SYMBOL(ath9k_hw_reset);
  1452. /************************/
  1453. /* Key Cache Management */
  1454. /************************/
  1455. bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
  1456. {
  1457. u32 keyType;
  1458. if (entry >= ah->caps.keycache_size) {
  1459. ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
  1460. "keychache entry %u out of range\n", entry);
  1461. return false;
  1462. }
  1463. keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
  1464. REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
  1465. REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
  1466. REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
  1467. REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
  1468. REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
  1469. REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
  1470. REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
  1471. REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
  1472. if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
  1473. u16 micentry = entry + 64;
  1474. REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
  1475. REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
  1476. REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
  1477. REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
  1478. }
  1479. return true;
  1480. }
  1481. EXPORT_SYMBOL(ath9k_hw_keyreset);
  1482. bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
  1483. {
  1484. u32 macHi, macLo;
  1485. if (entry >= ah->caps.keycache_size) {
  1486. ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
  1487. "keychache entry %u out of range\n", entry);
  1488. return false;
  1489. }
  1490. if (mac != NULL) {
  1491. macHi = (mac[5] << 8) | mac[4];
  1492. macLo = (mac[3] << 24) |
  1493. (mac[2] << 16) |
  1494. (mac[1] << 8) |
  1495. mac[0];
  1496. macLo >>= 1;
  1497. macLo |= (macHi & 1) << 31;
  1498. macHi >>= 1;
  1499. } else {
  1500. macLo = macHi = 0;
  1501. }
  1502. REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
  1503. REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
  1504. return true;
  1505. }
  1506. EXPORT_SYMBOL(ath9k_hw_keysetmac);
  1507. bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
  1508. const struct ath9k_keyval *k,
  1509. const u8 *mac)
  1510. {
  1511. const struct ath9k_hw_capabilities *pCap = &ah->caps;
  1512. struct ath_common *common = ath9k_hw_common(ah);
  1513. u32 key0, key1, key2, key3, key4;
  1514. u32 keyType;
  1515. if (entry >= pCap->keycache_size) {
  1516. ath_print(common, ATH_DBG_FATAL,
  1517. "keycache entry %u out of range\n", entry);
  1518. return false;
  1519. }
  1520. switch (k->kv_type) {
  1521. case ATH9K_CIPHER_AES_OCB:
  1522. keyType = AR_KEYTABLE_TYPE_AES;
  1523. break;
  1524. case ATH9K_CIPHER_AES_CCM:
  1525. if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
  1526. ath_print(common, ATH_DBG_ANY,
  1527. "AES-CCM not supported by mac rev 0x%x\n",
  1528. ah->hw_version.macRev);
  1529. return false;
  1530. }
  1531. keyType = AR_KEYTABLE_TYPE_CCM;
  1532. break;
  1533. case ATH9K_CIPHER_TKIP:
  1534. keyType = AR_KEYTABLE_TYPE_TKIP;
  1535. if (ATH9K_IS_MIC_ENABLED(ah)
  1536. && entry + 64 >= pCap->keycache_size) {
  1537. ath_print(common, ATH_DBG_ANY,
  1538. "entry %u inappropriate for TKIP\n", entry);
  1539. return false;
  1540. }
  1541. break;
  1542. case ATH9K_CIPHER_WEP:
  1543. if (k->kv_len < WLAN_KEY_LEN_WEP40) {
  1544. ath_print(common, ATH_DBG_ANY,
  1545. "WEP key length %u too small\n", k->kv_len);
  1546. return false;
  1547. }
  1548. if (k->kv_len <= WLAN_KEY_LEN_WEP40)
  1549. keyType = AR_KEYTABLE_TYPE_40;
  1550. else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
  1551. keyType = AR_KEYTABLE_TYPE_104;
  1552. else
  1553. keyType = AR_KEYTABLE_TYPE_128;
  1554. break;
  1555. case ATH9K_CIPHER_CLR:
  1556. keyType = AR_KEYTABLE_TYPE_CLR;
  1557. break;
  1558. default:
  1559. ath_print(common, ATH_DBG_FATAL,
  1560. "cipher %u not supported\n", k->kv_type);
  1561. return false;
  1562. }
  1563. key0 = get_unaligned_le32(k->kv_val + 0);
  1564. key1 = get_unaligned_le16(k->kv_val + 4);
  1565. key2 = get_unaligned_le32(k->kv_val + 6);
  1566. key3 = get_unaligned_le16(k->kv_val + 10);
  1567. key4 = get_unaligned_le32(k->kv_val + 12);
  1568. if (k->kv_len <= WLAN_KEY_LEN_WEP104)
  1569. key4 &= 0xff;
  1570. /*
  1571. * Note: Key cache registers access special memory area that requires
  1572. * two 32-bit writes to actually update the values in the internal
  1573. * memory. Consequently, the exact order and pairs used here must be
  1574. * maintained.
  1575. */
  1576. if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
  1577. u16 micentry = entry + 64;
  1578. /*
  1579. * Write inverted key[47:0] first to avoid Michael MIC errors
  1580. * on frames that could be sent or received at the same time.
  1581. * The correct key will be written in the end once everything
  1582. * else is ready.
  1583. */
  1584. REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
  1585. REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
  1586. /* Write key[95:48] */
  1587. REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
  1588. REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
  1589. /* Write key[127:96] and key type */
  1590. REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
  1591. REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
  1592. /* Write MAC address for the entry */
  1593. (void) ath9k_hw_keysetmac(ah, entry, mac);
  1594. if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
  1595. /*
  1596. * TKIP uses two key cache entries:
  1597. * Michael MIC TX/RX keys in the same key cache entry
  1598. * (idx = main index + 64):
  1599. * key0 [31:0] = RX key [31:0]
  1600. * key1 [15:0] = TX key [31:16]
  1601. * key1 [31:16] = reserved
  1602. * key2 [31:0] = RX key [63:32]
  1603. * key3 [15:0] = TX key [15:0]
  1604. * key3 [31:16] = reserved
  1605. * key4 [31:0] = TX key [63:32]
  1606. */
  1607. u32 mic0, mic1, mic2, mic3, mic4;
  1608. mic0 = get_unaligned_le32(k->kv_mic + 0);
  1609. mic2 = get_unaligned_le32(k->kv_mic + 4);
  1610. mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
  1611. mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
  1612. mic4 = get_unaligned_le32(k->kv_txmic + 4);
  1613. /* Write RX[31:0] and TX[31:16] */
  1614. REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
  1615. REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
  1616. /* Write RX[63:32] and TX[15:0] */
  1617. REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
  1618. REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
  1619. /* Write TX[63:32] and keyType(reserved) */
  1620. REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
  1621. REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
  1622. AR_KEYTABLE_TYPE_CLR);
  1623. } else {
  1624. /*
  1625. * TKIP uses four key cache entries (two for group
  1626. * keys):
  1627. * Michael MIC TX/RX keys are in different key cache
  1628. * entries (idx = main index + 64 for TX and
  1629. * main index + 32 + 96 for RX):
  1630. * key0 [31:0] = TX/RX MIC key [31:0]
  1631. * key1 [31:0] = reserved
  1632. * key2 [31:0] = TX/RX MIC key [63:32]
  1633. * key3 [31:0] = reserved
  1634. * key4 [31:0] = reserved
  1635. *
  1636. * Upper layer code will call this function separately
  1637. * for TX and RX keys when these registers offsets are
  1638. * used.
  1639. */
  1640. u32 mic0, mic2;
  1641. mic0 = get_unaligned_le32(k->kv_mic + 0);
  1642. mic2 = get_unaligned_le32(k->kv_mic + 4);
  1643. /* Write MIC key[31:0] */
  1644. REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
  1645. REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
  1646. /* Write MIC key[63:32] */
  1647. REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
  1648. REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
  1649. /* Write TX[63:32] and keyType(reserved) */
  1650. REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
  1651. REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
  1652. AR_KEYTABLE_TYPE_CLR);
  1653. }
  1654. /* MAC address registers are reserved for the MIC entry */
  1655. REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
  1656. REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
  1657. /*
  1658. * Write the correct (un-inverted) key[47:0] last to enable
  1659. * TKIP now that all other registers are set with correct
  1660. * values.
  1661. */
  1662. REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
  1663. REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
  1664. } else {
  1665. /* Write key[47:0] */
  1666. REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
  1667. REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
  1668. /* Write key[95:48] */
  1669. REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
  1670. REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
  1671. /* Write key[127:96] and key type */
  1672. REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
  1673. REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
  1674. /* Write MAC address for the entry */
  1675. (void) ath9k_hw_keysetmac(ah, entry, mac);
  1676. }
  1677. return true;
  1678. }
  1679. EXPORT_SYMBOL(ath9k_hw_set_keycache_entry);
  1680. bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
  1681. {
  1682. if (entry < ah->caps.keycache_size) {
  1683. u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
  1684. if (val & AR_KEYTABLE_VALID)
  1685. return true;
  1686. }
  1687. return false;
  1688. }
  1689. EXPORT_SYMBOL(ath9k_hw_keyisvalid);
  1690. /******************************/
  1691. /* Power Management (Chipset) */
  1692. /******************************/
  1693. /*
  1694. * Notify Power Mgt is disabled in self-generated frames.
  1695. * If requested, force chip to sleep.
  1696. */
  1697. static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
  1698. {
  1699. REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  1700. if (setChip) {
  1701. /*
  1702. * Clear the RTC force wake bit to allow the
  1703. * mac to go to sleep.
  1704. */
  1705. REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
  1706. AR_RTC_FORCE_WAKE_EN);
  1707. if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
  1708. REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
  1709. /* Shutdown chip. Active low */
  1710. if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah))
  1711. REG_CLR_BIT(ah, (AR_RTC_RESET),
  1712. AR_RTC_RESET_EN);
  1713. }
  1714. }
  1715. /*
  1716. * Notify Power Management is enabled in self-generating
  1717. * frames. If request, set power mode of chip to
  1718. * auto/normal. Duration in units of 128us (1/8 TU).
  1719. */
  1720. static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
  1721. {
  1722. REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  1723. if (setChip) {
  1724. struct ath9k_hw_capabilities *pCap = &ah->caps;
  1725. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  1726. /* Set WakeOnInterrupt bit; clear ForceWake bit */
  1727. REG_WRITE(ah, AR_RTC_FORCE_WAKE,
  1728. AR_RTC_FORCE_WAKE_ON_INT);
  1729. } else {
  1730. /*
  1731. * Clear the RTC force wake bit to allow the
  1732. * mac to go to sleep.
  1733. */
  1734. REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
  1735. AR_RTC_FORCE_WAKE_EN);
  1736. }
  1737. }
  1738. }
  1739. static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
  1740. {
  1741. u32 val;
  1742. int i;
  1743. if (setChip) {
  1744. if ((REG_READ(ah, AR_RTC_STATUS) &
  1745. AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
  1746. if (ath9k_hw_set_reset_reg(ah,
  1747. ATH9K_RESET_POWER_ON) != true) {
  1748. return false;
  1749. }
  1750. if (!AR_SREV_9300_20_OR_LATER(ah))
  1751. ath9k_hw_init_pll(ah, NULL);
  1752. }
  1753. if (AR_SREV_9100(ah))
  1754. REG_SET_BIT(ah, AR_RTC_RESET,
  1755. AR_RTC_RESET_EN);
  1756. REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
  1757. AR_RTC_FORCE_WAKE_EN);
  1758. udelay(50);
  1759. for (i = POWER_UP_TIME / 50; i > 0; i--) {
  1760. val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
  1761. if (val == AR_RTC_STATUS_ON)
  1762. break;
  1763. udelay(50);
  1764. REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
  1765. AR_RTC_FORCE_WAKE_EN);
  1766. }
  1767. if (i == 0) {
  1768. ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
  1769. "Failed to wakeup in %uus\n",
  1770. POWER_UP_TIME / 20);
  1771. return false;
  1772. }
  1773. }
  1774. REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  1775. return true;
  1776. }
  1777. bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
  1778. {
  1779. struct ath_common *common = ath9k_hw_common(ah);
  1780. int status = true, setChip = true;
  1781. static const char *modes[] = {
  1782. "AWAKE",
  1783. "FULL-SLEEP",
  1784. "NETWORK SLEEP",
  1785. "UNDEFINED"
  1786. };
  1787. if (ah->power_mode == mode)
  1788. return status;
  1789. ath_print(common, ATH_DBG_RESET, "%s -> %s\n",
  1790. modes[ah->power_mode], modes[mode]);
  1791. switch (mode) {
  1792. case ATH9K_PM_AWAKE:
  1793. status = ath9k_hw_set_power_awake(ah, setChip);
  1794. break;
  1795. case ATH9K_PM_FULL_SLEEP:
  1796. ath9k_set_power_sleep(ah, setChip);
  1797. ah->chip_fullsleep = true;
  1798. break;
  1799. case ATH9K_PM_NETWORK_SLEEP:
  1800. ath9k_set_power_network_sleep(ah, setChip);
  1801. break;
  1802. default:
  1803. ath_print(common, ATH_DBG_FATAL,
  1804. "Unknown power mode %u\n", mode);
  1805. return false;
  1806. }
  1807. ah->power_mode = mode;
  1808. return status;
  1809. }
  1810. EXPORT_SYMBOL(ath9k_hw_setpower);
  1811. /*
  1812. * Helper for ASPM support.
  1813. *
  1814. * Disable PLL when in L0s as well as receiver clock when in L1.
  1815. * This power saving option must be enabled through the SerDes.
  1816. *
  1817. * Programming the SerDes must go through the same 288 bit serial shift
  1818. * register as the other analog registers. Hence the 9 writes.
  1819. */
  1820. static void ar9002_hw_configpcipowersave(struct ath_hw *ah,
  1821. int restore,
  1822. int power_off)
  1823. {
  1824. u8 i;
  1825. u32 val;
  1826. if (ah->is_pciexpress != true)
  1827. return;
  1828. /* Do not touch SerDes registers */
  1829. if (ah->config.pcie_powersave_enable == 2)
  1830. return;
  1831. /* Nothing to do on restore for 11N */
  1832. if (!restore) {
  1833. if (AR_SREV_9280_20_OR_LATER(ah)) {
  1834. /*
  1835. * AR9280 2.0 or later chips use SerDes values from the
  1836. * initvals.h initialized depending on chipset during
  1837. * __ath9k_hw_init()
  1838. */
  1839. for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
  1840. REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
  1841. INI_RA(&ah->iniPcieSerdes, i, 1));
  1842. }
  1843. } else if (AR_SREV_9280(ah) &&
  1844. (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
  1845. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
  1846. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  1847. /* RX shut off when elecidle is asserted */
  1848. REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
  1849. REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
  1850. REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
  1851. /* Shut off CLKREQ active in L1 */
  1852. if (ah->config.pcie_clock_req)
  1853. REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
  1854. else
  1855. REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
  1856. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  1857. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  1858. REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
  1859. /* Load the new settings */
  1860. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  1861. } else {
  1862. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
  1863. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  1864. /* RX shut off when elecidle is asserted */
  1865. REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
  1866. REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
  1867. REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
  1868. /*
  1869. * Ignore ah->ah_config.pcie_clock_req setting for
  1870. * pre-AR9280 11n
  1871. */
  1872. REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
  1873. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  1874. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  1875. REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
  1876. /* Load the new settings */
  1877. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  1878. }
  1879. udelay(1000);
  1880. /* set bit 19 to allow forcing of pcie core into L1 state */
  1881. REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
  1882. /* Several PCIe massages to ensure proper behaviour */
  1883. if (ah->config.pcie_waen) {
  1884. val = ah->config.pcie_waen;
  1885. if (!power_off)
  1886. val &= (~AR_WA_D3_L1_DISABLE);
  1887. } else {
  1888. if (AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
  1889. AR_SREV_9287(ah)) {
  1890. val = AR9285_WA_DEFAULT;
  1891. if (!power_off)
  1892. val &= (~AR_WA_D3_L1_DISABLE);
  1893. } else if (AR_SREV_9280(ah)) {
  1894. /*
  1895. * On AR9280 chips bit 22 of 0x4004 needs to be
  1896. * set otherwise card may disappear.
  1897. */
  1898. val = AR9280_WA_DEFAULT;
  1899. if (!power_off)
  1900. val &= (~AR_WA_D3_L1_DISABLE);
  1901. } else
  1902. val = AR_WA_DEFAULT;
  1903. }
  1904. REG_WRITE(ah, AR_WA, val);
  1905. }
  1906. if (power_off) {
  1907. /*
  1908. * Set PCIe workaround bits
  1909. * bit 14 in WA register (disable L1) should only
  1910. * be set when device enters D3 and be cleared
  1911. * when device comes back to D0.
  1912. */
  1913. if (ah->config.pcie_waen) {
  1914. if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
  1915. REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
  1916. } else {
  1917. if (((AR_SREV_9285(ah) || AR_SREV_9271(ah) ||
  1918. AR_SREV_9287(ah)) &&
  1919. (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
  1920. (AR_SREV_9280(ah) &&
  1921. (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
  1922. REG_SET_BIT(ah, AR_WA, AR_WA_D3_L1_DISABLE);
  1923. }
  1924. }
  1925. }
  1926. }
  1927. /**********************/
  1928. /* Interrupt Handling */
  1929. /**********************/
  1930. bool ath9k_hw_intrpend(struct ath_hw *ah)
  1931. {
  1932. u32 host_isr;
  1933. if (AR_SREV_9100(ah))
  1934. return true;
  1935. host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
  1936. if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
  1937. return true;
  1938. host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
  1939. if ((host_isr & AR_INTR_SYNC_DEFAULT)
  1940. && (host_isr != AR_INTR_SPURIOUS))
  1941. return true;
  1942. return false;
  1943. }
  1944. EXPORT_SYMBOL(ath9k_hw_intrpend);
  1945. bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
  1946. {
  1947. u32 isr = 0;
  1948. u32 mask2 = 0;
  1949. struct ath9k_hw_capabilities *pCap = &ah->caps;
  1950. u32 sync_cause = 0;
  1951. bool fatal_int = false;
  1952. struct ath_common *common = ath9k_hw_common(ah);
  1953. if (!AR_SREV_9100(ah)) {
  1954. if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
  1955. if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
  1956. == AR_RTC_STATUS_ON) {
  1957. isr = REG_READ(ah, AR_ISR);
  1958. }
  1959. }
  1960. sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
  1961. AR_INTR_SYNC_DEFAULT;
  1962. *masked = 0;
  1963. if (!isr && !sync_cause)
  1964. return false;
  1965. } else {
  1966. *masked = 0;
  1967. isr = REG_READ(ah, AR_ISR);
  1968. }
  1969. if (isr) {
  1970. if (isr & AR_ISR_BCNMISC) {
  1971. u32 isr2;
  1972. isr2 = REG_READ(ah, AR_ISR_S2);
  1973. if (isr2 & AR_ISR_S2_TIM)
  1974. mask2 |= ATH9K_INT_TIM;
  1975. if (isr2 & AR_ISR_S2_DTIM)
  1976. mask2 |= ATH9K_INT_DTIM;
  1977. if (isr2 & AR_ISR_S2_DTIMSYNC)
  1978. mask2 |= ATH9K_INT_DTIMSYNC;
  1979. if (isr2 & (AR_ISR_S2_CABEND))
  1980. mask2 |= ATH9K_INT_CABEND;
  1981. if (isr2 & AR_ISR_S2_GTT)
  1982. mask2 |= ATH9K_INT_GTT;
  1983. if (isr2 & AR_ISR_S2_CST)
  1984. mask2 |= ATH9K_INT_CST;
  1985. if (isr2 & AR_ISR_S2_TSFOOR)
  1986. mask2 |= ATH9K_INT_TSFOOR;
  1987. }
  1988. isr = REG_READ(ah, AR_ISR_RAC);
  1989. if (isr == 0xffffffff) {
  1990. *masked = 0;
  1991. return false;
  1992. }
  1993. *masked = isr & ATH9K_INT_COMMON;
  1994. if (ah->config.rx_intr_mitigation) {
  1995. if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
  1996. *masked |= ATH9K_INT_RX;
  1997. }
  1998. if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
  1999. *masked |= ATH9K_INT_RX;
  2000. if (isr &
  2001. (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
  2002. AR_ISR_TXEOL)) {
  2003. u32 s0_s, s1_s;
  2004. *masked |= ATH9K_INT_TX;
  2005. s0_s = REG_READ(ah, AR_ISR_S0_S);
  2006. ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
  2007. ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
  2008. s1_s = REG_READ(ah, AR_ISR_S1_S);
  2009. ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
  2010. ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
  2011. }
  2012. if (isr & AR_ISR_RXORN) {
  2013. ath_print(common, ATH_DBG_INTERRUPT,
  2014. "receive FIFO overrun interrupt\n");
  2015. }
  2016. if (!AR_SREV_9100(ah)) {
  2017. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  2018. u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
  2019. if (isr5 & AR_ISR_S5_TIM_TIMER)
  2020. *masked |= ATH9K_INT_TIM_TIMER;
  2021. }
  2022. }
  2023. *masked |= mask2;
  2024. }
  2025. if (AR_SREV_9100(ah))
  2026. return true;
  2027. if (isr & AR_ISR_GENTMR) {
  2028. u32 s5_s;
  2029. s5_s = REG_READ(ah, AR_ISR_S5_S);
  2030. if (isr & AR_ISR_GENTMR) {
  2031. ah->intr_gen_timer_trigger =
  2032. MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
  2033. ah->intr_gen_timer_thresh =
  2034. MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
  2035. if (ah->intr_gen_timer_trigger)
  2036. *masked |= ATH9K_INT_GENTIMER;
  2037. }
  2038. }
  2039. if (sync_cause) {
  2040. fatal_int =
  2041. (sync_cause &
  2042. (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
  2043. ? true : false;
  2044. if (fatal_int) {
  2045. if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
  2046. ath_print(common, ATH_DBG_ANY,
  2047. "received PCI FATAL interrupt\n");
  2048. }
  2049. if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
  2050. ath_print(common, ATH_DBG_ANY,
  2051. "received PCI PERR interrupt\n");
  2052. }
  2053. *masked |= ATH9K_INT_FATAL;
  2054. }
  2055. if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
  2056. ath_print(common, ATH_DBG_INTERRUPT,
  2057. "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
  2058. REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
  2059. REG_WRITE(ah, AR_RC, 0);
  2060. *masked |= ATH9K_INT_FATAL;
  2061. }
  2062. if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
  2063. ath_print(common, ATH_DBG_INTERRUPT,
  2064. "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
  2065. }
  2066. REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
  2067. (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
  2068. }
  2069. return true;
  2070. }
  2071. EXPORT_SYMBOL(ath9k_hw_getisr);
  2072. enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
  2073. {
  2074. enum ath9k_int omask = ah->imask;
  2075. u32 mask, mask2;
  2076. struct ath9k_hw_capabilities *pCap = &ah->caps;
  2077. struct ath_common *common = ath9k_hw_common(ah);
  2078. ath_print(common, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
  2079. if (omask & ATH9K_INT_GLOBAL) {
  2080. ath_print(common, ATH_DBG_INTERRUPT, "disable IER\n");
  2081. REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
  2082. (void) REG_READ(ah, AR_IER);
  2083. if (!AR_SREV_9100(ah)) {
  2084. REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
  2085. (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
  2086. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
  2087. (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
  2088. }
  2089. }
  2090. mask = ints & ATH9K_INT_COMMON;
  2091. mask2 = 0;
  2092. if (ints & ATH9K_INT_TX) {
  2093. if (ah->txok_interrupt_mask)
  2094. mask |= AR_IMR_TXOK;
  2095. if (ah->txdesc_interrupt_mask)
  2096. mask |= AR_IMR_TXDESC;
  2097. if (ah->txerr_interrupt_mask)
  2098. mask |= AR_IMR_TXERR;
  2099. if (ah->txeol_interrupt_mask)
  2100. mask |= AR_IMR_TXEOL;
  2101. }
  2102. if (ints & ATH9K_INT_RX) {
  2103. mask |= AR_IMR_RXERR;
  2104. if (ah->config.rx_intr_mitigation)
  2105. mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
  2106. else
  2107. mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
  2108. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  2109. mask |= AR_IMR_GENTMR;
  2110. }
  2111. if (ints & (ATH9K_INT_BMISC)) {
  2112. mask |= AR_IMR_BCNMISC;
  2113. if (ints & ATH9K_INT_TIM)
  2114. mask2 |= AR_IMR_S2_TIM;
  2115. if (ints & ATH9K_INT_DTIM)
  2116. mask2 |= AR_IMR_S2_DTIM;
  2117. if (ints & ATH9K_INT_DTIMSYNC)
  2118. mask2 |= AR_IMR_S2_DTIMSYNC;
  2119. if (ints & ATH9K_INT_CABEND)
  2120. mask2 |= AR_IMR_S2_CABEND;
  2121. if (ints & ATH9K_INT_TSFOOR)
  2122. mask2 |= AR_IMR_S2_TSFOOR;
  2123. }
  2124. if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
  2125. mask |= AR_IMR_BCNMISC;
  2126. if (ints & ATH9K_INT_GTT)
  2127. mask2 |= AR_IMR_S2_GTT;
  2128. if (ints & ATH9K_INT_CST)
  2129. mask2 |= AR_IMR_S2_CST;
  2130. }
  2131. ath_print(common, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
  2132. REG_WRITE(ah, AR_IMR, mask);
  2133. ah->imrs2_reg &= ~(AR_IMR_S2_TIM | AR_IMR_S2_DTIM | AR_IMR_S2_DTIMSYNC |
  2134. AR_IMR_S2_CABEND | AR_IMR_S2_CABTO |
  2135. AR_IMR_S2_TSFOOR | AR_IMR_S2_GTT | AR_IMR_S2_CST);
  2136. ah->imrs2_reg |= mask2;
  2137. REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
  2138. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  2139. if (ints & ATH9K_INT_TIM_TIMER)
  2140. REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
  2141. else
  2142. REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
  2143. }
  2144. if (ints & ATH9K_INT_GLOBAL) {
  2145. ath_print(common, ATH_DBG_INTERRUPT, "enable IER\n");
  2146. REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
  2147. if (!AR_SREV_9100(ah)) {
  2148. REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
  2149. AR_INTR_MAC_IRQ);
  2150. REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
  2151. REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
  2152. AR_INTR_SYNC_DEFAULT);
  2153. REG_WRITE(ah, AR_INTR_SYNC_MASK,
  2154. AR_INTR_SYNC_DEFAULT);
  2155. }
  2156. ath_print(common, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
  2157. REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
  2158. }
  2159. return omask;
  2160. }
  2161. EXPORT_SYMBOL(ath9k_hw_set_interrupts);
  2162. /*******************/
  2163. /* Beacon Handling */
  2164. /*******************/
  2165. void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
  2166. {
  2167. int flags = 0;
  2168. ah->beacon_interval = beacon_period;
  2169. switch (ah->opmode) {
  2170. case NL80211_IFTYPE_STATION:
  2171. case NL80211_IFTYPE_MONITOR:
  2172. REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
  2173. REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
  2174. REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
  2175. flags |= AR_TBTT_TIMER_EN;
  2176. break;
  2177. case NL80211_IFTYPE_ADHOC:
  2178. case NL80211_IFTYPE_MESH_POINT:
  2179. REG_SET_BIT(ah, AR_TXCFG,
  2180. AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
  2181. REG_WRITE(ah, AR_NEXT_NDP_TIMER,
  2182. TU_TO_USEC(next_beacon +
  2183. (ah->atim_window ? ah->
  2184. atim_window : 1)));
  2185. flags |= AR_NDP_TIMER_EN;
  2186. case NL80211_IFTYPE_AP:
  2187. REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
  2188. REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
  2189. TU_TO_USEC(next_beacon -
  2190. ah->config.
  2191. dma_beacon_response_time));
  2192. REG_WRITE(ah, AR_NEXT_SWBA,
  2193. TU_TO_USEC(next_beacon -
  2194. ah->config.
  2195. sw_beacon_response_time));
  2196. flags |=
  2197. AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
  2198. break;
  2199. default:
  2200. ath_print(ath9k_hw_common(ah), ATH_DBG_BEACON,
  2201. "%s: unsupported opmode: %d\n",
  2202. __func__, ah->opmode);
  2203. return;
  2204. break;
  2205. }
  2206. REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
  2207. REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
  2208. REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
  2209. REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
  2210. beacon_period &= ~ATH9K_BEACON_ENA;
  2211. if (beacon_period & ATH9K_BEACON_RESET_TSF) {
  2212. ath9k_hw_reset_tsf(ah);
  2213. }
  2214. REG_SET_BIT(ah, AR_TIMER_MODE, flags);
  2215. }
  2216. EXPORT_SYMBOL(ath9k_hw_beaconinit);
  2217. void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
  2218. const struct ath9k_beacon_state *bs)
  2219. {
  2220. u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
  2221. struct ath9k_hw_capabilities *pCap = &ah->caps;
  2222. struct ath_common *common = ath9k_hw_common(ah);
  2223. REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
  2224. REG_WRITE(ah, AR_BEACON_PERIOD,
  2225. TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
  2226. REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
  2227. TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
  2228. REG_RMW_FIELD(ah, AR_RSSI_THR,
  2229. AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
  2230. beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
  2231. if (bs->bs_sleepduration > beaconintval)
  2232. beaconintval = bs->bs_sleepduration;
  2233. dtimperiod = bs->bs_dtimperiod;
  2234. if (bs->bs_sleepduration > dtimperiod)
  2235. dtimperiod = bs->bs_sleepduration;
  2236. if (beaconintval == dtimperiod)
  2237. nextTbtt = bs->bs_nextdtim;
  2238. else
  2239. nextTbtt = bs->bs_nexttbtt;
  2240. ath_print(common, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
  2241. ath_print(common, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
  2242. ath_print(common, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
  2243. ath_print(common, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
  2244. REG_WRITE(ah, AR_NEXT_DTIM,
  2245. TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
  2246. REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
  2247. REG_WRITE(ah, AR_SLEEP1,
  2248. SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
  2249. | AR_SLEEP1_ASSUME_DTIM);
  2250. if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
  2251. beacontimeout = (BEACON_TIMEOUT_VAL << 3);
  2252. else
  2253. beacontimeout = MIN_BEACON_TIMEOUT_VAL;
  2254. REG_WRITE(ah, AR_SLEEP2,
  2255. SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
  2256. REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
  2257. REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
  2258. REG_SET_BIT(ah, AR_TIMER_MODE,
  2259. AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
  2260. AR_DTIM_TIMER_EN);
  2261. /* TSF Out of Range Threshold */
  2262. REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
  2263. }
  2264. EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
  2265. /*******************/
  2266. /* HW Capabilities */
  2267. /*******************/
  2268. int ath9k_hw_fill_cap_info(struct ath_hw *ah)
  2269. {
  2270. struct ath9k_hw_capabilities *pCap = &ah->caps;
  2271. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  2272. struct ath_common *common = ath9k_hw_common(ah);
  2273. struct ath_btcoex_hw *btcoex_hw = &ah->btcoex_hw;
  2274. u16 capField = 0, eeval;
  2275. eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
  2276. regulatory->current_rd = eeval;
  2277. eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
  2278. if (AR_SREV_9285_10_OR_LATER(ah))
  2279. eeval |= AR9285_RDEXT_DEFAULT;
  2280. regulatory->current_rd_ext = eeval;
  2281. capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
  2282. if (ah->opmode != NL80211_IFTYPE_AP &&
  2283. ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
  2284. if (regulatory->current_rd == 0x64 ||
  2285. regulatory->current_rd == 0x65)
  2286. regulatory->current_rd += 5;
  2287. else if (regulatory->current_rd == 0x41)
  2288. regulatory->current_rd = 0x43;
  2289. ath_print(common, ATH_DBG_REGULATORY,
  2290. "regdomain mapped to 0x%x\n", regulatory->current_rd);
  2291. }
  2292. eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
  2293. if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) {
  2294. ath_print(common, ATH_DBG_FATAL,
  2295. "no band has been marked as supported in EEPROM.\n");
  2296. return -EINVAL;
  2297. }
  2298. bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
  2299. if (eeval & AR5416_OPFLAGS_11A) {
  2300. set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
  2301. if (ah->config.ht_enable) {
  2302. if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
  2303. set_bit(ATH9K_MODE_11NA_HT20,
  2304. pCap->wireless_modes);
  2305. if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
  2306. set_bit(ATH9K_MODE_11NA_HT40PLUS,
  2307. pCap->wireless_modes);
  2308. set_bit(ATH9K_MODE_11NA_HT40MINUS,
  2309. pCap->wireless_modes);
  2310. }
  2311. }
  2312. }
  2313. if (eeval & AR5416_OPFLAGS_11G) {
  2314. set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
  2315. if (ah->config.ht_enable) {
  2316. if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
  2317. set_bit(ATH9K_MODE_11NG_HT20,
  2318. pCap->wireless_modes);
  2319. if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
  2320. set_bit(ATH9K_MODE_11NG_HT40PLUS,
  2321. pCap->wireless_modes);
  2322. set_bit(ATH9K_MODE_11NG_HT40MINUS,
  2323. pCap->wireless_modes);
  2324. }
  2325. }
  2326. }
  2327. pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
  2328. /*
  2329. * For AR9271 we will temporarilly uses the rx chainmax as read from
  2330. * the EEPROM.
  2331. */
  2332. if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
  2333. !(eeval & AR5416_OPFLAGS_11A) &&
  2334. !(AR_SREV_9271(ah)))
  2335. /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
  2336. pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
  2337. else
  2338. /* Use rx_chainmask from EEPROM. */
  2339. pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
  2340. if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
  2341. ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
  2342. pCap->low_2ghz_chan = 2312;
  2343. pCap->high_2ghz_chan = 2732;
  2344. pCap->low_5ghz_chan = 4920;
  2345. pCap->high_5ghz_chan = 6100;
  2346. pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
  2347. pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
  2348. pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
  2349. pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
  2350. pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
  2351. pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
  2352. if (ah->config.ht_enable)
  2353. pCap->hw_caps |= ATH9K_HW_CAP_HT;
  2354. else
  2355. pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
  2356. pCap->hw_caps |= ATH9K_HW_CAP_GTT;
  2357. pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
  2358. pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
  2359. pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
  2360. if (capField & AR_EEPROM_EEPCAP_MAXQCU)
  2361. pCap->total_queues =
  2362. MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
  2363. else
  2364. pCap->total_queues = ATH9K_NUM_TX_QUEUES;
  2365. if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
  2366. pCap->keycache_size =
  2367. 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
  2368. else
  2369. pCap->keycache_size = AR_KEYTABLE_SIZE;
  2370. pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
  2371. if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
  2372. pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD >> 1;
  2373. else
  2374. pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
  2375. if (AR_SREV_9271(ah))
  2376. pCap->num_gpio_pins = AR9271_NUM_GPIO;
  2377. else if (AR_SREV_9285_10_OR_LATER(ah))
  2378. pCap->num_gpio_pins = AR9285_NUM_GPIO;
  2379. else if (AR_SREV_9280_10_OR_LATER(ah))
  2380. pCap->num_gpio_pins = AR928X_NUM_GPIO;
  2381. else
  2382. pCap->num_gpio_pins = AR_NUM_GPIO;
  2383. if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
  2384. pCap->hw_caps |= ATH9K_HW_CAP_CST;
  2385. pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
  2386. } else {
  2387. pCap->rts_aggr_limit = (8 * 1024);
  2388. }
  2389. pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
  2390. #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
  2391. ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
  2392. if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
  2393. ah->rfkill_gpio =
  2394. MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
  2395. ah->rfkill_polarity =
  2396. MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
  2397. pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
  2398. }
  2399. #endif
  2400. if (AR_SREV_9271(ah))
  2401. pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
  2402. else
  2403. pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
  2404. if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
  2405. pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
  2406. else
  2407. pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
  2408. if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
  2409. pCap->reg_cap =
  2410. AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
  2411. AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
  2412. AR_EEPROM_EEREGCAP_EN_KK_U2 |
  2413. AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
  2414. } else {
  2415. pCap->reg_cap =
  2416. AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
  2417. AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
  2418. }
  2419. /* Advertise midband for AR5416 with FCC midband set in eeprom */
  2420. if (regulatory->current_rd_ext & (1 << REG_EXT_FCC_MIDBAND) &&
  2421. AR_SREV_5416(ah))
  2422. pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
  2423. pCap->num_antcfg_5ghz =
  2424. ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
  2425. pCap->num_antcfg_2ghz =
  2426. ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
  2427. if (AR_SREV_9280_10_OR_LATER(ah) &&
  2428. ath9k_hw_btcoex_supported(ah)) {
  2429. btcoex_hw->btactive_gpio = ATH_BTACTIVE_GPIO;
  2430. btcoex_hw->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
  2431. if (AR_SREV_9285(ah)) {
  2432. btcoex_hw->scheme = ATH_BTCOEX_CFG_3WIRE;
  2433. btcoex_hw->btpriority_gpio = ATH_BTPRIORITY_GPIO;
  2434. } else {
  2435. btcoex_hw->scheme = ATH_BTCOEX_CFG_2WIRE;
  2436. }
  2437. } else {
  2438. btcoex_hw->scheme = ATH_BTCOEX_CFG_NONE;
  2439. }
  2440. if (AR_SREV_9300_20_OR_LATER(ah)) {
  2441. pCap->hw_caps |= ATH9K_HW_CAP_EDMA;
  2442. pCap->rx_hp_qdepth = ATH9K_HW_RX_HP_QDEPTH;
  2443. pCap->rx_lp_qdepth = ATH9K_HW_RX_LP_QDEPTH;
  2444. pCap->rx_status_len = sizeof(struct ar9003_rxs);
  2445. }
  2446. return 0;
  2447. }
  2448. bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
  2449. u32 capability, u32 *result)
  2450. {
  2451. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  2452. switch (type) {
  2453. case ATH9K_CAP_CIPHER:
  2454. switch (capability) {
  2455. case ATH9K_CIPHER_AES_CCM:
  2456. case ATH9K_CIPHER_AES_OCB:
  2457. case ATH9K_CIPHER_TKIP:
  2458. case ATH9K_CIPHER_WEP:
  2459. case ATH9K_CIPHER_MIC:
  2460. case ATH9K_CIPHER_CLR:
  2461. return true;
  2462. default:
  2463. return false;
  2464. }
  2465. case ATH9K_CAP_TKIP_MIC:
  2466. switch (capability) {
  2467. case 0:
  2468. return true;
  2469. case 1:
  2470. return (ah->sta_id1_defaults &
  2471. AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
  2472. false;
  2473. }
  2474. case ATH9K_CAP_TKIP_SPLIT:
  2475. return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
  2476. false : true;
  2477. case ATH9K_CAP_MCAST_KEYSRCH:
  2478. switch (capability) {
  2479. case 0:
  2480. return true;
  2481. case 1:
  2482. if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
  2483. return false;
  2484. } else {
  2485. return (ah->sta_id1_defaults &
  2486. AR_STA_ID1_MCAST_KSRCH) ? true :
  2487. false;
  2488. }
  2489. }
  2490. return false;
  2491. case ATH9K_CAP_TXPOW:
  2492. switch (capability) {
  2493. case 0:
  2494. return 0;
  2495. case 1:
  2496. *result = regulatory->power_limit;
  2497. return 0;
  2498. case 2:
  2499. *result = regulatory->max_power_level;
  2500. return 0;
  2501. case 3:
  2502. *result = regulatory->tp_scale;
  2503. return 0;
  2504. }
  2505. return false;
  2506. case ATH9K_CAP_DS:
  2507. return (AR_SREV_9280_20_OR_LATER(ah) &&
  2508. (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
  2509. ? false : true;
  2510. default:
  2511. return false;
  2512. }
  2513. }
  2514. EXPORT_SYMBOL(ath9k_hw_getcapability);
  2515. bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
  2516. u32 capability, u32 setting, int *status)
  2517. {
  2518. switch (type) {
  2519. case ATH9K_CAP_TKIP_MIC:
  2520. if (setting)
  2521. ah->sta_id1_defaults |=
  2522. AR_STA_ID1_CRPT_MIC_ENABLE;
  2523. else
  2524. ah->sta_id1_defaults &=
  2525. ~AR_STA_ID1_CRPT_MIC_ENABLE;
  2526. return true;
  2527. case ATH9K_CAP_MCAST_KEYSRCH:
  2528. if (setting)
  2529. ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
  2530. else
  2531. ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
  2532. return true;
  2533. default:
  2534. return false;
  2535. }
  2536. }
  2537. EXPORT_SYMBOL(ath9k_hw_setcapability);
  2538. /****************************/
  2539. /* GPIO / RFKILL / Antennae */
  2540. /****************************/
  2541. static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
  2542. u32 gpio, u32 type)
  2543. {
  2544. int addr;
  2545. u32 gpio_shift, tmp;
  2546. if (gpio > 11)
  2547. addr = AR_GPIO_OUTPUT_MUX3;
  2548. else if (gpio > 5)
  2549. addr = AR_GPIO_OUTPUT_MUX2;
  2550. else
  2551. addr = AR_GPIO_OUTPUT_MUX1;
  2552. gpio_shift = (gpio % 6) * 5;
  2553. if (AR_SREV_9280_20_OR_LATER(ah)
  2554. || (addr != AR_GPIO_OUTPUT_MUX1)) {
  2555. REG_RMW(ah, addr, (type << gpio_shift),
  2556. (0x1f << gpio_shift));
  2557. } else {
  2558. tmp = REG_READ(ah, addr);
  2559. tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
  2560. tmp &= ~(0x1f << gpio_shift);
  2561. tmp |= (type << gpio_shift);
  2562. REG_WRITE(ah, addr, tmp);
  2563. }
  2564. }
  2565. void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
  2566. {
  2567. u32 gpio_shift;
  2568. BUG_ON(gpio >= ah->caps.num_gpio_pins);
  2569. gpio_shift = gpio << 1;
  2570. REG_RMW(ah,
  2571. AR_GPIO_OE_OUT,
  2572. (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
  2573. (AR_GPIO_OE_OUT_DRV << gpio_shift));
  2574. }
  2575. EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
  2576. u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
  2577. {
  2578. #define MS_REG_READ(x, y) \
  2579. (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
  2580. if (gpio >= ah->caps.num_gpio_pins)
  2581. return 0xffffffff;
  2582. if (AR_SREV_9300_20_OR_LATER(ah))
  2583. return MS_REG_READ(AR9300, gpio) != 0;
  2584. else if (AR_SREV_9271(ah))
  2585. return MS_REG_READ(AR9271, gpio) != 0;
  2586. else if (AR_SREV_9287_10_OR_LATER(ah))
  2587. return MS_REG_READ(AR9287, gpio) != 0;
  2588. else if (AR_SREV_9285_10_OR_LATER(ah))
  2589. return MS_REG_READ(AR9285, gpio) != 0;
  2590. else if (AR_SREV_9280_10_OR_LATER(ah))
  2591. return MS_REG_READ(AR928X, gpio) != 0;
  2592. else
  2593. return MS_REG_READ(AR, gpio) != 0;
  2594. }
  2595. EXPORT_SYMBOL(ath9k_hw_gpio_get);
  2596. void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
  2597. u32 ah_signal_type)
  2598. {
  2599. u32 gpio_shift;
  2600. ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
  2601. gpio_shift = 2 * gpio;
  2602. REG_RMW(ah,
  2603. AR_GPIO_OE_OUT,
  2604. (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
  2605. (AR_GPIO_OE_OUT_DRV << gpio_shift));
  2606. }
  2607. EXPORT_SYMBOL(ath9k_hw_cfg_output);
  2608. void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
  2609. {
  2610. if (AR_SREV_9271(ah))
  2611. val = ~val;
  2612. REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
  2613. AR_GPIO_BIT(gpio));
  2614. }
  2615. EXPORT_SYMBOL(ath9k_hw_set_gpio);
  2616. u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
  2617. {
  2618. return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
  2619. }
  2620. EXPORT_SYMBOL(ath9k_hw_getdefantenna);
  2621. void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
  2622. {
  2623. REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
  2624. }
  2625. EXPORT_SYMBOL(ath9k_hw_setantenna);
  2626. /*********************/
  2627. /* General Operation */
  2628. /*********************/
  2629. u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
  2630. {
  2631. u32 bits = REG_READ(ah, AR_RX_FILTER);
  2632. u32 phybits = REG_READ(ah, AR_PHY_ERR);
  2633. if (phybits & AR_PHY_ERR_RADAR)
  2634. bits |= ATH9K_RX_FILTER_PHYRADAR;
  2635. if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
  2636. bits |= ATH9K_RX_FILTER_PHYERR;
  2637. return bits;
  2638. }
  2639. EXPORT_SYMBOL(ath9k_hw_getrxfilter);
  2640. void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
  2641. {
  2642. u32 phybits;
  2643. REG_WRITE(ah, AR_RX_FILTER, bits);
  2644. phybits = 0;
  2645. if (bits & ATH9K_RX_FILTER_PHYRADAR)
  2646. phybits |= AR_PHY_ERR_RADAR;
  2647. if (bits & ATH9K_RX_FILTER_PHYERR)
  2648. phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
  2649. REG_WRITE(ah, AR_PHY_ERR, phybits);
  2650. if (phybits)
  2651. REG_WRITE(ah, AR_RXCFG,
  2652. REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
  2653. else
  2654. REG_WRITE(ah, AR_RXCFG,
  2655. REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
  2656. }
  2657. EXPORT_SYMBOL(ath9k_hw_setrxfilter);
  2658. bool ath9k_hw_phy_disable(struct ath_hw *ah)
  2659. {
  2660. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
  2661. return false;
  2662. ath9k_hw_init_pll(ah, NULL);
  2663. return true;
  2664. }
  2665. EXPORT_SYMBOL(ath9k_hw_phy_disable);
  2666. bool ath9k_hw_disable(struct ath_hw *ah)
  2667. {
  2668. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  2669. return false;
  2670. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
  2671. return false;
  2672. ath9k_hw_init_pll(ah, NULL);
  2673. return true;
  2674. }
  2675. EXPORT_SYMBOL(ath9k_hw_disable);
  2676. void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
  2677. {
  2678. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  2679. struct ath9k_channel *chan = ah->curchan;
  2680. struct ieee80211_channel *channel = chan->chan;
  2681. regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
  2682. ah->eep_ops->set_txpower(ah, chan,
  2683. ath9k_regd_get_ctl(regulatory, chan),
  2684. channel->max_antenna_gain * 2,
  2685. channel->max_power * 2,
  2686. min((u32) MAX_RATE_POWER,
  2687. (u32) regulatory->power_limit));
  2688. }
  2689. EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
  2690. void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
  2691. {
  2692. memcpy(ath9k_hw_common(ah)->macaddr, mac, ETH_ALEN);
  2693. }
  2694. EXPORT_SYMBOL(ath9k_hw_setmac);
  2695. void ath9k_hw_setopmode(struct ath_hw *ah)
  2696. {
  2697. ath9k_hw_set_operating_mode(ah, ah->opmode);
  2698. }
  2699. EXPORT_SYMBOL(ath9k_hw_setopmode);
  2700. void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
  2701. {
  2702. REG_WRITE(ah, AR_MCAST_FIL0, filter0);
  2703. REG_WRITE(ah, AR_MCAST_FIL1, filter1);
  2704. }
  2705. EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
  2706. void ath9k_hw_write_associd(struct ath_hw *ah)
  2707. {
  2708. struct ath_common *common = ath9k_hw_common(ah);
  2709. REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
  2710. REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
  2711. ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
  2712. }
  2713. EXPORT_SYMBOL(ath9k_hw_write_associd);
  2714. u64 ath9k_hw_gettsf64(struct ath_hw *ah)
  2715. {
  2716. u64 tsf;
  2717. tsf = REG_READ(ah, AR_TSF_U32);
  2718. tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
  2719. return tsf;
  2720. }
  2721. EXPORT_SYMBOL(ath9k_hw_gettsf64);
  2722. void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
  2723. {
  2724. REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
  2725. REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
  2726. }
  2727. EXPORT_SYMBOL(ath9k_hw_settsf64);
  2728. void ath9k_hw_reset_tsf(struct ath_hw *ah)
  2729. {
  2730. if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
  2731. AH_TSF_WRITE_TIMEOUT))
  2732. ath_print(ath9k_hw_common(ah), ATH_DBG_RESET,
  2733. "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
  2734. REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
  2735. }
  2736. EXPORT_SYMBOL(ath9k_hw_reset_tsf);
  2737. void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
  2738. {
  2739. if (setting)
  2740. ah->misc_mode |= AR_PCU_TX_ADD_TSF;
  2741. else
  2742. ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
  2743. }
  2744. EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
  2745. /*
  2746. * Extend 15-bit time stamp from rx descriptor to
  2747. * a full 64-bit TSF using the current h/w TSF.
  2748. */
  2749. u64 ath9k_hw_extend_tsf(struct ath_hw *ah, u32 rstamp)
  2750. {
  2751. u64 tsf;
  2752. tsf = ath9k_hw_gettsf64(ah);
  2753. if ((tsf & 0x7fff) < rstamp)
  2754. tsf -= 0x8000;
  2755. return (tsf & ~0x7fff) | rstamp;
  2756. }
  2757. EXPORT_SYMBOL(ath9k_hw_extend_tsf);
  2758. void ath9k_hw_set11nmac2040(struct ath_hw *ah)
  2759. {
  2760. struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
  2761. u32 macmode;
  2762. if (conf_is_ht40(conf) && !ah->config.cwm_ignore_extcca)
  2763. macmode = AR_2040_JOINED_RX_CLEAR;
  2764. else
  2765. macmode = 0;
  2766. REG_WRITE(ah, AR_2040_MODE, macmode);
  2767. }
  2768. /* HW Generic timers configuration */
  2769. static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
  2770. {
  2771. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2772. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2773. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2774. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2775. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2776. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2777. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2778. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2779. {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
  2780. {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
  2781. AR_NDP2_TIMER_MODE, 0x0002},
  2782. {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
  2783. AR_NDP2_TIMER_MODE, 0x0004},
  2784. {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
  2785. AR_NDP2_TIMER_MODE, 0x0008},
  2786. {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
  2787. AR_NDP2_TIMER_MODE, 0x0010},
  2788. {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
  2789. AR_NDP2_TIMER_MODE, 0x0020},
  2790. {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
  2791. AR_NDP2_TIMER_MODE, 0x0040},
  2792. {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
  2793. AR_NDP2_TIMER_MODE, 0x0080}
  2794. };
  2795. /* HW generic timer primitives */
  2796. /* compute and clear index of rightmost 1 */
  2797. static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
  2798. {
  2799. u32 b;
  2800. b = *mask;
  2801. b &= (0-b);
  2802. *mask &= ~b;
  2803. b *= debruijn32;
  2804. b >>= 27;
  2805. return timer_table->gen_timer_index[b];
  2806. }
  2807. u32 ath9k_hw_gettsf32(struct ath_hw *ah)
  2808. {
  2809. return REG_READ(ah, AR_TSF_L32);
  2810. }
  2811. EXPORT_SYMBOL(ath9k_hw_gettsf32);
  2812. struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
  2813. void (*trigger)(void *),
  2814. void (*overflow)(void *),
  2815. void *arg,
  2816. u8 timer_index)
  2817. {
  2818. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  2819. struct ath_gen_timer *timer;
  2820. timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
  2821. if (timer == NULL) {
  2822. ath_print(ath9k_hw_common(ah), ATH_DBG_FATAL,
  2823. "Failed to allocate memory"
  2824. "for hw timer[%d]\n", timer_index);
  2825. return NULL;
  2826. }
  2827. /* allocate a hardware generic timer slot */
  2828. timer_table->timers[timer_index] = timer;
  2829. timer->index = timer_index;
  2830. timer->trigger = trigger;
  2831. timer->overflow = overflow;
  2832. timer->arg = arg;
  2833. return timer;
  2834. }
  2835. EXPORT_SYMBOL(ath_gen_timer_alloc);
  2836. void ath9k_hw_gen_timer_start(struct ath_hw *ah,
  2837. struct ath_gen_timer *timer,
  2838. u32 timer_next,
  2839. u32 timer_period)
  2840. {
  2841. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  2842. u32 tsf;
  2843. BUG_ON(!timer_period);
  2844. set_bit(timer->index, &timer_table->timer_mask.timer_bits);
  2845. tsf = ath9k_hw_gettsf32(ah);
  2846. ath_print(ath9k_hw_common(ah), ATH_DBG_HWTIMER,
  2847. "curent tsf %x period %x"
  2848. "timer_next %x\n", tsf, timer_period, timer_next);
  2849. /*
  2850. * Pull timer_next forward if the current TSF already passed it
  2851. * because of software latency
  2852. */
  2853. if (timer_next < tsf)
  2854. timer_next = tsf + timer_period;
  2855. /*
  2856. * Program generic timer registers
  2857. */
  2858. REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
  2859. timer_next);
  2860. REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
  2861. timer_period);
  2862. REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
  2863. gen_tmr_configuration[timer->index].mode_mask);
  2864. /* Enable both trigger and thresh interrupt masks */
  2865. REG_SET_BIT(ah, AR_IMR_S5,
  2866. (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
  2867. SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
  2868. }
  2869. EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
  2870. void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
  2871. {
  2872. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  2873. if ((timer->index < AR_FIRST_NDP_TIMER) ||
  2874. (timer->index >= ATH_MAX_GEN_TIMER)) {
  2875. return;
  2876. }
  2877. /* Clear generic timer enable bits. */
  2878. REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
  2879. gen_tmr_configuration[timer->index].mode_mask);
  2880. /* Disable both trigger and thresh interrupt masks */
  2881. REG_CLR_BIT(ah, AR_IMR_S5,
  2882. (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
  2883. SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
  2884. clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
  2885. }
  2886. EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
  2887. void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
  2888. {
  2889. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  2890. /* free the hardware generic timer slot */
  2891. timer_table->timers[timer->index] = NULL;
  2892. kfree(timer);
  2893. }
  2894. EXPORT_SYMBOL(ath_gen_timer_free);
  2895. /*
  2896. * Generic Timer Interrupts handling
  2897. */
  2898. void ath_gen_timer_isr(struct ath_hw *ah)
  2899. {
  2900. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  2901. struct ath_gen_timer *timer;
  2902. struct ath_common *common = ath9k_hw_common(ah);
  2903. u32 trigger_mask, thresh_mask, index;
  2904. /* get hardware generic timer interrupt status */
  2905. trigger_mask = ah->intr_gen_timer_trigger;
  2906. thresh_mask = ah->intr_gen_timer_thresh;
  2907. trigger_mask &= timer_table->timer_mask.val;
  2908. thresh_mask &= timer_table->timer_mask.val;
  2909. trigger_mask &= ~thresh_mask;
  2910. while (thresh_mask) {
  2911. index = rightmost_index(timer_table, &thresh_mask);
  2912. timer = timer_table->timers[index];
  2913. BUG_ON(!timer);
  2914. ath_print(common, ATH_DBG_HWTIMER,
  2915. "TSF overflow for Gen timer %d\n", index);
  2916. timer->overflow(timer->arg);
  2917. }
  2918. while (trigger_mask) {
  2919. index = rightmost_index(timer_table, &trigger_mask);
  2920. timer = timer_table->timers[index];
  2921. BUG_ON(!timer);
  2922. ath_print(common, ATH_DBG_HWTIMER,
  2923. "Gen timer[%d] trigger\n", index);
  2924. timer->trigger(timer->arg);
  2925. }
  2926. }
  2927. EXPORT_SYMBOL(ath_gen_timer_isr);
  2928. /********/
  2929. /* HTC */
  2930. /********/
  2931. void ath9k_hw_htc_resetinit(struct ath_hw *ah)
  2932. {
  2933. ah->htc_reset_init = true;
  2934. }
  2935. EXPORT_SYMBOL(ath9k_hw_htc_resetinit);
  2936. static struct {
  2937. u32 version;
  2938. const char * name;
  2939. } ath_mac_bb_names[] = {
  2940. /* Devices with external radios */
  2941. { AR_SREV_VERSION_5416_PCI, "5416" },
  2942. { AR_SREV_VERSION_5416_PCIE, "5418" },
  2943. { AR_SREV_VERSION_9100, "9100" },
  2944. { AR_SREV_VERSION_9160, "9160" },
  2945. /* Single-chip solutions */
  2946. { AR_SREV_VERSION_9280, "9280" },
  2947. { AR_SREV_VERSION_9285, "9285" },
  2948. { AR_SREV_VERSION_9287, "9287" },
  2949. { AR_SREV_VERSION_9271, "9271" },
  2950. };
  2951. /* For devices with external radios */
  2952. static struct {
  2953. u16 version;
  2954. const char * name;
  2955. } ath_rf_names[] = {
  2956. { 0, "5133" },
  2957. { AR_RAD5133_SREV_MAJOR, "5133" },
  2958. { AR_RAD5122_SREV_MAJOR, "5122" },
  2959. { AR_RAD2133_SREV_MAJOR, "2133" },
  2960. { AR_RAD2122_SREV_MAJOR, "2122" }
  2961. };
  2962. /*
  2963. * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
  2964. */
  2965. static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
  2966. {
  2967. int i;
  2968. for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
  2969. if (ath_mac_bb_names[i].version == mac_bb_version) {
  2970. return ath_mac_bb_names[i].name;
  2971. }
  2972. }
  2973. return "????";
  2974. }
  2975. /*
  2976. * Return the RF name. "????" is returned if the RF is unknown.
  2977. * Used for devices with external radios.
  2978. */
  2979. static const char *ath9k_hw_rf_name(u16 rf_version)
  2980. {
  2981. int i;
  2982. for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
  2983. if (ath_rf_names[i].version == rf_version) {
  2984. return ath_rf_names[i].name;
  2985. }
  2986. }
  2987. return "????";
  2988. }
  2989. void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
  2990. {
  2991. int used;
  2992. /* chipsets >= AR9280 are single-chip */
  2993. if (AR_SREV_9280_10_OR_LATER(ah)) {
  2994. used = snprintf(hw_name, len,
  2995. "Atheros AR%s Rev:%x",
  2996. ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
  2997. ah->hw_version.macRev);
  2998. }
  2999. else {
  3000. used = snprintf(hw_name, len,
  3001. "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
  3002. ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
  3003. ah->hw_version.macRev,
  3004. ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
  3005. AR_RADIO_SREV_MAJOR)),
  3006. ah->hw_version.phyRev);
  3007. }
  3008. hw_name[used] = '\0';
  3009. }
  3010. EXPORT_SYMBOL(ath9k_hw_name);
  3011. /* Sets up the AR5008/AR9001/AR9002 hardware familiy callbacks */
  3012. static void ar9002_hw_attach_ops(struct ath_hw *ah)
  3013. {
  3014. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  3015. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  3016. priv_ops->init_cal_settings = ar9002_hw_init_cal_settings;
  3017. priv_ops->init_mode_regs = ar9002_hw_init_mode_regs;
  3018. priv_ops->macversion_supported = ar9002_hw_macversion_supported;
  3019. ops->config_pci_powersave = ar9002_hw_configpcipowersave;
  3020. ar5008_hw_attach_phy_ops(ah);
  3021. if (AR_SREV_9280_10_OR_LATER(ah))
  3022. ar9002_hw_attach_phy_ops(ah);
  3023. ar9002_hw_attach_mac_ops(ah);
  3024. }
  3025. /* Sets up the AR9003 hardware familiy callbacks */
  3026. static void ar9003_hw_attach_ops(struct ath_hw *ah)
  3027. {
  3028. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  3029. priv_ops->macversion_supported = ar9003_hw_macversion_supported;
  3030. ar9003_hw_attach_phy_ops(ah);
  3031. ar9003_hw_attach_mac_ops(ah);
  3032. }