hw.c 109 KB

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