iwl-agn.c 123 KB

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