hw.c 113 KB

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