hw.c 101 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826
  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_9280(ah)) {
  1834. ahp->ah_txchainmask &= 0x3;
  1835. ahp->ah_rxchainmask &= 0x3;
  1836. }
  1837. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  1838. return -EIO;
  1839. if (curchan)
  1840. ath9k_hw_getnf(ah, curchan);
  1841. if (bChannelChange &&
  1842. (ahp->ah_chipFullSleep != true) &&
  1843. (ah->ah_curchan != NULL) &&
  1844. (chan->channel != ah->ah_curchan->channel) &&
  1845. ((chan->channelFlags & CHANNEL_ALL) ==
  1846. (ah->ah_curchan->channelFlags & CHANNEL_ALL)) &&
  1847. (!AR_SREV_9280(ah) || (!IS_CHAN_A_5MHZ_SPACED(chan) &&
  1848. !IS_CHAN_A_5MHZ_SPACED(ah->ah_curchan)))) {
  1849. if (ath9k_hw_channel_change(ah, chan, sc->tx_chan_width)) {
  1850. ath9k_hw_loadnf(ah, ah->ah_curchan);
  1851. ath9k_hw_start_nfcal(ah);
  1852. return 0;
  1853. }
  1854. }
  1855. saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
  1856. if (saveDefAntenna == 0)
  1857. saveDefAntenna = 1;
  1858. macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
  1859. saveLedState = REG_READ(ah, AR_CFG_LED) &
  1860. (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
  1861. AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
  1862. ath9k_hw_mark_phy_inactive(ah);
  1863. if (!ath9k_hw_chip_reset(ah, chan)) {
  1864. DPRINTF(ah->ah_sc, ATH_DBG_RESET, "chip reset failed\n");
  1865. return -EINVAL;
  1866. }
  1867. if (AR_SREV_9280_10_OR_LATER(ah))
  1868. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
  1869. r = ath9k_hw_process_ini(ah, chan, sc->tx_chan_width);
  1870. if (r)
  1871. return r;
  1872. /* Setup MFP options for CCMP */
  1873. if (AR_SREV_9280_20_OR_LATER(ah)) {
  1874. /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
  1875. * frames when constructing CCMP AAD. */
  1876. REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
  1877. 0xc7ff);
  1878. ah->sw_mgmt_crypto = false;
  1879. } else if (AR_SREV_9160_10_OR_LATER(ah)) {
  1880. /* Disable hardware crypto for management frames */
  1881. REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
  1882. AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
  1883. REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
  1884. AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
  1885. ah->sw_mgmt_crypto = true;
  1886. } else
  1887. ah->sw_mgmt_crypto = true;
  1888. if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
  1889. ath9k_hw_set_delta_slope(ah, chan);
  1890. if (AR_SREV_9280_10_OR_LATER(ah))
  1891. ath9k_hw_9280_spur_mitigate(ah, chan);
  1892. else
  1893. ath9k_hw_spur_mitigate(ah, chan);
  1894. if (!ath9k_hw_eeprom_set_board_values(ah, chan)) {
  1895. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  1896. "error setting board options\n");
  1897. return -EIO;
  1898. }
  1899. ath9k_hw_decrease_chain_power(ah, chan);
  1900. REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(ahp->ah_macaddr));
  1901. REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(ahp->ah_macaddr + 4)
  1902. | macStaId1
  1903. | AR_STA_ID1_RTS_USE_DEF
  1904. | (ah->ah_config.
  1905. ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
  1906. | ahp->ah_staId1Defaults);
  1907. ath9k_hw_set_operating_mode(ah, ah->ah_opmode);
  1908. REG_WRITE(ah, AR_BSSMSKL, get_unaligned_le32(ahp->ah_bssidmask));
  1909. REG_WRITE(ah, AR_BSSMSKU, get_unaligned_le16(ahp->ah_bssidmask + 4));
  1910. REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
  1911. REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(ahp->ah_bssid));
  1912. REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(ahp->ah_bssid + 4) |
  1913. ((ahp->ah_assocId & 0x3fff) << AR_BSS_ID1_AID_S));
  1914. REG_WRITE(ah, AR_ISR, ~0);
  1915. REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
  1916. if (AR_SREV_9280_10_OR_LATER(ah)) {
  1917. if (!(ath9k_hw_ar9280_set_channel(ah, chan)))
  1918. return -EIO;
  1919. } else {
  1920. if (!(ath9k_hw_set_channel(ah, chan)))
  1921. return -EIO;
  1922. }
  1923. for (i = 0; i < AR_NUM_DCU; i++)
  1924. REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
  1925. ahp->ah_intrTxqs = 0;
  1926. for (i = 0; i < ah->ah_caps.total_queues; i++)
  1927. ath9k_hw_resettxqueue(ah, i);
  1928. ath9k_hw_init_interrupt_masks(ah, ah->ah_opmode);
  1929. ath9k_hw_init_qos(ah);
  1930. #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
  1931. if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
  1932. ath9k_enable_rfkill(ah);
  1933. #endif
  1934. ath9k_hw_init_user_settings(ah);
  1935. REG_WRITE(ah, AR_STA_ID1,
  1936. REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
  1937. ath9k_hw_set_dma(ah);
  1938. REG_WRITE(ah, AR_OBS, 8);
  1939. if (ahp->ah_intrMitigation) {
  1940. REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
  1941. REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
  1942. }
  1943. ath9k_hw_init_bb(ah, chan);
  1944. if (!ath9k_hw_init_cal(ah, chan))
  1945. return -EIO;;
  1946. rx_chainmask = ahp->ah_rxchainmask;
  1947. if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
  1948. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
  1949. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
  1950. }
  1951. REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
  1952. if (AR_SREV_9100(ah)) {
  1953. u32 mask;
  1954. mask = REG_READ(ah, AR_CFG);
  1955. if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
  1956. DPRINTF(ah->ah_sc, ATH_DBG_RESET,
  1957. "CFG Byte Swap Set 0x%x\n", mask);
  1958. } else {
  1959. mask =
  1960. INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
  1961. REG_WRITE(ah, AR_CFG, mask);
  1962. DPRINTF(ah->ah_sc, ATH_DBG_RESET,
  1963. "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
  1964. }
  1965. } else {
  1966. #ifdef __BIG_ENDIAN
  1967. REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
  1968. #endif
  1969. }
  1970. return 0;
  1971. }
  1972. /************************/
  1973. /* Key Cache Management */
  1974. /************************/
  1975. bool ath9k_hw_keyreset(struct ath_hal *ah, u16 entry)
  1976. {
  1977. u32 keyType;
  1978. if (entry >= ah->ah_caps.keycache_size) {
  1979. DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
  1980. "entry %u out of range\n", entry);
  1981. return false;
  1982. }
  1983. keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
  1984. REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
  1985. REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
  1986. REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
  1987. REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
  1988. REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
  1989. REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
  1990. REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
  1991. REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
  1992. if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
  1993. u16 micentry = entry + 64;
  1994. REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
  1995. REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
  1996. REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
  1997. REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
  1998. }
  1999. if (ah->ah_curchan == NULL)
  2000. return true;
  2001. return true;
  2002. }
  2003. bool ath9k_hw_keysetmac(struct ath_hal *ah, u16 entry, const u8 *mac)
  2004. {
  2005. u32 macHi, macLo;
  2006. if (entry >= ah->ah_caps.keycache_size) {
  2007. DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
  2008. "entry %u out of range\n", entry);
  2009. return false;
  2010. }
  2011. if (mac != NULL) {
  2012. macHi = (mac[5] << 8) | mac[4];
  2013. macLo = (mac[3] << 24) |
  2014. (mac[2] << 16) |
  2015. (mac[1] << 8) |
  2016. mac[0];
  2017. macLo >>= 1;
  2018. macLo |= (macHi & 1) << 31;
  2019. macHi >>= 1;
  2020. } else {
  2021. macLo = macHi = 0;
  2022. }
  2023. REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
  2024. REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
  2025. return true;
  2026. }
  2027. bool ath9k_hw_set_keycache_entry(struct ath_hal *ah, u16 entry,
  2028. const struct ath9k_keyval *k,
  2029. const u8 *mac, int xorKey)
  2030. {
  2031. const struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
  2032. u32 key0, key1, key2, key3, key4;
  2033. u32 keyType;
  2034. u32 xorMask = xorKey ?
  2035. (ATH9K_KEY_XOR << 24 | ATH9K_KEY_XOR << 16 | ATH9K_KEY_XOR << 8
  2036. | ATH9K_KEY_XOR) : 0;
  2037. struct ath_hal_5416 *ahp = AH5416(ah);
  2038. if (entry >= pCap->keycache_size) {
  2039. DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
  2040. "entry %u out of range\n", entry);
  2041. return false;
  2042. }
  2043. switch (k->kv_type) {
  2044. case ATH9K_CIPHER_AES_OCB:
  2045. keyType = AR_KEYTABLE_TYPE_AES;
  2046. break;
  2047. case ATH9K_CIPHER_AES_CCM:
  2048. if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
  2049. DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
  2050. "AES-CCM not supported by mac rev 0x%x\n",
  2051. ah->ah_macRev);
  2052. return false;
  2053. }
  2054. keyType = AR_KEYTABLE_TYPE_CCM;
  2055. break;
  2056. case ATH9K_CIPHER_TKIP:
  2057. keyType = AR_KEYTABLE_TYPE_TKIP;
  2058. if (ATH9K_IS_MIC_ENABLED(ah)
  2059. && entry + 64 >= pCap->keycache_size) {
  2060. DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
  2061. "entry %u inappropriate for TKIP\n", entry);
  2062. return false;
  2063. }
  2064. break;
  2065. case ATH9K_CIPHER_WEP:
  2066. if (k->kv_len < LEN_WEP40) {
  2067. DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
  2068. "WEP key length %u too small\n", k->kv_len);
  2069. return false;
  2070. }
  2071. if (k->kv_len <= LEN_WEP40)
  2072. keyType = AR_KEYTABLE_TYPE_40;
  2073. else if (k->kv_len <= LEN_WEP104)
  2074. keyType = AR_KEYTABLE_TYPE_104;
  2075. else
  2076. keyType = AR_KEYTABLE_TYPE_128;
  2077. break;
  2078. case ATH9K_CIPHER_CLR:
  2079. keyType = AR_KEYTABLE_TYPE_CLR;
  2080. break;
  2081. default:
  2082. DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
  2083. "cipher %u not supported\n", k->kv_type);
  2084. return false;
  2085. }
  2086. key0 = get_unaligned_le32(k->kv_val + 0) ^ xorMask;
  2087. key1 = (get_unaligned_le16(k->kv_val + 4) ^ xorMask) & 0xffff;
  2088. key2 = get_unaligned_le32(k->kv_val + 6) ^ xorMask;
  2089. key3 = (get_unaligned_le16(k->kv_val + 10) ^ xorMask) & 0xffff;
  2090. key4 = get_unaligned_le32(k->kv_val + 12) ^ xorMask;
  2091. if (k->kv_len <= LEN_WEP104)
  2092. key4 &= 0xff;
  2093. if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
  2094. u16 micentry = entry + 64;
  2095. REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
  2096. REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
  2097. REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
  2098. REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
  2099. REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
  2100. REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
  2101. (void) ath9k_hw_keysetmac(ah, entry, mac);
  2102. if (ahp->ah_miscMode & AR_PCU_MIC_NEW_LOC_ENA) {
  2103. u32 mic0, mic1, mic2, mic3, mic4;
  2104. mic0 = get_unaligned_le32(k->kv_mic + 0);
  2105. mic2 = get_unaligned_le32(k->kv_mic + 4);
  2106. mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
  2107. mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
  2108. mic4 = get_unaligned_le32(k->kv_txmic + 4);
  2109. REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
  2110. REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
  2111. REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
  2112. REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
  2113. REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
  2114. REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
  2115. AR_KEYTABLE_TYPE_CLR);
  2116. } else {
  2117. u32 mic0, mic2;
  2118. mic0 = get_unaligned_le32(k->kv_mic + 0);
  2119. mic2 = get_unaligned_le32(k->kv_mic + 4);
  2120. REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
  2121. REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
  2122. REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
  2123. REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
  2124. REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
  2125. REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
  2126. AR_KEYTABLE_TYPE_CLR);
  2127. }
  2128. REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
  2129. REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
  2130. REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
  2131. REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
  2132. } else {
  2133. REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
  2134. REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
  2135. REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
  2136. REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
  2137. REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
  2138. REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
  2139. (void) ath9k_hw_keysetmac(ah, entry, mac);
  2140. }
  2141. if (ah->ah_curchan == NULL)
  2142. return true;
  2143. return true;
  2144. }
  2145. bool ath9k_hw_keyisvalid(struct ath_hal *ah, u16 entry)
  2146. {
  2147. if (entry < ah->ah_caps.keycache_size) {
  2148. u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
  2149. if (val & AR_KEYTABLE_VALID)
  2150. return true;
  2151. }
  2152. return false;
  2153. }
  2154. /******************************/
  2155. /* Power Management (Chipset) */
  2156. /******************************/
  2157. static void ath9k_set_power_sleep(struct ath_hal *ah, int setChip)
  2158. {
  2159. REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  2160. if (setChip) {
  2161. REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
  2162. AR_RTC_FORCE_WAKE_EN);
  2163. if (!AR_SREV_9100(ah))
  2164. REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
  2165. REG_CLR_BIT(ah, (AR_RTC_RESET),
  2166. AR_RTC_RESET_EN);
  2167. }
  2168. }
  2169. static void ath9k_set_power_network_sleep(struct ath_hal *ah, int setChip)
  2170. {
  2171. REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  2172. if (setChip) {
  2173. struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
  2174. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  2175. REG_WRITE(ah, AR_RTC_FORCE_WAKE,
  2176. AR_RTC_FORCE_WAKE_ON_INT);
  2177. } else {
  2178. REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
  2179. AR_RTC_FORCE_WAKE_EN);
  2180. }
  2181. }
  2182. }
  2183. static bool ath9k_hw_set_power_awake(struct ath_hal *ah,
  2184. int setChip)
  2185. {
  2186. u32 val;
  2187. int i;
  2188. if (setChip) {
  2189. if ((REG_READ(ah, AR_RTC_STATUS) &
  2190. AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
  2191. if (ath9k_hw_set_reset_reg(ah,
  2192. ATH9K_RESET_POWER_ON) != true) {
  2193. return false;
  2194. }
  2195. }
  2196. if (AR_SREV_9100(ah))
  2197. REG_SET_BIT(ah, AR_RTC_RESET,
  2198. AR_RTC_RESET_EN);
  2199. REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
  2200. AR_RTC_FORCE_WAKE_EN);
  2201. udelay(50);
  2202. for (i = POWER_UP_TIME / 50; i > 0; i--) {
  2203. val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
  2204. if (val == AR_RTC_STATUS_ON)
  2205. break;
  2206. udelay(50);
  2207. REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
  2208. AR_RTC_FORCE_WAKE_EN);
  2209. }
  2210. if (i == 0) {
  2211. DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
  2212. "Failed to wakeup in %uus\n", POWER_UP_TIME / 20);
  2213. return false;
  2214. }
  2215. }
  2216. REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  2217. return true;
  2218. }
  2219. bool ath9k_hw_setpower(struct ath_hal *ah,
  2220. enum ath9k_power_mode mode)
  2221. {
  2222. struct ath_hal_5416 *ahp = AH5416(ah);
  2223. static const char *modes[] = {
  2224. "AWAKE",
  2225. "FULL-SLEEP",
  2226. "NETWORK SLEEP",
  2227. "UNDEFINED"
  2228. };
  2229. int status = true, setChip = true;
  2230. DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, "%s -> %s (%s)\n",
  2231. modes[ah->ah_power_mode], modes[mode],
  2232. setChip ? "set chip " : "");
  2233. switch (mode) {
  2234. case ATH9K_PM_AWAKE:
  2235. status = ath9k_hw_set_power_awake(ah, setChip);
  2236. break;
  2237. case ATH9K_PM_FULL_SLEEP:
  2238. ath9k_set_power_sleep(ah, setChip);
  2239. ahp->ah_chipFullSleep = true;
  2240. break;
  2241. case ATH9K_PM_NETWORK_SLEEP:
  2242. ath9k_set_power_network_sleep(ah, setChip);
  2243. break;
  2244. default:
  2245. DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
  2246. "Unknown power mode %u\n", mode);
  2247. return false;
  2248. }
  2249. ah->ah_power_mode = mode;
  2250. return status;
  2251. }
  2252. void ath9k_hw_configpcipowersave(struct ath_hal *ah, int restore)
  2253. {
  2254. struct ath_hal_5416 *ahp = AH5416(ah);
  2255. u8 i;
  2256. if (ah->ah_isPciExpress != true)
  2257. return;
  2258. if (ah->ah_config.pcie_powersave_enable == 2)
  2259. return;
  2260. if (restore)
  2261. return;
  2262. if (AR_SREV_9280_20_OR_LATER(ah)) {
  2263. for (i = 0; i < ahp->ah_iniPcieSerdes.ia_rows; i++) {
  2264. REG_WRITE(ah, INI_RA(&ahp->ah_iniPcieSerdes, i, 0),
  2265. INI_RA(&ahp->ah_iniPcieSerdes, i, 1));
  2266. }
  2267. udelay(1000);
  2268. } else if (AR_SREV_9280(ah) &&
  2269. (ah->ah_macRev == AR_SREV_REVISION_9280_10)) {
  2270. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
  2271. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  2272. REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
  2273. REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
  2274. REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
  2275. if (ah->ah_config.pcie_clock_req)
  2276. REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
  2277. else
  2278. REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
  2279. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  2280. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  2281. REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
  2282. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  2283. udelay(1000);
  2284. } else {
  2285. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
  2286. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  2287. REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
  2288. REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
  2289. REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
  2290. REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
  2291. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  2292. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  2293. REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
  2294. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  2295. }
  2296. REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
  2297. if (ah->ah_config.pcie_waen) {
  2298. REG_WRITE(ah, AR_WA, ah->ah_config.pcie_waen);
  2299. } else {
  2300. if (AR_SREV_9285(ah))
  2301. REG_WRITE(ah, AR_WA, AR9285_WA_DEFAULT);
  2302. else if (AR_SREV_9280(ah))
  2303. REG_WRITE(ah, AR_WA, AR9280_WA_DEFAULT);
  2304. else
  2305. REG_WRITE(ah, AR_WA, AR_WA_DEFAULT);
  2306. }
  2307. }
  2308. /**********************/
  2309. /* Interrupt Handling */
  2310. /**********************/
  2311. bool ath9k_hw_intrpend(struct ath_hal *ah)
  2312. {
  2313. u32 host_isr;
  2314. if (AR_SREV_9100(ah))
  2315. return true;
  2316. host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
  2317. if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
  2318. return true;
  2319. host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
  2320. if ((host_isr & AR_INTR_SYNC_DEFAULT)
  2321. && (host_isr != AR_INTR_SPURIOUS))
  2322. return true;
  2323. return false;
  2324. }
  2325. bool ath9k_hw_getisr(struct ath_hal *ah, enum ath9k_int *masked)
  2326. {
  2327. u32 isr = 0;
  2328. u32 mask2 = 0;
  2329. struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
  2330. u32 sync_cause = 0;
  2331. bool fatal_int = false;
  2332. struct ath_hal_5416 *ahp = AH5416(ah);
  2333. if (!AR_SREV_9100(ah)) {
  2334. if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
  2335. if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
  2336. == AR_RTC_STATUS_ON) {
  2337. isr = REG_READ(ah, AR_ISR);
  2338. }
  2339. }
  2340. sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
  2341. AR_INTR_SYNC_DEFAULT;
  2342. *masked = 0;
  2343. if (!isr && !sync_cause)
  2344. return false;
  2345. } else {
  2346. *masked = 0;
  2347. isr = REG_READ(ah, AR_ISR);
  2348. }
  2349. if (isr) {
  2350. if (isr & AR_ISR_BCNMISC) {
  2351. u32 isr2;
  2352. isr2 = REG_READ(ah, AR_ISR_S2);
  2353. if (isr2 & AR_ISR_S2_TIM)
  2354. mask2 |= ATH9K_INT_TIM;
  2355. if (isr2 & AR_ISR_S2_DTIM)
  2356. mask2 |= ATH9K_INT_DTIM;
  2357. if (isr2 & AR_ISR_S2_DTIMSYNC)
  2358. mask2 |= ATH9K_INT_DTIMSYNC;
  2359. if (isr2 & (AR_ISR_S2_CABEND))
  2360. mask2 |= ATH9K_INT_CABEND;
  2361. if (isr2 & AR_ISR_S2_GTT)
  2362. mask2 |= ATH9K_INT_GTT;
  2363. if (isr2 & AR_ISR_S2_CST)
  2364. mask2 |= ATH9K_INT_CST;
  2365. }
  2366. isr = REG_READ(ah, AR_ISR_RAC);
  2367. if (isr == 0xffffffff) {
  2368. *masked = 0;
  2369. return false;
  2370. }
  2371. *masked = isr & ATH9K_INT_COMMON;
  2372. if (ahp->ah_intrMitigation) {
  2373. if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
  2374. *masked |= ATH9K_INT_RX;
  2375. }
  2376. if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
  2377. *masked |= ATH9K_INT_RX;
  2378. if (isr &
  2379. (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
  2380. AR_ISR_TXEOL)) {
  2381. u32 s0_s, s1_s;
  2382. *masked |= ATH9K_INT_TX;
  2383. s0_s = REG_READ(ah, AR_ISR_S0_S);
  2384. ahp->ah_intrTxqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
  2385. ahp->ah_intrTxqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
  2386. s1_s = REG_READ(ah, AR_ISR_S1_S);
  2387. ahp->ah_intrTxqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
  2388. ahp->ah_intrTxqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
  2389. }
  2390. if (isr & AR_ISR_RXORN) {
  2391. DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
  2392. "receive FIFO overrun interrupt\n");
  2393. }
  2394. if (!AR_SREV_9100(ah)) {
  2395. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  2396. u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
  2397. if (isr5 & AR_ISR_S5_TIM_TIMER)
  2398. *masked |= ATH9K_INT_TIM_TIMER;
  2399. }
  2400. }
  2401. *masked |= mask2;
  2402. }
  2403. if (AR_SREV_9100(ah))
  2404. return true;
  2405. if (sync_cause) {
  2406. fatal_int =
  2407. (sync_cause &
  2408. (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
  2409. ? true : false;
  2410. if (fatal_int) {
  2411. if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
  2412. DPRINTF(ah->ah_sc, ATH_DBG_ANY,
  2413. "received PCI FATAL interrupt\n");
  2414. }
  2415. if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
  2416. DPRINTF(ah->ah_sc, ATH_DBG_ANY,
  2417. "received PCI PERR interrupt\n");
  2418. }
  2419. }
  2420. if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
  2421. DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
  2422. "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
  2423. REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
  2424. REG_WRITE(ah, AR_RC, 0);
  2425. *masked |= ATH9K_INT_FATAL;
  2426. }
  2427. if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
  2428. DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
  2429. "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
  2430. }
  2431. REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
  2432. (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
  2433. }
  2434. return true;
  2435. }
  2436. enum ath9k_int ath9k_hw_intrget(struct ath_hal *ah)
  2437. {
  2438. return AH5416(ah)->ah_maskReg;
  2439. }
  2440. enum ath9k_int ath9k_hw_set_interrupts(struct ath_hal *ah, enum ath9k_int ints)
  2441. {
  2442. struct ath_hal_5416 *ahp = AH5416(ah);
  2443. u32 omask = ahp->ah_maskReg;
  2444. u32 mask, mask2;
  2445. struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
  2446. DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
  2447. if (omask & ATH9K_INT_GLOBAL) {
  2448. DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "disable IER\n");
  2449. REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
  2450. (void) REG_READ(ah, AR_IER);
  2451. if (!AR_SREV_9100(ah)) {
  2452. REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
  2453. (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
  2454. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
  2455. (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
  2456. }
  2457. }
  2458. mask = ints & ATH9K_INT_COMMON;
  2459. mask2 = 0;
  2460. if (ints & ATH9K_INT_TX) {
  2461. if (ahp->ah_txOkInterruptMask)
  2462. mask |= AR_IMR_TXOK;
  2463. if (ahp->ah_txDescInterruptMask)
  2464. mask |= AR_IMR_TXDESC;
  2465. if (ahp->ah_txErrInterruptMask)
  2466. mask |= AR_IMR_TXERR;
  2467. if (ahp->ah_txEolInterruptMask)
  2468. mask |= AR_IMR_TXEOL;
  2469. }
  2470. if (ints & ATH9K_INT_RX) {
  2471. mask |= AR_IMR_RXERR;
  2472. if (ahp->ah_intrMitigation)
  2473. mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
  2474. else
  2475. mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
  2476. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  2477. mask |= AR_IMR_GENTMR;
  2478. }
  2479. if (ints & (ATH9K_INT_BMISC)) {
  2480. mask |= AR_IMR_BCNMISC;
  2481. if (ints & ATH9K_INT_TIM)
  2482. mask2 |= AR_IMR_S2_TIM;
  2483. if (ints & ATH9K_INT_DTIM)
  2484. mask2 |= AR_IMR_S2_DTIM;
  2485. if (ints & ATH9K_INT_DTIMSYNC)
  2486. mask2 |= AR_IMR_S2_DTIMSYNC;
  2487. if (ints & ATH9K_INT_CABEND)
  2488. mask2 |= (AR_IMR_S2_CABEND);
  2489. }
  2490. if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
  2491. mask |= AR_IMR_BCNMISC;
  2492. if (ints & ATH9K_INT_GTT)
  2493. mask2 |= AR_IMR_S2_GTT;
  2494. if (ints & ATH9K_INT_CST)
  2495. mask2 |= AR_IMR_S2_CST;
  2496. }
  2497. DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
  2498. REG_WRITE(ah, AR_IMR, mask);
  2499. mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
  2500. AR_IMR_S2_DTIM |
  2501. AR_IMR_S2_DTIMSYNC |
  2502. AR_IMR_S2_CABEND |
  2503. AR_IMR_S2_CABTO |
  2504. AR_IMR_S2_TSFOOR |
  2505. AR_IMR_S2_GTT | AR_IMR_S2_CST);
  2506. REG_WRITE(ah, AR_IMR_S2, mask | mask2);
  2507. ahp->ah_maskReg = ints;
  2508. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  2509. if (ints & ATH9K_INT_TIM_TIMER)
  2510. REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
  2511. else
  2512. REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
  2513. }
  2514. if (ints & ATH9K_INT_GLOBAL) {
  2515. DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "enable IER\n");
  2516. REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
  2517. if (!AR_SREV_9100(ah)) {
  2518. REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
  2519. AR_INTR_MAC_IRQ);
  2520. REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
  2521. REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
  2522. AR_INTR_SYNC_DEFAULT);
  2523. REG_WRITE(ah, AR_INTR_SYNC_MASK,
  2524. AR_INTR_SYNC_DEFAULT);
  2525. }
  2526. DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
  2527. REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
  2528. }
  2529. return omask;
  2530. }
  2531. /*******************/
  2532. /* Beacon Handling */
  2533. /*******************/
  2534. void ath9k_hw_beaconinit(struct ath_hal *ah, u32 next_beacon, u32 beacon_period)
  2535. {
  2536. struct ath_hal_5416 *ahp = AH5416(ah);
  2537. int flags = 0;
  2538. ahp->ah_beaconInterval = beacon_period;
  2539. switch (ah->ah_opmode) {
  2540. case NL80211_IFTYPE_STATION:
  2541. case NL80211_IFTYPE_MONITOR:
  2542. REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
  2543. REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
  2544. REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
  2545. flags |= AR_TBTT_TIMER_EN;
  2546. break;
  2547. case NL80211_IFTYPE_ADHOC:
  2548. REG_SET_BIT(ah, AR_TXCFG,
  2549. AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
  2550. REG_WRITE(ah, AR_NEXT_NDP_TIMER,
  2551. TU_TO_USEC(next_beacon +
  2552. (ahp->ah_atimWindow ? ahp->
  2553. ah_atimWindow : 1)));
  2554. flags |= AR_NDP_TIMER_EN;
  2555. case NL80211_IFTYPE_AP:
  2556. REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
  2557. REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
  2558. TU_TO_USEC(next_beacon -
  2559. ah->ah_config.
  2560. dma_beacon_response_time));
  2561. REG_WRITE(ah, AR_NEXT_SWBA,
  2562. TU_TO_USEC(next_beacon -
  2563. ah->ah_config.
  2564. sw_beacon_response_time));
  2565. flags |=
  2566. AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
  2567. break;
  2568. default:
  2569. DPRINTF(ah->ah_sc, ATH_DBG_BEACON,
  2570. "%s: unsupported opmode: %d\n",
  2571. __func__, ah->ah_opmode);
  2572. return;
  2573. break;
  2574. }
  2575. REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
  2576. REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
  2577. REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
  2578. REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
  2579. beacon_period &= ~ATH9K_BEACON_ENA;
  2580. if (beacon_period & ATH9K_BEACON_RESET_TSF) {
  2581. beacon_period &= ~ATH9K_BEACON_RESET_TSF;
  2582. ath9k_hw_reset_tsf(ah);
  2583. }
  2584. REG_SET_BIT(ah, AR_TIMER_MODE, flags);
  2585. }
  2586. void ath9k_hw_set_sta_beacon_timers(struct ath_hal *ah,
  2587. const struct ath9k_beacon_state *bs)
  2588. {
  2589. u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
  2590. struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
  2591. REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
  2592. REG_WRITE(ah, AR_BEACON_PERIOD,
  2593. TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
  2594. REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
  2595. TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
  2596. REG_RMW_FIELD(ah, AR_RSSI_THR,
  2597. AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
  2598. beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
  2599. if (bs->bs_sleepduration > beaconintval)
  2600. beaconintval = bs->bs_sleepduration;
  2601. dtimperiod = bs->bs_dtimperiod;
  2602. if (bs->bs_sleepduration > dtimperiod)
  2603. dtimperiod = bs->bs_sleepduration;
  2604. if (beaconintval == dtimperiod)
  2605. nextTbtt = bs->bs_nextdtim;
  2606. else
  2607. nextTbtt = bs->bs_nexttbtt;
  2608. DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
  2609. DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
  2610. DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
  2611. DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
  2612. REG_WRITE(ah, AR_NEXT_DTIM,
  2613. TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
  2614. REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
  2615. REG_WRITE(ah, AR_SLEEP1,
  2616. SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
  2617. | AR_SLEEP1_ASSUME_DTIM);
  2618. if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
  2619. beacontimeout = (BEACON_TIMEOUT_VAL << 3);
  2620. else
  2621. beacontimeout = MIN_BEACON_TIMEOUT_VAL;
  2622. REG_WRITE(ah, AR_SLEEP2,
  2623. SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
  2624. REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
  2625. REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
  2626. REG_SET_BIT(ah, AR_TIMER_MODE,
  2627. AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
  2628. AR_DTIM_TIMER_EN);
  2629. }
  2630. /*******************/
  2631. /* HW Capabilities */
  2632. /*******************/
  2633. bool ath9k_hw_fill_cap_info(struct ath_hal *ah)
  2634. {
  2635. struct ath_hal_5416 *ahp = AH5416(ah);
  2636. struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
  2637. u16 capField = 0, eeval;
  2638. eeval = ath9k_hw_get_eeprom(ah, EEP_REG_0);
  2639. ah->ah_currentRD = eeval;
  2640. eeval = ath9k_hw_get_eeprom(ah, EEP_REG_1);
  2641. ah->ah_currentRDExt = eeval;
  2642. capField = ath9k_hw_get_eeprom(ah, EEP_OP_CAP);
  2643. if (ah->ah_opmode != NL80211_IFTYPE_AP &&
  2644. ah->ah_subvendorid == AR_SUBVENDOR_ID_NEW_A) {
  2645. if (ah->ah_currentRD == 0x64 || ah->ah_currentRD == 0x65)
  2646. ah->ah_currentRD += 5;
  2647. else if (ah->ah_currentRD == 0x41)
  2648. ah->ah_currentRD = 0x43;
  2649. DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY,
  2650. "regdomain mapped to 0x%x\n", ah->ah_currentRD);
  2651. }
  2652. eeval = ath9k_hw_get_eeprom(ah, EEP_OP_MODE);
  2653. bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
  2654. if (eeval & AR5416_OPFLAGS_11A) {
  2655. set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
  2656. if (ah->ah_config.ht_enable) {
  2657. if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
  2658. set_bit(ATH9K_MODE_11NA_HT20,
  2659. pCap->wireless_modes);
  2660. if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
  2661. set_bit(ATH9K_MODE_11NA_HT40PLUS,
  2662. pCap->wireless_modes);
  2663. set_bit(ATH9K_MODE_11NA_HT40MINUS,
  2664. pCap->wireless_modes);
  2665. }
  2666. }
  2667. }
  2668. if (eeval & AR5416_OPFLAGS_11G) {
  2669. set_bit(ATH9K_MODE_11B, pCap->wireless_modes);
  2670. set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
  2671. if (ah->ah_config.ht_enable) {
  2672. if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
  2673. set_bit(ATH9K_MODE_11NG_HT20,
  2674. pCap->wireless_modes);
  2675. if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
  2676. set_bit(ATH9K_MODE_11NG_HT40PLUS,
  2677. pCap->wireless_modes);
  2678. set_bit(ATH9K_MODE_11NG_HT40MINUS,
  2679. pCap->wireless_modes);
  2680. }
  2681. }
  2682. }
  2683. pCap->tx_chainmask = ath9k_hw_get_eeprom(ah, EEP_TX_MASK);
  2684. if ((ah->ah_isPciExpress)
  2685. || (eeval & AR5416_OPFLAGS_11A)) {
  2686. pCap->rx_chainmask =
  2687. ath9k_hw_get_eeprom(ah, EEP_RX_MASK);
  2688. } else {
  2689. pCap->rx_chainmask =
  2690. (ath9k_hw_gpio_get(ah, 0)) ? 0x5 : 0x7;
  2691. }
  2692. if (!(AR_SREV_9280(ah) && (ah->ah_macRev == 0)))
  2693. ahp->ah_miscMode |= AR_PCU_MIC_NEW_LOC_ENA;
  2694. pCap->low_2ghz_chan = 2312;
  2695. pCap->high_2ghz_chan = 2732;
  2696. pCap->low_5ghz_chan = 4920;
  2697. pCap->high_5ghz_chan = 6100;
  2698. pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
  2699. pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
  2700. pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
  2701. pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
  2702. pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
  2703. pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
  2704. pCap->hw_caps |= ATH9K_HW_CAP_CHAN_SPREAD;
  2705. if (ah->ah_config.ht_enable)
  2706. pCap->hw_caps |= ATH9K_HW_CAP_HT;
  2707. else
  2708. pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
  2709. pCap->hw_caps |= ATH9K_HW_CAP_GTT;
  2710. pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
  2711. pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
  2712. pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
  2713. if (capField & AR_EEPROM_EEPCAP_MAXQCU)
  2714. pCap->total_queues =
  2715. MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
  2716. else
  2717. pCap->total_queues = ATH9K_NUM_TX_QUEUES;
  2718. if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
  2719. pCap->keycache_size =
  2720. 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
  2721. else
  2722. pCap->keycache_size = AR_KEYTABLE_SIZE;
  2723. pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
  2724. pCap->num_mr_retries = 4;
  2725. pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
  2726. if (AR_SREV_9285_10_OR_LATER(ah))
  2727. pCap->num_gpio_pins = AR9285_NUM_GPIO;
  2728. else if (AR_SREV_9280_10_OR_LATER(ah))
  2729. pCap->num_gpio_pins = AR928X_NUM_GPIO;
  2730. else
  2731. pCap->num_gpio_pins = AR_NUM_GPIO;
  2732. if (AR_SREV_9280_10_OR_LATER(ah)) {
  2733. pCap->hw_caps |= ATH9K_HW_CAP_WOW;
  2734. pCap->hw_caps |= ATH9K_HW_CAP_WOW_MATCHPATTERN_EXACT;
  2735. } else {
  2736. pCap->hw_caps &= ~ATH9K_HW_CAP_WOW;
  2737. pCap->hw_caps &= ~ATH9K_HW_CAP_WOW_MATCHPATTERN_EXACT;
  2738. }
  2739. if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
  2740. pCap->hw_caps |= ATH9K_HW_CAP_CST;
  2741. pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
  2742. } else {
  2743. pCap->rts_aggr_limit = (8 * 1024);
  2744. }
  2745. pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
  2746. #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
  2747. ah->ah_rfsilent = ath9k_hw_get_eeprom(ah, EEP_RF_SILENT);
  2748. if (ah->ah_rfsilent & EEP_RFSILENT_ENABLED) {
  2749. ah->ah_rfkill_gpio =
  2750. MS(ah->ah_rfsilent, EEP_RFSILENT_GPIO_SEL);
  2751. ah->ah_rfkill_polarity =
  2752. MS(ah->ah_rfsilent, EEP_RFSILENT_POLARITY);
  2753. pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
  2754. }
  2755. #endif
  2756. if ((ah->ah_macVersion == AR_SREV_VERSION_5416_PCI) ||
  2757. (ah->ah_macVersion == AR_SREV_VERSION_5416_PCIE) ||
  2758. (ah->ah_macVersion == AR_SREV_VERSION_9160) ||
  2759. (ah->ah_macVersion == AR_SREV_VERSION_9100) ||
  2760. (ah->ah_macVersion == AR_SREV_VERSION_9280))
  2761. pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
  2762. else
  2763. pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
  2764. if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
  2765. pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
  2766. else
  2767. pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
  2768. if (ah->ah_currentRDExt & (1 << REG_EXT_JAPAN_MIDBAND)) {
  2769. pCap->reg_cap =
  2770. AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
  2771. AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
  2772. AR_EEPROM_EEREGCAP_EN_KK_U2 |
  2773. AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
  2774. } else {
  2775. pCap->reg_cap =
  2776. AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
  2777. AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
  2778. }
  2779. pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
  2780. pCap->num_antcfg_5ghz =
  2781. ath9k_hw_get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
  2782. pCap->num_antcfg_2ghz =
  2783. ath9k_hw_get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
  2784. if (AR_SREV_9280_10_OR_LATER(ah) && btcoex_enable) {
  2785. pCap->hw_caps |= ATH9K_HW_CAP_BT_COEX;
  2786. ah->ah_btactive_gpio = 6;
  2787. ah->ah_wlanactive_gpio = 5;
  2788. }
  2789. return true;
  2790. }
  2791. bool ath9k_hw_getcapability(struct ath_hal *ah, enum ath9k_capability_type type,
  2792. u32 capability, u32 *result)
  2793. {
  2794. struct ath_hal_5416 *ahp = AH5416(ah);
  2795. const struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
  2796. switch (type) {
  2797. case ATH9K_CAP_CIPHER:
  2798. switch (capability) {
  2799. case ATH9K_CIPHER_AES_CCM:
  2800. case ATH9K_CIPHER_AES_OCB:
  2801. case ATH9K_CIPHER_TKIP:
  2802. case ATH9K_CIPHER_WEP:
  2803. case ATH9K_CIPHER_MIC:
  2804. case ATH9K_CIPHER_CLR:
  2805. return true;
  2806. default:
  2807. return false;
  2808. }
  2809. case ATH9K_CAP_TKIP_MIC:
  2810. switch (capability) {
  2811. case 0:
  2812. return true;
  2813. case 1:
  2814. return (ahp->ah_staId1Defaults &
  2815. AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
  2816. false;
  2817. }
  2818. case ATH9K_CAP_TKIP_SPLIT:
  2819. return (ahp->ah_miscMode & AR_PCU_MIC_NEW_LOC_ENA) ?
  2820. false : true;
  2821. case ATH9K_CAP_WME_TKIPMIC:
  2822. return 0;
  2823. case ATH9K_CAP_PHYCOUNTERS:
  2824. return ahp->ah_hasHwPhyCounters ? 0 : -ENXIO;
  2825. case ATH9K_CAP_DIVERSITY:
  2826. return (REG_READ(ah, AR_PHY_CCK_DETECT) &
  2827. AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
  2828. true : false;
  2829. case ATH9K_CAP_PHYDIAG:
  2830. return true;
  2831. case ATH9K_CAP_MCAST_KEYSRCH:
  2832. switch (capability) {
  2833. case 0:
  2834. return true;
  2835. case 1:
  2836. if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
  2837. return false;
  2838. } else {
  2839. return (ahp->ah_staId1Defaults &
  2840. AR_STA_ID1_MCAST_KSRCH) ? true :
  2841. false;
  2842. }
  2843. }
  2844. return false;
  2845. case ATH9K_CAP_TSF_ADJUST:
  2846. return (ahp->ah_miscMode & AR_PCU_TX_ADD_TSF) ?
  2847. true : false;
  2848. case ATH9K_CAP_RFSILENT:
  2849. if (capability == 3)
  2850. return false;
  2851. case ATH9K_CAP_ANT_CFG_2GHZ:
  2852. *result = pCap->num_antcfg_2ghz;
  2853. return true;
  2854. case ATH9K_CAP_ANT_CFG_5GHZ:
  2855. *result = pCap->num_antcfg_5ghz;
  2856. return true;
  2857. case ATH9K_CAP_TXPOW:
  2858. switch (capability) {
  2859. case 0:
  2860. return 0;
  2861. case 1:
  2862. *result = ah->ah_powerLimit;
  2863. return 0;
  2864. case 2:
  2865. *result = ah->ah_maxPowerLevel;
  2866. return 0;
  2867. case 3:
  2868. *result = ah->ah_tpScale;
  2869. return 0;
  2870. }
  2871. return false;
  2872. default:
  2873. return false;
  2874. }
  2875. }
  2876. bool ath9k_hw_setcapability(struct ath_hal *ah, enum ath9k_capability_type type,
  2877. u32 capability, u32 setting, int *status)
  2878. {
  2879. struct ath_hal_5416 *ahp = AH5416(ah);
  2880. u32 v;
  2881. switch (type) {
  2882. case ATH9K_CAP_TKIP_MIC:
  2883. if (setting)
  2884. ahp->ah_staId1Defaults |=
  2885. AR_STA_ID1_CRPT_MIC_ENABLE;
  2886. else
  2887. ahp->ah_staId1Defaults &=
  2888. ~AR_STA_ID1_CRPT_MIC_ENABLE;
  2889. return true;
  2890. case ATH9K_CAP_DIVERSITY:
  2891. v = REG_READ(ah, AR_PHY_CCK_DETECT);
  2892. if (setting)
  2893. v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
  2894. else
  2895. v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
  2896. REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
  2897. return true;
  2898. case ATH9K_CAP_MCAST_KEYSRCH:
  2899. if (setting)
  2900. ahp->ah_staId1Defaults |= AR_STA_ID1_MCAST_KSRCH;
  2901. else
  2902. ahp->ah_staId1Defaults &= ~AR_STA_ID1_MCAST_KSRCH;
  2903. return true;
  2904. case ATH9K_CAP_TSF_ADJUST:
  2905. if (setting)
  2906. ahp->ah_miscMode |= AR_PCU_TX_ADD_TSF;
  2907. else
  2908. ahp->ah_miscMode &= ~AR_PCU_TX_ADD_TSF;
  2909. return true;
  2910. default:
  2911. return false;
  2912. }
  2913. }
  2914. /****************************/
  2915. /* GPIO / RFKILL / Antennae */
  2916. /****************************/
  2917. static void ath9k_hw_gpio_cfg_output_mux(struct ath_hal *ah,
  2918. u32 gpio, u32 type)
  2919. {
  2920. int addr;
  2921. u32 gpio_shift, tmp;
  2922. if (gpio > 11)
  2923. addr = AR_GPIO_OUTPUT_MUX3;
  2924. else if (gpio > 5)
  2925. addr = AR_GPIO_OUTPUT_MUX2;
  2926. else
  2927. addr = AR_GPIO_OUTPUT_MUX1;
  2928. gpio_shift = (gpio % 6) * 5;
  2929. if (AR_SREV_9280_20_OR_LATER(ah)
  2930. || (addr != AR_GPIO_OUTPUT_MUX1)) {
  2931. REG_RMW(ah, addr, (type << gpio_shift),
  2932. (0x1f << gpio_shift));
  2933. } else {
  2934. tmp = REG_READ(ah, addr);
  2935. tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
  2936. tmp &= ~(0x1f << gpio_shift);
  2937. tmp |= (type << gpio_shift);
  2938. REG_WRITE(ah, addr, tmp);
  2939. }
  2940. }
  2941. void ath9k_hw_cfg_gpio_input(struct ath_hal *ah, u32 gpio)
  2942. {
  2943. u32 gpio_shift;
  2944. ASSERT(gpio < ah->ah_caps.num_gpio_pins);
  2945. gpio_shift = gpio << 1;
  2946. REG_RMW(ah,
  2947. AR_GPIO_OE_OUT,
  2948. (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
  2949. (AR_GPIO_OE_OUT_DRV << gpio_shift));
  2950. }
  2951. u32 ath9k_hw_gpio_get(struct ath_hal *ah, u32 gpio)
  2952. {
  2953. #define MS_REG_READ(x, y) \
  2954. (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
  2955. if (gpio >= ah->ah_caps.num_gpio_pins)
  2956. return 0xffffffff;
  2957. if (AR_SREV_9285_10_OR_LATER(ah))
  2958. return MS_REG_READ(AR9285, gpio) != 0;
  2959. else if (AR_SREV_9280_10_OR_LATER(ah))
  2960. return MS_REG_READ(AR928X, gpio) != 0;
  2961. else
  2962. return MS_REG_READ(AR, gpio) != 0;
  2963. }
  2964. void ath9k_hw_cfg_output(struct ath_hal *ah, u32 gpio,
  2965. u32 ah_signal_type)
  2966. {
  2967. u32 gpio_shift;
  2968. ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
  2969. gpio_shift = 2 * gpio;
  2970. REG_RMW(ah,
  2971. AR_GPIO_OE_OUT,
  2972. (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
  2973. (AR_GPIO_OE_OUT_DRV << gpio_shift));
  2974. }
  2975. void ath9k_hw_set_gpio(struct ath_hal *ah, u32 gpio, u32 val)
  2976. {
  2977. REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
  2978. AR_GPIO_BIT(gpio));
  2979. }
  2980. #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
  2981. void ath9k_enable_rfkill(struct ath_hal *ah)
  2982. {
  2983. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
  2984. AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
  2985. REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
  2986. AR_GPIO_INPUT_MUX2_RFSILENT);
  2987. ath9k_hw_cfg_gpio_input(ah, ah->ah_rfkill_gpio);
  2988. REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
  2989. }
  2990. #endif
  2991. u32 ath9k_hw_getdefantenna(struct ath_hal *ah)
  2992. {
  2993. return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
  2994. }
  2995. void ath9k_hw_setantenna(struct ath_hal *ah, u32 antenna)
  2996. {
  2997. REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
  2998. }
  2999. bool ath9k_hw_setantennaswitch(struct ath_hal *ah,
  3000. enum ath9k_ant_setting settings,
  3001. struct ath9k_channel *chan,
  3002. u8 *tx_chainmask,
  3003. u8 *rx_chainmask,
  3004. u8 *antenna_cfgd)
  3005. {
  3006. struct ath_hal_5416 *ahp = AH5416(ah);
  3007. static u8 tx_chainmask_cfg, rx_chainmask_cfg;
  3008. if (AR_SREV_9280(ah)) {
  3009. if (!tx_chainmask_cfg) {
  3010. tx_chainmask_cfg = *tx_chainmask;
  3011. rx_chainmask_cfg = *rx_chainmask;
  3012. }
  3013. switch (settings) {
  3014. case ATH9K_ANT_FIXED_A:
  3015. *tx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
  3016. *rx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
  3017. *antenna_cfgd = true;
  3018. break;
  3019. case ATH9K_ANT_FIXED_B:
  3020. if (ah->ah_caps.tx_chainmask >
  3021. ATH9K_ANTENNA1_CHAINMASK) {
  3022. *tx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
  3023. }
  3024. *rx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
  3025. *antenna_cfgd = true;
  3026. break;
  3027. case ATH9K_ANT_VARIABLE:
  3028. *tx_chainmask = tx_chainmask_cfg;
  3029. *rx_chainmask = rx_chainmask_cfg;
  3030. *antenna_cfgd = true;
  3031. break;
  3032. default:
  3033. break;
  3034. }
  3035. } else {
  3036. ahp->ah_diversityControl = settings;
  3037. }
  3038. return true;
  3039. }
  3040. /*********************/
  3041. /* General Operation */
  3042. /*********************/
  3043. u32 ath9k_hw_getrxfilter(struct ath_hal *ah)
  3044. {
  3045. u32 bits = REG_READ(ah, AR_RX_FILTER);
  3046. u32 phybits = REG_READ(ah, AR_PHY_ERR);
  3047. if (phybits & AR_PHY_ERR_RADAR)
  3048. bits |= ATH9K_RX_FILTER_PHYRADAR;
  3049. if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
  3050. bits |= ATH9K_RX_FILTER_PHYERR;
  3051. return bits;
  3052. }
  3053. void ath9k_hw_setrxfilter(struct ath_hal *ah, u32 bits)
  3054. {
  3055. u32 phybits;
  3056. REG_WRITE(ah, AR_RX_FILTER, (bits & 0xffff) | AR_RX_COMPR_BAR);
  3057. phybits = 0;
  3058. if (bits & ATH9K_RX_FILTER_PHYRADAR)
  3059. phybits |= AR_PHY_ERR_RADAR;
  3060. if (bits & ATH9K_RX_FILTER_PHYERR)
  3061. phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
  3062. REG_WRITE(ah, AR_PHY_ERR, phybits);
  3063. if (phybits)
  3064. REG_WRITE(ah, AR_RXCFG,
  3065. REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
  3066. else
  3067. REG_WRITE(ah, AR_RXCFG,
  3068. REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
  3069. }
  3070. bool ath9k_hw_phy_disable(struct ath_hal *ah)
  3071. {
  3072. return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM);
  3073. }
  3074. bool ath9k_hw_disable(struct ath_hal *ah)
  3075. {
  3076. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  3077. return false;
  3078. return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD);
  3079. }
  3080. bool ath9k_hw_set_txpowerlimit(struct ath_hal *ah, u32 limit)
  3081. {
  3082. struct ath9k_channel *chan = ah->ah_curchan;
  3083. struct ieee80211_channel *channel = chan->chan;
  3084. ah->ah_powerLimit = min(limit, (u32) MAX_RATE_POWER);
  3085. if (ath9k_hw_set_txpower(ah, chan,
  3086. ath9k_regd_get_ctl(ah, chan),
  3087. channel->max_antenna_gain * 2,
  3088. channel->max_power * 2,
  3089. min((u32) MAX_RATE_POWER,
  3090. (u32) ah->ah_powerLimit)) != 0)
  3091. return false;
  3092. return true;
  3093. }
  3094. void ath9k_hw_getmac(struct ath_hal *ah, u8 *mac)
  3095. {
  3096. struct ath_hal_5416 *ahp = AH5416(ah);
  3097. memcpy(mac, ahp->ah_macaddr, ETH_ALEN);
  3098. }
  3099. bool ath9k_hw_setmac(struct ath_hal *ah, const u8 *mac)
  3100. {
  3101. struct ath_hal_5416 *ahp = AH5416(ah);
  3102. memcpy(ahp->ah_macaddr, mac, ETH_ALEN);
  3103. return true;
  3104. }
  3105. void ath9k_hw_setopmode(struct ath_hal *ah)
  3106. {
  3107. ath9k_hw_set_operating_mode(ah, ah->ah_opmode);
  3108. }
  3109. void ath9k_hw_setmcastfilter(struct ath_hal *ah, u32 filter0, u32 filter1)
  3110. {
  3111. REG_WRITE(ah, AR_MCAST_FIL0, filter0);
  3112. REG_WRITE(ah, AR_MCAST_FIL1, filter1);
  3113. }
  3114. void ath9k_hw_getbssidmask(struct ath_hal *ah, u8 *mask)
  3115. {
  3116. struct ath_hal_5416 *ahp = AH5416(ah);
  3117. memcpy(mask, ahp->ah_bssidmask, ETH_ALEN);
  3118. }
  3119. bool ath9k_hw_setbssidmask(struct ath_hal *ah, const u8 *mask)
  3120. {
  3121. struct ath_hal_5416 *ahp = AH5416(ah);
  3122. memcpy(ahp->ah_bssidmask, mask, ETH_ALEN);
  3123. REG_WRITE(ah, AR_BSSMSKL, get_unaligned_le32(ahp->ah_bssidmask));
  3124. REG_WRITE(ah, AR_BSSMSKU, get_unaligned_le16(ahp->ah_bssidmask + 4));
  3125. return true;
  3126. }
  3127. void ath9k_hw_write_associd(struct ath_hal *ah, const u8 *bssid, u16 assocId)
  3128. {
  3129. struct ath_hal_5416 *ahp = AH5416(ah);
  3130. memcpy(ahp->ah_bssid, bssid, ETH_ALEN);
  3131. ahp->ah_assocId = assocId;
  3132. REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(ahp->ah_bssid));
  3133. REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(ahp->ah_bssid + 4) |
  3134. ((assocId & 0x3fff) << AR_BSS_ID1_AID_S));
  3135. }
  3136. u64 ath9k_hw_gettsf64(struct ath_hal *ah)
  3137. {
  3138. u64 tsf;
  3139. tsf = REG_READ(ah, AR_TSF_U32);
  3140. tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
  3141. return tsf;
  3142. }
  3143. void ath9k_hw_settsf64(struct ath_hal *ah, u64 tsf64)
  3144. {
  3145. REG_WRITE(ah, AR_TSF_L32, 0x00000000);
  3146. REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
  3147. REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
  3148. }
  3149. void ath9k_hw_reset_tsf(struct ath_hal *ah)
  3150. {
  3151. int count;
  3152. count = 0;
  3153. while (REG_READ(ah, AR_SLP32_MODE) & AR_SLP32_TSF_WRITE_STATUS) {
  3154. count++;
  3155. if (count > 10) {
  3156. DPRINTF(ah->ah_sc, ATH_DBG_RESET,
  3157. "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
  3158. break;
  3159. }
  3160. udelay(10);
  3161. }
  3162. REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
  3163. }
  3164. bool ath9k_hw_set_tsfadjust(struct ath_hal *ah, u32 setting)
  3165. {
  3166. struct ath_hal_5416 *ahp = AH5416(ah);
  3167. if (setting)
  3168. ahp->ah_miscMode |= AR_PCU_TX_ADD_TSF;
  3169. else
  3170. ahp->ah_miscMode &= ~AR_PCU_TX_ADD_TSF;
  3171. return true;
  3172. }
  3173. bool ath9k_hw_setslottime(struct ath_hal *ah, u32 us)
  3174. {
  3175. struct ath_hal_5416 *ahp = AH5416(ah);
  3176. if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
  3177. DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad slot time %u\n", us);
  3178. ahp->ah_slottime = (u32) -1;
  3179. return false;
  3180. } else {
  3181. REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
  3182. ahp->ah_slottime = us;
  3183. return true;
  3184. }
  3185. }
  3186. void ath9k_hw_set11nmac2040(struct ath_hal *ah, enum ath9k_ht_macmode mode)
  3187. {
  3188. u32 macmode;
  3189. if (mode == ATH9K_HT_MACMODE_2040 &&
  3190. !ah->ah_config.cwm_ignore_extcca)
  3191. macmode = AR_2040_JOINED_RX_CLEAR;
  3192. else
  3193. macmode = 0;
  3194. REG_WRITE(ah, AR_2040_MODE, macmode);
  3195. }
  3196. /***************************/
  3197. /* Bluetooth Coexistence */
  3198. /***************************/
  3199. void ath9k_hw_btcoex_enable(struct ath_hal *ah)
  3200. {
  3201. /* connect bt_active to baseband */
  3202. REG_CLR_BIT(ah, AR_GPIO_INPUT_EN_VAL,
  3203. (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_DEF |
  3204. AR_GPIO_INPUT_EN_VAL_BT_FREQUENCY_DEF));
  3205. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
  3206. AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB);
  3207. /* Set input mux for bt_active to gpio pin */
  3208. REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
  3209. AR_GPIO_INPUT_MUX1_BT_ACTIVE,
  3210. ah->ah_btactive_gpio);
  3211. /* Configure the desired gpio port for input */
  3212. ath9k_hw_cfg_gpio_input(ah, ah->ah_btactive_gpio);
  3213. /* Configure the desired GPIO port for TX_FRAME output */
  3214. ath9k_hw_cfg_output(ah, ah->ah_wlanactive_gpio,
  3215. AR_GPIO_OUTPUT_MUX_AS_TX_FRAME);
  3216. }