hw.c 106 KB

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