hw.c 101 KB

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