hw.c 105 KB

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