hw.c 102 KB

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