hw.c 102 KB

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