hw.c 101 KB

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