hw.c 110 KB

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