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