hw.c 99 KB

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