hw.c 119 KB

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