hw.c 114 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530
  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. case IEEE80211_IF_TYPE_MESH_POINT:
  2015. pcu_reg |= AR5K_STA_ID1_AP | AR5K_STA_ID1_RTS_DEF_ANTENNA |
  2016. (ah->ah_version == AR5K_AR5210 ?
  2017. AR5K_STA_ID1_NO_PSPOLL : 0);
  2018. beacon_reg |= AR5K_BCR_AP;
  2019. break;
  2020. case IEEE80211_IF_TYPE_STA:
  2021. pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
  2022. (ah->ah_version == AR5K_AR5210 ?
  2023. AR5K_STA_ID1_PWR_SV : 0);
  2024. case IEEE80211_IF_TYPE_MNTR:
  2025. pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
  2026. (ah->ah_version == AR5K_AR5210 ?
  2027. AR5K_STA_ID1_NO_PSPOLL : 0);
  2028. break;
  2029. default:
  2030. return -EINVAL;
  2031. }
  2032. /*
  2033. * Set PCU registers
  2034. */
  2035. low_id = AR5K_LOW_ID(ah->ah_sta_id);
  2036. high_id = AR5K_HIGH_ID(ah->ah_sta_id);
  2037. ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
  2038. ath5k_hw_reg_write(ah, pcu_reg | high_id, AR5K_STA_ID1);
  2039. /*
  2040. * Set Beacon Control Register on 5210
  2041. */
  2042. if (ah->ah_version == AR5K_AR5210)
  2043. ath5k_hw_reg_write(ah, beacon_reg, AR5K_BCR);
  2044. return 0;
  2045. }
  2046. /*
  2047. * BSSID Functions
  2048. */
  2049. /*
  2050. * Get station id
  2051. */
  2052. void ath5k_hw_get_lladdr(struct ath5k_hw *ah, u8 *mac)
  2053. {
  2054. ATH5K_TRACE(ah->ah_sc);
  2055. memcpy(mac, ah->ah_sta_id, ETH_ALEN);
  2056. }
  2057. /*
  2058. * Set station id
  2059. */
  2060. int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac)
  2061. {
  2062. u32 low_id, high_id;
  2063. ATH5K_TRACE(ah->ah_sc);
  2064. /* Set new station ID */
  2065. memcpy(ah->ah_sta_id, mac, ETH_ALEN);
  2066. low_id = AR5K_LOW_ID(mac);
  2067. high_id = AR5K_HIGH_ID(mac);
  2068. ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
  2069. ath5k_hw_reg_write(ah, high_id, AR5K_STA_ID1);
  2070. return 0;
  2071. }
  2072. /*
  2073. * Set BSSID
  2074. */
  2075. void ath5k_hw_set_associd(struct ath5k_hw *ah, const u8 *bssid, u16 assoc_id)
  2076. {
  2077. u32 low_id, high_id;
  2078. u16 tim_offset = 0;
  2079. /*
  2080. * Set simple BSSID mask on 5212
  2081. */
  2082. if (ah->ah_version == AR5K_AR5212) {
  2083. ath5k_hw_reg_write(ah, 0xffffffff, AR5K_BSS_IDM0);
  2084. ath5k_hw_reg_write(ah, 0xffffffff, AR5K_BSS_IDM1);
  2085. }
  2086. /*
  2087. * Set BSSID which triggers the "SME Join" operation
  2088. */
  2089. low_id = AR5K_LOW_ID(bssid);
  2090. high_id = AR5K_HIGH_ID(bssid);
  2091. ath5k_hw_reg_write(ah, low_id, AR5K_BSS_ID0);
  2092. ath5k_hw_reg_write(ah, high_id | ((assoc_id & 0x3fff) <<
  2093. AR5K_BSS_ID1_AID_S), AR5K_BSS_ID1);
  2094. if (assoc_id == 0) {
  2095. ath5k_hw_disable_pspoll(ah);
  2096. return;
  2097. }
  2098. AR5K_REG_WRITE_BITS(ah, AR5K_BEACON, AR5K_BEACON_TIM,
  2099. tim_offset ? tim_offset + 4 : 0);
  2100. ath5k_hw_enable_pspoll(ah, NULL, 0);
  2101. }
  2102. /**
  2103. * ath5k_hw_set_bssid_mask - set common bits we should listen to
  2104. *
  2105. * The bssid_mask is a utility used by AR5212 hardware to inform the hardware
  2106. * which bits of the interface's MAC address should be looked at when trying
  2107. * to decide which packets to ACK. In station mode every bit matters. In AP
  2108. * mode with a single BSS every bit matters as well. In AP mode with
  2109. * multiple BSSes not every bit matters.
  2110. *
  2111. * @ah: the &struct ath5k_hw
  2112. * @mask: the bssid_mask, a u8 array of size ETH_ALEN
  2113. *
  2114. * Note that this is a simple filter and *does* not filter out all
  2115. * relevant frames. Some non-relevant frames will get through, probability
  2116. * jocks are welcomed to compute.
  2117. *
  2118. * When handling multiple BSSes (or VAPs) you can get the BSSID mask by
  2119. * computing the set of:
  2120. *
  2121. * ~ ( MAC XOR BSSID )
  2122. *
  2123. * When you do this you are essentially computing the common bits. Later it
  2124. * is assumed the harware will "and" (&) the BSSID mask with the MAC address
  2125. * to obtain the relevant bits which should match on the destination frame.
  2126. *
  2127. * Simple example: on your card you have have two BSSes you have created with
  2128. * BSSID-01 and BSSID-02. Lets assume BSSID-01 will not use the MAC address.
  2129. * There is another BSSID-03 but you are not part of it. For simplicity's sake,
  2130. * assuming only 4 bits for a mac address and for BSSIDs you can then have:
  2131. *
  2132. * \
  2133. * MAC: 0001 |
  2134. * BSSID-01: 0100 | --> Belongs to us
  2135. * BSSID-02: 1001 |
  2136. * /
  2137. * -------------------
  2138. * BSSID-03: 0110 | --> External
  2139. * -------------------
  2140. *
  2141. * Our bssid_mask would then be:
  2142. *
  2143. * On loop iteration for BSSID-01:
  2144. * ~(0001 ^ 0100) -> ~(0101)
  2145. * -> 1010
  2146. * bssid_mask = 1010
  2147. *
  2148. * On loop iteration for BSSID-02:
  2149. * bssid_mask &= ~(0001 ^ 1001)
  2150. * bssid_mask = (1010) & ~(0001 ^ 1001)
  2151. * bssid_mask = (1010) & ~(1001)
  2152. * bssid_mask = (1010) & (0110)
  2153. * bssid_mask = 0010
  2154. *
  2155. * A bssid_mask of 0010 means "only pay attention to the second least
  2156. * significant bit". This is because its the only bit common
  2157. * amongst the MAC and all BSSIDs we support. To findout what the real
  2158. * common bit is we can simply "&" the bssid_mask now with any BSSID we have
  2159. * or our MAC address (we assume the hardware uses the MAC address).
  2160. *
  2161. * Now, suppose there's an incoming frame for BSSID-03:
  2162. *
  2163. * IFRAME-01: 0110
  2164. *
  2165. * An easy eye-inspeciton of this already should tell you that this frame
  2166. * will not pass our check. This is beacuse the bssid_mask tells the
  2167. * hardware to only look at the second least significant bit and the
  2168. * common bit amongst the MAC and BSSIDs is 0, this frame has the 2nd LSB
  2169. * as 1, which does not match 0.
  2170. *
  2171. * So with IFRAME-01 we *assume* the hardware will do:
  2172. *
  2173. * allow = (IFRAME-01 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
  2174. * --> allow = (0110 & 0010) == (0010 & 0001) ? 1 : 0;
  2175. * --> allow = (0010) == 0000 ? 1 : 0;
  2176. * --> allow = 0
  2177. *
  2178. * Lets now test a frame that should work:
  2179. *
  2180. * IFRAME-02: 0001 (we should allow)
  2181. *
  2182. * allow = (0001 & 1010) == 1010
  2183. *
  2184. * allow = (IFRAME-02 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
  2185. * --> allow = (0001 & 0010) == (0010 & 0001) ? 1 :0;
  2186. * --> allow = (0010) == (0010)
  2187. * --> allow = 1
  2188. *
  2189. * Other examples:
  2190. *
  2191. * IFRAME-03: 0100 --> allowed
  2192. * IFRAME-04: 1001 --> allowed
  2193. * IFRAME-05: 1101 --> allowed but its not for us!!!
  2194. *
  2195. */
  2196. int ath5k_hw_set_bssid_mask(struct ath5k_hw *ah, const u8 *mask)
  2197. {
  2198. u32 low_id, high_id;
  2199. ATH5K_TRACE(ah->ah_sc);
  2200. if (ah->ah_version == AR5K_AR5212) {
  2201. low_id = AR5K_LOW_ID(mask);
  2202. high_id = AR5K_HIGH_ID(mask);
  2203. ath5k_hw_reg_write(ah, low_id, AR5K_BSS_IDM0);
  2204. ath5k_hw_reg_write(ah, high_id, AR5K_BSS_IDM1);
  2205. return 0;
  2206. }
  2207. return -EIO;
  2208. }
  2209. /*
  2210. * Receive start/stop functions
  2211. */
  2212. /*
  2213. * Start receive on PCU
  2214. */
  2215. void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah)
  2216. {
  2217. ATH5K_TRACE(ah->ah_sc);
  2218. AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
  2219. /* TODO: ANI Support */
  2220. }
  2221. /*
  2222. * Stop receive on PCU
  2223. */
  2224. void ath5k_hw_stop_pcu_recv(struct ath5k_hw *ah)
  2225. {
  2226. ATH5K_TRACE(ah->ah_sc);
  2227. AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
  2228. /* TODO: ANI Support */
  2229. }
  2230. /*
  2231. * RX Filter functions
  2232. */
  2233. /*
  2234. * Set multicast filter
  2235. */
  2236. void ath5k_hw_set_mcast_filter(struct ath5k_hw *ah, u32 filter0, u32 filter1)
  2237. {
  2238. ATH5K_TRACE(ah->ah_sc);
  2239. /* Set the multicat filter */
  2240. ath5k_hw_reg_write(ah, filter0, AR5K_MCAST_FILTER0);
  2241. ath5k_hw_reg_write(ah, filter1, AR5K_MCAST_FILTER1);
  2242. }
  2243. /*
  2244. * Set multicast filter by index
  2245. */
  2246. int ath5k_hw_set_mcast_filterindex(struct ath5k_hw *ah, u32 index)
  2247. {
  2248. ATH5K_TRACE(ah->ah_sc);
  2249. if (index >= 64)
  2250. return -EINVAL;
  2251. else if (index >= 32)
  2252. AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER1,
  2253. (1 << (index - 32)));
  2254. else
  2255. AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
  2256. return 0;
  2257. }
  2258. /*
  2259. * Clear Multicast filter by index
  2260. */
  2261. int ath5k_hw_clear_mcast_filter_idx(struct ath5k_hw *ah, u32 index)
  2262. {
  2263. ATH5K_TRACE(ah->ah_sc);
  2264. if (index >= 64)
  2265. return -EINVAL;
  2266. else if (index >= 32)
  2267. AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER1,
  2268. (1 << (index - 32)));
  2269. else
  2270. AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
  2271. return 0;
  2272. }
  2273. /*
  2274. * Get current rx filter
  2275. */
  2276. u32 ath5k_hw_get_rx_filter(struct ath5k_hw *ah)
  2277. {
  2278. u32 data, filter = 0;
  2279. ATH5K_TRACE(ah->ah_sc);
  2280. filter = ath5k_hw_reg_read(ah, AR5K_RX_FILTER);
  2281. /*Radar detection for 5212*/
  2282. if (ah->ah_version == AR5K_AR5212) {
  2283. data = ath5k_hw_reg_read(ah, AR5K_PHY_ERR_FIL);
  2284. if (data & AR5K_PHY_ERR_FIL_RADAR)
  2285. filter |= AR5K_RX_FILTER_RADARERR;
  2286. if (data & (AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK))
  2287. filter |= AR5K_RX_FILTER_PHYERR;
  2288. }
  2289. return filter;
  2290. }
  2291. /*
  2292. * Set rx filter
  2293. */
  2294. void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter)
  2295. {
  2296. u32 data = 0;
  2297. ATH5K_TRACE(ah->ah_sc);
  2298. /* Set PHY error filter register on 5212*/
  2299. if (ah->ah_version == AR5K_AR5212) {
  2300. if (filter & AR5K_RX_FILTER_RADARERR)
  2301. data |= AR5K_PHY_ERR_FIL_RADAR;
  2302. if (filter & AR5K_RX_FILTER_PHYERR)
  2303. data |= AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK;
  2304. }
  2305. /*
  2306. * The AR5210 uses promiscous mode to detect radar activity
  2307. */
  2308. if (ah->ah_version == AR5K_AR5210 &&
  2309. (filter & AR5K_RX_FILTER_RADARERR)) {
  2310. filter &= ~AR5K_RX_FILTER_RADARERR;
  2311. filter |= AR5K_RX_FILTER_PROM;
  2312. }
  2313. /*Zero length DMA*/
  2314. if (data)
  2315. AR5K_REG_ENABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
  2316. else
  2317. AR5K_REG_DISABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
  2318. /*Write RX Filter register*/
  2319. ath5k_hw_reg_write(ah, filter & 0xff, AR5K_RX_FILTER);
  2320. /*Write PHY error filter register on 5212*/
  2321. if (ah->ah_version == AR5K_AR5212)
  2322. ath5k_hw_reg_write(ah, data, AR5K_PHY_ERR_FIL);
  2323. }
  2324. /*
  2325. * Beacon related functions
  2326. */
  2327. /*
  2328. * Get a 32bit TSF
  2329. */
  2330. u32 ath5k_hw_get_tsf32(struct ath5k_hw *ah)
  2331. {
  2332. ATH5K_TRACE(ah->ah_sc);
  2333. return ath5k_hw_reg_read(ah, AR5K_TSF_L32);
  2334. }
  2335. /*
  2336. * Get the full 64bit TSF
  2337. */
  2338. u64 ath5k_hw_get_tsf64(struct ath5k_hw *ah)
  2339. {
  2340. u64 tsf = ath5k_hw_reg_read(ah, AR5K_TSF_U32);
  2341. ATH5K_TRACE(ah->ah_sc);
  2342. return ath5k_hw_reg_read(ah, AR5K_TSF_L32) | (tsf << 32);
  2343. }
  2344. /*
  2345. * Force a TSF reset
  2346. */
  2347. void ath5k_hw_reset_tsf(struct ath5k_hw *ah)
  2348. {
  2349. ATH5K_TRACE(ah->ah_sc);
  2350. AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_RESET_TSF);
  2351. }
  2352. /*
  2353. * Initialize beacon timers
  2354. */
  2355. void ath5k_hw_init_beacon(struct ath5k_hw *ah, u32 next_beacon, u32 interval)
  2356. {
  2357. u32 timer1, timer2, timer3;
  2358. ATH5K_TRACE(ah->ah_sc);
  2359. /*
  2360. * Set the additional timers by mode
  2361. */
  2362. switch (ah->ah_op_mode) {
  2363. case IEEE80211_IF_TYPE_STA:
  2364. if (ah->ah_version == AR5K_AR5210) {
  2365. timer1 = 0xffffffff;
  2366. timer2 = 0xffffffff;
  2367. } else {
  2368. timer1 = 0x0000ffff;
  2369. timer2 = 0x0007ffff;
  2370. }
  2371. break;
  2372. default:
  2373. timer1 = (next_beacon - AR5K_TUNE_DMA_BEACON_RESP) << 3;
  2374. timer2 = (next_beacon - AR5K_TUNE_SW_BEACON_RESP) << 3;
  2375. }
  2376. timer3 = next_beacon + (ah->ah_atim_window ? ah->ah_atim_window : 1);
  2377. /*
  2378. * Set the beacon register and enable all timers.
  2379. * (next beacon, DMA beacon, software beacon, ATIM window time)
  2380. */
  2381. ath5k_hw_reg_write(ah, next_beacon, AR5K_TIMER0);
  2382. ath5k_hw_reg_write(ah, timer1, AR5K_TIMER1);
  2383. ath5k_hw_reg_write(ah, timer2, AR5K_TIMER2);
  2384. ath5k_hw_reg_write(ah, timer3, AR5K_TIMER3);
  2385. ath5k_hw_reg_write(ah, interval & (AR5K_BEACON_PERIOD |
  2386. AR5K_BEACON_RESET_TSF | AR5K_BEACON_ENABLE),
  2387. AR5K_BEACON);
  2388. }
  2389. #if 0
  2390. /*
  2391. * Set beacon timers
  2392. */
  2393. int ath5k_hw_set_beacon_timers(struct ath5k_hw *ah,
  2394. const struct ath5k_beacon_state *state)
  2395. {
  2396. u32 cfp_period, next_cfp, dtim, interval, next_beacon;
  2397. /*
  2398. * TODO: should be changed through *state
  2399. * review struct ath5k_beacon_state struct
  2400. *
  2401. * XXX: These are used for cfp period bellow, are they
  2402. * ok ? Is it O.K. for tsf here to be 0 or should we use
  2403. * get_tsf ?
  2404. */
  2405. u32 dtim_count = 0; /* XXX */
  2406. u32 cfp_count = 0; /* XXX */
  2407. u32 tsf = 0; /* XXX */
  2408. ATH5K_TRACE(ah->ah_sc);
  2409. /* Return on an invalid beacon state */
  2410. if (state->bs_interval < 1)
  2411. return -EINVAL;
  2412. interval = state->bs_interval;
  2413. dtim = state->bs_dtim_period;
  2414. /*
  2415. * PCF support?
  2416. */
  2417. if (state->bs_cfp_period > 0) {
  2418. /*
  2419. * Enable PCF mode and set the CFP
  2420. * (Contention Free Period) and timer registers
  2421. */
  2422. cfp_period = state->bs_cfp_period * state->bs_dtim_period *
  2423. state->bs_interval;
  2424. next_cfp = (cfp_count * state->bs_dtim_period + dtim_count) *
  2425. state->bs_interval;
  2426. AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
  2427. AR5K_STA_ID1_DEFAULT_ANTENNA |
  2428. AR5K_STA_ID1_PCF);
  2429. ath5k_hw_reg_write(ah, cfp_period, AR5K_CFP_PERIOD);
  2430. ath5k_hw_reg_write(ah, state->bs_cfp_max_duration,
  2431. AR5K_CFP_DUR);
  2432. ath5k_hw_reg_write(ah, (tsf + (next_cfp == 0 ? cfp_period :
  2433. next_cfp)) << 3, AR5K_TIMER2);
  2434. } else {
  2435. /* Disable PCF mode */
  2436. AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
  2437. AR5K_STA_ID1_DEFAULT_ANTENNA |
  2438. AR5K_STA_ID1_PCF);
  2439. }
  2440. /*
  2441. * Enable the beacon timer register
  2442. */
  2443. ath5k_hw_reg_write(ah, state->bs_next_beacon, AR5K_TIMER0);
  2444. /*
  2445. * Start the beacon timers
  2446. */
  2447. ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_BEACON) &~
  2448. (AR5K_BEACON_PERIOD | AR5K_BEACON_TIM)) |
  2449. AR5K_REG_SM(state->bs_tim_offset ? state->bs_tim_offset + 4 : 0,
  2450. AR5K_BEACON_TIM) | AR5K_REG_SM(state->bs_interval,
  2451. AR5K_BEACON_PERIOD), AR5K_BEACON);
  2452. /*
  2453. * Write new beacon miss threshold, if it appears to be valid
  2454. * XXX: Figure out right values for min <= bs_bmiss_threshold <= max
  2455. * and return if its not in range. We can test this by reading value and
  2456. * setting value to a largest value and seeing which values register.
  2457. */
  2458. AR5K_REG_WRITE_BITS(ah, AR5K_RSSI_THR, AR5K_RSSI_THR_BMISS,
  2459. state->bs_bmiss_threshold);
  2460. /*
  2461. * Set sleep control register
  2462. * XXX: Didn't find this in 5210 code but since this register
  2463. * exists also in ar5k's 5210 headers i leave it as common code.
  2464. */
  2465. AR5K_REG_WRITE_BITS(ah, AR5K_SLEEP_CTL, AR5K_SLEEP_CTL_SLDUR,
  2466. (state->bs_sleep_duration - 3) << 3);
  2467. /*
  2468. * Set enhanced sleep registers on 5212
  2469. */
  2470. if (ah->ah_version == AR5K_AR5212) {
  2471. if (state->bs_sleep_duration > state->bs_interval &&
  2472. roundup(state->bs_sleep_duration, interval) ==
  2473. state->bs_sleep_duration)
  2474. interval = state->bs_sleep_duration;
  2475. if (state->bs_sleep_duration > dtim && (dtim == 0 ||
  2476. roundup(state->bs_sleep_duration, dtim) ==
  2477. state->bs_sleep_duration))
  2478. dtim = state->bs_sleep_duration;
  2479. if (interval > dtim)
  2480. return -EINVAL;
  2481. next_beacon = interval == dtim ? state->bs_next_dtim :
  2482. state->bs_next_beacon;
  2483. ath5k_hw_reg_write(ah,
  2484. AR5K_REG_SM((state->bs_next_dtim - 3) << 3,
  2485. AR5K_SLEEP0_NEXT_DTIM) |
  2486. AR5K_REG_SM(10, AR5K_SLEEP0_CABTO) |
  2487. AR5K_SLEEP0_ENH_SLEEP_EN |
  2488. AR5K_SLEEP0_ASSUME_DTIM, AR5K_SLEEP0);
  2489. ath5k_hw_reg_write(ah, AR5K_REG_SM((next_beacon - 3) << 3,
  2490. AR5K_SLEEP1_NEXT_TIM) |
  2491. AR5K_REG_SM(10, AR5K_SLEEP1_BEACON_TO), AR5K_SLEEP1);
  2492. ath5k_hw_reg_write(ah,
  2493. AR5K_REG_SM(interval, AR5K_SLEEP2_TIM_PER) |
  2494. AR5K_REG_SM(dtim, AR5K_SLEEP2_DTIM_PER), AR5K_SLEEP2);
  2495. }
  2496. return 0;
  2497. }
  2498. /*
  2499. * Reset beacon timers
  2500. */
  2501. void ath5k_hw_reset_beacon(struct ath5k_hw *ah)
  2502. {
  2503. ATH5K_TRACE(ah->ah_sc);
  2504. /*
  2505. * Disable beacon timer
  2506. */
  2507. ath5k_hw_reg_write(ah, 0, AR5K_TIMER0);
  2508. /*
  2509. * Disable some beacon register values
  2510. */
  2511. AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
  2512. AR5K_STA_ID1_DEFAULT_ANTENNA | AR5K_STA_ID1_PCF);
  2513. ath5k_hw_reg_write(ah, AR5K_BEACON_PERIOD, AR5K_BEACON);
  2514. }
  2515. /*
  2516. * Wait for beacon queue to finish
  2517. */
  2518. int ath5k_hw_beaconq_finish(struct ath5k_hw *ah, unsigned long phys_addr)
  2519. {
  2520. unsigned int i;
  2521. int ret;
  2522. ATH5K_TRACE(ah->ah_sc);
  2523. /* 5210 doesn't have QCU*/
  2524. if (ah->ah_version == AR5K_AR5210) {
  2525. /*
  2526. * Wait for beaconn queue to finish by checking
  2527. * Control Register and Beacon Status Register.
  2528. */
  2529. for (i = AR5K_TUNE_BEACON_INTERVAL / 2; i > 0; i--) {
  2530. if (!(ath5k_hw_reg_read(ah, AR5K_BSR) & AR5K_BSR_TXQ1F)
  2531. ||
  2532. !(ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_BSR_TXQ1F))
  2533. break;
  2534. udelay(10);
  2535. }
  2536. /* Timeout... */
  2537. if (i <= 0) {
  2538. /*
  2539. * Re-schedule the beacon queue
  2540. */
  2541. ath5k_hw_reg_write(ah, phys_addr, AR5K_NOQCU_TXDP1);
  2542. ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
  2543. AR5K_BCR);
  2544. return -EIO;
  2545. }
  2546. ret = 0;
  2547. } else {
  2548. /*5211/5212*/
  2549. ret = ath5k_hw_register_timeout(ah,
  2550. AR5K_QUEUE_STATUS(AR5K_TX_QUEUE_ID_BEACON),
  2551. AR5K_QCU_STS_FRMPENDCNT, 0, false);
  2552. if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, AR5K_TX_QUEUE_ID_BEACON))
  2553. return -EIO;
  2554. }
  2555. return ret;
  2556. }
  2557. #endif
  2558. /*
  2559. * Update mib counters (statistics)
  2560. */
  2561. void ath5k_hw_update_mib_counters(struct ath5k_hw *ah,
  2562. struct ieee80211_low_level_stats *stats)
  2563. {
  2564. ATH5K_TRACE(ah->ah_sc);
  2565. /* Read-And-Clear */
  2566. stats->dot11ACKFailureCount += ath5k_hw_reg_read(ah, AR5K_ACK_FAIL);
  2567. stats->dot11RTSFailureCount += ath5k_hw_reg_read(ah, AR5K_RTS_FAIL);
  2568. stats->dot11RTSSuccessCount += ath5k_hw_reg_read(ah, AR5K_RTS_OK);
  2569. stats->dot11FCSErrorCount += ath5k_hw_reg_read(ah, AR5K_FCS_FAIL);
  2570. /* XXX: Should we use this to track beacon count ?
  2571. * -we read it anyway to clear the register */
  2572. ath5k_hw_reg_read(ah, AR5K_BEACON_CNT);
  2573. /* Reset profile count registers on 5212*/
  2574. if (ah->ah_version == AR5K_AR5212) {
  2575. ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_TX);
  2576. ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RX);
  2577. ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RXCLR);
  2578. ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_CYCLE);
  2579. }
  2580. }
  2581. /** ath5k_hw_set_ack_bitrate - set bitrate for ACKs
  2582. *
  2583. * @ah: the &struct ath5k_hw
  2584. * @high: determines if to use low bit rate or now
  2585. */
  2586. void ath5k_hw_set_ack_bitrate_high(struct ath5k_hw *ah, bool high)
  2587. {
  2588. if (ah->ah_version != AR5K_AR5212)
  2589. return;
  2590. else {
  2591. u32 val = AR5K_STA_ID1_BASE_RATE_11B | AR5K_STA_ID1_ACKCTS_6MB;
  2592. if (high)
  2593. AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1, val);
  2594. else
  2595. AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, val);
  2596. }
  2597. }
  2598. /*
  2599. * ACK/CTS Timeouts
  2600. */
  2601. /*
  2602. * Set ACK timeout on PCU
  2603. */
  2604. int ath5k_hw_set_ack_timeout(struct ath5k_hw *ah, unsigned int timeout)
  2605. {
  2606. ATH5K_TRACE(ah->ah_sc);
  2607. if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_ACK),
  2608. ah->ah_turbo) <= timeout)
  2609. return -EINVAL;
  2610. AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_ACK,
  2611. ath5k_hw_htoclock(timeout, ah->ah_turbo));
  2612. return 0;
  2613. }
  2614. /*
  2615. * Read the ACK timeout from PCU
  2616. */
  2617. unsigned int ath5k_hw_get_ack_timeout(struct ath5k_hw *ah)
  2618. {
  2619. ATH5K_TRACE(ah->ah_sc);
  2620. return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
  2621. AR5K_TIME_OUT), AR5K_TIME_OUT_ACK), ah->ah_turbo);
  2622. }
  2623. /*
  2624. * Set CTS timeout on PCU
  2625. */
  2626. int ath5k_hw_set_cts_timeout(struct ath5k_hw *ah, unsigned int timeout)
  2627. {
  2628. ATH5K_TRACE(ah->ah_sc);
  2629. if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_CTS),
  2630. ah->ah_turbo) <= timeout)
  2631. return -EINVAL;
  2632. AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_CTS,
  2633. ath5k_hw_htoclock(timeout, ah->ah_turbo));
  2634. return 0;
  2635. }
  2636. /*
  2637. * Read CTS timeout from PCU
  2638. */
  2639. unsigned int ath5k_hw_get_cts_timeout(struct ath5k_hw *ah)
  2640. {
  2641. ATH5K_TRACE(ah->ah_sc);
  2642. return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
  2643. AR5K_TIME_OUT), AR5K_TIME_OUT_CTS), ah->ah_turbo);
  2644. }
  2645. /*
  2646. * Key table (WEP) functions
  2647. */
  2648. int ath5k_hw_reset_key(struct ath5k_hw *ah, u16 entry)
  2649. {
  2650. unsigned int i;
  2651. ATH5K_TRACE(ah->ah_sc);
  2652. AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
  2653. for (i = 0; i < AR5K_KEYCACHE_SIZE; i++)
  2654. ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_OFF(entry, i));
  2655. /*
  2656. * Set NULL encryption on AR5212+
  2657. *
  2658. * Note: AR5K_KEYTABLE_TYPE -> AR5K_KEYTABLE_OFF(entry, 5)
  2659. * AR5K_KEYTABLE_TYPE_NULL -> 0x00000007
  2660. *
  2661. * Note2: Windows driver (ndiswrapper) sets this to
  2662. * 0x00000714 instead of 0x00000007
  2663. */
  2664. if (ah->ah_version > AR5K_AR5211)
  2665. ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL,
  2666. AR5K_KEYTABLE_TYPE(entry));
  2667. return 0;
  2668. }
  2669. int ath5k_hw_is_key_valid(struct ath5k_hw *ah, u16 entry)
  2670. {
  2671. ATH5K_TRACE(ah->ah_sc);
  2672. AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
  2673. /* Check the validation flag at the end of the entry */
  2674. return ath5k_hw_reg_read(ah, AR5K_KEYTABLE_MAC1(entry)) &
  2675. AR5K_KEYTABLE_VALID;
  2676. }
  2677. int ath5k_hw_set_key(struct ath5k_hw *ah, u16 entry,
  2678. const struct ieee80211_key_conf *key, const u8 *mac)
  2679. {
  2680. unsigned int i;
  2681. __le32 key_v[5] = {};
  2682. u32 keytype;
  2683. ATH5K_TRACE(ah->ah_sc);
  2684. /* key->keylen comes in from mac80211 in bytes */
  2685. if (key->keylen > AR5K_KEYTABLE_SIZE / 8)
  2686. return -EOPNOTSUPP;
  2687. switch (key->keylen) {
  2688. /* WEP 40-bit = 40-bit entered key + 24 bit IV = 64-bit */
  2689. case 40 / 8:
  2690. memcpy(&key_v[0], key->key, 5);
  2691. keytype = AR5K_KEYTABLE_TYPE_40;
  2692. break;
  2693. /* WEP 104-bit = 104-bit entered key + 24-bit IV = 128-bit */
  2694. case 104 / 8:
  2695. memcpy(&key_v[0], &key->key[0], 6);
  2696. memcpy(&key_v[2], &key->key[6], 6);
  2697. memcpy(&key_v[4], &key->key[12], 1);
  2698. keytype = AR5K_KEYTABLE_TYPE_104;
  2699. break;
  2700. /* WEP 128-bit = 128-bit entered key + 24 bit IV = 152-bit */
  2701. case 128 / 8:
  2702. memcpy(&key_v[0], &key->key[0], 6);
  2703. memcpy(&key_v[2], &key->key[6], 6);
  2704. memcpy(&key_v[4], &key->key[12], 4);
  2705. keytype = AR5K_KEYTABLE_TYPE_128;
  2706. break;
  2707. default:
  2708. return -EINVAL; /* shouldn't happen */
  2709. }
  2710. for (i = 0; i < ARRAY_SIZE(key_v); i++)
  2711. ath5k_hw_reg_write(ah, le32_to_cpu(key_v[i]),
  2712. AR5K_KEYTABLE_OFF(entry, i));
  2713. ath5k_hw_reg_write(ah, keytype, AR5K_KEYTABLE_TYPE(entry));
  2714. return ath5k_hw_set_key_lladdr(ah, entry, mac);
  2715. }
  2716. int ath5k_hw_set_key_lladdr(struct ath5k_hw *ah, u16 entry, const u8 *mac)
  2717. {
  2718. u32 low_id, high_id;
  2719. ATH5K_TRACE(ah->ah_sc);
  2720. /* Invalid entry (key table overflow) */
  2721. AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
  2722. /* MAC may be NULL if it's a broadcast key. In this case no need to
  2723. * to compute AR5K_LOW_ID and AR5K_HIGH_ID as we already know it. */
  2724. if (unlikely(mac == NULL)) {
  2725. low_id = 0xffffffff;
  2726. high_id = 0xffff | AR5K_KEYTABLE_VALID;
  2727. } else {
  2728. low_id = AR5K_LOW_ID(mac);
  2729. high_id = AR5K_HIGH_ID(mac) | AR5K_KEYTABLE_VALID;
  2730. }
  2731. ath5k_hw_reg_write(ah, low_id, AR5K_KEYTABLE_MAC0(entry));
  2732. ath5k_hw_reg_write(ah, high_id, AR5K_KEYTABLE_MAC1(entry));
  2733. return 0;
  2734. }
  2735. /********************************************\
  2736. Queue Control Unit, DFS Control Unit Functions
  2737. \********************************************/
  2738. /*
  2739. * Initialize a transmit queue
  2740. */
  2741. int ath5k_hw_setup_tx_queue(struct ath5k_hw *ah, enum ath5k_tx_queue queue_type,
  2742. struct ath5k_txq_info *queue_info)
  2743. {
  2744. unsigned int queue;
  2745. int ret;
  2746. ATH5K_TRACE(ah->ah_sc);
  2747. /*
  2748. * Get queue by type
  2749. */
  2750. /*5210 only has 2 queues*/
  2751. if (ah->ah_version == AR5K_AR5210) {
  2752. switch (queue_type) {
  2753. case AR5K_TX_QUEUE_DATA:
  2754. queue = AR5K_TX_QUEUE_ID_NOQCU_DATA;
  2755. break;
  2756. case AR5K_TX_QUEUE_BEACON:
  2757. case AR5K_TX_QUEUE_CAB:
  2758. queue = AR5K_TX_QUEUE_ID_NOQCU_BEACON;
  2759. break;
  2760. default:
  2761. return -EINVAL;
  2762. }
  2763. } else {
  2764. switch (queue_type) {
  2765. case AR5K_TX_QUEUE_DATA:
  2766. for (queue = AR5K_TX_QUEUE_ID_DATA_MIN;
  2767. ah->ah_txq[queue].tqi_type !=
  2768. AR5K_TX_QUEUE_INACTIVE; queue++) {
  2769. if (queue > AR5K_TX_QUEUE_ID_DATA_MAX)
  2770. return -EINVAL;
  2771. }
  2772. break;
  2773. case AR5K_TX_QUEUE_UAPSD:
  2774. queue = AR5K_TX_QUEUE_ID_UAPSD;
  2775. break;
  2776. case AR5K_TX_QUEUE_BEACON:
  2777. queue = AR5K_TX_QUEUE_ID_BEACON;
  2778. break;
  2779. case AR5K_TX_QUEUE_CAB:
  2780. queue = AR5K_TX_QUEUE_ID_CAB;
  2781. break;
  2782. case AR5K_TX_QUEUE_XR_DATA:
  2783. if (ah->ah_version != AR5K_AR5212)
  2784. ATH5K_ERR(ah->ah_sc,
  2785. "XR data queues only supported in"
  2786. " 5212!\n");
  2787. queue = AR5K_TX_QUEUE_ID_XR_DATA;
  2788. break;
  2789. default:
  2790. return -EINVAL;
  2791. }
  2792. }
  2793. /*
  2794. * Setup internal queue structure
  2795. */
  2796. memset(&ah->ah_txq[queue], 0, sizeof(struct ath5k_txq_info));
  2797. ah->ah_txq[queue].tqi_type = queue_type;
  2798. if (queue_info != NULL) {
  2799. queue_info->tqi_type = queue_type;
  2800. ret = ath5k_hw_setup_tx_queueprops(ah, queue, queue_info);
  2801. if (ret)
  2802. return ret;
  2803. }
  2804. /*
  2805. * We use ah_txq_status to hold a temp value for
  2806. * the Secondary interrupt mask registers on 5211+
  2807. * check out ath5k_hw_reset_tx_queue
  2808. */
  2809. AR5K_Q_ENABLE_BITS(ah->ah_txq_status, queue);
  2810. return queue;
  2811. }
  2812. /*
  2813. * Setup a transmit queue
  2814. */
  2815. int ath5k_hw_setup_tx_queueprops(struct ath5k_hw *ah, int queue,
  2816. const struct ath5k_txq_info *queue_info)
  2817. {
  2818. ATH5K_TRACE(ah->ah_sc);
  2819. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  2820. if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
  2821. return -EIO;
  2822. memcpy(&ah->ah_txq[queue], queue_info, sizeof(struct ath5k_txq_info));
  2823. /*XXX: Is this supported on 5210 ?*/
  2824. if ((queue_info->tqi_type == AR5K_TX_QUEUE_DATA &&
  2825. ((queue_info->tqi_subtype == AR5K_WME_AC_VI) ||
  2826. (queue_info->tqi_subtype == AR5K_WME_AC_VO))) ||
  2827. queue_info->tqi_type == AR5K_TX_QUEUE_UAPSD)
  2828. ah->ah_txq[queue].tqi_flags |= AR5K_TXQ_FLAG_POST_FR_BKOFF_DIS;
  2829. return 0;
  2830. }
  2831. /*
  2832. * Get properties for a specific transmit queue
  2833. */
  2834. int ath5k_hw_get_tx_queueprops(struct ath5k_hw *ah, int queue,
  2835. struct ath5k_txq_info *queue_info)
  2836. {
  2837. ATH5K_TRACE(ah->ah_sc);
  2838. memcpy(queue_info, &ah->ah_txq[queue], sizeof(struct ath5k_txq_info));
  2839. return 0;
  2840. }
  2841. /*
  2842. * Set a transmit queue inactive
  2843. */
  2844. void ath5k_hw_release_tx_queue(struct ath5k_hw *ah, unsigned int queue)
  2845. {
  2846. ATH5K_TRACE(ah->ah_sc);
  2847. if (WARN_ON(queue >= ah->ah_capabilities.cap_queues.q_tx_num))
  2848. return;
  2849. /* This queue will be skipped in further operations */
  2850. ah->ah_txq[queue].tqi_type = AR5K_TX_QUEUE_INACTIVE;
  2851. /*For SIMR setup*/
  2852. AR5K_Q_DISABLE_BITS(ah->ah_txq_status, queue);
  2853. }
  2854. /*
  2855. * Set DFS params for a transmit queue
  2856. */
  2857. int ath5k_hw_reset_tx_queue(struct ath5k_hw *ah, unsigned int queue)
  2858. {
  2859. u32 cw_min, cw_max, retry_lg, retry_sh;
  2860. struct ath5k_txq_info *tq = &ah->ah_txq[queue];
  2861. ATH5K_TRACE(ah->ah_sc);
  2862. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  2863. tq = &ah->ah_txq[queue];
  2864. if (tq->tqi_type == AR5K_TX_QUEUE_INACTIVE)
  2865. return 0;
  2866. if (ah->ah_version == AR5K_AR5210) {
  2867. /* Only handle data queues, others will be ignored */
  2868. if (tq->tqi_type != AR5K_TX_QUEUE_DATA)
  2869. return 0;
  2870. /* Set Slot time */
  2871. ath5k_hw_reg_write(ah, ah->ah_turbo ?
  2872. AR5K_INIT_SLOT_TIME_TURBO : AR5K_INIT_SLOT_TIME,
  2873. AR5K_SLOT_TIME);
  2874. /* Set ACK_CTS timeout */
  2875. ath5k_hw_reg_write(ah, ah->ah_turbo ?
  2876. AR5K_INIT_ACK_CTS_TIMEOUT_TURBO :
  2877. AR5K_INIT_ACK_CTS_TIMEOUT, AR5K_SLOT_TIME);
  2878. /* Set Transmit Latency */
  2879. ath5k_hw_reg_write(ah, ah->ah_turbo ?
  2880. AR5K_INIT_TRANSMIT_LATENCY_TURBO :
  2881. AR5K_INIT_TRANSMIT_LATENCY, AR5K_USEC_5210);
  2882. /* Set IFS0 */
  2883. if (ah->ah_turbo)
  2884. ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS_TURBO +
  2885. (ah->ah_aifs + tq->tqi_aifs) *
  2886. AR5K_INIT_SLOT_TIME_TURBO) <<
  2887. AR5K_IFS0_DIFS_S) | AR5K_INIT_SIFS_TURBO,
  2888. AR5K_IFS0);
  2889. else
  2890. ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS +
  2891. (ah->ah_aifs + tq->tqi_aifs) *
  2892. AR5K_INIT_SLOT_TIME) << AR5K_IFS0_DIFS_S) |
  2893. AR5K_INIT_SIFS, AR5K_IFS0);
  2894. /* Set IFS1 */
  2895. ath5k_hw_reg_write(ah, ah->ah_turbo ?
  2896. AR5K_INIT_PROTO_TIME_CNTRL_TURBO :
  2897. AR5K_INIT_PROTO_TIME_CNTRL, AR5K_IFS1);
  2898. /* Set AR5K_PHY_SETTLING */
  2899. ath5k_hw_reg_write(ah, ah->ah_turbo ?
  2900. (ath5k_hw_reg_read(ah, AR5K_PHY_SETTLING) & ~0x7F)
  2901. | 0x38 :
  2902. (ath5k_hw_reg_read(ah, AR5K_PHY_SETTLING) & ~0x7F)
  2903. | 0x1C,
  2904. AR5K_PHY_SETTLING);
  2905. /* Set Frame Control Register */
  2906. ath5k_hw_reg_write(ah, ah->ah_turbo ?
  2907. (AR5K_PHY_FRAME_CTL_INI | AR5K_PHY_TURBO_MODE |
  2908. AR5K_PHY_TURBO_SHORT | 0x2020) :
  2909. (AR5K_PHY_FRAME_CTL_INI | 0x1020),
  2910. AR5K_PHY_FRAME_CTL_5210);
  2911. }
  2912. /*
  2913. * Calculate cwmin/max by channel mode
  2914. */
  2915. cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN;
  2916. cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX;
  2917. ah->ah_aifs = AR5K_TUNE_AIFS;
  2918. /*XR is only supported on 5212*/
  2919. if (IS_CHAN_XR(ah->ah_current_channel) &&
  2920. ah->ah_version == AR5K_AR5212) {
  2921. cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_XR;
  2922. cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_XR;
  2923. ah->ah_aifs = AR5K_TUNE_AIFS_XR;
  2924. /*B mode is not supported on 5210*/
  2925. } else if (IS_CHAN_B(ah->ah_current_channel) &&
  2926. ah->ah_version != AR5K_AR5210) {
  2927. cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_11B;
  2928. cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_11B;
  2929. ah->ah_aifs = AR5K_TUNE_AIFS_11B;
  2930. }
  2931. cw_min = 1;
  2932. while (cw_min < ah->ah_cw_min)
  2933. cw_min = (cw_min << 1) | 1;
  2934. cw_min = tq->tqi_cw_min < 0 ? (cw_min >> (-tq->tqi_cw_min)) :
  2935. ((cw_min << tq->tqi_cw_min) + (1 << tq->tqi_cw_min) - 1);
  2936. cw_max = tq->tqi_cw_max < 0 ? (cw_max >> (-tq->tqi_cw_max)) :
  2937. ((cw_max << tq->tqi_cw_max) + (1 << tq->tqi_cw_max) - 1);
  2938. /*
  2939. * Calculate and set retry limits
  2940. */
  2941. if (ah->ah_software_retry) {
  2942. /* XXX Need to test this */
  2943. retry_lg = ah->ah_limit_tx_retries;
  2944. retry_sh = retry_lg = retry_lg > AR5K_DCU_RETRY_LMT_SH_RETRY ?
  2945. AR5K_DCU_RETRY_LMT_SH_RETRY : retry_lg;
  2946. } else {
  2947. retry_lg = AR5K_INIT_LG_RETRY;
  2948. retry_sh = AR5K_INIT_SH_RETRY;
  2949. }
  2950. /*No QCU/DCU [5210]*/
  2951. if (ah->ah_version == AR5K_AR5210) {
  2952. ath5k_hw_reg_write(ah,
  2953. (cw_min << AR5K_NODCU_RETRY_LMT_CW_MIN_S)
  2954. | AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
  2955. AR5K_NODCU_RETRY_LMT_SLG_RETRY)
  2956. | AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
  2957. AR5K_NODCU_RETRY_LMT_SSH_RETRY)
  2958. | AR5K_REG_SM(retry_lg, AR5K_NODCU_RETRY_LMT_LG_RETRY)
  2959. | AR5K_REG_SM(retry_sh, AR5K_NODCU_RETRY_LMT_SH_RETRY),
  2960. AR5K_NODCU_RETRY_LMT);
  2961. } else {
  2962. /*QCU/DCU [5211+]*/
  2963. ath5k_hw_reg_write(ah,
  2964. AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
  2965. AR5K_DCU_RETRY_LMT_SLG_RETRY) |
  2966. AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
  2967. AR5K_DCU_RETRY_LMT_SSH_RETRY) |
  2968. AR5K_REG_SM(retry_lg, AR5K_DCU_RETRY_LMT_LG_RETRY) |
  2969. AR5K_REG_SM(retry_sh, AR5K_DCU_RETRY_LMT_SH_RETRY),
  2970. AR5K_QUEUE_DFS_RETRY_LIMIT(queue));
  2971. /*===Rest is also for QCU/DCU only [5211+]===*/
  2972. /*
  2973. * Set initial content window (cw_min/cw_max)
  2974. * and arbitrated interframe space (aifs)...
  2975. */
  2976. ath5k_hw_reg_write(ah,
  2977. AR5K_REG_SM(cw_min, AR5K_DCU_LCL_IFS_CW_MIN) |
  2978. AR5K_REG_SM(cw_max, AR5K_DCU_LCL_IFS_CW_MAX) |
  2979. AR5K_REG_SM(ah->ah_aifs + tq->tqi_aifs,
  2980. AR5K_DCU_LCL_IFS_AIFS),
  2981. AR5K_QUEUE_DFS_LOCAL_IFS(queue));
  2982. /*
  2983. * Set misc registers
  2984. */
  2985. ath5k_hw_reg_write(ah, AR5K_QCU_MISC_DCU_EARLY,
  2986. AR5K_QUEUE_MISC(queue));
  2987. if (tq->tqi_cbr_period) {
  2988. ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_cbr_period,
  2989. AR5K_QCU_CBRCFG_INTVAL) |
  2990. AR5K_REG_SM(tq->tqi_cbr_overflow_limit,
  2991. AR5K_QCU_CBRCFG_ORN_THRES),
  2992. AR5K_QUEUE_CBRCFG(queue));
  2993. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  2994. AR5K_QCU_MISC_FRSHED_CBR);
  2995. if (tq->tqi_cbr_overflow_limit)
  2996. AR5K_REG_ENABLE_BITS(ah,
  2997. AR5K_QUEUE_MISC(queue),
  2998. AR5K_QCU_MISC_CBR_THRES_ENABLE);
  2999. }
  3000. if (tq->tqi_ready_time)
  3001. ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_ready_time,
  3002. AR5K_QCU_RDYTIMECFG_INTVAL) |
  3003. AR5K_QCU_RDYTIMECFG_ENABLE,
  3004. AR5K_QUEUE_RDYTIMECFG(queue));
  3005. if (tq->tqi_burst_time) {
  3006. ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_burst_time,
  3007. AR5K_DCU_CHAN_TIME_DUR) |
  3008. AR5K_DCU_CHAN_TIME_ENABLE,
  3009. AR5K_QUEUE_DFS_CHANNEL_TIME(queue));
  3010. if (tq->tqi_flags & AR5K_TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)
  3011. AR5K_REG_ENABLE_BITS(ah,
  3012. AR5K_QUEUE_MISC(queue),
  3013. AR5K_QCU_MISC_RDY_VEOL_POLICY);
  3014. }
  3015. if (tq->tqi_flags & AR5K_TXQ_FLAG_BACKOFF_DISABLE)
  3016. ath5k_hw_reg_write(ah, AR5K_DCU_MISC_POST_FR_BKOFF_DIS,
  3017. AR5K_QUEUE_DFS_MISC(queue));
  3018. if (tq->tqi_flags & AR5K_TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE)
  3019. ath5k_hw_reg_write(ah, AR5K_DCU_MISC_BACKOFF_FRAG,
  3020. AR5K_QUEUE_DFS_MISC(queue));
  3021. /*
  3022. * Set registers by queue type
  3023. */
  3024. switch (tq->tqi_type) {
  3025. case AR5K_TX_QUEUE_BEACON:
  3026. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  3027. AR5K_QCU_MISC_FRSHED_DBA_GT |
  3028. AR5K_QCU_MISC_CBREXP_BCN |
  3029. AR5K_QCU_MISC_BCN_ENABLE);
  3030. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
  3031. (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
  3032. AR5K_DCU_MISC_ARBLOCK_CTL_S) |
  3033. AR5K_DCU_MISC_POST_FR_BKOFF_DIS |
  3034. AR5K_DCU_MISC_BCN_ENABLE);
  3035. ath5k_hw_reg_write(ah, ((AR5K_TUNE_BEACON_INTERVAL -
  3036. (AR5K_TUNE_SW_BEACON_RESP -
  3037. AR5K_TUNE_DMA_BEACON_RESP) -
  3038. AR5K_TUNE_ADDITIONAL_SWBA_BACKOFF) * 1024) |
  3039. AR5K_QCU_RDYTIMECFG_ENABLE,
  3040. AR5K_QUEUE_RDYTIMECFG(queue));
  3041. break;
  3042. case AR5K_TX_QUEUE_CAB:
  3043. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  3044. AR5K_QCU_MISC_FRSHED_DBA_GT |
  3045. AR5K_QCU_MISC_CBREXP |
  3046. AR5K_QCU_MISC_CBREXP_BCN);
  3047. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
  3048. (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
  3049. AR5K_DCU_MISC_ARBLOCK_CTL_S));
  3050. break;
  3051. case AR5K_TX_QUEUE_UAPSD:
  3052. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  3053. AR5K_QCU_MISC_CBREXP);
  3054. break;
  3055. case AR5K_TX_QUEUE_DATA:
  3056. default:
  3057. break;
  3058. }
  3059. /*
  3060. * Enable interrupts for this tx queue
  3061. * in the secondary interrupt mask registers
  3062. */
  3063. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXOKINT_ENABLE)
  3064. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txok, queue);
  3065. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXERRINT_ENABLE)
  3066. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txerr, queue);
  3067. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXURNINT_ENABLE)
  3068. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txurn, queue);
  3069. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXDESCINT_ENABLE)
  3070. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txdesc, queue);
  3071. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXEOLINT_ENABLE)
  3072. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txeol, queue);
  3073. /* Update secondary interrupt mask registers */
  3074. ah->ah_txq_imr_txok &= ah->ah_txq_status;
  3075. ah->ah_txq_imr_txerr &= ah->ah_txq_status;
  3076. ah->ah_txq_imr_txurn &= ah->ah_txq_status;
  3077. ah->ah_txq_imr_txdesc &= ah->ah_txq_status;
  3078. ah->ah_txq_imr_txeol &= ah->ah_txq_status;
  3079. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txok,
  3080. AR5K_SIMR0_QCU_TXOK) |
  3081. AR5K_REG_SM(ah->ah_txq_imr_txdesc,
  3082. AR5K_SIMR0_QCU_TXDESC), AR5K_SIMR0);
  3083. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txerr,
  3084. AR5K_SIMR1_QCU_TXERR) |
  3085. AR5K_REG_SM(ah->ah_txq_imr_txeol,
  3086. AR5K_SIMR1_QCU_TXEOL), AR5K_SIMR1);
  3087. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txurn,
  3088. AR5K_SIMR2_QCU_TXURN), AR5K_SIMR2);
  3089. }
  3090. return 0;
  3091. }
  3092. /*
  3093. * Get number of pending frames
  3094. * for a specific queue [5211+]
  3095. */
  3096. u32 ath5k_hw_num_tx_pending(struct ath5k_hw *ah, unsigned int queue) {
  3097. ATH5K_TRACE(ah->ah_sc);
  3098. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  3099. /* Return if queue is declared inactive */
  3100. if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
  3101. return false;
  3102. /* XXX: How about AR5K_CFG_TXCNT ? */
  3103. if (ah->ah_version == AR5K_AR5210)
  3104. return false;
  3105. return AR5K_QUEUE_STATUS(queue) & AR5K_QCU_STS_FRMPENDCNT;
  3106. }
  3107. /*
  3108. * Set slot time
  3109. */
  3110. int ath5k_hw_set_slot_time(struct ath5k_hw *ah, unsigned int slot_time)
  3111. {
  3112. ATH5K_TRACE(ah->ah_sc);
  3113. if (slot_time < AR5K_SLOT_TIME_9 || slot_time > AR5K_SLOT_TIME_MAX)
  3114. return -EINVAL;
  3115. if (ah->ah_version == AR5K_AR5210)
  3116. ath5k_hw_reg_write(ah, ath5k_hw_htoclock(slot_time,
  3117. ah->ah_turbo), AR5K_SLOT_TIME);
  3118. else
  3119. ath5k_hw_reg_write(ah, slot_time, AR5K_DCU_GBL_IFS_SLOT);
  3120. return 0;
  3121. }
  3122. /*
  3123. * Get slot time
  3124. */
  3125. unsigned int ath5k_hw_get_slot_time(struct ath5k_hw *ah)
  3126. {
  3127. ATH5K_TRACE(ah->ah_sc);
  3128. if (ah->ah_version == AR5K_AR5210)
  3129. return ath5k_hw_clocktoh(ath5k_hw_reg_read(ah,
  3130. AR5K_SLOT_TIME) & 0xffff, ah->ah_turbo);
  3131. else
  3132. return ath5k_hw_reg_read(ah, AR5K_DCU_GBL_IFS_SLOT) & 0xffff;
  3133. }
  3134. /******************************\
  3135. Hardware Descriptor Functions
  3136. \******************************/
  3137. /*
  3138. * TX Descriptor
  3139. */
  3140. /*
  3141. * Initialize the 2-word tx descriptor on 5210/5211
  3142. */
  3143. static int
  3144. ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
  3145. unsigned int pkt_len, unsigned int hdr_len, enum ath5k_pkt_type type,
  3146. unsigned int tx_power, unsigned int tx_rate0, unsigned int tx_tries0,
  3147. unsigned int key_index, unsigned int antenna_mode, unsigned int flags,
  3148. unsigned int rtscts_rate, unsigned int rtscts_duration)
  3149. {
  3150. u32 frame_type;
  3151. struct ath5k_hw_2w_tx_ctl *tx_ctl;
  3152. unsigned int frame_len;
  3153. tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
  3154. /*
  3155. * Validate input
  3156. * - Zero retries don't make sense.
  3157. * - A zero rate will put the HW into a mode where it continously sends
  3158. * noise on the channel, so it is important to avoid this.
  3159. */
  3160. if (unlikely(tx_tries0 == 0)) {
  3161. ATH5K_ERR(ah->ah_sc, "zero retries\n");
  3162. WARN_ON(1);
  3163. return -EINVAL;
  3164. }
  3165. if (unlikely(tx_rate0 == 0)) {
  3166. ATH5K_ERR(ah->ah_sc, "zero rate\n");
  3167. WARN_ON(1);
  3168. return -EINVAL;
  3169. }
  3170. /* Clear descriptor */
  3171. memset(&desc->ud.ds_tx5210, 0, sizeof(struct ath5k_hw_5210_tx_desc));
  3172. /* Setup control descriptor */
  3173. /* Verify and set frame length */
  3174. /* remove padding we might have added before */
  3175. frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
  3176. if (frame_len & ~AR5K_2W_TX_DESC_CTL0_FRAME_LEN)
  3177. return -EINVAL;
  3178. tx_ctl->tx_control_0 = frame_len & AR5K_2W_TX_DESC_CTL0_FRAME_LEN;
  3179. /* Verify and set buffer length */
  3180. /* NB: beacon's BufLen must be a multiple of 4 bytes */
  3181. if(type == AR5K_PKT_TYPE_BEACON)
  3182. pkt_len = roundup(pkt_len, 4);
  3183. if (pkt_len & ~AR5K_2W_TX_DESC_CTL1_BUF_LEN)
  3184. return -EINVAL;
  3185. tx_ctl->tx_control_1 = pkt_len & AR5K_2W_TX_DESC_CTL1_BUF_LEN;
  3186. /*
  3187. * Verify and set header length
  3188. * XXX: I only found that on 5210 code, does it work on 5211 ?
  3189. */
  3190. if (ah->ah_version == AR5K_AR5210) {
  3191. if (hdr_len & ~AR5K_2W_TX_DESC_CTL0_HEADER_LEN)
  3192. return -EINVAL;
  3193. tx_ctl->tx_control_0 |=
  3194. AR5K_REG_SM(hdr_len, AR5K_2W_TX_DESC_CTL0_HEADER_LEN);
  3195. }
  3196. /*Diferences between 5210-5211*/
  3197. if (ah->ah_version == AR5K_AR5210) {
  3198. switch (type) {
  3199. case AR5K_PKT_TYPE_BEACON:
  3200. case AR5K_PKT_TYPE_PROBE_RESP:
  3201. frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_NO_DELAY;
  3202. case AR5K_PKT_TYPE_PIFS:
  3203. frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_PIFS;
  3204. default:
  3205. frame_type = type /*<< 2 ?*/;
  3206. }
  3207. tx_ctl->tx_control_0 |=
  3208. AR5K_REG_SM(frame_type, AR5K_2W_TX_DESC_CTL0_FRAME_TYPE) |
  3209. AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
  3210. } else {
  3211. tx_ctl->tx_control_0 |=
  3212. AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE) |
  3213. AR5K_REG_SM(antenna_mode, AR5K_2W_TX_DESC_CTL0_ANT_MODE_XMIT);
  3214. tx_ctl->tx_control_1 |=
  3215. AR5K_REG_SM(type, AR5K_2W_TX_DESC_CTL1_FRAME_TYPE);
  3216. }
  3217. #define _TX_FLAGS(_c, _flag) \
  3218. if (flags & AR5K_TXDESC_##_flag) \
  3219. tx_ctl->tx_control_##_c |= \
  3220. AR5K_2W_TX_DESC_CTL##_c##_##_flag
  3221. _TX_FLAGS(0, CLRDMASK);
  3222. _TX_FLAGS(0, VEOL);
  3223. _TX_FLAGS(0, INTREQ);
  3224. _TX_FLAGS(0, RTSENA);
  3225. _TX_FLAGS(1, NOACK);
  3226. #undef _TX_FLAGS
  3227. /*
  3228. * WEP crap
  3229. */
  3230. if (key_index != AR5K_TXKEYIX_INVALID) {
  3231. tx_ctl->tx_control_0 |=
  3232. AR5K_2W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
  3233. tx_ctl->tx_control_1 |=
  3234. AR5K_REG_SM(key_index,
  3235. AR5K_2W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
  3236. }
  3237. /*
  3238. * RTS/CTS Duration [5210 ?]
  3239. */
  3240. if ((ah->ah_version == AR5K_AR5210) &&
  3241. (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)))
  3242. tx_ctl->tx_control_1 |= rtscts_duration &
  3243. AR5K_2W_TX_DESC_CTL1_RTS_DURATION;
  3244. return 0;
  3245. }
  3246. /*
  3247. * Initialize the 4-word tx descriptor on 5212
  3248. */
  3249. static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *ah,
  3250. struct ath5k_desc *desc, unsigned int pkt_len, unsigned int hdr_len,
  3251. enum ath5k_pkt_type type, unsigned int tx_power, unsigned int tx_rate0,
  3252. unsigned int tx_tries0, unsigned int key_index,
  3253. unsigned int antenna_mode, unsigned int flags, unsigned int rtscts_rate,
  3254. unsigned int rtscts_duration)
  3255. {
  3256. struct ath5k_hw_4w_tx_ctl *tx_ctl;
  3257. unsigned int frame_len;
  3258. ATH5K_TRACE(ah->ah_sc);
  3259. tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
  3260. /*
  3261. * Validate input
  3262. * - Zero retries don't make sense.
  3263. * - A zero rate will put the HW into a mode where it continously sends
  3264. * noise on the channel, so it is important to avoid this.
  3265. */
  3266. if (unlikely(tx_tries0 == 0)) {
  3267. ATH5K_ERR(ah->ah_sc, "zero retries\n");
  3268. WARN_ON(1);
  3269. return -EINVAL;
  3270. }
  3271. if (unlikely(tx_rate0 == 0)) {
  3272. ATH5K_ERR(ah->ah_sc, "zero rate\n");
  3273. WARN_ON(1);
  3274. return -EINVAL;
  3275. }
  3276. /* Clear descriptor */
  3277. memset(&desc->ud.ds_tx5212, 0, sizeof(struct ath5k_hw_5212_tx_desc));
  3278. /* Setup control descriptor */
  3279. /* Verify and set frame length */
  3280. /* remove padding we might have added before */
  3281. frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
  3282. if (frame_len & ~AR5K_4W_TX_DESC_CTL0_FRAME_LEN)
  3283. return -EINVAL;
  3284. tx_ctl->tx_control_0 = frame_len & AR5K_4W_TX_DESC_CTL0_FRAME_LEN;
  3285. /* Verify and set buffer length */
  3286. /* NB: beacon's BufLen must be a multiple of 4 bytes */
  3287. if(type == AR5K_PKT_TYPE_BEACON)
  3288. pkt_len = roundup(pkt_len, 4);
  3289. if (pkt_len & ~AR5K_4W_TX_DESC_CTL1_BUF_LEN)
  3290. return -EINVAL;
  3291. tx_ctl->tx_control_1 = pkt_len & AR5K_4W_TX_DESC_CTL1_BUF_LEN;
  3292. tx_ctl->tx_control_0 |=
  3293. AR5K_REG_SM(tx_power, AR5K_4W_TX_DESC_CTL0_XMIT_POWER) |
  3294. AR5K_REG_SM(antenna_mode, AR5K_4W_TX_DESC_CTL0_ANT_MODE_XMIT);
  3295. tx_ctl->tx_control_1 |= AR5K_REG_SM(type,
  3296. AR5K_4W_TX_DESC_CTL1_FRAME_TYPE);
  3297. tx_ctl->tx_control_2 = AR5K_REG_SM(tx_tries0 + AR5K_TUNE_HWTXTRIES,
  3298. AR5K_4W_TX_DESC_CTL2_XMIT_TRIES0);
  3299. tx_ctl->tx_control_3 = tx_rate0 & AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
  3300. #define _TX_FLAGS(_c, _flag) \
  3301. if (flags & AR5K_TXDESC_##_flag) \
  3302. tx_ctl->tx_control_##_c |= \
  3303. AR5K_4W_TX_DESC_CTL##_c##_##_flag
  3304. _TX_FLAGS(0, CLRDMASK);
  3305. _TX_FLAGS(0, VEOL);
  3306. _TX_FLAGS(0, INTREQ);
  3307. _TX_FLAGS(0, RTSENA);
  3308. _TX_FLAGS(0, CTSENA);
  3309. _TX_FLAGS(1, NOACK);
  3310. #undef _TX_FLAGS
  3311. /*
  3312. * WEP crap
  3313. */
  3314. if (key_index != AR5K_TXKEYIX_INVALID) {
  3315. tx_ctl->tx_control_0 |= AR5K_4W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
  3316. tx_ctl->tx_control_1 |= AR5K_REG_SM(key_index,
  3317. AR5K_4W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
  3318. }
  3319. /*
  3320. * RTS/CTS
  3321. */
  3322. if (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)) {
  3323. if ((flags & AR5K_TXDESC_RTSENA) &&
  3324. (flags & AR5K_TXDESC_CTSENA))
  3325. return -EINVAL;
  3326. tx_ctl->tx_control_2 |= rtscts_duration &
  3327. AR5K_4W_TX_DESC_CTL2_RTS_DURATION;
  3328. tx_ctl->tx_control_3 |= AR5K_REG_SM(rtscts_rate,
  3329. AR5K_4W_TX_DESC_CTL3_RTS_CTS_RATE);
  3330. }
  3331. return 0;
  3332. }
  3333. /*
  3334. * Initialize a 4-word multirate tx descriptor on 5212
  3335. */
  3336. static int
  3337. ath5k_hw_setup_xr_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
  3338. unsigned int tx_rate1, u_int tx_tries1, u_int tx_rate2, u_int tx_tries2,
  3339. unsigned int tx_rate3, u_int tx_tries3)
  3340. {
  3341. struct ath5k_hw_4w_tx_ctl *tx_ctl;
  3342. /*
  3343. * Rates can be 0 as long as the retry count is 0 too.
  3344. * A zero rate and nonzero retry count will put the HW into a mode where
  3345. * it continously sends noise on the channel, so it is important to
  3346. * avoid this.
  3347. */
  3348. if (unlikely((tx_rate1 == 0 && tx_tries1 != 0) ||
  3349. (tx_rate2 == 0 && tx_tries2 != 0) ||
  3350. (tx_rate3 == 0 && tx_tries3 != 0))) {
  3351. ATH5K_ERR(ah->ah_sc, "zero rate\n");
  3352. WARN_ON(1);
  3353. return -EINVAL;
  3354. }
  3355. if (ah->ah_version == AR5K_AR5212) {
  3356. tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
  3357. #define _XTX_TRIES(_n) \
  3358. if (tx_tries##_n) { \
  3359. tx_ctl->tx_control_2 |= \
  3360. AR5K_REG_SM(tx_tries##_n, \
  3361. AR5K_4W_TX_DESC_CTL2_XMIT_TRIES##_n); \
  3362. tx_ctl->tx_control_3 |= \
  3363. AR5K_REG_SM(tx_rate##_n, \
  3364. AR5K_4W_TX_DESC_CTL3_XMIT_RATE##_n); \
  3365. }
  3366. _XTX_TRIES(1);
  3367. _XTX_TRIES(2);
  3368. _XTX_TRIES(3);
  3369. #undef _XTX_TRIES
  3370. return 1;
  3371. }
  3372. return 0;
  3373. }
  3374. /*
  3375. * Proccess the tx status descriptor on 5210/5211
  3376. */
  3377. static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *ah,
  3378. struct ath5k_desc *desc, struct ath5k_tx_status *ts)
  3379. {
  3380. struct ath5k_hw_2w_tx_ctl *tx_ctl;
  3381. struct ath5k_hw_tx_status *tx_status;
  3382. ATH5K_TRACE(ah->ah_sc);
  3383. tx_ctl = &desc->ud.ds_tx5210.tx_ctl;
  3384. tx_status = &desc->ud.ds_tx5210.tx_stat;
  3385. /* No frame has been send or error */
  3386. if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
  3387. return -EINPROGRESS;
  3388. /*
  3389. * Get descriptor status
  3390. */
  3391. ts->ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
  3392. AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
  3393. ts->ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
  3394. AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
  3395. ts->ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
  3396. AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
  3397. /*TODO: ts->ts_virtcol + test*/
  3398. ts->ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
  3399. AR5K_DESC_TX_STATUS1_SEQ_NUM);
  3400. ts->ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
  3401. AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
  3402. ts->ts_antenna = 1;
  3403. ts->ts_status = 0;
  3404. ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_0,
  3405. AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
  3406. if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
  3407. if (tx_status->tx_status_0 &
  3408. AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
  3409. ts->ts_status |= AR5K_TXERR_XRETRY;
  3410. if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
  3411. ts->ts_status |= AR5K_TXERR_FIFO;
  3412. if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
  3413. ts->ts_status |= AR5K_TXERR_FILT;
  3414. }
  3415. return 0;
  3416. }
  3417. /*
  3418. * Proccess a tx descriptor on 5212
  3419. */
  3420. static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *ah,
  3421. struct ath5k_desc *desc, struct ath5k_tx_status *ts)
  3422. {
  3423. struct ath5k_hw_4w_tx_ctl *tx_ctl;
  3424. struct ath5k_hw_tx_status *tx_status;
  3425. ATH5K_TRACE(ah->ah_sc);
  3426. tx_ctl = &desc->ud.ds_tx5212.tx_ctl;
  3427. tx_status = &desc->ud.ds_tx5212.tx_stat;
  3428. /* No frame has been send or error */
  3429. if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
  3430. return -EINPROGRESS;
  3431. /*
  3432. * Get descriptor status
  3433. */
  3434. ts->ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
  3435. AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
  3436. ts->ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
  3437. AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
  3438. ts->ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
  3439. AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
  3440. ts->ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
  3441. AR5K_DESC_TX_STATUS1_SEQ_NUM);
  3442. ts->ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
  3443. AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
  3444. ts->ts_antenna = (tx_status->tx_status_1 &
  3445. AR5K_DESC_TX_STATUS1_XMIT_ANTENNA) ? 2 : 1;
  3446. ts->ts_status = 0;
  3447. switch (AR5K_REG_MS(tx_status->tx_status_1,
  3448. AR5K_DESC_TX_STATUS1_FINAL_TS_INDEX)) {
  3449. case 0:
  3450. ts->ts_rate = tx_ctl->tx_control_3 &
  3451. AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
  3452. break;
  3453. case 1:
  3454. ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_3,
  3455. AR5K_4W_TX_DESC_CTL3_XMIT_RATE1);
  3456. ts->ts_longretry += AR5K_REG_MS(tx_ctl->tx_control_2,
  3457. AR5K_4W_TX_DESC_CTL2_XMIT_TRIES1);
  3458. break;
  3459. case 2:
  3460. ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_3,
  3461. AR5K_4W_TX_DESC_CTL3_XMIT_RATE2);
  3462. ts->ts_longretry += AR5K_REG_MS(tx_ctl->tx_control_2,
  3463. AR5K_4W_TX_DESC_CTL2_XMIT_TRIES2);
  3464. break;
  3465. case 3:
  3466. ts->ts_rate = AR5K_REG_MS(tx_ctl->tx_control_3,
  3467. AR5K_4W_TX_DESC_CTL3_XMIT_RATE3);
  3468. ts->ts_longretry += AR5K_REG_MS(tx_ctl->tx_control_2,
  3469. AR5K_4W_TX_DESC_CTL2_XMIT_TRIES3);
  3470. break;
  3471. }
  3472. if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
  3473. if (tx_status->tx_status_0 &
  3474. AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
  3475. ts->ts_status |= AR5K_TXERR_XRETRY;
  3476. if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
  3477. ts->ts_status |= AR5K_TXERR_FIFO;
  3478. if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
  3479. ts->ts_status |= AR5K_TXERR_FILT;
  3480. }
  3481. return 0;
  3482. }
  3483. /*
  3484. * RX Descriptor
  3485. */
  3486. /*
  3487. * Initialize an rx descriptor
  3488. */
  3489. int ath5k_hw_setup_rx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
  3490. u32 size, unsigned int flags)
  3491. {
  3492. struct ath5k_hw_rx_ctl *rx_ctl;
  3493. ATH5K_TRACE(ah->ah_sc);
  3494. rx_ctl = &desc->ud.ds_rx.rx_ctl;
  3495. /*
  3496. * Clear the descriptor
  3497. * If we don't clean the status descriptor,
  3498. * while scanning we get too many results,
  3499. * most of them virtual, after some secs
  3500. * of scanning system hangs. M.F.
  3501. */
  3502. memset(&desc->ud.ds_rx, 0, sizeof(struct ath5k_hw_all_rx_desc));
  3503. /* Setup descriptor */
  3504. rx_ctl->rx_control_1 = size & AR5K_DESC_RX_CTL1_BUF_LEN;
  3505. if (unlikely(rx_ctl->rx_control_1 != size))
  3506. return -EINVAL;
  3507. if (flags & AR5K_RXDESC_INTREQ)
  3508. rx_ctl->rx_control_1 |= AR5K_DESC_RX_CTL1_INTREQ;
  3509. return 0;
  3510. }
  3511. /*
  3512. * Proccess the rx status descriptor on 5210/5211
  3513. */
  3514. static int ath5k_hw_proc_5210_rx_status(struct ath5k_hw *ah,
  3515. struct ath5k_desc *desc, struct ath5k_rx_status *rs)
  3516. {
  3517. struct ath5k_hw_rx_status *rx_status;
  3518. rx_status = &desc->ud.ds_rx.u.rx_stat;
  3519. /* No frame received / not ready */
  3520. if (unlikely((rx_status->rx_status_1 & AR5K_5210_RX_DESC_STATUS1_DONE)
  3521. == 0))
  3522. return -EINPROGRESS;
  3523. /*
  3524. * Frame receive status
  3525. */
  3526. rs->rs_datalen = rx_status->rx_status_0 &
  3527. AR5K_5210_RX_DESC_STATUS0_DATA_LEN;
  3528. rs->rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
  3529. AR5K_5210_RX_DESC_STATUS0_RECEIVE_SIGNAL);
  3530. rs->rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
  3531. AR5K_5210_RX_DESC_STATUS0_RECEIVE_RATE);
  3532. rs->rs_antenna = rx_status->rx_status_0 &
  3533. AR5K_5210_RX_DESC_STATUS0_RECEIVE_ANTENNA;
  3534. rs->rs_more = rx_status->rx_status_0 &
  3535. AR5K_5210_RX_DESC_STATUS0_MORE;
  3536. /* TODO: this timestamp is 13 bit, later on we assume 15 bit */
  3537. rs->rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
  3538. AR5K_5210_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
  3539. rs->rs_status = 0;
  3540. rs->rs_phyerr = 0;
  3541. /*
  3542. * Key table status
  3543. */
  3544. if (rx_status->rx_status_1 & AR5K_5210_RX_DESC_STATUS1_KEY_INDEX_VALID)
  3545. rs->rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
  3546. AR5K_5210_RX_DESC_STATUS1_KEY_INDEX);
  3547. else
  3548. rs->rs_keyix = AR5K_RXKEYIX_INVALID;
  3549. /*
  3550. * Receive/descriptor errors
  3551. */
  3552. if ((rx_status->rx_status_1 &
  3553. AR5K_5210_RX_DESC_STATUS1_FRAME_RECEIVE_OK) == 0) {
  3554. if (rx_status->rx_status_1 &
  3555. AR5K_5210_RX_DESC_STATUS1_CRC_ERROR)
  3556. rs->rs_status |= AR5K_RXERR_CRC;
  3557. if (rx_status->rx_status_1 &
  3558. AR5K_5210_RX_DESC_STATUS1_FIFO_OVERRUN)
  3559. rs->rs_status |= AR5K_RXERR_FIFO;
  3560. if (rx_status->rx_status_1 &
  3561. AR5K_5210_RX_DESC_STATUS1_PHY_ERROR) {
  3562. rs->rs_status |= AR5K_RXERR_PHY;
  3563. rs->rs_phyerr |= AR5K_REG_MS(rx_status->rx_status_1,
  3564. AR5K_5210_RX_DESC_STATUS1_PHY_ERROR);
  3565. }
  3566. if (rx_status->rx_status_1 &
  3567. AR5K_5210_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
  3568. rs->rs_status |= AR5K_RXERR_DECRYPT;
  3569. }
  3570. return 0;
  3571. }
  3572. /*
  3573. * Proccess the rx status descriptor on 5212
  3574. */
  3575. static int ath5k_hw_proc_5212_rx_status(struct ath5k_hw *ah,
  3576. struct ath5k_desc *desc, struct ath5k_rx_status *rs)
  3577. {
  3578. struct ath5k_hw_rx_status *rx_status;
  3579. struct ath5k_hw_rx_error *rx_err;
  3580. ATH5K_TRACE(ah->ah_sc);
  3581. rx_status = &desc->ud.ds_rx.u.rx_stat;
  3582. /* Overlay on error */
  3583. rx_err = &desc->ud.ds_rx.u.rx_err;
  3584. /* No frame received / not ready */
  3585. if (unlikely((rx_status->rx_status_1 & AR5K_5212_RX_DESC_STATUS1_DONE)
  3586. == 0))
  3587. return -EINPROGRESS;
  3588. /*
  3589. * Frame receive status
  3590. */
  3591. rs->rs_datalen = rx_status->rx_status_0 &
  3592. AR5K_5212_RX_DESC_STATUS0_DATA_LEN;
  3593. rs->rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
  3594. AR5K_5212_RX_DESC_STATUS0_RECEIVE_SIGNAL);
  3595. rs->rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
  3596. AR5K_5212_RX_DESC_STATUS0_RECEIVE_RATE);
  3597. rs->rs_antenna = rx_status->rx_status_0 &
  3598. AR5K_5212_RX_DESC_STATUS0_RECEIVE_ANTENNA;
  3599. rs->rs_more = rx_status->rx_status_0 &
  3600. AR5K_5212_RX_DESC_STATUS0_MORE;
  3601. rs->rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
  3602. AR5K_5212_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
  3603. rs->rs_status = 0;
  3604. rs->rs_phyerr = 0;
  3605. /*
  3606. * Key table status
  3607. */
  3608. if (rx_status->rx_status_1 & AR5K_5212_RX_DESC_STATUS1_KEY_INDEX_VALID)
  3609. rs->rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
  3610. AR5K_5212_RX_DESC_STATUS1_KEY_INDEX);
  3611. else
  3612. rs->rs_keyix = AR5K_RXKEYIX_INVALID;
  3613. /*
  3614. * Receive/descriptor errors
  3615. */
  3616. if ((rx_status->rx_status_1 &
  3617. AR5K_5212_RX_DESC_STATUS1_FRAME_RECEIVE_OK) == 0) {
  3618. if (rx_status->rx_status_1 &
  3619. AR5K_5212_RX_DESC_STATUS1_CRC_ERROR)
  3620. rs->rs_status |= AR5K_RXERR_CRC;
  3621. if (rx_status->rx_status_1 &
  3622. AR5K_5212_RX_DESC_STATUS1_PHY_ERROR) {
  3623. rs->rs_status |= AR5K_RXERR_PHY;
  3624. rs->rs_phyerr |= AR5K_REG_MS(rx_err->rx_error_1,
  3625. AR5K_RX_DESC_ERROR1_PHY_ERROR_CODE);
  3626. }
  3627. if (rx_status->rx_status_1 &
  3628. AR5K_5212_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
  3629. rs->rs_status |= AR5K_RXERR_DECRYPT;
  3630. if (rx_status->rx_status_1 &
  3631. AR5K_5212_RX_DESC_STATUS1_MIC_ERROR)
  3632. rs->rs_status |= AR5K_RXERR_MIC;
  3633. }
  3634. return 0;
  3635. }
  3636. /****************\
  3637. GPIO Functions
  3638. \****************/
  3639. /*
  3640. * Set led state
  3641. */
  3642. void ath5k_hw_set_ledstate(struct ath5k_hw *ah, unsigned int state)
  3643. {
  3644. u32 led;
  3645. /*5210 has different led mode handling*/
  3646. u32 led_5210;
  3647. ATH5K_TRACE(ah->ah_sc);
  3648. /*Reset led status*/
  3649. if (ah->ah_version != AR5K_AR5210)
  3650. AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG,
  3651. AR5K_PCICFG_LEDMODE | AR5K_PCICFG_LED);
  3652. else
  3653. AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_LED);
  3654. /*
  3655. * Some blinking values, define at your wish
  3656. */
  3657. switch (state) {
  3658. case AR5K_LED_SCAN:
  3659. case AR5K_LED_AUTH:
  3660. led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_PEND;
  3661. led_5210 = AR5K_PCICFG_LED_PEND | AR5K_PCICFG_LED_BCTL;
  3662. break;
  3663. case AR5K_LED_INIT:
  3664. led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_NONE;
  3665. led_5210 = AR5K_PCICFG_LED_PEND;
  3666. break;
  3667. case AR5K_LED_ASSOC:
  3668. case AR5K_LED_RUN:
  3669. led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_ASSOC;
  3670. led_5210 = AR5K_PCICFG_LED_ASSOC;
  3671. break;
  3672. default:
  3673. led = AR5K_PCICFG_LEDMODE_PROM | AR5K_PCICFG_LED_NONE;
  3674. led_5210 = AR5K_PCICFG_LED_PEND;
  3675. break;
  3676. }
  3677. /*Write new status to the register*/
  3678. if (ah->ah_version != AR5K_AR5210)
  3679. AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led);
  3680. else
  3681. AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led_5210);
  3682. }
  3683. /*
  3684. * Set GPIO outputs
  3685. */
  3686. int ath5k_hw_set_gpio_output(struct ath5k_hw *ah, u32 gpio)
  3687. {
  3688. ATH5K_TRACE(ah->ah_sc);
  3689. if (gpio > AR5K_NUM_GPIO)
  3690. return -EINVAL;
  3691. ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
  3692. AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_OUT(gpio), AR5K_GPIOCR);
  3693. return 0;
  3694. }
  3695. /*
  3696. * Set GPIO inputs
  3697. */
  3698. int ath5k_hw_set_gpio_input(struct ath5k_hw *ah, u32 gpio)
  3699. {
  3700. ATH5K_TRACE(ah->ah_sc);
  3701. if (gpio > AR5K_NUM_GPIO)
  3702. return -EINVAL;
  3703. ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
  3704. AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_IN(gpio), AR5K_GPIOCR);
  3705. return 0;
  3706. }
  3707. /*
  3708. * Get GPIO state
  3709. */
  3710. u32 ath5k_hw_get_gpio(struct ath5k_hw *ah, u32 gpio)
  3711. {
  3712. ATH5K_TRACE(ah->ah_sc);
  3713. if (gpio > AR5K_NUM_GPIO)
  3714. return 0xffffffff;
  3715. /* GPIO input magic */
  3716. return ((ath5k_hw_reg_read(ah, AR5K_GPIODI) & AR5K_GPIODI_M) >> gpio) &
  3717. 0x1;
  3718. }
  3719. /*
  3720. * Set GPIO state
  3721. */
  3722. int ath5k_hw_set_gpio(struct ath5k_hw *ah, u32 gpio, u32 val)
  3723. {
  3724. u32 data;
  3725. ATH5K_TRACE(ah->ah_sc);
  3726. if (gpio > AR5K_NUM_GPIO)
  3727. return -EINVAL;
  3728. /* GPIO output magic */
  3729. data = ath5k_hw_reg_read(ah, AR5K_GPIODO);
  3730. data &= ~(1 << gpio);
  3731. data |= (val & 1) << gpio;
  3732. ath5k_hw_reg_write(ah, data, AR5K_GPIODO);
  3733. return 0;
  3734. }
  3735. /*
  3736. * Initialize the GPIO interrupt (RFKill switch)
  3737. */
  3738. void ath5k_hw_set_gpio_intr(struct ath5k_hw *ah, unsigned int gpio,
  3739. u32 interrupt_level)
  3740. {
  3741. u32 data;
  3742. ATH5K_TRACE(ah->ah_sc);
  3743. if (gpio > AR5K_NUM_GPIO)
  3744. return;
  3745. /*
  3746. * Set the GPIO interrupt
  3747. */
  3748. data = (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &
  3749. ~(AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_SELH |
  3750. AR5K_GPIOCR_INT_ENA | AR5K_GPIOCR_OUT(gpio))) |
  3751. (AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_ENA);
  3752. ath5k_hw_reg_write(ah, interrupt_level ? data :
  3753. (data | AR5K_GPIOCR_INT_SELH), AR5K_GPIOCR);
  3754. ah->ah_imr |= AR5K_IMR_GPIO;
  3755. /* Enable GPIO interrupts */
  3756. AR5K_REG_ENABLE_BITS(ah, AR5K_PIMR, AR5K_IMR_GPIO);
  3757. }
  3758. /****************\
  3759. Misc functions
  3760. \****************/
  3761. int ath5k_hw_get_capability(struct ath5k_hw *ah,
  3762. enum ath5k_capability_type cap_type,
  3763. u32 capability, u32 *result)
  3764. {
  3765. ATH5K_TRACE(ah->ah_sc);
  3766. switch (cap_type) {
  3767. case AR5K_CAP_NUM_TXQUEUES:
  3768. if (result) {
  3769. if (ah->ah_version == AR5K_AR5210)
  3770. *result = AR5K_NUM_TX_QUEUES_NOQCU;
  3771. else
  3772. *result = AR5K_NUM_TX_QUEUES;
  3773. goto yes;
  3774. }
  3775. case AR5K_CAP_VEOL:
  3776. goto yes;
  3777. case AR5K_CAP_COMPRESSION:
  3778. if (ah->ah_version == AR5K_AR5212)
  3779. goto yes;
  3780. else
  3781. goto no;
  3782. case AR5K_CAP_BURST:
  3783. goto yes;
  3784. case AR5K_CAP_TPC:
  3785. goto yes;
  3786. case AR5K_CAP_BSSIDMASK:
  3787. if (ah->ah_version == AR5K_AR5212)
  3788. goto yes;
  3789. else
  3790. goto no;
  3791. case AR5K_CAP_XR:
  3792. if (ah->ah_version == AR5K_AR5212)
  3793. goto yes;
  3794. else
  3795. goto no;
  3796. default:
  3797. goto no;
  3798. }
  3799. no:
  3800. return -EINVAL;
  3801. yes:
  3802. return 0;
  3803. }
  3804. static int ath5k_hw_enable_pspoll(struct ath5k_hw *ah, u8 *bssid,
  3805. u16 assoc_id)
  3806. {
  3807. ATH5K_TRACE(ah->ah_sc);
  3808. if (ah->ah_version == AR5K_AR5210) {
  3809. AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
  3810. AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);
  3811. return 0;
  3812. }
  3813. return -EIO;
  3814. }
  3815. static int ath5k_hw_disable_pspoll(struct ath5k_hw *ah)
  3816. {
  3817. ATH5K_TRACE(ah->ah_sc);
  3818. if (ah->ah_version == AR5K_AR5210) {
  3819. AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
  3820. AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);
  3821. return 0;
  3822. }
  3823. return -EIO;
  3824. }