iwl-agn.c 124 KB

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