hw.c 95 KB

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