hw.c 104 KB

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