iwl-agn.c 123 KB

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