hw.c 106 KB

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