hw.c 103 KB

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