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