hw.c 101 KB

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