hw.c 112 KB

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