hw.c 112 KB

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