iwl-agn.c 124 KB

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