hw.c 102 KB

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