iwl4965-base.c 122 KB

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