hw.c 100 KB

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