iwl4965-base.c 122 KB

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