iwl4965-base.c 128 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
  4. *
  5. * Portions of this file are derived from the ipw3945 project, as well
  6. * as portions of the ieee80211 subsystem header files.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of version 2 of the GNU General Public License as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  20. *
  21. * The full GNU General Public License is included in this distribution in the
  22. * file called LICENSE.
  23. *
  24. * Contact Information:
  25. * James P. Ketrenos <ipw2100-admin@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/version.h>
  32. #include <linux/init.h>
  33. #include <linux/pci.h>
  34. #include <linux/dma-mapping.h>
  35. #include <linux/delay.h>
  36. #include <linux/skbuff.h>
  37. #include <linux/netdevice.h>
  38. #include <linux/wireless.h>
  39. #include <linux/firmware.h>
  40. #include <linux/etherdevice.h>
  41. #include <linux/if_arp.h>
  42. #include <net/mac80211.h>
  43. #include <asm/div64.h>
  44. #include "iwl-eeprom.h"
  45. #include "iwl-dev.h"
  46. #include "iwl-core.h"
  47. #include "iwl-io.h"
  48. #include "iwl-helpers.h"
  49. #include "iwl-sta.h"
  50. #include "iwl-calib.h"
  51. /******************************************************************************
  52. *
  53. * module boiler plate
  54. *
  55. ******************************************************************************/
  56. /*
  57. * module name, copyright, version, etc.
  58. * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
  59. */
  60. #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux"
  61. #ifdef CONFIG_IWLWIFI_DEBUG
  62. #define VD "d"
  63. #else
  64. #define VD
  65. #endif
  66. #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
  67. #define VS "s"
  68. #else
  69. #define VS
  70. #endif
  71. #define DRV_VERSION IWLWIFI_VERSION VD VS
  72. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  73. MODULE_VERSION(DRV_VERSION);
  74. MODULE_AUTHOR(DRV_COPYRIGHT);
  75. MODULE_LICENSE("GPL");
  76. /*************** STATION TABLE MANAGEMENT ****
  77. * mac80211 should be examined to determine if sta_info is duplicating
  78. * the functionality provided here
  79. */
  80. /**************************************************************/
  81. static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
  82. {
  83. struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
  84. if (hw_decrypt)
  85. rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
  86. else
  87. rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
  88. }
  89. /**
  90. * iwl4965_check_rxon_cmd - validate RXON structure is valid
  91. *
  92. * NOTE: This is really only useful during development and can eventually
  93. * be #ifdef'd out once the driver is stable and folks aren't actively
  94. * making changes
  95. */
  96. static int iwl4965_check_rxon_cmd(struct iwl_rxon_cmd *rxon)
  97. {
  98. int error = 0;
  99. int counter = 1;
  100. if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
  101. error |= le32_to_cpu(rxon->flags &
  102. (RXON_FLG_TGJ_NARROW_BAND_MSK |
  103. RXON_FLG_RADAR_DETECT_MSK));
  104. if (error)
  105. IWL_WARNING("check 24G fields %d | %d\n",
  106. counter++, error);
  107. } else {
  108. error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
  109. 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
  110. if (error)
  111. IWL_WARNING("check 52 fields %d | %d\n",
  112. counter++, error);
  113. error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
  114. if (error)
  115. IWL_WARNING("check 52 CCK %d | %d\n",
  116. counter++, error);
  117. }
  118. error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
  119. if (error)
  120. IWL_WARNING("check mac addr %d | %d\n", counter++, error);
  121. /* make sure basic rates 6Mbps and 1Mbps are supported */
  122. error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
  123. ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
  124. if (error)
  125. IWL_WARNING("check basic rate %d | %d\n", counter++, error);
  126. error |= (le16_to_cpu(rxon->assoc_id) > 2007);
  127. if (error)
  128. IWL_WARNING("check assoc id %d | %d\n", counter++, error);
  129. error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
  130. == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
  131. if (error)
  132. IWL_WARNING("check CCK and short slot %d | %d\n",
  133. counter++, error);
  134. error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
  135. == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
  136. if (error)
  137. IWL_WARNING("check CCK & auto detect %d | %d\n",
  138. counter++, error);
  139. error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
  140. RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
  141. if (error)
  142. IWL_WARNING("check TGG and auto detect %d | %d\n",
  143. counter++, error);
  144. if (error)
  145. IWL_WARNING("Tuning to channel %d\n",
  146. le16_to_cpu(rxon->channel));
  147. if (error) {
  148. IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n");
  149. return -1;
  150. }
  151. return 0;
  152. }
  153. /**
  154. * iwl4965_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
  155. * @priv: staging_rxon is compared to active_rxon
  156. *
  157. * If the RXON structure is changing enough to require a new tune,
  158. * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
  159. * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
  160. */
  161. static int iwl4965_full_rxon_required(struct iwl_priv *priv)
  162. {
  163. /* These items are only settable from the full RXON command */
  164. if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ||
  165. compare_ether_addr(priv->staging_rxon.bssid_addr,
  166. priv->active_rxon.bssid_addr) ||
  167. compare_ether_addr(priv->staging_rxon.node_addr,
  168. priv->active_rxon.node_addr) ||
  169. compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
  170. priv->active_rxon.wlap_bssid_addr) ||
  171. (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
  172. (priv->staging_rxon.channel != priv->active_rxon.channel) ||
  173. (priv->staging_rxon.air_propagation !=
  174. priv->active_rxon.air_propagation) ||
  175. (priv->staging_rxon.ofdm_ht_single_stream_basic_rates !=
  176. priv->active_rxon.ofdm_ht_single_stream_basic_rates) ||
  177. (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates !=
  178. priv->active_rxon.ofdm_ht_dual_stream_basic_rates) ||
  179. (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) ||
  180. (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
  181. return 1;
  182. /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
  183. * be updated with the RXON_ASSOC command -- however only some
  184. * flag transitions are allowed using RXON_ASSOC */
  185. /* Check if we are not switching bands */
  186. if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
  187. (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
  188. return 1;
  189. /* Check if we are switching association toggle */
  190. if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
  191. (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
  192. return 1;
  193. return 0;
  194. }
  195. /**
  196. * iwl4965_commit_rxon - commit staging_rxon to hardware
  197. *
  198. * The RXON command in staging_rxon is committed to the hardware and
  199. * the active_rxon structure is updated with the new data. This
  200. * function correctly transitions out of the RXON_ASSOC_MSK state if
  201. * a HW tune is required based on the RXON structure changes.
  202. */
  203. static int iwl4965_commit_rxon(struct iwl_priv *priv)
  204. {
  205. /* cast away the const for active_rxon in this function */
  206. struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
  207. DECLARE_MAC_BUF(mac);
  208. int rc = 0;
  209. if (!iwl_is_alive(priv))
  210. return -1;
  211. /* always get timestamp with Rx frame */
  212. priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
  213. rc = iwl4965_check_rxon_cmd(&priv->staging_rxon);
  214. if (rc) {
  215. IWL_ERROR("Invalid RXON configuration. Not committing.\n");
  216. return -EINVAL;
  217. }
  218. /* If we don't need to send a full RXON, we can use
  219. * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
  220. * and other flags for the current radio configuration. */
  221. if (!iwl4965_full_rxon_required(priv)) {
  222. rc = iwl_send_rxon_assoc(priv);
  223. if (rc) {
  224. IWL_ERROR("Error setting RXON_ASSOC "
  225. "configuration (%d).\n", rc);
  226. return rc;
  227. }
  228. memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
  229. return 0;
  230. }
  231. /* station table will be cleared */
  232. priv->assoc_station_added = 0;
  233. /* If we are currently associated and the new config requires
  234. * an RXON_ASSOC and the new config wants the associated mask enabled,
  235. * we must clear the associated from the active configuration
  236. * before we apply the new config */
  237. if (iwl_is_associated(priv) &&
  238. (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) {
  239. IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
  240. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  241. rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
  242. sizeof(struct iwl_rxon_cmd),
  243. &priv->active_rxon);
  244. /* If the mask clearing failed then we set
  245. * active_rxon back to what it was previously */
  246. if (rc) {
  247. active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
  248. IWL_ERROR("Error clearing ASSOC_MSK on current "
  249. "configuration (%d).\n", rc);
  250. return rc;
  251. }
  252. }
  253. IWL_DEBUG_INFO("Sending RXON\n"
  254. "* with%s RXON_FILTER_ASSOC_MSK\n"
  255. "* channel = %d\n"
  256. "* bssid = %s\n",
  257. ((priv->staging_rxon.filter_flags &
  258. RXON_FILTER_ASSOC_MSK) ? "" : "out"),
  259. le16_to_cpu(priv->staging_rxon.channel),
  260. print_mac(mac, priv->staging_rxon.bssid_addr));
  261. iwl4965_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
  262. /* Apply the new configuration */
  263. rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
  264. sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
  265. if (rc) {
  266. IWL_ERROR("Error setting new configuration (%d).\n", rc);
  267. return rc;
  268. }
  269. iwl_remove_station(priv, iwl_bcast_addr, 0);
  270. iwlcore_clear_stations_table(priv);
  271. if (!priv->error_recovering)
  272. priv->start_calib = 0;
  273. iwl_init_sensitivity(priv);
  274. memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
  275. /* If we issue a new RXON command which required a tune then we must
  276. * send a new TXPOWER command or we won't be able to Tx any frames */
  277. rc = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
  278. if (rc) {
  279. IWL_ERROR("Error sending TX power (%d).\n", rc);
  280. return rc;
  281. }
  282. /* Add the broadcast address so we can send broadcast frames */
  283. if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) ==
  284. IWL_INVALID_STATION) {
  285. IWL_ERROR("Error adding BROADCAST address for transmit.\n");
  286. return -EIO;
  287. }
  288. /* If we have set the ASSOC_MSK and we are in BSS mode then
  289. * add the IWL_AP_ID to the station rate table */
  290. if (iwl_is_associated(priv) &&
  291. (priv->iw_mode == IEEE80211_IF_TYPE_STA)) {
  292. if (iwl_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1)
  293. == IWL_INVALID_STATION) {
  294. IWL_ERROR("Error adding AP address for transmit.\n");
  295. return -EIO;
  296. }
  297. priv->assoc_station_added = 1;
  298. if (priv->default_wep_key &&
  299. iwl_send_static_wepkey_cmd(priv, 0))
  300. IWL_ERROR("Could not send WEP static key.\n");
  301. }
  302. return 0;
  303. }
  304. void iwl4965_update_chain_flags(struct iwl_priv *priv)
  305. {
  306. iwl_set_rxon_chain(priv);
  307. iwl4965_commit_rxon(priv);
  308. }
  309. static int iwl4965_send_bt_config(struct iwl_priv *priv)
  310. {
  311. struct iwl4965_bt_cmd bt_cmd = {
  312. .flags = 3,
  313. .lead_time = 0xAA,
  314. .max_kill = 1,
  315. .kill_ack_mask = 0,
  316. .kill_cts_mask = 0,
  317. };
  318. return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  319. sizeof(struct iwl4965_bt_cmd), &bt_cmd);
  320. }
  321. /*
  322. * CARD_STATE_CMD
  323. *
  324. * Use: Sets the device's internal card state to enable, disable, or halt
  325. *
  326. * When in the 'enable' state the card operates as normal.
  327. * When in the 'disable' state, the card enters into a low power mode.
  328. * When in the 'halt' state, the card is shut down and must be fully
  329. * restarted to come back on.
  330. */
  331. static int iwl4965_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag)
  332. {
  333. struct iwl_host_cmd cmd = {
  334. .id = REPLY_CARD_STATE_CMD,
  335. .len = sizeof(u32),
  336. .data = &flags,
  337. .meta.flags = meta_flag,
  338. };
  339. return iwl_send_cmd(priv, &cmd);
  340. }
  341. static void iwl_clear_free_frames(struct iwl_priv *priv)
  342. {
  343. struct list_head *element;
  344. IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
  345. priv->frames_count);
  346. while (!list_empty(&priv->free_frames)) {
  347. element = priv->free_frames.next;
  348. list_del(element);
  349. kfree(list_entry(element, struct iwl_frame, list));
  350. priv->frames_count--;
  351. }
  352. if (priv->frames_count) {
  353. IWL_WARNING("%d frames still in use. Did we lose one?\n",
  354. priv->frames_count);
  355. priv->frames_count = 0;
  356. }
  357. }
  358. static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
  359. {
  360. struct iwl_frame *frame;
  361. struct list_head *element;
  362. if (list_empty(&priv->free_frames)) {
  363. frame = kzalloc(sizeof(*frame), GFP_KERNEL);
  364. if (!frame) {
  365. IWL_ERROR("Could not allocate frame!\n");
  366. return NULL;
  367. }
  368. priv->frames_count++;
  369. return frame;
  370. }
  371. element = priv->free_frames.next;
  372. list_del(element);
  373. return list_entry(element, struct iwl_frame, list);
  374. }
  375. static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
  376. {
  377. memset(frame, 0, sizeof(*frame));
  378. list_add(&frame->list, &priv->free_frames);
  379. }
  380. unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv,
  381. struct ieee80211_hdr *hdr,
  382. const u8 *dest, int left)
  383. {
  384. if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
  385. ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) &&
  386. (priv->iw_mode != IEEE80211_IF_TYPE_AP)))
  387. return 0;
  388. if (priv->ibss_beacon->len > left)
  389. return 0;
  390. memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
  391. return priv->ibss_beacon->len;
  392. }
  393. static u8 iwl4965_rate_get_lowest_plcp(struct iwl_priv *priv)
  394. {
  395. int i;
  396. int rate_mask;
  397. /* Set rate mask*/
  398. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
  399. rate_mask = priv->active_rate_basic & 0xF;
  400. else
  401. rate_mask = priv->active_rate_basic & 0xFF0;
  402. /* Find lowest valid rate */
  403. for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
  404. i = iwl_rates[i].next_ieee) {
  405. if (rate_mask & (1 << i))
  406. return iwl_rates[i].plcp;
  407. }
  408. /* No valid rate was found. Assign the lowest one */
  409. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
  410. return IWL_RATE_1M_PLCP;
  411. else
  412. return IWL_RATE_6M_PLCP;
  413. }
  414. static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
  415. {
  416. struct iwl_frame *frame;
  417. unsigned int frame_size;
  418. int rc;
  419. u8 rate;
  420. frame = iwl_get_free_frame(priv);
  421. if (!frame) {
  422. IWL_ERROR("Could not obtain free frame buffer for beacon "
  423. "command.\n");
  424. return -ENOMEM;
  425. }
  426. rate = iwl4965_rate_get_lowest_plcp(priv);
  427. frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate);
  428. rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
  429. &frame->u.cmd[0]);
  430. iwl_free_frame(priv, frame);
  431. return rc;
  432. }
  433. /******************************************************************************
  434. *
  435. * Misc. internal state and helper functions
  436. *
  437. ******************************************************************************/
  438. static void iwl4965_ht_conf(struct iwl_priv *priv,
  439. struct ieee80211_bss_conf *bss_conf)
  440. {
  441. struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf;
  442. struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf;
  443. struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
  444. IWL_DEBUG_MAC80211("enter: \n");
  445. iwl_conf->is_ht = bss_conf->assoc_ht;
  446. if (!iwl_conf->is_ht)
  447. return;
  448. priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
  449. if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
  450. iwl_conf->sgf |= HT_SHORT_GI_20MHZ;
  451. if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
  452. iwl_conf->sgf |= HT_SHORT_GI_40MHZ;
  453. iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
  454. iwl_conf->max_amsdu_size =
  455. !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
  456. iwl_conf->supported_chan_width =
  457. !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH);
  458. iwl_conf->extension_chan_offset =
  459. ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET;
  460. /* If no above or below channel supplied disable FAT channel */
  461. if (iwl_conf->extension_chan_offset != IEEE80211_HT_IE_CHA_SEC_ABOVE &&
  462. iwl_conf->extension_chan_offset != IEEE80211_HT_IE_CHA_SEC_BELOW) {
  463. iwl_conf->extension_chan_offset = IEEE80211_HT_IE_CHA_SEC_NONE;
  464. iwl_conf->supported_chan_width = 0;
  465. }
  466. iwl_conf->tx_mimo_ps_mode =
  467. (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
  468. memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16);
  469. iwl_conf->control_channel = ht_bss_conf->primary_channel;
  470. iwl_conf->tx_chan_width =
  471. !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH);
  472. iwl_conf->ht_protection =
  473. ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION;
  474. iwl_conf->non_GF_STA_present =
  475. !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT);
  476. IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel);
  477. IWL_DEBUG_MAC80211("leave\n");
  478. }
  479. /*
  480. * QoS support
  481. */
  482. static int iwl4965_send_qos_params_command(struct iwl_priv *priv,
  483. struct iwl4965_qosparam_cmd *qos)
  484. {
  485. return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM,
  486. sizeof(struct iwl4965_qosparam_cmd), qos);
  487. }
  488. static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force)
  489. {
  490. unsigned long flags;
  491. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  492. return;
  493. if (!priv->qos_data.qos_enable)
  494. return;
  495. spin_lock_irqsave(&priv->lock, flags);
  496. priv->qos_data.def_qos_parm.qos_flags = 0;
  497. if (priv->qos_data.qos_cap.q_AP.queue_request &&
  498. !priv->qos_data.qos_cap.q_AP.txop_request)
  499. priv->qos_data.def_qos_parm.qos_flags |=
  500. QOS_PARAM_FLG_TXOP_TYPE_MSK;
  501. if (priv->qos_data.qos_active)
  502. priv->qos_data.def_qos_parm.qos_flags |=
  503. QOS_PARAM_FLG_UPDATE_EDCA_MSK;
  504. if (priv->current_ht_config.is_ht)
  505. priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
  506. spin_unlock_irqrestore(&priv->lock, flags);
  507. if (force || iwl_is_associated(priv)) {
  508. IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
  509. priv->qos_data.qos_active,
  510. priv->qos_data.def_qos_parm.qos_flags);
  511. iwl4965_send_qos_params_command(priv,
  512. &(priv->qos_data.def_qos_parm));
  513. }
  514. }
  515. int iwl4965_is_network_packet(struct iwl_priv *priv, struct ieee80211_hdr *header)
  516. {
  517. /* Filter incoming packets to determine if they are targeted toward
  518. * this network, discarding packets coming from ourselves */
  519. switch (priv->iw_mode) {
  520. case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */
  521. /* packets from our adapter are dropped (echo) */
  522. if (!compare_ether_addr(header->addr2, priv->mac_addr))
  523. return 0;
  524. /* {broad,multi}cast packets to our IBSS go through */
  525. if (is_multicast_ether_addr(header->addr1))
  526. return !compare_ether_addr(header->addr3, priv->bssid);
  527. /* packets to our adapter go through */
  528. return !compare_ether_addr(header->addr1, priv->mac_addr);
  529. case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */
  530. /* packets from our adapter are dropped (echo) */
  531. if (!compare_ether_addr(header->addr3, priv->mac_addr))
  532. return 0;
  533. /* {broad,multi}cast packets to our BSS go through */
  534. if (is_multicast_ether_addr(header->addr1))
  535. return !compare_ether_addr(header->addr2, priv->bssid);
  536. /* packets to our adapter go through */
  537. return !compare_ether_addr(header->addr1, priv->mac_addr);
  538. default:
  539. break;
  540. }
  541. return 1;
  542. }
  543. static void iwl4965_sequence_reset(struct iwl_priv *priv)
  544. {
  545. /* Reset ieee stats */
  546. /* We don't reset the net_device_stats (ieee->stats) on
  547. * re-association */
  548. priv->last_seq_num = -1;
  549. priv->last_frag_num = -1;
  550. priv->last_packet_time = 0;
  551. iwl_scan_cancel(priv);
  552. }
  553. #define MAX_UCODE_BEACON_INTERVAL 4096
  554. #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
  555. static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val)
  556. {
  557. u16 new_val = 0;
  558. u16 beacon_factor = 0;
  559. beacon_factor =
  560. (beacon_val + MAX_UCODE_BEACON_INTERVAL)
  561. / MAX_UCODE_BEACON_INTERVAL;
  562. new_val = beacon_val / beacon_factor;
  563. return cpu_to_le16(new_val);
  564. }
  565. static void iwl4965_setup_rxon_timing(struct iwl_priv *priv)
  566. {
  567. u64 interval_tm_unit;
  568. u64 tsf, result;
  569. unsigned long flags;
  570. struct ieee80211_conf *conf = NULL;
  571. u16 beacon_int = 0;
  572. conf = ieee80211_get_hw_conf(priv->hw);
  573. spin_lock_irqsave(&priv->lock, flags);
  574. priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp >> 32);
  575. priv->rxon_timing.timestamp.dw[0] =
  576. cpu_to_le32(priv->timestamp & 0xFFFFFFFF);
  577. priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
  578. tsf = priv->timestamp;
  579. beacon_int = priv->beacon_int;
  580. spin_unlock_irqrestore(&priv->lock, flags);
  581. if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
  582. if (beacon_int == 0) {
  583. priv->rxon_timing.beacon_interval = cpu_to_le16(100);
  584. priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
  585. } else {
  586. priv->rxon_timing.beacon_interval =
  587. cpu_to_le16(beacon_int);
  588. priv->rxon_timing.beacon_interval =
  589. iwl4965_adjust_beacon_interval(
  590. le16_to_cpu(priv->rxon_timing.beacon_interval));
  591. }
  592. priv->rxon_timing.atim_window = 0;
  593. } else {
  594. priv->rxon_timing.beacon_interval =
  595. iwl4965_adjust_beacon_interval(conf->beacon_int);
  596. /* TODO: we need to get atim_window from upper stack
  597. * for now we set to 0 */
  598. priv->rxon_timing.atim_window = 0;
  599. }
  600. interval_tm_unit =
  601. (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
  602. result = do_div(tsf, interval_tm_unit);
  603. priv->rxon_timing.beacon_init_val =
  604. cpu_to_le32((u32) ((u64) interval_tm_unit - result));
  605. IWL_DEBUG_ASSOC
  606. ("beacon interval %d beacon timer %d beacon tim %d\n",
  607. le16_to_cpu(priv->rxon_timing.beacon_interval),
  608. le32_to_cpu(priv->rxon_timing.beacon_init_val),
  609. le16_to_cpu(priv->rxon_timing.atim_window));
  610. }
  611. static void iwl_set_flags_for_band(struct iwl_priv *priv,
  612. enum ieee80211_band band)
  613. {
  614. if (band == IEEE80211_BAND_5GHZ) {
  615. priv->staging_rxon.flags &=
  616. ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
  617. | RXON_FLG_CCK_MSK);
  618. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  619. } else {
  620. /* Copied from iwl4965_post_associate() */
  621. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
  622. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  623. else
  624. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  625. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  626. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  627. priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
  628. priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
  629. priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
  630. }
  631. }
  632. /*
  633. * initialize rxon structure with default values from eeprom
  634. */
  635. static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
  636. {
  637. const struct iwl_channel_info *ch_info;
  638. memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
  639. switch (priv->iw_mode) {
  640. case IEEE80211_IF_TYPE_AP:
  641. priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
  642. break;
  643. case IEEE80211_IF_TYPE_STA:
  644. priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
  645. priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
  646. break;
  647. case IEEE80211_IF_TYPE_IBSS:
  648. priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
  649. priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
  650. priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
  651. RXON_FILTER_ACCEPT_GRP_MSK;
  652. break;
  653. case IEEE80211_IF_TYPE_MNTR:
  654. priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
  655. priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
  656. RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
  657. break;
  658. default:
  659. IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode);
  660. break;
  661. }
  662. #if 0
  663. /* TODO: Figure out when short_preamble would be set and cache from
  664. * that */
  665. if (!hw_to_local(priv->hw)->short_preamble)
  666. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  667. else
  668. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  669. #endif
  670. ch_info = iwl_get_channel_info(priv, priv->band,
  671. le16_to_cpu(priv->staging_rxon.channel));
  672. if (!ch_info)
  673. ch_info = &priv->channel_info[0];
  674. /*
  675. * in some case A channels are all non IBSS
  676. * in this case force B/G channel
  677. */
  678. if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
  679. !(is_channel_ibss(ch_info)))
  680. ch_info = &priv->channel_info[0];
  681. priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
  682. priv->band = ch_info->band;
  683. iwl_set_flags_for_band(priv, priv->band);
  684. priv->staging_rxon.ofdm_basic_rates =
  685. (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  686. priv->staging_rxon.cck_basic_rates =
  687. (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  688. priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
  689. RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
  690. memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  691. memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
  692. priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
  693. priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
  694. iwl_set_rxon_chain(priv);
  695. }
  696. static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
  697. {
  698. priv->iw_mode = mode;
  699. /* init channel/phymode to values given at driver init */
  700. iwl_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
  701. iwl4965_connection_init_rx_config(priv);
  702. memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  703. iwlcore_clear_stations_table(priv);
  704. /* dont commit rxon if rf-kill is on*/
  705. if (!iwl_is_ready_rf(priv))
  706. return -EAGAIN;
  707. cancel_delayed_work(&priv->scan_check);
  708. if (iwl_scan_cancel_timeout(priv, 100)) {
  709. IWL_WARNING("Aborted scan still in progress after 100ms\n");
  710. IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
  711. return -EAGAIN;
  712. }
  713. iwl4965_commit_rxon(priv);
  714. return 0;
  715. }
  716. static void iwl4965_set_rate(struct iwl_priv *priv)
  717. {
  718. const struct ieee80211_supported_band *hw = NULL;
  719. struct ieee80211_rate *rate;
  720. int i;
  721. hw = iwl_get_hw_mode(priv, priv->band);
  722. if (!hw) {
  723. IWL_ERROR("Failed to set rate: unable to get hw mode\n");
  724. return;
  725. }
  726. priv->active_rate = 0;
  727. priv->active_rate_basic = 0;
  728. for (i = 0; i < hw->n_bitrates; i++) {
  729. rate = &(hw->bitrates[i]);
  730. if (rate->hw_value < IWL_RATE_COUNT)
  731. priv->active_rate |= (1 << rate->hw_value);
  732. }
  733. IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
  734. priv->active_rate, priv->active_rate_basic);
  735. /*
  736. * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
  737. * otherwise set it to the default of all CCK rates and 6, 12, 24 for
  738. * OFDM
  739. */
  740. if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
  741. priv->staging_rxon.cck_basic_rates =
  742. ((priv->active_rate_basic &
  743. IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
  744. else
  745. priv->staging_rxon.cck_basic_rates =
  746. (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  747. if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
  748. priv->staging_rxon.ofdm_basic_rates =
  749. ((priv->active_rate_basic &
  750. (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
  751. IWL_FIRST_OFDM_RATE) & 0xFF;
  752. else
  753. priv->staging_rxon.ofdm_basic_rates =
  754. (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  755. }
  756. int iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
  757. {
  758. unsigned long flags;
  759. if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
  760. return 0;
  761. IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
  762. disable_radio ? "OFF" : "ON");
  763. if (disable_radio) {
  764. iwl_scan_cancel(priv);
  765. /* FIXME: This is a workaround for AP */
  766. if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
  767. spin_lock_irqsave(&priv->lock, flags);
  768. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  769. CSR_UCODE_SW_BIT_RFKILL);
  770. spin_unlock_irqrestore(&priv->lock, flags);
  771. /* call the host command only if no hw rf-kill set */
  772. if (!test_bit(STATUS_RF_KILL_HW, &priv->status) &&
  773. iwl_is_ready(priv))
  774. iwl4965_send_card_state(priv,
  775. CARD_STATE_CMD_DISABLE,
  776. 0);
  777. set_bit(STATUS_RF_KILL_SW, &priv->status);
  778. /* make sure mac80211 stop sending Tx frame */
  779. if (priv->mac80211_registered)
  780. ieee80211_stop_queues(priv->hw);
  781. }
  782. return 0;
  783. }
  784. spin_lock_irqsave(&priv->lock, flags);
  785. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  786. clear_bit(STATUS_RF_KILL_SW, &priv->status);
  787. spin_unlock_irqrestore(&priv->lock, flags);
  788. /* wake up ucode */
  789. msleep(10);
  790. spin_lock_irqsave(&priv->lock, flags);
  791. iwl_read32(priv, CSR_UCODE_DRV_GP1);
  792. if (!iwl_grab_nic_access(priv))
  793. iwl_release_nic_access(priv);
  794. spin_unlock_irqrestore(&priv->lock, flags);
  795. if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
  796. IWL_DEBUG_RF_KILL("Can not turn radio back on - "
  797. "disabled by HW switch\n");
  798. return 0;
  799. }
  800. if (priv->is_open)
  801. queue_work(priv->workqueue, &priv->restart);
  802. return 1;
  803. }
  804. #define IWL_PACKET_RETRY_TIME HZ
  805. int iwl4965_is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header)
  806. {
  807. u16 sc = le16_to_cpu(header->seq_ctrl);
  808. u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
  809. u16 frag = sc & IEEE80211_SCTL_FRAG;
  810. u16 *last_seq, *last_frag;
  811. unsigned long *last_time;
  812. switch (priv->iw_mode) {
  813. case IEEE80211_IF_TYPE_IBSS:{
  814. struct list_head *p;
  815. struct iwl4965_ibss_seq *entry = NULL;
  816. u8 *mac = header->addr2;
  817. int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1);
  818. __list_for_each(p, &priv->ibss_mac_hash[index]) {
  819. entry = list_entry(p, struct iwl4965_ibss_seq, list);
  820. if (!compare_ether_addr(entry->mac, mac))
  821. break;
  822. }
  823. if (p == &priv->ibss_mac_hash[index]) {
  824. entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
  825. if (!entry) {
  826. IWL_ERROR("Cannot malloc new mac entry\n");
  827. return 0;
  828. }
  829. memcpy(entry->mac, mac, ETH_ALEN);
  830. entry->seq_num = seq;
  831. entry->frag_num = frag;
  832. entry->packet_time = jiffies;
  833. list_add(&entry->list, &priv->ibss_mac_hash[index]);
  834. return 0;
  835. }
  836. last_seq = &entry->seq_num;
  837. last_frag = &entry->frag_num;
  838. last_time = &entry->packet_time;
  839. break;
  840. }
  841. case IEEE80211_IF_TYPE_STA:
  842. last_seq = &priv->last_seq_num;
  843. last_frag = &priv->last_frag_num;
  844. last_time = &priv->last_packet_time;
  845. break;
  846. default:
  847. return 0;
  848. }
  849. if ((*last_seq == seq) &&
  850. time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) {
  851. if (*last_frag == frag)
  852. goto drop;
  853. if (*last_frag + 1 != frag)
  854. /* out-of-order fragment */
  855. goto drop;
  856. } else
  857. *last_seq = seq;
  858. *last_frag = frag;
  859. *last_time = jiffies;
  860. return 0;
  861. drop:
  862. return 1;
  863. }
  864. #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
  865. #include "iwl-spectrum.h"
  866. #define BEACON_TIME_MASK_LOW 0x00FFFFFF
  867. #define BEACON_TIME_MASK_HIGH 0xFF000000
  868. #define TIME_UNIT 1024
  869. /*
  870. * extended beacon time format
  871. * time in usec will be changed into a 32-bit value in 8:24 format
  872. * the high 1 byte is the beacon counts
  873. * the lower 3 bytes is the time in usec within one beacon interval
  874. */
  875. static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval)
  876. {
  877. u32 quot;
  878. u32 rem;
  879. u32 interval = beacon_interval * 1024;
  880. if (!interval || !usec)
  881. return 0;
  882. quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
  883. rem = (usec % interval) & BEACON_TIME_MASK_LOW;
  884. return (quot << 24) + rem;
  885. }
  886. /* base is usually what we get from ucode with each received frame,
  887. * the same as HW timer counter counting down
  888. */
  889. static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
  890. {
  891. u32 base_low = base & BEACON_TIME_MASK_LOW;
  892. u32 addon_low = addon & BEACON_TIME_MASK_LOW;
  893. u32 interval = beacon_interval * TIME_UNIT;
  894. u32 res = (base & BEACON_TIME_MASK_HIGH) +
  895. (addon & BEACON_TIME_MASK_HIGH);
  896. if (base_low > addon_low)
  897. res += base_low - addon_low;
  898. else if (base_low < addon_low) {
  899. res += interval + base_low - addon_low;
  900. res += (1 << 24);
  901. } else
  902. res += (1 << 24);
  903. return cpu_to_le32(res);
  904. }
  905. static int iwl4965_get_measurement(struct iwl_priv *priv,
  906. struct ieee80211_measurement_params *params,
  907. u8 type)
  908. {
  909. struct iwl4965_spectrum_cmd spectrum;
  910. struct iwl_rx_packet *res;
  911. struct iwl_host_cmd cmd = {
  912. .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
  913. .data = (void *)&spectrum,
  914. .meta.flags = CMD_WANT_SKB,
  915. };
  916. u32 add_time = le64_to_cpu(params->start_time);
  917. int rc;
  918. int spectrum_resp_status;
  919. int duration = le16_to_cpu(params->duration);
  920. if (iwl_is_associated(priv))
  921. add_time =
  922. iwl4965_usecs_to_beacons(
  923. le64_to_cpu(params->start_time) - priv->last_tsf,
  924. le16_to_cpu(priv->rxon_timing.beacon_interval));
  925. memset(&spectrum, 0, sizeof(spectrum));
  926. spectrum.channel_count = cpu_to_le16(1);
  927. spectrum.flags =
  928. RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
  929. spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
  930. cmd.len = sizeof(spectrum);
  931. spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
  932. if (iwl_is_associated(priv))
  933. spectrum.start_time =
  934. iwl4965_add_beacon_time(priv->last_beacon_time,
  935. add_time,
  936. le16_to_cpu(priv->rxon_timing.beacon_interval));
  937. else
  938. spectrum.start_time = 0;
  939. spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
  940. spectrum.channels[0].channel = params->channel;
  941. spectrum.channels[0].type = type;
  942. if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
  943. spectrum.flags |= RXON_FLG_BAND_24G_MSK |
  944. RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
  945. rc = iwl_send_cmd_sync(priv, &cmd);
  946. if (rc)
  947. return rc;
  948. res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
  949. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  950. IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
  951. rc = -EIO;
  952. }
  953. spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
  954. switch (spectrum_resp_status) {
  955. case 0: /* Command will be handled */
  956. if (res->u.spectrum.id != 0xff) {
  957. IWL_DEBUG_INFO
  958. ("Replaced existing measurement: %d\n",
  959. res->u.spectrum.id);
  960. priv->measurement_status &= ~MEASUREMENT_READY;
  961. }
  962. priv->measurement_status |= MEASUREMENT_ACTIVE;
  963. rc = 0;
  964. break;
  965. case 1: /* Command will not be handled */
  966. rc = -EAGAIN;
  967. break;
  968. }
  969. dev_kfree_skb_any(cmd.meta.u.skb);
  970. return rc;
  971. }
  972. #endif
  973. /******************************************************************************
  974. *
  975. * Generic RX handler implementations
  976. *
  977. ******************************************************************************/
  978. static void iwl_rx_reply_alive(struct iwl_priv *priv,
  979. struct iwl_rx_mem_buffer *rxb)
  980. {
  981. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  982. struct iwl_alive_resp *palive;
  983. struct delayed_work *pwork;
  984. palive = &pkt->u.alive_frame;
  985. IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
  986. "0x%01X 0x%01X\n",
  987. palive->is_valid, palive->ver_type,
  988. palive->ver_subtype);
  989. if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
  990. IWL_DEBUG_INFO("Initialization Alive received.\n");
  991. memcpy(&priv->card_alive_init,
  992. &pkt->u.alive_frame,
  993. sizeof(struct iwl_init_alive_resp));
  994. pwork = &priv->init_alive_start;
  995. } else {
  996. IWL_DEBUG_INFO("Runtime Alive received.\n");
  997. memcpy(&priv->card_alive, &pkt->u.alive_frame,
  998. sizeof(struct iwl_alive_resp));
  999. pwork = &priv->alive_start;
  1000. }
  1001. /* We delay the ALIVE response by 5ms to
  1002. * give the HW RF Kill time to activate... */
  1003. if (palive->is_valid == UCODE_VALID_OK)
  1004. queue_delayed_work(priv->workqueue, pwork,
  1005. msecs_to_jiffies(5));
  1006. else
  1007. IWL_WARNING("uCode did not respond OK.\n");
  1008. }
  1009. static void iwl4965_rx_reply_error(struct iwl_priv *priv,
  1010. struct iwl_rx_mem_buffer *rxb)
  1011. {
  1012. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1013. IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
  1014. "seq 0x%04X ser 0x%08X\n",
  1015. le32_to_cpu(pkt->u.err_resp.error_type),
  1016. get_cmd_string(pkt->u.err_resp.cmd_id),
  1017. pkt->u.err_resp.cmd_id,
  1018. le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
  1019. le32_to_cpu(pkt->u.err_resp.error_info));
  1020. }
  1021. #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
  1022. static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
  1023. {
  1024. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1025. struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
  1026. struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif);
  1027. IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
  1028. le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
  1029. rxon->channel = csa->channel;
  1030. priv->staging_rxon.channel = csa->channel;
  1031. }
  1032. static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv,
  1033. struct iwl_rx_mem_buffer *rxb)
  1034. {
  1035. #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
  1036. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1037. struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif);
  1038. if (!report->state) {
  1039. IWL_DEBUG(IWL_DL_11H,
  1040. "Spectrum Measure Notification: Start\n");
  1041. return;
  1042. }
  1043. memcpy(&priv->measure_report, report, sizeof(*report));
  1044. priv->measurement_status |= MEASUREMENT_READY;
  1045. #endif
  1046. }
  1047. static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv,
  1048. struct iwl_rx_mem_buffer *rxb)
  1049. {
  1050. #ifdef CONFIG_IWLWIFI_DEBUG
  1051. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1052. struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif);
  1053. IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
  1054. sleep->pm_sleep_mode, sleep->pm_wakeup_src);
  1055. #endif
  1056. }
  1057. static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
  1058. struct iwl_rx_mem_buffer *rxb)
  1059. {
  1060. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1061. IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
  1062. "notification for %s:\n",
  1063. le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
  1064. iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
  1065. }
  1066. static void iwl4965_bg_beacon_update(struct work_struct *work)
  1067. {
  1068. struct iwl_priv *priv =
  1069. container_of(work, struct iwl_priv, beacon_update);
  1070. struct sk_buff *beacon;
  1071. /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
  1072. beacon = ieee80211_beacon_get(priv->hw, priv->vif);
  1073. if (!beacon) {
  1074. IWL_ERROR("update beacon failed\n");
  1075. return;
  1076. }
  1077. mutex_lock(&priv->mutex);
  1078. /* new beacon skb is allocated every time; dispose previous.*/
  1079. if (priv->ibss_beacon)
  1080. dev_kfree_skb(priv->ibss_beacon);
  1081. priv->ibss_beacon = beacon;
  1082. mutex_unlock(&priv->mutex);
  1083. iwl4965_send_beacon_cmd(priv);
  1084. }
  1085. /**
  1086. * iwl4965_bg_statistics_periodic - Timer callback to queue statistics
  1087. *
  1088. * This callback is provided in order to send a statistics request.
  1089. *
  1090. * This timer function is continually reset to execute within
  1091. * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
  1092. * was received. We need to ensure we receive the statistics in order
  1093. * to update the temperature used for calibrating the TXPOWER.
  1094. */
  1095. static void iwl4965_bg_statistics_periodic(unsigned long data)
  1096. {
  1097. struct iwl_priv *priv = (struct iwl_priv *)data;
  1098. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1099. return;
  1100. iwl_send_statistics_request(priv, CMD_ASYNC);
  1101. }
  1102. static void iwl4965_rx_beacon_notif(struct iwl_priv *priv,
  1103. struct iwl_rx_mem_buffer *rxb)
  1104. {
  1105. #ifdef CONFIG_IWLWIFI_DEBUG
  1106. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1107. struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status);
  1108. u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
  1109. IWL_DEBUG_RX("beacon status %x retries %d iss %d "
  1110. "tsf %d %d rate %d\n",
  1111. le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
  1112. beacon->beacon_notify_hdr.failure_frame,
  1113. le32_to_cpu(beacon->ibss_mgr_status),
  1114. le32_to_cpu(beacon->high_tsf),
  1115. le32_to_cpu(beacon->low_tsf), rate);
  1116. #endif
  1117. if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
  1118. (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
  1119. queue_work(priv->workqueue, &priv->beacon_update);
  1120. }
  1121. /* Handle notification from uCode that card's power state is changing
  1122. * due to software, hardware, or critical temperature RFKILL */
  1123. static void iwl4965_rx_card_state_notif(struct iwl_priv *priv,
  1124. struct iwl_rx_mem_buffer *rxb)
  1125. {
  1126. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1127. u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
  1128. unsigned long status = priv->status;
  1129. IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
  1130. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  1131. (flags & SW_CARD_DISABLED) ? "Kill" : "On");
  1132. if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
  1133. RF_CARD_DISABLED)) {
  1134. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  1135. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  1136. if (!iwl_grab_nic_access(priv)) {
  1137. iwl_write_direct32(
  1138. priv, HBUS_TARG_MBX_C,
  1139. HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  1140. iwl_release_nic_access(priv);
  1141. }
  1142. if (!(flags & RXON_CARD_DISABLED)) {
  1143. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  1144. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  1145. if (!iwl_grab_nic_access(priv)) {
  1146. iwl_write_direct32(
  1147. priv, HBUS_TARG_MBX_C,
  1148. HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  1149. iwl_release_nic_access(priv);
  1150. }
  1151. }
  1152. if (flags & RF_CARD_DISABLED) {
  1153. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  1154. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  1155. iwl_read32(priv, CSR_UCODE_DRV_GP1);
  1156. if (!iwl_grab_nic_access(priv))
  1157. iwl_release_nic_access(priv);
  1158. }
  1159. }
  1160. if (flags & HW_CARD_DISABLED)
  1161. set_bit(STATUS_RF_KILL_HW, &priv->status);
  1162. else
  1163. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  1164. if (flags & SW_CARD_DISABLED)
  1165. set_bit(STATUS_RF_KILL_SW, &priv->status);
  1166. else
  1167. clear_bit(STATUS_RF_KILL_SW, &priv->status);
  1168. if (!(flags & RXON_CARD_DISABLED))
  1169. iwl_scan_cancel(priv);
  1170. if ((test_bit(STATUS_RF_KILL_HW, &status) !=
  1171. test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
  1172. (test_bit(STATUS_RF_KILL_SW, &status) !=
  1173. test_bit(STATUS_RF_KILL_SW, &priv->status)))
  1174. queue_work(priv->workqueue, &priv->rf_kill);
  1175. else
  1176. wake_up_interruptible(&priv->wait_command_queue);
  1177. }
  1178. /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
  1179. * This will be used later in iwl4965_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
  1180. static void iwl4965_rx_reply_rx_phy(struct iwl_priv *priv,
  1181. struct iwl_rx_mem_buffer *rxb)
  1182. {
  1183. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1184. priv->last_phy_res[0] = 1;
  1185. memcpy(&priv->last_phy_res[1], &(pkt->u.raw[0]),
  1186. sizeof(struct iwl4965_rx_phy_res));
  1187. }
  1188. /**
  1189. * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
  1190. *
  1191. * Setup the RX handlers for each of the reply types sent from the uCode
  1192. * to the host.
  1193. *
  1194. * This function chains into the hardware specific files for them to setup
  1195. * any hardware specific handlers as well.
  1196. */
  1197. static void iwl4965_setup_rx_handlers(struct iwl_priv *priv)
  1198. {
  1199. priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
  1200. priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error;
  1201. priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa;
  1202. priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
  1203. iwl4965_rx_spectrum_measure_notif;
  1204. priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif;
  1205. priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
  1206. iwl4965_rx_pm_debug_statistics_notif;
  1207. priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
  1208. /*
  1209. * The same handler is used for both the REPLY to a discrete
  1210. * statistics request from the host as well as for the periodic
  1211. * statistics notifications (after received beacons) from the uCode.
  1212. */
  1213. priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics;
  1214. priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics;
  1215. iwl_setup_rx_scan_handlers(priv);
  1216. /* status change handler */
  1217. priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif;
  1218. priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
  1219. iwl_rx_missed_beacon_notif;
  1220. /* Rx handlers */
  1221. priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl4965_rx_reply_rx_phy;
  1222. priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl4965_rx_reply_rx;
  1223. /* Set up hardware specific Rx handlers */
  1224. priv->cfg->ops->lib->rx_handler_setup(priv);
  1225. }
  1226. /*
  1227. * this should be called while priv->lock is locked
  1228. */
  1229. static void __iwl_rx_replenish(struct iwl_priv *priv)
  1230. {
  1231. iwl_rx_allocate(priv);
  1232. iwl_rx_queue_restock(priv);
  1233. }
  1234. /**
  1235. * iwl_rx_handle - Main entry function for receiving responses from uCode
  1236. *
  1237. * Uses the priv->rx_handlers callback function array to invoke
  1238. * the appropriate handlers, including command responses,
  1239. * frame-received notifications, and other notifications.
  1240. */
  1241. void iwl_rx_handle(struct iwl_priv *priv)
  1242. {
  1243. struct iwl_rx_mem_buffer *rxb;
  1244. struct iwl_rx_packet *pkt;
  1245. struct iwl_rx_queue *rxq = &priv->rxq;
  1246. u32 r, i;
  1247. int reclaim;
  1248. unsigned long flags;
  1249. u8 fill_rx = 0;
  1250. u32 count = 8;
  1251. /* uCode's read index (stored in shared DRAM) indicates the last Rx
  1252. * buffer that the driver may process (last buffer filled by ucode). */
  1253. r = priv->cfg->ops->lib->shared_mem_rx_idx(priv);
  1254. i = rxq->read;
  1255. /* Rx interrupt, but nothing sent from uCode */
  1256. if (i == r)
  1257. IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d\n", r, i);
  1258. if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
  1259. fill_rx = 1;
  1260. while (i != r) {
  1261. rxb = rxq->queue[i];
  1262. /* If an RXB doesn't have a Rx queue slot associated with it,
  1263. * then a bug has been introduced in the queue refilling
  1264. * routines -- catch it here */
  1265. BUG_ON(rxb == NULL);
  1266. rxq->queue[i] = NULL;
  1267. pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
  1268. priv->hw_params.rx_buf_size,
  1269. PCI_DMA_FROMDEVICE);
  1270. pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1271. /* Reclaim a command buffer only if this packet is a response
  1272. * to a (driver-originated) command.
  1273. * If the packet (e.g. Rx frame) originated from uCode,
  1274. * there is no command buffer to reclaim.
  1275. * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
  1276. * but apparently a few don't get set; catch them here. */
  1277. reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
  1278. (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
  1279. (pkt->hdr.cmd != REPLY_RX) &&
  1280. (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
  1281. (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
  1282. (pkt->hdr.cmd != REPLY_TX);
  1283. /* Based on type of command response or notification,
  1284. * handle those that need handling via function in
  1285. * rx_handlers table. See iwl4965_setup_rx_handlers() */
  1286. if (priv->rx_handlers[pkt->hdr.cmd]) {
  1287. IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r,
  1288. i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
  1289. priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
  1290. } else {
  1291. /* No handling needed */
  1292. IWL_DEBUG(IWL_DL_RX,
  1293. "r %d i %d No handler needed for %s, 0x%02x\n",
  1294. r, i, get_cmd_string(pkt->hdr.cmd),
  1295. pkt->hdr.cmd);
  1296. }
  1297. if (reclaim) {
  1298. /* Invoke any callbacks, transfer the skb to caller, and
  1299. * fire off the (possibly) blocking iwl_send_cmd()
  1300. * as we reclaim the driver command queue */
  1301. if (rxb && rxb->skb)
  1302. iwl_tx_cmd_complete(priv, rxb);
  1303. else
  1304. IWL_WARNING("Claim null rxb?\n");
  1305. }
  1306. /* For now we just don't re-use anything. We can tweak this
  1307. * later to try and re-use notification packets and SKBs that
  1308. * fail to Rx correctly */
  1309. if (rxb->skb != NULL) {
  1310. priv->alloc_rxb_skb--;
  1311. dev_kfree_skb_any(rxb->skb);
  1312. rxb->skb = NULL;
  1313. }
  1314. pci_unmap_single(priv->pci_dev, rxb->dma_addr,
  1315. priv->hw_params.rx_buf_size,
  1316. PCI_DMA_FROMDEVICE);
  1317. spin_lock_irqsave(&rxq->lock, flags);
  1318. list_add_tail(&rxb->list, &priv->rxq.rx_used);
  1319. spin_unlock_irqrestore(&rxq->lock, flags);
  1320. i = (i + 1) & RX_QUEUE_MASK;
  1321. /* If there are a lot of unused frames,
  1322. * restock the Rx queue so ucode wont assert. */
  1323. if (fill_rx) {
  1324. count++;
  1325. if (count >= 8) {
  1326. priv->rxq.read = i;
  1327. __iwl_rx_replenish(priv);
  1328. count = 0;
  1329. }
  1330. }
  1331. }
  1332. /* Backtrack one entry */
  1333. priv->rxq.read = i;
  1334. iwl_rx_queue_restock(priv);
  1335. }
  1336. #define PERFECT_RSSI (-20) /* dBm */
  1337. #define WORST_RSSI (-95) /* dBm */
  1338. #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
  1339. /* Calculate an indication of rx signal quality (a percentage, not dBm!).
  1340. * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
  1341. * about formulas used below. */
  1342. int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm)
  1343. {
  1344. int sig_qual;
  1345. int degradation = PERFECT_RSSI - rssi_dbm;
  1346. /* If we get a noise measurement, use signal-to-noise ratio (SNR)
  1347. * as indicator; formula is (signal dbm - noise dbm).
  1348. * SNR at or above 40 is a great signal (100%).
  1349. * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
  1350. * Weakest usable signal is usually 10 - 15 dB SNR. */
  1351. if (noise_dbm) {
  1352. if (rssi_dbm - noise_dbm >= 40)
  1353. return 100;
  1354. else if (rssi_dbm < noise_dbm)
  1355. return 0;
  1356. sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
  1357. /* Else use just the signal level.
  1358. * This formula is a least squares fit of data points collected and
  1359. * compared with a reference system that had a percentage (%) display
  1360. * for signal quality. */
  1361. } else
  1362. sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
  1363. (15 * RSSI_RANGE + 62 * degradation)) /
  1364. (RSSI_RANGE * RSSI_RANGE);
  1365. if (sig_qual > 100)
  1366. sig_qual = 100;
  1367. else if (sig_qual < 1)
  1368. sig_qual = 0;
  1369. return sig_qual;
  1370. }
  1371. #ifdef CONFIG_IWLWIFI_DEBUG
  1372. static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv)
  1373. {
  1374. struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
  1375. DECLARE_MAC_BUF(mac);
  1376. IWL_DEBUG_RADIO("RX CONFIG:\n");
  1377. iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
  1378. IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
  1379. IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
  1380. IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
  1381. le32_to_cpu(rxon->filter_flags));
  1382. IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
  1383. IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
  1384. rxon->ofdm_basic_rates);
  1385. IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
  1386. IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
  1387. print_mac(mac, rxon->node_addr));
  1388. IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
  1389. print_mac(mac, rxon->bssid_addr));
  1390. IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
  1391. }
  1392. #endif
  1393. static void iwl4965_enable_interrupts(struct iwl_priv *priv)
  1394. {
  1395. IWL_DEBUG_ISR("Enabling interrupts\n");
  1396. set_bit(STATUS_INT_ENABLED, &priv->status);
  1397. iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
  1398. }
  1399. /* call this function to flush any scheduled tasklet */
  1400. static inline void iwl_synchronize_irq(struct iwl_priv *priv)
  1401. {
  1402. /* wait to make sure we flush pedding tasklet*/
  1403. synchronize_irq(priv->pci_dev->irq);
  1404. tasklet_kill(&priv->irq_tasklet);
  1405. }
  1406. static inline void iwl4965_disable_interrupts(struct iwl_priv *priv)
  1407. {
  1408. clear_bit(STATUS_INT_ENABLED, &priv->status);
  1409. /* disable interrupts from uCode/NIC to host */
  1410. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  1411. /* acknowledge/clear/reset any interrupts still pending
  1412. * from uCode or flow handler (Rx/Tx DMA) */
  1413. iwl_write32(priv, CSR_INT, 0xffffffff);
  1414. iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
  1415. IWL_DEBUG_ISR("Disabled interrupts\n");
  1416. }
  1417. /**
  1418. * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
  1419. */
  1420. static void iwl4965_irq_handle_error(struct iwl_priv *priv)
  1421. {
  1422. /* Set the FW error flag -- cleared on iwl4965_down */
  1423. set_bit(STATUS_FW_ERROR, &priv->status);
  1424. /* Cancel currently queued command. */
  1425. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  1426. #ifdef CONFIG_IWLWIFI_DEBUG
  1427. if (priv->debug_level & IWL_DL_FW_ERRORS) {
  1428. iwl_dump_nic_error_log(priv);
  1429. iwl_dump_nic_event_log(priv);
  1430. iwl4965_print_rx_config_cmd(priv);
  1431. }
  1432. #endif
  1433. wake_up_interruptible(&priv->wait_command_queue);
  1434. /* Keep the restart process from trying to send host
  1435. * commands by clearing the INIT status bit */
  1436. clear_bit(STATUS_READY, &priv->status);
  1437. if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  1438. IWL_DEBUG(IWL_DL_FW_ERRORS,
  1439. "Restarting adapter due to uCode error.\n");
  1440. if (iwl_is_associated(priv)) {
  1441. memcpy(&priv->recovery_rxon, &priv->active_rxon,
  1442. sizeof(priv->recovery_rxon));
  1443. priv->error_recovering = 1;
  1444. }
  1445. if (priv->cfg->mod_params->restart_fw)
  1446. queue_work(priv->workqueue, &priv->restart);
  1447. }
  1448. }
  1449. static void iwl4965_error_recovery(struct iwl_priv *priv)
  1450. {
  1451. unsigned long flags;
  1452. memcpy(&priv->staging_rxon, &priv->recovery_rxon,
  1453. sizeof(priv->staging_rxon));
  1454. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1455. iwl4965_commit_rxon(priv);
  1456. iwl_rxon_add_station(priv, priv->bssid, 1);
  1457. spin_lock_irqsave(&priv->lock, flags);
  1458. priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
  1459. priv->error_recovering = 0;
  1460. spin_unlock_irqrestore(&priv->lock, flags);
  1461. }
  1462. static void iwl4965_irq_tasklet(struct iwl_priv *priv)
  1463. {
  1464. u32 inta, handled = 0;
  1465. u32 inta_fh;
  1466. unsigned long flags;
  1467. #ifdef CONFIG_IWLWIFI_DEBUG
  1468. u32 inta_mask;
  1469. #endif
  1470. spin_lock_irqsave(&priv->lock, flags);
  1471. /* Ack/clear/reset pending uCode interrupts.
  1472. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
  1473. * and will clear only when CSR_FH_INT_STATUS gets cleared. */
  1474. inta = iwl_read32(priv, CSR_INT);
  1475. iwl_write32(priv, CSR_INT, inta);
  1476. /* Ack/clear/reset pending flow-handler (DMA) interrupts.
  1477. * Any new interrupts that happen after this, either while we're
  1478. * in this tasklet, or later, will show up in next ISR/tasklet. */
  1479. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  1480. iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
  1481. #ifdef CONFIG_IWLWIFI_DEBUG
  1482. if (priv->debug_level & IWL_DL_ISR) {
  1483. /* just for debug */
  1484. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  1485. IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  1486. inta, inta_mask, inta_fh);
  1487. }
  1488. #endif
  1489. /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
  1490. * atomic, make sure that inta covers all the interrupts that
  1491. * we've discovered, even if FH interrupt came in just after
  1492. * reading CSR_INT. */
  1493. if (inta_fh & CSR49_FH_INT_RX_MASK)
  1494. inta |= CSR_INT_BIT_FH_RX;
  1495. if (inta_fh & CSR49_FH_INT_TX_MASK)
  1496. inta |= CSR_INT_BIT_FH_TX;
  1497. /* Now service all interrupt bits discovered above. */
  1498. if (inta & CSR_INT_BIT_HW_ERR) {
  1499. IWL_ERROR("Microcode HW error detected. Restarting.\n");
  1500. /* Tell the device to stop sending interrupts */
  1501. iwl4965_disable_interrupts(priv);
  1502. iwl4965_irq_handle_error(priv);
  1503. handled |= CSR_INT_BIT_HW_ERR;
  1504. spin_unlock_irqrestore(&priv->lock, flags);
  1505. return;
  1506. }
  1507. #ifdef CONFIG_IWLWIFI_DEBUG
  1508. if (priv->debug_level & (IWL_DL_ISR)) {
  1509. /* NIC fires this, but we don't use it, redundant with WAKEUP */
  1510. if (inta & CSR_INT_BIT_SCD)
  1511. IWL_DEBUG_ISR("Scheduler finished to transmit "
  1512. "the frame/frames.\n");
  1513. /* Alive notification via Rx interrupt will do the real work */
  1514. if (inta & CSR_INT_BIT_ALIVE)
  1515. IWL_DEBUG_ISR("Alive interrupt\n");
  1516. }
  1517. #endif
  1518. /* Safely ignore these bits for debug checks below */
  1519. inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
  1520. /* HW RF KILL switch toggled */
  1521. if (inta & CSR_INT_BIT_RF_KILL) {
  1522. int hw_rf_kill = 0;
  1523. if (!(iwl_read32(priv, CSR_GP_CNTRL) &
  1524. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
  1525. hw_rf_kill = 1;
  1526. IWL_DEBUG(IWL_DL_RF_KILL, "RF_KILL bit toggled to %s.\n",
  1527. hw_rf_kill ? "disable radio":"enable radio");
  1528. /* Queue restart only if RF_KILL switch was set to "kill"
  1529. * when we loaded driver, and is now set to "enable".
  1530. * After we're Alive, RF_KILL gets handled by
  1531. * iwl4965_rx_card_state_notif() */
  1532. if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) {
  1533. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  1534. queue_work(priv->workqueue, &priv->restart);
  1535. }
  1536. handled |= CSR_INT_BIT_RF_KILL;
  1537. }
  1538. /* Chip got too hot and stopped itself */
  1539. if (inta & CSR_INT_BIT_CT_KILL) {
  1540. IWL_ERROR("Microcode CT kill error detected.\n");
  1541. handled |= CSR_INT_BIT_CT_KILL;
  1542. }
  1543. /* Error detected by uCode */
  1544. if (inta & CSR_INT_BIT_SW_ERR) {
  1545. IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
  1546. inta);
  1547. iwl4965_irq_handle_error(priv);
  1548. handled |= CSR_INT_BIT_SW_ERR;
  1549. }
  1550. /* uCode wakes up after power-down sleep */
  1551. if (inta & CSR_INT_BIT_WAKEUP) {
  1552. IWL_DEBUG_ISR("Wakeup interrupt\n");
  1553. iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
  1554. iwl_txq_update_write_ptr(priv, &priv->txq[0]);
  1555. iwl_txq_update_write_ptr(priv, &priv->txq[1]);
  1556. iwl_txq_update_write_ptr(priv, &priv->txq[2]);
  1557. iwl_txq_update_write_ptr(priv, &priv->txq[3]);
  1558. iwl_txq_update_write_ptr(priv, &priv->txq[4]);
  1559. iwl_txq_update_write_ptr(priv, &priv->txq[5]);
  1560. handled |= CSR_INT_BIT_WAKEUP;
  1561. }
  1562. /* All uCode command responses, including Tx command responses,
  1563. * Rx "responses" (frame-received notification), and other
  1564. * notifications from uCode come through here*/
  1565. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
  1566. iwl_rx_handle(priv);
  1567. handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
  1568. }
  1569. if (inta & CSR_INT_BIT_FH_TX) {
  1570. IWL_DEBUG_ISR("Tx interrupt\n");
  1571. handled |= CSR_INT_BIT_FH_TX;
  1572. /* FH finished to write, send event */
  1573. priv->ucode_write_complete = 1;
  1574. wake_up_interruptible(&priv->wait_command_queue);
  1575. }
  1576. if (inta & ~handled)
  1577. IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
  1578. if (inta & ~CSR_INI_SET_MASK) {
  1579. IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
  1580. inta & ~CSR_INI_SET_MASK);
  1581. IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh);
  1582. }
  1583. /* Re-enable all interrupts */
  1584. /* only Re-enable if diabled by irq */
  1585. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  1586. iwl4965_enable_interrupts(priv);
  1587. #ifdef CONFIG_IWLWIFI_DEBUG
  1588. if (priv->debug_level & (IWL_DL_ISR)) {
  1589. inta = iwl_read32(priv, CSR_INT);
  1590. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  1591. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  1592. IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
  1593. "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
  1594. }
  1595. #endif
  1596. spin_unlock_irqrestore(&priv->lock, flags);
  1597. }
  1598. static irqreturn_t iwl4965_isr(int irq, void *data)
  1599. {
  1600. struct iwl_priv *priv = data;
  1601. u32 inta, inta_mask;
  1602. u32 inta_fh;
  1603. if (!priv)
  1604. return IRQ_NONE;
  1605. spin_lock(&priv->lock);
  1606. /* Disable (but don't clear!) interrupts here to avoid
  1607. * back-to-back ISRs and sporadic interrupts from our NIC.
  1608. * If we have something to service, the tasklet will re-enable ints.
  1609. * If we *don't* have something, we'll re-enable before leaving here. */
  1610. inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
  1611. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  1612. /* Discover which interrupts are active/pending */
  1613. inta = iwl_read32(priv, CSR_INT);
  1614. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  1615. /* Ignore interrupt if there's nothing in NIC to service.
  1616. * This may be due to IRQ shared with another device,
  1617. * or due to sporadic interrupts thrown from our NIC. */
  1618. if (!inta && !inta_fh) {
  1619. IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
  1620. goto none;
  1621. }
  1622. if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
  1623. /* Hardware disappeared. It might have already raised
  1624. * an interrupt */
  1625. IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
  1626. goto unplugged;
  1627. }
  1628. IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  1629. inta, inta_mask, inta_fh);
  1630. inta &= ~CSR_INT_BIT_SCD;
  1631. /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
  1632. if (likely(inta || inta_fh))
  1633. tasklet_schedule(&priv->irq_tasklet);
  1634. unplugged:
  1635. spin_unlock(&priv->lock);
  1636. return IRQ_HANDLED;
  1637. none:
  1638. /* re-enable interrupts here since we don't have anything to service. */
  1639. /* only Re-enable if diabled by irq */
  1640. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  1641. iwl4965_enable_interrupts(priv);
  1642. spin_unlock(&priv->lock);
  1643. return IRQ_NONE;
  1644. }
  1645. /******************************************************************************
  1646. *
  1647. * uCode download functions
  1648. *
  1649. ******************************************************************************/
  1650. static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv)
  1651. {
  1652. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
  1653. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
  1654. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  1655. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
  1656. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  1657. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
  1658. }
  1659. static void iwl4965_nic_start(struct iwl_priv *priv)
  1660. {
  1661. /* Remove all resets to allow NIC to operate */
  1662. iwl_write32(priv, CSR_RESET, 0);
  1663. }
  1664. /**
  1665. * iwl4965_read_ucode - Read uCode images from disk file.
  1666. *
  1667. * Copy into buffers for card to fetch via bus-mastering
  1668. */
  1669. static int iwl4965_read_ucode(struct iwl_priv *priv)
  1670. {
  1671. struct iwl_ucode *ucode;
  1672. int ret;
  1673. const struct firmware *ucode_raw;
  1674. const char *name = priv->cfg->fw_name;
  1675. u8 *src;
  1676. size_t len;
  1677. u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
  1678. /* Ask kernel firmware_class module to get the boot firmware off disk.
  1679. * request_firmware() is synchronous, file is in memory on return. */
  1680. ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
  1681. if (ret < 0) {
  1682. IWL_ERROR("%s firmware file req failed: Reason %d\n",
  1683. name, ret);
  1684. goto error;
  1685. }
  1686. IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
  1687. name, ucode_raw->size);
  1688. /* Make sure that we got at least our header! */
  1689. if (ucode_raw->size < sizeof(*ucode)) {
  1690. IWL_ERROR("File size way too small!\n");
  1691. ret = -EINVAL;
  1692. goto err_release;
  1693. }
  1694. /* Data from ucode file: header followed by uCode images */
  1695. ucode = (void *)ucode_raw->data;
  1696. ver = le32_to_cpu(ucode->ver);
  1697. inst_size = le32_to_cpu(ucode->inst_size);
  1698. data_size = le32_to_cpu(ucode->data_size);
  1699. init_size = le32_to_cpu(ucode->init_size);
  1700. init_data_size = le32_to_cpu(ucode->init_data_size);
  1701. boot_size = le32_to_cpu(ucode->boot_size);
  1702. IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver);
  1703. IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
  1704. inst_size);
  1705. IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
  1706. data_size);
  1707. IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
  1708. init_size);
  1709. IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
  1710. init_data_size);
  1711. IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
  1712. boot_size);
  1713. /* Verify size of file vs. image size info in file's header */
  1714. if (ucode_raw->size < sizeof(*ucode) +
  1715. inst_size + data_size + init_size +
  1716. init_data_size + boot_size) {
  1717. IWL_DEBUG_INFO("uCode file size %d too small\n",
  1718. (int)ucode_raw->size);
  1719. ret = -EINVAL;
  1720. goto err_release;
  1721. }
  1722. /* Verify that uCode images will fit in card's SRAM */
  1723. if (inst_size > priv->hw_params.max_inst_size) {
  1724. IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
  1725. inst_size);
  1726. ret = -EINVAL;
  1727. goto err_release;
  1728. }
  1729. if (data_size > priv->hw_params.max_data_size) {
  1730. IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
  1731. data_size);
  1732. ret = -EINVAL;
  1733. goto err_release;
  1734. }
  1735. if (init_size > priv->hw_params.max_inst_size) {
  1736. IWL_DEBUG_INFO
  1737. ("uCode init instr len %d too large to fit in\n",
  1738. init_size);
  1739. ret = -EINVAL;
  1740. goto err_release;
  1741. }
  1742. if (init_data_size > priv->hw_params.max_data_size) {
  1743. IWL_DEBUG_INFO
  1744. ("uCode init data len %d too large to fit in\n",
  1745. init_data_size);
  1746. ret = -EINVAL;
  1747. goto err_release;
  1748. }
  1749. if (boot_size > priv->hw_params.max_bsm_size) {
  1750. IWL_DEBUG_INFO
  1751. ("uCode boot instr len %d too large to fit in\n",
  1752. boot_size);
  1753. ret = -EINVAL;
  1754. goto err_release;
  1755. }
  1756. /* Allocate ucode buffers for card's bus-master loading ... */
  1757. /* Runtime instructions and 2 copies of data:
  1758. * 1) unmodified from disk
  1759. * 2) backup cache for save/restore during power-downs */
  1760. priv->ucode_code.len = inst_size;
  1761. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
  1762. priv->ucode_data.len = data_size;
  1763. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
  1764. priv->ucode_data_backup.len = data_size;
  1765. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  1766. /* Initialization instructions and data */
  1767. if (init_size && init_data_size) {
  1768. priv->ucode_init.len = init_size;
  1769. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
  1770. priv->ucode_init_data.len = init_data_size;
  1771. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  1772. if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
  1773. goto err_pci_alloc;
  1774. }
  1775. /* Bootstrap (instructions only, no data) */
  1776. if (boot_size) {
  1777. priv->ucode_boot.len = boot_size;
  1778. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
  1779. if (!priv->ucode_boot.v_addr)
  1780. goto err_pci_alloc;
  1781. }
  1782. /* Copy images into buffers for card's bus-master reads ... */
  1783. /* Runtime instructions (first block of data in file) */
  1784. src = &ucode->data[0];
  1785. len = priv->ucode_code.len;
  1786. IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
  1787. memcpy(priv->ucode_code.v_addr, src, len);
  1788. IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
  1789. priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
  1790. /* Runtime data (2nd block)
  1791. * NOTE: Copy into backup buffer will be done in iwl4965_up() */
  1792. src = &ucode->data[inst_size];
  1793. len = priv->ucode_data.len;
  1794. IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
  1795. memcpy(priv->ucode_data.v_addr, src, len);
  1796. memcpy(priv->ucode_data_backup.v_addr, src, len);
  1797. /* Initialization instructions (3rd block) */
  1798. if (init_size) {
  1799. src = &ucode->data[inst_size + data_size];
  1800. len = priv->ucode_init.len;
  1801. IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
  1802. len);
  1803. memcpy(priv->ucode_init.v_addr, src, len);
  1804. }
  1805. /* Initialization data (4th block) */
  1806. if (init_data_size) {
  1807. src = &ucode->data[inst_size + data_size + init_size];
  1808. len = priv->ucode_init_data.len;
  1809. IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
  1810. len);
  1811. memcpy(priv->ucode_init_data.v_addr, src, len);
  1812. }
  1813. /* Bootstrap instructions (5th block) */
  1814. src = &ucode->data[inst_size + data_size + init_size + init_data_size];
  1815. len = priv->ucode_boot.len;
  1816. IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len);
  1817. memcpy(priv->ucode_boot.v_addr, src, len);
  1818. /* We have our copies now, allow OS release its copies */
  1819. release_firmware(ucode_raw);
  1820. return 0;
  1821. err_pci_alloc:
  1822. IWL_ERROR("failed to allocate pci memory\n");
  1823. ret = -ENOMEM;
  1824. iwl4965_dealloc_ucode_pci(priv);
  1825. err_release:
  1826. release_firmware(ucode_raw);
  1827. error:
  1828. return ret;
  1829. }
  1830. /**
  1831. * iwl_alive_start - called after REPLY_ALIVE notification received
  1832. * from protocol/runtime uCode (initialization uCode's
  1833. * Alive gets handled by iwl_init_alive_start()).
  1834. */
  1835. static void iwl_alive_start(struct iwl_priv *priv)
  1836. {
  1837. int ret = 0;
  1838. IWL_DEBUG_INFO("Runtime Alive received.\n");
  1839. if (priv->card_alive.is_valid != UCODE_VALID_OK) {
  1840. /* We had an error bringing up the hardware, so take it
  1841. * all the way back down so we can try again */
  1842. IWL_DEBUG_INFO("Alive failed.\n");
  1843. goto restart;
  1844. }
  1845. /* Initialize uCode has loaded Runtime uCode ... verify inst image.
  1846. * This is a paranoid check, because we would not have gotten the
  1847. * "runtime" alive if code weren't properly loaded. */
  1848. if (iwl_verify_ucode(priv)) {
  1849. /* Runtime instruction load was bad;
  1850. * take it all the way back down so we can try again */
  1851. IWL_DEBUG_INFO("Bad runtime uCode load.\n");
  1852. goto restart;
  1853. }
  1854. iwlcore_clear_stations_table(priv);
  1855. ret = priv->cfg->ops->lib->alive_notify(priv);
  1856. if (ret) {
  1857. IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
  1858. ret);
  1859. goto restart;
  1860. }
  1861. /* After the ALIVE response, we can send host commands to 4965 uCode */
  1862. set_bit(STATUS_ALIVE, &priv->status);
  1863. if (iwl_is_rfkill(priv))
  1864. return;
  1865. ieee80211_wake_queues(priv->hw);
  1866. priv->active_rate = priv->rates_mask;
  1867. priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
  1868. if (iwl_is_associated(priv)) {
  1869. struct iwl_rxon_cmd *active_rxon =
  1870. (struct iwl_rxon_cmd *)&priv->active_rxon;
  1871. memcpy(&priv->staging_rxon, &priv->active_rxon,
  1872. sizeof(priv->staging_rxon));
  1873. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1874. } else {
  1875. /* Initialize our rx_config data */
  1876. iwl4965_connection_init_rx_config(priv);
  1877. memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  1878. }
  1879. /* Configure Bluetooth device coexistence support */
  1880. iwl4965_send_bt_config(priv);
  1881. iwl_reset_run_time_calib(priv);
  1882. /* Configure the adapter for unassociated operation */
  1883. iwl4965_commit_rxon(priv);
  1884. /* At this point, the NIC is initialized and operational */
  1885. iwl_rf_kill_ct_config(priv);
  1886. iwl_leds_register(priv);
  1887. IWL_DEBUG_INFO("ALIVE processing complete.\n");
  1888. set_bit(STATUS_READY, &priv->status);
  1889. wake_up_interruptible(&priv->wait_command_queue);
  1890. if (priv->error_recovering)
  1891. iwl4965_error_recovery(priv);
  1892. iwl_power_update_mode(priv, 1);
  1893. ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC);
  1894. if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
  1895. iwl4965_set_mode(priv, priv->iw_mode);
  1896. return;
  1897. restart:
  1898. queue_work(priv->workqueue, &priv->restart);
  1899. }
  1900. static void iwl_cancel_deferred_work(struct iwl_priv *priv);
  1901. static void __iwl4965_down(struct iwl_priv *priv)
  1902. {
  1903. unsigned long flags;
  1904. int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
  1905. IWL_DEBUG_INFO(DRV_NAME " is going down\n");
  1906. if (!exit_pending)
  1907. set_bit(STATUS_EXIT_PENDING, &priv->status);
  1908. iwl_leds_unregister(priv);
  1909. iwlcore_clear_stations_table(priv);
  1910. /* Unblock any waiting calls */
  1911. wake_up_interruptible_all(&priv->wait_command_queue);
  1912. /* Wipe out the EXIT_PENDING status bit if we are not actually
  1913. * exiting the module */
  1914. if (!exit_pending)
  1915. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  1916. /* stop and reset the on-board processor */
  1917. iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  1918. /* tell the device to stop sending interrupts */
  1919. spin_lock_irqsave(&priv->lock, flags);
  1920. iwl4965_disable_interrupts(priv);
  1921. spin_unlock_irqrestore(&priv->lock, flags);
  1922. iwl_synchronize_irq(priv);
  1923. if (priv->mac80211_registered)
  1924. ieee80211_stop_queues(priv->hw);
  1925. /* If we have not previously called iwl4965_init() then
  1926. * clear all bits but the RF Kill and SUSPEND bits and return */
  1927. if (!iwl_is_init(priv)) {
  1928. priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  1929. STATUS_RF_KILL_HW |
  1930. test_bit(STATUS_RF_KILL_SW, &priv->status) <<
  1931. STATUS_RF_KILL_SW |
  1932. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  1933. STATUS_GEO_CONFIGURED |
  1934. test_bit(STATUS_IN_SUSPEND, &priv->status) <<
  1935. STATUS_IN_SUSPEND;
  1936. goto exit;
  1937. }
  1938. /* ...otherwise clear out all the status bits but the RF Kill and
  1939. * SUSPEND bits and continue taking the NIC down. */
  1940. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  1941. STATUS_RF_KILL_HW |
  1942. test_bit(STATUS_RF_KILL_SW, &priv->status) <<
  1943. STATUS_RF_KILL_SW |
  1944. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  1945. STATUS_GEO_CONFIGURED |
  1946. test_bit(STATUS_IN_SUSPEND, &priv->status) <<
  1947. STATUS_IN_SUSPEND |
  1948. test_bit(STATUS_FW_ERROR, &priv->status) <<
  1949. STATUS_FW_ERROR;
  1950. spin_lock_irqsave(&priv->lock, flags);
  1951. iwl_clear_bit(priv, CSR_GP_CNTRL,
  1952. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  1953. spin_unlock_irqrestore(&priv->lock, flags);
  1954. iwl_txq_ctx_stop(priv);
  1955. iwl_rxq_stop(priv);
  1956. spin_lock_irqsave(&priv->lock, flags);
  1957. if (!iwl_grab_nic_access(priv)) {
  1958. iwl_write_prph(priv, APMG_CLK_DIS_REG,
  1959. APMG_CLK_VAL_DMA_CLK_RQT);
  1960. iwl_release_nic_access(priv);
  1961. }
  1962. spin_unlock_irqrestore(&priv->lock, flags);
  1963. udelay(5);
  1964. /* FIXME: apm_ops.suspend(priv) */
  1965. priv->cfg->ops->lib->apm_ops.reset(priv);
  1966. priv->cfg->ops->lib->free_shared_mem(priv);
  1967. exit:
  1968. memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
  1969. if (priv->ibss_beacon)
  1970. dev_kfree_skb(priv->ibss_beacon);
  1971. priv->ibss_beacon = NULL;
  1972. /* clear out any free frames */
  1973. iwl_clear_free_frames(priv);
  1974. }
  1975. static void iwl4965_down(struct iwl_priv *priv)
  1976. {
  1977. mutex_lock(&priv->mutex);
  1978. __iwl4965_down(priv);
  1979. mutex_unlock(&priv->mutex);
  1980. iwl_cancel_deferred_work(priv);
  1981. }
  1982. #define MAX_HW_RESTARTS 5
  1983. static int __iwl4965_up(struct iwl_priv *priv)
  1984. {
  1985. int i;
  1986. int ret;
  1987. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  1988. IWL_WARNING("Exit pending; will not bring the NIC up\n");
  1989. return -EIO;
  1990. }
  1991. if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
  1992. IWL_ERROR("ucode not available for device bringup\n");
  1993. return -EIO;
  1994. }
  1995. /* If platform's RF_KILL switch is NOT set to KILL */
  1996. if (iwl_read32(priv, CSR_GP_CNTRL) &
  1997. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  1998. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  1999. else {
  2000. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2001. if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
  2002. iwl_rfkill_set_hw_state(priv);
  2003. IWL_WARNING("Radio disabled by HW RF Kill switch\n");
  2004. return -ENODEV;
  2005. }
  2006. }
  2007. iwl_rfkill_set_hw_state(priv);
  2008. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  2009. ret = priv->cfg->ops->lib->alloc_shared_mem(priv);
  2010. if (ret) {
  2011. IWL_ERROR("Unable to allocate shared memory\n");
  2012. return ret;
  2013. }
  2014. ret = iwl_hw_nic_init(priv);
  2015. if (ret) {
  2016. IWL_ERROR("Unable to init nic\n");
  2017. return ret;
  2018. }
  2019. /* make sure rfkill handshake bits are cleared */
  2020. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2021. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  2022. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  2023. /* clear (again), then enable host interrupts */
  2024. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  2025. iwl4965_enable_interrupts(priv);
  2026. /* really make sure rfkill handshake bits are cleared */
  2027. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2028. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2029. /* Copy original ucode data image from disk into backup cache.
  2030. * This will be used to initialize the on-board processor's
  2031. * data SRAM for a clean start when the runtime program first loads. */
  2032. memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
  2033. priv->ucode_data.len);
  2034. /* We return success when we resume from suspend and rf_kill is on. */
  2035. if (test_bit(STATUS_RF_KILL_HW, &priv->status) ||
  2036. test_bit(STATUS_RF_KILL_SW, &priv->status))
  2037. return 0;
  2038. for (i = 0; i < MAX_HW_RESTARTS; i++) {
  2039. iwlcore_clear_stations_table(priv);
  2040. /* load bootstrap state machine,
  2041. * load bootstrap program into processor's memory,
  2042. * prepare to load the "initialize" uCode */
  2043. ret = priv->cfg->ops->lib->load_ucode(priv);
  2044. if (ret) {
  2045. IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret);
  2046. continue;
  2047. }
  2048. /* Clear out the uCode error bit if it is set */
  2049. clear_bit(STATUS_FW_ERROR, &priv->status);
  2050. /* start card; "initialize" will load runtime ucode */
  2051. iwl4965_nic_start(priv);
  2052. IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
  2053. return 0;
  2054. }
  2055. set_bit(STATUS_EXIT_PENDING, &priv->status);
  2056. __iwl4965_down(priv);
  2057. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  2058. /* tried to restart and config the device for as long as our
  2059. * patience could withstand */
  2060. IWL_ERROR("Unable to initialize device after %d attempts.\n", i);
  2061. return -EIO;
  2062. }
  2063. /*****************************************************************************
  2064. *
  2065. * Workqueue callbacks
  2066. *
  2067. *****************************************************************************/
  2068. static void iwl_bg_init_alive_start(struct work_struct *data)
  2069. {
  2070. struct iwl_priv *priv =
  2071. container_of(data, struct iwl_priv, init_alive_start.work);
  2072. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2073. return;
  2074. mutex_lock(&priv->mutex);
  2075. priv->cfg->ops->lib->init_alive_start(priv);
  2076. mutex_unlock(&priv->mutex);
  2077. }
  2078. static void iwl_bg_alive_start(struct work_struct *data)
  2079. {
  2080. struct iwl_priv *priv =
  2081. container_of(data, struct iwl_priv, alive_start.work);
  2082. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2083. return;
  2084. mutex_lock(&priv->mutex);
  2085. iwl_alive_start(priv);
  2086. mutex_unlock(&priv->mutex);
  2087. }
  2088. static void iwl4965_bg_rf_kill(struct work_struct *work)
  2089. {
  2090. struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill);
  2091. wake_up_interruptible(&priv->wait_command_queue);
  2092. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2093. return;
  2094. mutex_lock(&priv->mutex);
  2095. if (!iwl_is_rfkill(priv)) {
  2096. IWL_DEBUG(IWL_DL_RF_KILL,
  2097. "HW and/or SW RF Kill no longer active, restarting "
  2098. "device\n");
  2099. if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
  2100. queue_work(priv->workqueue, &priv->restart);
  2101. } else {
  2102. /* make sure mac80211 stop sending Tx frame */
  2103. if (priv->mac80211_registered)
  2104. ieee80211_stop_queues(priv->hw);
  2105. if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
  2106. IWL_DEBUG_RF_KILL("Can not turn radio back on - "
  2107. "disabled by SW switch\n");
  2108. else
  2109. IWL_WARNING("Radio Frequency Kill Switch is On:\n"
  2110. "Kill switch must be turned off for "
  2111. "wireless networking to work.\n");
  2112. }
  2113. iwl_rfkill_set_hw_state(priv);
  2114. mutex_unlock(&priv->mutex);
  2115. }
  2116. static void iwl4965_bg_set_monitor(struct work_struct *work)
  2117. {
  2118. struct iwl_priv *priv = container_of(work,
  2119. struct iwl_priv, set_monitor);
  2120. int ret;
  2121. IWL_DEBUG(IWL_DL_STATE, "setting monitor mode\n");
  2122. mutex_lock(&priv->mutex);
  2123. ret = iwl4965_set_mode(priv, IEEE80211_IF_TYPE_MNTR);
  2124. if (ret) {
  2125. if (ret == -EAGAIN)
  2126. IWL_DEBUG(IWL_DL_STATE, "leave - not ready\n");
  2127. else
  2128. IWL_ERROR("iwl4965_set_mode() failed ret = %d\n", ret);
  2129. }
  2130. mutex_unlock(&priv->mutex);
  2131. }
  2132. static void iwl_bg_run_time_calib_work(struct work_struct *work)
  2133. {
  2134. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  2135. run_time_calib_work);
  2136. mutex_lock(&priv->mutex);
  2137. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  2138. test_bit(STATUS_SCANNING, &priv->status)) {
  2139. mutex_unlock(&priv->mutex);
  2140. return;
  2141. }
  2142. if (priv->start_calib) {
  2143. iwl_chain_noise_calibration(priv, &priv->statistics);
  2144. iwl_sensitivity_calibration(priv, &priv->statistics);
  2145. }
  2146. mutex_unlock(&priv->mutex);
  2147. return;
  2148. }
  2149. static void iwl4965_bg_up(struct work_struct *data)
  2150. {
  2151. struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
  2152. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2153. return;
  2154. mutex_lock(&priv->mutex);
  2155. __iwl4965_up(priv);
  2156. mutex_unlock(&priv->mutex);
  2157. }
  2158. static void iwl4965_bg_restart(struct work_struct *data)
  2159. {
  2160. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  2161. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2162. return;
  2163. iwl4965_down(priv);
  2164. queue_work(priv->workqueue, &priv->up);
  2165. }
  2166. static void iwl4965_bg_rx_replenish(struct work_struct *data)
  2167. {
  2168. struct iwl_priv *priv =
  2169. container_of(data, struct iwl_priv, rx_replenish);
  2170. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2171. return;
  2172. mutex_lock(&priv->mutex);
  2173. iwl_rx_replenish(priv);
  2174. mutex_unlock(&priv->mutex);
  2175. }
  2176. #define IWL_DELAY_NEXT_SCAN (HZ*2)
  2177. static void iwl4965_post_associate(struct iwl_priv *priv)
  2178. {
  2179. struct ieee80211_conf *conf = NULL;
  2180. int ret = 0;
  2181. DECLARE_MAC_BUF(mac);
  2182. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  2183. IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__);
  2184. return;
  2185. }
  2186. IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
  2187. priv->assoc_id,
  2188. print_mac(mac, priv->active_rxon.bssid_addr));
  2189. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2190. return;
  2191. if (!priv->vif || !priv->is_open)
  2192. return;
  2193. iwl_scan_cancel_timeout(priv, 200);
  2194. conf = ieee80211_get_hw_conf(priv->hw);
  2195. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2196. iwl4965_commit_rxon(priv);
  2197. memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
  2198. iwl4965_setup_rxon_timing(priv);
  2199. ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
  2200. sizeof(priv->rxon_timing), &priv->rxon_timing);
  2201. if (ret)
  2202. IWL_WARNING("REPLY_RXON_TIMING failed - "
  2203. "Attempting to continue.\n");
  2204. priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  2205. if (priv->current_ht_config.is_ht)
  2206. iwl_set_rxon_ht(priv, &priv->current_ht_config);
  2207. iwl_set_rxon_chain(priv);
  2208. priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
  2209. IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
  2210. priv->assoc_id, priv->beacon_int);
  2211. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  2212. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  2213. else
  2214. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  2215. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
  2216. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
  2217. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  2218. else
  2219. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  2220. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  2221. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  2222. }
  2223. iwl4965_commit_rxon(priv);
  2224. switch (priv->iw_mode) {
  2225. case IEEE80211_IF_TYPE_STA:
  2226. iwl4965_rate_scale_init(priv->hw, IWL_AP_ID);
  2227. break;
  2228. case IEEE80211_IF_TYPE_IBSS:
  2229. /* assume default assoc id */
  2230. priv->assoc_id = 1;
  2231. iwl_rxon_add_station(priv, priv->bssid, 0);
  2232. iwl4965_rate_scale_init(priv->hw, IWL_STA_ID);
  2233. iwl4965_send_beacon_cmd(priv);
  2234. break;
  2235. default:
  2236. IWL_ERROR("%s Should not be called in %d mode\n",
  2237. __FUNCTION__, priv->iw_mode);
  2238. break;
  2239. }
  2240. iwl4965_sequence_reset(priv);
  2241. /* Enable Rx differential gain and sensitivity calibrations */
  2242. iwl_chain_noise_reset(priv);
  2243. priv->start_calib = 1;
  2244. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  2245. priv->assoc_station_added = 1;
  2246. iwl4965_activate_qos(priv, 0);
  2247. iwl_power_update_mode(priv, 0);
  2248. /* we have just associated, don't start scan too early */
  2249. priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
  2250. }
  2251. static void iwl4965_bg_post_associate(struct work_struct *data)
  2252. {
  2253. struct iwl_priv *priv = container_of(data, struct iwl_priv,
  2254. post_associate.work);
  2255. mutex_lock(&priv->mutex);
  2256. iwl4965_post_associate(priv);
  2257. mutex_unlock(&priv->mutex);
  2258. }
  2259. static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
  2260. static void iwl_bg_scan_completed(struct work_struct *work)
  2261. {
  2262. struct iwl_priv *priv =
  2263. container_of(work, struct iwl_priv, scan_completed);
  2264. IWL_DEBUG_SCAN("SCAN complete scan\n");
  2265. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2266. return;
  2267. if (test_bit(STATUS_CONF_PENDING, &priv->status))
  2268. iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw));
  2269. ieee80211_scan_completed(priv->hw);
  2270. /* Since setting the TXPOWER may have been deferred while
  2271. * performing the scan, fire one off */
  2272. mutex_lock(&priv->mutex);
  2273. iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
  2274. mutex_unlock(&priv->mutex);
  2275. }
  2276. /*****************************************************************************
  2277. *
  2278. * mac80211 entry point functions
  2279. *
  2280. *****************************************************************************/
  2281. #define UCODE_READY_TIMEOUT (2 * HZ)
  2282. static int iwl4965_mac_start(struct ieee80211_hw *hw)
  2283. {
  2284. struct iwl_priv *priv = hw->priv;
  2285. int ret;
  2286. IWL_DEBUG_MAC80211("enter\n");
  2287. if (pci_enable_device(priv->pci_dev)) {
  2288. IWL_ERROR("Fail to pci_enable_device\n");
  2289. return -ENODEV;
  2290. }
  2291. pci_restore_state(priv->pci_dev);
  2292. pci_enable_msi(priv->pci_dev);
  2293. ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED,
  2294. DRV_NAME, priv);
  2295. if (ret) {
  2296. IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq);
  2297. goto out_disable_msi;
  2298. }
  2299. /* we should be verifying the device is ready to be opened */
  2300. mutex_lock(&priv->mutex);
  2301. memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd));
  2302. /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
  2303. * ucode filename and max sizes are card-specific. */
  2304. if (!priv->ucode_code.len) {
  2305. ret = iwl4965_read_ucode(priv);
  2306. if (ret) {
  2307. IWL_ERROR("Could not read microcode: %d\n", ret);
  2308. mutex_unlock(&priv->mutex);
  2309. goto out_release_irq;
  2310. }
  2311. }
  2312. ret = __iwl4965_up(priv);
  2313. mutex_unlock(&priv->mutex);
  2314. if (ret)
  2315. goto out_release_irq;
  2316. IWL_DEBUG_INFO("Start UP work done.\n");
  2317. if (test_bit(STATUS_IN_SUSPEND, &priv->status))
  2318. return 0;
  2319. /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
  2320. * mac80211 will not be run successfully. */
  2321. if (priv->ucode_type == UCODE_RT) {
  2322. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  2323. test_bit(STATUS_READY, &priv->status),
  2324. UCODE_READY_TIMEOUT);
  2325. if (!ret) {
  2326. if (!test_bit(STATUS_READY, &priv->status)) {
  2327. IWL_ERROR("START_ALIVE timeout after %dms.\n",
  2328. jiffies_to_msecs(UCODE_READY_TIMEOUT));
  2329. ret = -ETIMEDOUT;
  2330. goto out_release_irq;
  2331. }
  2332. }
  2333. priv->is_open = 1;
  2334. }
  2335. IWL_DEBUG_MAC80211("leave\n");
  2336. return 0;
  2337. out_release_irq:
  2338. free_irq(priv->pci_dev->irq, priv);
  2339. out_disable_msi:
  2340. pci_disable_msi(priv->pci_dev);
  2341. pci_disable_device(priv->pci_dev);
  2342. priv->is_open = 0;
  2343. IWL_DEBUG_MAC80211("leave - failed\n");
  2344. return ret;
  2345. }
  2346. static void iwl4965_mac_stop(struct ieee80211_hw *hw)
  2347. {
  2348. struct iwl_priv *priv = hw->priv;
  2349. IWL_DEBUG_MAC80211("enter\n");
  2350. if (!priv->is_open) {
  2351. IWL_DEBUG_MAC80211("leave - skip\n");
  2352. return;
  2353. }
  2354. priv->is_open = 0;
  2355. if (iwl_is_ready_rf(priv)) {
  2356. /* stop mac, cancel any scan request and clear
  2357. * RXON_FILTER_ASSOC_MSK BIT
  2358. */
  2359. mutex_lock(&priv->mutex);
  2360. iwl_scan_cancel_timeout(priv, 100);
  2361. cancel_delayed_work(&priv->post_associate);
  2362. mutex_unlock(&priv->mutex);
  2363. }
  2364. iwl4965_down(priv);
  2365. flush_workqueue(priv->workqueue);
  2366. free_irq(priv->pci_dev->irq, priv);
  2367. pci_disable_msi(priv->pci_dev);
  2368. pci_save_state(priv->pci_dev);
  2369. pci_disable_device(priv->pci_dev);
  2370. IWL_DEBUG_MAC80211("leave\n");
  2371. }
  2372. static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  2373. {
  2374. struct iwl_priv *priv = hw->priv;
  2375. IWL_DEBUG_MAC80211("enter\n");
  2376. if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
  2377. IWL_DEBUG_MAC80211("leave - monitor\n");
  2378. return -1;
  2379. }
  2380. IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  2381. ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
  2382. if (iwl_tx_skb(priv, skb))
  2383. dev_kfree_skb_any(skb);
  2384. IWL_DEBUG_MAC80211("leave\n");
  2385. return 0;
  2386. }
  2387. static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
  2388. struct ieee80211_if_init_conf *conf)
  2389. {
  2390. struct iwl_priv *priv = hw->priv;
  2391. unsigned long flags;
  2392. DECLARE_MAC_BUF(mac);
  2393. IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
  2394. if (priv->vif) {
  2395. IWL_DEBUG_MAC80211("leave - vif != NULL\n");
  2396. return -EOPNOTSUPP;
  2397. }
  2398. spin_lock_irqsave(&priv->lock, flags);
  2399. priv->vif = conf->vif;
  2400. spin_unlock_irqrestore(&priv->lock, flags);
  2401. mutex_lock(&priv->mutex);
  2402. if (conf->mac_addr) {
  2403. IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr));
  2404. memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
  2405. }
  2406. if (iwl4965_set_mode(priv, conf->type) == -EAGAIN)
  2407. /* we are not ready, will run again when ready */
  2408. set_bit(STATUS_MODE_PENDING, &priv->status);
  2409. mutex_unlock(&priv->mutex);
  2410. IWL_DEBUG_MAC80211("leave\n");
  2411. return 0;
  2412. }
  2413. /**
  2414. * iwl4965_mac_config - mac80211 config callback
  2415. *
  2416. * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
  2417. * be set inappropriately and the driver currently sets the hardware up to
  2418. * use it whenever needed.
  2419. */
  2420. static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
  2421. {
  2422. struct iwl_priv *priv = hw->priv;
  2423. const struct iwl_channel_info *ch_info;
  2424. unsigned long flags;
  2425. int ret = 0;
  2426. u16 channel;
  2427. mutex_lock(&priv->mutex);
  2428. IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
  2429. priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP);
  2430. if (priv->cfg->ops->lib->radio_kill_sw &&
  2431. priv->cfg->ops->lib->radio_kill_sw(priv, !conf->radio_enabled)) {
  2432. IWL_DEBUG_MAC80211("leave - RF-KILL - waiting for uCode\n");
  2433. mutex_unlock(&priv->mutex);
  2434. }
  2435. if (!iwl_is_ready(priv)) {
  2436. IWL_DEBUG_MAC80211("leave - not ready\n");
  2437. ret = -EIO;
  2438. goto out;
  2439. }
  2440. if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
  2441. test_bit(STATUS_SCANNING, &priv->status))) {
  2442. IWL_DEBUG_MAC80211("leave - scanning\n");
  2443. set_bit(STATUS_CONF_PENDING, &priv->status);
  2444. mutex_unlock(&priv->mutex);
  2445. return 0;
  2446. }
  2447. channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
  2448. ch_info = iwl_get_channel_info(priv, conf->channel->band, channel);
  2449. if (!is_channel_valid(ch_info)) {
  2450. IWL_DEBUG_MAC80211("leave - invalid channel\n");
  2451. ret = -EINVAL;
  2452. goto out;
  2453. }
  2454. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS &&
  2455. !is_channel_ibss(ch_info)) {
  2456. IWL_ERROR("channel %d in band %d not IBSS channel\n",
  2457. conf->channel->hw_value, conf->channel->band);
  2458. ret = -EINVAL;
  2459. goto out;
  2460. }
  2461. spin_lock_irqsave(&priv->lock, flags);
  2462. /* if we are switching from ht to 2.4 clear flags
  2463. * from any ht related info since 2.4 does not
  2464. * support ht */
  2465. if ((le16_to_cpu(priv->staging_rxon.channel) != channel)
  2466. #ifdef IEEE80211_CONF_CHANNEL_SWITCH
  2467. && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH)
  2468. #endif
  2469. )
  2470. priv->staging_rxon.flags = 0;
  2471. iwl_set_rxon_channel(priv, conf->channel->band, channel);
  2472. iwl_set_flags_for_band(priv, conf->channel->band);
  2473. /* The list of supported rates and rate mask can be different
  2474. * for each band; since the band may have changed, reset
  2475. * the rate mask to what mac80211 lists */
  2476. iwl4965_set_rate(priv);
  2477. spin_unlock_irqrestore(&priv->lock, flags);
  2478. #ifdef IEEE80211_CONF_CHANNEL_SWITCH
  2479. if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
  2480. iwl4965_hw_channel_switch(priv, conf->channel);
  2481. goto out;
  2482. }
  2483. #endif
  2484. if (!conf->radio_enabled) {
  2485. IWL_DEBUG_MAC80211("leave - radio disabled\n");
  2486. goto out;
  2487. }
  2488. if (iwl_is_rfkill(priv)) {
  2489. IWL_DEBUG_MAC80211("leave - RF kill\n");
  2490. ret = -EIO;
  2491. goto out;
  2492. }
  2493. IWL_DEBUG_MAC80211("TX Power old=%d new=%d\n",
  2494. priv->tx_power_user_lmt, conf->power_level);
  2495. iwl_set_tx_power(priv, conf->power_level, false);
  2496. iwl4965_set_rate(priv);
  2497. if (memcmp(&priv->active_rxon,
  2498. &priv->staging_rxon, sizeof(priv->staging_rxon)))
  2499. iwl4965_commit_rxon(priv);
  2500. else
  2501. IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
  2502. IWL_DEBUG_MAC80211("leave\n");
  2503. out:
  2504. clear_bit(STATUS_CONF_PENDING, &priv->status);
  2505. mutex_unlock(&priv->mutex);
  2506. return ret;
  2507. }
  2508. static void iwl4965_config_ap(struct iwl_priv *priv)
  2509. {
  2510. int ret = 0;
  2511. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2512. return;
  2513. /* The following should be done only at AP bring up */
  2514. if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) {
  2515. /* RXON - unassoc (to set timing command) */
  2516. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2517. iwl4965_commit_rxon(priv);
  2518. /* RXON Timing */
  2519. memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
  2520. iwl4965_setup_rxon_timing(priv);
  2521. ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
  2522. sizeof(priv->rxon_timing), &priv->rxon_timing);
  2523. if (ret)
  2524. IWL_WARNING("REPLY_RXON_TIMING failed - "
  2525. "Attempting to continue.\n");
  2526. iwl_set_rxon_chain(priv);
  2527. /* FIXME: what should be the assoc_id for AP? */
  2528. priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
  2529. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  2530. priv->staging_rxon.flags |=
  2531. RXON_FLG_SHORT_PREAMBLE_MSK;
  2532. else
  2533. priv->staging_rxon.flags &=
  2534. ~RXON_FLG_SHORT_PREAMBLE_MSK;
  2535. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
  2536. if (priv->assoc_capability &
  2537. WLAN_CAPABILITY_SHORT_SLOT_TIME)
  2538. priv->staging_rxon.flags |=
  2539. RXON_FLG_SHORT_SLOT_MSK;
  2540. else
  2541. priv->staging_rxon.flags &=
  2542. ~RXON_FLG_SHORT_SLOT_MSK;
  2543. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  2544. priv->staging_rxon.flags &=
  2545. ~RXON_FLG_SHORT_SLOT_MSK;
  2546. }
  2547. /* restore RXON assoc */
  2548. priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  2549. iwl4965_commit_rxon(priv);
  2550. iwl4965_activate_qos(priv, 1);
  2551. iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
  2552. }
  2553. iwl4965_send_beacon_cmd(priv);
  2554. /* FIXME - we need to add code here to detect a totally new
  2555. * configuration, reset the AP, unassoc, rxon timing, assoc,
  2556. * clear sta table, add BCAST sta... */
  2557. }
  2558. static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
  2559. struct ieee80211_vif *vif,
  2560. struct ieee80211_if_conf *conf)
  2561. {
  2562. struct iwl_priv *priv = hw->priv;
  2563. DECLARE_MAC_BUF(mac);
  2564. unsigned long flags;
  2565. int rc;
  2566. if (conf == NULL)
  2567. return -EIO;
  2568. if (priv->vif != vif) {
  2569. IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
  2570. return 0;
  2571. }
  2572. if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
  2573. (!conf->beacon || !conf->ssid_len)) {
  2574. IWL_DEBUG_MAC80211
  2575. ("Leaving in AP mode because HostAPD is not ready.\n");
  2576. return 0;
  2577. }
  2578. if (!iwl_is_alive(priv))
  2579. return -EAGAIN;
  2580. mutex_lock(&priv->mutex);
  2581. if (conf->bssid)
  2582. IWL_DEBUG_MAC80211("bssid: %s\n",
  2583. print_mac(mac, conf->bssid));
  2584. /*
  2585. * very dubious code was here; the probe filtering flag is never set:
  2586. *
  2587. if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
  2588. !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
  2589. */
  2590. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  2591. if (!conf->bssid) {
  2592. conf->bssid = priv->mac_addr;
  2593. memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
  2594. IWL_DEBUG_MAC80211("bssid was set to: %s\n",
  2595. print_mac(mac, conf->bssid));
  2596. }
  2597. if (priv->ibss_beacon)
  2598. dev_kfree_skb(priv->ibss_beacon);
  2599. priv->ibss_beacon = conf->beacon;
  2600. }
  2601. if (iwl_is_rfkill(priv))
  2602. goto done;
  2603. if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
  2604. !is_multicast_ether_addr(conf->bssid)) {
  2605. /* If there is currently a HW scan going on in the background
  2606. * then we need to cancel it else the RXON below will fail. */
  2607. if (iwl_scan_cancel_timeout(priv, 100)) {
  2608. IWL_WARNING("Aborted scan still in progress "
  2609. "after 100ms\n");
  2610. IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
  2611. mutex_unlock(&priv->mutex);
  2612. return -EAGAIN;
  2613. }
  2614. memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
  2615. /* TODO: Audit driver for usage of these members and see
  2616. * if mac80211 deprecates them (priv->bssid looks like it
  2617. * shouldn't be there, but I haven't scanned the IBSS code
  2618. * to verify) - jpk */
  2619. memcpy(priv->bssid, conf->bssid, ETH_ALEN);
  2620. if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
  2621. iwl4965_config_ap(priv);
  2622. else {
  2623. rc = iwl4965_commit_rxon(priv);
  2624. if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc)
  2625. iwl_rxon_add_station(
  2626. priv, priv->active_rxon.bssid_addr, 1);
  2627. }
  2628. } else {
  2629. iwl_scan_cancel_timeout(priv, 100);
  2630. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2631. iwl4965_commit_rxon(priv);
  2632. }
  2633. done:
  2634. spin_lock_irqsave(&priv->lock, flags);
  2635. if (!conf->ssid_len)
  2636. memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
  2637. else
  2638. memcpy(priv->essid, conf->ssid, conf->ssid_len);
  2639. priv->essid_len = conf->ssid_len;
  2640. spin_unlock_irqrestore(&priv->lock, flags);
  2641. IWL_DEBUG_MAC80211("leave\n");
  2642. mutex_unlock(&priv->mutex);
  2643. return 0;
  2644. }
  2645. static void iwl4965_configure_filter(struct ieee80211_hw *hw,
  2646. unsigned int changed_flags,
  2647. unsigned int *total_flags,
  2648. int mc_count, struct dev_addr_list *mc_list)
  2649. {
  2650. /*
  2651. * XXX: dummy
  2652. * see also iwl4965_connection_init_rx_config
  2653. */
  2654. struct iwl_priv *priv = hw->priv;
  2655. int new_flags = 0;
  2656. if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) {
  2657. if (*total_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) {
  2658. IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n",
  2659. IEEE80211_IF_TYPE_MNTR,
  2660. changed_flags, *total_flags);
  2661. /* queue work 'cuz mac80211 is holding a lock which
  2662. * prevents us from issuing (synchronous) f/w cmds */
  2663. queue_work(priv->workqueue, &priv->set_monitor);
  2664. new_flags &= FIF_PROMISC_IN_BSS |
  2665. FIF_OTHER_BSS |
  2666. FIF_ALLMULTI;
  2667. }
  2668. }
  2669. *total_flags = new_flags;
  2670. }
  2671. static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
  2672. struct ieee80211_if_init_conf *conf)
  2673. {
  2674. struct iwl_priv *priv = hw->priv;
  2675. IWL_DEBUG_MAC80211("enter\n");
  2676. mutex_lock(&priv->mutex);
  2677. if (iwl_is_ready_rf(priv)) {
  2678. iwl_scan_cancel_timeout(priv, 100);
  2679. cancel_delayed_work(&priv->post_associate);
  2680. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2681. iwl4965_commit_rxon(priv);
  2682. }
  2683. if (priv->vif == conf->vif) {
  2684. priv->vif = NULL;
  2685. memset(priv->bssid, 0, ETH_ALEN);
  2686. memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
  2687. priv->essid_len = 0;
  2688. }
  2689. mutex_unlock(&priv->mutex);
  2690. IWL_DEBUG_MAC80211("leave\n");
  2691. }
  2692. #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
  2693. static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
  2694. struct ieee80211_vif *vif,
  2695. struct ieee80211_bss_conf *bss_conf,
  2696. u32 changes)
  2697. {
  2698. struct iwl_priv *priv = hw->priv;
  2699. IWL_DEBUG_MAC80211("changes = 0x%X\n", changes);
  2700. if (changes & BSS_CHANGED_ERP_PREAMBLE) {
  2701. IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
  2702. bss_conf->use_short_preamble);
  2703. if (bss_conf->use_short_preamble)
  2704. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  2705. else
  2706. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  2707. }
  2708. if (changes & BSS_CHANGED_ERP_CTS_PROT) {
  2709. IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot);
  2710. if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
  2711. priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
  2712. else
  2713. priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
  2714. }
  2715. if (changes & BSS_CHANGED_HT) {
  2716. IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht);
  2717. iwl4965_ht_conf(priv, bss_conf);
  2718. iwl_set_rxon_chain(priv);
  2719. }
  2720. if (changes & BSS_CHANGED_ASSOC) {
  2721. IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc);
  2722. /* This should never happen as this function should
  2723. * never be called from interrupt context. */
  2724. if (WARN_ON_ONCE(in_interrupt()))
  2725. return;
  2726. if (bss_conf->assoc) {
  2727. priv->assoc_id = bss_conf->aid;
  2728. priv->beacon_int = bss_conf->beacon_int;
  2729. priv->timestamp = bss_conf->timestamp;
  2730. priv->assoc_capability = bss_conf->assoc_capability;
  2731. priv->next_scan_jiffies = jiffies +
  2732. IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
  2733. mutex_lock(&priv->mutex);
  2734. iwl4965_post_associate(priv);
  2735. mutex_unlock(&priv->mutex);
  2736. } else {
  2737. priv->assoc_id = 0;
  2738. IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc);
  2739. }
  2740. } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
  2741. IWL_DEBUG_MAC80211("Associated Changes %d\n", changes);
  2742. iwl_send_rxon_assoc(priv);
  2743. }
  2744. }
  2745. static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
  2746. {
  2747. int rc = 0;
  2748. unsigned long flags;
  2749. struct iwl_priv *priv = hw->priv;
  2750. IWL_DEBUG_MAC80211("enter\n");
  2751. mutex_lock(&priv->mutex);
  2752. spin_lock_irqsave(&priv->lock, flags);
  2753. if (!iwl_is_ready_rf(priv)) {
  2754. rc = -EIO;
  2755. IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
  2756. goto out_unlock;
  2757. }
  2758. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */
  2759. rc = -EIO;
  2760. IWL_ERROR("ERROR: APs don't scan\n");
  2761. goto out_unlock;
  2762. }
  2763. /* we don't schedule scan within next_scan_jiffies period */
  2764. if (priv->next_scan_jiffies &&
  2765. time_after(priv->next_scan_jiffies, jiffies)) {
  2766. rc = -EAGAIN;
  2767. goto out_unlock;
  2768. }
  2769. /* if we just finished scan ask for delay */
  2770. if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies +
  2771. IWL_DELAY_NEXT_SCAN, jiffies)) {
  2772. rc = -EAGAIN;
  2773. goto out_unlock;
  2774. }
  2775. if (len) {
  2776. IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
  2777. iwl_escape_essid(ssid, len), (int)len);
  2778. priv->one_direct_scan = 1;
  2779. priv->direct_ssid_len = (u8)
  2780. min((u8) len, (u8) IW_ESSID_MAX_SIZE);
  2781. memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
  2782. } else
  2783. priv->one_direct_scan = 0;
  2784. rc = iwl_scan_initiate(priv);
  2785. IWL_DEBUG_MAC80211("leave\n");
  2786. out_unlock:
  2787. spin_unlock_irqrestore(&priv->lock, flags);
  2788. mutex_unlock(&priv->mutex);
  2789. return rc;
  2790. }
  2791. static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw,
  2792. struct ieee80211_key_conf *keyconf, const u8 *addr,
  2793. u32 iv32, u16 *phase1key)
  2794. {
  2795. struct iwl_priv *priv = hw->priv;
  2796. u8 sta_id = IWL_INVALID_STATION;
  2797. unsigned long flags;
  2798. __le16 key_flags = 0;
  2799. int i;
  2800. DECLARE_MAC_BUF(mac);
  2801. IWL_DEBUG_MAC80211("enter\n");
  2802. sta_id = iwl_find_station(priv, addr);
  2803. if (sta_id == IWL_INVALID_STATION) {
  2804. IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
  2805. print_mac(mac, addr));
  2806. return;
  2807. }
  2808. iwl_scan_cancel_timeout(priv, 100);
  2809. key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
  2810. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  2811. key_flags &= ~STA_KEY_FLG_INVALID;
  2812. if (sta_id == priv->hw_params.bcast_sta_id)
  2813. key_flags |= STA_KEY_MULTICAST_MSK;
  2814. spin_lock_irqsave(&priv->sta_lock, flags);
  2815. priv->stations[sta_id].sta.key.key_flags = key_flags;
  2816. priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
  2817. for (i = 0; i < 5; i++)
  2818. priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
  2819. cpu_to_le16(phase1key[i]);
  2820. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  2821. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2822. iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  2823. spin_unlock_irqrestore(&priv->sta_lock, flags);
  2824. IWL_DEBUG_MAC80211("leave\n");
  2825. }
  2826. static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  2827. const u8 *local_addr, const u8 *addr,
  2828. struct ieee80211_key_conf *key)
  2829. {
  2830. struct iwl_priv *priv = hw->priv;
  2831. DECLARE_MAC_BUF(mac);
  2832. int ret = 0;
  2833. u8 sta_id = IWL_INVALID_STATION;
  2834. u8 is_default_wep_key = 0;
  2835. IWL_DEBUG_MAC80211("enter\n");
  2836. if (priv->hw_params.sw_crypto) {
  2837. IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
  2838. return -EOPNOTSUPP;
  2839. }
  2840. if (is_zero_ether_addr(addr))
  2841. /* only support pairwise keys */
  2842. return -EOPNOTSUPP;
  2843. sta_id = iwl_find_station(priv, addr);
  2844. if (sta_id == IWL_INVALID_STATION) {
  2845. IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
  2846. print_mac(mac, addr));
  2847. return -EINVAL;
  2848. }
  2849. mutex_lock(&priv->mutex);
  2850. iwl_scan_cancel_timeout(priv, 100);
  2851. mutex_unlock(&priv->mutex);
  2852. /* If we are getting WEP group key and we didn't receive any key mapping
  2853. * so far, we are in legacy wep mode (group key only), otherwise we are
  2854. * in 1X mode.
  2855. * In legacy wep mode, we use another host command to the uCode */
  2856. if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id &&
  2857. priv->iw_mode != IEEE80211_IF_TYPE_AP) {
  2858. if (cmd == SET_KEY)
  2859. is_default_wep_key = !priv->key_mapping_key;
  2860. else
  2861. is_default_wep_key =
  2862. (key->hw_key_idx == HW_KEY_DEFAULT);
  2863. }
  2864. switch (cmd) {
  2865. case SET_KEY:
  2866. if (is_default_wep_key)
  2867. ret = iwl_set_default_wep_key(priv, key);
  2868. else
  2869. ret = iwl_set_dynamic_key(priv, key, sta_id);
  2870. IWL_DEBUG_MAC80211("enable hwcrypto key\n");
  2871. break;
  2872. case DISABLE_KEY:
  2873. if (is_default_wep_key)
  2874. ret = iwl_remove_default_wep_key(priv, key);
  2875. else
  2876. ret = iwl_remove_dynamic_key(priv, key, sta_id);
  2877. IWL_DEBUG_MAC80211("disable hwcrypto key\n");
  2878. break;
  2879. default:
  2880. ret = -EINVAL;
  2881. }
  2882. IWL_DEBUG_MAC80211("leave\n");
  2883. return ret;
  2884. }
  2885. static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  2886. const struct ieee80211_tx_queue_params *params)
  2887. {
  2888. struct iwl_priv *priv = hw->priv;
  2889. unsigned long flags;
  2890. int q;
  2891. IWL_DEBUG_MAC80211("enter\n");
  2892. if (!iwl_is_ready_rf(priv)) {
  2893. IWL_DEBUG_MAC80211("leave - RF not ready\n");
  2894. return -EIO;
  2895. }
  2896. if (queue >= AC_NUM) {
  2897. IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
  2898. return 0;
  2899. }
  2900. if (!priv->qos_data.qos_enable) {
  2901. priv->qos_data.qos_active = 0;
  2902. IWL_DEBUG_MAC80211("leave - qos not enabled\n");
  2903. return 0;
  2904. }
  2905. q = AC_NUM - 1 - queue;
  2906. spin_lock_irqsave(&priv->lock, flags);
  2907. priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
  2908. priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
  2909. priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
  2910. priv->qos_data.def_qos_parm.ac[q].edca_txop =
  2911. cpu_to_le16((params->txop * 32));
  2912. priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
  2913. priv->qos_data.qos_active = 1;
  2914. spin_unlock_irqrestore(&priv->lock, flags);
  2915. mutex_lock(&priv->mutex);
  2916. if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
  2917. iwl4965_activate_qos(priv, 1);
  2918. else if (priv->assoc_id && iwl_is_associated(priv))
  2919. iwl4965_activate_qos(priv, 0);
  2920. mutex_unlock(&priv->mutex);
  2921. IWL_DEBUG_MAC80211("leave\n");
  2922. return 0;
  2923. }
  2924. static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
  2925. struct ieee80211_tx_queue_stats *stats)
  2926. {
  2927. struct iwl_priv *priv = hw->priv;
  2928. int i, avail;
  2929. struct iwl_tx_queue *txq;
  2930. struct iwl_queue *q;
  2931. unsigned long flags;
  2932. IWL_DEBUG_MAC80211("enter\n");
  2933. if (!iwl_is_ready_rf(priv)) {
  2934. IWL_DEBUG_MAC80211("leave - RF not ready\n");
  2935. return -EIO;
  2936. }
  2937. spin_lock_irqsave(&priv->lock, flags);
  2938. for (i = 0; i < AC_NUM; i++) {
  2939. txq = &priv->txq[i];
  2940. q = &txq->q;
  2941. avail = iwl_queue_space(q);
  2942. stats[i].len = q->n_window - avail;
  2943. stats[i].limit = q->n_window - q->high_mark;
  2944. stats[i].count = q->n_window;
  2945. }
  2946. spin_unlock_irqrestore(&priv->lock, flags);
  2947. IWL_DEBUG_MAC80211("leave\n");
  2948. return 0;
  2949. }
  2950. static int iwl4965_mac_get_stats(struct ieee80211_hw *hw,
  2951. struct ieee80211_low_level_stats *stats)
  2952. {
  2953. struct iwl_priv *priv = hw->priv;
  2954. priv = hw->priv;
  2955. IWL_DEBUG_MAC80211("enter\n");
  2956. IWL_DEBUG_MAC80211("leave\n");
  2957. return 0;
  2958. }
  2959. static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw)
  2960. {
  2961. struct iwl_priv *priv;
  2962. priv = hw->priv;
  2963. IWL_DEBUG_MAC80211("enter\n");
  2964. IWL_DEBUG_MAC80211("leave\n");
  2965. return 0;
  2966. }
  2967. static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
  2968. {
  2969. struct iwl_priv *priv = hw->priv;
  2970. unsigned long flags;
  2971. mutex_lock(&priv->mutex);
  2972. IWL_DEBUG_MAC80211("enter\n");
  2973. priv->lq_mngr.lq_ready = 0;
  2974. spin_lock_irqsave(&priv->lock, flags);
  2975. memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
  2976. spin_unlock_irqrestore(&priv->lock, flags);
  2977. iwl_reset_qos(priv);
  2978. cancel_delayed_work(&priv->post_associate);
  2979. spin_lock_irqsave(&priv->lock, flags);
  2980. priv->assoc_id = 0;
  2981. priv->assoc_capability = 0;
  2982. priv->assoc_station_added = 0;
  2983. /* new association get rid of ibss beacon skb */
  2984. if (priv->ibss_beacon)
  2985. dev_kfree_skb(priv->ibss_beacon);
  2986. priv->ibss_beacon = NULL;
  2987. priv->beacon_int = priv->hw->conf.beacon_int;
  2988. priv->timestamp = 0;
  2989. if ((priv->iw_mode == IEEE80211_IF_TYPE_STA))
  2990. priv->beacon_int = 0;
  2991. spin_unlock_irqrestore(&priv->lock, flags);
  2992. if (!iwl_is_ready_rf(priv)) {
  2993. IWL_DEBUG_MAC80211("leave - not ready\n");
  2994. mutex_unlock(&priv->mutex);
  2995. return;
  2996. }
  2997. /* we are restarting association process
  2998. * clear RXON_FILTER_ASSOC_MSK bit
  2999. */
  3000. if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
  3001. iwl_scan_cancel_timeout(priv, 100);
  3002. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3003. iwl4965_commit_rxon(priv);
  3004. }
  3005. iwl_power_update_mode(priv, 0);
  3006. /* Per mac80211.h: This is only used in IBSS mode... */
  3007. if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
  3008. IWL_DEBUG_MAC80211("leave - not in IBSS\n");
  3009. mutex_unlock(&priv->mutex);
  3010. return;
  3011. }
  3012. iwl4965_set_rate(priv);
  3013. mutex_unlock(&priv->mutex);
  3014. IWL_DEBUG_MAC80211("leave\n");
  3015. }
  3016. static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
  3017. {
  3018. struct iwl_priv *priv = hw->priv;
  3019. unsigned long flags;
  3020. mutex_lock(&priv->mutex);
  3021. IWL_DEBUG_MAC80211("enter\n");
  3022. if (!iwl_is_ready_rf(priv)) {
  3023. IWL_DEBUG_MAC80211("leave - RF not ready\n");
  3024. mutex_unlock(&priv->mutex);
  3025. return -EIO;
  3026. }
  3027. if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
  3028. IWL_DEBUG_MAC80211("leave - not IBSS\n");
  3029. mutex_unlock(&priv->mutex);
  3030. return -EIO;
  3031. }
  3032. spin_lock_irqsave(&priv->lock, flags);
  3033. if (priv->ibss_beacon)
  3034. dev_kfree_skb(priv->ibss_beacon);
  3035. priv->ibss_beacon = skb;
  3036. priv->assoc_id = 0;
  3037. IWL_DEBUG_MAC80211("leave\n");
  3038. spin_unlock_irqrestore(&priv->lock, flags);
  3039. iwl_reset_qos(priv);
  3040. iwl4965_post_associate(priv);
  3041. mutex_unlock(&priv->mutex);
  3042. return 0;
  3043. }
  3044. /*****************************************************************************
  3045. *
  3046. * sysfs attributes
  3047. *
  3048. *****************************************************************************/
  3049. #ifdef CONFIG_IWLWIFI_DEBUG
  3050. /*
  3051. * The following adds a new attribute to the sysfs representation
  3052. * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
  3053. * used for controlling the debug level.
  3054. *
  3055. * See the level definitions in iwl for details.
  3056. */
  3057. static ssize_t show_debug_level(struct device *d,
  3058. struct device_attribute *attr, char *buf)
  3059. {
  3060. struct iwl_priv *priv = d->driver_data;
  3061. return sprintf(buf, "0x%08X\n", priv->debug_level);
  3062. }
  3063. static ssize_t store_debug_level(struct device *d,
  3064. struct device_attribute *attr,
  3065. const char *buf, size_t count)
  3066. {
  3067. struct iwl_priv *priv = d->driver_data;
  3068. char *p = (char *)buf;
  3069. u32 val;
  3070. val = simple_strtoul(p, &p, 0);
  3071. if (p == buf)
  3072. printk(KERN_INFO DRV_NAME
  3073. ": %s is not in hex or decimal form.\n", buf);
  3074. else
  3075. priv->debug_level = val;
  3076. return strnlen(buf, count);
  3077. }
  3078. static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
  3079. show_debug_level, store_debug_level);
  3080. #endif /* CONFIG_IWLWIFI_DEBUG */
  3081. static ssize_t show_version(struct device *d,
  3082. struct device_attribute *attr, char *buf)
  3083. {
  3084. struct iwl_priv *priv = d->driver_data;
  3085. struct iwl_alive_resp *palive = &priv->card_alive;
  3086. if (palive->is_valid)
  3087. return sprintf(buf, "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n"
  3088. "fw type: 0x%01X 0x%01X\n",
  3089. palive->ucode_major, palive->ucode_minor,
  3090. palive->sw_rev[0], palive->sw_rev[1],
  3091. palive->ver_type, palive->ver_subtype);
  3092. else
  3093. return sprintf(buf, "fw not loaded\n");
  3094. }
  3095. static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL);
  3096. static ssize_t show_temperature(struct device *d,
  3097. struct device_attribute *attr, char *buf)
  3098. {
  3099. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3100. if (!iwl_is_alive(priv))
  3101. return -EAGAIN;
  3102. return sprintf(buf, "%d\n", priv->temperature);
  3103. }
  3104. static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
  3105. static ssize_t show_rs_window(struct device *d,
  3106. struct device_attribute *attr,
  3107. char *buf)
  3108. {
  3109. struct iwl_priv *priv = d->driver_data;
  3110. return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID);
  3111. }
  3112. static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL);
  3113. static ssize_t show_tx_power(struct device *d,
  3114. struct device_attribute *attr, char *buf)
  3115. {
  3116. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3117. return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
  3118. }
  3119. static ssize_t store_tx_power(struct device *d,
  3120. struct device_attribute *attr,
  3121. const char *buf, size_t count)
  3122. {
  3123. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3124. char *p = (char *)buf;
  3125. u32 val;
  3126. val = simple_strtoul(p, &p, 10);
  3127. if (p == buf)
  3128. printk(KERN_INFO DRV_NAME
  3129. ": %s is not in decimal form.\n", buf);
  3130. else
  3131. iwl_set_tx_power(priv, val, false);
  3132. return count;
  3133. }
  3134. static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
  3135. static ssize_t show_flags(struct device *d,
  3136. struct device_attribute *attr, char *buf)
  3137. {
  3138. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3139. return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
  3140. }
  3141. static ssize_t store_flags(struct device *d,
  3142. struct device_attribute *attr,
  3143. const char *buf, size_t count)
  3144. {
  3145. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3146. u32 flags = simple_strtoul(buf, NULL, 0);
  3147. mutex_lock(&priv->mutex);
  3148. if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
  3149. /* Cancel any currently running scans... */
  3150. if (iwl_scan_cancel_timeout(priv, 100))
  3151. IWL_WARNING("Could not cancel scan.\n");
  3152. else {
  3153. IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
  3154. flags);
  3155. priv->staging_rxon.flags = cpu_to_le32(flags);
  3156. iwl4965_commit_rxon(priv);
  3157. }
  3158. }
  3159. mutex_unlock(&priv->mutex);
  3160. return count;
  3161. }
  3162. static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
  3163. static ssize_t show_filter_flags(struct device *d,
  3164. struct device_attribute *attr, char *buf)
  3165. {
  3166. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3167. return sprintf(buf, "0x%04X\n",
  3168. le32_to_cpu(priv->active_rxon.filter_flags));
  3169. }
  3170. static ssize_t store_filter_flags(struct device *d,
  3171. struct device_attribute *attr,
  3172. const char *buf, size_t count)
  3173. {
  3174. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3175. u32 filter_flags = simple_strtoul(buf, NULL, 0);
  3176. mutex_lock(&priv->mutex);
  3177. if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
  3178. /* Cancel any currently running scans... */
  3179. if (iwl_scan_cancel_timeout(priv, 100))
  3180. IWL_WARNING("Could not cancel scan.\n");
  3181. else {
  3182. IWL_DEBUG_INFO("Committing rxon.filter_flags = "
  3183. "0x%04X\n", filter_flags);
  3184. priv->staging_rxon.filter_flags =
  3185. cpu_to_le32(filter_flags);
  3186. iwl4965_commit_rxon(priv);
  3187. }
  3188. }
  3189. mutex_unlock(&priv->mutex);
  3190. return count;
  3191. }
  3192. static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
  3193. store_filter_flags);
  3194. #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
  3195. static ssize_t show_measurement(struct device *d,
  3196. struct device_attribute *attr, char *buf)
  3197. {
  3198. struct iwl_priv *priv = dev_get_drvdata(d);
  3199. struct iwl4965_spectrum_notification measure_report;
  3200. u32 size = sizeof(measure_report), len = 0, ofs = 0;
  3201. u8 *data = (u8 *) & measure_report;
  3202. unsigned long flags;
  3203. spin_lock_irqsave(&priv->lock, flags);
  3204. if (!(priv->measurement_status & MEASUREMENT_READY)) {
  3205. spin_unlock_irqrestore(&priv->lock, flags);
  3206. return 0;
  3207. }
  3208. memcpy(&measure_report, &priv->measure_report, size);
  3209. priv->measurement_status = 0;
  3210. spin_unlock_irqrestore(&priv->lock, flags);
  3211. while (size && (PAGE_SIZE - len)) {
  3212. hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
  3213. PAGE_SIZE - len, 1);
  3214. len = strlen(buf);
  3215. if (PAGE_SIZE - len)
  3216. buf[len++] = '\n';
  3217. ofs += 16;
  3218. size -= min(size, 16U);
  3219. }
  3220. return len;
  3221. }
  3222. static ssize_t store_measurement(struct device *d,
  3223. struct device_attribute *attr,
  3224. const char *buf, size_t count)
  3225. {
  3226. struct iwl_priv *priv = dev_get_drvdata(d);
  3227. struct ieee80211_measurement_params params = {
  3228. .channel = le16_to_cpu(priv->active_rxon.channel),
  3229. .start_time = cpu_to_le64(priv->last_tsf),
  3230. .duration = cpu_to_le16(1),
  3231. };
  3232. u8 type = IWL_MEASURE_BASIC;
  3233. u8 buffer[32];
  3234. u8 channel;
  3235. if (count) {
  3236. char *p = buffer;
  3237. strncpy(buffer, buf, min(sizeof(buffer), count));
  3238. channel = simple_strtoul(p, NULL, 0);
  3239. if (channel)
  3240. params.channel = channel;
  3241. p = buffer;
  3242. while (*p && *p != ' ')
  3243. p++;
  3244. if (*p)
  3245. type = simple_strtoul(p + 1, NULL, 0);
  3246. }
  3247. IWL_DEBUG_INFO("Invoking measurement of type %d on "
  3248. "channel %d (for '%s')\n", type, params.channel, buf);
  3249. iwl4965_get_measurement(priv, &params, type);
  3250. return count;
  3251. }
  3252. static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
  3253. show_measurement, store_measurement);
  3254. #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
  3255. static ssize_t store_retry_rate(struct device *d,
  3256. struct device_attribute *attr,
  3257. const char *buf, size_t count)
  3258. {
  3259. struct iwl_priv *priv = dev_get_drvdata(d);
  3260. priv->retry_rate = simple_strtoul(buf, NULL, 0);
  3261. if (priv->retry_rate <= 0)
  3262. priv->retry_rate = 1;
  3263. return count;
  3264. }
  3265. static ssize_t show_retry_rate(struct device *d,
  3266. struct device_attribute *attr, char *buf)
  3267. {
  3268. struct iwl_priv *priv = dev_get_drvdata(d);
  3269. return sprintf(buf, "%d", priv->retry_rate);
  3270. }
  3271. static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
  3272. store_retry_rate);
  3273. static ssize_t store_power_level(struct device *d,
  3274. struct device_attribute *attr,
  3275. const char *buf, size_t count)
  3276. {
  3277. struct iwl_priv *priv = dev_get_drvdata(d);
  3278. int rc;
  3279. int mode;
  3280. mode = simple_strtoul(buf, NULL, 0);
  3281. mutex_lock(&priv->mutex);
  3282. if (!iwl_is_ready(priv)) {
  3283. rc = -EAGAIN;
  3284. goto out;
  3285. }
  3286. rc = iwl_power_set_user_mode(priv, mode);
  3287. if (rc) {
  3288. IWL_DEBUG_MAC80211("failed setting power mode.\n");
  3289. goto out;
  3290. }
  3291. rc = count;
  3292. out:
  3293. mutex_unlock(&priv->mutex);
  3294. return rc;
  3295. }
  3296. #define MAX_WX_STRING 80
  3297. /* Values are in microsecond */
  3298. static const s32 timeout_duration[] = {
  3299. 350000,
  3300. 250000,
  3301. 75000,
  3302. 37000,
  3303. 25000,
  3304. };
  3305. static const s32 period_duration[] = {
  3306. 400000,
  3307. 700000,
  3308. 1000000,
  3309. 1000000,
  3310. 1000000
  3311. };
  3312. static ssize_t show_power_level(struct device *d,
  3313. struct device_attribute *attr, char *buf)
  3314. {
  3315. struct iwl_priv *priv = dev_get_drvdata(d);
  3316. int level = priv->power_data.power_mode;
  3317. char *p = buf;
  3318. p += sprintf(p, "%d ", level);
  3319. switch (level) {
  3320. case IWL_POWER_MODE_CAM:
  3321. case IWL_POWER_AC:
  3322. p += sprintf(p, "(AC)");
  3323. break;
  3324. case IWL_POWER_BATTERY:
  3325. p += sprintf(p, "(BATTERY)");
  3326. break;
  3327. default:
  3328. p += sprintf(p,
  3329. "(Timeout %dms, Period %dms)",
  3330. timeout_duration[level - 1] / 1000,
  3331. period_duration[level - 1] / 1000);
  3332. }
  3333. /*
  3334. if (!(priv->power_mode & IWL_POWER_ENABLED))
  3335. p += sprintf(p, " OFF\n");
  3336. else
  3337. p += sprintf(p, " \n");
  3338. */
  3339. p += sprintf(p, " \n");
  3340. return (p - buf + 1);
  3341. }
  3342. static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
  3343. store_power_level);
  3344. static ssize_t show_channels(struct device *d,
  3345. struct device_attribute *attr, char *buf)
  3346. {
  3347. struct iwl_priv *priv = dev_get_drvdata(d);
  3348. struct ieee80211_channel *channels = NULL;
  3349. const struct ieee80211_supported_band *supp_band = NULL;
  3350. int len = 0, i;
  3351. int count = 0;
  3352. if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
  3353. return -EAGAIN;
  3354. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
  3355. channels = supp_band->channels;
  3356. count = supp_band->n_channels;
  3357. len += sprintf(&buf[len],
  3358. "Displaying %d channels in 2.4GHz band "
  3359. "(802.11bg):\n", count);
  3360. for (i = 0; i < count; i++)
  3361. len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
  3362. ieee80211_frequency_to_channel(
  3363. channels[i].center_freq),
  3364. channels[i].max_power,
  3365. channels[i].flags & IEEE80211_CHAN_RADAR ?
  3366. " (IEEE 802.11h required)" : "",
  3367. (!(channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  3368. || (channels[i].flags &
  3369. IEEE80211_CHAN_RADAR)) ? "" :
  3370. ", IBSS",
  3371. channels[i].flags &
  3372. IEEE80211_CHAN_PASSIVE_SCAN ?
  3373. "passive only" : "active/passive");
  3374. supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
  3375. channels = supp_band->channels;
  3376. count = supp_band->n_channels;
  3377. len += sprintf(&buf[len], "Displaying %d channels in 5.2GHz band "
  3378. "(802.11a):\n", count);
  3379. for (i = 0; i < count; i++)
  3380. len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
  3381. ieee80211_frequency_to_channel(
  3382. channels[i].center_freq),
  3383. channels[i].max_power,
  3384. channels[i].flags & IEEE80211_CHAN_RADAR ?
  3385. " (IEEE 802.11h required)" : "",
  3386. ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
  3387. || (channels[i].flags &
  3388. IEEE80211_CHAN_RADAR)) ? "" :
  3389. ", IBSS",
  3390. channels[i].flags &
  3391. IEEE80211_CHAN_PASSIVE_SCAN ?
  3392. "passive only" : "active/passive");
  3393. return len;
  3394. }
  3395. static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
  3396. static ssize_t show_statistics(struct device *d,
  3397. struct device_attribute *attr, char *buf)
  3398. {
  3399. struct iwl_priv *priv = dev_get_drvdata(d);
  3400. u32 size = sizeof(struct iwl4965_notif_statistics);
  3401. u32 len = 0, ofs = 0;
  3402. u8 *data = (u8 *) & priv->statistics;
  3403. int rc = 0;
  3404. if (!iwl_is_alive(priv))
  3405. return -EAGAIN;
  3406. mutex_lock(&priv->mutex);
  3407. rc = iwl_send_statistics_request(priv, 0);
  3408. mutex_unlock(&priv->mutex);
  3409. if (rc) {
  3410. len = sprintf(buf,
  3411. "Error sending statistics request: 0x%08X\n", rc);
  3412. return len;
  3413. }
  3414. while (size && (PAGE_SIZE - len)) {
  3415. hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
  3416. PAGE_SIZE - len, 1);
  3417. len = strlen(buf);
  3418. if (PAGE_SIZE - len)
  3419. buf[len++] = '\n';
  3420. ofs += 16;
  3421. size -= min(size, 16U);
  3422. }
  3423. return len;
  3424. }
  3425. static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
  3426. static ssize_t show_status(struct device *d,
  3427. struct device_attribute *attr, char *buf)
  3428. {
  3429. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3430. if (!iwl_is_alive(priv))
  3431. return -EAGAIN;
  3432. return sprintf(buf, "0x%08x\n", (int)priv->status);
  3433. }
  3434. static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
  3435. /*****************************************************************************
  3436. *
  3437. * driver setup and teardown
  3438. *
  3439. *****************************************************************************/
  3440. static void iwl_setup_deferred_work(struct iwl_priv *priv)
  3441. {
  3442. priv->workqueue = create_workqueue(DRV_NAME);
  3443. init_waitqueue_head(&priv->wait_command_queue);
  3444. INIT_WORK(&priv->up, iwl4965_bg_up);
  3445. INIT_WORK(&priv->restart, iwl4965_bg_restart);
  3446. INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish);
  3447. INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill);
  3448. INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update);
  3449. INIT_WORK(&priv->set_monitor, iwl4965_bg_set_monitor);
  3450. INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
  3451. INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate);
  3452. INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
  3453. INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
  3454. /* FIXME : remove when resolved PENDING */
  3455. INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
  3456. iwl_setup_scan_deferred_work(priv);
  3457. if (priv->cfg->ops->lib->setup_deferred_work)
  3458. priv->cfg->ops->lib->setup_deferred_work(priv);
  3459. init_timer(&priv->statistics_periodic);
  3460. priv->statistics_periodic.data = (unsigned long)priv;
  3461. priv->statistics_periodic.function = iwl4965_bg_statistics_periodic;
  3462. tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
  3463. iwl4965_irq_tasklet, (unsigned long)priv);
  3464. }
  3465. static void iwl_cancel_deferred_work(struct iwl_priv *priv)
  3466. {
  3467. if (priv->cfg->ops->lib->cancel_deferred_work)
  3468. priv->cfg->ops->lib->cancel_deferred_work(priv);
  3469. cancel_delayed_work_sync(&priv->init_alive_start);
  3470. cancel_delayed_work(&priv->scan_check);
  3471. cancel_delayed_work(&priv->alive_start);
  3472. cancel_delayed_work(&priv->post_associate);
  3473. cancel_work_sync(&priv->beacon_update);
  3474. del_timer_sync(&priv->statistics_periodic);
  3475. }
  3476. static struct attribute *iwl4965_sysfs_entries[] = {
  3477. &dev_attr_channels.attr,
  3478. &dev_attr_flags.attr,
  3479. &dev_attr_filter_flags.attr,
  3480. #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
  3481. &dev_attr_measurement.attr,
  3482. #endif
  3483. &dev_attr_power_level.attr,
  3484. &dev_attr_retry_rate.attr,
  3485. &dev_attr_rs_window.attr,
  3486. &dev_attr_statistics.attr,
  3487. &dev_attr_status.attr,
  3488. &dev_attr_temperature.attr,
  3489. &dev_attr_tx_power.attr,
  3490. #ifdef CONFIG_IWLWIFI_DEBUG
  3491. &dev_attr_debug_level.attr,
  3492. #endif
  3493. &dev_attr_version.attr,
  3494. NULL
  3495. };
  3496. static struct attribute_group iwl4965_attribute_group = {
  3497. .name = NULL, /* put in device directory */
  3498. .attrs = iwl4965_sysfs_entries,
  3499. };
  3500. static struct ieee80211_ops iwl4965_hw_ops = {
  3501. .tx = iwl4965_mac_tx,
  3502. .start = iwl4965_mac_start,
  3503. .stop = iwl4965_mac_stop,
  3504. .add_interface = iwl4965_mac_add_interface,
  3505. .remove_interface = iwl4965_mac_remove_interface,
  3506. .config = iwl4965_mac_config,
  3507. .config_interface = iwl4965_mac_config_interface,
  3508. .configure_filter = iwl4965_configure_filter,
  3509. .set_key = iwl4965_mac_set_key,
  3510. .update_tkip_key = iwl4965_mac_update_tkip_key,
  3511. .get_stats = iwl4965_mac_get_stats,
  3512. .get_tx_stats = iwl4965_mac_get_tx_stats,
  3513. .conf_tx = iwl4965_mac_conf_tx,
  3514. .get_tsf = iwl4965_mac_get_tsf,
  3515. .reset_tsf = iwl4965_mac_reset_tsf,
  3516. .beacon_update = iwl4965_mac_beacon_update,
  3517. .bss_info_changed = iwl4965_bss_info_changed,
  3518. .ampdu_action = iwl4965_mac_ampdu_action,
  3519. .hw_scan = iwl4965_mac_hw_scan
  3520. };
  3521. static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  3522. {
  3523. int err = 0;
  3524. struct iwl_priv *priv;
  3525. struct ieee80211_hw *hw;
  3526. struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
  3527. unsigned long flags;
  3528. DECLARE_MAC_BUF(mac);
  3529. /************************
  3530. * 1. Allocating HW data
  3531. ************************/
  3532. /* Disabling hardware scan means that mac80211 will perform scans
  3533. * "the hard way", rather than using device's scan. */
  3534. if (cfg->mod_params->disable_hw_scan) {
  3535. if (cfg->mod_params->debug & IWL_DL_INFO)
  3536. dev_printk(KERN_DEBUG, &(pdev->dev),
  3537. "Disabling hw_scan\n");
  3538. iwl4965_hw_ops.hw_scan = NULL;
  3539. }
  3540. hw = iwl_alloc_all(cfg, &iwl4965_hw_ops);
  3541. if (!hw) {
  3542. err = -ENOMEM;
  3543. goto out;
  3544. }
  3545. priv = hw->priv;
  3546. /* At this point both hw and priv are allocated. */
  3547. SET_IEEE80211_DEV(hw, &pdev->dev);
  3548. IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
  3549. priv->cfg = cfg;
  3550. priv->pci_dev = pdev;
  3551. #ifdef CONFIG_IWLWIFI_DEBUG
  3552. priv->debug_level = priv->cfg->mod_params->debug;
  3553. atomic_set(&priv->restrict_refcnt, 0);
  3554. #endif
  3555. /**************************
  3556. * 2. Initializing PCI bus
  3557. **************************/
  3558. if (pci_enable_device(pdev)) {
  3559. err = -ENODEV;
  3560. goto out_ieee80211_free_hw;
  3561. }
  3562. pci_set_master(pdev);
  3563. err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
  3564. if (!err)
  3565. err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
  3566. if (err) {
  3567. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  3568. if (!err)
  3569. err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  3570. /* both attempts failed: */
  3571. if (err) {
  3572. printk(KERN_WARNING "%s: No suitable DMA available.\n",
  3573. DRV_NAME);
  3574. goto out_pci_disable_device;
  3575. }
  3576. }
  3577. err = pci_request_regions(pdev, DRV_NAME);
  3578. if (err)
  3579. goto out_pci_disable_device;
  3580. pci_set_drvdata(pdev, priv);
  3581. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  3582. * PCI Tx retries from interfering with C3 CPU state */
  3583. pci_write_config_byte(pdev, 0x41, 0x00);
  3584. /***********************
  3585. * 3. Read REV register
  3586. ***********************/
  3587. priv->hw_base = pci_iomap(pdev, 0, 0);
  3588. if (!priv->hw_base) {
  3589. err = -ENODEV;
  3590. goto out_pci_release_regions;
  3591. }
  3592. IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
  3593. (unsigned long long) pci_resource_len(pdev, 0));
  3594. IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
  3595. iwl_hw_detect(priv);
  3596. printk(KERN_INFO DRV_NAME
  3597. ": Detected Intel Wireless WiFi Link %s REV=0x%X\n",
  3598. priv->cfg->name, priv->hw_rev);
  3599. /* amp init */
  3600. err = priv->cfg->ops->lib->apm_ops.init(priv);
  3601. if (err < 0) {
  3602. IWL_DEBUG_INFO("Failed to init APMG\n");
  3603. goto out_iounmap;
  3604. }
  3605. /*****************
  3606. * 4. Read EEPROM
  3607. *****************/
  3608. /* Read the EEPROM */
  3609. err = iwl_eeprom_init(priv);
  3610. if (err) {
  3611. IWL_ERROR("Unable to init EEPROM\n");
  3612. goto out_iounmap;
  3613. }
  3614. err = iwl_eeprom_check_version(priv);
  3615. if (err)
  3616. goto out_iounmap;
  3617. /* extract MAC Address */
  3618. iwl_eeprom_get_mac(priv, priv->mac_addr);
  3619. IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr));
  3620. SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
  3621. /************************
  3622. * 5. Setup HW constants
  3623. ************************/
  3624. /* Device-specific setup */
  3625. if (priv->cfg->ops->lib->set_hw_params(priv)) {
  3626. IWL_ERROR("failed to set hw parameters\n");
  3627. goto out_free_eeprom;
  3628. }
  3629. /*******************
  3630. * 6. Setup priv
  3631. *******************/
  3632. err = iwl_init_drv(priv);
  3633. if (err)
  3634. goto out_free_eeprom;
  3635. /* At this point both hw and priv are initialized. */
  3636. /**********************************
  3637. * 7. Initialize module parameters
  3638. **********************************/
  3639. /* Disable radio (SW RF KILL) via parameter when loading driver */
  3640. if (priv->cfg->mod_params->disable) {
  3641. set_bit(STATUS_RF_KILL_SW, &priv->status);
  3642. IWL_DEBUG_INFO("Radio disabled.\n");
  3643. }
  3644. /********************
  3645. * 8. Setup services
  3646. ********************/
  3647. spin_lock_irqsave(&priv->lock, flags);
  3648. iwl4965_disable_interrupts(priv);
  3649. spin_unlock_irqrestore(&priv->lock, flags);
  3650. err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group);
  3651. if (err) {
  3652. IWL_ERROR("failed to create sysfs device attributes\n");
  3653. goto out_uninit_drv;
  3654. }
  3655. iwl_setup_deferred_work(priv);
  3656. iwl4965_setup_rx_handlers(priv);
  3657. /********************
  3658. * 9. Conclude
  3659. ********************/
  3660. pci_save_state(pdev);
  3661. pci_disable_device(pdev);
  3662. /**********************************
  3663. * 10. Setup and register mac80211
  3664. **********************************/
  3665. err = iwl_setup_mac(priv);
  3666. if (err)
  3667. goto out_remove_sysfs;
  3668. err = iwl_dbgfs_register(priv, DRV_NAME);
  3669. if (err)
  3670. IWL_ERROR("failed to create debugfs files\n");
  3671. err = iwl_rfkill_init(priv);
  3672. if (err)
  3673. IWL_ERROR("Unable to initialize RFKILL system. "
  3674. "Ignoring error: %d\n", err);
  3675. iwl_power_initialize(priv);
  3676. return 0;
  3677. out_remove_sysfs:
  3678. sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
  3679. out_uninit_drv:
  3680. iwl_uninit_drv(priv);
  3681. out_free_eeprom:
  3682. iwl_eeprom_free(priv);
  3683. out_iounmap:
  3684. pci_iounmap(pdev, priv->hw_base);
  3685. out_pci_release_regions:
  3686. pci_release_regions(pdev);
  3687. pci_set_drvdata(pdev, NULL);
  3688. out_pci_disable_device:
  3689. pci_disable_device(pdev);
  3690. out_ieee80211_free_hw:
  3691. ieee80211_free_hw(priv->hw);
  3692. out:
  3693. return err;
  3694. }
  3695. static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
  3696. {
  3697. struct iwl_priv *priv = pci_get_drvdata(pdev);
  3698. struct list_head *p, *q;
  3699. int i;
  3700. unsigned long flags;
  3701. if (!priv)
  3702. return;
  3703. IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
  3704. iwl_dbgfs_unregister(priv);
  3705. sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
  3706. if (priv->mac80211_registered) {
  3707. ieee80211_unregister_hw(priv->hw);
  3708. priv->mac80211_registered = 0;
  3709. }
  3710. set_bit(STATUS_EXIT_PENDING, &priv->status);
  3711. iwl4965_down(priv);
  3712. /* make sure we flush any pending irq or
  3713. * tasklet for the driver
  3714. */
  3715. spin_lock_irqsave(&priv->lock, flags);
  3716. iwl4965_disable_interrupts(priv);
  3717. spin_unlock_irqrestore(&priv->lock, flags);
  3718. iwl_synchronize_irq(priv);
  3719. /* Free MAC hash list for ADHOC */
  3720. for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) {
  3721. list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
  3722. list_del(p);
  3723. kfree(list_entry(p, struct iwl4965_ibss_seq, list));
  3724. }
  3725. }
  3726. iwl_rfkill_unregister(priv);
  3727. iwl4965_dealloc_ucode_pci(priv);
  3728. if (priv->rxq.bd)
  3729. iwl_rx_queue_free(priv, &priv->rxq);
  3730. iwl_hw_txq_ctx_free(priv);
  3731. iwlcore_clear_stations_table(priv);
  3732. iwl_eeprom_free(priv);
  3733. /*netif_stop_queue(dev); */
  3734. flush_workqueue(priv->workqueue);
  3735. /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
  3736. * priv->workqueue... so we can't take down the workqueue
  3737. * until now... */
  3738. destroy_workqueue(priv->workqueue);
  3739. priv->workqueue = NULL;
  3740. pci_iounmap(pdev, priv->hw_base);
  3741. pci_release_regions(pdev);
  3742. pci_disable_device(pdev);
  3743. pci_set_drvdata(pdev, NULL);
  3744. iwl_uninit_drv(priv);
  3745. if (priv->ibss_beacon)
  3746. dev_kfree_skb(priv->ibss_beacon);
  3747. ieee80211_free_hw(priv->hw);
  3748. }
  3749. #ifdef CONFIG_PM
  3750. static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  3751. {
  3752. struct iwl_priv *priv = pci_get_drvdata(pdev);
  3753. if (priv->is_open) {
  3754. set_bit(STATUS_IN_SUSPEND, &priv->status);
  3755. iwl4965_mac_stop(priv->hw);
  3756. priv->is_open = 1;
  3757. }
  3758. pci_set_power_state(pdev, PCI_D3hot);
  3759. return 0;
  3760. }
  3761. static int iwl4965_pci_resume(struct pci_dev *pdev)
  3762. {
  3763. struct iwl_priv *priv = pci_get_drvdata(pdev);
  3764. pci_set_power_state(pdev, PCI_D0);
  3765. if (priv->is_open)
  3766. iwl4965_mac_start(priv->hw);
  3767. clear_bit(STATUS_IN_SUSPEND, &priv->status);
  3768. return 0;
  3769. }
  3770. #endif /* CONFIG_PM */
  3771. /*****************************************************************************
  3772. *
  3773. * driver and module entry point
  3774. *
  3775. *****************************************************************************/
  3776. /* Hardware specific file defines the PCI IDs table for that hardware module */
  3777. static struct pci_device_id iwl_hw_card_ids[] = {
  3778. {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
  3779. {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
  3780. #ifdef CONFIG_IWL5000
  3781. {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)},
  3782. {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)},
  3783. {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID, iwl5350_agn_cfg)},
  3784. #endif /* CONFIG_IWL5000 */
  3785. {0}
  3786. };
  3787. MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
  3788. static struct pci_driver iwl_driver = {
  3789. .name = DRV_NAME,
  3790. .id_table = iwl_hw_card_ids,
  3791. .probe = iwl4965_pci_probe,
  3792. .remove = __devexit_p(iwl4965_pci_remove),
  3793. #ifdef CONFIG_PM
  3794. .suspend = iwl4965_pci_suspend,
  3795. .resume = iwl4965_pci_resume,
  3796. #endif
  3797. };
  3798. static int __init iwl4965_init(void)
  3799. {
  3800. int ret;
  3801. printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
  3802. printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
  3803. ret = iwl4965_rate_control_register();
  3804. if (ret) {
  3805. IWL_ERROR("Unable to register rate control algorithm: %d\n", ret);
  3806. return ret;
  3807. }
  3808. ret = pci_register_driver(&iwl_driver);
  3809. if (ret) {
  3810. IWL_ERROR("Unable to initialize PCI module\n");
  3811. goto error_register;
  3812. }
  3813. return ret;
  3814. error_register:
  3815. iwl4965_rate_control_unregister();
  3816. return ret;
  3817. }
  3818. static void __exit iwl4965_exit(void)
  3819. {
  3820. pci_unregister_driver(&iwl_driver);
  3821. iwl4965_rate_control_unregister();
  3822. }
  3823. module_exit(iwl4965_exit);
  3824. module_init(iwl4965_init);