hw.c 112 KB

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