hw.c 114 KB

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