hw.c 108 KB

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