hw.c 101 KB

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