hw.c 105 KB

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