hw.c 114 KB

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