hw.c 104 KB

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