hw.c 114 KB

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