hw.c 108 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301
  1. /*
  2. * Copyright (c) 2004-2007 Reyk Floeter <reyk@openbsd.org>
  3. * Copyright (c) 2006-2007 Nick Kossifidis <mickflemm@gmail.com>
  4. * Copyright (c) 2007 Matthew W. S. Bell <mentor@madwifi.org>
  5. * Copyright (c) 2007 Luis Rodriguez <mcgrof@winlab.rutgers.edu>
  6. * Copyright (c) 2007 Pavel Roskin <proski@gnu.org>
  7. * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com>
  8. *
  9. * Permission to use, copy, modify, and distribute this software for any
  10. * purpose with or without fee is hereby granted, provided that the above
  11. * copyright notice and this permission notice appear in all copies.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  14. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  15. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  16. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  17. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  18. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  19. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  20. *
  21. */
  22. /*
  23. * HW related functions for Atheros Wireless LAN devices.
  24. */
  25. #include <linux/pci.h>
  26. #include <linux/delay.h>
  27. #include "reg.h"
  28. #include "base.h"
  29. #include "debug.h"
  30. /*Rate tables*/
  31. static const struct ath5k_rate_table ath5k_rt_11a = AR5K_RATES_11A;
  32. static const struct ath5k_rate_table ath5k_rt_11b = AR5K_RATES_11B;
  33. static const struct ath5k_rate_table ath5k_rt_11g = AR5K_RATES_11G;
  34. static const struct ath5k_rate_table ath5k_rt_turbo = AR5K_RATES_TURBO;
  35. static const struct ath5k_rate_table ath5k_rt_xr = AR5K_RATES_XR;
  36. /*Prototypes*/
  37. static int ath5k_hw_nic_reset(struct ath5k_hw *, u32);
  38. static int ath5k_hw_nic_wakeup(struct ath5k_hw *, int, bool);
  39. static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *, struct ath5k_desc *,
  40. unsigned int, unsigned int, enum ath5k_pkt_type, unsigned int,
  41. unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
  42. unsigned int, unsigned int);
  43. static int ath5k_hw_setup_xr_tx_desc(struct ath5k_hw *, struct ath5k_desc *,
  44. unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
  45. unsigned int);
  46. static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *, struct ath5k_desc *);
  47. static int ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *, struct ath5k_desc *,
  48. unsigned int, unsigned int, enum ath5k_pkt_type, unsigned int,
  49. unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
  50. unsigned int, unsigned int);
  51. static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *, struct ath5k_desc *);
  52. static int ath5k_hw_proc_new_rx_status(struct ath5k_hw *, struct ath5k_desc *);
  53. static int ath5k_hw_proc_old_rx_status(struct ath5k_hw *, struct ath5k_desc *);
  54. static int ath5k_hw_get_capabilities(struct ath5k_hw *);
  55. static int ath5k_eeprom_init(struct ath5k_hw *);
  56. static int ath5k_eeprom_read_mac(struct ath5k_hw *, u8 *);
  57. static int ath5k_hw_enable_pspoll(struct ath5k_hw *, u8 *, u16);
  58. static int ath5k_hw_disable_pspoll(struct ath5k_hw *);
  59. /*
  60. * Enable to overwrite the country code (use "00" for debug)
  61. */
  62. #if 0
  63. #define COUNTRYCODE "00"
  64. #endif
  65. /*******************\
  66. General Functions
  67. \*******************/
  68. /*
  69. * Functions used internaly
  70. */
  71. static inline unsigned int ath5k_hw_htoclock(unsigned int usec, bool turbo)
  72. {
  73. return turbo == true ? (usec * 80) : (usec * 40);
  74. }
  75. static inline unsigned int ath5k_hw_clocktoh(unsigned int clock, bool turbo)
  76. {
  77. return turbo == true ? (clock / 80) : (clock / 40);
  78. }
  79. /*
  80. * Check if a register write has been completed
  81. */
  82. int ath5k_hw_register_timeout(struct ath5k_hw *ah, u32 reg, u32 flag, u32 val,
  83. bool is_set)
  84. {
  85. int i;
  86. u32 data;
  87. for (i = AR5K_TUNE_REGISTER_TIMEOUT; i > 0; i--) {
  88. data = ath5k_hw_reg_read(ah, reg);
  89. if ((is_set == true) && (data & flag))
  90. break;
  91. else if ((data & flag) == val)
  92. break;
  93. udelay(15);
  94. }
  95. return (i <= 0) ? -EAGAIN : 0;
  96. }
  97. /***************************************\
  98. Attach/Detach Functions
  99. \***************************************/
  100. /*
  101. * Check if the device is supported and initialize the needed structs
  102. */
  103. struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version)
  104. {
  105. struct ath5k_hw *ah;
  106. u8 mac[ETH_ALEN];
  107. int ret;
  108. u32 srev;
  109. /*If we passed the test malloc a ath5k_hw struct*/
  110. ah = kzalloc(sizeof(struct ath5k_hw), GFP_KERNEL);
  111. if (ah == NULL) {
  112. ret = -ENOMEM;
  113. ATH5K_ERR(sc, "out of memory\n");
  114. goto err;
  115. }
  116. ah->ah_sc = sc;
  117. ah->ah_iobase = sc->iobase;
  118. /*
  119. * HW information
  120. */
  121. ah->ah_op_mode = IEEE80211_IF_TYPE_STA;
  122. ah->ah_radar.r_enabled = AR5K_TUNE_RADAR_ALERT;
  123. ah->ah_turbo = false;
  124. ah->ah_txpower.txp_tpc = AR5K_TUNE_TPC_TXPOWER;
  125. ah->ah_imr = 0;
  126. ah->ah_atim_window = 0;
  127. ah->ah_aifs = AR5K_TUNE_AIFS;
  128. ah->ah_cw_min = AR5K_TUNE_CWMIN;
  129. ah->ah_limit_tx_retries = AR5K_INIT_TX_RETRY;
  130. ah->ah_software_retry = false;
  131. ah->ah_ant_diversity = AR5K_TUNE_ANT_DIVERSITY;
  132. /*
  133. * Set the mac revision based on the pci id
  134. */
  135. ah->ah_version = mac_version;
  136. /*Fill the ath5k_hw struct with the needed functions*/
  137. if (ah->ah_version == AR5K_AR5212)
  138. ah->ah_magic = AR5K_EEPROM_MAGIC_5212;
  139. else if (ah->ah_version == AR5K_AR5211)
  140. ah->ah_magic = AR5K_EEPROM_MAGIC_5211;
  141. if (ah->ah_version == AR5K_AR5212) {
  142. ah->ah_setup_tx_desc = ath5k_hw_setup_4word_tx_desc;
  143. ah->ah_setup_xtx_desc = ath5k_hw_setup_xr_tx_desc;
  144. ah->ah_proc_tx_desc = ath5k_hw_proc_4word_tx_status;
  145. } else {
  146. ah->ah_setup_tx_desc = ath5k_hw_setup_2word_tx_desc;
  147. ah->ah_setup_xtx_desc = ath5k_hw_setup_xr_tx_desc;
  148. ah->ah_proc_tx_desc = ath5k_hw_proc_2word_tx_status;
  149. }
  150. if (ah->ah_version == AR5K_AR5212)
  151. ah->ah_proc_rx_desc = ath5k_hw_proc_new_rx_status;
  152. else if (ah->ah_version <= AR5K_AR5211)
  153. ah->ah_proc_rx_desc = ath5k_hw_proc_old_rx_status;
  154. /* Bring device out of sleep and reset it's units */
  155. ret = ath5k_hw_nic_wakeup(ah, AR5K_INIT_MODE, true);
  156. if (ret)
  157. goto err_free;
  158. /* Get MAC, PHY and RADIO revisions */
  159. srev = ath5k_hw_reg_read(ah, AR5K_SREV);
  160. ah->ah_mac_srev = srev;
  161. ah->ah_mac_version = AR5K_REG_MS(srev, AR5K_SREV_VER);
  162. ah->ah_mac_revision = AR5K_REG_MS(srev, AR5K_SREV_REV);
  163. ah->ah_phy_revision = ath5k_hw_reg_read(ah, AR5K_PHY_CHIP_ID) &
  164. 0xffffffff;
  165. ah->ah_radio_5ghz_revision = ath5k_hw_radio_revision(ah,
  166. CHANNEL_5GHZ);
  167. if (ah->ah_version == AR5K_AR5210)
  168. ah->ah_radio_2ghz_revision = 0;
  169. else
  170. ah->ah_radio_2ghz_revision = ath5k_hw_radio_revision(ah,
  171. CHANNEL_2GHZ);
  172. /* Return on unsuported chips (unsupported eeprom etc) */
  173. if(srev >= AR5K_SREV_VER_AR5416){
  174. ATH5K_ERR(sc, "Device not yet supported.\n");
  175. ret = -ENODEV;
  176. goto err_free;
  177. }
  178. /* Identify single chip solutions */
  179. if((srev <= AR5K_SREV_VER_AR5414) &&
  180. (srev >= AR5K_SREV_VER_AR2413)) {
  181. ah->ah_single_chip = true;
  182. } else {
  183. ah->ah_single_chip = false;
  184. }
  185. /* Single chip radio */
  186. if (ah->ah_radio_2ghz_revision == ah->ah_radio_5ghz_revision)
  187. ah->ah_radio_2ghz_revision = 0;
  188. /* Identify the radio chip*/
  189. if (ah->ah_version == AR5K_AR5210) {
  190. ah->ah_radio = AR5K_RF5110;
  191. } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_5112) {
  192. ah->ah_radio = AR5K_RF5111;
  193. ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5111;
  194. } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC0) {
  195. ah->ah_radio = AR5K_RF5112;
  196. if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_5112A) {
  197. ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112;
  198. } else {
  199. ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
  200. }
  201. } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC1) {
  202. ah->ah_radio = AR5K_RF2413;
  203. ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
  204. } else {
  205. ah->ah_radio = AR5K_RF5413;
  206. if (ah->ah_mac_srev <= AR5K_SREV_VER_AR5424 &&
  207. ah->ah_mac_srev >= AR5K_SREV_VER_AR2424)
  208. ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5424;
  209. else if (ah->ah_mac_srev >= AR5K_SREV_VER_AR2425)
  210. ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112;
  211. else
  212. ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
  213. }
  214. ah->ah_phy = AR5K_PHY(0);
  215. /*
  216. * Get card capabilities, values, ...
  217. */
  218. ret = ath5k_eeprom_init(ah);
  219. if (ret) {
  220. ATH5K_ERR(sc, "unable to init EEPROM\n");
  221. goto err_free;
  222. }
  223. /* Get misc capabilities */
  224. ret = ath5k_hw_get_capabilities(ah);
  225. if (ret) {
  226. ATH5K_ERR(sc, "unable to get device capabilities: 0x%04x\n",
  227. sc->pdev->device);
  228. goto err_free;
  229. }
  230. /* Get MAC address */
  231. ret = ath5k_eeprom_read_mac(ah, mac);
  232. if (ret) {
  233. ATH5K_ERR(sc, "unable to read address from EEPROM: 0x%04x\n",
  234. sc->pdev->device);
  235. goto err_free;
  236. }
  237. ath5k_hw_set_lladdr(ah, mac);
  238. /* Set BSSID to bcast address: ff:ff:ff:ff:ff:ff for now */
  239. memset(ah->ah_bssid, 0xff, ETH_ALEN);
  240. ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
  241. ath5k_hw_set_opmode(ah);
  242. ath5k_hw_set_rfgain_opt(ah);
  243. return ah;
  244. err_free:
  245. kfree(ah);
  246. err:
  247. return ERR_PTR(ret);
  248. }
  249. /*
  250. * Bring up MAC + PHY Chips
  251. */
  252. static int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
  253. {
  254. u32 turbo, mode, clock;
  255. int ret;
  256. turbo = 0;
  257. mode = 0;
  258. clock = 0;
  259. ATH5K_TRACE(ah->ah_sc);
  260. /* Wakeup the device */
  261. ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
  262. if (ret) {
  263. ATH5K_ERR(ah->ah_sc, "failed to wakeup the MAC Chip\n");
  264. return ret;
  265. }
  266. if (ah->ah_version != AR5K_AR5210) {
  267. /*
  268. * Get channel mode flags
  269. */
  270. if (ah->ah_radio >= AR5K_RF5112) {
  271. mode = AR5K_PHY_MODE_RAD_RF5112;
  272. clock = AR5K_PHY_PLL_RF5112;
  273. } else {
  274. mode = AR5K_PHY_MODE_RAD_RF5111; /*Zero*/
  275. clock = AR5K_PHY_PLL_RF5111; /*Zero*/
  276. }
  277. if (flags & CHANNEL_2GHZ) {
  278. mode |= AR5K_PHY_MODE_FREQ_2GHZ;
  279. clock |= AR5K_PHY_PLL_44MHZ;
  280. if (flags & CHANNEL_CCK) {
  281. mode |= AR5K_PHY_MODE_MOD_CCK;
  282. } else if (flags & CHANNEL_OFDM) {
  283. /* XXX Dynamic OFDM/CCK is not supported by the
  284. * AR5211 so we set MOD_OFDM for plain g (no
  285. * CCK headers) operation. We need to test
  286. * this, 5211 might support ofdm-only g after
  287. * all, there are also initial register values
  288. * in the code for g mode (see initvals.c). */
  289. if (ah->ah_version == AR5K_AR5211)
  290. mode |= AR5K_PHY_MODE_MOD_OFDM;
  291. else
  292. mode |= AR5K_PHY_MODE_MOD_DYN;
  293. } else {
  294. ATH5K_ERR(ah->ah_sc,
  295. "invalid radio modulation mode\n");
  296. return -EINVAL;
  297. }
  298. } else if (flags & CHANNEL_5GHZ) {
  299. mode |= AR5K_PHY_MODE_FREQ_5GHZ;
  300. clock |= AR5K_PHY_PLL_40MHZ;
  301. if (flags & CHANNEL_OFDM)
  302. mode |= AR5K_PHY_MODE_MOD_OFDM;
  303. else {
  304. ATH5K_ERR(ah->ah_sc,
  305. "invalid radio modulation mode\n");
  306. return -EINVAL;
  307. }
  308. } else {
  309. ATH5K_ERR(ah->ah_sc, "invalid radio frequency mode\n");
  310. return -EINVAL;
  311. }
  312. if (flags & CHANNEL_TURBO)
  313. turbo = AR5K_PHY_TURBO_MODE | AR5K_PHY_TURBO_SHORT;
  314. } else { /* Reset the device */
  315. /* ...enable Atheros turbo mode if requested */
  316. if (flags & CHANNEL_TURBO)
  317. ath5k_hw_reg_write(ah, AR5K_PHY_TURBO_MODE,
  318. AR5K_PHY_TURBO);
  319. }
  320. /* ...reset chipset and PCI device */
  321. if (ah->ah_single_chip == false && ath5k_hw_nic_reset(ah,
  322. AR5K_RESET_CTL_CHIP | AR5K_RESET_CTL_PCI)) {
  323. ATH5K_ERR(ah->ah_sc, "failed to reset the MAC Chip + PCI\n");
  324. return -EIO;
  325. }
  326. if (ah->ah_version == AR5K_AR5210)
  327. udelay(2300);
  328. /* ...wakeup again!*/
  329. ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
  330. if (ret) {
  331. ATH5K_ERR(ah->ah_sc, "failed to resume the MAC Chip\n");
  332. return ret;
  333. }
  334. /* ...final warm reset */
  335. if (ath5k_hw_nic_reset(ah, 0)) {
  336. ATH5K_ERR(ah->ah_sc, "failed to warm reset the MAC Chip\n");
  337. return -EIO;
  338. }
  339. if (ah->ah_version != AR5K_AR5210) {
  340. /* ...set the PHY operating mode */
  341. ath5k_hw_reg_write(ah, clock, AR5K_PHY_PLL);
  342. udelay(300);
  343. ath5k_hw_reg_write(ah, mode, AR5K_PHY_MODE);
  344. ath5k_hw_reg_write(ah, turbo, AR5K_PHY_TURBO);
  345. }
  346. return 0;
  347. }
  348. /*
  349. * Get the rate table for a specific operation mode
  350. */
  351. const struct ath5k_rate_table *ath5k_hw_get_rate_table(struct ath5k_hw *ah,
  352. unsigned int mode)
  353. {
  354. ATH5K_TRACE(ah->ah_sc);
  355. if (!test_bit(mode, ah->ah_capabilities.cap_mode))
  356. return NULL;
  357. /* Get rate tables */
  358. switch (mode) {
  359. case AR5K_MODE_11A:
  360. return &ath5k_rt_11a;
  361. case AR5K_MODE_11A_TURBO:
  362. return &ath5k_rt_turbo;
  363. case AR5K_MODE_11B:
  364. return &ath5k_rt_11b;
  365. case AR5K_MODE_11G:
  366. return &ath5k_rt_11g;
  367. case AR5K_MODE_11G_TURBO:
  368. return &ath5k_rt_xr;
  369. }
  370. return NULL;
  371. }
  372. /*
  373. * Free the ath5k_hw struct
  374. */
  375. void ath5k_hw_detach(struct ath5k_hw *ah)
  376. {
  377. ATH5K_TRACE(ah->ah_sc);
  378. if (ah->ah_rf_banks != NULL)
  379. kfree(ah->ah_rf_banks);
  380. /* assume interrupts are down */
  381. kfree(ah);
  382. }
  383. /****************************\
  384. Reset function and helpers
  385. \****************************/
  386. /**
  387. * ath5k_hw_write_ofdm_timings - set OFDM timings on AR5212
  388. *
  389. * @ah: the &struct ath5k_hw
  390. * @channel: the currently set channel upon reset
  391. *
  392. * Write the OFDM timings for the AR5212 upon reset. This is a helper for
  393. * ath5k_hw_reset(). This seems to tune the PLL a specified frequency
  394. * depending on the bandwidth of the channel.
  395. *
  396. */
  397. static inline int ath5k_hw_write_ofdm_timings(struct ath5k_hw *ah,
  398. struct ieee80211_channel *channel)
  399. {
  400. /* Get exponent and mantissa and set it */
  401. u32 coef_scaled, coef_exp, coef_man,
  402. ds_coef_exp, ds_coef_man, clock;
  403. if (!(ah->ah_version == AR5K_AR5212) ||
  404. !(channel->hw_value & CHANNEL_OFDM))
  405. BUG();
  406. /* Seems there are two PLLs, one for baseband sampling and one
  407. * for tuning. Tuning basebands are 40 MHz or 80MHz when in
  408. * turbo. */
  409. clock = channel->hw_value & CHANNEL_TURBO ? 80 : 40;
  410. coef_scaled = ((5 * (clock << 24)) / 2) /
  411. channel->center_freq;
  412. for (coef_exp = 31; coef_exp > 0; coef_exp--)
  413. if ((coef_scaled >> coef_exp) & 0x1)
  414. break;
  415. if (!coef_exp)
  416. return -EINVAL;
  417. coef_exp = 14 - (coef_exp - 24);
  418. coef_man = coef_scaled +
  419. (1 << (24 - coef_exp - 1));
  420. ds_coef_man = coef_man >> (24 - coef_exp);
  421. ds_coef_exp = coef_exp - 16;
  422. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
  423. AR5K_PHY_TIMING_3_DSC_MAN, ds_coef_man);
  424. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
  425. AR5K_PHY_TIMING_3_DSC_EXP, ds_coef_exp);
  426. return 0;
  427. }
  428. /**
  429. * ath5k_hw_write_rate_duration - set rate duration during hw resets
  430. *
  431. * @ah: the &struct ath5k_hw
  432. * @mode: one of enum ath5k_driver_mode
  433. *
  434. * Write the rate duration table for the current mode upon hw reset. This
  435. * is a helper for ath5k_hw_reset(). It seems all this is doing is setting
  436. * an ACK timeout for the hardware for the current mode for each rate. The
  437. * rates which are capable of short preamble (802.11b rates 2Mbps, 5.5Mbps,
  438. * and 11Mbps) have another register for the short preamble ACK timeout
  439. * calculation.
  440. *
  441. */
  442. static inline void ath5k_hw_write_rate_duration(struct ath5k_hw *ah,
  443. unsigned int mode)
  444. {
  445. struct ath5k_softc *sc = ah->ah_sc;
  446. const struct ath5k_rate_table *rt;
  447. struct ieee80211_rate srate = {};
  448. unsigned int i;
  449. /* Get rate table for the current operating mode */
  450. rt = ath5k_hw_get_rate_table(ah, mode);
  451. /* Write rate duration table */
  452. for (i = 0; i < rt->rate_count; i++) {
  453. const struct ath5k_rate *rate, *control_rate;
  454. u32 reg;
  455. u16 tx_time;
  456. rate = &rt->rates[i];
  457. control_rate = &rt->rates[rate->control_rate];
  458. /* Set ACK timeout */
  459. reg = AR5K_RATE_DUR(rate->rate_code);
  460. srate.bitrate = control_rate->rate_kbps/100;
  461. /* An ACK frame consists of 10 bytes. If you add the FCS,
  462. * which ieee80211_generic_frame_duration() adds,
  463. * its 14 bytes. Note we use the control rate and not the
  464. * actual rate for this rate. See mac80211 tx.c
  465. * ieee80211_duration() for a brief description of
  466. * what rate we should choose to TX ACKs. */
  467. tx_time = le16_to_cpu(ieee80211_generic_frame_duration(sc->hw,
  468. sc->vif, 10, &srate));
  469. ath5k_hw_reg_write(ah, tx_time, reg);
  470. if (!HAS_SHPREAMBLE(i))
  471. continue;
  472. /*
  473. * We're not distinguishing short preamble here,
  474. * This is true, all we'll get is a longer value here
  475. * which is not necessarilly bad. We could use
  476. * export ieee80211_frame_duration() but that needs to be
  477. * fixed first to be properly used by mac802111 drivers:
  478. *
  479. * - remove erp stuff and let the routine figure ofdm
  480. * erp rates
  481. * - remove passing argument ieee80211_local as
  482. * drivers don't have access to it
  483. * - move drivers using ieee80211_generic_frame_duration()
  484. * to this
  485. */
  486. ath5k_hw_reg_write(ah, tx_time,
  487. reg + (AR5K_SET_SHORT_PREAMBLE << 2));
  488. }
  489. }
  490. /*
  491. * Main reset function
  492. */
  493. int ath5k_hw_reset(struct ath5k_hw *ah, enum ieee80211_if_types op_mode,
  494. struct ieee80211_channel *channel, bool change_channel)
  495. {
  496. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  497. u32 data, s_seq, s_ant, s_led[3];
  498. unsigned int i, mode, freq, ee_mode, ant[2];
  499. int ret;
  500. ATH5K_TRACE(ah->ah_sc);
  501. s_seq = 0;
  502. s_ant = 0;
  503. ee_mode = 0;
  504. freq = 0;
  505. mode = 0;
  506. /*
  507. * Save some registers before a reset
  508. */
  509. /*DCU/Antenna selection not available on 5210*/
  510. if (ah->ah_version != AR5K_AR5210) {
  511. if (change_channel == true) {
  512. /* Seq number for queue 0 -do this for all queues ? */
  513. s_seq = ath5k_hw_reg_read(ah,
  514. AR5K_QUEUE_DFS_SEQNUM(0));
  515. /*Default antenna*/
  516. s_ant = ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);
  517. }
  518. }
  519. /*GPIOs*/
  520. s_led[0] = ath5k_hw_reg_read(ah, AR5K_PCICFG) & AR5K_PCICFG_LEDSTATE;
  521. s_led[1] = ath5k_hw_reg_read(ah, AR5K_GPIOCR);
  522. s_led[2] = ath5k_hw_reg_read(ah, AR5K_GPIODO);
  523. if (change_channel == true && ah->ah_rf_banks != NULL)
  524. ath5k_hw_get_rf_gain(ah);
  525. /*Wakeup the device*/
  526. ret = ath5k_hw_nic_wakeup(ah, channel->hw_value, false);
  527. if (ret)
  528. return ret;
  529. /*
  530. * Initialize operating mode
  531. */
  532. ah->ah_op_mode = op_mode;
  533. /*
  534. * 5111/5112 Settings
  535. * 5210 only comes with RF5110
  536. */
  537. if (ah->ah_version != AR5K_AR5210) {
  538. if (ah->ah_radio != AR5K_RF5111 &&
  539. ah->ah_radio != AR5K_RF5112 &&
  540. ah->ah_radio != AR5K_RF5413 &&
  541. ah->ah_radio != AR5K_RF2413) {
  542. ATH5K_ERR(ah->ah_sc,
  543. "invalid phy radio: %u\n", ah->ah_radio);
  544. return -EINVAL;
  545. }
  546. switch (channel->hw_value & CHANNEL_MODES) {
  547. case CHANNEL_A:
  548. mode = AR5K_MODE_11A;
  549. freq = AR5K_INI_RFGAIN_5GHZ;
  550. ee_mode = AR5K_EEPROM_MODE_11A;
  551. break;
  552. case CHANNEL_G:
  553. mode = AR5K_MODE_11G;
  554. freq = AR5K_INI_RFGAIN_2GHZ;
  555. ee_mode = AR5K_EEPROM_MODE_11G;
  556. break;
  557. case CHANNEL_B:
  558. mode = AR5K_MODE_11B;
  559. freq = AR5K_INI_RFGAIN_2GHZ;
  560. ee_mode = AR5K_EEPROM_MODE_11B;
  561. break;
  562. case CHANNEL_T:
  563. mode = AR5K_MODE_11A_TURBO;
  564. freq = AR5K_INI_RFGAIN_5GHZ;
  565. ee_mode = AR5K_EEPROM_MODE_11A;
  566. break;
  567. /*Is this ok on 5211 too ?*/
  568. case CHANNEL_TG:
  569. mode = AR5K_MODE_11G_TURBO;
  570. freq = AR5K_INI_RFGAIN_2GHZ;
  571. ee_mode = AR5K_EEPROM_MODE_11G;
  572. break;
  573. case CHANNEL_XR:
  574. if (ah->ah_version == AR5K_AR5211) {
  575. ATH5K_ERR(ah->ah_sc,
  576. "XR mode not available on 5211");
  577. return -EINVAL;
  578. }
  579. mode = AR5K_MODE_XR;
  580. freq = AR5K_INI_RFGAIN_5GHZ;
  581. ee_mode = AR5K_EEPROM_MODE_11A;
  582. break;
  583. default:
  584. ATH5K_ERR(ah->ah_sc,
  585. "invalid channel: %d\n", channel->center_freq);
  586. return -EINVAL;
  587. }
  588. /* PHY access enable */
  589. ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));
  590. }
  591. ret = ath5k_hw_write_initvals(ah, mode, change_channel);
  592. if (ret)
  593. return ret;
  594. /*
  595. * 5211/5212 Specific
  596. */
  597. if (ah->ah_version != AR5K_AR5210) {
  598. /*
  599. * Write initial RF gain settings
  600. * This should work for both 5111/5112
  601. */
  602. ret = ath5k_hw_rfgain(ah, freq);
  603. if (ret)
  604. return ret;
  605. mdelay(1);
  606. /*
  607. * Write some more initial register settings
  608. */
  609. if (ah->ah_version > AR5K_AR5211){ /* found on 5213+ */
  610. ath5k_hw_reg_write(ah, 0x0002a002, AR5K_PHY(11));
  611. if (channel->hw_value == CHANNEL_G)
  612. ath5k_hw_reg_write(ah, 0x00f80d80, AR5K_PHY(83)); /* 0x00fc0ec0 */
  613. else
  614. ath5k_hw_reg_write(ah, 0x00000000, AR5K_PHY(83));
  615. ath5k_hw_reg_write(ah, 0x000001b5, 0xa228); /* 0x000009b5 */
  616. ath5k_hw_reg_write(ah, 0x000009b5, 0xa228);
  617. ath5k_hw_reg_write(ah, 0x0000000f, 0x8060);
  618. ath5k_hw_reg_write(ah, 0x00000000, 0xa254);
  619. ath5k_hw_reg_write(ah, 0x0000000e, AR5K_PHY_SCAL);
  620. }
  621. /* Fix for first revision of the RF5112 RF chipset */
  622. if (ah->ah_radio >= AR5K_RF5112 &&
  623. ah->ah_radio_5ghz_revision <
  624. AR5K_SREV_RAD_5112A) {
  625. ath5k_hw_reg_write(ah, AR5K_PHY_CCKTXCTL_WORLD,
  626. AR5K_PHY_CCKTXCTL);
  627. if (channel->hw_value & CHANNEL_5GHZ)
  628. data = 0xffb81020;
  629. else
  630. data = 0xffb80d20;
  631. ath5k_hw_reg_write(ah, data, AR5K_PHY_FRAME_CTL);
  632. }
  633. /*
  634. * Set TX power (FIXME)
  635. */
  636. ret = ath5k_hw_txpower(ah, channel, AR5K_TUNE_DEFAULT_TXPOWER);
  637. if (ret)
  638. return ret;
  639. /* Write rate duration table only on AR5212 and if
  640. * virtual interface has already been brought up
  641. * XXX: rethink this after new mode changes to
  642. * mac80211 are integrated */
  643. if (ah->ah_version == AR5K_AR5212 &&
  644. ah->ah_sc->vif != NULL)
  645. ath5k_hw_write_rate_duration(ah, mode);
  646. /*
  647. * Write RF registers
  648. * TODO:Does this work on 5211 (5111) ?
  649. */
  650. ret = ath5k_hw_rfregs(ah, channel, mode);
  651. if (ret)
  652. return ret;
  653. /*
  654. * Configure additional registers
  655. */
  656. /* Write OFDM timings on 5212*/
  657. if (ah->ah_version == AR5K_AR5212 &&
  658. channel->hw_value & CHANNEL_OFDM) {
  659. ret = ath5k_hw_write_ofdm_timings(ah, channel);
  660. if (ret)
  661. return ret;
  662. }
  663. /*Enable/disable 802.11b mode on 5111
  664. (enable 2111 frequency converter + CCK)*/
  665. if (ah->ah_radio == AR5K_RF5111) {
  666. if (mode == AR5K_MODE_11B)
  667. AR5K_REG_ENABLE_BITS(ah, AR5K_TXCFG,
  668. AR5K_TXCFG_B_MODE);
  669. else
  670. AR5K_REG_DISABLE_BITS(ah, AR5K_TXCFG,
  671. AR5K_TXCFG_B_MODE);
  672. }
  673. /*
  674. * Set channel and calibrate the PHY
  675. */
  676. ret = ath5k_hw_channel(ah, channel);
  677. if (ret)
  678. return ret;
  679. /* Set antenna mode */
  680. AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x44),
  681. ah->ah_antenna[ee_mode][0], 0xfffffc06);
  682. /*
  683. * In case a fixed antenna was set as default
  684. * write the same settings on both AR5K_PHY_ANT_SWITCH_TABLE
  685. * registers.
  686. */
  687. if (s_ant != 0){
  688. if (s_ant == AR5K_ANT_FIXED_A) /* 1 - Main */
  689. ant[0] = ant[1] = AR5K_ANT_FIXED_A;
  690. else /* 2 - Aux */
  691. ant[0] = ant[1] = AR5K_ANT_FIXED_B;
  692. } else {
  693. ant[0] = AR5K_ANT_FIXED_A;
  694. ant[1] = AR5K_ANT_FIXED_B;
  695. }
  696. ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[0]],
  697. AR5K_PHY_ANT_SWITCH_TABLE_0);
  698. ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[1]],
  699. AR5K_PHY_ANT_SWITCH_TABLE_1);
  700. /* Commit values from EEPROM */
  701. if (ah->ah_radio == AR5K_RF5111)
  702. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_FRAME_CTL,
  703. AR5K_PHY_FRAME_CTL_TX_CLIP, ee->ee_tx_clip);
  704. ath5k_hw_reg_write(ah,
  705. AR5K_PHY_NF_SVAL(ee->ee_noise_floor_thr[ee_mode]),
  706. AR5K_PHY(0x5a));
  707. AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x11),
  708. (ee->ee_switch_settling[ee_mode] << 7) & 0x3f80,
  709. 0xffffc07f);
  710. AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x12),
  711. (ee->ee_ant_tx_rx[ee_mode] << 12) & 0x3f000,
  712. 0xfffc0fff);
  713. AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x14),
  714. (ee->ee_adc_desired_size[ee_mode] & 0x00ff) |
  715. ((ee->ee_pga_desired_size[ee_mode] << 8) & 0xff00),
  716. 0xffff0000);
  717. ath5k_hw_reg_write(ah,
  718. (ee->ee_tx_end2xpa_disable[ee_mode] << 24) |
  719. (ee->ee_tx_end2xpa_disable[ee_mode] << 16) |
  720. (ee->ee_tx_frm2xpa_enable[ee_mode] << 8) |
  721. (ee->ee_tx_frm2xpa_enable[ee_mode]), AR5K_PHY(0x0d));
  722. AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x0a),
  723. ee->ee_tx_end2xlna_enable[ee_mode] << 8, 0xffff00ff);
  724. AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x19),
  725. (ee->ee_thr_62[ee_mode] << 12) & 0x7f000, 0xfff80fff);
  726. AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x49), 4, 0xffffff01);
  727. AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
  728. AR5K_PHY_IQ_CORR_ENABLE |
  729. (ee->ee_i_cal[ee_mode] << AR5K_PHY_IQ_CORR_Q_I_COFF_S) |
  730. ee->ee_q_cal[ee_mode]);
  731. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
  732. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN_2GHZ,
  733. AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX,
  734. ee->ee_margin_tx_rx[ee_mode]);
  735. } else {
  736. mdelay(1);
  737. /* Disable phy and wait */
  738. ath5k_hw_reg_write(ah, AR5K_PHY_ACT_DISABLE, AR5K_PHY_ACT);
  739. mdelay(1);
  740. }
  741. /*
  742. * Restore saved values
  743. */
  744. /*DCU/Antenna selection not available on 5210*/
  745. if (ah->ah_version != AR5K_AR5210) {
  746. ath5k_hw_reg_write(ah, s_seq, AR5K_QUEUE_DFS_SEQNUM(0));
  747. ath5k_hw_reg_write(ah, s_ant, AR5K_DEFAULT_ANTENNA);
  748. }
  749. AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, s_led[0]);
  750. ath5k_hw_reg_write(ah, s_led[1], AR5K_GPIOCR);
  751. ath5k_hw_reg_write(ah, s_led[2], AR5K_GPIODO);
  752. /*
  753. * Misc
  754. */
  755. /* XXX: add ah->aid once mac80211 gives this to us */
  756. ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
  757. ath5k_hw_set_opmode(ah);
  758. /*PISR/SISR Not available on 5210*/
  759. if (ah->ah_version != AR5K_AR5210) {
  760. ath5k_hw_reg_write(ah, 0xffffffff, AR5K_PISR);
  761. /* If we later allow tuning for this, store into sc structure */
  762. data = AR5K_TUNE_RSSI_THRES |
  763. AR5K_TUNE_BMISS_THRES << AR5K_RSSI_THR_BMISS_S;
  764. ath5k_hw_reg_write(ah, data, AR5K_RSSI_THR);
  765. }
  766. /*
  767. * Set Rx/Tx DMA Configuration
  768. *(passing dma size not available on 5210)
  769. */
  770. if (ah->ah_version != AR5K_AR5210) {
  771. AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG, AR5K_TXCFG_SDMAMR,
  772. AR5K_DMASIZE_512B | AR5K_TXCFG_DMASIZE);
  773. AR5K_REG_WRITE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_SDMAMW,
  774. AR5K_DMASIZE_512B);
  775. }
  776. /*
  777. * Enable the PHY and wait until completion
  778. */
  779. ath5k_hw_reg_write(ah, AR5K_PHY_ACT_ENABLE, AR5K_PHY_ACT);
  780. /*
  781. * 5111/5112 Specific
  782. */
  783. if (ah->ah_version != AR5K_AR5210) {
  784. data = ath5k_hw_reg_read(ah, AR5K_PHY_RX_DELAY) &
  785. AR5K_PHY_RX_DELAY_M;
  786. data = (channel->hw_value & CHANNEL_CCK) ?
  787. ((data << 2) / 22) : (data / 10);
  788. udelay(100 + data);
  789. } else {
  790. mdelay(1);
  791. }
  792. /*
  793. * Enable calibration and wait until completion
  794. */
  795. AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL,
  796. AR5K_PHY_AGCCTL_CAL);
  797. if (ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
  798. AR5K_PHY_AGCCTL_CAL, 0, false)) {
  799. ATH5K_ERR(ah->ah_sc, "calibration timeout (%uMHz)\n",
  800. channel->center_freq);
  801. return -EAGAIN;
  802. }
  803. ret = ath5k_hw_noise_floor_calibration(ah, channel->center_freq);
  804. if (ret)
  805. return ret;
  806. ah->ah_calibration = false;
  807. /* A and G modes can use QAM modulation which requires enabling
  808. * I and Q calibration. Don't bother in B mode. */
  809. if (!(mode == AR5K_MODE_11B)) {
  810. ah->ah_calibration = true;
  811. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ,
  812. AR5K_PHY_IQ_CAL_NUM_LOG_MAX, 15);
  813. AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
  814. AR5K_PHY_IQ_RUN);
  815. }
  816. /*
  817. * Reset queues and start beacon timers at the end of the reset routine
  818. */
  819. for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++) {
  820. /*No QCU on 5210*/
  821. if (ah->ah_version != AR5K_AR5210)
  822. AR5K_REG_WRITE_Q(ah, AR5K_QUEUE_QCUMASK(i), i);
  823. ret = ath5k_hw_reset_tx_queue(ah, i);
  824. if (ret) {
  825. ATH5K_ERR(ah->ah_sc,
  826. "failed to reset TX queue #%d\n", i);
  827. return ret;
  828. }
  829. }
  830. /* Pre-enable interrupts on 5211/5212*/
  831. if (ah->ah_version != AR5K_AR5210)
  832. ath5k_hw_set_intr(ah, AR5K_INT_RX | AR5K_INT_TX |
  833. AR5K_INT_FATAL);
  834. /*
  835. * Set RF kill flags if supported by the device (read from the EEPROM)
  836. * Disable gpio_intr for now since it results system hang.
  837. * TODO: Handle this in ath5k_intr
  838. */
  839. #if 0
  840. if (AR5K_EEPROM_HDR_RFKILL(ah->ah_capabilities.cap_eeprom.ee_header)) {
  841. ath5k_hw_set_gpio_input(ah, 0);
  842. ah->ah_gpio[0] = ath5k_hw_get_gpio(ah, 0);
  843. if (ah->ah_gpio[0] == 0)
  844. ath5k_hw_set_gpio_intr(ah, 0, 1);
  845. else
  846. ath5k_hw_set_gpio_intr(ah, 0, 0);
  847. }
  848. #endif
  849. /*
  850. * Set the 32MHz reference clock on 5212 phy clock sleep register
  851. */
  852. if (ah->ah_version == AR5K_AR5212) {
  853. ath5k_hw_reg_write(ah, AR5K_PHY_SCR_32MHZ, AR5K_PHY_SCR);
  854. ath5k_hw_reg_write(ah, AR5K_PHY_SLMT_32MHZ, AR5K_PHY_SLMT);
  855. ath5k_hw_reg_write(ah, AR5K_PHY_SCAL_32MHZ, AR5K_PHY_SCAL);
  856. ath5k_hw_reg_write(ah, AR5K_PHY_SCLOCK_32MHZ, AR5K_PHY_SCLOCK);
  857. ath5k_hw_reg_write(ah, AR5K_PHY_SDELAY_32MHZ, AR5K_PHY_SDELAY);
  858. ath5k_hw_reg_write(ah, ah->ah_phy_spending, AR5K_PHY_SPENDING);
  859. }
  860. /*
  861. * Disable beacons and reset the register
  862. */
  863. AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE |
  864. AR5K_BEACON_RESET_TSF);
  865. return 0;
  866. }
  867. /*
  868. * Reset chipset
  869. */
  870. static int ath5k_hw_nic_reset(struct ath5k_hw *ah, u32 val)
  871. {
  872. int ret;
  873. u32 mask = val ? val : ~0U;
  874. ATH5K_TRACE(ah->ah_sc);
  875. /* Read-and-clear RX Descriptor Pointer*/
  876. ath5k_hw_reg_read(ah, AR5K_RXDP);
  877. /*
  878. * Reset the device and wait until success
  879. */
  880. ath5k_hw_reg_write(ah, val, AR5K_RESET_CTL);
  881. /* Wait at least 128 PCI clocks */
  882. udelay(15);
  883. if (ah->ah_version == AR5K_AR5210) {
  884. val &= AR5K_RESET_CTL_CHIP;
  885. mask &= AR5K_RESET_CTL_CHIP;
  886. } else {
  887. val &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
  888. mask &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
  889. }
  890. ret = ath5k_hw_register_timeout(ah, AR5K_RESET_CTL, mask, val, false);
  891. /*
  892. * Reset configuration register (for hw byte-swap). Note that this
  893. * is only set for big endian. We do the necessary magic in
  894. * AR5K_INIT_CFG.
  895. */
  896. if ((val & AR5K_RESET_CTL_PCU) == 0)
  897. ath5k_hw_reg_write(ah, AR5K_INIT_CFG, AR5K_CFG);
  898. return ret;
  899. }
  900. /*
  901. * Power management functions
  902. */
  903. /*
  904. * Sleep control
  905. */
  906. int ath5k_hw_set_power(struct ath5k_hw *ah, enum ath5k_power_mode mode,
  907. bool set_chip, u16 sleep_duration)
  908. {
  909. unsigned int i;
  910. u32 staid;
  911. ATH5K_TRACE(ah->ah_sc);
  912. staid = ath5k_hw_reg_read(ah, AR5K_STA_ID1);
  913. switch (mode) {
  914. case AR5K_PM_AUTO:
  915. staid &= ~AR5K_STA_ID1_DEFAULT_ANTENNA;
  916. /* fallthrough */
  917. case AR5K_PM_NETWORK_SLEEP:
  918. if (set_chip == true)
  919. ath5k_hw_reg_write(ah,
  920. AR5K_SLEEP_CTL_SLE | sleep_duration,
  921. AR5K_SLEEP_CTL);
  922. staid |= AR5K_STA_ID1_PWR_SV;
  923. break;
  924. case AR5K_PM_FULL_SLEEP:
  925. if (set_chip == true)
  926. ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_SLP,
  927. AR5K_SLEEP_CTL);
  928. staid |= AR5K_STA_ID1_PWR_SV;
  929. break;
  930. case AR5K_PM_AWAKE:
  931. if (set_chip == false)
  932. goto commit;
  933. ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_WAKE,
  934. AR5K_SLEEP_CTL);
  935. for (i = 5000; i > 0; i--) {
  936. /* Check if the chip did wake up */
  937. if ((ath5k_hw_reg_read(ah, AR5K_PCICFG) &
  938. AR5K_PCICFG_SPWR_DN) == 0)
  939. break;
  940. /* Wait a bit and retry */
  941. udelay(200);
  942. ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_WAKE,
  943. AR5K_SLEEP_CTL);
  944. }
  945. /* Fail if the chip didn't wake up */
  946. if (i <= 0)
  947. return -EIO;
  948. staid &= ~AR5K_STA_ID1_PWR_SV;
  949. break;
  950. default:
  951. return -EINVAL;
  952. }
  953. commit:
  954. ah->ah_power_mode = mode;
  955. ath5k_hw_reg_write(ah, staid, AR5K_STA_ID1);
  956. return 0;
  957. }
  958. /***********************\
  959. DMA Related Functions
  960. \***********************/
  961. /*
  962. * Receive functions
  963. */
  964. /*
  965. * Start DMA receive
  966. */
  967. void ath5k_hw_start_rx(struct ath5k_hw *ah)
  968. {
  969. ATH5K_TRACE(ah->ah_sc);
  970. ath5k_hw_reg_write(ah, AR5K_CR_RXE, AR5K_CR);
  971. }
  972. /*
  973. * Stop DMA receive
  974. */
  975. int ath5k_hw_stop_rx_dma(struct ath5k_hw *ah)
  976. {
  977. unsigned int i;
  978. ATH5K_TRACE(ah->ah_sc);
  979. ath5k_hw_reg_write(ah, AR5K_CR_RXD, AR5K_CR);
  980. /*
  981. * It may take some time to disable the DMA receive unit
  982. */
  983. for (i = 2000; i > 0 &&
  984. (ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_CR_RXE) != 0;
  985. i--)
  986. udelay(10);
  987. return i ? 0 : -EBUSY;
  988. }
  989. /*
  990. * Get the address of the RX Descriptor
  991. */
  992. u32 ath5k_hw_get_rx_buf(struct ath5k_hw *ah)
  993. {
  994. return ath5k_hw_reg_read(ah, AR5K_RXDP);
  995. }
  996. /*
  997. * Set the address of the RX Descriptor
  998. */
  999. void ath5k_hw_put_rx_buf(struct ath5k_hw *ah, u32 phys_addr)
  1000. {
  1001. ATH5K_TRACE(ah->ah_sc);
  1002. /*TODO:Shouldn't we check if RX is enabled first ?*/
  1003. ath5k_hw_reg_write(ah, phys_addr, AR5K_RXDP);
  1004. }
  1005. /*
  1006. * Transmit functions
  1007. */
  1008. /*
  1009. * Start DMA transmit for a specific queue
  1010. * (see also QCU/DCU functions)
  1011. */
  1012. int ath5k_hw_tx_start(struct ath5k_hw *ah, unsigned int queue)
  1013. {
  1014. u32 tx_queue;
  1015. ATH5K_TRACE(ah->ah_sc);
  1016. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  1017. /* Return if queue is declared inactive */
  1018. if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
  1019. return -EIO;
  1020. if (ah->ah_version == AR5K_AR5210) {
  1021. tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
  1022. /*
  1023. * Set the queue by type on 5210
  1024. */
  1025. switch (ah->ah_txq[queue].tqi_type) {
  1026. case AR5K_TX_QUEUE_DATA:
  1027. tx_queue |= AR5K_CR_TXE0 & ~AR5K_CR_TXD0;
  1028. break;
  1029. case AR5K_TX_QUEUE_BEACON:
  1030. tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
  1031. ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
  1032. AR5K_BSR);
  1033. break;
  1034. case AR5K_TX_QUEUE_CAB:
  1035. tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
  1036. ath5k_hw_reg_write(ah, AR5K_BCR_TQ1FV | AR5K_BCR_TQ1V |
  1037. AR5K_BCR_BDMAE, AR5K_BSR);
  1038. break;
  1039. default:
  1040. return -EINVAL;
  1041. }
  1042. /* Start queue */
  1043. ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
  1044. } else {
  1045. /* Return if queue is disabled */
  1046. if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXD, queue))
  1047. return -EIO;
  1048. /* Start queue */
  1049. AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXE, queue);
  1050. }
  1051. return 0;
  1052. }
  1053. /*
  1054. * Stop DMA transmit for a specific queue
  1055. * (see also QCU/DCU functions)
  1056. */
  1057. int ath5k_hw_stop_tx_dma(struct ath5k_hw *ah, unsigned int queue)
  1058. {
  1059. unsigned int i = 100;
  1060. u32 tx_queue, pending;
  1061. ATH5K_TRACE(ah->ah_sc);
  1062. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  1063. /* Return if queue is declared inactive */
  1064. if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
  1065. return -EIO;
  1066. if (ah->ah_version == AR5K_AR5210) {
  1067. tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
  1068. /*
  1069. * Set by queue type
  1070. */
  1071. switch (ah->ah_txq[queue].tqi_type) {
  1072. case AR5K_TX_QUEUE_DATA:
  1073. tx_queue |= AR5K_CR_TXD0 & ~AR5K_CR_TXE0;
  1074. break;
  1075. case AR5K_TX_QUEUE_BEACON:
  1076. case AR5K_TX_QUEUE_CAB:
  1077. /* XXX Fix me... */
  1078. tx_queue |= AR5K_CR_TXD1 & ~AR5K_CR_TXD1;
  1079. ath5k_hw_reg_write(ah, 0, AR5K_BSR);
  1080. break;
  1081. default:
  1082. return -EINVAL;
  1083. }
  1084. /* Stop queue */
  1085. ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
  1086. } else {
  1087. /*
  1088. * Schedule TX disable and wait until queue is empty
  1089. */
  1090. AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXD, queue);
  1091. /*Check for pending frames*/
  1092. do {
  1093. pending = ath5k_hw_reg_read(ah,
  1094. AR5K_QUEUE_STATUS(queue)) &
  1095. AR5K_QCU_STS_FRMPENDCNT;
  1096. udelay(100);
  1097. } while (--i && pending);
  1098. /* Clear register */
  1099. ath5k_hw_reg_write(ah, 0, AR5K_QCU_TXD);
  1100. }
  1101. /* TODO: Check for success else return error */
  1102. return 0;
  1103. }
  1104. /*
  1105. * Get the address of the TX Descriptor for a specific queue
  1106. * (see also QCU/DCU functions)
  1107. */
  1108. u32 ath5k_hw_get_tx_buf(struct ath5k_hw *ah, unsigned int queue)
  1109. {
  1110. u16 tx_reg;
  1111. ATH5K_TRACE(ah->ah_sc);
  1112. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  1113. /*
  1114. * Get the transmit queue descriptor pointer from the selected queue
  1115. */
  1116. /*5210 doesn't have QCU*/
  1117. if (ah->ah_version == AR5K_AR5210) {
  1118. switch (ah->ah_txq[queue].tqi_type) {
  1119. case AR5K_TX_QUEUE_DATA:
  1120. tx_reg = AR5K_NOQCU_TXDP0;
  1121. break;
  1122. case AR5K_TX_QUEUE_BEACON:
  1123. case AR5K_TX_QUEUE_CAB:
  1124. tx_reg = AR5K_NOQCU_TXDP1;
  1125. break;
  1126. default:
  1127. return 0xffffffff;
  1128. }
  1129. } else {
  1130. tx_reg = AR5K_QUEUE_TXDP(queue);
  1131. }
  1132. return ath5k_hw_reg_read(ah, tx_reg);
  1133. }
  1134. /*
  1135. * Set the address of the TX Descriptor for a specific queue
  1136. * (see also QCU/DCU functions)
  1137. */
  1138. int ath5k_hw_put_tx_buf(struct ath5k_hw *ah, unsigned int queue, u32 phys_addr)
  1139. {
  1140. u16 tx_reg;
  1141. ATH5K_TRACE(ah->ah_sc);
  1142. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  1143. /*
  1144. * Set the transmit queue descriptor pointer register by type
  1145. * on 5210
  1146. */
  1147. if (ah->ah_version == AR5K_AR5210) {
  1148. switch (ah->ah_txq[queue].tqi_type) {
  1149. case AR5K_TX_QUEUE_DATA:
  1150. tx_reg = AR5K_NOQCU_TXDP0;
  1151. break;
  1152. case AR5K_TX_QUEUE_BEACON:
  1153. case AR5K_TX_QUEUE_CAB:
  1154. tx_reg = AR5K_NOQCU_TXDP1;
  1155. break;
  1156. default:
  1157. return -EINVAL;
  1158. }
  1159. } else {
  1160. /*
  1161. * Set the transmit queue descriptor pointer for
  1162. * the selected queue on QCU for 5211+
  1163. * (this won't work if the queue is still active)
  1164. */
  1165. if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, queue))
  1166. return -EIO;
  1167. tx_reg = AR5K_QUEUE_TXDP(queue);
  1168. }
  1169. /* Set descriptor pointer */
  1170. ath5k_hw_reg_write(ah, phys_addr, tx_reg);
  1171. return 0;
  1172. }
  1173. /*
  1174. * Update tx trigger level
  1175. */
  1176. int ath5k_hw_update_tx_triglevel(struct ath5k_hw *ah, bool increase)
  1177. {
  1178. u32 trigger_level, imr;
  1179. int ret = -EIO;
  1180. ATH5K_TRACE(ah->ah_sc);
  1181. /*
  1182. * Disable interrupts by setting the mask
  1183. */
  1184. imr = ath5k_hw_set_intr(ah, ah->ah_imr & ~AR5K_INT_GLOBAL);
  1185. /*TODO: Boundary check on trigger_level*/
  1186. trigger_level = AR5K_REG_MS(ath5k_hw_reg_read(ah, AR5K_TXCFG),
  1187. AR5K_TXCFG_TXFULL);
  1188. if (increase == false) {
  1189. if (--trigger_level < AR5K_TUNE_MIN_TX_FIFO_THRES)
  1190. goto done;
  1191. } else
  1192. trigger_level +=
  1193. ((AR5K_TUNE_MAX_TX_FIFO_THRES - trigger_level) / 2);
  1194. /*
  1195. * Update trigger level on success
  1196. */
  1197. if (ah->ah_version == AR5K_AR5210)
  1198. ath5k_hw_reg_write(ah, trigger_level, AR5K_TRIG_LVL);
  1199. else
  1200. AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
  1201. AR5K_TXCFG_TXFULL, trigger_level);
  1202. ret = 0;
  1203. done:
  1204. /*
  1205. * Restore interrupt mask
  1206. */
  1207. ath5k_hw_set_intr(ah, imr);
  1208. return ret;
  1209. }
  1210. /*
  1211. * Interrupt handling
  1212. */
  1213. /*
  1214. * Check if we have pending interrupts
  1215. */
  1216. bool ath5k_hw_is_intr_pending(struct ath5k_hw *ah)
  1217. {
  1218. ATH5K_TRACE(ah->ah_sc);
  1219. return ath5k_hw_reg_read(ah, AR5K_INTPEND);
  1220. }
  1221. /*
  1222. * Get interrupt mask (ISR)
  1223. */
  1224. int ath5k_hw_get_isr(struct ath5k_hw *ah, enum ath5k_int *interrupt_mask)
  1225. {
  1226. u32 data;
  1227. ATH5K_TRACE(ah->ah_sc);
  1228. /*
  1229. * Read interrupt status from the Interrupt Status register
  1230. * on 5210
  1231. */
  1232. if (ah->ah_version == AR5K_AR5210) {
  1233. data = ath5k_hw_reg_read(ah, AR5K_ISR);
  1234. if (unlikely(data == AR5K_INT_NOCARD)) {
  1235. *interrupt_mask = data;
  1236. return -ENODEV;
  1237. }
  1238. } else {
  1239. /*
  1240. * Read interrupt status from the Read-And-Clear shadow register
  1241. * Note: PISR/SISR Not available on 5210
  1242. */
  1243. data = ath5k_hw_reg_read(ah, AR5K_RAC_PISR);
  1244. }
  1245. /*
  1246. * Get abstract interrupt mask (driver-compatible)
  1247. */
  1248. *interrupt_mask = (data & AR5K_INT_COMMON) & ah->ah_imr;
  1249. if (unlikely(data == AR5K_INT_NOCARD))
  1250. return -ENODEV;
  1251. if (data & (AR5K_ISR_RXOK | AR5K_ISR_RXERR))
  1252. *interrupt_mask |= AR5K_INT_RX;
  1253. if (data & (AR5K_ISR_TXOK | AR5K_ISR_TXERR
  1254. | AR5K_ISR_TXDESC | AR5K_ISR_TXEOL))
  1255. *interrupt_mask |= AR5K_INT_TX;
  1256. if (ah->ah_version != AR5K_AR5210) {
  1257. /*HIU = Host Interface Unit (PCI etc)*/
  1258. if (unlikely(data & (AR5K_ISR_HIUERR)))
  1259. *interrupt_mask |= AR5K_INT_FATAL;
  1260. /*Beacon Not Ready*/
  1261. if (unlikely(data & (AR5K_ISR_BNR)))
  1262. *interrupt_mask |= AR5K_INT_BNR;
  1263. }
  1264. /*
  1265. * XXX: BMISS interrupts may occur after association.
  1266. * I found this on 5210 code but it needs testing. If this is
  1267. * true we should disable them before assoc and re-enable them
  1268. * after a successfull assoc + some jiffies.
  1269. */
  1270. #if 0
  1271. interrupt_mask &= ~AR5K_INT_BMISS;
  1272. #endif
  1273. /*
  1274. * In case we didn't handle anything,
  1275. * print the register value.
  1276. */
  1277. if (unlikely(*interrupt_mask == 0 && net_ratelimit()))
  1278. ATH5K_PRINTF("0x%08x\n", data);
  1279. return 0;
  1280. }
  1281. /*
  1282. * Set interrupt mask
  1283. */
  1284. enum ath5k_int ath5k_hw_set_intr(struct ath5k_hw *ah, enum ath5k_int new_mask)
  1285. {
  1286. enum ath5k_int old_mask, int_mask;
  1287. /*
  1288. * Disable card interrupts to prevent any race conditions
  1289. * (they will be re-enabled afterwards).
  1290. */
  1291. ath5k_hw_reg_write(ah, AR5K_IER_DISABLE, AR5K_IER);
  1292. old_mask = ah->ah_imr;
  1293. /*
  1294. * Add additional, chipset-dependent interrupt mask flags
  1295. * and write them to the IMR (interrupt mask register).
  1296. */
  1297. int_mask = new_mask & AR5K_INT_COMMON;
  1298. if (new_mask & AR5K_INT_RX)
  1299. int_mask |= AR5K_IMR_RXOK | AR5K_IMR_RXERR | AR5K_IMR_RXORN |
  1300. AR5K_IMR_RXDESC;
  1301. if (new_mask & AR5K_INT_TX)
  1302. int_mask |= AR5K_IMR_TXOK | AR5K_IMR_TXERR | AR5K_IMR_TXDESC |
  1303. AR5K_IMR_TXURN;
  1304. if (ah->ah_version != AR5K_AR5210) {
  1305. if (new_mask & AR5K_INT_FATAL) {
  1306. int_mask |= AR5K_IMR_HIUERR;
  1307. AR5K_REG_ENABLE_BITS(ah, AR5K_SIMR2, AR5K_SIMR2_MCABT |
  1308. AR5K_SIMR2_SSERR | AR5K_SIMR2_DPERR);
  1309. }
  1310. }
  1311. ath5k_hw_reg_write(ah, int_mask, AR5K_PIMR);
  1312. /* Store new interrupt mask */
  1313. ah->ah_imr = new_mask;
  1314. /* ..re-enable interrupts */
  1315. ath5k_hw_reg_write(ah, AR5K_IER_ENABLE, AR5K_IER);
  1316. return old_mask;
  1317. }
  1318. /*************************\
  1319. EEPROM access functions
  1320. \*************************/
  1321. /*
  1322. * Read from eeprom
  1323. */
  1324. static int ath5k_hw_eeprom_read(struct ath5k_hw *ah, u32 offset, u16 *data)
  1325. {
  1326. u32 status, timeout;
  1327. ATH5K_TRACE(ah->ah_sc);
  1328. /*
  1329. * Initialize EEPROM access
  1330. */
  1331. if (ah->ah_version == AR5K_AR5210) {
  1332. AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
  1333. (void)ath5k_hw_reg_read(ah, AR5K_EEPROM_BASE + (4 * offset));
  1334. } else {
  1335. ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
  1336. AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
  1337. AR5K_EEPROM_CMD_READ);
  1338. }
  1339. for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
  1340. status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
  1341. if (status & AR5K_EEPROM_STAT_RDDONE) {
  1342. if (status & AR5K_EEPROM_STAT_RDERR)
  1343. return -EIO;
  1344. *data = (u16)(ath5k_hw_reg_read(ah, AR5K_EEPROM_DATA) &
  1345. 0xffff);
  1346. return 0;
  1347. }
  1348. udelay(15);
  1349. }
  1350. return -ETIMEDOUT;
  1351. }
  1352. /*
  1353. * Write to eeprom - currently disabled, use at your own risk
  1354. */
  1355. #if 0
  1356. static int ath5k_hw_eeprom_write(struct ath5k_hw *ah, u32 offset, u16 data)
  1357. {
  1358. u32 status, timeout;
  1359. ATH5K_TRACE(ah->ah_sc);
  1360. /*
  1361. * Initialize eeprom access
  1362. */
  1363. if (ah->ah_version == AR5K_AR5210) {
  1364. AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
  1365. } else {
  1366. AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
  1367. AR5K_EEPROM_CMD_RESET);
  1368. }
  1369. /*
  1370. * Write data to data register
  1371. */
  1372. if (ah->ah_version == AR5K_AR5210) {
  1373. ath5k_hw_reg_write(ah, data, AR5K_EEPROM_BASE + (4 * offset));
  1374. } else {
  1375. ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
  1376. ath5k_hw_reg_write(ah, data, AR5K_EEPROM_DATA);
  1377. AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
  1378. AR5K_EEPROM_CMD_WRITE);
  1379. }
  1380. /*
  1381. * Check status
  1382. */
  1383. for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
  1384. status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
  1385. if (status & AR5K_EEPROM_STAT_WRDONE) {
  1386. if (status & AR5K_EEPROM_STAT_WRERR)
  1387. return EIO;
  1388. return 0;
  1389. }
  1390. udelay(15);
  1391. }
  1392. ATH5K_ERR(ah->ah_sc, "EEPROM Write is disabled!");
  1393. return -EIO;
  1394. }
  1395. #endif
  1396. /*
  1397. * Translate binary channel representation in EEPROM to frequency
  1398. */
  1399. static u16 ath5k_eeprom_bin2freq(struct ath5k_hw *ah, u16 bin, unsigned int mode)
  1400. {
  1401. u16 val;
  1402. if (bin == AR5K_EEPROM_CHANNEL_DIS)
  1403. return bin;
  1404. if (mode == AR5K_EEPROM_MODE_11A) {
  1405. if (ah->ah_ee_version > AR5K_EEPROM_VERSION_3_2)
  1406. val = (5 * bin) + 4800;
  1407. else
  1408. val = bin > 62 ? (10 * 62) + (5 * (bin - 62)) + 5100 :
  1409. (bin * 10) + 5100;
  1410. } else {
  1411. if (ah->ah_ee_version > AR5K_EEPROM_VERSION_3_2)
  1412. val = bin + 2300;
  1413. else
  1414. val = bin + 2400;
  1415. }
  1416. return val;
  1417. }
  1418. /*
  1419. * Read antenna infos from eeprom
  1420. */
  1421. static int ath5k_eeprom_read_ants(struct ath5k_hw *ah, u32 *offset,
  1422. unsigned int mode)
  1423. {
  1424. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  1425. u32 o = *offset;
  1426. u16 val;
  1427. int ret, i = 0;
  1428. AR5K_EEPROM_READ(o++, val);
  1429. ee->ee_switch_settling[mode] = (val >> 8) & 0x7f;
  1430. ee->ee_ant_tx_rx[mode] = (val >> 2) & 0x3f;
  1431. ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
  1432. AR5K_EEPROM_READ(o++, val);
  1433. ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
  1434. ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
  1435. ee->ee_ant_control[mode][i++] = val & 0x3f;
  1436. AR5K_EEPROM_READ(o++, val);
  1437. ee->ee_ant_control[mode][i++] = (val >> 10) & 0x3f;
  1438. ee->ee_ant_control[mode][i++] = (val >> 4) & 0x3f;
  1439. ee->ee_ant_control[mode][i] = (val << 2) & 0x3f;
  1440. AR5K_EEPROM_READ(o++, val);
  1441. ee->ee_ant_control[mode][i++] |= (val >> 14) & 0x3;
  1442. ee->ee_ant_control[mode][i++] = (val >> 8) & 0x3f;
  1443. ee->ee_ant_control[mode][i++] = (val >> 2) & 0x3f;
  1444. ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
  1445. AR5K_EEPROM_READ(o++, val);
  1446. ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
  1447. ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
  1448. ee->ee_ant_control[mode][i++] = val & 0x3f;
  1449. /* Get antenna modes */
  1450. ah->ah_antenna[mode][0] =
  1451. (ee->ee_ant_control[mode][0] << 4) | 0x1;
  1452. ah->ah_antenna[mode][AR5K_ANT_FIXED_A] =
  1453. ee->ee_ant_control[mode][1] |
  1454. (ee->ee_ant_control[mode][2] << 6) |
  1455. (ee->ee_ant_control[mode][3] << 12) |
  1456. (ee->ee_ant_control[mode][4] << 18) |
  1457. (ee->ee_ant_control[mode][5] << 24);
  1458. ah->ah_antenna[mode][AR5K_ANT_FIXED_B] =
  1459. ee->ee_ant_control[mode][6] |
  1460. (ee->ee_ant_control[mode][7] << 6) |
  1461. (ee->ee_ant_control[mode][8] << 12) |
  1462. (ee->ee_ant_control[mode][9] << 18) |
  1463. (ee->ee_ant_control[mode][10] << 24);
  1464. /* return new offset */
  1465. *offset = o;
  1466. return 0;
  1467. }
  1468. /*
  1469. * Read supported modes from eeprom
  1470. */
  1471. static int ath5k_eeprom_read_modes(struct ath5k_hw *ah, u32 *offset,
  1472. unsigned int mode)
  1473. {
  1474. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  1475. u32 o = *offset;
  1476. u16 val;
  1477. int ret;
  1478. AR5K_EEPROM_READ(o++, val);
  1479. ee->ee_tx_end2xlna_enable[mode] = (val >> 8) & 0xff;
  1480. ee->ee_thr_62[mode] = val & 0xff;
  1481. if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
  1482. ee->ee_thr_62[mode] = mode == AR5K_EEPROM_MODE_11A ? 15 : 28;
  1483. AR5K_EEPROM_READ(o++, val);
  1484. ee->ee_tx_end2xpa_disable[mode] = (val >> 8) & 0xff;
  1485. ee->ee_tx_frm2xpa_enable[mode] = val & 0xff;
  1486. AR5K_EEPROM_READ(o++, val);
  1487. ee->ee_pga_desired_size[mode] = (val >> 8) & 0xff;
  1488. if ((val & 0xff) & 0x80)
  1489. ee->ee_noise_floor_thr[mode] = -((((val & 0xff) ^ 0xff)) + 1);
  1490. else
  1491. ee->ee_noise_floor_thr[mode] = val & 0xff;
  1492. if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
  1493. ee->ee_noise_floor_thr[mode] =
  1494. mode == AR5K_EEPROM_MODE_11A ? -54 : -1;
  1495. AR5K_EEPROM_READ(o++, val);
  1496. ee->ee_xlna_gain[mode] = (val >> 5) & 0xff;
  1497. ee->ee_x_gain[mode] = (val >> 1) & 0xf;
  1498. ee->ee_xpd[mode] = val & 0x1;
  1499. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0)
  1500. ee->ee_fixed_bias[mode] = (val >> 13) & 0x1;
  1501. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_3) {
  1502. AR5K_EEPROM_READ(o++, val);
  1503. ee->ee_false_detect[mode] = (val >> 6) & 0x7f;
  1504. if (mode == AR5K_EEPROM_MODE_11A)
  1505. ee->ee_xr_power[mode] = val & 0x3f;
  1506. else {
  1507. ee->ee_ob[mode][0] = val & 0x7;
  1508. ee->ee_db[mode][0] = (val >> 3) & 0x7;
  1509. }
  1510. }
  1511. if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_4) {
  1512. ee->ee_i_gain[mode] = AR5K_EEPROM_I_GAIN;
  1513. ee->ee_cck_ofdm_power_delta = AR5K_EEPROM_CCK_OFDM_DELTA;
  1514. } else {
  1515. ee->ee_i_gain[mode] = (val >> 13) & 0x7;
  1516. AR5K_EEPROM_READ(o++, val);
  1517. ee->ee_i_gain[mode] |= (val << 3) & 0x38;
  1518. if (mode == AR5K_EEPROM_MODE_11G)
  1519. ee->ee_cck_ofdm_power_delta = (val >> 3) & 0xff;
  1520. }
  1521. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0 &&
  1522. mode == AR5K_EEPROM_MODE_11A) {
  1523. ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
  1524. ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
  1525. }
  1526. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_6 &&
  1527. mode == AR5K_EEPROM_MODE_11G)
  1528. ee->ee_scaled_cck_delta = (val >> 11) & 0x1f;
  1529. /* return new offset */
  1530. *offset = o;
  1531. return 0;
  1532. }
  1533. /*
  1534. * Initialize eeprom & capabilities structs
  1535. */
  1536. static int ath5k_eeprom_init(struct ath5k_hw *ah)
  1537. {
  1538. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  1539. unsigned int mode, i;
  1540. int ret;
  1541. u32 offset;
  1542. u16 val;
  1543. /* Initial TX thermal adjustment values */
  1544. ee->ee_tx_clip = 4;
  1545. ee->ee_pwd_84 = ee->ee_pwd_90 = 1;
  1546. ee->ee_gain_select = 1;
  1547. /*
  1548. * Read values from EEPROM and store them in the capability structure
  1549. */
  1550. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MAGIC, ee_magic);
  1551. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_PROTECT, ee_protect);
  1552. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_REG_DOMAIN, ee_regdomain);
  1553. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_VERSION, ee_version);
  1554. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_HDR, ee_header);
  1555. /* Return if we have an old EEPROM */
  1556. if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_0)
  1557. return 0;
  1558. #ifdef notyet
  1559. /*
  1560. * Validate the checksum of the EEPROM date. There are some
  1561. * devices with invalid EEPROMs.
  1562. */
  1563. for (cksum = 0, offset = 0; offset < AR5K_EEPROM_INFO_MAX; offset++) {
  1564. AR5K_EEPROM_READ(AR5K_EEPROM_INFO(offset), val);
  1565. cksum ^= val;
  1566. }
  1567. if (cksum != AR5K_EEPROM_INFO_CKSUM) {
  1568. ATH5K_ERR(ah->ah_sc, "Invalid EEPROM checksum 0x%04x\n", cksum);
  1569. return -EIO;
  1570. }
  1571. #endif
  1572. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_ANT_GAIN(ah->ah_ee_version),
  1573. ee_ant_gain);
  1574. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
  1575. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC0, ee_misc0);
  1576. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC1, ee_misc1);
  1577. }
  1578. if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_3) {
  1579. AR5K_EEPROM_READ(AR5K_EEPROM_OBDB0_2GHZ, val);
  1580. ee->ee_ob[AR5K_EEPROM_MODE_11B][0] = val & 0x7;
  1581. ee->ee_db[AR5K_EEPROM_MODE_11B][0] = (val >> 3) & 0x7;
  1582. AR5K_EEPROM_READ(AR5K_EEPROM_OBDB1_2GHZ, val);
  1583. ee->ee_ob[AR5K_EEPROM_MODE_11G][0] = val & 0x7;
  1584. ee->ee_db[AR5K_EEPROM_MODE_11G][0] = (val >> 3) & 0x7;
  1585. }
  1586. /*
  1587. * Get conformance test limit values
  1588. */
  1589. offset = AR5K_EEPROM_CTL(ah->ah_ee_version);
  1590. ee->ee_ctls = AR5K_EEPROM_N_CTLS(ah->ah_ee_version);
  1591. for (i = 0; i < ee->ee_ctls; i++) {
  1592. AR5K_EEPROM_READ(offset++, val);
  1593. ee->ee_ctl[i] = (val >> 8) & 0xff;
  1594. ee->ee_ctl[i + 1] = val & 0xff;
  1595. }
  1596. /*
  1597. * Get values for 802.11a (5GHz)
  1598. */
  1599. mode = AR5K_EEPROM_MODE_11A;
  1600. ee->ee_turbo_max_power[mode] =
  1601. AR5K_EEPROM_HDR_T_5GHZ_DBM(ee->ee_header);
  1602. offset = AR5K_EEPROM_MODES_11A(ah->ah_ee_version);
  1603. ret = ath5k_eeprom_read_ants(ah, &offset, mode);
  1604. if (ret)
  1605. return ret;
  1606. AR5K_EEPROM_READ(offset++, val);
  1607. ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
  1608. ee->ee_ob[mode][3] = (val >> 5) & 0x7;
  1609. ee->ee_db[mode][3] = (val >> 2) & 0x7;
  1610. ee->ee_ob[mode][2] = (val << 1) & 0x7;
  1611. AR5K_EEPROM_READ(offset++, val);
  1612. ee->ee_ob[mode][2] |= (val >> 15) & 0x1;
  1613. ee->ee_db[mode][2] = (val >> 12) & 0x7;
  1614. ee->ee_ob[mode][1] = (val >> 9) & 0x7;
  1615. ee->ee_db[mode][1] = (val >> 6) & 0x7;
  1616. ee->ee_ob[mode][0] = (val >> 3) & 0x7;
  1617. ee->ee_db[mode][0] = val & 0x7;
  1618. ret = ath5k_eeprom_read_modes(ah, &offset, mode);
  1619. if (ret)
  1620. return ret;
  1621. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1) {
  1622. AR5K_EEPROM_READ(offset++, val);
  1623. ee->ee_margin_tx_rx[mode] = val & 0x3f;
  1624. }
  1625. /*
  1626. * Get values for 802.11b (2.4GHz)
  1627. */
  1628. mode = AR5K_EEPROM_MODE_11B;
  1629. offset = AR5K_EEPROM_MODES_11B(ah->ah_ee_version);
  1630. ret = ath5k_eeprom_read_ants(ah, &offset, mode);
  1631. if (ret)
  1632. return ret;
  1633. AR5K_EEPROM_READ(offset++, val);
  1634. ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
  1635. ee->ee_ob[mode][1] = (val >> 4) & 0x7;
  1636. ee->ee_db[mode][1] = val & 0x7;
  1637. ret = ath5k_eeprom_read_modes(ah, &offset, mode);
  1638. if (ret)
  1639. return ret;
  1640. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
  1641. AR5K_EEPROM_READ(offset++, val);
  1642. ee->ee_cal_pier[mode][0] =
  1643. ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
  1644. ee->ee_cal_pier[mode][1] =
  1645. ath5k_eeprom_bin2freq(ah, (val >> 8) & 0xff, mode);
  1646. AR5K_EEPROM_READ(offset++, val);
  1647. ee->ee_cal_pier[mode][2] =
  1648. ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
  1649. }
  1650. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
  1651. ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
  1652. /*
  1653. * Get values for 802.11g (2.4GHz)
  1654. */
  1655. mode = AR5K_EEPROM_MODE_11G;
  1656. offset = AR5K_EEPROM_MODES_11G(ah->ah_ee_version);
  1657. ret = ath5k_eeprom_read_ants(ah, &offset, mode);
  1658. if (ret)
  1659. return ret;
  1660. AR5K_EEPROM_READ(offset++, val);
  1661. ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
  1662. ee->ee_ob[mode][1] = (val >> 4) & 0x7;
  1663. ee->ee_db[mode][1] = val & 0x7;
  1664. ret = ath5k_eeprom_read_modes(ah, &offset, mode);
  1665. if (ret)
  1666. return ret;
  1667. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
  1668. AR5K_EEPROM_READ(offset++, val);
  1669. ee->ee_cal_pier[mode][0] =
  1670. ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
  1671. ee->ee_cal_pier[mode][1] =
  1672. ath5k_eeprom_bin2freq(ah, (val >> 8) & 0xff, mode);
  1673. AR5K_EEPROM_READ(offset++, val);
  1674. ee->ee_turbo_max_power[mode] = val & 0x7f;
  1675. ee->ee_xr_power[mode] = (val >> 7) & 0x3f;
  1676. AR5K_EEPROM_READ(offset++, val);
  1677. ee->ee_cal_pier[mode][2] =
  1678. ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
  1679. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
  1680. ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
  1681. AR5K_EEPROM_READ(offset++, val);
  1682. ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
  1683. ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
  1684. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_2) {
  1685. AR5K_EEPROM_READ(offset++, val);
  1686. ee->ee_cck_ofdm_gain_delta = val & 0xff;
  1687. }
  1688. }
  1689. /*
  1690. * Read 5GHz EEPROM channels
  1691. */
  1692. return 0;
  1693. }
  1694. /*
  1695. * Read the MAC address from eeprom
  1696. */
  1697. static int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
  1698. {
  1699. u8 mac_d[ETH_ALEN];
  1700. u32 total, offset;
  1701. u16 data;
  1702. int octet, ret;
  1703. memset(mac, 0, ETH_ALEN);
  1704. memset(mac_d, 0, ETH_ALEN);
  1705. ret = ath5k_hw_eeprom_read(ah, 0x20, &data);
  1706. if (ret)
  1707. return ret;
  1708. for (offset = 0x1f, octet = 0, total = 0; offset >= 0x1d; offset--) {
  1709. ret = ath5k_hw_eeprom_read(ah, offset, &data);
  1710. if (ret)
  1711. return ret;
  1712. total += data;
  1713. mac_d[octet + 1] = data & 0xff;
  1714. mac_d[octet] = data >> 8;
  1715. octet += 2;
  1716. }
  1717. memcpy(mac, mac_d, ETH_ALEN);
  1718. if (!total || total == 3 * 0xffff)
  1719. return -EINVAL;
  1720. return 0;
  1721. }
  1722. /*
  1723. * Fill the capabilities struct
  1724. */
  1725. static int ath5k_hw_get_capabilities(struct ath5k_hw *ah)
  1726. {
  1727. u16 ee_header;
  1728. ATH5K_TRACE(ah->ah_sc);
  1729. /* Capabilities stored in the EEPROM */
  1730. ee_header = ah->ah_capabilities.cap_eeprom.ee_header;
  1731. if (ah->ah_version == AR5K_AR5210) {
  1732. /*
  1733. * Set radio capabilities
  1734. * (The AR5110 only supports the middle 5GHz band)
  1735. */
  1736. ah->ah_capabilities.cap_range.range_5ghz_min = 5120;
  1737. ah->ah_capabilities.cap_range.range_5ghz_max = 5430;
  1738. ah->ah_capabilities.cap_range.range_2ghz_min = 0;
  1739. ah->ah_capabilities.cap_range.range_2ghz_max = 0;
  1740. /* Set supported modes */
  1741. __set_bit(AR5K_MODE_11A, ah->ah_capabilities.cap_mode);
  1742. __set_bit(AR5K_MODE_11A_TURBO, ah->ah_capabilities.cap_mode);
  1743. } else {
  1744. /*
  1745. * XXX The tranceiver supports frequencies from 4920 to 6100GHz
  1746. * XXX and from 2312 to 2732GHz. There are problems with the
  1747. * XXX current ieee80211 implementation because the IEEE
  1748. * XXX channel mapping does not support negative channel
  1749. * XXX numbers (2312MHz is channel -19). Of course, this
  1750. * XXX doesn't matter because these channels are out of range
  1751. * XXX but some regulation domains like MKK (Japan) will
  1752. * XXX support frequencies somewhere around 4.8GHz.
  1753. */
  1754. /*
  1755. * Set radio capabilities
  1756. */
  1757. if (AR5K_EEPROM_HDR_11A(ee_header)) {
  1758. ah->ah_capabilities.cap_range.range_5ghz_min = 5005; /* 4920 */
  1759. ah->ah_capabilities.cap_range.range_5ghz_max = 6100;
  1760. /* Set supported modes */
  1761. __set_bit(AR5K_MODE_11A,
  1762. ah->ah_capabilities.cap_mode);
  1763. __set_bit(AR5K_MODE_11A_TURBO,
  1764. ah->ah_capabilities.cap_mode);
  1765. if (ah->ah_version == AR5K_AR5212)
  1766. __set_bit(AR5K_MODE_11G_TURBO,
  1767. ah->ah_capabilities.cap_mode);
  1768. }
  1769. /* Enable 802.11b if a 2GHz capable radio (2111/5112) is
  1770. * connected */
  1771. if (AR5K_EEPROM_HDR_11B(ee_header) ||
  1772. AR5K_EEPROM_HDR_11G(ee_header)) {
  1773. ah->ah_capabilities.cap_range.range_2ghz_min = 2412; /* 2312 */
  1774. ah->ah_capabilities.cap_range.range_2ghz_max = 2732;
  1775. if (AR5K_EEPROM_HDR_11B(ee_header))
  1776. __set_bit(AR5K_MODE_11B,
  1777. ah->ah_capabilities.cap_mode);
  1778. if (AR5K_EEPROM_HDR_11G(ee_header))
  1779. __set_bit(AR5K_MODE_11G,
  1780. ah->ah_capabilities.cap_mode);
  1781. }
  1782. }
  1783. /* GPIO */
  1784. ah->ah_gpio_npins = AR5K_NUM_GPIO;
  1785. /* Set number of supported TX queues */
  1786. if (ah->ah_version == AR5K_AR5210)
  1787. ah->ah_capabilities.cap_queues.q_tx_num =
  1788. AR5K_NUM_TX_QUEUES_NOQCU;
  1789. else
  1790. ah->ah_capabilities.cap_queues.q_tx_num = AR5K_NUM_TX_QUEUES;
  1791. return 0;
  1792. }
  1793. /*********************************\
  1794. Protocol Control Unit Functions
  1795. \*********************************/
  1796. /*
  1797. * Set Operation mode
  1798. */
  1799. int ath5k_hw_set_opmode(struct ath5k_hw *ah)
  1800. {
  1801. u32 pcu_reg, beacon_reg, low_id, high_id;
  1802. pcu_reg = 0;
  1803. beacon_reg = 0;
  1804. ATH5K_TRACE(ah->ah_sc);
  1805. switch (ah->ah_op_mode) {
  1806. case IEEE80211_IF_TYPE_IBSS:
  1807. pcu_reg |= AR5K_STA_ID1_ADHOC | AR5K_STA_ID1_DESC_ANTENNA |
  1808. (ah->ah_version == AR5K_AR5210 ?
  1809. AR5K_STA_ID1_NO_PSPOLL : 0);
  1810. beacon_reg |= AR5K_BCR_ADHOC;
  1811. break;
  1812. case IEEE80211_IF_TYPE_AP:
  1813. pcu_reg |= AR5K_STA_ID1_AP | AR5K_STA_ID1_RTS_DEF_ANTENNA |
  1814. (ah->ah_version == AR5K_AR5210 ?
  1815. AR5K_STA_ID1_NO_PSPOLL : 0);
  1816. beacon_reg |= AR5K_BCR_AP;
  1817. break;
  1818. case IEEE80211_IF_TYPE_STA:
  1819. pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
  1820. (ah->ah_version == AR5K_AR5210 ?
  1821. AR5K_STA_ID1_PWR_SV : 0);
  1822. case IEEE80211_IF_TYPE_MNTR:
  1823. pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
  1824. (ah->ah_version == AR5K_AR5210 ?
  1825. AR5K_STA_ID1_NO_PSPOLL : 0);
  1826. break;
  1827. default:
  1828. return -EINVAL;
  1829. }
  1830. /*
  1831. * Set PCU registers
  1832. */
  1833. low_id = AR5K_LOW_ID(ah->ah_sta_id);
  1834. high_id = AR5K_HIGH_ID(ah->ah_sta_id);
  1835. ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
  1836. ath5k_hw_reg_write(ah, pcu_reg | high_id, AR5K_STA_ID1);
  1837. /*
  1838. * Set Beacon Control Register on 5210
  1839. */
  1840. if (ah->ah_version == AR5K_AR5210)
  1841. ath5k_hw_reg_write(ah, beacon_reg, AR5K_BCR);
  1842. return 0;
  1843. }
  1844. /*
  1845. * BSSID Functions
  1846. */
  1847. /*
  1848. * Get station id
  1849. */
  1850. void ath5k_hw_get_lladdr(struct ath5k_hw *ah, u8 *mac)
  1851. {
  1852. ATH5K_TRACE(ah->ah_sc);
  1853. memcpy(mac, ah->ah_sta_id, ETH_ALEN);
  1854. }
  1855. /*
  1856. * Set station id
  1857. */
  1858. int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac)
  1859. {
  1860. u32 low_id, high_id;
  1861. ATH5K_TRACE(ah->ah_sc);
  1862. /* Set new station ID */
  1863. memcpy(ah->ah_sta_id, mac, ETH_ALEN);
  1864. low_id = AR5K_LOW_ID(mac);
  1865. high_id = AR5K_HIGH_ID(mac);
  1866. ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
  1867. ath5k_hw_reg_write(ah, high_id, AR5K_STA_ID1);
  1868. return 0;
  1869. }
  1870. /*
  1871. * Set BSSID
  1872. */
  1873. void ath5k_hw_set_associd(struct ath5k_hw *ah, const u8 *bssid, u16 assoc_id)
  1874. {
  1875. u32 low_id, high_id;
  1876. u16 tim_offset = 0;
  1877. /*
  1878. * Set simple BSSID mask on 5212
  1879. */
  1880. if (ah->ah_version == AR5K_AR5212) {
  1881. ath5k_hw_reg_write(ah, 0xfffffff, AR5K_BSS_IDM0);
  1882. ath5k_hw_reg_write(ah, 0xfffffff, AR5K_BSS_IDM1);
  1883. }
  1884. /*
  1885. * Set BSSID which triggers the "SME Join" operation
  1886. */
  1887. low_id = AR5K_LOW_ID(bssid);
  1888. high_id = AR5K_HIGH_ID(bssid);
  1889. ath5k_hw_reg_write(ah, low_id, AR5K_BSS_ID0);
  1890. ath5k_hw_reg_write(ah, high_id | ((assoc_id & 0x3fff) <<
  1891. AR5K_BSS_ID1_AID_S), AR5K_BSS_ID1);
  1892. if (assoc_id == 0) {
  1893. ath5k_hw_disable_pspoll(ah);
  1894. return;
  1895. }
  1896. AR5K_REG_WRITE_BITS(ah, AR5K_BEACON, AR5K_BEACON_TIM,
  1897. tim_offset ? tim_offset + 4 : 0);
  1898. ath5k_hw_enable_pspoll(ah, NULL, 0);
  1899. }
  1900. /**
  1901. * ath5k_hw_set_bssid_mask - set common bits we should listen to
  1902. *
  1903. * The bssid_mask is a utility used by AR5212 hardware to inform the hardware
  1904. * which bits of the interface's MAC address should be looked at when trying
  1905. * to decide which packets to ACK. In station mode every bit matters. In AP
  1906. * mode with a single BSS every bit matters as well. In AP mode with
  1907. * multiple BSSes not every bit matters.
  1908. *
  1909. * @ah: the &struct ath5k_hw
  1910. * @mask: the bssid_mask, a u8 array of size ETH_ALEN
  1911. *
  1912. * Note that this is a simple filter and *does* not filter out all
  1913. * relevant frames. Some non-relevant frames will get through, probability
  1914. * jocks are welcomed to compute.
  1915. *
  1916. * When handling multiple BSSes (or VAPs) you can get the BSSID mask by
  1917. * computing the set of:
  1918. *
  1919. * ~ ( MAC XOR BSSID )
  1920. *
  1921. * When you do this you are essentially computing the common bits. Later it
  1922. * is assumed the harware will "and" (&) the BSSID mask with the MAC address
  1923. * to obtain the relevant bits which should match on the destination frame.
  1924. *
  1925. * Simple example: on your card you have have two BSSes you have created with
  1926. * BSSID-01 and BSSID-02. Lets assume BSSID-01 will not use the MAC address.
  1927. * There is another BSSID-03 but you are not part of it. For simplicity's sake,
  1928. * assuming only 4 bits for a mac address and for BSSIDs you can then have:
  1929. *
  1930. * \
  1931. * MAC: 0001 |
  1932. * BSSID-01: 0100 | --> Belongs to us
  1933. * BSSID-02: 1001 |
  1934. * /
  1935. * -------------------
  1936. * BSSID-03: 0110 | --> External
  1937. * -------------------
  1938. *
  1939. * Our bssid_mask would then be:
  1940. *
  1941. * On loop iteration for BSSID-01:
  1942. * ~(0001 ^ 0100) -> ~(0101)
  1943. * -> 1010
  1944. * bssid_mask = 1010
  1945. *
  1946. * On loop iteration for BSSID-02:
  1947. * bssid_mask &= ~(0001 ^ 1001)
  1948. * bssid_mask = (1010) & ~(0001 ^ 1001)
  1949. * bssid_mask = (1010) & ~(1001)
  1950. * bssid_mask = (1010) & (0110)
  1951. * bssid_mask = 0010
  1952. *
  1953. * A bssid_mask of 0010 means "only pay attention to the second least
  1954. * significant bit". This is because its the only bit common
  1955. * amongst the MAC and all BSSIDs we support. To findout what the real
  1956. * common bit is we can simply "&" the bssid_mask now with any BSSID we have
  1957. * or our MAC address (we assume the hardware uses the MAC address).
  1958. *
  1959. * Now, suppose there's an incoming frame for BSSID-03:
  1960. *
  1961. * IFRAME-01: 0110
  1962. *
  1963. * An easy eye-inspeciton of this already should tell you that this frame
  1964. * will not pass our check. This is beacuse the bssid_mask tells the
  1965. * hardware to only look at the second least significant bit and the
  1966. * common bit amongst the MAC and BSSIDs is 0, this frame has the 2nd LSB
  1967. * as 1, which does not match 0.
  1968. *
  1969. * So with IFRAME-01 we *assume* the hardware will do:
  1970. *
  1971. * allow = (IFRAME-01 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
  1972. * --> allow = (0110 & 0010) == (0010 & 0001) ? 1 : 0;
  1973. * --> allow = (0010) == 0000 ? 1 : 0;
  1974. * --> allow = 0
  1975. *
  1976. * Lets now test a frame that should work:
  1977. *
  1978. * IFRAME-02: 0001 (we should allow)
  1979. *
  1980. * allow = (0001 & 1010) == 1010
  1981. *
  1982. * allow = (IFRAME-02 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
  1983. * --> allow = (0001 & 0010) == (0010 & 0001) ? 1 :0;
  1984. * --> allow = (0010) == (0010)
  1985. * --> allow = 1
  1986. *
  1987. * Other examples:
  1988. *
  1989. * IFRAME-03: 0100 --> allowed
  1990. * IFRAME-04: 1001 --> allowed
  1991. * IFRAME-05: 1101 --> allowed but its not for us!!!
  1992. *
  1993. */
  1994. int ath5k_hw_set_bssid_mask(struct ath5k_hw *ah, const u8 *mask)
  1995. {
  1996. u32 low_id, high_id;
  1997. ATH5K_TRACE(ah->ah_sc);
  1998. if (ah->ah_version == AR5K_AR5212) {
  1999. low_id = AR5K_LOW_ID(mask);
  2000. high_id = AR5K_HIGH_ID(mask);
  2001. ath5k_hw_reg_write(ah, low_id, AR5K_BSS_IDM0);
  2002. ath5k_hw_reg_write(ah, high_id, AR5K_BSS_IDM1);
  2003. return 0;
  2004. }
  2005. return -EIO;
  2006. }
  2007. /*
  2008. * Receive start/stop functions
  2009. */
  2010. /*
  2011. * Start receive on PCU
  2012. */
  2013. void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah)
  2014. {
  2015. ATH5K_TRACE(ah->ah_sc);
  2016. AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
  2017. }
  2018. /*
  2019. * Stop receive on PCU
  2020. */
  2021. void ath5k_hw_stop_pcu_recv(struct ath5k_hw *ah)
  2022. {
  2023. ATH5K_TRACE(ah->ah_sc);
  2024. AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
  2025. }
  2026. /*
  2027. * RX Filter functions
  2028. */
  2029. /*
  2030. * Set multicast filter
  2031. */
  2032. void ath5k_hw_set_mcast_filter(struct ath5k_hw *ah, u32 filter0, u32 filter1)
  2033. {
  2034. ATH5K_TRACE(ah->ah_sc);
  2035. /* Set the multicat filter */
  2036. ath5k_hw_reg_write(ah, filter0, AR5K_MCAST_FILTER0);
  2037. ath5k_hw_reg_write(ah, filter1, AR5K_MCAST_FILTER1);
  2038. }
  2039. /*
  2040. * Set multicast filter by index
  2041. */
  2042. int ath5k_hw_set_mcast_filterindex(struct ath5k_hw *ah, u32 index)
  2043. {
  2044. ATH5K_TRACE(ah->ah_sc);
  2045. if (index >= 64)
  2046. return -EINVAL;
  2047. else if (index >= 32)
  2048. AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER1,
  2049. (1 << (index - 32)));
  2050. else
  2051. AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
  2052. return 0;
  2053. }
  2054. /*
  2055. * Clear Multicast filter by index
  2056. */
  2057. int ath5k_hw_clear_mcast_filter_idx(struct ath5k_hw *ah, u32 index)
  2058. {
  2059. ATH5K_TRACE(ah->ah_sc);
  2060. if (index >= 64)
  2061. return -EINVAL;
  2062. else if (index >= 32)
  2063. AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER1,
  2064. (1 << (index - 32)));
  2065. else
  2066. AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
  2067. return 0;
  2068. }
  2069. /*
  2070. * Get current rx filter
  2071. */
  2072. u32 ath5k_hw_get_rx_filter(struct ath5k_hw *ah)
  2073. {
  2074. u32 data, filter = 0;
  2075. ATH5K_TRACE(ah->ah_sc);
  2076. filter = ath5k_hw_reg_read(ah, AR5K_RX_FILTER);
  2077. /*Radar detection for 5212*/
  2078. if (ah->ah_version == AR5K_AR5212) {
  2079. data = ath5k_hw_reg_read(ah, AR5K_PHY_ERR_FIL);
  2080. if (data & AR5K_PHY_ERR_FIL_RADAR)
  2081. filter |= AR5K_RX_FILTER_RADARERR;
  2082. if (data & (AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK))
  2083. filter |= AR5K_RX_FILTER_PHYERR;
  2084. }
  2085. return filter;
  2086. }
  2087. /*
  2088. * Set rx filter
  2089. */
  2090. void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter)
  2091. {
  2092. u32 data = 0;
  2093. ATH5K_TRACE(ah->ah_sc);
  2094. /* Set PHY error filter register on 5212*/
  2095. if (ah->ah_version == AR5K_AR5212) {
  2096. if (filter & AR5K_RX_FILTER_RADARERR)
  2097. data |= AR5K_PHY_ERR_FIL_RADAR;
  2098. if (filter & AR5K_RX_FILTER_PHYERR)
  2099. data |= AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK;
  2100. }
  2101. /*
  2102. * The AR5210 uses promiscous mode to detect radar activity
  2103. */
  2104. if (ah->ah_version == AR5K_AR5210 &&
  2105. (filter & AR5K_RX_FILTER_RADARERR)) {
  2106. filter &= ~AR5K_RX_FILTER_RADARERR;
  2107. filter |= AR5K_RX_FILTER_PROM;
  2108. }
  2109. /*Zero length DMA*/
  2110. if (data)
  2111. AR5K_REG_ENABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
  2112. else
  2113. AR5K_REG_DISABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
  2114. /*Write RX Filter register*/
  2115. ath5k_hw_reg_write(ah, filter & 0xff, AR5K_RX_FILTER);
  2116. /*Write PHY error filter register on 5212*/
  2117. if (ah->ah_version == AR5K_AR5212)
  2118. ath5k_hw_reg_write(ah, data, AR5K_PHY_ERR_FIL);
  2119. }
  2120. /*
  2121. * Beacon related functions
  2122. */
  2123. /*
  2124. * Get a 32bit TSF
  2125. */
  2126. u32 ath5k_hw_get_tsf32(struct ath5k_hw *ah)
  2127. {
  2128. ATH5K_TRACE(ah->ah_sc);
  2129. return ath5k_hw_reg_read(ah, AR5K_TSF_L32);
  2130. }
  2131. /*
  2132. * Get the full 64bit TSF
  2133. */
  2134. u64 ath5k_hw_get_tsf64(struct ath5k_hw *ah)
  2135. {
  2136. u64 tsf = ath5k_hw_reg_read(ah, AR5K_TSF_U32);
  2137. ATH5K_TRACE(ah->ah_sc);
  2138. return ath5k_hw_reg_read(ah, AR5K_TSF_L32) | (tsf << 32);
  2139. }
  2140. /*
  2141. * Force a TSF reset
  2142. */
  2143. void ath5k_hw_reset_tsf(struct ath5k_hw *ah)
  2144. {
  2145. ATH5K_TRACE(ah->ah_sc);
  2146. AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_RESET_TSF);
  2147. }
  2148. /*
  2149. * Initialize beacon timers
  2150. */
  2151. void ath5k_hw_init_beacon(struct ath5k_hw *ah, u32 next_beacon, u32 interval)
  2152. {
  2153. u32 timer1, timer2, timer3;
  2154. ATH5K_TRACE(ah->ah_sc);
  2155. /*
  2156. * Set the additional timers by mode
  2157. */
  2158. switch (ah->ah_op_mode) {
  2159. case IEEE80211_IF_TYPE_STA:
  2160. if (ah->ah_version == AR5K_AR5210) {
  2161. timer1 = 0xffffffff;
  2162. timer2 = 0xffffffff;
  2163. } else {
  2164. timer1 = 0x0000ffff;
  2165. timer2 = 0x0007ffff;
  2166. }
  2167. break;
  2168. default:
  2169. timer1 = (next_beacon - AR5K_TUNE_DMA_BEACON_RESP) << 3;
  2170. timer2 = (next_beacon - AR5K_TUNE_SW_BEACON_RESP) << 3;
  2171. }
  2172. timer3 = next_beacon + (ah->ah_atim_window ? ah->ah_atim_window : 1);
  2173. /*
  2174. * Set the beacon register and enable all timers.
  2175. * (next beacon, DMA beacon, software beacon, ATIM window time)
  2176. */
  2177. ath5k_hw_reg_write(ah, next_beacon, AR5K_TIMER0);
  2178. ath5k_hw_reg_write(ah, timer1, AR5K_TIMER1);
  2179. ath5k_hw_reg_write(ah, timer2, AR5K_TIMER2);
  2180. ath5k_hw_reg_write(ah, timer3, AR5K_TIMER3);
  2181. ath5k_hw_reg_write(ah, interval & (AR5K_BEACON_PERIOD |
  2182. AR5K_BEACON_RESET_TSF | AR5K_BEACON_ENABLE),
  2183. AR5K_BEACON);
  2184. }
  2185. #if 0
  2186. /*
  2187. * Set beacon timers
  2188. */
  2189. int ath5k_hw_set_beacon_timers(struct ath5k_hw *ah,
  2190. const struct ath5k_beacon_state *state)
  2191. {
  2192. u32 cfp_period, next_cfp, dtim, interval, next_beacon;
  2193. /*
  2194. * TODO: should be changed through *state
  2195. * review struct ath5k_beacon_state struct
  2196. *
  2197. * XXX: These are used for cfp period bellow, are they
  2198. * ok ? Is it O.K. for tsf here to be 0 or should we use
  2199. * get_tsf ?
  2200. */
  2201. u32 dtim_count = 0; /* XXX */
  2202. u32 cfp_count = 0; /* XXX */
  2203. u32 tsf = 0; /* XXX */
  2204. ATH5K_TRACE(ah->ah_sc);
  2205. /* Return on an invalid beacon state */
  2206. if (state->bs_interval < 1)
  2207. return -EINVAL;
  2208. interval = state->bs_interval;
  2209. dtim = state->bs_dtim_period;
  2210. /*
  2211. * PCF support?
  2212. */
  2213. if (state->bs_cfp_period > 0) {
  2214. /*
  2215. * Enable PCF mode and set the CFP
  2216. * (Contention Free Period) and timer registers
  2217. */
  2218. cfp_period = state->bs_cfp_period * state->bs_dtim_period *
  2219. state->bs_interval;
  2220. next_cfp = (cfp_count * state->bs_dtim_period + dtim_count) *
  2221. state->bs_interval;
  2222. AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
  2223. AR5K_STA_ID1_DEFAULT_ANTENNA |
  2224. AR5K_STA_ID1_PCF);
  2225. ath5k_hw_reg_write(ah, cfp_period, AR5K_CFP_PERIOD);
  2226. ath5k_hw_reg_write(ah, state->bs_cfp_max_duration,
  2227. AR5K_CFP_DUR);
  2228. ath5k_hw_reg_write(ah, (tsf + (next_cfp == 0 ? cfp_period :
  2229. next_cfp)) << 3, AR5K_TIMER2);
  2230. } else {
  2231. /* Disable PCF mode */
  2232. AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
  2233. AR5K_STA_ID1_DEFAULT_ANTENNA |
  2234. AR5K_STA_ID1_PCF);
  2235. }
  2236. /*
  2237. * Enable the beacon timer register
  2238. */
  2239. ath5k_hw_reg_write(ah, state->bs_next_beacon, AR5K_TIMER0);
  2240. /*
  2241. * Start the beacon timers
  2242. */
  2243. ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_BEACON) &~
  2244. (AR5K_BEACON_PERIOD | AR5K_BEACON_TIM)) |
  2245. AR5K_REG_SM(state->bs_tim_offset ? state->bs_tim_offset + 4 : 0,
  2246. AR5K_BEACON_TIM) | AR5K_REG_SM(state->bs_interval,
  2247. AR5K_BEACON_PERIOD), AR5K_BEACON);
  2248. /*
  2249. * Write new beacon miss threshold, if it appears to be valid
  2250. * XXX: Figure out right values for min <= bs_bmiss_threshold <= max
  2251. * and return if its not in range. We can test this by reading value and
  2252. * setting value to a largest value and seeing which values register.
  2253. */
  2254. AR5K_REG_WRITE_BITS(ah, AR5K_RSSI_THR, AR5K_RSSI_THR_BMISS,
  2255. state->bs_bmiss_threshold);
  2256. /*
  2257. * Set sleep control register
  2258. * XXX: Didn't find this in 5210 code but since this register
  2259. * exists also in ar5k's 5210 headers i leave it as common code.
  2260. */
  2261. AR5K_REG_WRITE_BITS(ah, AR5K_SLEEP_CTL, AR5K_SLEEP_CTL_SLDUR,
  2262. (state->bs_sleep_duration - 3) << 3);
  2263. /*
  2264. * Set enhanced sleep registers on 5212
  2265. */
  2266. if (ah->ah_version == AR5K_AR5212) {
  2267. if (state->bs_sleep_duration > state->bs_interval &&
  2268. roundup(state->bs_sleep_duration, interval) ==
  2269. state->bs_sleep_duration)
  2270. interval = state->bs_sleep_duration;
  2271. if (state->bs_sleep_duration > dtim && (dtim == 0 ||
  2272. roundup(state->bs_sleep_duration, dtim) ==
  2273. state->bs_sleep_duration))
  2274. dtim = state->bs_sleep_duration;
  2275. if (interval > dtim)
  2276. return -EINVAL;
  2277. next_beacon = interval == dtim ? state->bs_next_dtim :
  2278. state->bs_next_beacon;
  2279. ath5k_hw_reg_write(ah,
  2280. AR5K_REG_SM((state->bs_next_dtim - 3) << 3,
  2281. AR5K_SLEEP0_NEXT_DTIM) |
  2282. AR5K_REG_SM(10, AR5K_SLEEP0_CABTO) |
  2283. AR5K_SLEEP0_ENH_SLEEP_EN |
  2284. AR5K_SLEEP0_ASSUME_DTIM, AR5K_SLEEP0);
  2285. ath5k_hw_reg_write(ah, AR5K_REG_SM((next_beacon - 3) << 3,
  2286. AR5K_SLEEP1_NEXT_TIM) |
  2287. AR5K_REG_SM(10, AR5K_SLEEP1_BEACON_TO), AR5K_SLEEP1);
  2288. ath5k_hw_reg_write(ah,
  2289. AR5K_REG_SM(interval, AR5K_SLEEP2_TIM_PER) |
  2290. AR5K_REG_SM(dtim, AR5K_SLEEP2_DTIM_PER), AR5K_SLEEP2);
  2291. }
  2292. return 0;
  2293. }
  2294. /*
  2295. * Reset beacon timers
  2296. */
  2297. void ath5k_hw_reset_beacon(struct ath5k_hw *ah)
  2298. {
  2299. ATH5K_TRACE(ah->ah_sc);
  2300. /*
  2301. * Disable beacon timer
  2302. */
  2303. ath5k_hw_reg_write(ah, 0, AR5K_TIMER0);
  2304. /*
  2305. * Disable some beacon register values
  2306. */
  2307. AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
  2308. AR5K_STA_ID1_DEFAULT_ANTENNA | AR5K_STA_ID1_PCF);
  2309. ath5k_hw_reg_write(ah, AR5K_BEACON_PERIOD, AR5K_BEACON);
  2310. }
  2311. /*
  2312. * Wait for beacon queue to finish
  2313. */
  2314. int ath5k_hw_beaconq_finish(struct ath5k_hw *ah, unsigned long phys_addr)
  2315. {
  2316. unsigned int i;
  2317. int ret;
  2318. ATH5K_TRACE(ah->ah_sc);
  2319. /* 5210 doesn't have QCU*/
  2320. if (ah->ah_version == AR5K_AR5210) {
  2321. /*
  2322. * Wait for beaconn queue to finish by checking
  2323. * Control Register and Beacon Status Register.
  2324. */
  2325. for (i = AR5K_TUNE_BEACON_INTERVAL / 2; i > 0; i--) {
  2326. if (!(ath5k_hw_reg_read(ah, AR5K_BSR) & AR5K_BSR_TXQ1F)
  2327. ||
  2328. !(ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_BSR_TXQ1F))
  2329. break;
  2330. udelay(10);
  2331. }
  2332. /* Timeout... */
  2333. if (i <= 0) {
  2334. /*
  2335. * Re-schedule the beacon queue
  2336. */
  2337. ath5k_hw_reg_write(ah, phys_addr, AR5K_NOQCU_TXDP1);
  2338. ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
  2339. AR5K_BCR);
  2340. return -EIO;
  2341. }
  2342. ret = 0;
  2343. } else {
  2344. /*5211/5212*/
  2345. ret = ath5k_hw_register_timeout(ah,
  2346. AR5K_QUEUE_STATUS(AR5K_TX_QUEUE_ID_BEACON),
  2347. AR5K_QCU_STS_FRMPENDCNT, 0, false);
  2348. if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, AR5K_TX_QUEUE_ID_BEACON))
  2349. return -EIO;
  2350. }
  2351. return ret;
  2352. }
  2353. #endif
  2354. /*
  2355. * Update mib counters (statistics)
  2356. */
  2357. void ath5k_hw_update_mib_counters(struct ath5k_hw *ah,
  2358. struct ath5k_mib_stats *statistics)
  2359. {
  2360. ATH5K_TRACE(ah->ah_sc);
  2361. /* Read-And-Clear */
  2362. statistics->ackrcv_bad += ath5k_hw_reg_read(ah, AR5K_ACK_FAIL);
  2363. statistics->rts_bad += ath5k_hw_reg_read(ah, AR5K_RTS_FAIL);
  2364. statistics->rts_good += ath5k_hw_reg_read(ah, AR5K_RTS_OK);
  2365. statistics->fcs_bad += ath5k_hw_reg_read(ah, AR5K_FCS_FAIL);
  2366. statistics->beacons += ath5k_hw_reg_read(ah, AR5K_BEACON_CNT);
  2367. /* Reset profile count registers on 5212*/
  2368. if (ah->ah_version == AR5K_AR5212) {
  2369. ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_TX);
  2370. ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RX);
  2371. ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RXCLR);
  2372. ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_CYCLE);
  2373. }
  2374. }
  2375. /** ath5k_hw_set_ack_bitrate - set bitrate for ACKs
  2376. *
  2377. * @ah: the &struct ath5k_hw
  2378. * @high: determines if to use low bit rate or now
  2379. */
  2380. void ath5k_hw_set_ack_bitrate_high(struct ath5k_hw *ah, bool high)
  2381. {
  2382. if (ah->ah_version != AR5K_AR5212)
  2383. return;
  2384. else {
  2385. u32 val = AR5K_STA_ID1_BASE_RATE_11B | AR5K_STA_ID1_ACKCTS_6MB;
  2386. if (high)
  2387. AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1, val);
  2388. else
  2389. AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, val);
  2390. }
  2391. }
  2392. /*
  2393. * ACK/CTS Timeouts
  2394. */
  2395. /*
  2396. * Set ACK timeout on PCU
  2397. */
  2398. int ath5k_hw_set_ack_timeout(struct ath5k_hw *ah, unsigned int timeout)
  2399. {
  2400. ATH5K_TRACE(ah->ah_sc);
  2401. if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_ACK),
  2402. ah->ah_turbo) <= timeout)
  2403. return -EINVAL;
  2404. AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_ACK,
  2405. ath5k_hw_htoclock(timeout, ah->ah_turbo));
  2406. return 0;
  2407. }
  2408. /*
  2409. * Read the ACK timeout from PCU
  2410. */
  2411. unsigned int ath5k_hw_get_ack_timeout(struct ath5k_hw *ah)
  2412. {
  2413. ATH5K_TRACE(ah->ah_sc);
  2414. return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
  2415. AR5K_TIME_OUT), AR5K_TIME_OUT_ACK), ah->ah_turbo);
  2416. }
  2417. /*
  2418. * Set CTS timeout on PCU
  2419. */
  2420. int ath5k_hw_set_cts_timeout(struct ath5k_hw *ah, unsigned int timeout)
  2421. {
  2422. ATH5K_TRACE(ah->ah_sc);
  2423. if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_CTS),
  2424. ah->ah_turbo) <= timeout)
  2425. return -EINVAL;
  2426. AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_CTS,
  2427. ath5k_hw_htoclock(timeout, ah->ah_turbo));
  2428. return 0;
  2429. }
  2430. /*
  2431. * Read CTS timeout from PCU
  2432. */
  2433. unsigned int ath5k_hw_get_cts_timeout(struct ath5k_hw *ah)
  2434. {
  2435. ATH5K_TRACE(ah->ah_sc);
  2436. return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
  2437. AR5K_TIME_OUT), AR5K_TIME_OUT_CTS), ah->ah_turbo);
  2438. }
  2439. /*
  2440. * Key table (WEP) functions
  2441. */
  2442. int ath5k_hw_reset_key(struct ath5k_hw *ah, u16 entry)
  2443. {
  2444. unsigned int i;
  2445. ATH5K_TRACE(ah->ah_sc);
  2446. AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
  2447. for (i = 0; i < AR5K_KEYCACHE_SIZE; i++)
  2448. ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_OFF(entry, i));
  2449. /* Set NULL encryption on non-5210*/
  2450. if (ah->ah_version != AR5K_AR5210)
  2451. ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL,
  2452. AR5K_KEYTABLE_TYPE(entry));
  2453. return 0;
  2454. }
  2455. int ath5k_hw_is_key_valid(struct ath5k_hw *ah, u16 entry)
  2456. {
  2457. ATH5K_TRACE(ah->ah_sc);
  2458. AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
  2459. /* Check the validation flag at the end of the entry */
  2460. return ath5k_hw_reg_read(ah, AR5K_KEYTABLE_MAC1(entry)) &
  2461. AR5K_KEYTABLE_VALID;
  2462. }
  2463. int ath5k_hw_set_key(struct ath5k_hw *ah, u16 entry,
  2464. const struct ieee80211_key_conf *key, const u8 *mac)
  2465. {
  2466. unsigned int i;
  2467. __le32 key_v[5] = {};
  2468. u32 keytype;
  2469. ATH5K_TRACE(ah->ah_sc);
  2470. /* key->keylen comes in from mac80211 in bytes */
  2471. if (key->keylen > AR5K_KEYTABLE_SIZE / 8)
  2472. return -EOPNOTSUPP;
  2473. switch (key->keylen) {
  2474. /* WEP 40-bit = 40-bit entered key + 24 bit IV = 64-bit */
  2475. case 40 / 8:
  2476. memcpy(&key_v[0], key->key, 5);
  2477. keytype = AR5K_KEYTABLE_TYPE_40;
  2478. break;
  2479. /* WEP 104-bit = 104-bit entered key + 24-bit IV = 128-bit */
  2480. case 104 / 8:
  2481. memcpy(&key_v[0], &key->key[0], 6);
  2482. memcpy(&key_v[2], &key->key[6], 6);
  2483. memcpy(&key_v[4], &key->key[12], 1);
  2484. keytype = AR5K_KEYTABLE_TYPE_104;
  2485. break;
  2486. /* WEP 128-bit = 128-bit entered key + 24 bit IV = 152-bit */
  2487. case 128 / 8:
  2488. memcpy(&key_v[0], &key->key[0], 6);
  2489. memcpy(&key_v[2], &key->key[6], 6);
  2490. memcpy(&key_v[4], &key->key[12], 4);
  2491. keytype = AR5K_KEYTABLE_TYPE_128;
  2492. break;
  2493. default:
  2494. return -EINVAL; /* shouldn't happen */
  2495. }
  2496. for (i = 0; i < ARRAY_SIZE(key_v); i++)
  2497. ath5k_hw_reg_write(ah, le32_to_cpu(key_v[i]),
  2498. AR5K_KEYTABLE_OFF(entry, i));
  2499. ath5k_hw_reg_write(ah, keytype, AR5K_KEYTABLE_TYPE(entry));
  2500. return ath5k_hw_set_key_lladdr(ah, entry, mac);
  2501. }
  2502. int ath5k_hw_set_key_lladdr(struct ath5k_hw *ah, u16 entry, const u8 *mac)
  2503. {
  2504. u32 low_id, high_id;
  2505. ATH5K_TRACE(ah->ah_sc);
  2506. /* Invalid entry (key table overflow) */
  2507. AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
  2508. /* MAC may be NULL if it's a broadcast key. In this case no need to
  2509. * to compute AR5K_LOW_ID and AR5K_HIGH_ID as we already know it. */
  2510. if (unlikely(mac == NULL)) {
  2511. low_id = 0xffffffff;
  2512. high_id = 0xffff | AR5K_KEYTABLE_VALID;
  2513. } else {
  2514. low_id = AR5K_LOW_ID(mac);
  2515. high_id = AR5K_HIGH_ID(mac) | AR5K_KEYTABLE_VALID;
  2516. }
  2517. ath5k_hw_reg_write(ah, low_id, AR5K_KEYTABLE_MAC0(entry));
  2518. ath5k_hw_reg_write(ah, high_id, AR5K_KEYTABLE_MAC1(entry));
  2519. return 0;
  2520. }
  2521. /********************************************\
  2522. Queue Control Unit, DFS Control Unit Functions
  2523. \********************************************/
  2524. /*
  2525. * Initialize a transmit queue
  2526. */
  2527. int ath5k_hw_setup_tx_queue(struct ath5k_hw *ah, enum ath5k_tx_queue queue_type,
  2528. struct ath5k_txq_info *queue_info)
  2529. {
  2530. unsigned int queue;
  2531. int ret;
  2532. ATH5K_TRACE(ah->ah_sc);
  2533. /*
  2534. * Get queue by type
  2535. */
  2536. /*5210 only has 2 queues*/
  2537. if (ah->ah_version == AR5K_AR5210) {
  2538. switch (queue_type) {
  2539. case AR5K_TX_QUEUE_DATA:
  2540. queue = AR5K_TX_QUEUE_ID_NOQCU_DATA;
  2541. break;
  2542. case AR5K_TX_QUEUE_BEACON:
  2543. case AR5K_TX_QUEUE_CAB:
  2544. queue = AR5K_TX_QUEUE_ID_NOQCU_BEACON;
  2545. break;
  2546. default:
  2547. return -EINVAL;
  2548. }
  2549. } else {
  2550. switch (queue_type) {
  2551. case AR5K_TX_QUEUE_DATA:
  2552. for (queue = AR5K_TX_QUEUE_ID_DATA_MIN;
  2553. ah->ah_txq[queue].tqi_type !=
  2554. AR5K_TX_QUEUE_INACTIVE; queue++) {
  2555. if (queue > AR5K_TX_QUEUE_ID_DATA_MAX)
  2556. return -EINVAL;
  2557. }
  2558. break;
  2559. case AR5K_TX_QUEUE_UAPSD:
  2560. queue = AR5K_TX_QUEUE_ID_UAPSD;
  2561. break;
  2562. case AR5K_TX_QUEUE_BEACON:
  2563. queue = AR5K_TX_QUEUE_ID_BEACON;
  2564. break;
  2565. case AR5K_TX_QUEUE_CAB:
  2566. queue = AR5K_TX_QUEUE_ID_CAB;
  2567. break;
  2568. case AR5K_TX_QUEUE_XR_DATA:
  2569. if (ah->ah_version != AR5K_AR5212)
  2570. ATH5K_ERR(ah->ah_sc,
  2571. "XR data queues only supported in"
  2572. " 5212!\n");
  2573. queue = AR5K_TX_QUEUE_ID_XR_DATA;
  2574. break;
  2575. default:
  2576. return -EINVAL;
  2577. }
  2578. }
  2579. /*
  2580. * Setup internal queue structure
  2581. */
  2582. memset(&ah->ah_txq[queue], 0, sizeof(struct ath5k_txq_info));
  2583. ah->ah_txq[queue].tqi_type = queue_type;
  2584. if (queue_info != NULL) {
  2585. queue_info->tqi_type = queue_type;
  2586. ret = ath5k_hw_setup_tx_queueprops(ah, queue, queue_info);
  2587. if (ret)
  2588. return ret;
  2589. }
  2590. /*
  2591. * We use ah_txq_status to hold a temp value for
  2592. * the Secondary interrupt mask registers on 5211+
  2593. * check out ath5k_hw_reset_tx_queue
  2594. */
  2595. AR5K_Q_ENABLE_BITS(ah->ah_txq_status, queue);
  2596. return queue;
  2597. }
  2598. /*
  2599. * Setup a transmit queue
  2600. */
  2601. int ath5k_hw_setup_tx_queueprops(struct ath5k_hw *ah, int queue,
  2602. const struct ath5k_txq_info *queue_info)
  2603. {
  2604. ATH5K_TRACE(ah->ah_sc);
  2605. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  2606. if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
  2607. return -EIO;
  2608. memcpy(&ah->ah_txq[queue], queue_info, sizeof(struct ath5k_txq_info));
  2609. /*XXX: Is this supported on 5210 ?*/
  2610. if ((queue_info->tqi_type == AR5K_TX_QUEUE_DATA &&
  2611. ((queue_info->tqi_subtype == AR5K_WME_AC_VI) ||
  2612. (queue_info->tqi_subtype == AR5K_WME_AC_VO))) ||
  2613. queue_info->tqi_type == AR5K_TX_QUEUE_UAPSD)
  2614. ah->ah_txq[queue].tqi_flags |= AR5K_TXQ_FLAG_POST_FR_BKOFF_DIS;
  2615. return 0;
  2616. }
  2617. /*
  2618. * Get properties for a specific transmit queue
  2619. */
  2620. int ath5k_hw_get_tx_queueprops(struct ath5k_hw *ah, int queue,
  2621. struct ath5k_txq_info *queue_info)
  2622. {
  2623. ATH5K_TRACE(ah->ah_sc);
  2624. memcpy(queue_info, &ah->ah_txq[queue], sizeof(struct ath5k_txq_info));
  2625. return 0;
  2626. }
  2627. /*
  2628. * Set a transmit queue inactive
  2629. */
  2630. void ath5k_hw_release_tx_queue(struct ath5k_hw *ah, unsigned int queue)
  2631. {
  2632. ATH5K_TRACE(ah->ah_sc);
  2633. if (WARN_ON(queue >= ah->ah_capabilities.cap_queues.q_tx_num))
  2634. return;
  2635. /* This queue will be skipped in further operations */
  2636. ah->ah_txq[queue].tqi_type = AR5K_TX_QUEUE_INACTIVE;
  2637. /*For SIMR setup*/
  2638. AR5K_Q_DISABLE_BITS(ah->ah_txq_status, queue);
  2639. }
  2640. /*
  2641. * Set DFS params for a transmit queue
  2642. */
  2643. int ath5k_hw_reset_tx_queue(struct ath5k_hw *ah, unsigned int queue)
  2644. {
  2645. u32 cw_min, cw_max, retry_lg, retry_sh;
  2646. struct ath5k_txq_info *tq = &ah->ah_txq[queue];
  2647. ATH5K_TRACE(ah->ah_sc);
  2648. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  2649. tq = &ah->ah_txq[queue];
  2650. if (tq->tqi_type == AR5K_TX_QUEUE_INACTIVE)
  2651. return 0;
  2652. if (ah->ah_version == AR5K_AR5210) {
  2653. /* Only handle data queues, others will be ignored */
  2654. if (tq->tqi_type != AR5K_TX_QUEUE_DATA)
  2655. return 0;
  2656. /* Set Slot time */
  2657. ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
  2658. AR5K_INIT_SLOT_TIME_TURBO : AR5K_INIT_SLOT_TIME,
  2659. AR5K_SLOT_TIME);
  2660. /* Set ACK_CTS timeout */
  2661. ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
  2662. AR5K_INIT_ACK_CTS_TIMEOUT_TURBO :
  2663. AR5K_INIT_ACK_CTS_TIMEOUT, AR5K_SLOT_TIME);
  2664. /* Set Transmit Latency */
  2665. ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
  2666. AR5K_INIT_TRANSMIT_LATENCY_TURBO :
  2667. AR5K_INIT_TRANSMIT_LATENCY, AR5K_USEC_5210);
  2668. /* Set IFS0 */
  2669. if (ah->ah_turbo == true)
  2670. ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS_TURBO +
  2671. (ah->ah_aifs + tq->tqi_aifs) *
  2672. AR5K_INIT_SLOT_TIME_TURBO) <<
  2673. AR5K_IFS0_DIFS_S) | AR5K_INIT_SIFS_TURBO,
  2674. AR5K_IFS0);
  2675. else
  2676. ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS +
  2677. (ah->ah_aifs + tq->tqi_aifs) *
  2678. AR5K_INIT_SLOT_TIME) << AR5K_IFS0_DIFS_S) |
  2679. AR5K_INIT_SIFS, AR5K_IFS0);
  2680. /* Set IFS1 */
  2681. ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
  2682. AR5K_INIT_PROTO_TIME_CNTRL_TURBO :
  2683. AR5K_INIT_PROTO_TIME_CNTRL, AR5K_IFS1);
  2684. /* Set PHY register 0x9844 (??) */
  2685. ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
  2686. (ath5k_hw_reg_read(ah, AR5K_PHY(17)) & ~0x7F) | 0x38 :
  2687. (ath5k_hw_reg_read(ah, AR5K_PHY(17)) & ~0x7F) | 0x1C,
  2688. AR5K_PHY(17));
  2689. /* Set Frame Control Register */
  2690. ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
  2691. (AR5K_PHY_FRAME_CTL_INI | AR5K_PHY_TURBO_MODE |
  2692. AR5K_PHY_TURBO_SHORT | 0x2020) :
  2693. (AR5K_PHY_FRAME_CTL_INI | 0x1020),
  2694. AR5K_PHY_FRAME_CTL_5210);
  2695. }
  2696. /*
  2697. * Calculate cwmin/max by channel mode
  2698. */
  2699. cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN;
  2700. cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX;
  2701. ah->ah_aifs = AR5K_TUNE_AIFS;
  2702. /*XR is only supported on 5212*/
  2703. if (IS_CHAN_XR(ah->ah_current_channel) &&
  2704. ah->ah_version == AR5K_AR5212) {
  2705. cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_XR;
  2706. cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_XR;
  2707. ah->ah_aifs = AR5K_TUNE_AIFS_XR;
  2708. /*B mode is not supported on 5210*/
  2709. } else if (IS_CHAN_B(ah->ah_current_channel) &&
  2710. ah->ah_version != AR5K_AR5210) {
  2711. cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_11B;
  2712. cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_11B;
  2713. ah->ah_aifs = AR5K_TUNE_AIFS_11B;
  2714. }
  2715. cw_min = 1;
  2716. while (cw_min < ah->ah_cw_min)
  2717. cw_min = (cw_min << 1) | 1;
  2718. cw_min = tq->tqi_cw_min < 0 ? (cw_min >> (-tq->tqi_cw_min)) :
  2719. ((cw_min << tq->tqi_cw_min) + (1 << tq->tqi_cw_min) - 1);
  2720. cw_max = tq->tqi_cw_max < 0 ? (cw_max >> (-tq->tqi_cw_max)) :
  2721. ((cw_max << tq->tqi_cw_max) + (1 << tq->tqi_cw_max) - 1);
  2722. /*
  2723. * Calculate and set retry limits
  2724. */
  2725. if (ah->ah_software_retry == true) {
  2726. /* XXX Need to test this */
  2727. retry_lg = ah->ah_limit_tx_retries;
  2728. retry_sh = retry_lg = retry_lg > AR5K_DCU_RETRY_LMT_SH_RETRY ?
  2729. AR5K_DCU_RETRY_LMT_SH_RETRY : retry_lg;
  2730. } else {
  2731. retry_lg = AR5K_INIT_LG_RETRY;
  2732. retry_sh = AR5K_INIT_SH_RETRY;
  2733. }
  2734. /*No QCU/DCU [5210]*/
  2735. if (ah->ah_version == AR5K_AR5210) {
  2736. ath5k_hw_reg_write(ah,
  2737. (cw_min << AR5K_NODCU_RETRY_LMT_CW_MIN_S)
  2738. | AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
  2739. AR5K_NODCU_RETRY_LMT_SLG_RETRY)
  2740. | AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
  2741. AR5K_NODCU_RETRY_LMT_SSH_RETRY)
  2742. | AR5K_REG_SM(retry_lg, AR5K_NODCU_RETRY_LMT_LG_RETRY)
  2743. | AR5K_REG_SM(retry_sh, AR5K_NODCU_RETRY_LMT_SH_RETRY),
  2744. AR5K_NODCU_RETRY_LMT);
  2745. } else {
  2746. /*QCU/DCU [5211+]*/
  2747. ath5k_hw_reg_write(ah,
  2748. AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
  2749. AR5K_DCU_RETRY_LMT_SLG_RETRY) |
  2750. AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
  2751. AR5K_DCU_RETRY_LMT_SSH_RETRY) |
  2752. AR5K_REG_SM(retry_lg, AR5K_DCU_RETRY_LMT_LG_RETRY) |
  2753. AR5K_REG_SM(retry_sh, AR5K_DCU_RETRY_LMT_SH_RETRY),
  2754. AR5K_QUEUE_DFS_RETRY_LIMIT(queue));
  2755. /*===Rest is also for QCU/DCU only [5211+]===*/
  2756. /*
  2757. * Set initial content window (cw_min/cw_max)
  2758. * and arbitrated interframe space (aifs)...
  2759. */
  2760. ath5k_hw_reg_write(ah,
  2761. AR5K_REG_SM(cw_min, AR5K_DCU_LCL_IFS_CW_MIN) |
  2762. AR5K_REG_SM(cw_max, AR5K_DCU_LCL_IFS_CW_MAX) |
  2763. AR5K_REG_SM(ah->ah_aifs + tq->tqi_aifs,
  2764. AR5K_DCU_LCL_IFS_AIFS),
  2765. AR5K_QUEUE_DFS_LOCAL_IFS(queue));
  2766. /*
  2767. * Set misc registers
  2768. */
  2769. ath5k_hw_reg_write(ah, AR5K_QCU_MISC_DCU_EARLY,
  2770. AR5K_QUEUE_MISC(queue));
  2771. if (tq->tqi_cbr_period) {
  2772. ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_cbr_period,
  2773. AR5K_QCU_CBRCFG_INTVAL) |
  2774. AR5K_REG_SM(tq->tqi_cbr_overflow_limit,
  2775. AR5K_QCU_CBRCFG_ORN_THRES),
  2776. AR5K_QUEUE_CBRCFG(queue));
  2777. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  2778. AR5K_QCU_MISC_FRSHED_CBR);
  2779. if (tq->tqi_cbr_overflow_limit)
  2780. AR5K_REG_ENABLE_BITS(ah,
  2781. AR5K_QUEUE_MISC(queue),
  2782. AR5K_QCU_MISC_CBR_THRES_ENABLE);
  2783. }
  2784. if (tq->tqi_ready_time)
  2785. ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_ready_time,
  2786. AR5K_QCU_RDYTIMECFG_INTVAL) |
  2787. AR5K_QCU_RDYTIMECFG_ENABLE,
  2788. AR5K_QUEUE_RDYTIMECFG(queue));
  2789. if (tq->tqi_burst_time) {
  2790. ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_burst_time,
  2791. AR5K_DCU_CHAN_TIME_DUR) |
  2792. AR5K_DCU_CHAN_TIME_ENABLE,
  2793. AR5K_QUEUE_DFS_CHANNEL_TIME(queue));
  2794. if (tq->tqi_flags & AR5K_TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)
  2795. AR5K_REG_ENABLE_BITS(ah,
  2796. AR5K_QUEUE_MISC(queue),
  2797. AR5K_QCU_MISC_TXE);
  2798. }
  2799. if (tq->tqi_flags & AR5K_TXQ_FLAG_BACKOFF_DISABLE)
  2800. ath5k_hw_reg_write(ah, AR5K_DCU_MISC_POST_FR_BKOFF_DIS,
  2801. AR5K_QUEUE_DFS_MISC(queue));
  2802. if (tq->tqi_flags & AR5K_TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE)
  2803. ath5k_hw_reg_write(ah, AR5K_DCU_MISC_BACKOFF_FRAG,
  2804. AR5K_QUEUE_DFS_MISC(queue));
  2805. /*
  2806. * Set registers by queue type
  2807. */
  2808. switch (tq->tqi_type) {
  2809. case AR5K_TX_QUEUE_BEACON:
  2810. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  2811. AR5K_QCU_MISC_FRSHED_DBA_GT |
  2812. AR5K_QCU_MISC_CBREXP_BCN |
  2813. AR5K_QCU_MISC_BCN_ENABLE);
  2814. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
  2815. (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
  2816. AR5K_DCU_MISC_ARBLOCK_CTL_S) |
  2817. AR5K_DCU_MISC_POST_FR_BKOFF_DIS |
  2818. AR5K_DCU_MISC_BCN_ENABLE);
  2819. ath5k_hw_reg_write(ah, ((AR5K_TUNE_BEACON_INTERVAL -
  2820. (AR5K_TUNE_SW_BEACON_RESP -
  2821. AR5K_TUNE_DMA_BEACON_RESP) -
  2822. AR5K_TUNE_ADDITIONAL_SWBA_BACKOFF) * 1024) |
  2823. AR5K_QCU_RDYTIMECFG_ENABLE,
  2824. AR5K_QUEUE_RDYTIMECFG(queue));
  2825. break;
  2826. case AR5K_TX_QUEUE_CAB:
  2827. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  2828. AR5K_QCU_MISC_FRSHED_DBA_GT |
  2829. AR5K_QCU_MISC_CBREXP |
  2830. AR5K_QCU_MISC_CBREXP_BCN);
  2831. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
  2832. (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
  2833. AR5K_DCU_MISC_ARBLOCK_CTL_S));
  2834. break;
  2835. case AR5K_TX_QUEUE_UAPSD:
  2836. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  2837. AR5K_QCU_MISC_CBREXP);
  2838. break;
  2839. case AR5K_TX_QUEUE_DATA:
  2840. default:
  2841. break;
  2842. }
  2843. /*
  2844. * Enable interrupts for this tx queue
  2845. * in the secondary interrupt mask registers
  2846. */
  2847. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXOKINT_ENABLE)
  2848. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txok, queue);
  2849. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXERRINT_ENABLE)
  2850. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txerr, queue);
  2851. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXURNINT_ENABLE)
  2852. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txurn, queue);
  2853. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXDESCINT_ENABLE)
  2854. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txdesc, queue);
  2855. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXEOLINT_ENABLE)
  2856. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txeol, queue);
  2857. /* Update secondary interrupt mask registers */
  2858. ah->ah_txq_imr_txok &= ah->ah_txq_status;
  2859. ah->ah_txq_imr_txerr &= ah->ah_txq_status;
  2860. ah->ah_txq_imr_txurn &= ah->ah_txq_status;
  2861. ah->ah_txq_imr_txdesc &= ah->ah_txq_status;
  2862. ah->ah_txq_imr_txeol &= ah->ah_txq_status;
  2863. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txok,
  2864. AR5K_SIMR0_QCU_TXOK) |
  2865. AR5K_REG_SM(ah->ah_txq_imr_txdesc,
  2866. AR5K_SIMR0_QCU_TXDESC), AR5K_SIMR0);
  2867. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txerr,
  2868. AR5K_SIMR1_QCU_TXERR) |
  2869. AR5K_REG_SM(ah->ah_txq_imr_txeol,
  2870. AR5K_SIMR1_QCU_TXEOL), AR5K_SIMR1);
  2871. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txurn,
  2872. AR5K_SIMR2_QCU_TXURN), AR5K_SIMR2);
  2873. }
  2874. return 0;
  2875. }
  2876. /*
  2877. * Get number of pending frames
  2878. * for a specific queue [5211+]
  2879. */
  2880. u32 ath5k_hw_num_tx_pending(struct ath5k_hw *ah, unsigned int queue) {
  2881. ATH5K_TRACE(ah->ah_sc);
  2882. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  2883. /* Return if queue is declared inactive */
  2884. if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
  2885. return false;
  2886. /* XXX: How about AR5K_CFG_TXCNT ? */
  2887. if (ah->ah_version == AR5K_AR5210)
  2888. return false;
  2889. return AR5K_QUEUE_STATUS(queue) & AR5K_QCU_STS_FRMPENDCNT;
  2890. }
  2891. /*
  2892. * Set slot time
  2893. */
  2894. int ath5k_hw_set_slot_time(struct ath5k_hw *ah, unsigned int slot_time)
  2895. {
  2896. ATH5K_TRACE(ah->ah_sc);
  2897. if (slot_time < AR5K_SLOT_TIME_9 || slot_time > AR5K_SLOT_TIME_MAX)
  2898. return -EINVAL;
  2899. if (ah->ah_version == AR5K_AR5210)
  2900. ath5k_hw_reg_write(ah, ath5k_hw_htoclock(slot_time,
  2901. ah->ah_turbo), AR5K_SLOT_TIME);
  2902. else
  2903. ath5k_hw_reg_write(ah, slot_time, AR5K_DCU_GBL_IFS_SLOT);
  2904. return 0;
  2905. }
  2906. /*
  2907. * Get slot time
  2908. */
  2909. unsigned int ath5k_hw_get_slot_time(struct ath5k_hw *ah)
  2910. {
  2911. ATH5K_TRACE(ah->ah_sc);
  2912. if (ah->ah_version == AR5K_AR5210)
  2913. return ath5k_hw_clocktoh(ath5k_hw_reg_read(ah,
  2914. AR5K_SLOT_TIME) & 0xffff, ah->ah_turbo);
  2915. else
  2916. return ath5k_hw_reg_read(ah, AR5K_DCU_GBL_IFS_SLOT) & 0xffff;
  2917. }
  2918. /******************************\
  2919. Hardware Descriptor Functions
  2920. \******************************/
  2921. /*
  2922. * TX Descriptor
  2923. */
  2924. /*
  2925. * Initialize the 2-word tx descriptor on 5210/5211
  2926. */
  2927. static int
  2928. ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
  2929. unsigned int pkt_len, unsigned int hdr_len, enum ath5k_pkt_type type,
  2930. unsigned int tx_power, unsigned int tx_rate0, unsigned int tx_tries0,
  2931. unsigned int key_index, unsigned int antenna_mode, unsigned int flags,
  2932. unsigned int rtscts_rate, unsigned int rtscts_duration)
  2933. {
  2934. u32 frame_type;
  2935. struct ath5k_hw_2w_tx_desc *tx_desc;
  2936. unsigned int frame_len;
  2937. tx_desc = (struct ath5k_hw_2w_tx_desc *)&desc->ds_ctl0;
  2938. /*
  2939. * Validate input
  2940. * - Zero retries don't make sense.
  2941. * - A zero rate will put the HW into a mode where it continously sends
  2942. * noise on the channel, so it is important to avoid this.
  2943. */
  2944. if (unlikely(tx_tries0 == 0)) {
  2945. ATH5K_ERR(ah->ah_sc, "zero retries\n");
  2946. WARN_ON(1);
  2947. return -EINVAL;
  2948. }
  2949. if (unlikely(tx_rate0 == 0)) {
  2950. ATH5K_ERR(ah->ah_sc, "zero rate\n");
  2951. WARN_ON(1);
  2952. return -EINVAL;
  2953. }
  2954. /* Clear status descriptor */
  2955. memset(desc->ds_hw, 0, sizeof(struct ath5k_hw_tx_status));
  2956. /* Initialize control descriptor */
  2957. tx_desc->tx_control_0 = 0;
  2958. tx_desc->tx_control_1 = 0;
  2959. /* Setup control descriptor */
  2960. /* Verify and set frame length */
  2961. /* remove padding we might have added before */
  2962. frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
  2963. if (frame_len & ~AR5K_2W_TX_DESC_CTL0_FRAME_LEN)
  2964. return -EINVAL;
  2965. tx_desc->tx_control_0 = frame_len & AR5K_2W_TX_DESC_CTL0_FRAME_LEN;
  2966. /* Verify and set buffer length */
  2967. /* NB: beacon's BufLen must be a multiple of 4 bytes */
  2968. if(type == AR5K_PKT_TYPE_BEACON)
  2969. pkt_len = roundup(pkt_len, 4);
  2970. if (pkt_len & ~AR5K_2W_TX_DESC_CTL1_BUF_LEN)
  2971. return -EINVAL;
  2972. tx_desc->tx_control_1 = pkt_len & AR5K_2W_TX_DESC_CTL1_BUF_LEN;
  2973. /*
  2974. * Verify and set header length
  2975. * XXX: I only found that on 5210 code, does it work on 5211 ?
  2976. */
  2977. if (ah->ah_version == AR5K_AR5210) {
  2978. if (hdr_len & ~AR5K_2W_TX_DESC_CTL0_HEADER_LEN)
  2979. return -EINVAL;
  2980. tx_desc->tx_control_0 |=
  2981. AR5K_REG_SM(hdr_len, AR5K_2W_TX_DESC_CTL0_HEADER_LEN);
  2982. }
  2983. /*Diferences between 5210-5211*/
  2984. if (ah->ah_version == AR5K_AR5210) {
  2985. switch (type) {
  2986. case AR5K_PKT_TYPE_BEACON:
  2987. case AR5K_PKT_TYPE_PROBE_RESP:
  2988. frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_NO_DELAY;
  2989. case AR5K_PKT_TYPE_PIFS:
  2990. frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_PIFS;
  2991. default:
  2992. frame_type = type /*<< 2 ?*/;
  2993. }
  2994. tx_desc->tx_control_0 |=
  2995. AR5K_REG_SM(frame_type, AR5K_2W_TX_DESC_CTL0_FRAME_TYPE) |
  2996. AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
  2997. } else {
  2998. tx_desc->tx_control_0 |=
  2999. AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE) |
  3000. AR5K_REG_SM(antenna_mode, AR5K_2W_TX_DESC_CTL0_ANT_MODE_XMIT);
  3001. tx_desc->tx_control_1 |=
  3002. AR5K_REG_SM(type, AR5K_2W_TX_DESC_CTL1_FRAME_TYPE);
  3003. }
  3004. #define _TX_FLAGS(_c, _flag) \
  3005. if (flags & AR5K_TXDESC_##_flag) \
  3006. tx_desc->tx_control_##_c |= \
  3007. AR5K_2W_TX_DESC_CTL##_c##_##_flag
  3008. _TX_FLAGS(0, CLRDMASK);
  3009. _TX_FLAGS(0, VEOL);
  3010. _TX_FLAGS(0, INTREQ);
  3011. _TX_FLAGS(0, RTSENA);
  3012. _TX_FLAGS(1, NOACK);
  3013. #undef _TX_FLAGS
  3014. /*
  3015. * WEP crap
  3016. */
  3017. if (key_index != AR5K_TXKEYIX_INVALID) {
  3018. tx_desc->tx_control_0 |=
  3019. AR5K_2W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
  3020. tx_desc->tx_control_1 |=
  3021. AR5K_REG_SM(key_index,
  3022. AR5K_2W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
  3023. }
  3024. /*
  3025. * RTS/CTS Duration [5210 ?]
  3026. */
  3027. if ((ah->ah_version == AR5K_AR5210) &&
  3028. (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)))
  3029. tx_desc->tx_control_1 |= rtscts_duration &
  3030. AR5K_2W_TX_DESC_CTL1_RTS_DURATION;
  3031. return 0;
  3032. }
  3033. /*
  3034. * Initialize the 4-word tx descriptor on 5212
  3035. */
  3036. static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *ah,
  3037. struct ath5k_desc *desc, unsigned int pkt_len, unsigned int hdr_len,
  3038. enum ath5k_pkt_type type, unsigned int tx_power, unsigned int tx_rate0,
  3039. unsigned int tx_tries0, unsigned int key_index,
  3040. unsigned int antenna_mode, unsigned int flags, unsigned int rtscts_rate,
  3041. unsigned int rtscts_duration)
  3042. {
  3043. struct ath5k_hw_4w_tx_desc *tx_desc;
  3044. struct ath5k_hw_tx_status *tx_status;
  3045. unsigned int frame_len;
  3046. ATH5K_TRACE(ah->ah_sc);
  3047. tx_desc = (struct ath5k_hw_4w_tx_desc *)&desc->ds_ctl0;
  3048. tx_status = (struct ath5k_hw_tx_status *)&desc->ds_hw[2];
  3049. /*
  3050. * Validate input
  3051. * - Zero retries don't make sense.
  3052. * - A zero rate will put the HW into a mode where it continously sends
  3053. * noise on the channel, so it is important to avoid this.
  3054. */
  3055. if (unlikely(tx_tries0 == 0)) {
  3056. ATH5K_ERR(ah->ah_sc, "zero retries\n");
  3057. WARN_ON(1);
  3058. return -EINVAL;
  3059. }
  3060. if (unlikely(tx_rate0 == 0)) {
  3061. ATH5K_ERR(ah->ah_sc, "zero rate\n");
  3062. WARN_ON(1);
  3063. return -EINVAL;
  3064. }
  3065. /* Clear status descriptor */
  3066. memset(tx_status, 0, sizeof(struct ath5k_hw_tx_status));
  3067. /* Initialize control descriptor */
  3068. tx_desc->tx_control_0 = 0;
  3069. tx_desc->tx_control_1 = 0;
  3070. tx_desc->tx_control_2 = 0;
  3071. tx_desc->tx_control_3 = 0;
  3072. /* Setup control descriptor */
  3073. /* Verify and set frame length */
  3074. /* remove padding we might have added before */
  3075. frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
  3076. if (frame_len & ~AR5K_4W_TX_DESC_CTL0_FRAME_LEN)
  3077. return -EINVAL;
  3078. tx_desc->tx_control_0 = frame_len & AR5K_4W_TX_DESC_CTL0_FRAME_LEN;
  3079. /* Verify and set buffer length */
  3080. /* NB: beacon's BufLen must be a multiple of 4 bytes */
  3081. if(type == AR5K_PKT_TYPE_BEACON)
  3082. pkt_len = roundup(pkt_len, 4);
  3083. if (pkt_len & ~AR5K_4W_TX_DESC_CTL1_BUF_LEN)
  3084. return -EINVAL;
  3085. tx_desc->tx_control_1 = pkt_len & AR5K_4W_TX_DESC_CTL1_BUF_LEN;
  3086. tx_desc->tx_control_0 |=
  3087. AR5K_REG_SM(tx_power, AR5K_4W_TX_DESC_CTL0_XMIT_POWER) |
  3088. AR5K_REG_SM(antenna_mode, AR5K_4W_TX_DESC_CTL0_ANT_MODE_XMIT);
  3089. tx_desc->tx_control_1 |= AR5K_REG_SM(type,
  3090. AR5K_4W_TX_DESC_CTL1_FRAME_TYPE);
  3091. tx_desc->tx_control_2 = AR5K_REG_SM(tx_tries0 + AR5K_TUNE_HWTXTRIES,
  3092. AR5K_4W_TX_DESC_CTL2_XMIT_TRIES0);
  3093. tx_desc->tx_control_3 = tx_rate0 & AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
  3094. #define _TX_FLAGS(_c, _flag) \
  3095. if (flags & AR5K_TXDESC_##_flag) \
  3096. tx_desc->tx_control_##_c |= \
  3097. AR5K_4W_TX_DESC_CTL##_c##_##_flag
  3098. _TX_FLAGS(0, CLRDMASK);
  3099. _TX_FLAGS(0, VEOL);
  3100. _TX_FLAGS(0, INTREQ);
  3101. _TX_FLAGS(0, RTSENA);
  3102. _TX_FLAGS(0, CTSENA);
  3103. _TX_FLAGS(1, NOACK);
  3104. #undef _TX_FLAGS
  3105. /*
  3106. * WEP crap
  3107. */
  3108. if (key_index != AR5K_TXKEYIX_INVALID) {
  3109. tx_desc->tx_control_0 |= AR5K_4W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
  3110. tx_desc->tx_control_1 |= AR5K_REG_SM(key_index,
  3111. AR5K_4W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
  3112. }
  3113. /*
  3114. * RTS/CTS
  3115. */
  3116. if (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)) {
  3117. if ((flags & AR5K_TXDESC_RTSENA) &&
  3118. (flags & AR5K_TXDESC_CTSENA))
  3119. return -EINVAL;
  3120. tx_desc->tx_control_2 |= rtscts_duration &
  3121. AR5K_4W_TX_DESC_CTL2_RTS_DURATION;
  3122. tx_desc->tx_control_3 |= AR5K_REG_SM(rtscts_rate,
  3123. AR5K_4W_TX_DESC_CTL3_RTS_CTS_RATE);
  3124. }
  3125. return 0;
  3126. }
  3127. /*
  3128. * Initialize a 4-word multirate tx descriptor on 5212
  3129. */
  3130. static int
  3131. ath5k_hw_setup_xr_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
  3132. unsigned int tx_rate1, u_int tx_tries1, u_int tx_rate2, u_int tx_tries2,
  3133. unsigned int tx_rate3, u_int tx_tries3)
  3134. {
  3135. struct ath5k_hw_4w_tx_desc *tx_desc;
  3136. /*
  3137. * Rates can be 0 as long as the retry count is 0 too.
  3138. * A zero rate and nonzero retry count will put the HW into a mode where
  3139. * it continously sends noise on the channel, so it is important to
  3140. * avoid this.
  3141. */
  3142. if (unlikely((tx_rate1 == 0 && tx_tries1 != 0) ||
  3143. (tx_rate2 == 0 && tx_tries2 != 0) ||
  3144. (tx_rate3 == 0 && tx_tries3 != 0))) {
  3145. ATH5K_ERR(ah->ah_sc, "zero rate\n");
  3146. WARN_ON(1);
  3147. return -EINVAL;
  3148. }
  3149. if (ah->ah_version == AR5K_AR5212) {
  3150. tx_desc = (struct ath5k_hw_4w_tx_desc *)&desc->ds_ctl0;
  3151. #define _XTX_TRIES(_n) \
  3152. if (tx_tries##_n) { \
  3153. tx_desc->tx_control_2 |= \
  3154. AR5K_REG_SM(tx_tries##_n, \
  3155. AR5K_4W_TX_DESC_CTL2_XMIT_TRIES##_n); \
  3156. tx_desc->tx_control_3 |= \
  3157. AR5K_REG_SM(tx_rate##_n, \
  3158. AR5K_4W_TX_DESC_CTL3_XMIT_RATE##_n); \
  3159. }
  3160. _XTX_TRIES(1);
  3161. _XTX_TRIES(2);
  3162. _XTX_TRIES(3);
  3163. #undef _XTX_TRIES
  3164. return 1;
  3165. }
  3166. return 0;
  3167. }
  3168. /*
  3169. * Proccess the tx status descriptor on 5210/5211
  3170. */
  3171. static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *ah,
  3172. struct ath5k_desc *desc)
  3173. {
  3174. struct ath5k_hw_tx_status *tx_status;
  3175. struct ath5k_hw_2w_tx_desc *tx_desc;
  3176. tx_desc = (struct ath5k_hw_2w_tx_desc *)&desc->ds_ctl0;
  3177. tx_status = (struct ath5k_hw_tx_status *)&desc->ds_hw[0];
  3178. /* No frame has been send or error */
  3179. if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
  3180. return -EINPROGRESS;
  3181. /*
  3182. * Get descriptor status
  3183. */
  3184. desc->ds_us.tx.ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
  3185. AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
  3186. desc->ds_us.tx.ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
  3187. AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
  3188. desc->ds_us.tx.ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
  3189. AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
  3190. /*TODO: desc->ds_us.tx.ts_virtcol + test*/
  3191. desc->ds_us.tx.ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
  3192. AR5K_DESC_TX_STATUS1_SEQ_NUM);
  3193. desc->ds_us.tx.ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
  3194. AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
  3195. desc->ds_us.tx.ts_antenna = 1;
  3196. desc->ds_us.tx.ts_status = 0;
  3197. desc->ds_us.tx.ts_rate = AR5K_REG_MS(tx_desc->tx_control_0,
  3198. AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
  3199. if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
  3200. if (tx_status->tx_status_0 &
  3201. AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
  3202. desc->ds_us.tx.ts_status |= AR5K_TXERR_XRETRY;
  3203. if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
  3204. desc->ds_us.tx.ts_status |= AR5K_TXERR_FIFO;
  3205. if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
  3206. desc->ds_us.tx.ts_status |= AR5K_TXERR_FILT;
  3207. }
  3208. return 0;
  3209. }
  3210. /*
  3211. * Proccess a tx descriptor on 5212
  3212. */
  3213. static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *ah,
  3214. struct ath5k_desc *desc)
  3215. {
  3216. struct ath5k_hw_tx_status *tx_status;
  3217. struct ath5k_hw_4w_tx_desc *tx_desc;
  3218. ATH5K_TRACE(ah->ah_sc);
  3219. tx_desc = (struct ath5k_hw_4w_tx_desc *)&desc->ds_ctl0;
  3220. tx_status = (struct ath5k_hw_tx_status *)&desc->ds_hw[2];
  3221. /* No frame has been send or error */
  3222. if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
  3223. return -EINPROGRESS;
  3224. /*
  3225. * Get descriptor status
  3226. */
  3227. desc->ds_us.tx.ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
  3228. AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
  3229. desc->ds_us.tx.ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
  3230. AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
  3231. desc->ds_us.tx.ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
  3232. AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
  3233. desc->ds_us.tx.ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
  3234. AR5K_DESC_TX_STATUS1_SEQ_NUM);
  3235. desc->ds_us.tx.ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
  3236. AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
  3237. desc->ds_us.tx.ts_antenna = (tx_status->tx_status_1 &
  3238. AR5K_DESC_TX_STATUS1_XMIT_ANTENNA) ? 2 : 1;
  3239. desc->ds_us.tx.ts_status = 0;
  3240. switch (AR5K_REG_MS(tx_status->tx_status_1,
  3241. AR5K_DESC_TX_STATUS1_FINAL_TS_INDEX)) {
  3242. case 0:
  3243. desc->ds_us.tx.ts_rate = tx_desc->tx_control_3 &
  3244. AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
  3245. break;
  3246. case 1:
  3247. desc->ds_us.tx.ts_rate = AR5K_REG_MS(tx_desc->tx_control_3,
  3248. AR5K_4W_TX_DESC_CTL3_XMIT_RATE1);
  3249. desc->ds_us.tx.ts_longretry +=AR5K_REG_MS(tx_desc->tx_control_2,
  3250. AR5K_4W_TX_DESC_CTL2_XMIT_TRIES1);
  3251. break;
  3252. case 2:
  3253. desc->ds_us.tx.ts_rate = AR5K_REG_MS(tx_desc->tx_control_3,
  3254. AR5K_4W_TX_DESC_CTL3_XMIT_RATE2);
  3255. desc->ds_us.tx.ts_longretry +=AR5K_REG_MS(tx_desc->tx_control_2,
  3256. AR5K_4W_TX_DESC_CTL2_XMIT_TRIES2);
  3257. break;
  3258. case 3:
  3259. desc->ds_us.tx.ts_rate = AR5K_REG_MS(tx_desc->tx_control_3,
  3260. AR5K_4W_TX_DESC_CTL3_XMIT_RATE3);
  3261. desc->ds_us.tx.ts_longretry +=AR5K_REG_MS(tx_desc->tx_control_2,
  3262. AR5K_4W_TX_DESC_CTL2_XMIT_TRIES3);
  3263. break;
  3264. }
  3265. if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
  3266. if (tx_status->tx_status_0 &
  3267. AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
  3268. desc->ds_us.tx.ts_status |= AR5K_TXERR_XRETRY;
  3269. if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
  3270. desc->ds_us.tx.ts_status |= AR5K_TXERR_FIFO;
  3271. if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
  3272. desc->ds_us.tx.ts_status |= AR5K_TXERR_FILT;
  3273. }
  3274. return 0;
  3275. }
  3276. /*
  3277. * RX Descriptor
  3278. */
  3279. /*
  3280. * Initialize an rx descriptor
  3281. */
  3282. int ath5k_hw_setup_rx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
  3283. u32 size, unsigned int flags)
  3284. {
  3285. struct ath5k_rx_desc *rx_desc;
  3286. ATH5K_TRACE(ah->ah_sc);
  3287. rx_desc = (struct ath5k_rx_desc *)&desc->ds_ctl0;
  3288. /*
  3289. *Clear ds_hw
  3290. * If we don't clean the status descriptor,
  3291. * while scanning we get too many results,
  3292. * most of them virtual, after some secs
  3293. * of scanning system hangs. M.F.
  3294. */
  3295. memset(desc->ds_hw, 0, sizeof(desc->ds_hw));
  3296. /*Initialize rx descriptor*/
  3297. rx_desc->rx_control_0 = 0;
  3298. rx_desc->rx_control_1 = 0;
  3299. /* Setup descriptor */
  3300. rx_desc->rx_control_1 = size & AR5K_DESC_RX_CTL1_BUF_LEN;
  3301. if (unlikely(rx_desc->rx_control_1 != size))
  3302. return -EINVAL;
  3303. if (flags & AR5K_RXDESC_INTREQ)
  3304. rx_desc->rx_control_1 |= AR5K_DESC_RX_CTL1_INTREQ;
  3305. return 0;
  3306. }
  3307. /*
  3308. * Proccess the rx status descriptor on 5210/5211
  3309. */
  3310. static int ath5k_hw_proc_old_rx_status(struct ath5k_hw *ah,
  3311. struct ath5k_desc *desc)
  3312. {
  3313. struct ath5k_hw_old_rx_status *rx_status;
  3314. rx_status = (struct ath5k_hw_old_rx_status *)&desc->ds_hw[0];
  3315. /* No frame received / not ready */
  3316. if (unlikely((rx_status->rx_status_1 & AR5K_OLD_RX_DESC_STATUS1_DONE)
  3317. == 0))
  3318. return -EINPROGRESS;
  3319. /*
  3320. * Frame receive status
  3321. */
  3322. desc->ds_us.rx.rs_datalen = rx_status->rx_status_0 &
  3323. AR5K_OLD_RX_DESC_STATUS0_DATA_LEN;
  3324. desc->ds_us.rx.rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
  3325. AR5K_OLD_RX_DESC_STATUS0_RECEIVE_SIGNAL);
  3326. desc->ds_us.rx.rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
  3327. AR5K_OLD_RX_DESC_STATUS0_RECEIVE_RATE);
  3328. desc->ds_us.rx.rs_antenna = rx_status->rx_status_0 &
  3329. AR5K_OLD_RX_DESC_STATUS0_RECEIVE_ANTENNA;
  3330. desc->ds_us.rx.rs_more = rx_status->rx_status_0 &
  3331. AR5K_OLD_RX_DESC_STATUS0_MORE;
  3332. desc->ds_us.rx.rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
  3333. AR5K_OLD_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
  3334. desc->ds_us.rx.rs_status = 0;
  3335. /*
  3336. * Key table status
  3337. */
  3338. if (rx_status->rx_status_1 & AR5K_OLD_RX_DESC_STATUS1_KEY_INDEX_VALID)
  3339. desc->ds_us.rx.rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
  3340. AR5K_OLD_RX_DESC_STATUS1_KEY_INDEX);
  3341. else
  3342. desc->ds_us.rx.rs_keyix = AR5K_RXKEYIX_INVALID;
  3343. /*
  3344. * Receive/descriptor errors
  3345. */
  3346. if ((rx_status->rx_status_1 & AR5K_OLD_RX_DESC_STATUS1_FRAME_RECEIVE_OK)
  3347. == 0) {
  3348. if (rx_status->rx_status_1 & AR5K_OLD_RX_DESC_STATUS1_CRC_ERROR)
  3349. desc->ds_us.rx.rs_status |= AR5K_RXERR_CRC;
  3350. if (rx_status->rx_status_1 &
  3351. AR5K_OLD_RX_DESC_STATUS1_FIFO_OVERRUN)
  3352. desc->ds_us.rx.rs_status |= AR5K_RXERR_FIFO;
  3353. if (rx_status->rx_status_1 &
  3354. AR5K_OLD_RX_DESC_STATUS1_PHY_ERROR) {
  3355. desc->ds_us.rx.rs_status |= AR5K_RXERR_PHY;
  3356. desc->ds_us.rx.rs_phyerr =
  3357. AR5K_REG_MS(rx_status->rx_status_1,
  3358. AR5K_OLD_RX_DESC_STATUS1_PHY_ERROR);
  3359. }
  3360. if (rx_status->rx_status_1 &
  3361. AR5K_OLD_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
  3362. desc->ds_us.rx.rs_status |= AR5K_RXERR_DECRYPT;
  3363. }
  3364. return 0;
  3365. }
  3366. /*
  3367. * Proccess the rx status descriptor on 5212
  3368. */
  3369. static int ath5k_hw_proc_new_rx_status(struct ath5k_hw *ah,
  3370. struct ath5k_desc *desc)
  3371. {
  3372. struct ath5k_hw_new_rx_status *rx_status;
  3373. struct ath5k_hw_rx_error *rx_err;
  3374. ATH5K_TRACE(ah->ah_sc);
  3375. rx_status = (struct ath5k_hw_new_rx_status *)&desc->ds_hw[0];
  3376. /* Overlay on error */
  3377. rx_err = (struct ath5k_hw_rx_error *)&desc->ds_hw[0];
  3378. /* No frame received / not ready */
  3379. if (unlikely((rx_status->rx_status_1 & AR5K_NEW_RX_DESC_STATUS1_DONE)
  3380. == 0))
  3381. return -EINPROGRESS;
  3382. /*
  3383. * Frame receive status
  3384. */
  3385. desc->ds_us.rx.rs_datalen = rx_status->rx_status_0 &
  3386. AR5K_NEW_RX_DESC_STATUS0_DATA_LEN;
  3387. desc->ds_us.rx.rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
  3388. AR5K_NEW_RX_DESC_STATUS0_RECEIVE_SIGNAL);
  3389. desc->ds_us.rx.rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
  3390. AR5K_NEW_RX_DESC_STATUS0_RECEIVE_RATE);
  3391. desc->ds_us.rx.rs_antenna = rx_status->rx_status_0 &
  3392. AR5K_NEW_RX_DESC_STATUS0_RECEIVE_ANTENNA;
  3393. desc->ds_us.rx.rs_more = rx_status->rx_status_0 &
  3394. AR5K_NEW_RX_DESC_STATUS0_MORE;
  3395. desc->ds_us.rx.rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
  3396. AR5K_NEW_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
  3397. desc->ds_us.rx.rs_status = 0;
  3398. /*
  3399. * Key table status
  3400. */
  3401. if (rx_status->rx_status_1 & AR5K_NEW_RX_DESC_STATUS1_KEY_INDEX_VALID)
  3402. desc->ds_us.rx.rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
  3403. AR5K_NEW_RX_DESC_STATUS1_KEY_INDEX);
  3404. else
  3405. desc->ds_us.rx.rs_keyix = AR5K_RXKEYIX_INVALID;
  3406. /*
  3407. * Receive/descriptor errors
  3408. */
  3409. if ((rx_status->rx_status_1 &
  3410. AR5K_NEW_RX_DESC_STATUS1_FRAME_RECEIVE_OK) == 0) {
  3411. if (rx_status->rx_status_1 & AR5K_NEW_RX_DESC_STATUS1_CRC_ERROR)
  3412. desc->ds_us.rx.rs_status |= AR5K_RXERR_CRC;
  3413. if (rx_status->rx_status_1 &
  3414. AR5K_NEW_RX_DESC_STATUS1_PHY_ERROR) {
  3415. desc->ds_us.rx.rs_status |= AR5K_RXERR_PHY;
  3416. desc->ds_us.rx.rs_phyerr =
  3417. AR5K_REG_MS(rx_err->rx_error_1,
  3418. AR5K_RX_DESC_ERROR1_PHY_ERROR_CODE);
  3419. }
  3420. if (rx_status->rx_status_1 &
  3421. AR5K_NEW_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
  3422. desc->ds_us.rx.rs_status |= AR5K_RXERR_DECRYPT;
  3423. if (rx_status->rx_status_1 & AR5K_NEW_RX_DESC_STATUS1_MIC_ERROR)
  3424. desc->ds_us.rx.rs_status |= AR5K_RXERR_MIC;
  3425. }
  3426. return 0;
  3427. }
  3428. /****************\
  3429. GPIO Functions
  3430. \****************/
  3431. /*
  3432. * Set led state
  3433. */
  3434. void ath5k_hw_set_ledstate(struct ath5k_hw *ah, unsigned int state)
  3435. {
  3436. u32 led;
  3437. /*5210 has different led mode handling*/
  3438. u32 led_5210;
  3439. ATH5K_TRACE(ah->ah_sc);
  3440. /*Reset led status*/
  3441. if (ah->ah_version != AR5K_AR5210)
  3442. AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG,
  3443. AR5K_PCICFG_LEDMODE | AR5K_PCICFG_LED);
  3444. else
  3445. AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_LED);
  3446. /*
  3447. * Some blinking values, define at your wish
  3448. */
  3449. switch (state) {
  3450. case AR5K_LED_SCAN:
  3451. case AR5K_LED_AUTH:
  3452. led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_PEND;
  3453. led_5210 = AR5K_PCICFG_LED_PEND | AR5K_PCICFG_LED_BCTL;
  3454. break;
  3455. case AR5K_LED_INIT:
  3456. led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_NONE;
  3457. led_5210 = AR5K_PCICFG_LED_PEND;
  3458. break;
  3459. case AR5K_LED_ASSOC:
  3460. case AR5K_LED_RUN:
  3461. led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_ASSOC;
  3462. led_5210 = AR5K_PCICFG_LED_ASSOC;
  3463. break;
  3464. default:
  3465. led = AR5K_PCICFG_LEDMODE_PROM | AR5K_PCICFG_LED_NONE;
  3466. led_5210 = AR5K_PCICFG_LED_PEND;
  3467. break;
  3468. }
  3469. /*Write new status to the register*/
  3470. if (ah->ah_version != AR5K_AR5210)
  3471. AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led);
  3472. else
  3473. AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led_5210);
  3474. }
  3475. /*
  3476. * Set GPIO outputs
  3477. */
  3478. int ath5k_hw_set_gpio_output(struct ath5k_hw *ah, u32 gpio)
  3479. {
  3480. ATH5K_TRACE(ah->ah_sc);
  3481. if (gpio > AR5K_NUM_GPIO)
  3482. return -EINVAL;
  3483. ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
  3484. AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_OUT(gpio), AR5K_GPIOCR);
  3485. return 0;
  3486. }
  3487. /*
  3488. * Set GPIO inputs
  3489. */
  3490. int ath5k_hw_set_gpio_input(struct ath5k_hw *ah, u32 gpio)
  3491. {
  3492. ATH5K_TRACE(ah->ah_sc);
  3493. if (gpio > AR5K_NUM_GPIO)
  3494. return -EINVAL;
  3495. ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
  3496. AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_IN(gpio), AR5K_GPIOCR);
  3497. return 0;
  3498. }
  3499. /*
  3500. * Get GPIO state
  3501. */
  3502. u32 ath5k_hw_get_gpio(struct ath5k_hw *ah, u32 gpio)
  3503. {
  3504. ATH5K_TRACE(ah->ah_sc);
  3505. if (gpio > AR5K_NUM_GPIO)
  3506. return 0xffffffff;
  3507. /* GPIO input magic */
  3508. return ((ath5k_hw_reg_read(ah, AR5K_GPIODI) & AR5K_GPIODI_M) >> gpio) &
  3509. 0x1;
  3510. }
  3511. /*
  3512. * Set GPIO state
  3513. */
  3514. int ath5k_hw_set_gpio(struct ath5k_hw *ah, u32 gpio, u32 val)
  3515. {
  3516. u32 data;
  3517. ATH5K_TRACE(ah->ah_sc);
  3518. if (gpio > AR5K_NUM_GPIO)
  3519. return -EINVAL;
  3520. /* GPIO output magic */
  3521. data = ath5k_hw_reg_read(ah, AR5K_GPIODO);
  3522. data &= ~(1 << gpio);
  3523. data |= (val & 1) << gpio;
  3524. ath5k_hw_reg_write(ah, data, AR5K_GPIODO);
  3525. return 0;
  3526. }
  3527. /*
  3528. * Initialize the GPIO interrupt (RFKill switch)
  3529. */
  3530. void ath5k_hw_set_gpio_intr(struct ath5k_hw *ah, unsigned int gpio,
  3531. u32 interrupt_level)
  3532. {
  3533. u32 data;
  3534. ATH5K_TRACE(ah->ah_sc);
  3535. if (gpio > AR5K_NUM_GPIO)
  3536. return;
  3537. /*
  3538. * Set the GPIO interrupt
  3539. */
  3540. data = (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &
  3541. ~(AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_SELH |
  3542. AR5K_GPIOCR_INT_ENA | AR5K_GPIOCR_OUT(gpio))) |
  3543. (AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_ENA);
  3544. ath5k_hw_reg_write(ah, interrupt_level ? data :
  3545. (data | AR5K_GPIOCR_INT_SELH), AR5K_GPIOCR);
  3546. ah->ah_imr |= AR5K_IMR_GPIO;
  3547. /* Enable GPIO interrupts */
  3548. AR5K_REG_ENABLE_BITS(ah, AR5K_PIMR, AR5K_IMR_GPIO);
  3549. }
  3550. /****************\
  3551. Misc functions
  3552. \****************/
  3553. int ath5k_hw_get_capability(struct ath5k_hw *ah,
  3554. enum ath5k_capability_type cap_type,
  3555. u32 capability, u32 *result)
  3556. {
  3557. ATH5K_TRACE(ah->ah_sc);
  3558. switch (cap_type) {
  3559. case AR5K_CAP_NUM_TXQUEUES:
  3560. if (result) {
  3561. if (ah->ah_version == AR5K_AR5210)
  3562. *result = AR5K_NUM_TX_QUEUES_NOQCU;
  3563. else
  3564. *result = AR5K_NUM_TX_QUEUES;
  3565. goto yes;
  3566. }
  3567. case AR5K_CAP_VEOL:
  3568. goto yes;
  3569. case AR5K_CAP_COMPRESSION:
  3570. if (ah->ah_version == AR5K_AR5212)
  3571. goto yes;
  3572. else
  3573. goto no;
  3574. case AR5K_CAP_BURST:
  3575. goto yes;
  3576. case AR5K_CAP_TPC:
  3577. goto yes;
  3578. case AR5K_CAP_BSSIDMASK:
  3579. if (ah->ah_version == AR5K_AR5212)
  3580. goto yes;
  3581. else
  3582. goto no;
  3583. case AR5K_CAP_XR:
  3584. if (ah->ah_version == AR5K_AR5212)
  3585. goto yes;
  3586. else
  3587. goto no;
  3588. default:
  3589. goto no;
  3590. }
  3591. no:
  3592. return -EINVAL;
  3593. yes:
  3594. return 0;
  3595. }
  3596. static int ath5k_hw_enable_pspoll(struct ath5k_hw *ah, u8 *bssid,
  3597. u16 assoc_id)
  3598. {
  3599. ATH5K_TRACE(ah->ah_sc);
  3600. if (ah->ah_version == AR5K_AR5210) {
  3601. AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
  3602. AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);
  3603. return 0;
  3604. }
  3605. return -EIO;
  3606. }
  3607. static int ath5k_hw_disable_pspoll(struct ath5k_hw *ah)
  3608. {
  3609. ATH5K_TRACE(ah->ah_sc);
  3610. if (ah->ah_version == AR5K_AR5210) {
  3611. AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
  3612. AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);
  3613. return 0;
  3614. }
  3615. return -EIO;
  3616. }