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 "ath9k.h"
  19. #include "initvals.h"
  20. static int btcoex_enable;
  21. module_param(btcoex_enable, bool, 0);
  22. MODULE_PARM_DESC(btcoex_enable, "Enable Bluetooth coexistence support");
  23. #define ATH9K_CLOCK_RATE_CCK 22
  24. #define ATH9K_CLOCK_RATE_5GHZ_OFDM 40
  25. #define ATH9K_CLOCK_RATE_2GHZ_OFDM 44
  26. static bool ath9k_hw_set_reset_reg(struct ath_hal *ah, u32 type);
  27. static void ath9k_hw_set_regs(struct ath_hal *ah, struct ath9k_channel *chan,
  28. enum ath9k_ht_macmode macmode);
  29. static u32 ath9k_hw_ini_fixup(struct ath_hal *ah,
  30. struct ar5416_eeprom_def *pEepData,
  31. u32 reg, u32 value);
  32. static void ath9k_hw_9280_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan);
  33. static void ath9k_hw_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan);
  34. /********************/
  35. /* Helper Functions */
  36. /********************/
  37. static u32 ath9k_hw_mac_usec(struct ath_hal *ah, u32 clks)
  38. {
  39. struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
  40. if (!ah->ah_curchan) /* should really check for CCK instead */
  41. return clks / ATH9K_CLOCK_RATE_CCK;
  42. if (conf->channel->band == IEEE80211_BAND_2GHZ)
  43. return clks / ATH9K_CLOCK_RATE_2GHZ_OFDM;
  44. return clks / ATH9K_CLOCK_RATE_5GHZ_OFDM;
  45. }
  46. static u32 ath9k_hw_mac_to_usec(struct ath_hal *ah, u32 clks)
  47. {
  48. struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
  49. if (conf_is_ht40(conf))
  50. return ath9k_hw_mac_usec(ah, clks) / 2;
  51. else
  52. return ath9k_hw_mac_usec(ah, clks);
  53. }
  54. static u32 ath9k_hw_mac_clks(struct ath_hal *ah, u32 usecs)
  55. {
  56. struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
  57. if (!ah->ah_curchan) /* should really check for CCK instead */
  58. return usecs *ATH9K_CLOCK_RATE_CCK;
  59. if (conf->channel->band == IEEE80211_BAND_2GHZ)
  60. return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
  61. return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM;
  62. }
  63. static u32 ath9k_hw_mac_to_clks(struct ath_hal *ah, u32 usecs)
  64. {
  65. struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
  66. if (conf_is_ht40(conf))
  67. return ath9k_hw_mac_clks(ah, usecs) * 2;
  68. else
  69. return ath9k_hw_mac_clks(ah, usecs);
  70. }
  71. bool ath9k_hw_wait(struct ath_hal *ah, u32 reg, u32 mask, u32 val)
  72. {
  73. int i;
  74. for (i = 0; i < (AH_TIMEOUT / AH_TIME_QUANTUM); i++) {
  75. if ((REG_READ(ah, reg) & mask) == val)
  76. return true;
  77. udelay(AH_TIME_QUANTUM);
  78. }
  79. DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
  80. "timeout on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
  81. reg, REG_READ(ah, reg), mask, val);
  82. return false;
  83. }
  84. u32 ath9k_hw_reverse_bits(u32 val, u32 n)
  85. {
  86. u32 retval;
  87. int i;
  88. for (i = 0, retval = 0; i < n; i++) {
  89. retval = (retval << 1) | (val & 1);
  90. val >>= 1;
  91. }
  92. return retval;
  93. }
  94. bool ath9k_get_channel_edges(struct ath_hal *ah,
  95. u16 flags, u16 *low,
  96. u16 *high)
  97. {
  98. struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
  99. if (flags & CHANNEL_5GHZ) {
  100. *low = pCap->low_5ghz_chan;
  101. *high = pCap->high_5ghz_chan;
  102. return true;
  103. }
  104. if ((flags & CHANNEL_2GHZ)) {
  105. *low = pCap->low_2ghz_chan;
  106. *high = pCap->high_2ghz_chan;
  107. return true;
  108. }
  109. return false;
  110. }
  111. u16 ath9k_hw_computetxtime(struct ath_hal *ah,
  112. struct ath_rate_table *rates,
  113. u32 frameLen, u16 rateix,
  114. bool shortPreamble)
  115. {
  116. u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
  117. u32 kbps;
  118. kbps = rates->info[rateix].ratekbps;
  119. if (kbps == 0)
  120. return 0;
  121. switch (rates->info[rateix].phy) {
  122. case WLAN_RC_PHY_CCK:
  123. phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
  124. if (shortPreamble && rates->info[rateix].short_preamble)
  125. phyTime >>= 1;
  126. numBits = frameLen << 3;
  127. txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
  128. break;
  129. case WLAN_RC_PHY_OFDM:
  130. if (ah->ah_curchan && IS_CHAN_QUARTER_RATE(ah->ah_curchan)) {
  131. bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
  132. numBits = OFDM_PLCP_BITS + (frameLen << 3);
  133. numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
  134. txTime = OFDM_SIFS_TIME_QUARTER
  135. + OFDM_PREAMBLE_TIME_QUARTER
  136. + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
  137. } else if (ah->ah_curchan &&
  138. IS_CHAN_HALF_RATE(ah->ah_curchan)) {
  139. bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
  140. numBits = OFDM_PLCP_BITS + (frameLen << 3);
  141. numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
  142. txTime = OFDM_SIFS_TIME_HALF +
  143. OFDM_PREAMBLE_TIME_HALF
  144. + (numSymbols * OFDM_SYMBOL_TIME_HALF);
  145. } else {
  146. bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
  147. numBits = OFDM_PLCP_BITS + (frameLen << 3);
  148. numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
  149. txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
  150. + (numSymbols * OFDM_SYMBOL_TIME);
  151. }
  152. break;
  153. default:
  154. DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
  155. "Unknown phy %u (rate ix %u)\n",
  156. rates->info[rateix].phy, rateix);
  157. txTime = 0;
  158. break;
  159. }
  160. return txTime;
  161. }
  162. void ath9k_hw_get_channel_centers(struct ath_hal *ah,
  163. struct ath9k_channel *chan,
  164. struct chan_centers *centers)
  165. {
  166. int8_t extoff;
  167. struct ath_hal_5416 *ahp = AH5416(ah);
  168. if (!IS_CHAN_HT40(chan)) {
  169. centers->ctl_center = centers->ext_center =
  170. centers->synth_center = chan->channel;
  171. return;
  172. }
  173. if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
  174. (chan->chanmode == CHANNEL_G_HT40PLUS)) {
  175. centers->synth_center =
  176. chan->channel + HT40_CHANNEL_CENTER_SHIFT;
  177. extoff = 1;
  178. } else {
  179. centers->synth_center =
  180. chan->channel - HT40_CHANNEL_CENTER_SHIFT;
  181. extoff = -1;
  182. }
  183. centers->ctl_center =
  184. centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
  185. centers->ext_center =
  186. centers->synth_center + (extoff *
  187. ((ahp->ah_extprotspacing == ATH9K_HT_EXTPROTSPACING_20) ?
  188. HT40_CHANNEL_CENTER_SHIFT : 15));
  189. }
  190. /******************/
  191. /* Chip Revisions */
  192. /******************/
  193. static void ath9k_hw_read_revisions(struct ath_hal *ah)
  194. {
  195. u32 val;
  196. val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
  197. if (val == 0xFF) {
  198. val = REG_READ(ah, AR_SREV);
  199. ah->ah_macVersion = (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
  200. ah->ah_macRev = MS(val, AR_SREV_REVISION2);
  201. ah->ah_isPciExpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
  202. } else {
  203. if (!AR_SREV_9100(ah))
  204. ah->ah_macVersion = MS(val, AR_SREV_VERSION);
  205. ah->ah_macRev = val & AR_SREV_REVISION;
  206. if (ah->ah_macVersion == AR_SREV_VERSION_5416_PCIE)
  207. ah->ah_isPciExpress = true;
  208. }
  209. }
  210. static int ath9k_hw_get_radiorev(struct ath_hal *ah)
  211. {
  212. u32 val;
  213. int i;
  214. REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
  215. for (i = 0; i < 8; i++)
  216. REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
  217. val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
  218. val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
  219. return ath9k_hw_reverse_bits(val, 8);
  220. }
  221. /************************************/
  222. /* HW Attach, Detach, Init Routines */
  223. /************************************/
  224. static void ath9k_hw_disablepcie(struct ath_hal *ah)
  225. {
  226. if (AR_SREV_9100(ah))
  227. return;
  228. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
  229. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  230. REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
  231. REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
  232. REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
  233. REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
  234. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  235. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  236. REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
  237. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  238. }
  239. static bool ath9k_hw_chip_test(struct ath_hal *ah)
  240. {
  241. u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) };
  242. u32 regHold[2];
  243. u32 patternData[4] = { 0x55555555,
  244. 0xaaaaaaaa,
  245. 0x66666666,
  246. 0x99999999 };
  247. int i, j;
  248. for (i = 0; i < 2; i++) {
  249. u32 addr = regAddr[i];
  250. u32 wrData, rdData;
  251. regHold[i] = REG_READ(ah, addr);
  252. for (j = 0; j < 0x100; j++) {
  253. wrData = (j << 16) | j;
  254. REG_WRITE(ah, addr, wrData);
  255. rdData = REG_READ(ah, addr);
  256. if (rdData != wrData) {
  257. DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
  258. "address test failed "
  259. "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
  260. addr, wrData, rdData);
  261. return false;
  262. }
  263. }
  264. for (j = 0; j < 4; j++) {
  265. wrData = patternData[j];
  266. REG_WRITE(ah, addr, wrData);
  267. rdData = REG_READ(ah, addr);
  268. if (wrData != rdData) {
  269. DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
  270. "address test failed "
  271. "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
  272. addr, wrData, rdData);
  273. return false;
  274. }
  275. }
  276. REG_WRITE(ah, regAddr[i], regHold[i]);
  277. }
  278. udelay(100);
  279. return true;
  280. }
  281. static const char *ath9k_hw_devname(u16 devid)
  282. {
  283. switch (devid) {
  284. case AR5416_DEVID_PCI:
  285. return "Atheros 5416";
  286. case AR5416_DEVID_PCIE:
  287. return "Atheros 5418";
  288. case AR9160_DEVID_PCI:
  289. return "Atheros 9160";
  290. case AR5416_AR9100_DEVID:
  291. return "Atheros 9100";
  292. case AR9280_DEVID_PCI:
  293. case AR9280_DEVID_PCIE:
  294. return "Atheros 9280";
  295. case AR9285_DEVID_PCIE:
  296. return "Atheros 9285";
  297. }
  298. return NULL;
  299. }
  300. static void ath9k_hw_set_defaults(struct ath_hal *ah)
  301. {
  302. int i;
  303. ah->ah_config.dma_beacon_response_time = 2;
  304. ah->ah_config.sw_beacon_response_time = 10;
  305. ah->ah_config.additional_swba_backoff = 0;
  306. ah->ah_config.ack_6mb = 0x0;
  307. ah->ah_config.cwm_ignore_extcca = 0;
  308. ah->ah_config.pcie_powersave_enable = 0;
  309. ah->ah_config.pcie_l1skp_enable = 0;
  310. ah->ah_config.pcie_clock_req = 0;
  311. ah->ah_config.pcie_power_reset = 0x100;
  312. ah->ah_config.pcie_restore = 0;
  313. ah->ah_config.pcie_waen = 0;
  314. ah->ah_config.analog_shiftreg = 1;
  315. ah->ah_config.ht_enable = 1;
  316. ah->ah_config.ofdm_trig_low = 200;
  317. ah->ah_config.ofdm_trig_high = 500;
  318. ah->ah_config.cck_trig_high = 200;
  319. ah->ah_config.cck_trig_low = 100;
  320. ah->ah_config.enable_ani = 1;
  321. ah->ah_config.noise_immunity_level = 4;
  322. ah->ah_config.ofdm_weaksignal_det = 1;
  323. ah->ah_config.cck_weaksignal_thr = 0;
  324. ah->ah_config.spur_immunity_level = 2;
  325. ah->ah_config.firstep_level = 0;
  326. ah->ah_config.rssi_thr_high = 40;
  327. ah->ah_config.rssi_thr_low = 7;
  328. ah->ah_config.diversity_control = 0;
  329. ah->ah_config.antenna_switch_swap = 0;
  330. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  331. ah->ah_config.spurchans[i][0] = AR_NO_SPUR;
  332. ah->ah_config.spurchans[i][1] = AR_NO_SPUR;
  333. }
  334. ah->ah_config.intr_mitigation = 1;
  335. }
  336. static struct ath_hal_5416 *ath9k_hw_newstate(u16 devid,
  337. struct ath_softc *sc,
  338. void __iomem *mem,
  339. int *status)
  340. {
  341. static const u8 defbssidmask[ETH_ALEN] =
  342. { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  343. struct ath_hal_5416 *ahp;
  344. struct ath_hal *ah;
  345. ahp = kzalloc(sizeof(struct ath_hal_5416), GFP_KERNEL);
  346. if (ahp == NULL) {
  347. DPRINTF(sc, ATH_DBG_FATAL,
  348. "Cannot allocate memory for state block\n");
  349. *status = -ENOMEM;
  350. return NULL;
  351. }
  352. ah = &ahp->ah;
  353. ah->ah_sc = sc;
  354. ah->ah_sh = mem;
  355. ah->ah_magic = AR5416_MAGIC;
  356. ah->ah_countryCode = CTRY_DEFAULT;
  357. ah->ah_devid = devid;
  358. ah->ah_subvendorid = 0;
  359. ah->ah_flags = 0;
  360. if ((devid == AR5416_AR9100_DEVID))
  361. ah->ah_macVersion = AR_SREV_VERSION_9100;
  362. if (!AR_SREV_9100(ah))
  363. ah->ah_flags = AH_USE_EEPROM;
  364. ah->ah_powerLimit = MAX_RATE_POWER;
  365. ah->ah_tpScale = ATH9K_TP_SCALE_MAX;
  366. ahp->ah_atimWindow = 0;
  367. ahp->ah_diversityControl = ah->ah_config.diversity_control;
  368. ahp->ah_antennaSwitchSwap =
  369. ah->ah_config.antenna_switch_swap;
  370. ahp->ah_staId1Defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
  371. ahp->ah_beaconInterval = 100;
  372. ahp->ah_enable32kHzClock = DONT_USE_32KHZ;
  373. ahp->ah_slottime = (u32) -1;
  374. ahp->ah_acktimeout = (u32) -1;
  375. ahp->ah_ctstimeout = (u32) -1;
  376. ahp->ah_globaltxtimeout = (u32) -1;
  377. memcpy(&ahp->ah_bssidmask, defbssidmask, ETH_ALEN);
  378. ahp->ah_gBeaconRate = 0;
  379. return ahp;
  380. }
  381. static int ath9k_hw_rfattach(struct ath_hal *ah)
  382. {
  383. bool rfStatus = false;
  384. int ecode = 0;
  385. rfStatus = ath9k_hw_init_rf(ah, &ecode);
  386. if (!rfStatus) {
  387. DPRINTF(ah->ah_sc, ATH_DBG_RESET,
  388. "RF setup failed, status %u\n", ecode);
  389. return ecode;
  390. }
  391. return 0;
  392. }
  393. static int ath9k_hw_rf_claim(struct ath_hal *ah)
  394. {
  395. u32 val;
  396. REG_WRITE(ah, AR_PHY(0), 0x00000007);
  397. val = ath9k_hw_get_radiorev(ah);
  398. switch (val & AR_RADIO_SREV_MAJOR) {
  399. case 0:
  400. val = AR_RAD5133_SREV_MAJOR;
  401. break;
  402. case AR_RAD5133_SREV_MAJOR:
  403. case AR_RAD5122_SREV_MAJOR:
  404. case AR_RAD2133_SREV_MAJOR:
  405. case AR_RAD2122_SREV_MAJOR:
  406. break;
  407. default:
  408. DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
  409. "5G Radio Chip Rev 0x%02X is not "
  410. "supported by this driver\n",
  411. ah->ah_analog5GhzRev);
  412. return -EOPNOTSUPP;
  413. }
  414. ah->ah_analog5GhzRev = val;
  415. return 0;
  416. }
  417. static int ath9k_hw_init_macaddr(struct ath_hal *ah)
  418. {
  419. u32 sum;
  420. int i;
  421. u16 eeval;
  422. struct ath_hal_5416 *ahp = AH5416(ah);
  423. sum = 0;
  424. for (i = 0; i < 3; i++) {
  425. eeval = ath9k_hw_get_eeprom(ah, AR_EEPROM_MAC(i));
  426. sum += eeval;
  427. ahp->ah_macaddr[2 * i] = eeval >> 8;
  428. ahp->ah_macaddr[2 * i + 1] = eeval & 0xff;
  429. }
  430. if (sum == 0 || sum == 0xffff * 3) {
  431. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  432. "mac address read failed: %pM\n",
  433. ahp->ah_macaddr);
  434. return -EADDRNOTAVAIL;
  435. }
  436. return 0;
  437. }
  438. static void ath9k_hw_init_rxgain_ini(struct ath_hal *ah)
  439. {
  440. u32 rxgain_type;
  441. struct ath_hal_5416 *ahp = AH5416(ah);
  442. if (ath9k_hw_get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
  443. rxgain_type = ath9k_hw_get_eeprom(ah, EEP_RXGAIN_TYPE);
  444. if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
  445. INIT_INI_ARRAY(&ahp->ah_iniModesRxGain,
  446. ar9280Modes_backoff_13db_rxgain_9280_2,
  447. ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
  448. else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
  449. INIT_INI_ARRAY(&ahp->ah_iniModesRxGain,
  450. ar9280Modes_backoff_23db_rxgain_9280_2,
  451. ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
  452. else
  453. INIT_INI_ARRAY(&ahp->ah_iniModesRxGain,
  454. ar9280Modes_original_rxgain_9280_2,
  455. ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
  456. } else
  457. INIT_INI_ARRAY(&ahp->ah_iniModesRxGain,
  458. ar9280Modes_original_rxgain_9280_2,
  459. ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
  460. }
  461. static void ath9k_hw_init_txgain_ini(struct ath_hal *ah)
  462. {
  463. u32 txgain_type;
  464. struct ath_hal_5416 *ahp = AH5416(ah);
  465. if (ath9k_hw_get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
  466. txgain_type = ath9k_hw_get_eeprom(ah, EEP_TXGAIN_TYPE);
  467. if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
  468. INIT_INI_ARRAY(&ahp->ah_iniModesTxGain,
  469. ar9280Modes_high_power_tx_gain_9280_2,
  470. ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
  471. else
  472. INIT_INI_ARRAY(&ahp->ah_iniModesTxGain,
  473. ar9280Modes_original_tx_gain_9280_2,
  474. ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
  475. } else
  476. INIT_INI_ARRAY(&ahp->ah_iniModesTxGain,
  477. ar9280Modes_original_tx_gain_9280_2,
  478. ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
  479. }
  480. static int ath9k_hw_post_attach(struct ath_hal *ah)
  481. {
  482. int ecode;
  483. if (!ath9k_hw_chip_test(ah)) {
  484. DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
  485. "hardware self-test failed\n");
  486. return -ENODEV;
  487. }
  488. ecode = ath9k_hw_rf_claim(ah);
  489. if (ecode != 0)
  490. return ecode;
  491. ecode = ath9k_hw_eeprom_attach(ah);
  492. if (ecode != 0)
  493. return ecode;
  494. ecode = ath9k_hw_rfattach(ah);
  495. if (ecode != 0)
  496. return ecode;
  497. if (!AR_SREV_9100(ah)) {
  498. ath9k_hw_ani_setup(ah);
  499. ath9k_hw_ani_attach(ah);
  500. }
  501. return 0;
  502. }
  503. static struct ath_hal *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
  504. void __iomem *mem, int *status)
  505. {
  506. struct ath_hal_5416 *ahp;
  507. struct ath_hal *ah;
  508. int ecode;
  509. u32 i, j;
  510. ahp = ath9k_hw_newstate(devid, sc, mem, status);
  511. if (ahp == NULL)
  512. return NULL;
  513. ah = &ahp->ah;
  514. ath9k_hw_set_defaults(ah);
  515. if (ah->ah_config.intr_mitigation != 0)
  516. ahp->ah_intrMitigation = true;
  517. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
  518. DPRINTF(ah->ah_sc, ATH_DBG_RESET, "Couldn't reset chip\n");
  519. ecode = -EIO;
  520. goto bad;
  521. }
  522. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
  523. DPRINTF(ah->ah_sc, ATH_DBG_RESET, "Couldn't wakeup chip\n");
  524. ecode = -EIO;
  525. goto bad;
  526. }
  527. if (ah->ah_config.serialize_regmode == SER_REG_MODE_AUTO) {
  528. if (ah->ah_macVersion == AR_SREV_VERSION_5416_PCI) {
  529. ah->ah_config.serialize_regmode =
  530. SER_REG_MODE_ON;
  531. } else {
  532. ah->ah_config.serialize_regmode =
  533. SER_REG_MODE_OFF;
  534. }
  535. }
  536. DPRINTF(ah->ah_sc, ATH_DBG_RESET,
  537. "serialize_regmode is %d\n",
  538. ah->ah_config.serialize_regmode);
  539. if ((ah->ah_macVersion != AR_SREV_VERSION_5416_PCI) &&
  540. (ah->ah_macVersion != AR_SREV_VERSION_5416_PCIE) &&
  541. (ah->ah_macVersion != AR_SREV_VERSION_9160) &&
  542. (!AR_SREV_9100(ah)) && (!AR_SREV_9280(ah)) && (!AR_SREV_9285(ah))) {
  543. DPRINTF(ah->ah_sc, ATH_DBG_RESET,
  544. "Mac Chip Rev 0x%02x.%x is not supported by "
  545. "this driver\n", ah->ah_macVersion, ah->ah_macRev);
  546. ecode = -EOPNOTSUPP;
  547. goto bad;
  548. }
  549. if (AR_SREV_9100(ah)) {
  550. ahp->ah_iqCalData.calData = &iq_cal_multi_sample;
  551. ahp->ah_suppCals = IQ_MISMATCH_CAL;
  552. ah->ah_isPciExpress = false;
  553. }
  554. ah->ah_phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
  555. if (AR_SREV_9160_10_OR_LATER(ah)) {
  556. if (AR_SREV_9280_10_OR_LATER(ah)) {
  557. ahp->ah_iqCalData.calData = &iq_cal_single_sample;
  558. ahp->ah_adcGainCalData.calData =
  559. &adc_gain_cal_single_sample;
  560. ahp->ah_adcDcCalData.calData =
  561. &adc_dc_cal_single_sample;
  562. ahp->ah_adcDcCalInitData.calData =
  563. &adc_init_dc_cal;
  564. } else {
  565. ahp->ah_iqCalData.calData = &iq_cal_multi_sample;
  566. ahp->ah_adcGainCalData.calData =
  567. &adc_gain_cal_multi_sample;
  568. ahp->ah_adcDcCalData.calData =
  569. &adc_dc_cal_multi_sample;
  570. ahp->ah_adcDcCalInitData.calData =
  571. &adc_init_dc_cal;
  572. }
  573. ahp->ah_suppCals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
  574. }
  575. if (AR_SREV_9160(ah)) {
  576. ah->ah_config.enable_ani = 1;
  577. ahp->ah_ani_function = (ATH9K_ANI_SPUR_IMMUNITY_LEVEL |
  578. ATH9K_ANI_FIRSTEP_LEVEL);
  579. } else {
  580. ahp->ah_ani_function = ATH9K_ANI_ALL;
  581. if (AR_SREV_9280_10_OR_LATER(ah)) {
  582. ahp->ah_ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
  583. }
  584. }
  585. DPRINTF(ah->ah_sc, ATH_DBG_RESET,
  586. "This Mac Chip Rev 0x%02x.%x is \n",
  587. ah->ah_macVersion, ah->ah_macRev);
  588. if (AR_SREV_9285_12_OR_LATER(ah)) {
  589. INIT_INI_ARRAY(&ahp->ah_iniModes, ar9285Modes_9285_1_2,
  590. ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
  591. INIT_INI_ARRAY(&ahp->ah_iniCommon, ar9285Common_9285_1_2,
  592. ARRAY_SIZE(ar9285Common_9285_1_2), 2);
  593. if (ah->ah_config.pcie_clock_req) {
  594. INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
  595. ar9285PciePhy_clkreq_off_L1_9285_1_2,
  596. ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
  597. } else {
  598. INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
  599. ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
  600. ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
  601. 2);
  602. }
  603. } else if (AR_SREV_9285_10_OR_LATER(ah)) {
  604. INIT_INI_ARRAY(&ahp->ah_iniModes, ar9285Modes_9285,
  605. ARRAY_SIZE(ar9285Modes_9285), 6);
  606. INIT_INI_ARRAY(&ahp->ah_iniCommon, ar9285Common_9285,
  607. ARRAY_SIZE(ar9285Common_9285), 2);
  608. if (ah->ah_config.pcie_clock_req) {
  609. INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
  610. ar9285PciePhy_clkreq_off_L1_9285,
  611. ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
  612. } else {
  613. INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
  614. ar9285PciePhy_clkreq_always_on_L1_9285,
  615. ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
  616. }
  617. } else if (AR_SREV_9280_20_OR_LATER(ah)) {
  618. INIT_INI_ARRAY(&ahp->ah_iniModes, ar9280Modes_9280_2,
  619. ARRAY_SIZE(ar9280Modes_9280_2), 6);
  620. INIT_INI_ARRAY(&ahp->ah_iniCommon, ar9280Common_9280_2,
  621. ARRAY_SIZE(ar9280Common_9280_2), 2);
  622. if (ah->ah_config.pcie_clock_req) {
  623. INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
  624. ar9280PciePhy_clkreq_off_L1_9280,
  625. ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
  626. } else {
  627. INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
  628. ar9280PciePhy_clkreq_always_on_L1_9280,
  629. ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
  630. }
  631. INIT_INI_ARRAY(&ahp->ah_iniModesAdditional,
  632. ar9280Modes_fast_clock_9280_2,
  633. ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
  634. } else if (AR_SREV_9280_10_OR_LATER(ah)) {
  635. INIT_INI_ARRAY(&ahp->ah_iniModes, ar9280Modes_9280,
  636. ARRAY_SIZE(ar9280Modes_9280), 6);
  637. INIT_INI_ARRAY(&ahp->ah_iniCommon, ar9280Common_9280,
  638. ARRAY_SIZE(ar9280Common_9280), 2);
  639. } else if (AR_SREV_9160_10_OR_LATER(ah)) {
  640. INIT_INI_ARRAY(&ahp->ah_iniModes, ar5416Modes_9160,
  641. ARRAY_SIZE(ar5416Modes_9160), 6);
  642. INIT_INI_ARRAY(&ahp->ah_iniCommon, ar5416Common_9160,
  643. ARRAY_SIZE(ar5416Common_9160), 2);
  644. INIT_INI_ARRAY(&ahp->ah_iniBank0, ar5416Bank0_9160,
  645. ARRAY_SIZE(ar5416Bank0_9160), 2);
  646. INIT_INI_ARRAY(&ahp->ah_iniBB_RfGain, ar5416BB_RfGain_9160,
  647. ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
  648. INIT_INI_ARRAY(&ahp->ah_iniBank1, ar5416Bank1_9160,
  649. ARRAY_SIZE(ar5416Bank1_9160), 2);
  650. INIT_INI_ARRAY(&ahp->ah_iniBank2, ar5416Bank2_9160,
  651. ARRAY_SIZE(ar5416Bank2_9160), 2);
  652. INIT_INI_ARRAY(&ahp->ah_iniBank3, ar5416Bank3_9160,
  653. ARRAY_SIZE(ar5416Bank3_9160), 3);
  654. INIT_INI_ARRAY(&ahp->ah_iniBank6, ar5416Bank6_9160,
  655. ARRAY_SIZE(ar5416Bank6_9160), 3);
  656. INIT_INI_ARRAY(&ahp->ah_iniBank6TPC, ar5416Bank6TPC_9160,
  657. ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
  658. INIT_INI_ARRAY(&ahp->ah_iniBank7, ar5416Bank7_9160,
  659. ARRAY_SIZE(ar5416Bank7_9160), 2);
  660. if (AR_SREV_9160_11(ah)) {
  661. INIT_INI_ARRAY(&ahp->ah_iniAddac,
  662. ar5416Addac_91601_1,
  663. ARRAY_SIZE(ar5416Addac_91601_1), 2);
  664. } else {
  665. INIT_INI_ARRAY(&ahp->ah_iniAddac, ar5416Addac_9160,
  666. ARRAY_SIZE(ar5416Addac_9160), 2);
  667. }
  668. } else if (AR_SREV_9100_OR_LATER(ah)) {
  669. INIT_INI_ARRAY(&ahp->ah_iniModes, ar5416Modes_9100,
  670. ARRAY_SIZE(ar5416Modes_9100), 6);
  671. INIT_INI_ARRAY(&ahp->ah_iniCommon, ar5416Common_9100,
  672. ARRAY_SIZE(ar5416Common_9100), 2);
  673. INIT_INI_ARRAY(&ahp->ah_iniBank0, ar5416Bank0_9100,
  674. ARRAY_SIZE(ar5416Bank0_9100), 2);
  675. INIT_INI_ARRAY(&ahp->ah_iniBB_RfGain, ar5416BB_RfGain_9100,
  676. ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
  677. INIT_INI_ARRAY(&ahp->ah_iniBank1, ar5416Bank1_9100,
  678. ARRAY_SIZE(ar5416Bank1_9100), 2);
  679. INIT_INI_ARRAY(&ahp->ah_iniBank2, ar5416Bank2_9100,
  680. ARRAY_SIZE(ar5416Bank2_9100), 2);
  681. INIT_INI_ARRAY(&ahp->ah_iniBank3, ar5416Bank3_9100,
  682. ARRAY_SIZE(ar5416Bank3_9100), 3);
  683. INIT_INI_ARRAY(&ahp->ah_iniBank6, ar5416Bank6_9100,
  684. ARRAY_SIZE(ar5416Bank6_9100), 3);
  685. INIT_INI_ARRAY(&ahp->ah_iniBank6TPC, ar5416Bank6TPC_9100,
  686. ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
  687. INIT_INI_ARRAY(&ahp->ah_iniBank7, ar5416Bank7_9100,
  688. ARRAY_SIZE(ar5416Bank7_9100), 2);
  689. INIT_INI_ARRAY(&ahp->ah_iniAddac, ar5416Addac_9100,
  690. ARRAY_SIZE(ar5416Addac_9100), 2);
  691. } else {
  692. INIT_INI_ARRAY(&ahp->ah_iniModes, ar5416Modes,
  693. ARRAY_SIZE(ar5416Modes), 6);
  694. INIT_INI_ARRAY(&ahp->ah_iniCommon, ar5416Common,
  695. ARRAY_SIZE(ar5416Common), 2);
  696. INIT_INI_ARRAY(&ahp->ah_iniBank0, ar5416Bank0,
  697. ARRAY_SIZE(ar5416Bank0), 2);
  698. INIT_INI_ARRAY(&ahp->ah_iniBB_RfGain, ar5416BB_RfGain,
  699. ARRAY_SIZE(ar5416BB_RfGain), 3);
  700. INIT_INI_ARRAY(&ahp->ah_iniBank1, ar5416Bank1,
  701. ARRAY_SIZE(ar5416Bank1), 2);
  702. INIT_INI_ARRAY(&ahp->ah_iniBank2, ar5416Bank2,
  703. ARRAY_SIZE(ar5416Bank2), 2);
  704. INIT_INI_ARRAY(&ahp->ah_iniBank3, ar5416Bank3,
  705. ARRAY_SIZE(ar5416Bank3), 3);
  706. INIT_INI_ARRAY(&ahp->ah_iniBank6, ar5416Bank6,
  707. ARRAY_SIZE(ar5416Bank6), 3);
  708. INIT_INI_ARRAY(&ahp->ah_iniBank6TPC, ar5416Bank6TPC,
  709. ARRAY_SIZE(ar5416Bank6TPC), 3);
  710. INIT_INI_ARRAY(&ahp->ah_iniBank7, ar5416Bank7,
  711. ARRAY_SIZE(ar5416Bank7), 2);
  712. INIT_INI_ARRAY(&ahp->ah_iniAddac, ar5416Addac,
  713. ARRAY_SIZE(ar5416Addac), 2);
  714. }
  715. if (ah->ah_isPciExpress)
  716. ath9k_hw_configpcipowersave(ah, 0);
  717. else
  718. ath9k_hw_disablepcie(ah);
  719. ecode = ath9k_hw_post_attach(ah);
  720. if (ecode != 0)
  721. goto bad;
  722. /* rxgain table */
  723. if (AR_SREV_9280_20(ah))
  724. ath9k_hw_init_rxgain_ini(ah);
  725. /* txgain table */
  726. if (AR_SREV_9280_20(ah))
  727. ath9k_hw_init_txgain_ini(ah);
  728. if (ah->ah_devid == AR9280_DEVID_PCI) {
  729. for (i = 0; i < ahp->ah_iniModes.ia_rows; i++) {
  730. u32 reg = INI_RA(&ahp->ah_iniModes, i, 0);
  731. for (j = 1; j < ahp->ah_iniModes.ia_columns; j++) {
  732. u32 val = INI_RA(&ahp->ah_iniModes, i, j);
  733. INI_RA(&ahp->ah_iniModes, i, j) =
  734. ath9k_hw_ini_fixup(ah,
  735. &ahp->ah_eeprom.def,
  736. reg, val);
  737. }
  738. }
  739. }
  740. if (!ath9k_hw_fill_cap_info(ah)) {
  741. DPRINTF(ah->ah_sc, ATH_DBG_RESET,
  742. "failed ath9k_hw_fill_cap_info\n");
  743. ecode = -EINVAL;
  744. goto bad;
  745. }
  746. ecode = ath9k_hw_init_macaddr(ah);
  747. if (ecode != 0) {
  748. DPRINTF(ah->ah_sc, ATH_DBG_RESET,
  749. "failed initializing mac address\n");
  750. goto bad;
  751. }
  752. if (AR_SREV_9285(ah))
  753. ah->ah_txTrigLevel = (AR_FTRIG_256B >> AR_FTRIG_S);
  754. else
  755. ah->ah_txTrigLevel = (AR_FTRIG_512B >> AR_FTRIG_S);
  756. ath9k_init_nfcal_hist_buffer(ah);
  757. return ah;
  758. bad:
  759. if (ahp)
  760. ath9k_hw_detach((struct ath_hal *) ahp);
  761. if (status)
  762. *status = ecode;
  763. return NULL;
  764. }
  765. static void ath9k_hw_init_bb(struct ath_hal *ah,
  766. struct ath9k_channel *chan)
  767. {
  768. u32 synthDelay;
  769. synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  770. if (IS_CHAN_B(chan))
  771. synthDelay = (4 * synthDelay) / 22;
  772. else
  773. synthDelay /= 10;
  774. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
  775. udelay(synthDelay + BASE_ACTIVATE_DELAY);
  776. }
  777. static void ath9k_hw_init_qos(struct ath_hal *ah)
  778. {
  779. REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
  780. REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
  781. REG_WRITE(ah, AR_QOS_NO_ACK,
  782. SM(2, AR_QOS_NO_ACK_TWO_BIT) |
  783. SM(5, AR_QOS_NO_ACK_BIT_OFF) |
  784. SM(0, AR_QOS_NO_ACK_BYTE_OFF));
  785. REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
  786. REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
  787. REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
  788. REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
  789. REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
  790. }
  791. static void ath9k_hw_init_pll(struct ath_hal *ah,
  792. struct ath9k_channel *chan)
  793. {
  794. u32 pll;
  795. if (AR_SREV_9100(ah)) {
  796. if (chan && IS_CHAN_5GHZ(chan))
  797. pll = 0x1450;
  798. else
  799. pll = 0x1458;
  800. } else {
  801. if (AR_SREV_9280_10_OR_LATER(ah)) {
  802. pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
  803. if (chan && IS_CHAN_HALF_RATE(chan))
  804. pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
  805. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  806. pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
  807. if (chan && IS_CHAN_5GHZ(chan)) {
  808. pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
  809. if (AR_SREV_9280_20(ah)) {
  810. if (((chan->channel % 20) == 0)
  811. || ((chan->channel % 10) == 0))
  812. pll = 0x2850;
  813. else
  814. pll = 0x142c;
  815. }
  816. } else {
  817. pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
  818. }
  819. } else if (AR_SREV_9160_10_OR_LATER(ah)) {
  820. pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
  821. if (chan && IS_CHAN_HALF_RATE(chan))
  822. pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
  823. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  824. pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
  825. if (chan && IS_CHAN_5GHZ(chan))
  826. pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
  827. else
  828. pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
  829. } else {
  830. pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
  831. if (chan && IS_CHAN_HALF_RATE(chan))
  832. pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
  833. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  834. pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
  835. if (chan && IS_CHAN_5GHZ(chan))
  836. pll |= SM(0xa, AR_RTC_PLL_DIV);
  837. else
  838. pll |= SM(0xb, AR_RTC_PLL_DIV);
  839. }
  840. }
  841. REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
  842. udelay(RTC_PLL_SETTLE_DELAY);
  843. REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
  844. }
  845. static void ath9k_hw_init_chain_masks(struct ath_hal *ah)
  846. {
  847. struct ath_hal_5416 *ahp = AH5416(ah);
  848. int rx_chainmask, tx_chainmask;
  849. rx_chainmask = ahp->ah_rxchainmask;
  850. tx_chainmask = ahp->ah_txchainmask;
  851. switch (rx_chainmask) {
  852. case 0x5:
  853. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  854. AR_PHY_SWAP_ALT_CHAIN);
  855. case 0x3:
  856. if (((ah)->ah_macVersion <= AR_SREV_VERSION_9160)) {
  857. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
  858. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
  859. break;
  860. }
  861. case 0x1:
  862. case 0x2:
  863. case 0x7:
  864. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
  865. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
  866. break;
  867. default:
  868. break;
  869. }
  870. REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
  871. if (tx_chainmask == 0x5) {
  872. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  873. AR_PHY_SWAP_ALT_CHAIN);
  874. }
  875. if (AR_SREV_9100(ah))
  876. REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
  877. REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
  878. }
  879. static void ath9k_hw_init_interrupt_masks(struct ath_hal *ah,
  880. enum nl80211_iftype opmode)
  881. {
  882. struct ath_hal_5416 *ahp = AH5416(ah);
  883. ahp->ah_maskReg = AR_IMR_TXERR |
  884. AR_IMR_TXURN |
  885. AR_IMR_RXERR |
  886. AR_IMR_RXORN |
  887. AR_IMR_BCNMISC;
  888. if (ahp->ah_intrMitigation)
  889. ahp->ah_maskReg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
  890. else
  891. ahp->ah_maskReg |= AR_IMR_RXOK;
  892. ahp->ah_maskReg |= AR_IMR_TXOK;
  893. if (opmode == NL80211_IFTYPE_AP)
  894. ahp->ah_maskReg |= AR_IMR_MIB;
  895. REG_WRITE(ah, AR_IMR, ahp->ah_maskReg);
  896. REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
  897. if (!AR_SREV_9100(ah)) {
  898. REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
  899. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
  900. REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
  901. }
  902. }
  903. static bool ath9k_hw_set_ack_timeout(struct ath_hal *ah, u32 us)
  904. {
  905. struct ath_hal_5416 *ahp = AH5416(ah);
  906. if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
  907. DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad ack timeout %u\n", us);
  908. ahp->ah_acktimeout = (u32) -1;
  909. return false;
  910. } else {
  911. REG_RMW_FIELD(ah, AR_TIME_OUT,
  912. AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
  913. ahp->ah_acktimeout = us;
  914. return true;
  915. }
  916. }
  917. static bool ath9k_hw_set_cts_timeout(struct ath_hal *ah, u32 us)
  918. {
  919. struct ath_hal_5416 *ahp = AH5416(ah);
  920. if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
  921. DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad cts timeout %u\n", us);
  922. ahp->ah_ctstimeout = (u32) -1;
  923. return false;
  924. } else {
  925. REG_RMW_FIELD(ah, AR_TIME_OUT,
  926. AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
  927. ahp->ah_ctstimeout = us;
  928. return true;
  929. }
  930. }
  931. static bool ath9k_hw_set_global_txtimeout(struct ath_hal *ah, u32 tu)
  932. {
  933. struct ath_hal_5416 *ahp = AH5416(ah);
  934. if (tu > 0xFFFF) {
  935. DPRINTF(ah->ah_sc, ATH_DBG_XMIT,
  936. "bad global tx timeout %u\n", tu);
  937. ahp->ah_globaltxtimeout = (u32) -1;
  938. return false;
  939. } else {
  940. REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
  941. ahp->ah_globaltxtimeout = tu;
  942. return true;
  943. }
  944. }
  945. static void ath9k_hw_init_user_settings(struct ath_hal *ah)
  946. {
  947. struct ath_hal_5416 *ahp = AH5416(ah);
  948. DPRINTF(ah->ah_sc, ATH_DBG_RESET, "ahp->ah_miscMode 0x%x\n",
  949. ahp->ah_miscMode);
  950. if (ahp->ah_miscMode != 0)
  951. REG_WRITE(ah, AR_PCU_MISC,
  952. REG_READ(ah, AR_PCU_MISC) | ahp->ah_miscMode);
  953. if (ahp->ah_slottime != (u32) -1)
  954. ath9k_hw_setslottime(ah, ahp->ah_slottime);
  955. if (ahp->ah_acktimeout != (u32) -1)
  956. ath9k_hw_set_ack_timeout(ah, ahp->ah_acktimeout);
  957. if (ahp->ah_ctstimeout != (u32) -1)
  958. ath9k_hw_set_cts_timeout(ah, ahp->ah_ctstimeout);
  959. if (ahp->ah_globaltxtimeout != (u32) -1)
  960. ath9k_hw_set_global_txtimeout(ah, ahp->ah_globaltxtimeout);
  961. }
  962. const char *ath9k_hw_probe(u16 vendorid, u16 devid)
  963. {
  964. return vendorid == ATHEROS_VENDOR_ID ?
  965. ath9k_hw_devname(devid) : NULL;
  966. }
  967. void ath9k_hw_detach(struct ath_hal *ah)
  968. {
  969. if (!AR_SREV_9100(ah))
  970. ath9k_hw_ani_detach(ah);
  971. ath9k_hw_rfdetach(ah);
  972. ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
  973. kfree(ah);
  974. }
  975. struct ath_hal *ath9k_hw_attach(u16 devid, struct ath_softc *sc,
  976. void __iomem *mem, int *error)
  977. {
  978. struct ath_hal *ah = NULL;
  979. switch (devid) {
  980. case AR5416_DEVID_PCI:
  981. case AR5416_DEVID_PCIE:
  982. case AR5416_AR9100_DEVID:
  983. case AR9160_DEVID_PCI:
  984. case AR9280_DEVID_PCI:
  985. case AR9280_DEVID_PCIE:
  986. case AR9285_DEVID_PCIE:
  987. ah = ath9k_hw_do_attach(devid, sc, mem, error);
  988. break;
  989. default:
  990. *error = -ENXIO;
  991. break;
  992. }
  993. return ah;
  994. }
  995. /*******/
  996. /* INI */
  997. /*******/
  998. static void ath9k_hw_override_ini(struct ath_hal *ah,
  999. struct ath9k_channel *chan)
  1000. {
  1001. /*
  1002. * Set the RX_ABORT and RX_DIS and clear if off only after
  1003. * RXE is set for MAC. This prevents frames with corrupted
  1004. * descriptor status.
  1005. */
  1006. REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  1007. if (!AR_SREV_5416_V20_OR_LATER(ah) ||
  1008. AR_SREV_9280_10_OR_LATER(ah))
  1009. return;
  1010. REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
  1011. }
  1012. static u32 ath9k_hw_def_ini_fixup(struct ath_hal *ah,
  1013. struct ar5416_eeprom_def *pEepData,
  1014. u32 reg, u32 value)
  1015. {
  1016. struct base_eep_header *pBase = &(pEepData->baseEepHeader);
  1017. switch (ah->ah_devid) {
  1018. case AR9280_DEVID_PCI:
  1019. if (reg == 0x7894) {
  1020. DPRINTF(ah->ah_sc, ATH_DBG_ANY,
  1021. "ini VAL: %x EEPROM: %x\n", value,
  1022. (pBase->version & 0xff));
  1023. if ((pBase->version & 0xff) > 0x0a) {
  1024. DPRINTF(ah->ah_sc, ATH_DBG_ANY,
  1025. "PWDCLKIND: %d\n",
  1026. pBase->pwdclkind);
  1027. value &= ~AR_AN_TOP2_PWDCLKIND;
  1028. value |= AR_AN_TOP2_PWDCLKIND &
  1029. (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
  1030. } else {
  1031. DPRINTF(ah->ah_sc, ATH_DBG_ANY,
  1032. "PWDCLKIND Earlier Rev\n");
  1033. }
  1034. DPRINTF(ah->ah_sc, ATH_DBG_ANY,
  1035. "final ini VAL: %x\n", value);
  1036. }
  1037. break;
  1038. }
  1039. return value;
  1040. }
  1041. static u32 ath9k_hw_ini_fixup(struct ath_hal *ah,
  1042. struct ar5416_eeprom_def *pEepData,
  1043. u32 reg, u32 value)
  1044. {
  1045. struct ath_hal_5416 *ahp = AH5416(ah);
  1046. if (ahp->ah_eep_map == EEP_MAP_4KBITS)
  1047. return value;
  1048. else
  1049. return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value);
  1050. }
  1051. static int ath9k_hw_process_ini(struct ath_hal *ah,
  1052. struct ath9k_channel *chan,
  1053. enum ath9k_ht_macmode macmode)
  1054. {
  1055. int i, regWrites = 0;
  1056. struct ath_hal_5416 *ahp = AH5416(ah);
  1057. struct ieee80211_channel *channel = chan->chan;
  1058. u32 modesIndex, freqIndex;
  1059. int status;
  1060. switch (chan->chanmode) {
  1061. case CHANNEL_A:
  1062. case CHANNEL_A_HT20:
  1063. modesIndex = 1;
  1064. freqIndex = 1;
  1065. break;
  1066. case CHANNEL_A_HT40PLUS:
  1067. case CHANNEL_A_HT40MINUS:
  1068. modesIndex = 2;
  1069. freqIndex = 1;
  1070. break;
  1071. case CHANNEL_G:
  1072. case CHANNEL_G_HT20:
  1073. case CHANNEL_B:
  1074. modesIndex = 4;
  1075. freqIndex = 2;
  1076. break;
  1077. case CHANNEL_G_HT40PLUS:
  1078. case CHANNEL_G_HT40MINUS:
  1079. modesIndex = 3;
  1080. freqIndex = 2;
  1081. break;
  1082. default:
  1083. return -EINVAL;
  1084. }
  1085. REG_WRITE(ah, AR_PHY(0), 0x00000007);
  1086. REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
  1087. ath9k_hw_set_addac(ah, chan);
  1088. if (AR_SREV_5416_V22_OR_LATER(ah)) {
  1089. REG_WRITE_ARRAY(&ahp->ah_iniAddac, 1, regWrites);
  1090. } else {
  1091. struct ar5416IniArray temp;
  1092. u32 addacSize =
  1093. sizeof(u32) * ahp->ah_iniAddac.ia_rows *
  1094. ahp->ah_iniAddac.ia_columns;
  1095. memcpy(ahp->ah_addac5416_21,
  1096. ahp->ah_iniAddac.ia_array, addacSize);
  1097. (ahp->ah_addac5416_21)[31 * ahp->ah_iniAddac.ia_columns + 1] = 0;
  1098. temp.ia_array = ahp->ah_addac5416_21;
  1099. temp.ia_columns = ahp->ah_iniAddac.ia_columns;
  1100. temp.ia_rows = ahp->ah_iniAddac.ia_rows;
  1101. REG_WRITE_ARRAY(&temp, 1, regWrites);
  1102. }
  1103. REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
  1104. for (i = 0; i < ahp->ah_iniModes.ia_rows; i++) {
  1105. u32 reg = INI_RA(&ahp->ah_iniModes, i, 0);
  1106. u32 val = INI_RA(&ahp->ah_iniModes, i, modesIndex);
  1107. REG_WRITE(ah, reg, val);
  1108. if (reg >= 0x7800 && reg < 0x78a0
  1109. && ah->ah_config.analog_shiftreg) {
  1110. udelay(100);
  1111. }
  1112. DO_DELAY(regWrites);
  1113. }
  1114. if (AR_SREV_9280(ah))
  1115. REG_WRITE_ARRAY(&ahp->ah_iniModesRxGain, modesIndex, regWrites);
  1116. if (AR_SREV_9280(ah))
  1117. REG_WRITE_ARRAY(&ahp->ah_iniModesTxGain, modesIndex, regWrites);
  1118. for (i = 0; i < ahp->ah_iniCommon.ia_rows; i++) {
  1119. u32 reg = INI_RA(&ahp->ah_iniCommon, i, 0);
  1120. u32 val = INI_RA(&ahp->ah_iniCommon, i, 1);
  1121. REG_WRITE(ah, reg, val);
  1122. if (reg >= 0x7800 && reg < 0x78a0
  1123. && ah->ah_config.analog_shiftreg) {
  1124. udelay(100);
  1125. }
  1126. DO_DELAY(regWrites);
  1127. }
  1128. ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites);
  1129. if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
  1130. REG_WRITE_ARRAY(&ahp->ah_iniModesAdditional, modesIndex,
  1131. regWrites);
  1132. }
  1133. ath9k_hw_override_ini(ah, chan);
  1134. ath9k_hw_set_regs(ah, chan, macmode);
  1135. ath9k_hw_init_chain_masks(ah);
  1136. status = ath9k_hw_set_txpower(ah, chan,
  1137. ath9k_regd_get_ctl(ah, chan),
  1138. channel->max_antenna_gain * 2,
  1139. channel->max_power * 2,
  1140. min((u32) MAX_RATE_POWER,
  1141. (u32) ah->ah_powerLimit));
  1142. if (status != 0) {
  1143. DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
  1144. "error init'ing transmit power\n");
  1145. return -EIO;
  1146. }
  1147. if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
  1148. DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
  1149. "ar5416SetRfRegs failed\n");
  1150. return -EIO;
  1151. }
  1152. return 0;
  1153. }
  1154. /****************************************/
  1155. /* Reset and Channel Switching Routines */
  1156. /****************************************/
  1157. static void ath9k_hw_set_rfmode(struct ath_hal *ah, struct ath9k_channel *chan)
  1158. {
  1159. u32 rfMode = 0;
  1160. if (chan == NULL)
  1161. return;
  1162. rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
  1163. ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
  1164. if (!AR_SREV_9280_10_OR_LATER(ah))
  1165. rfMode |= (IS_CHAN_5GHZ(chan)) ?
  1166. AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
  1167. if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
  1168. rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
  1169. REG_WRITE(ah, AR_PHY_MODE, rfMode);
  1170. }
  1171. static void ath9k_hw_mark_phy_inactive(struct ath_hal *ah)
  1172. {
  1173. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
  1174. }
  1175. static inline void ath9k_hw_set_dma(struct ath_hal *ah)
  1176. {
  1177. u32 regval;
  1178. regval = REG_READ(ah, AR_AHB_MODE);
  1179. REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
  1180. regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
  1181. REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
  1182. REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->ah_txTrigLevel);
  1183. regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
  1184. REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
  1185. REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
  1186. if (AR_SREV_9285(ah)) {
  1187. REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
  1188. AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
  1189. } else {
  1190. REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
  1191. AR_PCU_TXBUF_CTRL_USABLE_SIZE);
  1192. }
  1193. }
  1194. static void ath9k_hw_set_operating_mode(struct ath_hal *ah, int opmode)
  1195. {
  1196. u32 val;
  1197. val = REG_READ(ah, AR_STA_ID1);
  1198. val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
  1199. switch (opmode) {
  1200. case NL80211_IFTYPE_AP:
  1201. REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
  1202. | AR_STA_ID1_KSRCH_MODE);
  1203. REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
  1204. break;
  1205. case NL80211_IFTYPE_ADHOC:
  1206. REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
  1207. | AR_STA_ID1_KSRCH_MODE);
  1208. REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
  1209. break;
  1210. case NL80211_IFTYPE_STATION:
  1211. case NL80211_IFTYPE_MONITOR:
  1212. REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
  1213. break;
  1214. }
  1215. }
  1216. static inline void ath9k_hw_get_delta_slope_vals(struct ath_hal *ah,
  1217. u32 coef_scaled,
  1218. u32 *coef_mantissa,
  1219. u32 *coef_exponent)
  1220. {
  1221. u32 coef_exp, coef_man;
  1222. for (coef_exp = 31; coef_exp > 0; coef_exp--)
  1223. if ((coef_scaled >> coef_exp) & 0x1)
  1224. break;
  1225. coef_exp = 14 - (coef_exp - COEF_SCALE_S);
  1226. coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
  1227. *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
  1228. *coef_exponent = coef_exp - 16;
  1229. }
  1230. static void ath9k_hw_set_delta_slope(struct ath_hal *ah,
  1231. struct ath9k_channel *chan)
  1232. {
  1233. u32 coef_scaled, ds_coef_exp, ds_coef_man;
  1234. u32 clockMhzScaled = 0x64000000;
  1235. struct chan_centers centers;
  1236. if (IS_CHAN_HALF_RATE(chan))
  1237. clockMhzScaled = clockMhzScaled >> 1;
  1238. else if (IS_CHAN_QUARTER_RATE(chan))
  1239. clockMhzScaled = clockMhzScaled >> 2;
  1240. ath9k_hw_get_channel_centers(ah, chan, &centers);
  1241. coef_scaled = clockMhzScaled / centers.synth_center;
  1242. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  1243. &ds_coef_exp);
  1244. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  1245. AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
  1246. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  1247. AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
  1248. coef_scaled = (9 * coef_scaled) / 10;
  1249. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  1250. &ds_coef_exp);
  1251. REG_RMW_FIELD(ah, AR_PHY_HALFGI,
  1252. AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
  1253. REG_RMW_FIELD(ah, AR_PHY_HALFGI,
  1254. AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
  1255. }
  1256. static bool ath9k_hw_set_reset(struct ath_hal *ah, int type)
  1257. {
  1258. u32 rst_flags;
  1259. u32 tmpReg;
  1260. REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
  1261. AR_RTC_FORCE_WAKE_ON_INT);
  1262. if (AR_SREV_9100(ah)) {
  1263. rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
  1264. AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
  1265. } else {
  1266. tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
  1267. if (tmpReg &
  1268. (AR_INTR_SYNC_LOCAL_TIMEOUT |
  1269. AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
  1270. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
  1271. REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
  1272. } else {
  1273. REG_WRITE(ah, AR_RC, AR_RC_AHB);
  1274. }
  1275. rst_flags = AR_RTC_RC_MAC_WARM;
  1276. if (type == ATH9K_RESET_COLD)
  1277. rst_flags |= AR_RTC_RC_MAC_COLD;
  1278. }
  1279. REG_WRITE(ah, AR_RTC_RC, rst_flags);
  1280. udelay(50);
  1281. REG_WRITE(ah, AR_RTC_RC, 0);
  1282. if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0)) {
  1283. DPRINTF(ah->ah_sc, ATH_DBG_RESET,
  1284. "RTC stuck in MAC reset\n");
  1285. return false;
  1286. }
  1287. if (!AR_SREV_9100(ah))
  1288. REG_WRITE(ah, AR_RC, 0);
  1289. ath9k_hw_init_pll(ah, NULL);
  1290. if (AR_SREV_9100(ah))
  1291. udelay(50);
  1292. return true;
  1293. }
  1294. static bool ath9k_hw_set_reset_power_on(struct ath_hal *ah)
  1295. {
  1296. REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
  1297. AR_RTC_FORCE_WAKE_ON_INT);
  1298. REG_WRITE(ah, AR_RTC_RESET, 0);
  1299. REG_WRITE(ah, AR_RTC_RESET, 1);
  1300. if (!ath9k_hw_wait(ah,
  1301. AR_RTC_STATUS,
  1302. AR_RTC_STATUS_M,
  1303. AR_RTC_STATUS_ON)) {
  1304. DPRINTF(ah->ah_sc, ATH_DBG_RESET, "RTC not waking up\n");
  1305. return false;
  1306. }
  1307. ath9k_hw_read_revisions(ah);
  1308. return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
  1309. }
  1310. static bool ath9k_hw_set_reset_reg(struct ath_hal *ah, u32 type)
  1311. {
  1312. REG_WRITE(ah, AR_RTC_FORCE_WAKE,
  1313. AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
  1314. switch (type) {
  1315. case ATH9K_RESET_POWER_ON:
  1316. return ath9k_hw_set_reset_power_on(ah);
  1317. break;
  1318. case ATH9K_RESET_WARM:
  1319. case ATH9K_RESET_COLD:
  1320. return ath9k_hw_set_reset(ah, type);
  1321. break;
  1322. default:
  1323. return false;
  1324. }
  1325. }
  1326. static void ath9k_hw_set_regs(struct ath_hal *ah, struct ath9k_channel *chan,
  1327. enum ath9k_ht_macmode macmode)
  1328. {
  1329. u32 phymode;
  1330. u32 enableDacFifo = 0;
  1331. struct ath_hal_5416 *ahp = AH5416(ah);
  1332. if (AR_SREV_9285_10_OR_LATER(ah))
  1333. enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
  1334. AR_PHY_FC_ENABLE_DAC_FIFO);
  1335. phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
  1336. | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
  1337. if (IS_CHAN_HT40(chan)) {
  1338. phymode |= AR_PHY_FC_DYN2040_EN;
  1339. if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
  1340. (chan->chanmode == CHANNEL_G_HT40PLUS))
  1341. phymode |= AR_PHY_FC_DYN2040_PRI_CH;
  1342. if (ahp->ah_extprotspacing == ATH9K_HT_EXTPROTSPACING_25)
  1343. phymode |= AR_PHY_FC_DYN2040_EXT_CH;
  1344. }
  1345. REG_WRITE(ah, AR_PHY_TURBO, phymode);
  1346. ath9k_hw_set11nmac2040(ah, macmode);
  1347. REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
  1348. REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
  1349. }
  1350. static bool ath9k_hw_chip_reset(struct ath_hal *ah,
  1351. struct ath9k_channel *chan)
  1352. {
  1353. struct ath_hal_5416 *ahp = AH5416(ah);
  1354. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
  1355. return false;
  1356. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  1357. return false;
  1358. ahp->ah_chipFullSleep = false;
  1359. ath9k_hw_init_pll(ah, chan);
  1360. ath9k_hw_set_rfmode(ah, chan);
  1361. return true;
  1362. }
  1363. static bool ath9k_hw_channel_change(struct ath_hal *ah,
  1364. struct ath9k_channel *chan,
  1365. enum ath9k_ht_macmode macmode)
  1366. {
  1367. struct ieee80211_channel *channel = chan->chan;
  1368. u32 synthDelay, qnum;
  1369. for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
  1370. if (ath9k_hw_numtxpending(ah, qnum)) {
  1371. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
  1372. "Transmit frames pending on queue %d\n", qnum);
  1373. return false;
  1374. }
  1375. }
  1376. REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
  1377. if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
  1378. AR_PHY_RFBUS_GRANT_EN)) {
  1379. DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
  1380. "Could not kill baseband RX\n");
  1381. return false;
  1382. }
  1383. ath9k_hw_set_regs(ah, chan, macmode);
  1384. if (AR_SREV_9280_10_OR_LATER(ah)) {
  1385. if (!(ath9k_hw_ar9280_set_channel(ah, chan))) {
  1386. DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
  1387. "failed to set channel\n");
  1388. return false;
  1389. }
  1390. } else {
  1391. if (!(ath9k_hw_set_channel(ah, chan))) {
  1392. DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
  1393. "failed to set channel\n");
  1394. return false;
  1395. }
  1396. }
  1397. if (ath9k_hw_set_txpower(ah, chan,
  1398. ath9k_regd_get_ctl(ah, chan),
  1399. channel->max_antenna_gain * 2,
  1400. channel->max_power * 2,
  1401. min((u32) MAX_RATE_POWER,
  1402. (u32) ah->ah_powerLimit)) != 0) {
  1403. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  1404. "error init'ing transmit power\n");
  1405. return false;
  1406. }
  1407. synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  1408. if (IS_CHAN_B(chan))
  1409. synthDelay = (4 * synthDelay) / 22;
  1410. else
  1411. synthDelay /= 10;
  1412. udelay(synthDelay + BASE_ACTIVATE_DELAY);
  1413. REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
  1414. if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
  1415. ath9k_hw_set_delta_slope(ah, chan);
  1416. if (AR_SREV_9280_10_OR_LATER(ah))
  1417. ath9k_hw_9280_spur_mitigate(ah, chan);
  1418. else
  1419. ath9k_hw_spur_mitigate(ah, chan);
  1420. if (!chan->oneTimeCalsDone)
  1421. chan->oneTimeCalsDone = true;
  1422. return true;
  1423. }
  1424. static void ath9k_hw_9280_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan)
  1425. {
  1426. int bb_spur = AR_NO_SPUR;
  1427. int freq;
  1428. int bin, cur_bin;
  1429. int bb_spur_off, spur_subchannel_sd;
  1430. int spur_freq_sd;
  1431. int spur_delta_phase;
  1432. int denominator;
  1433. int upper, lower, cur_vit_mask;
  1434. int tmp, newVal;
  1435. int i;
  1436. int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
  1437. AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
  1438. };
  1439. int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
  1440. AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
  1441. };
  1442. int inc[4] = { 0, 100, 0, 0 };
  1443. struct chan_centers centers;
  1444. int8_t mask_m[123];
  1445. int8_t mask_p[123];
  1446. int8_t mask_amt;
  1447. int tmp_mask;
  1448. int cur_bb_spur;
  1449. bool is2GHz = IS_CHAN_2GHZ(chan);
  1450. memset(&mask_m, 0, sizeof(int8_t) * 123);
  1451. memset(&mask_p, 0, sizeof(int8_t) * 123);
  1452. ath9k_hw_get_channel_centers(ah, chan, &centers);
  1453. freq = centers.synth_center;
  1454. ah->ah_config.spurmode = SPUR_ENABLE_EEPROM;
  1455. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  1456. cur_bb_spur = ath9k_hw_eeprom_get_spur_chan(ah, i, is2GHz);
  1457. if (is2GHz)
  1458. cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
  1459. else
  1460. cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
  1461. if (AR_NO_SPUR == cur_bb_spur)
  1462. break;
  1463. cur_bb_spur = cur_bb_spur - freq;
  1464. if (IS_CHAN_HT40(chan)) {
  1465. if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
  1466. (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
  1467. bb_spur = cur_bb_spur;
  1468. break;
  1469. }
  1470. } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
  1471. (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
  1472. bb_spur = cur_bb_spur;
  1473. break;
  1474. }
  1475. }
  1476. if (AR_NO_SPUR == bb_spur) {
  1477. REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
  1478. AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
  1479. return;
  1480. } else {
  1481. REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
  1482. AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
  1483. }
  1484. bin = bb_spur * 320;
  1485. tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
  1486. newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
  1487. AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
  1488. AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
  1489. AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
  1490. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
  1491. newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
  1492. AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
  1493. AR_PHY_SPUR_REG_MASK_RATE_SELECT |
  1494. AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
  1495. SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
  1496. REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
  1497. if (IS_CHAN_HT40(chan)) {
  1498. if (bb_spur < 0) {
  1499. spur_subchannel_sd = 1;
  1500. bb_spur_off = bb_spur + 10;
  1501. } else {
  1502. spur_subchannel_sd = 0;
  1503. bb_spur_off = bb_spur - 10;
  1504. }
  1505. } else {
  1506. spur_subchannel_sd = 0;
  1507. bb_spur_off = bb_spur;
  1508. }
  1509. if (IS_CHAN_HT40(chan))
  1510. spur_delta_phase =
  1511. ((bb_spur * 262144) /
  1512. 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
  1513. else
  1514. spur_delta_phase =
  1515. ((bb_spur * 524288) /
  1516. 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
  1517. denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
  1518. spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
  1519. newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
  1520. SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
  1521. SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
  1522. REG_WRITE(ah, AR_PHY_TIMING11, newVal);
  1523. newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
  1524. REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
  1525. cur_bin = -6000;
  1526. upper = bin + 100;
  1527. lower = bin - 100;
  1528. for (i = 0; i < 4; i++) {
  1529. int pilot_mask = 0;
  1530. int chan_mask = 0;
  1531. int bp = 0;
  1532. for (bp = 0; bp < 30; bp++) {
  1533. if ((cur_bin > lower) && (cur_bin < upper)) {
  1534. pilot_mask = pilot_mask | 0x1 << bp;
  1535. chan_mask = chan_mask | 0x1 << bp;
  1536. }
  1537. cur_bin += 100;
  1538. }
  1539. cur_bin += inc[i];
  1540. REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
  1541. REG_WRITE(ah, chan_mask_reg[i], chan_mask);
  1542. }
  1543. cur_vit_mask = 6100;
  1544. upper = bin + 120;
  1545. lower = bin - 120;
  1546. for (i = 0; i < 123; i++) {
  1547. if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
  1548. /* workaround for gcc bug #37014 */
  1549. volatile int tmp_v = abs(cur_vit_mask - bin);
  1550. if (tmp_v < 75)
  1551. mask_amt = 1;
  1552. else
  1553. mask_amt = 0;
  1554. if (cur_vit_mask < 0)
  1555. mask_m[abs(cur_vit_mask / 100)] = mask_amt;
  1556. else
  1557. mask_p[cur_vit_mask / 100] = mask_amt;
  1558. }
  1559. cur_vit_mask -= 100;
  1560. }
  1561. tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
  1562. | (mask_m[48] << 26) | (mask_m[49] << 24)
  1563. | (mask_m[50] << 22) | (mask_m[51] << 20)
  1564. | (mask_m[52] << 18) | (mask_m[53] << 16)
  1565. | (mask_m[54] << 14) | (mask_m[55] << 12)
  1566. | (mask_m[56] << 10) | (mask_m[57] << 8)
  1567. | (mask_m[58] << 6) | (mask_m[59] << 4)
  1568. | (mask_m[60] << 2) | (mask_m[61] << 0);
  1569. REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
  1570. REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
  1571. tmp_mask = (mask_m[31] << 28)
  1572. | (mask_m[32] << 26) | (mask_m[33] << 24)
  1573. | (mask_m[34] << 22) | (mask_m[35] << 20)
  1574. | (mask_m[36] << 18) | (mask_m[37] << 16)
  1575. | (mask_m[48] << 14) | (mask_m[39] << 12)
  1576. | (mask_m[40] << 10) | (mask_m[41] << 8)
  1577. | (mask_m[42] << 6) | (mask_m[43] << 4)
  1578. | (mask_m[44] << 2) | (mask_m[45] << 0);
  1579. REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
  1580. REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
  1581. tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
  1582. | (mask_m[18] << 26) | (mask_m[18] << 24)
  1583. | (mask_m[20] << 22) | (mask_m[20] << 20)
  1584. | (mask_m[22] << 18) | (mask_m[22] << 16)
  1585. | (mask_m[24] << 14) | (mask_m[24] << 12)
  1586. | (mask_m[25] << 10) | (mask_m[26] << 8)
  1587. | (mask_m[27] << 6) | (mask_m[28] << 4)
  1588. | (mask_m[29] << 2) | (mask_m[30] << 0);
  1589. REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
  1590. REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
  1591. tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
  1592. | (mask_m[2] << 26) | (mask_m[3] << 24)
  1593. | (mask_m[4] << 22) | (mask_m[5] << 20)
  1594. | (mask_m[6] << 18) | (mask_m[7] << 16)
  1595. | (mask_m[8] << 14) | (mask_m[9] << 12)
  1596. | (mask_m[10] << 10) | (mask_m[11] << 8)
  1597. | (mask_m[12] << 6) | (mask_m[13] << 4)
  1598. | (mask_m[14] << 2) | (mask_m[15] << 0);
  1599. REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
  1600. REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
  1601. tmp_mask = (mask_p[15] << 28)
  1602. | (mask_p[14] << 26) | (mask_p[13] << 24)
  1603. | (mask_p[12] << 22) | (mask_p[11] << 20)
  1604. | (mask_p[10] << 18) | (mask_p[9] << 16)
  1605. | (mask_p[8] << 14) | (mask_p[7] << 12)
  1606. | (mask_p[6] << 10) | (mask_p[5] << 8)
  1607. | (mask_p[4] << 6) | (mask_p[3] << 4)
  1608. | (mask_p[2] << 2) | (mask_p[1] << 0);
  1609. REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
  1610. REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
  1611. tmp_mask = (mask_p[30] << 28)
  1612. | (mask_p[29] << 26) | (mask_p[28] << 24)
  1613. | (mask_p[27] << 22) | (mask_p[26] << 20)
  1614. | (mask_p[25] << 18) | (mask_p[24] << 16)
  1615. | (mask_p[23] << 14) | (mask_p[22] << 12)
  1616. | (mask_p[21] << 10) | (mask_p[20] << 8)
  1617. | (mask_p[19] << 6) | (mask_p[18] << 4)
  1618. | (mask_p[17] << 2) | (mask_p[16] << 0);
  1619. REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
  1620. REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
  1621. tmp_mask = (mask_p[45] << 28)
  1622. | (mask_p[44] << 26) | (mask_p[43] << 24)
  1623. | (mask_p[42] << 22) | (mask_p[41] << 20)
  1624. | (mask_p[40] << 18) | (mask_p[39] << 16)
  1625. | (mask_p[38] << 14) | (mask_p[37] << 12)
  1626. | (mask_p[36] << 10) | (mask_p[35] << 8)
  1627. | (mask_p[34] << 6) | (mask_p[33] << 4)
  1628. | (mask_p[32] << 2) | (mask_p[31] << 0);
  1629. REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
  1630. REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
  1631. tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
  1632. | (mask_p[59] << 26) | (mask_p[58] << 24)
  1633. | (mask_p[57] << 22) | (mask_p[56] << 20)
  1634. | (mask_p[55] << 18) | (mask_p[54] << 16)
  1635. | (mask_p[53] << 14) | (mask_p[52] << 12)
  1636. | (mask_p[51] << 10) | (mask_p[50] << 8)
  1637. | (mask_p[49] << 6) | (mask_p[48] << 4)
  1638. | (mask_p[47] << 2) | (mask_p[46] << 0);
  1639. REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
  1640. REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
  1641. }
  1642. static void ath9k_hw_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan)
  1643. {
  1644. int bb_spur = AR_NO_SPUR;
  1645. int bin, cur_bin;
  1646. int spur_freq_sd;
  1647. int spur_delta_phase;
  1648. int denominator;
  1649. int upper, lower, cur_vit_mask;
  1650. int tmp, new;
  1651. int i;
  1652. int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
  1653. AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
  1654. };
  1655. int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
  1656. AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
  1657. };
  1658. int inc[4] = { 0, 100, 0, 0 };
  1659. int8_t mask_m[123];
  1660. int8_t mask_p[123];
  1661. int8_t mask_amt;
  1662. int tmp_mask;
  1663. int cur_bb_spur;
  1664. bool is2GHz = IS_CHAN_2GHZ(chan);
  1665. memset(&mask_m, 0, sizeof(int8_t) * 123);
  1666. memset(&mask_p, 0, sizeof(int8_t) * 123);
  1667. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  1668. cur_bb_spur = ath9k_hw_eeprom_get_spur_chan(ah, i, is2GHz);
  1669. if (AR_NO_SPUR == cur_bb_spur)
  1670. break;
  1671. cur_bb_spur = cur_bb_spur - (chan->channel * 10);
  1672. if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
  1673. bb_spur = cur_bb_spur;
  1674. break;
  1675. }
  1676. }
  1677. if (AR_NO_SPUR == bb_spur)
  1678. return;
  1679. bin = bb_spur * 32;
  1680. tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
  1681. new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
  1682. AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
  1683. AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
  1684. AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
  1685. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
  1686. new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
  1687. AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
  1688. AR_PHY_SPUR_REG_MASK_RATE_SELECT |
  1689. AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
  1690. SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
  1691. REG_WRITE(ah, AR_PHY_SPUR_REG, new);
  1692. spur_delta_phase = ((bb_spur * 524288) / 100) &
  1693. AR_PHY_TIMING11_SPUR_DELTA_PHASE;
  1694. denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
  1695. spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
  1696. new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
  1697. SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
  1698. SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
  1699. REG_WRITE(ah, AR_PHY_TIMING11, new);
  1700. cur_bin = -6000;
  1701. upper = bin + 100;
  1702. lower = bin - 100;
  1703. for (i = 0; i < 4; i++) {
  1704. int pilot_mask = 0;
  1705. int chan_mask = 0;
  1706. int bp = 0;
  1707. for (bp = 0; bp < 30; bp++) {
  1708. if ((cur_bin > lower) && (cur_bin < upper)) {
  1709. pilot_mask = pilot_mask | 0x1 << bp;
  1710. chan_mask = chan_mask | 0x1 << bp;
  1711. }
  1712. cur_bin += 100;
  1713. }
  1714. cur_bin += inc[i];
  1715. REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
  1716. REG_WRITE(ah, chan_mask_reg[i], chan_mask);
  1717. }
  1718. cur_vit_mask = 6100;
  1719. upper = bin + 120;
  1720. lower = bin - 120;
  1721. for (i = 0; i < 123; i++) {
  1722. if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
  1723. /* workaround for gcc bug #37014 */
  1724. volatile int tmp_v = abs(cur_vit_mask - bin);
  1725. if (tmp_v < 75)
  1726. mask_amt = 1;
  1727. else
  1728. mask_amt = 0;
  1729. if (cur_vit_mask < 0)
  1730. mask_m[abs(cur_vit_mask / 100)] = mask_amt;
  1731. else
  1732. mask_p[cur_vit_mask / 100] = mask_amt;
  1733. }
  1734. cur_vit_mask -= 100;
  1735. }
  1736. tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
  1737. | (mask_m[48] << 26) | (mask_m[49] << 24)
  1738. | (mask_m[50] << 22) | (mask_m[51] << 20)
  1739. | (mask_m[52] << 18) | (mask_m[53] << 16)
  1740. | (mask_m[54] << 14) | (mask_m[55] << 12)
  1741. | (mask_m[56] << 10) | (mask_m[57] << 8)
  1742. | (mask_m[58] << 6) | (mask_m[59] << 4)
  1743. | (mask_m[60] << 2) | (mask_m[61] << 0);
  1744. REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
  1745. REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
  1746. tmp_mask = (mask_m[31] << 28)
  1747. | (mask_m[32] << 26) | (mask_m[33] << 24)
  1748. | (mask_m[34] << 22) | (mask_m[35] << 20)
  1749. | (mask_m[36] << 18) | (mask_m[37] << 16)
  1750. | (mask_m[48] << 14) | (mask_m[39] << 12)
  1751. | (mask_m[40] << 10) | (mask_m[41] << 8)
  1752. | (mask_m[42] << 6) | (mask_m[43] << 4)
  1753. | (mask_m[44] << 2) | (mask_m[45] << 0);
  1754. REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
  1755. REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
  1756. tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
  1757. | (mask_m[18] << 26) | (mask_m[18] << 24)
  1758. | (mask_m[20] << 22) | (mask_m[20] << 20)
  1759. | (mask_m[22] << 18) | (mask_m[22] << 16)
  1760. | (mask_m[24] << 14) | (mask_m[24] << 12)
  1761. | (mask_m[25] << 10) | (mask_m[26] << 8)
  1762. | (mask_m[27] << 6) | (mask_m[28] << 4)
  1763. | (mask_m[29] << 2) | (mask_m[30] << 0);
  1764. REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
  1765. REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
  1766. tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
  1767. | (mask_m[2] << 26) | (mask_m[3] << 24)
  1768. | (mask_m[4] << 22) | (mask_m[5] << 20)
  1769. | (mask_m[6] << 18) | (mask_m[7] << 16)
  1770. | (mask_m[8] << 14) | (mask_m[9] << 12)
  1771. | (mask_m[10] << 10) | (mask_m[11] << 8)
  1772. | (mask_m[12] << 6) | (mask_m[13] << 4)
  1773. | (mask_m[14] << 2) | (mask_m[15] << 0);
  1774. REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
  1775. REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
  1776. tmp_mask = (mask_p[15] << 28)
  1777. | (mask_p[14] << 26) | (mask_p[13] << 24)
  1778. | (mask_p[12] << 22) | (mask_p[11] << 20)
  1779. | (mask_p[10] << 18) | (mask_p[9] << 16)
  1780. | (mask_p[8] << 14) | (mask_p[7] << 12)
  1781. | (mask_p[6] << 10) | (mask_p[5] << 8)
  1782. | (mask_p[4] << 6) | (mask_p[3] << 4)
  1783. | (mask_p[2] << 2) | (mask_p[1] << 0);
  1784. REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
  1785. REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
  1786. tmp_mask = (mask_p[30] << 28)
  1787. | (mask_p[29] << 26) | (mask_p[28] << 24)
  1788. | (mask_p[27] << 22) | (mask_p[26] << 20)
  1789. | (mask_p[25] << 18) | (mask_p[24] << 16)
  1790. | (mask_p[23] << 14) | (mask_p[22] << 12)
  1791. | (mask_p[21] << 10) | (mask_p[20] << 8)
  1792. | (mask_p[19] << 6) | (mask_p[18] << 4)
  1793. | (mask_p[17] << 2) | (mask_p[16] << 0);
  1794. REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
  1795. REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
  1796. tmp_mask = (mask_p[45] << 28)
  1797. | (mask_p[44] << 26) | (mask_p[43] << 24)
  1798. | (mask_p[42] << 22) | (mask_p[41] << 20)
  1799. | (mask_p[40] << 18) | (mask_p[39] << 16)
  1800. | (mask_p[38] << 14) | (mask_p[37] << 12)
  1801. | (mask_p[36] << 10) | (mask_p[35] << 8)
  1802. | (mask_p[34] << 6) | (mask_p[33] << 4)
  1803. | (mask_p[32] << 2) | (mask_p[31] << 0);
  1804. REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
  1805. REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
  1806. tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
  1807. | (mask_p[59] << 26) | (mask_p[58] << 24)
  1808. | (mask_p[57] << 22) | (mask_p[56] << 20)
  1809. | (mask_p[55] << 18) | (mask_p[54] << 16)
  1810. | (mask_p[53] << 14) | (mask_p[52] << 12)
  1811. | (mask_p[51] << 10) | (mask_p[50] << 8)
  1812. | (mask_p[49] << 6) | (mask_p[48] << 4)
  1813. | (mask_p[47] << 2) | (mask_p[46] << 0);
  1814. REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
  1815. REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
  1816. }
  1817. int ath9k_hw_reset(struct ath_hal *ah, struct ath9k_channel *chan,
  1818. bool bChannelChange)
  1819. {
  1820. u32 saveLedState;
  1821. struct ath_softc *sc = ah->ah_sc;
  1822. struct ath_hal_5416 *ahp = AH5416(ah);
  1823. struct ath9k_channel *curchan = ah->ah_curchan;
  1824. u32 saveDefAntenna;
  1825. u32 macStaId1;
  1826. int i, rx_chainmask, r;
  1827. ahp->ah_extprotspacing = sc->ht_extprotspacing;
  1828. ahp->ah_txchainmask = sc->tx_chainmask;
  1829. ahp->ah_rxchainmask = sc->rx_chainmask;
  1830. if (AR_SREV_9285(ah)) {
  1831. ahp->ah_txchainmask &= 0x1;
  1832. ahp->ah_rxchainmask &= 0x1;
  1833. } else 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. }