iwl-agn.c 135 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2010 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. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  30. #include <linux/kernel.h>
  31. #include <linux/module.h>
  32. #include <linux/init.h>
  33. #include <linux/pci.h>
  34. #include <linux/pci-aspm.h>
  35. #include <linux/slab.h>
  36. #include <linux/dma-mapping.h>
  37. #include <linux/delay.h>
  38. #include <linux/sched.h>
  39. #include <linux/skbuff.h>
  40. #include <linux/netdevice.h>
  41. #include <linux/wireless.h>
  42. #include <linux/firmware.h>
  43. #include <linux/etherdevice.h>
  44. #include <linux/if_arp.h>
  45. #include <net/mac80211.h>
  46. #include <asm/div64.h>
  47. #define DRV_NAME "iwlagn"
  48. #include "iwl-eeprom.h"
  49. #include "iwl-dev.h"
  50. #include "iwl-core.h"
  51. #include "iwl-io.h"
  52. #include "iwl-helpers.h"
  53. #include "iwl-sta.h"
  54. #include "iwl-calib.h"
  55. #include "iwl-agn.h"
  56. /******************************************************************************
  57. *
  58. * module boiler plate
  59. *
  60. ******************************************************************************/
  61. /*
  62. * module name, copyright, version, etc.
  63. */
  64. #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
  65. #ifdef CONFIG_IWLWIFI_DEBUG
  66. #define VD "d"
  67. #else
  68. #define VD
  69. #endif
  70. #define DRV_VERSION IWLWIFI_VERSION VD
  71. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  72. MODULE_VERSION(DRV_VERSION);
  73. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  74. MODULE_LICENSE("GPL");
  75. MODULE_ALIAS("iwl4965");
  76. static int iwlagn_ant_coupling;
  77. /**
  78. * iwl_commit_rxon - commit staging_rxon to hardware
  79. *
  80. * The RXON command in staging_rxon is committed to the hardware and
  81. * the active_rxon structure is updated with the new data. This
  82. * function correctly transitions out of the RXON_ASSOC_MSK state if
  83. * a HW tune is required based on the RXON structure changes.
  84. */
  85. int iwl_commit_rxon(struct iwl_priv *priv)
  86. {
  87. /* cast away the const for active_rxon in this function */
  88. struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
  89. int ret;
  90. bool new_assoc =
  91. !!(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK);
  92. if (!iwl_is_alive(priv))
  93. return -EBUSY;
  94. /* always get timestamp with Rx frame */
  95. priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
  96. ret = iwl_check_rxon_cmd(priv);
  97. if (ret) {
  98. IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
  99. return -EINVAL;
  100. }
  101. /*
  102. * receive commit_rxon request
  103. * abort any previous channel switch if still in process
  104. */
  105. if (priv->switch_rxon.switch_in_progress &&
  106. (priv->switch_rxon.channel != priv->staging_rxon.channel)) {
  107. IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
  108. le16_to_cpu(priv->switch_rxon.channel));
  109. iwl_chswitch_done(priv, false);
  110. }
  111. /* If we don't need to send a full RXON, we can use
  112. * iwl_rxon_assoc_cmd which is used to reconfigure filter
  113. * and other flags for the current radio configuration. */
  114. if (!iwl_full_rxon_required(priv)) {
  115. ret = iwl_send_rxon_assoc(priv);
  116. if (ret) {
  117. IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
  118. return ret;
  119. }
  120. memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
  121. iwl_print_rx_config_cmd(priv);
  122. return 0;
  123. }
  124. /* If we are currently associated and the new config requires
  125. * an RXON_ASSOC and the new config wants the associated mask enabled,
  126. * we must clear the associated from the active configuration
  127. * before we apply the new config */
  128. if (iwl_is_associated(priv) && new_assoc) {
  129. IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
  130. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  131. ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
  132. sizeof(struct iwl_rxon_cmd),
  133. &priv->active_rxon);
  134. /* If the mask clearing failed then we set
  135. * active_rxon back to what it was previously */
  136. if (ret) {
  137. active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
  138. IWL_ERR(priv, "Error clearing ASSOC_MSK (%d)\n", ret);
  139. return ret;
  140. }
  141. iwl_clear_ucode_stations(priv);
  142. iwl_restore_stations(priv);
  143. ret = iwl_restore_default_wep_keys(priv);
  144. if (ret) {
  145. IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
  146. return ret;
  147. }
  148. }
  149. IWL_DEBUG_INFO(priv, "Sending RXON\n"
  150. "* with%s RXON_FILTER_ASSOC_MSK\n"
  151. "* channel = %d\n"
  152. "* bssid = %pM\n",
  153. (new_assoc ? "" : "out"),
  154. le16_to_cpu(priv->staging_rxon.channel),
  155. priv->staging_rxon.bssid_addr);
  156. iwl_set_rxon_hwcrypto(priv, !priv->cfg->mod_params->sw_crypto);
  157. /* Apply the new configuration
  158. * RXON unassoc clears the station table in uCode so restoration of
  159. * stations is needed after it (the RXON command) completes
  160. */
  161. if (!new_assoc) {
  162. ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
  163. sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
  164. if (ret) {
  165. IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
  166. return ret;
  167. }
  168. IWL_DEBUG_INFO(priv, "Return from !new_assoc RXON.\n");
  169. memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
  170. iwl_clear_ucode_stations(priv);
  171. iwl_restore_stations(priv);
  172. ret = iwl_restore_default_wep_keys(priv);
  173. if (ret) {
  174. IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
  175. return ret;
  176. }
  177. }
  178. priv->start_calib = 0;
  179. if (new_assoc) {
  180. /* Apply the new configuration
  181. * RXON assoc doesn't clear the station table in uCode,
  182. */
  183. ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
  184. sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
  185. if (ret) {
  186. IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
  187. return ret;
  188. }
  189. memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
  190. }
  191. iwl_print_rx_config_cmd(priv);
  192. iwl_init_sensitivity(priv);
  193. /* If we issue a new RXON command which required a tune then we must
  194. * send a new TXPOWER command or we won't be able to Tx any frames */
  195. ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
  196. if (ret) {
  197. IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
  198. return ret;
  199. }
  200. return 0;
  201. }
  202. void iwl_update_chain_flags(struct iwl_priv *priv)
  203. {
  204. if (priv->cfg->ops->hcmd->set_rxon_chain)
  205. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  206. iwlcore_commit_rxon(priv);
  207. }
  208. static void iwl_clear_free_frames(struct iwl_priv *priv)
  209. {
  210. struct list_head *element;
  211. IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
  212. priv->frames_count);
  213. while (!list_empty(&priv->free_frames)) {
  214. element = priv->free_frames.next;
  215. list_del(element);
  216. kfree(list_entry(element, struct iwl_frame, list));
  217. priv->frames_count--;
  218. }
  219. if (priv->frames_count) {
  220. IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
  221. priv->frames_count);
  222. priv->frames_count = 0;
  223. }
  224. }
  225. static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
  226. {
  227. struct iwl_frame *frame;
  228. struct list_head *element;
  229. if (list_empty(&priv->free_frames)) {
  230. frame = kzalloc(sizeof(*frame), GFP_KERNEL);
  231. if (!frame) {
  232. IWL_ERR(priv, "Could not allocate frame!\n");
  233. return NULL;
  234. }
  235. priv->frames_count++;
  236. return frame;
  237. }
  238. element = priv->free_frames.next;
  239. list_del(element);
  240. return list_entry(element, struct iwl_frame, list);
  241. }
  242. static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
  243. {
  244. memset(frame, 0, sizeof(*frame));
  245. list_add(&frame->list, &priv->free_frames);
  246. }
  247. static u32 iwl_fill_beacon_frame(struct iwl_priv *priv,
  248. struct ieee80211_hdr *hdr,
  249. int left)
  250. {
  251. if (!priv->ibss_beacon)
  252. return 0;
  253. if (priv->ibss_beacon->len > left)
  254. return 0;
  255. memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
  256. return priv->ibss_beacon->len;
  257. }
  258. /* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
  259. static void iwl_set_beacon_tim(struct iwl_priv *priv,
  260. struct iwl_tx_beacon_cmd *tx_beacon_cmd,
  261. u8 *beacon, u32 frame_size)
  262. {
  263. u16 tim_idx;
  264. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
  265. /*
  266. * The index is relative to frame start but we start looking at the
  267. * variable-length part of the beacon.
  268. */
  269. tim_idx = mgmt->u.beacon.variable - beacon;
  270. /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
  271. while ((tim_idx < (frame_size - 2)) &&
  272. (beacon[tim_idx] != WLAN_EID_TIM))
  273. tim_idx += beacon[tim_idx+1] + 2;
  274. /* If TIM field was found, set variables */
  275. if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
  276. tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
  277. tx_beacon_cmd->tim_size = beacon[tim_idx+1];
  278. } else
  279. IWL_WARN(priv, "Unable to find TIM Element in beacon\n");
  280. }
  281. static unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv,
  282. struct iwl_frame *frame)
  283. {
  284. struct iwl_tx_beacon_cmd *tx_beacon_cmd;
  285. u32 frame_size;
  286. u32 rate_flags;
  287. u32 rate;
  288. /*
  289. * We have to set up the TX command, the TX Beacon command, and the
  290. * beacon contents.
  291. */
  292. /* Initialize memory */
  293. tx_beacon_cmd = &frame->u.beacon;
  294. memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
  295. /* Set up TX beacon contents */
  296. frame_size = iwl_fill_beacon_frame(priv, tx_beacon_cmd->frame,
  297. sizeof(frame->u) - sizeof(*tx_beacon_cmd));
  298. if (WARN_ON_ONCE(frame_size > MAX_MPDU_SIZE))
  299. return 0;
  300. /* Set up TX command fields */
  301. tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
  302. tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id;
  303. tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  304. tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
  305. TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
  306. /* Set up TX beacon command fields */
  307. iwl_set_beacon_tim(priv, tx_beacon_cmd, (u8 *)tx_beacon_cmd->frame,
  308. frame_size);
  309. /* Set up packet rate and flags */
  310. rate = iwl_rate_get_lowest_plcp(priv);
  311. priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
  312. priv->hw_params.valid_tx_ant);
  313. rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
  314. if ((rate >= IWL_FIRST_CCK_RATE) && (rate <= IWL_LAST_CCK_RATE))
  315. rate_flags |= RATE_MCS_CCK_MSK;
  316. tx_beacon_cmd->tx.rate_n_flags = iwl_hw_set_rate_n_flags(rate,
  317. rate_flags);
  318. return sizeof(*tx_beacon_cmd) + frame_size;
  319. }
  320. static int iwl_send_beacon_cmd(struct iwl_priv *priv)
  321. {
  322. struct iwl_frame *frame;
  323. unsigned int frame_size;
  324. int rc;
  325. frame = iwl_get_free_frame(priv);
  326. if (!frame) {
  327. IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
  328. "command.\n");
  329. return -ENOMEM;
  330. }
  331. frame_size = iwl_hw_get_beacon_cmd(priv, frame);
  332. if (!frame_size) {
  333. IWL_ERR(priv, "Error configuring the beacon command\n");
  334. iwl_free_frame(priv, frame);
  335. return -EINVAL;
  336. }
  337. rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
  338. &frame->u.cmd[0]);
  339. iwl_free_frame(priv, frame);
  340. return rc;
  341. }
  342. static inline dma_addr_t iwl_tfd_tb_get_addr(struct iwl_tfd *tfd, u8 idx)
  343. {
  344. struct iwl_tfd_tb *tb = &tfd->tbs[idx];
  345. dma_addr_t addr = get_unaligned_le32(&tb->lo);
  346. if (sizeof(dma_addr_t) > sizeof(u32))
  347. addr |=
  348. ((dma_addr_t)(le16_to_cpu(tb->hi_n_len) & 0xF) << 16) << 16;
  349. return addr;
  350. }
  351. static inline u16 iwl_tfd_tb_get_len(struct iwl_tfd *tfd, u8 idx)
  352. {
  353. struct iwl_tfd_tb *tb = &tfd->tbs[idx];
  354. return le16_to_cpu(tb->hi_n_len) >> 4;
  355. }
  356. static inline void iwl_tfd_set_tb(struct iwl_tfd *tfd, u8 idx,
  357. dma_addr_t addr, u16 len)
  358. {
  359. struct iwl_tfd_tb *tb = &tfd->tbs[idx];
  360. u16 hi_n_len = len << 4;
  361. put_unaligned_le32(addr, &tb->lo);
  362. if (sizeof(dma_addr_t) > sizeof(u32))
  363. hi_n_len |= ((addr >> 16) >> 16) & 0xF;
  364. tb->hi_n_len = cpu_to_le16(hi_n_len);
  365. tfd->num_tbs = idx + 1;
  366. }
  367. static inline u8 iwl_tfd_get_num_tbs(struct iwl_tfd *tfd)
  368. {
  369. return tfd->num_tbs & 0x1f;
  370. }
  371. /**
  372. * iwl_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
  373. * @priv - driver private data
  374. * @txq - tx queue
  375. *
  376. * Does NOT advance any TFD circular buffer read/write indexes
  377. * Does NOT free the TFD itself (which is within circular buffer)
  378. */
  379. void iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq)
  380. {
  381. struct iwl_tfd *tfd_tmp = (struct iwl_tfd *)txq->tfds;
  382. struct iwl_tfd *tfd;
  383. struct pci_dev *dev = priv->pci_dev;
  384. int index = txq->q.read_ptr;
  385. int i;
  386. int num_tbs;
  387. tfd = &tfd_tmp[index];
  388. /* Sanity check on number of chunks */
  389. num_tbs = iwl_tfd_get_num_tbs(tfd);
  390. if (num_tbs >= IWL_NUM_OF_TBS) {
  391. IWL_ERR(priv, "Too many chunks: %i\n", num_tbs);
  392. /* @todo issue fatal error, it is quite serious situation */
  393. return;
  394. }
  395. /* Unmap tx_cmd */
  396. if (num_tbs)
  397. pci_unmap_single(dev,
  398. dma_unmap_addr(&txq->meta[index], mapping),
  399. dma_unmap_len(&txq->meta[index], len),
  400. PCI_DMA_BIDIRECTIONAL);
  401. /* Unmap chunks, if any. */
  402. for (i = 1; i < num_tbs; i++)
  403. pci_unmap_single(dev, iwl_tfd_tb_get_addr(tfd, i),
  404. iwl_tfd_tb_get_len(tfd, i), PCI_DMA_TODEVICE);
  405. /* free SKB */
  406. if (txq->txb) {
  407. struct sk_buff *skb;
  408. skb = txq->txb[txq->q.read_ptr].skb;
  409. /* can be called from irqs-disabled context */
  410. if (skb) {
  411. dev_kfree_skb_any(skb);
  412. txq->txb[txq->q.read_ptr].skb = NULL;
  413. }
  414. }
  415. }
  416. int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv,
  417. struct iwl_tx_queue *txq,
  418. dma_addr_t addr, u16 len,
  419. u8 reset, u8 pad)
  420. {
  421. struct iwl_queue *q;
  422. struct iwl_tfd *tfd, *tfd_tmp;
  423. u32 num_tbs;
  424. q = &txq->q;
  425. tfd_tmp = (struct iwl_tfd *)txq->tfds;
  426. tfd = &tfd_tmp[q->write_ptr];
  427. if (reset)
  428. memset(tfd, 0, sizeof(*tfd));
  429. num_tbs = iwl_tfd_get_num_tbs(tfd);
  430. /* Each TFD can point to a maximum 20 Tx buffers */
  431. if (num_tbs >= IWL_NUM_OF_TBS) {
  432. IWL_ERR(priv, "Error can not send more than %d chunks\n",
  433. IWL_NUM_OF_TBS);
  434. return -EINVAL;
  435. }
  436. BUG_ON(addr & ~DMA_BIT_MASK(36));
  437. if (unlikely(addr & ~IWL_TX_DMA_MASK))
  438. IWL_ERR(priv, "Unaligned address = %llx\n",
  439. (unsigned long long)addr);
  440. iwl_tfd_set_tb(tfd, num_tbs, addr, len);
  441. return 0;
  442. }
  443. /*
  444. * Tell nic where to find circular buffer of Tx Frame Descriptors for
  445. * given Tx queue, and enable the DMA channel used for that queue.
  446. *
  447. * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA
  448. * channels supported in hardware.
  449. */
  450. int iwl_hw_tx_queue_init(struct iwl_priv *priv,
  451. struct iwl_tx_queue *txq)
  452. {
  453. int txq_id = txq->q.id;
  454. /* Circular buffer (TFD queue in DRAM) physical base address */
  455. iwl_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id),
  456. txq->q.dma_addr >> 8);
  457. return 0;
  458. }
  459. /******************************************************************************
  460. *
  461. * Generic RX handler implementations
  462. *
  463. ******************************************************************************/
  464. static void iwl_rx_reply_alive(struct iwl_priv *priv,
  465. struct iwl_rx_mem_buffer *rxb)
  466. {
  467. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  468. struct iwl_alive_resp *palive;
  469. struct delayed_work *pwork;
  470. palive = &pkt->u.alive_frame;
  471. IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
  472. "0x%01X 0x%01X\n",
  473. palive->is_valid, palive->ver_type,
  474. palive->ver_subtype);
  475. if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
  476. IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
  477. memcpy(&priv->card_alive_init,
  478. &pkt->u.alive_frame,
  479. sizeof(struct iwl_init_alive_resp));
  480. pwork = &priv->init_alive_start;
  481. } else {
  482. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  483. memcpy(&priv->card_alive, &pkt->u.alive_frame,
  484. sizeof(struct iwl_alive_resp));
  485. pwork = &priv->alive_start;
  486. }
  487. /* We delay the ALIVE response by 5ms to
  488. * give the HW RF Kill time to activate... */
  489. if (palive->is_valid == UCODE_VALID_OK)
  490. queue_delayed_work(priv->workqueue, pwork,
  491. msecs_to_jiffies(5));
  492. else
  493. IWL_WARN(priv, "uCode did not respond OK.\n");
  494. }
  495. static void iwl_bg_beacon_update(struct work_struct *work)
  496. {
  497. struct iwl_priv *priv =
  498. container_of(work, struct iwl_priv, beacon_update);
  499. struct sk_buff *beacon;
  500. /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
  501. beacon = ieee80211_beacon_get(priv->hw, priv->vif);
  502. if (!beacon) {
  503. IWL_ERR(priv, "update beacon failed\n");
  504. return;
  505. }
  506. mutex_lock(&priv->mutex);
  507. /* new beacon skb is allocated every time; dispose previous.*/
  508. if (priv->ibss_beacon)
  509. dev_kfree_skb(priv->ibss_beacon);
  510. priv->ibss_beacon = beacon;
  511. mutex_unlock(&priv->mutex);
  512. iwl_send_beacon_cmd(priv);
  513. }
  514. static void iwl_bg_bt_runtime_config(struct work_struct *work)
  515. {
  516. struct iwl_priv *priv =
  517. container_of(work, struct iwl_priv, bt_runtime_config);
  518. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  519. return;
  520. /* dont send host command if rf-kill is on */
  521. if (!iwl_is_ready_rf(priv))
  522. return;
  523. priv->cfg->ops->hcmd->send_bt_config(priv);
  524. }
  525. static void iwl_bg_bt_full_concurrency(struct work_struct *work)
  526. {
  527. struct iwl_priv *priv =
  528. container_of(work, struct iwl_priv, bt_full_concurrency);
  529. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  530. return;
  531. /* dont send host command if rf-kill is on */
  532. if (!iwl_is_ready_rf(priv))
  533. return;
  534. IWL_DEBUG_INFO(priv, "BT coex in %s mode\n",
  535. priv->bt_full_concurrent ?
  536. "full concurrency" : "3-wire");
  537. /*
  538. * LQ & RXON updated cmds must be sent before BT Config cmd
  539. * to avoid 3-wire collisions
  540. */
  541. if (priv->cfg->ops->hcmd->set_rxon_chain)
  542. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  543. iwlcore_commit_rxon(priv);
  544. priv->cfg->ops->hcmd->send_bt_config(priv);
  545. }
  546. /**
  547. * iwl_bg_statistics_periodic - Timer callback to queue statistics
  548. *
  549. * This callback is provided in order to send a statistics request.
  550. *
  551. * This timer function is continually reset to execute within
  552. * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
  553. * was received. We need to ensure we receive the statistics in order
  554. * to update the temperature used for calibrating the TXPOWER.
  555. */
  556. static void iwl_bg_statistics_periodic(unsigned long data)
  557. {
  558. struct iwl_priv *priv = (struct iwl_priv *)data;
  559. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  560. return;
  561. /* dont send host command if rf-kill is on */
  562. if (!iwl_is_ready_rf(priv))
  563. return;
  564. iwl_send_statistics_request(priv, CMD_ASYNC, false);
  565. }
  566. static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base,
  567. u32 start_idx, u32 num_events,
  568. u32 mode)
  569. {
  570. u32 i;
  571. u32 ptr; /* SRAM byte address of log data */
  572. u32 ev, time, data; /* event log data */
  573. unsigned long reg_flags;
  574. if (mode == 0)
  575. ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32));
  576. else
  577. ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32));
  578. /* Make sure device is powered up for SRAM reads */
  579. spin_lock_irqsave(&priv->reg_lock, reg_flags);
  580. if (iwl_grab_nic_access(priv)) {
  581. spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
  582. return;
  583. }
  584. /* Set starting address; reads will auto-increment */
  585. _iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, ptr);
  586. rmb();
  587. /*
  588. * "time" is actually "data" for mode 0 (no timestamp).
  589. * place event id # at far right for easier visual parsing.
  590. */
  591. for (i = 0; i < num_events; i++) {
  592. ev = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  593. time = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  594. if (mode == 0) {
  595. trace_iwlwifi_dev_ucode_cont_event(priv,
  596. 0, time, ev);
  597. } else {
  598. data = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  599. trace_iwlwifi_dev_ucode_cont_event(priv,
  600. time, data, ev);
  601. }
  602. }
  603. /* Allow device to power down */
  604. iwl_release_nic_access(priv);
  605. spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
  606. }
  607. static void iwl_continuous_event_trace(struct iwl_priv *priv)
  608. {
  609. u32 capacity; /* event log capacity in # entries */
  610. u32 base; /* SRAM byte address of event log header */
  611. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  612. u32 num_wraps; /* # times uCode wrapped to top of log */
  613. u32 next_entry; /* index of next entry to be written by uCode */
  614. if (priv->ucode_type == UCODE_INIT)
  615. base = le32_to_cpu(priv->card_alive_init.error_event_table_ptr);
  616. else
  617. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  618. if (priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
  619. capacity = iwl_read_targ_mem(priv, base);
  620. num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
  621. mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
  622. next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
  623. } else
  624. return;
  625. if (num_wraps == priv->event_log.num_wraps) {
  626. iwl_print_cont_event_trace(priv,
  627. base, priv->event_log.next_entry,
  628. next_entry - priv->event_log.next_entry,
  629. mode);
  630. priv->event_log.non_wraps_count++;
  631. } else {
  632. if ((num_wraps - priv->event_log.num_wraps) > 1)
  633. priv->event_log.wraps_more_count++;
  634. else
  635. priv->event_log.wraps_once_count++;
  636. trace_iwlwifi_dev_ucode_wrap_event(priv,
  637. num_wraps - priv->event_log.num_wraps,
  638. next_entry, priv->event_log.next_entry);
  639. if (next_entry < priv->event_log.next_entry) {
  640. iwl_print_cont_event_trace(priv, base,
  641. priv->event_log.next_entry,
  642. capacity - priv->event_log.next_entry,
  643. mode);
  644. iwl_print_cont_event_trace(priv, base, 0,
  645. next_entry, mode);
  646. } else {
  647. iwl_print_cont_event_trace(priv, base,
  648. next_entry, capacity - next_entry,
  649. mode);
  650. iwl_print_cont_event_trace(priv, base, 0,
  651. next_entry, mode);
  652. }
  653. }
  654. priv->event_log.num_wraps = num_wraps;
  655. priv->event_log.next_entry = next_entry;
  656. }
  657. /**
  658. * iwl_bg_ucode_trace - Timer callback to log ucode event
  659. *
  660. * The timer is continually set to execute every
  661. * UCODE_TRACE_PERIOD milliseconds after the last timer expired
  662. * this function is to perform continuous uCode event logging operation
  663. * if enabled
  664. */
  665. static void iwl_bg_ucode_trace(unsigned long data)
  666. {
  667. struct iwl_priv *priv = (struct iwl_priv *)data;
  668. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  669. return;
  670. if (priv->event_log.ucode_trace) {
  671. iwl_continuous_event_trace(priv);
  672. /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */
  673. mod_timer(&priv->ucode_trace,
  674. jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
  675. }
  676. }
  677. static void iwl_rx_beacon_notif(struct iwl_priv *priv,
  678. struct iwl_rx_mem_buffer *rxb)
  679. {
  680. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  681. struct iwl4965_beacon_notif *beacon =
  682. (struct iwl4965_beacon_notif *)pkt->u.raw;
  683. #ifdef CONFIG_IWLWIFI_DEBUG
  684. u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
  685. IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
  686. "tsf %d %d rate %d\n",
  687. le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
  688. beacon->beacon_notify_hdr.failure_frame,
  689. le32_to_cpu(beacon->ibss_mgr_status),
  690. le32_to_cpu(beacon->high_tsf),
  691. le32_to_cpu(beacon->low_tsf), rate);
  692. #endif
  693. priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status);
  694. if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
  695. (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
  696. queue_work(priv->workqueue, &priv->beacon_update);
  697. }
  698. /* Handle notification from uCode that card's power state is changing
  699. * due to software, hardware, or critical temperature RFKILL */
  700. static void iwl_rx_card_state_notif(struct iwl_priv *priv,
  701. struct iwl_rx_mem_buffer *rxb)
  702. {
  703. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  704. u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
  705. unsigned long status = priv->status;
  706. IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s CT:%s\n",
  707. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  708. (flags & SW_CARD_DISABLED) ? "Kill" : "On",
  709. (flags & CT_CARD_DISABLED) ?
  710. "Reached" : "Not reached");
  711. if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
  712. CT_CARD_DISABLED)) {
  713. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  714. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  715. iwl_write_direct32(priv, HBUS_TARG_MBX_C,
  716. HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  717. if (!(flags & RXON_CARD_DISABLED)) {
  718. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  719. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  720. iwl_write_direct32(priv, HBUS_TARG_MBX_C,
  721. HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  722. }
  723. if (flags & CT_CARD_DISABLED)
  724. iwl_tt_enter_ct_kill(priv);
  725. }
  726. if (!(flags & CT_CARD_DISABLED))
  727. iwl_tt_exit_ct_kill(priv);
  728. if (flags & HW_CARD_DISABLED)
  729. set_bit(STATUS_RF_KILL_HW, &priv->status);
  730. else
  731. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  732. if (!(flags & RXON_CARD_DISABLED))
  733. iwl_scan_cancel(priv);
  734. if ((test_bit(STATUS_RF_KILL_HW, &status) !=
  735. test_bit(STATUS_RF_KILL_HW, &priv->status)))
  736. wiphy_rfkill_set_hw_state(priv->hw->wiphy,
  737. test_bit(STATUS_RF_KILL_HW, &priv->status));
  738. else
  739. wake_up_interruptible(&priv->wait_command_queue);
  740. }
  741. int iwl_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
  742. {
  743. if (src == IWL_PWR_SRC_VAUX) {
  744. if (pci_pme_capable(priv->pci_dev, PCI_D3cold))
  745. iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
  746. APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
  747. ~APMG_PS_CTRL_MSK_PWR_SRC);
  748. } else {
  749. iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
  750. APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
  751. ~APMG_PS_CTRL_MSK_PWR_SRC);
  752. }
  753. return 0;
  754. }
  755. static void iwl_bg_tx_flush(struct work_struct *work)
  756. {
  757. struct iwl_priv *priv =
  758. container_of(work, struct iwl_priv, tx_flush);
  759. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  760. return;
  761. /* do nothing if rf-kill is on */
  762. if (!iwl_is_ready_rf(priv))
  763. return;
  764. if (priv->cfg->ops->lib->txfifo_flush) {
  765. IWL_DEBUG_INFO(priv, "device request: flush all tx frames\n");
  766. iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
  767. }
  768. }
  769. /**
  770. * iwl_setup_rx_handlers - Initialize Rx handler callbacks
  771. *
  772. * Setup the RX handlers for each of the reply types sent from the uCode
  773. * to the host.
  774. *
  775. * This function chains into the hardware specific files for them to setup
  776. * any hardware specific handlers as well.
  777. */
  778. static void iwl_setup_rx_handlers(struct iwl_priv *priv)
  779. {
  780. priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
  781. priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
  782. priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
  783. priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
  784. iwl_rx_spectrum_measure_notif;
  785. priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
  786. priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
  787. iwl_rx_pm_debug_statistics_notif;
  788. priv->rx_handlers[BEACON_NOTIFICATION] = iwl_rx_beacon_notif;
  789. /*
  790. * The same handler is used for both the REPLY to a discrete
  791. * statistics request from the host as well as for the periodic
  792. * statistics notifications (after received beacons) from the uCode.
  793. */
  794. priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_reply_statistics;
  795. priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
  796. iwl_setup_rx_scan_handlers(priv);
  797. /* status change handler */
  798. priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl_rx_card_state_notif;
  799. priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
  800. iwl_rx_missed_beacon_notif;
  801. /* Rx handlers */
  802. priv->rx_handlers[REPLY_RX_PHY_CMD] = iwlagn_rx_reply_rx_phy;
  803. priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwlagn_rx_reply_rx;
  804. /* block ack */
  805. priv->rx_handlers[REPLY_COMPRESSED_BA] = iwlagn_rx_reply_compressed_ba;
  806. /* Set up hardware specific Rx handlers */
  807. priv->cfg->ops->lib->rx_handler_setup(priv);
  808. }
  809. /**
  810. * iwl_rx_handle - Main entry function for receiving responses from uCode
  811. *
  812. * Uses the priv->rx_handlers callback function array to invoke
  813. * the appropriate handlers, including command responses,
  814. * frame-received notifications, and other notifications.
  815. */
  816. void iwl_rx_handle(struct iwl_priv *priv)
  817. {
  818. struct iwl_rx_mem_buffer *rxb;
  819. struct iwl_rx_packet *pkt;
  820. struct iwl_rx_queue *rxq = &priv->rxq;
  821. u32 r, i;
  822. int reclaim;
  823. unsigned long flags;
  824. u8 fill_rx = 0;
  825. u32 count = 8;
  826. int total_empty;
  827. /* uCode's read index (stored in shared DRAM) indicates the last Rx
  828. * buffer that the driver may process (last buffer filled by ucode). */
  829. r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
  830. i = rxq->read;
  831. /* Rx interrupt, but nothing sent from uCode */
  832. if (i == r)
  833. IWL_DEBUG_RX(priv, "r = %d, i = %d\n", r, i);
  834. /* calculate total frames need to be restock after handling RX */
  835. total_empty = r - rxq->write_actual;
  836. if (total_empty < 0)
  837. total_empty += RX_QUEUE_SIZE;
  838. if (total_empty > (RX_QUEUE_SIZE / 2))
  839. fill_rx = 1;
  840. while (i != r) {
  841. int len;
  842. rxb = rxq->queue[i];
  843. /* If an RXB doesn't have a Rx queue slot associated with it,
  844. * then a bug has been introduced in the queue refilling
  845. * routines -- catch it here */
  846. BUG_ON(rxb == NULL);
  847. rxq->queue[i] = NULL;
  848. pci_unmap_page(priv->pci_dev, rxb->page_dma,
  849. PAGE_SIZE << priv->hw_params.rx_page_order,
  850. PCI_DMA_FROMDEVICE);
  851. pkt = rxb_addr(rxb);
  852. len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  853. len += sizeof(u32); /* account for status word */
  854. trace_iwlwifi_dev_rx(priv, pkt, len);
  855. /* Reclaim a command buffer only if this packet is a response
  856. * to a (driver-originated) command.
  857. * If the packet (e.g. Rx frame) originated from uCode,
  858. * there is no command buffer to reclaim.
  859. * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
  860. * but apparently a few don't get set; catch them here. */
  861. reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
  862. (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
  863. (pkt->hdr.cmd != REPLY_RX) &&
  864. (pkt->hdr.cmd != REPLY_RX_MPDU_CMD) &&
  865. (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
  866. (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
  867. (pkt->hdr.cmd != REPLY_TX);
  868. /* Based on type of command response or notification,
  869. * handle those that need handling via function in
  870. * rx_handlers table. See iwl_setup_rx_handlers() */
  871. if (priv->rx_handlers[pkt->hdr.cmd]) {
  872. IWL_DEBUG_RX(priv, "r = %d, i = %d, %s, 0x%02x\n", r,
  873. i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
  874. priv->isr_stats.rx_handlers[pkt->hdr.cmd]++;
  875. priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
  876. } else {
  877. /* No handling needed */
  878. IWL_DEBUG_RX(priv,
  879. "r %d i %d No handler needed for %s, 0x%02x\n",
  880. r, i, get_cmd_string(pkt->hdr.cmd),
  881. pkt->hdr.cmd);
  882. }
  883. /*
  884. * XXX: After here, we should always check rxb->page
  885. * against NULL before touching it or its virtual
  886. * memory (pkt). Because some rx_handler might have
  887. * already taken or freed the pages.
  888. */
  889. if (reclaim) {
  890. /* Invoke any callbacks, transfer the buffer to caller,
  891. * and fire off the (possibly) blocking iwl_send_cmd()
  892. * as we reclaim the driver command queue */
  893. if (rxb->page)
  894. iwl_tx_cmd_complete(priv, rxb);
  895. else
  896. IWL_WARN(priv, "Claim null rxb?\n");
  897. }
  898. /* Reuse the page if possible. For notification packets and
  899. * SKBs that fail to Rx correctly, add them back into the
  900. * rx_free list for reuse later. */
  901. spin_lock_irqsave(&rxq->lock, flags);
  902. if (rxb->page != NULL) {
  903. rxb->page_dma = pci_map_page(priv->pci_dev, rxb->page,
  904. 0, PAGE_SIZE << priv->hw_params.rx_page_order,
  905. PCI_DMA_FROMDEVICE);
  906. list_add_tail(&rxb->list, &rxq->rx_free);
  907. rxq->free_count++;
  908. } else
  909. list_add_tail(&rxb->list, &rxq->rx_used);
  910. spin_unlock_irqrestore(&rxq->lock, flags);
  911. i = (i + 1) & RX_QUEUE_MASK;
  912. /* If there are a lot of unused frames,
  913. * restock the Rx queue so ucode wont assert. */
  914. if (fill_rx) {
  915. count++;
  916. if (count >= 8) {
  917. rxq->read = i;
  918. iwlagn_rx_replenish_now(priv);
  919. count = 0;
  920. }
  921. }
  922. }
  923. /* Backtrack one entry */
  924. rxq->read = i;
  925. if (fill_rx)
  926. iwlagn_rx_replenish_now(priv);
  927. else
  928. iwlagn_rx_queue_restock(priv);
  929. }
  930. /* call this function to flush any scheduled tasklet */
  931. static inline void iwl_synchronize_irq(struct iwl_priv *priv)
  932. {
  933. /* wait to make sure we flush pending tasklet*/
  934. synchronize_irq(priv->pci_dev->irq);
  935. tasklet_kill(&priv->irq_tasklet);
  936. }
  937. static void iwl_irq_tasklet_legacy(struct iwl_priv *priv)
  938. {
  939. u32 inta, handled = 0;
  940. u32 inta_fh;
  941. unsigned long flags;
  942. u32 i;
  943. #ifdef CONFIG_IWLWIFI_DEBUG
  944. u32 inta_mask;
  945. #endif
  946. spin_lock_irqsave(&priv->lock, flags);
  947. /* Ack/clear/reset pending uCode interrupts.
  948. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
  949. * and will clear only when CSR_FH_INT_STATUS gets cleared. */
  950. inta = iwl_read32(priv, CSR_INT);
  951. iwl_write32(priv, CSR_INT, inta);
  952. /* Ack/clear/reset pending flow-handler (DMA) interrupts.
  953. * Any new interrupts that happen after this, either while we're
  954. * in this tasklet, or later, will show up in next ISR/tasklet. */
  955. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  956. iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
  957. #ifdef CONFIG_IWLWIFI_DEBUG
  958. if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
  959. /* just for debug */
  960. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  961. IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  962. inta, inta_mask, inta_fh);
  963. }
  964. #endif
  965. spin_unlock_irqrestore(&priv->lock, flags);
  966. /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
  967. * atomic, make sure that inta covers all the interrupts that
  968. * we've discovered, even if FH interrupt came in just after
  969. * reading CSR_INT. */
  970. if (inta_fh & CSR49_FH_INT_RX_MASK)
  971. inta |= CSR_INT_BIT_FH_RX;
  972. if (inta_fh & CSR49_FH_INT_TX_MASK)
  973. inta |= CSR_INT_BIT_FH_TX;
  974. /* Now service all interrupt bits discovered above. */
  975. if (inta & CSR_INT_BIT_HW_ERR) {
  976. IWL_ERR(priv, "Hardware error detected. Restarting.\n");
  977. /* Tell the device to stop sending interrupts */
  978. iwl_disable_interrupts(priv);
  979. priv->isr_stats.hw++;
  980. iwl_irq_handle_error(priv);
  981. handled |= CSR_INT_BIT_HW_ERR;
  982. return;
  983. }
  984. #ifdef CONFIG_IWLWIFI_DEBUG
  985. if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
  986. /* NIC fires this, but we don't use it, redundant with WAKEUP */
  987. if (inta & CSR_INT_BIT_SCD) {
  988. IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
  989. "the frame/frames.\n");
  990. priv->isr_stats.sch++;
  991. }
  992. /* Alive notification via Rx interrupt will do the real work */
  993. if (inta & CSR_INT_BIT_ALIVE) {
  994. IWL_DEBUG_ISR(priv, "Alive interrupt\n");
  995. priv->isr_stats.alive++;
  996. }
  997. }
  998. #endif
  999. /* Safely ignore these bits for debug checks below */
  1000. inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
  1001. /* HW RF KILL switch toggled */
  1002. if (inta & CSR_INT_BIT_RF_KILL) {
  1003. int hw_rf_kill = 0;
  1004. if (!(iwl_read32(priv, CSR_GP_CNTRL) &
  1005. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
  1006. hw_rf_kill = 1;
  1007. IWL_WARN(priv, "RF_KILL bit toggled to %s.\n",
  1008. hw_rf_kill ? "disable radio" : "enable radio");
  1009. priv->isr_stats.rfkill++;
  1010. /* driver only loads ucode once setting the interface up.
  1011. * the driver allows loading the ucode even if the radio
  1012. * is killed. Hence update the killswitch state here. The
  1013. * rfkill handler will care about restarting if needed.
  1014. */
  1015. if (!test_bit(STATUS_ALIVE, &priv->status)) {
  1016. if (hw_rf_kill)
  1017. set_bit(STATUS_RF_KILL_HW, &priv->status);
  1018. else
  1019. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  1020. wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill);
  1021. }
  1022. handled |= CSR_INT_BIT_RF_KILL;
  1023. }
  1024. /* Chip got too hot and stopped itself */
  1025. if (inta & CSR_INT_BIT_CT_KILL) {
  1026. IWL_ERR(priv, "Microcode CT kill error detected.\n");
  1027. priv->isr_stats.ctkill++;
  1028. handled |= CSR_INT_BIT_CT_KILL;
  1029. }
  1030. /* Error detected by uCode */
  1031. if (inta & CSR_INT_BIT_SW_ERR) {
  1032. IWL_ERR(priv, "Microcode SW error detected. "
  1033. " Restarting 0x%X.\n", inta);
  1034. priv->isr_stats.sw++;
  1035. priv->isr_stats.sw_err = inta;
  1036. iwl_irq_handle_error(priv);
  1037. handled |= CSR_INT_BIT_SW_ERR;
  1038. }
  1039. /*
  1040. * uCode wakes up after power-down sleep.
  1041. * Tell device about any new tx or host commands enqueued,
  1042. * and about any Rx buffers made available while asleep.
  1043. */
  1044. if (inta & CSR_INT_BIT_WAKEUP) {
  1045. IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
  1046. iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
  1047. for (i = 0; i < priv->hw_params.max_txq_num; i++)
  1048. iwl_txq_update_write_ptr(priv, &priv->txq[i]);
  1049. priv->isr_stats.wakeup++;
  1050. handled |= CSR_INT_BIT_WAKEUP;
  1051. }
  1052. /* All uCode command responses, including Tx command responses,
  1053. * Rx "responses" (frame-received notification), and other
  1054. * notifications from uCode come through here*/
  1055. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
  1056. iwl_rx_handle(priv);
  1057. priv->isr_stats.rx++;
  1058. handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
  1059. }
  1060. /* This "Tx" DMA channel is used only for loading uCode */
  1061. if (inta & CSR_INT_BIT_FH_TX) {
  1062. IWL_DEBUG_ISR(priv, "uCode load interrupt\n");
  1063. priv->isr_stats.tx++;
  1064. handled |= CSR_INT_BIT_FH_TX;
  1065. /* Wake up uCode load routine, now that load is complete */
  1066. priv->ucode_write_complete = 1;
  1067. wake_up_interruptible(&priv->wait_command_queue);
  1068. }
  1069. if (inta & ~handled) {
  1070. IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
  1071. priv->isr_stats.unhandled++;
  1072. }
  1073. if (inta & ~(priv->inta_mask)) {
  1074. IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
  1075. inta & ~priv->inta_mask);
  1076. IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
  1077. }
  1078. /* Re-enable all interrupts */
  1079. /* only Re-enable if diabled by irq */
  1080. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  1081. iwl_enable_interrupts(priv);
  1082. #ifdef CONFIG_IWLWIFI_DEBUG
  1083. if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
  1084. inta = iwl_read32(priv, CSR_INT);
  1085. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  1086. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  1087. IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
  1088. "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
  1089. }
  1090. #endif
  1091. }
  1092. /* tasklet for iwlagn interrupt */
  1093. static void iwl_irq_tasklet(struct iwl_priv *priv)
  1094. {
  1095. u32 inta = 0;
  1096. u32 handled = 0;
  1097. unsigned long flags;
  1098. u32 i;
  1099. #ifdef CONFIG_IWLWIFI_DEBUG
  1100. u32 inta_mask;
  1101. #endif
  1102. spin_lock_irqsave(&priv->lock, flags);
  1103. /* Ack/clear/reset pending uCode interrupts.
  1104. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
  1105. */
  1106. /* There is a hardware bug in the interrupt mask function that some
  1107. * interrupts (i.e. CSR_INT_BIT_SCD) can still be generated even if
  1108. * they are disabled in the CSR_INT_MASK register. Furthermore the
  1109. * ICT interrupt handling mechanism has another bug that might cause
  1110. * these unmasked interrupts fail to be detected. We workaround the
  1111. * hardware bugs here by ACKing all the possible interrupts so that
  1112. * interrupt coalescing can still be achieved.
  1113. */
  1114. iwl_write32(priv, CSR_INT, priv->_agn.inta | ~priv->inta_mask);
  1115. inta = priv->_agn.inta;
  1116. #ifdef CONFIG_IWLWIFI_DEBUG
  1117. if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
  1118. /* just for debug */
  1119. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  1120. IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x\n ",
  1121. inta, inta_mask);
  1122. }
  1123. #endif
  1124. spin_unlock_irqrestore(&priv->lock, flags);
  1125. /* saved interrupt in inta variable now we can reset priv->_agn.inta */
  1126. priv->_agn.inta = 0;
  1127. /* Now service all interrupt bits discovered above. */
  1128. if (inta & CSR_INT_BIT_HW_ERR) {
  1129. IWL_ERR(priv, "Hardware error detected. Restarting.\n");
  1130. /* Tell the device to stop sending interrupts */
  1131. iwl_disable_interrupts(priv);
  1132. priv->isr_stats.hw++;
  1133. iwl_irq_handle_error(priv);
  1134. handled |= CSR_INT_BIT_HW_ERR;
  1135. return;
  1136. }
  1137. #ifdef CONFIG_IWLWIFI_DEBUG
  1138. if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
  1139. /* NIC fires this, but we don't use it, redundant with WAKEUP */
  1140. if (inta & CSR_INT_BIT_SCD) {
  1141. IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
  1142. "the frame/frames.\n");
  1143. priv->isr_stats.sch++;
  1144. }
  1145. /* Alive notification via Rx interrupt will do the real work */
  1146. if (inta & CSR_INT_BIT_ALIVE) {
  1147. IWL_DEBUG_ISR(priv, "Alive interrupt\n");
  1148. priv->isr_stats.alive++;
  1149. }
  1150. }
  1151. #endif
  1152. /* Safely ignore these bits for debug checks below */
  1153. inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
  1154. /* HW RF KILL switch toggled */
  1155. if (inta & CSR_INT_BIT_RF_KILL) {
  1156. int hw_rf_kill = 0;
  1157. if (!(iwl_read32(priv, CSR_GP_CNTRL) &
  1158. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
  1159. hw_rf_kill = 1;
  1160. IWL_WARN(priv, "RF_KILL bit toggled to %s.\n",
  1161. hw_rf_kill ? "disable radio" : "enable radio");
  1162. priv->isr_stats.rfkill++;
  1163. /* driver only loads ucode once setting the interface up.
  1164. * the driver allows loading the ucode even if the radio
  1165. * is killed. Hence update the killswitch state here. The
  1166. * rfkill handler will care about restarting if needed.
  1167. */
  1168. if (!test_bit(STATUS_ALIVE, &priv->status)) {
  1169. if (hw_rf_kill)
  1170. set_bit(STATUS_RF_KILL_HW, &priv->status);
  1171. else
  1172. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  1173. wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill);
  1174. }
  1175. handled |= CSR_INT_BIT_RF_KILL;
  1176. }
  1177. /* Chip got too hot and stopped itself */
  1178. if (inta & CSR_INT_BIT_CT_KILL) {
  1179. IWL_ERR(priv, "Microcode CT kill error detected.\n");
  1180. priv->isr_stats.ctkill++;
  1181. handled |= CSR_INT_BIT_CT_KILL;
  1182. }
  1183. /* Error detected by uCode */
  1184. if (inta & CSR_INT_BIT_SW_ERR) {
  1185. IWL_ERR(priv, "Microcode SW error detected. "
  1186. " Restarting 0x%X.\n", inta);
  1187. priv->isr_stats.sw++;
  1188. priv->isr_stats.sw_err = inta;
  1189. iwl_irq_handle_error(priv);
  1190. handled |= CSR_INT_BIT_SW_ERR;
  1191. }
  1192. /* uCode wakes up after power-down sleep */
  1193. if (inta & CSR_INT_BIT_WAKEUP) {
  1194. IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
  1195. iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
  1196. for (i = 0; i < priv->hw_params.max_txq_num; i++)
  1197. iwl_txq_update_write_ptr(priv, &priv->txq[i]);
  1198. priv->isr_stats.wakeup++;
  1199. handled |= CSR_INT_BIT_WAKEUP;
  1200. }
  1201. /* All uCode command responses, including Tx command responses,
  1202. * Rx "responses" (frame-received notification), and other
  1203. * notifications from uCode come through here*/
  1204. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX |
  1205. CSR_INT_BIT_RX_PERIODIC)) {
  1206. IWL_DEBUG_ISR(priv, "Rx interrupt\n");
  1207. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
  1208. handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
  1209. iwl_write32(priv, CSR_FH_INT_STATUS,
  1210. CSR49_FH_INT_RX_MASK);
  1211. }
  1212. if (inta & CSR_INT_BIT_RX_PERIODIC) {
  1213. handled |= CSR_INT_BIT_RX_PERIODIC;
  1214. iwl_write32(priv, CSR_INT, CSR_INT_BIT_RX_PERIODIC);
  1215. }
  1216. /* Sending RX interrupt require many steps to be done in the
  1217. * the device:
  1218. * 1- write interrupt to current index in ICT table.
  1219. * 2- dma RX frame.
  1220. * 3- update RX shared data to indicate last write index.
  1221. * 4- send interrupt.
  1222. * This could lead to RX race, driver could receive RX interrupt
  1223. * but the shared data changes does not reflect this;
  1224. * periodic interrupt will detect any dangling Rx activity.
  1225. */
  1226. /* Disable periodic interrupt; we use it as just a one-shot. */
  1227. iwl_write8(priv, CSR_INT_PERIODIC_REG,
  1228. CSR_INT_PERIODIC_DIS);
  1229. iwl_rx_handle(priv);
  1230. /*
  1231. * Enable periodic interrupt in 8 msec only if we received
  1232. * real RX interrupt (instead of just periodic int), to catch
  1233. * any dangling Rx interrupt. If it was just the periodic
  1234. * interrupt, there was no dangling Rx activity, and no need
  1235. * to extend the periodic interrupt; one-shot is enough.
  1236. */
  1237. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX))
  1238. iwl_write8(priv, CSR_INT_PERIODIC_REG,
  1239. CSR_INT_PERIODIC_ENA);
  1240. priv->isr_stats.rx++;
  1241. }
  1242. /* This "Tx" DMA channel is used only for loading uCode */
  1243. if (inta & CSR_INT_BIT_FH_TX) {
  1244. iwl_write32(priv, CSR_FH_INT_STATUS, CSR49_FH_INT_TX_MASK);
  1245. IWL_DEBUG_ISR(priv, "uCode load interrupt\n");
  1246. priv->isr_stats.tx++;
  1247. handled |= CSR_INT_BIT_FH_TX;
  1248. /* Wake up uCode load routine, now that load is complete */
  1249. priv->ucode_write_complete = 1;
  1250. wake_up_interruptible(&priv->wait_command_queue);
  1251. }
  1252. if (inta & ~handled) {
  1253. IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
  1254. priv->isr_stats.unhandled++;
  1255. }
  1256. if (inta & ~(priv->inta_mask)) {
  1257. IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
  1258. inta & ~priv->inta_mask);
  1259. }
  1260. /* Re-enable all interrupts */
  1261. /* only Re-enable if diabled by irq */
  1262. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  1263. iwl_enable_interrupts(priv);
  1264. }
  1265. /* the threshold ratio of actual_ack_cnt to expected_ack_cnt in percent */
  1266. #define ACK_CNT_RATIO (50)
  1267. #define BA_TIMEOUT_CNT (5)
  1268. #define BA_TIMEOUT_MAX (16)
  1269. /**
  1270. * iwl_good_ack_health - checks for ACK count ratios, BA timeout retries.
  1271. *
  1272. * When the ACK count ratio is 0 and aggregated BA timeout retries exceeding
  1273. * the BA_TIMEOUT_MAX, reload firmware and bring system back to normal
  1274. * operation state.
  1275. */
  1276. bool iwl_good_ack_health(struct iwl_priv *priv,
  1277. struct iwl_rx_packet *pkt)
  1278. {
  1279. bool rc = true;
  1280. int actual_ack_cnt_delta, expected_ack_cnt_delta;
  1281. int ba_timeout_delta;
  1282. actual_ack_cnt_delta =
  1283. le32_to_cpu(pkt->u.stats.tx.actual_ack_cnt) -
  1284. le32_to_cpu(priv->_agn.statistics.tx.actual_ack_cnt);
  1285. expected_ack_cnt_delta =
  1286. le32_to_cpu(pkt->u.stats.tx.expected_ack_cnt) -
  1287. le32_to_cpu(priv->_agn.statistics.tx.expected_ack_cnt);
  1288. ba_timeout_delta =
  1289. le32_to_cpu(pkt->u.stats.tx.agg.ba_timeout) -
  1290. le32_to_cpu(priv->_agn.statistics.tx.agg.ba_timeout);
  1291. if ((priv->_agn.agg_tids_count > 0) &&
  1292. (expected_ack_cnt_delta > 0) &&
  1293. (((actual_ack_cnt_delta * 100) / expected_ack_cnt_delta)
  1294. < ACK_CNT_RATIO) &&
  1295. (ba_timeout_delta > BA_TIMEOUT_CNT)) {
  1296. IWL_DEBUG_RADIO(priv, "actual_ack_cnt delta = %d,"
  1297. " expected_ack_cnt = %d\n",
  1298. actual_ack_cnt_delta, expected_ack_cnt_delta);
  1299. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1300. /*
  1301. * This is ifdef'ed on DEBUGFS because otherwise the
  1302. * statistics aren't available. If DEBUGFS is set but
  1303. * DEBUG is not, these will just compile out.
  1304. */
  1305. IWL_DEBUG_RADIO(priv, "rx_detected_cnt delta = %d\n",
  1306. priv->_agn.delta_statistics.tx.rx_detected_cnt);
  1307. IWL_DEBUG_RADIO(priv,
  1308. "ack_or_ba_timeout_collision delta = %d\n",
  1309. priv->_agn.delta_statistics.tx.
  1310. ack_or_ba_timeout_collision);
  1311. #endif
  1312. IWL_DEBUG_RADIO(priv, "agg ba_timeout delta = %d\n",
  1313. ba_timeout_delta);
  1314. if (!actual_ack_cnt_delta &&
  1315. (ba_timeout_delta >= BA_TIMEOUT_MAX))
  1316. rc = false;
  1317. }
  1318. return rc;
  1319. }
  1320. /*****************************************************************************
  1321. *
  1322. * sysfs attributes
  1323. *
  1324. *****************************************************************************/
  1325. #ifdef CONFIG_IWLWIFI_DEBUG
  1326. /*
  1327. * The following adds a new attribute to the sysfs representation
  1328. * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/)
  1329. * used for controlling the debug level.
  1330. *
  1331. * See the level definitions in iwl for details.
  1332. *
  1333. * The debug_level being managed using sysfs below is a per device debug
  1334. * level that is used instead of the global debug level if it (the per
  1335. * device debug level) is set.
  1336. */
  1337. static ssize_t show_debug_level(struct device *d,
  1338. struct device_attribute *attr, char *buf)
  1339. {
  1340. struct iwl_priv *priv = dev_get_drvdata(d);
  1341. return sprintf(buf, "0x%08X\n", iwl_get_debug_level(priv));
  1342. }
  1343. static ssize_t store_debug_level(struct device *d,
  1344. struct device_attribute *attr,
  1345. const char *buf, size_t count)
  1346. {
  1347. struct iwl_priv *priv = dev_get_drvdata(d);
  1348. unsigned long val;
  1349. int ret;
  1350. ret = strict_strtoul(buf, 0, &val);
  1351. if (ret)
  1352. IWL_ERR(priv, "%s is not in hex or decimal form.\n", buf);
  1353. else {
  1354. priv->debug_level = val;
  1355. if (iwl_alloc_traffic_mem(priv))
  1356. IWL_ERR(priv,
  1357. "Not enough memory to generate traffic log\n");
  1358. }
  1359. return strnlen(buf, count);
  1360. }
  1361. static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
  1362. show_debug_level, store_debug_level);
  1363. #endif /* CONFIG_IWLWIFI_DEBUG */
  1364. static ssize_t show_temperature(struct device *d,
  1365. struct device_attribute *attr, char *buf)
  1366. {
  1367. struct iwl_priv *priv = dev_get_drvdata(d);
  1368. if (!iwl_is_alive(priv))
  1369. return -EAGAIN;
  1370. return sprintf(buf, "%d\n", priv->temperature);
  1371. }
  1372. static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
  1373. static ssize_t show_tx_power(struct device *d,
  1374. struct device_attribute *attr, char *buf)
  1375. {
  1376. struct iwl_priv *priv = dev_get_drvdata(d);
  1377. if (!iwl_is_ready_rf(priv))
  1378. return sprintf(buf, "off\n");
  1379. else
  1380. return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
  1381. }
  1382. static ssize_t store_tx_power(struct device *d,
  1383. struct device_attribute *attr,
  1384. const char *buf, size_t count)
  1385. {
  1386. struct iwl_priv *priv = dev_get_drvdata(d);
  1387. unsigned long val;
  1388. int ret;
  1389. ret = strict_strtoul(buf, 10, &val);
  1390. if (ret)
  1391. IWL_INFO(priv, "%s is not in decimal form.\n", buf);
  1392. else {
  1393. ret = iwl_set_tx_power(priv, val, false);
  1394. if (ret)
  1395. IWL_ERR(priv, "failed setting tx power (0x%d).\n",
  1396. ret);
  1397. else
  1398. ret = count;
  1399. }
  1400. return ret;
  1401. }
  1402. static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
  1403. static struct attribute *iwl_sysfs_entries[] = {
  1404. &dev_attr_temperature.attr,
  1405. &dev_attr_tx_power.attr,
  1406. #ifdef CONFIG_IWLWIFI_DEBUG
  1407. &dev_attr_debug_level.attr,
  1408. #endif
  1409. NULL
  1410. };
  1411. static struct attribute_group iwl_attribute_group = {
  1412. .name = NULL, /* put in device directory */
  1413. .attrs = iwl_sysfs_entries,
  1414. };
  1415. /******************************************************************************
  1416. *
  1417. * uCode download functions
  1418. *
  1419. ******************************************************************************/
  1420. static void iwl_dealloc_ucode_pci(struct iwl_priv *priv)
  1421. {
  1422. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
  1423. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
  1424. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  1425. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
  1426. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  1427. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
  1428. }
  1429. static void iwl_nic_start(struct iwl_priv *priv)
  1430. {
  1431. /* Remove all resets to allow NIC to operate */
  1432. iwl_write32(priv, CSR_RESET, 0);
  1433. }
  1434. struct iwlagn_ucode_capabilities {
  1435. u32 max_probe_length;
  1436. u32 standard_phy_calibration_size;
  1437. };
  1438. static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context);
  1439. static int iwl_mac_setup_register(struct iwl_priv *priv,
  1440. struct iwlagn_ucode_capabilities *capa);
  1441. #define UCODE_EXPERIMENTAL_INDEX 100
  1442. #define UCODE_EXPERIMENTAL_TAG "exp"
  1443. static int __must_check iwl_request_firmware(struct iwl_priv *priv, bool first)
  1444. {
  1445. const char *name_pre = priv->cfg->fw_name_pre;
  1446. char tag[8];
  1447. if (first) {
  1448. #ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE
  1449. priv->fw_index = UCODE_EXPERIMENTAL_INDEX;
  1450. strcpy(tag, UCODE_EXPERIMENTAL_TAG);
  1451. } else if (priv->fw_index == UCODE_EXPERIMENTAL_INDEX) {
  1452. #endif
  1453. priv->fw_index = priv->cfg->ucode_api_max;
  1454. sprintf(tag, "%d", priv->fw_index);
  1455. } else {
  1456. priv->fw_index--;
  1457. sprintf(tag, "%d", priv->fw_index);
  1458. }
  1459. if (priv->fw_index < priv->cfg->ucode_api_min) {
  1460. IWL_ERR(priv, "no suitable firmware found!\n");
  1461. return -ENOENT;
  1462. }
  1463. sprintf(priv->firmware_name, "%s%s%s", name_pre, tag, ".ucode");
  1464. IWL_DEBUG_INFO(priv, "attempting to load firmware %s'%s'\n",
  1465. (priv->fw_index == UCODE_EXPERIMENTAL_INDEX)
  1466. ? "EXPERIMENTAL " : "",
  1467. priv->firmware_name);
  1468. return request_firmware_nowait(THIS_MODULE, 1, priv->firmware_name,
  1469. &priv->pci_dev->dev, GFP_KERNEL, priv,
  1470. iwl_ucode_callback);
  1471. }
  1472. struct iwlagn_firmware_pieces {
  1473. const void *inst, *data, *init, *init_data, *boot;
  1474. size_t inst_size, data_size, init_size, init_data_size, boot_size;
  1475. u32 build;
  1476. u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
  1477. u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
  1478. };
  1479. static int iwlagn_load_legacy_firmware(struct iwl_priv *priv,
  1480. const struct firmware *ucode_raw,
  1481. struct iwlagn_firmware_pieces *pieces)
  1482. {
  1483. struct iwl_ucode_header *ucode = (void *)ucode_raw->data;
  1484. u32 api_ver, hdr_size;
  1485. const u8 *src;
  1486. priv->ucode_ver = le32_to_cpu(ucode->ver);
  1487. api_ver = IWL_UCODE_API(priv->ucode_ver);
  1488. switch (api_ver) {
  1489. default:
  1490. /*
  1491. * 4965 doesn't revision the firmware file format
  1492. * along with the API version, it always uses v1
  1493. * file format.
  1494. */
  1495. if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) !=
  1496. CSR_HW_REV_TYPE_4965) {
  1497. hdr_size = 28;
  1498. if (ucode_raw->size < hdr_size) {
  1499. IWL_ERR(priv, "File size too small!\n");
  1500. return -EINVAL;
  1501. }
  1502. pieces->build = le32_to_cpu(ucode->u.v2.build);
  1503. pieces->inst_size = le32_to_cpu(ucode->u.v2.inst_size);
  1504. pieces->data_size = le32_to_cpu(ucode->u.v2.data_size);
  1505. pieces->init_size = le32_to_cpu(ucode->u.v2.init_size);
  1506. pieces->init_data_size = le32_to_cpu(ucode->u.v2.init_data_size);
  1507. pieces->boot_size = le32_to_cpu(ucode->u.v2.boot_size);
  1508. src = ucode->u.v2.data;
  1509. break;
  1510. }
  1511. /* fall through for 4965 */
  1512. case 0:
  1513. case 1:
  1514. case 2:
  1515. hdr_size = 24;
  1516. if (ucode_raw->size < hdr_size) {
  1517. IWL_ERR(priv, "File size too small!\n");
  1518. return -EINVAL;
  1519. }
  1520. pieces->build = 0;
  1521. pieces->inst_size = le32_to_cpu(ucode->u.v1.inst_size);
  1522. pieces->data_size = le32_to_cpu(ucode->u.v1.data_size);
  1523. pieces->init_size = le32_to_cpu(ucode->u.v1.init_size);
  1524. pieces->init_data_size = le32_to_cpu(ucode->u.v1.init_data_size);
  1525. pieces->boot_size = le32_to_cpu(ucode->u.v1.boot_size);
  1526. src = ucode->u.v1.data;
  1527. break;
  1528. }
  1529. /* Verify size of file vs. image size info in file's header */
  1530. if (ucode_raw->size != hdr_size + pieces->inst_size +
  1531. pieces->data_size + pieces->init_size +
  1532. pieces->init_data_size + pieces->boot_size) {
  1533. IWL_ERR(priv,
  1534. "uCode file size %d does not match expected size\n",
  1535. (int)ucode_raw->size);
  1536. return -EINVAL;
  1537. }
  1538. pieces->inst = src;
  1539. src += pieces->inst_size;
  1540. pieces->data = src;
  1541. src += pieces->data_size;
  1542. pieces->init = src;
  1543. src += pieces->init_size;
  1544. pieces->init_data = src;
  1545. src += pieces->init_data_size;
  1546. pieces->boot = src;
  1547. src += pieces->boot_size;
  1548. return 0;
  1549. }
  1550. static int iwlagn_wanted_ucode_alternative = 1;
  1551. static int iwlagn_load_firmware(struct iwl_priv *priv,
  1552. const struct firmware *ucode_raw,
  1553. struct iwlagn_firmware_pieces *pieces,
  1554. struct iwlagn_ucode_capabilities *capa)
  1555. {
  1556. struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data;
  1557. struct iwl_ucode_tlv *tlv;
  1558. size_t len = ucode_raw->size;
  1559. const u8 *data;
  1560. int wanted_alternative = iwlagn_wanted_ucode_alternative, tmp;
  1561. u64 alternatives;
  1562. u32 tlv_len;
  1563. enum iwl_ucode_tlv_type tlv_type;
  1564. const u8 *tlv_data;
  1565. if (len < sizeof(*ucode)) {
  1566. IWL_ERR(priv, "uCode has invalid length: %zd\n", len);
  1567. return -EINVAL;
  1568. }
  1569. if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) {
  1570. IWL_ERR(priv, "invalid uCode magic: 0X%x\n",
  1571. le32_to_cpu(ucode->magic));
  1572. return -EINVAL;
  1573. }
  1574. /*
  1575. * Check which alternatives are present, and "downgrade"
  1576. * when the chosen alternative is not present, warning
  1577. * the user when that happens. Some files may not have
  1578. * any alternatives, so don't warn in that case.
  1579. */
  1580. alternatives = le64_to_cpu(ucode->alternatives);
  1581. tmp = wanted_alternative;
  1582. if (wanted_alternative > 63)
  1583. wanted_alternative = 63;
  1584. while (wanted_alternative && !(alternatives & BIT(wanted_alternative)))
  1585. wanted_alternative--;
  1586. if (wanted_alternative && wanted_alternative != tmp)
  1587. IWL_WARN(priv,
  1588. "uCode alternative %d not available, choosing %d\n",
  1589. tmp, wanted_alternative);
  1590. priv->ucode_ver = le32_to_cpu(ucode->ver);
  1591. pieces->build = le32_to_cpu(ucode->build);
  1592. data = ucode->data;
  1593. len -= sizeof(*ucode);
  1594. while (len >= sizeof(*tlv)) {
  1595. u16 tlv_alt;
  1596. len -= sizeof(*tlv);
  1597. tlv = (void *)data;
  1598. tlv_len = le32_to_cpu(tlv->length);
  1599. tlv_type = le16_to_cpu(tlv->type);
  1600. tlv_alt = le16_to_cpu(tlv->alternative);
  1601. tlv_data = tlv->data;
  1602. if (len < tlv_len) {
  1603. IWL_ERR(priv, "invalid TLV len: %zd/%u\n",
  1604. len, tlv_len);
  1605. return -EINVAL;
  1606. }
  1607. len -= ALIGN(tlv_len, 4);
  1608. data += sizeof(*tlv) + ALIGN(tlv_len, 4);
  1609. /*
  1610. * Alternative 0 is always valid.
  1611. *
  1612. * Skip alternative TLVs that are not selected.
  1613. */
  1614. if (tlv_alt != 0 && tlv_alt != wanted_alternative)
  1615. continue;
  1616. switch (tlv_type) {
  1617. case IWL_UCODE_TLV_INST:
  1618. pieces->inst = tlv_data;
  1619. pieces->inst_size = tlv_len;
  1620. break;
  1621. case IWL_UCODE_TLV_DATA:
  1622. pieces->data = tlv_data;
  1623. pieces->data_size = tlv_len;
  1624. break;
  1625. case IWL_UCODE_TLV_INIT:
  1626. pieces->init = tlv_data;
  1627. pieces->init_size = tlv_len;
  1628. break;
  1629. case IWL_UCODE_TLV_INIT_DATA:
  1630. pieces->init_data = tlv_data;
  1631. pieces->init_data_size = tlv_len;
  1632. break;
  1633. case IWL_UCODE_TLV_BOOT:
  1634. pieces->boot = tlv_data;
  1635. pieces->boot_size = tlv_len;
  1636. break;
  1637. case IWL_UCODE_TLV_PROBE_MAX_LEN:
  1638. if (tlv_len != sizeof(u32))
  1639. goto invalid_tlv_len;
  1640. capa->max_probe_length =
  1641. le32_to_cpup((__le32 *)tlv_data);
  1642. break;
  1643. case IWL_UCODE_TLV_INIT_EVTLOG_PTR:
  1644. if (tlv_len != sizeof(u32))
  1645. goto invalid_tlv_len;
  1646. pieces->init_evtlog_ptr =
  1647. le32_to_cpup((__le32 *)tlv_data);
  1648. break;
  1649. case IWL_UCODE_TLV_INIT_EVTLOG_SIZE:
  1650. if (tlv_len != sizeof(u32))
  1651. goto invalid_tlv_len;
  1652. pieces->init_evtlog_size =
  1653. le32_to_cpup((__le32 *)tlv_data);
  1654. break;
  1655. case IWL_UCODE_TLV_INIT_ERRLOG_PTR:
  1656. if (tlv_len != sizeof(u32))
  1657. goto invalid_tlv_len;
  1658. pieces->init_errlog_ptr =
  1659. le32_to_cpup((__le32 *)tlv_data);
  1660. break;
  1661. case IWL_UCODE_TLV_RUNT_EVTLOG_PTR:
  1662. if (tlv_len != sizeof(u32))
  1663. goto invalid_tlv_len;
  1664. pieces->inst_evtlog_ptr =
  1665. le32_to_cpup((__le32 *)tlv_data);
  1666. break;
  1667. case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE:
  1668. if (tlv_len != sizeof(u32))
  1669. goto invalid_tlv_len;
  1670. pieces->inst_evtlog_size =
  1671. le32_to_cpup((__le32 *)tlv_data);
  1672. break;
  1673. case IWL_UCODE_TLV_RUNT_ERRLOG_PTR:
  1674. if (tlv_len != sizeof(u32))
  1675. goto invalid_tlv_len;
  1676. pieces->inst_errlog_ptr =
  1677. le32_to_cpup((__le32 *)tlv_data);
  1678. break;
  1679. case IWL_UCODE_TLV_ENHANCE_SENS_TBL:
  1680. if (tlv_len)
  1681. goto invalid_tlv_len;
  1682. priv->enhance_sensitivity_table = true;
  1683. break;
  1684. case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE:
  1685. if (tlv_len != sizeof(u32))
  1686. goto invalid_tlv_len;
  1687. capa->standard_phy_calibration_size =
  1688. le32_to_cpup((__le32 *)tlv_data);
  1689. break;
  1690. default:
  1691. IWL_WARN(priv, "unknown TLV: %d\n", tlv_type);
  1692. break;
  1693. }
  1694. }
  1695. if (len) {
  1696. IWL_ERR(priv, "invalid TLV after parsing: %zd\n", len);
  1697. iwl_print_hex_dump(priv, IWL_DL_FW, (u8 *)data, len);
  1698. return -EINVAL;
  1699. }
  1700. return 0;
  1701. invalid_tlv_len:
  1702. IWL_ERR(priv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len);
  1703. iwl_print_hex_dump(priv, IWL_DL_FW, tlv_data, tlv_len);
  1704. return -EINVAL;
  1705. }
  1706. /**
  1707. * iwl_ucode_callback - callback when firmware was loaded
  1708. *
  1709. * If loaded successfully, copies the firmware into buffers
  1710. * for the card to fetch (via DMA).
  1711. */
  1712. static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
  1713. {
  1714. struct iwl_priv *priv = context;
  1715. struct iwl_ucode_header *ucode;
  1716. int err;
  1717. struct iwlagn_firmware_pieces pieces;
  1718. const unsigned int api_max = priv->cfg->ucode_api_max;
  1719. const unsigned int api_min = priv->cfg->ucode_api_min;
  1720. u32 api_ver;
  1721. char buildstr[25];
  1722. u32 build;
  1723. struct iwlagn_ucode_capabilities ucode_capa = {
  1724. .max_probe_length = 200,
  1725. .standard_phy_calibration_size =
  1726. IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE,
  1727. };
  1728. memset(&pieces, 0, sizeof(pieces));
  1729. if (!ucode_raw) {
  1730. if (priv->fw_index <= priv->cfg->ucode_api_max)
  1731. IWL_ERR(priv,
  1732. "request for firmware file '%s' failed.\n",
  1733. priv->firmware_name);
  1734. goto try_again;
  1735. }
  1736. IWL_DEBUG_INFO(priv, "Loaded firmware file '%s' (%zd bytes).\n",
  1737. priv->firmware_name, ucode_raw->size);
  1738. /* Make sure that we got at least the API version number */
  1739. if (ucode_raw->size < 4) {
  1740. IWL_ERR(priv, "File size way too small!\n");
  1741. goto try_again;
  1742. }
  1743. /* Data from ucode file: header followed by uCode images */
  1744. ucode = (struct iwl_ucode_header *)ucode_raw->data;
  1745. if (ucode->ver)
  1746. err = iwlagn_load_legacy_firmware(priv, ucode_raw, &pieces);
  1747. else
  1748. err = iwlagn_load_firmware(priv, ucode_raw, &pieces,
  1749. &ucode_capa);
  1750. if (err)
  1751. goto try_again;
  1752. api_ver = IWL_UCODE_API(priv->ucode_ver);
  1753. build = pieces.build;
  1754. /*
  1755. * api_ver should match the api version forming part of the
  1756. * firmware filename ... but we don't check for that and only rely
  1757. * on the API version read from firmware header from here on forward
  1758. */
  1759. if (api_ver < api_min || api_ver > api_max) {
  1760. IWL_ERR(priv, "Driver unable to support your firmware API. "
  1761. "Driver supports v%u, firmware is v%u.\n",
  1762. api_max, api_ver);
  1763. goto try_again;
  1764. }
  1765. if (api_ver != api_max)
  1766. IWL_ERR(priv, "Firmware has old API version. Expected v%u, "
  1767. "got v%u. New firmware can be obtained "
  1768. "from http://www.intellinuxwireless.org.\n",
  1769. api_max, api_ver);
  1770. if (build)
  1771. sprintf(buildstr, " build %u%s", build,
  1772. (priv->fw_index == UCODE_EXPERIMENTAL_INDEX)
  1773. ? " (EXP)" : "");
  1774. else
  1775. buildstr[0] = '\0';
  1776. IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u%s\n",
  1777. IWL_UCODE_MAJOR(priv->ucode_ver),
  1778. IWL_UCODE_MINOR(priv->ucode_ver),
  1779. IWL_UCODE_API(priv->ucode_ver),
  1780. IWL_UCODE_SERIAL(priv->ucode_ver),
  1781. buildstr);
  1782. snprintf(priv->hw->wiphy->fw_version,
  1783. sizeof(priv->hw->wiphy->fw_version),
  1784. "%u.%u.%u.%u%s",
  1785. IWL_UCODE_MAJOR(priv->ucode_ver),
  1786. IWL_UCODE_MINOR(priv->ucode_ver),
  1787. IWL_UCODE_API(priv->ucode_ver),
  1788. IWL_UCODE_SERIAL(priv->ucode_ver),
  1789. buildstr);
  1790. /*
  1791. * For any of the failures below (before allocating pci memory)
  1792. * we will try to load a version with a smaller API -- maybe the
  1793. * user just got a corrupted version of the latest API.
  1794. */
  1795. IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
  1796. priv->ucode_ver);
  1797. IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %Zd\n",
  1798. pieces.inst_size);
  1799. IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %Zd\n",
  1800. pieces.data_size);
  1801. IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %Zd\n",
  1802. pieces.init_size);
  1803. IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %Zd\n",
  1804. pieces.init_data_size);
  1805. IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %Zd\n",
  1806. pieces.boot_size);
  1807. /* Verify that uCode images will fit in card's SRAM */
  1808. if (pieces.inst_size > priv->hw_params.max_inst_size) {
  1809. IWL_ERR(priv, "uCode instr len %Zd too large to fit in\n",
  1810. pieces.inst_size);
  1811. goto try_again;
  1812. }
  1813. if (pieces.data_size > priv->hw_params.max_data_size) {
  1814. IWL_ERR(priv, "uCode data len %Zd too large to fit in\n",
  1815. pieces.data_size);
  1816. goto try_again;
  1817. }
  1818. if (pieces.init_size > priv->hw_params.max_inst_size) {
  1819. IWL_ERR(priv, "uCode init instr len %Zd too large to fit in\n",
  1820. pieces.init_size);
  1821. goto try_again;
  1822. }
  1823. if (pieces.init_data_size > priv->hw_params.max_data_size) {
  1824. IWL_ERR(priv, "uCode init data len %Zd too large to fit in\n",
  1825. pieces.init_data_size);
  1826. goto try_again;
  1827. }
  1828. if (pieces.boot_size > priv->hw_params.max_bsm_size) {
  1829. IWL_ERR(priv, "uCode boot instr len %Zd too large to fit in\n",
  1830. pieces.boot_size);
  1831. goto try_again;
  1832. }
  1833. /* Allocate ucode buffers for card's bus-master loading ... */
  1834. /* Runtime instructions and 2 copies of data:
  1835. * 1) unmodified from disk
  1836. * 2) backup cache for save/restore during power-downs */
  1837. priv->ucode_code.len = pieces.inst_size;
  1838. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
  1839. priv->ucode_data.len = pieces.data_size;
  1840. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
  1841. priv->ucode_data_backup.len = pieces.data_size;
  1842. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  1843. if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
  1844. !priv->ucode_data_backup.v_addr)
  1845. goto err_pci_alloc;
  1846. /* Initialization instructions and data */
  1847. if (pieces.init_size && pieces.init_data_size) {
  1848. priv->ucode_init.len = pieces.init_size;
  1849. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
  1850. priv->ucode_init_data.len = pieces.init_data_size;
  1851. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  1852. if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
  1853. goto err_pci_alloc;
  1854. }
  1855. /* Bootstrap (instructions only, no data) */
  1856. if (pieces.boot_size) {
  1857. priv->ucode_boot.len = pieces.boot_size;
  1858. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
  1859. if (!priv->ucode_boot.v_addr)
  1860. goto err_pci_alloc;
  1861. }
  1862. /* Now that we can no longer fail, copy information */
  1863. /*
  1864. * The (size - 16) / 12 formula is based on the information recorded
  1865. * for each event, which is of mode 1 (including timestamp) for all
  1866. * new microcodes that include this information.
  1867. */
  1868. priv->_agn.init_evtlog_ptr = pieces.init_evtlog_ptr;
  1869. if (pieces.init_evtlog_size)
  1870. priv->_agn.init_evtlog_size = (pieces.init_evtlog_size - 16)/12;
  1871. else
  1872. priv->_agn.init_evtlog_size = priv->cfg->max_event_log_size;
  1873. priv->_agn.init_errlog_ptr = pieces.init_errlog_ptr;
  1874. priv->_agn.inst_evtlog_ptr = pieces.inst_evtlog_ptr;
  1875. if (pieces.inst_evtlog_size)
  1876. priv->_agn.inst_evtlog_size = (pieces.inst_evtlog_size - 16)/12;
  1877. else
  1878. priv->_agn.inst_evtlog_size = priv->cfg->max_event_log_size;
  1879. priv->_agn.inst_errlog_ptr = pieces.inst_errlog_ptr;
  1880. /* Copy images into buffers for card's bus-master reads ... */
  1881. /* Runtime instructions (first block of data in file) */
  1882. IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode instr len %Zd\n",
  1883. pieces.inst_size);
  1884. memcpy(priv->ucode_code.v_addr, pieces.inst, pieces.inst_size);
  1885. IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
  1886. priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
  1887. /*
  1888. * Runtime data
  1889. * NOTE: Copy into backup buffer will be done in iwl_up()
  1890. */
  1891. IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode data len %Zd\n",
  1892. pieces.data_size);
  1893. memcpy(priv->ucode_data.v_addr, pieces.data, pieces.data_size);
  1894. memcpy(priv->ucode_data_backup.v_addr, pieces.data, pieces.data_size);
  1895. /* Initialization instructions */
  1896. if (pieces.init_size) {
  1897. IWL_DEBUG_INFO(priv, "Copying (but not loading) init instr len %Zd\n",
  1898. pieces.init_size);
  1899. memcpy(priv->ucode_init.v_addr, pieces.init, pieces.init_size);
  1900. }
  1901. /* Initialization data */
  1902. if (pieces.init_data_size) {
  1903. IWL_DEBUG_INFO(priv, "Copying (but not loading) init data len %Zd\n",
  1904. pieces.init_data_size);
  1905. memcpy(priv->ucode_init_data.v_addr, pieces.init_data,
  1906. pieces.init_data_size);
  1907. }
  1908. /* Bootstrap instructions */
  1909. IWL_DEBUG_INFO(priv, "Copying (but not loading) boot instr len %Zd\n",
  1910. pieces.boot_size);
  1911. memcpy(priv->ucode_boot.v_addr, pieces.boot, pieces.boot_size);
  1912. /*
  1913. * figure out the offset of chain noise reset and gain commands
  1914. * base on the size of standard phy calibration commands table size
  1915. */
  1916. if (ucode_capa.standard_phy_calibration_size >
  1917. IWL_MAX_PHY_CALIBRATE_TBL_SIZE)
  1918. ucode_capa.standard_phy_calibration_size =
  1919. IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE;
  1920. priv->_agn.phy_calib_chain_noise_reset_cmd =
  1921. ucode_capa.standard_phy_calibration_size;
  1922. priv->_agn.phy_calib_chain_noise_gain_cmd =
  1923. ucode_capa.standard_phy_calibration_size + 1;
  1924. /**************************************************
  1925. * This is still part of probe() in a sense...
  1926. *
  1927. * 9. Setup and register with mac80211 and debugfs
  1928. **************************************************/
  1929. err = iwl_mac_setup_register(priv, &ucode_capa);
  1930. if (err)
  1931. goto out_unbind;
  1932. err = iwl_dbgfs_register(priv, DRV_NAME);
  1933. if (err)
  1934. IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
  1935. err = sysfs_create_group(&priv->pci_dev->dev.kobj,
  1936. &iwl_attribute_group);
  1937. if (err) {
  1938. IWL_ERR(priv, "failed to create sysfs device attributes\n");
  1939. goto out_unbind;
  1940. }
  1941. /* We have our copies now, allow OS release its copies */
  1942. release_firmware(ucode_raw);
  1943. complete(&priv->_agn.firmware_loading_complete);
  1944. return;
  1945. try_again:
  1946. /* try next, if any */
  1947. if (iwl_request_firmware(priv, false))
  1948. goto out_unbind;
  1949. release_firmware(ucode_raw);
  1950. return;
  1951. err_pci_alloc:
  1952. IWL_ERR(priv, "failed to allocate pci memory\n");
  1953. iwl_dealloc_ucode_pci(priv);
  1954. out_unbind:
  1955. complete(&priv->_agn.firmware_loading_complete);
  1956. device_release_driver(&priv->pci_dev->dev);
  1957. release_firmware(ucode_raw);
  1958. }
  1959. static const char *desc_lookup_text[] = {
  1960. "OK",
  1961. "FAIL",
  1962. "BAD_PARAM",
  1963. "BAD_CHECKSUM",
  1964. "NMI_INTERRUPT_WDG",
  1965. "SYSASSERT",
  1966. "FATAL_ERROR",
  1967. "BAD_COMMAND",
  1968. "HW_ERROR_TUNE_LOCK",
  1969. "HW_ERROR_TEMPERATURE",
  1970. "ILLEGAL_CHAN_FREQ",
  1971. "VCC_NOT_STABLE",
  1972. "FH_ERROR",
  1973. "NMI_INTERRUPT_HOST",
  1974. "NMI_INTERRUPT_ACTION_PT",
  1975. "NMI_INTERRUPT_UNKNOWN",
  1976. "UCODE_VERSION_MISMATCH",
  1977. "HW_ERROR_ABS_LOCK",
  1978. "HW_ERROR_CAL_LOCK_FAIL",
  1979. "NMI_INTERRUPT_INST_ACTION_PT",
  1980. "NMI_INTERRUPT_DATA_ACTION_PT",
  1981. "NMI_TRM_HW_ER",
  1982. "NMI_INTERRUPT_TRM",
  1983. "NMI_INTERRUPT_BREAK_POINT"
  1984. "DEBUG_0",
  1985. "DEBUG_1",
  1986. "DEBUG_2",
  1987. "DEBUG_3",
  1988. };
  1989. static struct { char *name; u8 num; } advanced_lookup[] = {
  1990. { "NMI_INTERRUPT_WDG", 0x34 },
  1991. { "SYSASSERT", 0x35 },
  1992. { "UCODE_VERSION_MISMATCH", 0x37 },
  1993. { "BAD_COMMAND", 0x38 },
  1994. { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
  1995. { "FATAL_ERROR", 0x3D },
  1996. { "NMI_TRM_HW_ERR", 0x46 },
  1997. { "NMI_INTERRUPT_TRM", 0x4C },
  1998. { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
  1999. { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
  2000. { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
  2001. { "NMI_INTERRUPT_HOST", 0x66 },
  2002. { "NMI_INTERRUPT_ACTION_PT", 0x7C },
  2003. { "NMI_INTERRUPT_UNKNOWN", 0x84 },
  2004. { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
  2005. { "ADVANCED_SYSASSERT", 0 },
  2006. };
  2007. static const char *desc_lookup(u32 num)
  2008. {
  2009. int i;
  2010. int max = ARRAY_SIZE(desc_lookup_text);
  2011. if (num < max)
  2012. return desc_lookup_text[num];
  2013. max = ARRAY_SIZE(advanced_lookup) - 1;
  2014. for (i = 0; i < max; i++) {
  2015. if (advanced_lookup[i].num == num)
  2016. break;;
  2017. }
  2018. return advanced_lookup[i].name;
  2019. }
  2020. #define ERROR_START_OFFSET (1 * sizeof(u32))
  2021. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  2022. void iwl_dump_nic_error_log(struct iwl_priv *priv)
  2023. {
  2024. u32 data2, line;
  2025. u32 desc, time, count, base, data1;
  2026. u32 blink1, blink2, ilink1, ilink2;
  2027. u32 pc, hcmd;
  2028. if (priv->ucode_type == UCODE_INIT) {
  2029. base = le32_to_cpu(priv->card_alive_init.error_event_table_ptr);
  2030. if (!base)
  2031. base = priv->_agn.init_errlog_ptr;
  2032. } else {
  2033. base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
  2034. if (!base)
  2035. base = priv->_agn.inst_errlog_ptr;
  2036. }
  2037. if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
  2038. IWL_ERR(priv,
  2039. "Not valid error log pointer 0x%08X for %s uCode\n",
  2040. base, (priv->ucode_type == UCODE_INIT) ? "Init" : "RT");
  2041. return;
  2042. }
  2043. count = iwl_read_targ_mem(priv, base);
  2044. if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
  2045. IWL_ERR(priv, "Start IWL Error Log Dump:\n");
  2046. IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
  2047. priv->status, count);
  2048. }
  2049. desc = iwl_read_targ_mem(priv, base + 1 * sizeof(u32));
  2050. pc = iwl_read_targ_mem(priv, base + 2 * sizeof(u32));
  2051. blink1 = iwl_read_targ_mem(priv, base + 3 * sizeof(u32));
  2052. blink2 = iwl_read_targ_mem(priv, base + 4 * sizeof(u32));
  2053. ilink1 = iwl_read_targ_mem(priv, base + 5 * sizeof(u32));
  2054. ilink2 = iwl_read_targ_mem(priv, base + 6 * sizeof(u32));
  2055. data1 = iwl_read_targ_mem(priv, base + 7 * sizeof(u32));
  2056. data2 = iwl_read_targ_mem(priv, base + 8 * sizeof(u32));
  2057. line = iwl_read_targ_mem(priv, base + 9 * sizeof(u32));
  2058. time = iwl_read_targ_mem(priv, base + 11 * sizeof(u32));
  2059. hcmd = iwl_read_targ_mem(priv, base + 22 * sizeof(u32));
  2060. trace_iwlwifi_dev_ucode_error(priv, desc, time, data1, data2, line,
  2061. blink1, blink2, ilink1, ilink2);
  2062. IWL_ERR(priv, "Desc Time "
  2063. "data1 data2 line\n");
  2064. IWL_ERR(priv, "%-28s (0x%04X) %010u 0x%08X 0x%08X %u\n",
  2065. desc_lookup(desc), desc, time, data1, data2, line);
  2066. IWL_ERR(priv, "pc blink1 blink2 ilink1 ilink2 hcmd\n");
  2067. IWL_ERR(priv, "0x%05X 0x%05X 0x%05X 0x%05X 0x%05X 0x%05X\n",
  2068. pc, blink1, blink2, ilink1, ilink2, hcmd);
  2069. }
  2070. #define EVENT_START_OFFSET (4 * sizeof(u32))
  2071. /**
  2072. * iwl_print_event_log - Dump error event log to syslog
  2073. *
  2074. */
  2075. static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
  2076. u32 num_events, u32 mode,
  2077. int pos, char **buf, size_t bufsz)
  2078. {
  2079. u32 i;
  2080. u32 base; /* SRAM byte address of event log header */
  2081. u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
  2082. u32 ptr; /* SRAM byte address of log data */
  2083. u32 ev, time, data; /* event log data */
  2084. unsigned long reg_flags;
  2085. if (num_events == 0)
  2086. return pos;
  2087. if (priv->ucode_type == UCODE_INIT) {
  2088. base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
  2089. if (!base)
  2090. base = priv->_agn.init_evtlog_ptr;
  2091. } else {
  2092. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  2093. if (!base)
  2094. base = priv->_agn.inst_evtlog_ptr;
  2095. }
  2096. if (mode == 0)
  2097. event_size = 2 * sizeof(u32);
  2098. else
  2099. event_size = 3 * sizeof(u32);
  2100. ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
  2101. /* Make sure device is powered up for SRAM reads */
  2102. spin_lock_irqsave(&priv->reg_lock, reg_flags);
  2103. iwl_grab_nic_access(priv);
  2104. /* Set starting address; reads will auto-increment */
  2105. _iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, ptr);
  2106. rmb();
  2107. /* "time" is actually "data" for mode 0 (no timestamp).
  2108. * place event id # at far right for easier visual parsing. */
  2109. for (i = 0; i < num_events; i++) {
  2110. ev = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  2111. time = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  2112. if (mode == 0) {
  2113. /* data, ev */
  2114. if (bufsz) {
  2115. pos += scnprintf(*buf + pos, bufsz - pos,
  2116. "EVT_LOG:0x%08x:%04u\n",
  2117. time, ev);
  2118. } else {
  2119. trace_iwlwifi_dev_ucode_event(priv, 0,
  2120. time, ev);
  2121. IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n",
  2122. time, ev);
  2123. }
  2124. } else {
  2125. data = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  2126. if (bufsz) {
  2127. pos += scnprintf(*buf + pos, bufsz - pos,
  2128. "EVT_LOGT:%010u:0x%08x:%04u\n",
  2129. time, data, ev);
  2130. } else {
  2131. IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
  2132. time, data, ev);
  2133. trace_iwlwifi_dev_ucode_event(priv, time,
  2134. data, ev);
  2135. }
  2136. }
  2137. }
  2138. /* Allow device to power down */
  2139. iwl_release_nic_access(priv);
  2140. spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
  2141. return pos;
  2142. }
  2143. /**
  2144. * iwl_print_last_event_logs - Dump the newest # of event log to syslog
  2145. */
  2146. static int iwl_print_last_event_logs(struct iwl_priv *priv, u32 capacity,
  2147. u32 num_wraps, u32 next_entry,
  2148. u32 size, u32 mode,
  2149. int pos, char **buf, size_t bufsz)
  2150. {
  2151. /*
  2152. * display the newest DEFAULT_LOG_ENTRIES entries
  2153. * i.e the entries just before the next ont that uCode would fill.
  2154. */
  2155. if (num_wraps) {
  2156. if (next_entry < size) {
  2157. pos = iwl_print_event_log(priv,
  2158. capacity - (size - next_entry),
  2159. size - next_entry, mode,
  2160. pos, buf, bufsz);
  2161. pos = iwl_print_event_log(priv, 0,
  2162. next_entry, mode,
  2163. pos, buf, bufsz);
  2164. } else
  2165. pos = iwl_print_event_log(priv, next_entry - size,
  2166. size, mode, pos, buf, bufsz);
  2167. } else {
  2168. if (next_entry < size) {
  2169. pos = iwl_print_event_log(priv, 0, next_entry,
  2170. mode, pos, buf, bufsz);
  2171. } else {
  2172. pos = iwl_print_event_log(priv, next_entry - size,
  2173. size, mode, pos, buf, bufsz);
  2174. }
  2175. }
  2176. return pos;
  2177. }
  2178. #define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20)
  2179. int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
  2180. char **buf, bool display)
  2181. {
  2182. u32 base; /* SRAM byte address of event log header */
  2183. u32 capacity; /* event log capacity in # entries */
  2184. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  2185. u32 num_wraps; /* # times uCode wrapped to top of log */
  2186. u32 next_entry; /* index of next entry to be written by uCode */
  2187. u32 size; /* # entries that we'll print */
  2188. u32 logsize;
  2189. int pos = 0;
  2190. size_t bufsz = 0;
  2191. if (priv->ucode_type == UCODE_INIT) {
  2192. base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
  2193. logsize = priv->_agn.init_evtlog_size;
  2194. if (!base)
  2195. base = priv->_agn.init_evtlog_ptr;
  2196. } else {
  2197. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  2198. logsize = priv->_agn.inst_evtlog_size;
  2199. if (!base)
  2200. base = priv->_agn.inst_evtlog_ptr;
  2201. }
  2202. if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
  2203. IWL_ERR(priv,
  2204. "Invalid event log pointer 0x%08X for %s uCode\n",
  2205. base, (priv->ucode_type == UCODE_INIT) ? "Init" : "RT");
  2206. return -EINVAL;
  2207. }
  2208. /* event log header */
  2209. capacity = iwl_read_targ_mem(priv, base);
  2210. mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
  2211. num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
  2212. next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
  2213. if (capacity > logsize) {
  2214. IWL_ERR(priv, "Log capacity %d is bogus, limit to %d entries\n",
  2215. capacity, logsize);
  2216. capacity = logsize;
  2217. }
  2218. if (next_entry > logsize) {
  2219. IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n",
  2220. next_entry, logsize);
  2221. next_entry = logsize;
  2222. }
  2223. size = num_wraps ? capacity : next_entry;
  2224. /* bail out if nothing in log */
  2225. if (size == 0) {
  2226. IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
  2227. return pos;
  2228. }
  2229. #ifdef CONFIG_IWLWIFI_DEBUG
  2230. if (!(iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) && !full_log)
  2231. size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
  2232. ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
  2233. #else
  2234. size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
  2235. ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
  2236. #endif
  2237. IWL_ERR(priv, "Start IWL Event Log Dump: display last %u entries\n",
  2238. size);
  2239. #ifdef CONFIG_IWLWIFI_DEBUG
  2240. if (display) {
  2241. if (full_log)
  2242. bufsz = capacity * 48;
  2243. else
  2244. bufsz = size * 48;
  2245. *buf = kmalloc(bufsz, GFP_KERNEL);
  2246. if (!*buf)
  2247. return -ENOMEM;
  2248. }
  2249. if ((iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) || full_log) {
  2250. /*
  2251. * if uCode has wrapped back to top of log,
  2252. * start at the oldest entry,
  2253. * i.e the next one that uCode would fill.
  2254. */
  2255. if (num_wraps)
  2256. pos = iwl_print_event_log(priv, next_entry,
  2257. capacity - next_entry, mode,
  2258. pos, buf, bufsz);
  2259. /* (then/else) start at top of log */
  2260. pos = iwl_print_event_log(priv, 0,
  2261. next_entry, mode, pos, buf, bufsz);
  2262. } else
  2263. pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
  2264. next_entry, size, mode,
  2265. pos, buf, bufsz);
  2266. #else
  2267. pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
  2268. next_entry, size, mode,
  2269. pos, buf, bufsz);
  2270. #endif
  2271. return pos;
  2272. }
  2273. static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
  2274. {
  2275. struct iwl_ct_kill_config cmd;
  2276. struct iwl_ct_kill_throttling_config adv_cmd;
  2277. unsigned long flags;
  2278. int ret = 0;
  2279. spin_lock_irqsave(&priv->lock, flags);
  2280. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  2281. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  2282. spin_unlock_irqrestore(&priv->lock, flags);
  2283. priv->thermal_throttle.ct_kill_toggle = false;
  2284. if (priv->cfg->support_ct_kill_exit) {
  2285. adv_cmd.critical_temperature_enter =
  2286. cpu_to_le32(priv->hw_params.ct_kill_threshold);
  2287. adv_cmd.critical_temperature_exit =
  2288. cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
  2289. ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
  2290. sizeof(adv_cmd), &adv_cmd);
  2291. if (ret)
  2292. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  2293. else
  2294. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  2295. "succeeded, "
  2296. "critical temperature enter is %d,"
  2297. "exit is %d\n",
  2298. priv->hw_params.ct_kill_threshold,
  2299. priv->hw_params.ct_kill_exit_threshold);
  2300. } else {
  2301. cmd.critical_temperature_R =
  2302. cpu_to_le32(priv->hw_params.ct_kill_threshold);
  2303. ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
  2304. sizeof(cmd), &cmd);
  2305. if (ret)
  2306. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  2307. else
  2308. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  2309. "succeeded, "
  2310. "critical temperature is %d\n",
  2311. priv->hw_params.ct_kill_threshold);
  2312. }
  2313. }
  2314. /**
  2315. * iwl_alive_start - called after REPLY_ALIVE notification received
  2316. * from protocol/runtime uCode (initialization uCode's
  2317. * Alive gets handled by iwl_init_alive_start()).
  2318. */
  2319. static void iwl_alive_start(struct iwl_priv *priv)
  2320. {
  2321. int ret = 0;
  2322. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  2323. if (priv->card_alive.is_valid != UCODE_VALID_OK) {
  2324. /* We had an error bringing up the hardware, so take it
  2325. * all the way back down so we can try again */
  2326. IWL_DEBUG_INFO(priv, "Alive failed.\n");
  2327. goto restart;
  2328. }
  2329. /* Initialize uCode has loaded Runtime uCode ... verify inst image.
  2330. * This is a paranoid check, because we would not have gotten the
  2331. * "runtime" alive if code weren't properly loaded. */
  2332. if (iwl_verify_ucode(priv)) {
  2333. /* Runtime instruction load was bad;
  2334. * take it all the way back down so we can try again */
  2335. IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
  2336. goto restart;
  2337. }
  2338. ret = priv->cfg->ops->lib->alive_notify(priv);
  2339. if (ret) {
  2340. IWL_WARN(priv,
  2341. "Could not complete ALIVE transition [ntf]: %d\n", ret);
  2342. goto restart;
  2343. }
  2344. /* After the ALIVE response, we can send host commands to the uCode */
  2345. set_bit(STATUS_ALIVE, &priv->status);
  2346. if (priv->cfg->ops->lib->recover_from_tx_stall) {
  2347. /* Enable timer to monitor the driver queues */
  2348. mod_timer(&priv->monitor_recover,
  2349. jiffies +
  2350. msecs_to_jiffies(priv->cfg->monitor_recover_period));
  2351. }
  2352. if (iwl_is_rfkill(priv))
  2353. return;
  2354. ieee80211_wake_queues(priv->hw);
  2355. priv->active_rate = IWL_RATES_MASK;
  2356. /* Configure Tx antenna selection based on H/W config */
  2357. if (priv->cfg->ops->hcmd->set_tx_ant)
  2358. priv->cfg->ops->hcmd->set_tx_ant(priv, priv->cfg->valid_tx_ant);
  2359. if (iwl_is_associated(priv)) {
  2360. struct iwl_rxon_cmd *active_rxon =
  2361. (struct iwl_rxon_cmd *)&priv->active_rxon;
  2362. /* apply any changes in staging */
  2363. priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  2364. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2365. } else {
  2366. /* Initialize our rx_config data */
  2367. iwl_connection_init_rx_config(priv, NULL);
  2368. if (priv->cfg->ops->hcmd->set_rxon_chain)
  2369. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  2370. }
  2371. if (!priv->cfg->advanced_bt_coexist) {
  2372. /* Configure Bluetooth device coexistence support */
  2373. priv->cfg->ops->hcmd->send_bt_config(priv);
  2374. }
  2375. iwl_reset_run_time_calib(priv);
  2376. /* Configure the adapter for unassociated operation */
  2377. iwlcore_commit_rxon(priv);
  2378. /* At this point, the NIC is initialized and operational */
  2379. iwl_rf_kill_ct_config(priv);
  2380. iwl_leds_init(priv);
  2381. IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
  2382. set_bit(STATUS_READY, &priv->status);
  2383. wake_up_interruptible(&priv->wait_command_queue);
  2384. iwl_power_update_mode(priv, true);
  2385. IWL_DEBUG_INFO(priv, "Updated power mode\n");
  2386. return;
  2387. restart:
  2388. queue_work(priv->workqueue, &priv->restart);
  2389. }
  2390. static void iwl_cancel_deferred_work(struct iwl_priv *priv);
  2391. static void __iwl_down(struct iwl_priv *priv)
  2392. {
  2393. unsigned long flags;
  2394. int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
  2395. IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
  2396. if (!exit_pending)
  2397. set_bit(STATUS_EXIT_PENDING, &priv->status);
  2398. /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set
  2399. * to prevent rearm timer */
  2400. if (priv->cfg->ops->lib->recover_from_tx_stall)
  2401. del_timer_sync(&priv->monitor_recover);
  2402. iwl_clear_ucode_stations(priv);
  2403. iwl_dealloc_bcast_station(priv);
  2404. iwl_clear_driver_stations(priv);
  2405. /* reset BT coex data */
  2406. priv->bt_traffic_load = priv->cfg->bt_init_traffic_load;
  2407. priv->bt_sco_active = false;
  2408. priv->bt_full_concurrent = false;
  2409. priv->bt_ci_compliance = 0;
  2410. /* Unblock any waiting calls */
  2411. wake_up_interruptible_all(&priv->wait_command_queue);
  2412. /* Wipe out the EXIT_PENDING status bit if we are not actually
  2413. * exiting the module */
  2414. if (!exit_pending)
  2415. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  2416. /* stop and reset the on-board processor */
  2417. iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  2418. /* tell the device to stop sending interrupts */
  2419. spin_lock_irqsave(&priv->lock, flags);
  2420. iwl_disable_interrupts(priv);
  2421. spin_unlock_irqrestore(&priv->lock, flags);
  2422. iwl_synchronize_irq(priv);
  2423. if (priv->mac80211_registered)
  2424. ieee80211_stop_queues(priv->hw);
  2425. /* If we have not previously called iwl_init() then
  2426. * clear all bits but the RF Kill bit and return */
  2427. if (!iwl_is_init(priv)) {
  2428. priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  2429. STATUS_RF_KILL_HW |
  2430. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  2431. STATUS_GEO_CONFIGURED |
  2432. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  2433. STATUS_EXIT_PENDING;
  2434. goto exit;
  2435. }
  2436. /* ...otherwise clear out all the status bits but the RF Kill
  2437. * bit and continue taking the NIC down. */
  2438. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  2439. STATUS_RF_KILL_HW |
  2440. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  2441. STATUS_GEO_CONFIGURED |
  2442. test_bit(STATUS_FW_ERROR, &priv->status) <<
  2443. STATUS_FW_ERROR |
  2444. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  2445. STATUS_EXIT_PENDING;
  2446. /* device going down, Stop using ICT table */
  2447. iwl_disable_ict(priv);
  2448. iwlagn_txq_ctx_stop(priv);
  2449. iwlagn_rxq_stop(priv);
  2450. /* Power-down device's busmaster DMA clocks */
  2451. iwl_write_prph(priv, APMG_CLK_DIS_REG, APMG_CLK_VAL_DMA_CLK_RQT);
  2452. udelay(5);
  2453. /* Make sure (redundant) we've released our request to stay awake */
  2454. iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  2455. /* Stop the device, and put it in low power state */
  2456. priv->cfg->ops->lib->apm_ops.stop(priv);
  2457. exit:
  2458. memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
  2459. if (priv->ibss_beacon)
  2460. dev_kfree_skb(priv->ibss_beacon);
  2461. priv->ibss_beacon = NULL;
  2462. /* clear out any free frames */
  2463. iwl_clear_free_frames(priv);
  2464. }
  2465. static void iwl_down(struct iwl_priv *priv)
  2466. {
  2467. mutex_lock(&priv->mutex);
  2468. __iwl_down(priv);
  2469. mutex_unlock(&priv->mutex);
  2470. iwl_cancel_deferred_work(priv);
  2471. }
  2472. #define HW_READY_TIMEOUT (50)
  2473. static int iwl_set_hw_ready(struct iwl_priv *priv)
  2474. {
  2475. int ret = 0;
  2476. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  2477. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY);
  2478. /* See if we got it */
  2479. ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
  2480. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
  2481. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
  2482. HW_READY_TIMEOUT);
  2483. if (ret != -ETIMEDOUT)
  2484. priv->hw_ready = true;
  2485. else
  2486. priv->hw_ready = false;
  2487. IWL_DEBUG_INFO(priv, "hardware %s\n",
  2488. (priv->hw_ready == 1) ? "ready" : "not ready");
  2489. return ret;
  2490. }
  2491. static int iwl_prepare_card_hw(struct iwl_priv *priv)
  2492. {
  2493. int ret = 0;
  2494. IWL_DEBUG_INFO(priv, "iwl_prepare_card_hw enter\n");
  2495. ret = iwl_set_hw_ready(priv);
  2496. if (priv->hw_ready)
  2497. return ret;
  2498. /* If HW is not ready, prepare the conditions to check again */
  2499. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  2500. CSR_HW_IF_CONFIG_REG_PREPARE);
  2501. ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
  2502. ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE,
  2503. CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000);
  2504. /* HW should be ready by now, check again. */
  2505. if (ret != -ETIMEDOUT)
  2506. iwl_set_hw_ready(priv);
  2507. return ret;
  2508. }
  2509. #define MAX_HW_RESTARTS 5
  2510. static int __iwl_up(struct iwl_priv *priv)
  2511. {
  2512. int i;
  2513. int ret;
  2514. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  2515. IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
  2516. return -EIO;
  2517. }
  2518. if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
  2519. IWL_ERR(priv, "ucode not available for device bringup\n");
  2520. return -EIO;
  2521. }
  2522. ret = iwl_alloc_bcast_station(priv, true);
  2523. if (ret)
  2524. return ret;
  2525. iwl_prepare_card_hw(priv);
  2526. if (!priv->hw_ready) {
  2527. IWL_WARN(priv, "Exit HW not ready\n");
  2528. return -EIO;
  2529. }
  2530. /* If platform's RF_KILL switch is NOT set to KILL */
  2531. if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  2532. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2533. else
  2534. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2535. if (iwl_is_rfkill(priv)) {
  2536. wiphy_rfkill_set_hw_state(priv->hw->wiphy, true);
  2537. iwl_enable_interrupts(priv);
  2538. IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
  2539. return 0;
  2540. }
  2541. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  2542. ret = iwlagn_hw_nic_init(priv);
  2543. if (ret) {
  2544. IWL_ERR(priv, "Unable to init nic\n");
  2545. return ret;
  2546. }
  2547. /* make sure rfkill handshake bits are cleared */
  2548. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2549. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  2550. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  2551. /* clear (again), then enable host interrupts */
  2552. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  2553. iwl_enable_interrupts(priv);
  2554. /* really make sure rfkill handshake bits are cleared */
  2555. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2556. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2557. /* Copy original ucode data image from disk into backup cache.
  2558. * This will be used to initialize the on-board processor's
  2559. * data SRAM for a clean start when the runtime program first loads. */
  2560. memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
  2561. priv->ucode_data.len);
  2562. for (i = 0; i < MAX_HW_RESTARTS; i++) {
  2563. /* load bootstrap state machine,
  2564. * load bootstrap program into processor's memory,
  2565. * prepare to load the "initialize" uCode */
  2566. ret = priv->cfg->ops->lib->load_ucode(priv);
  2567. if (ret) {
  2568. IWL_ERR(priv, "Unable to set up bootstrap uCode: %d\n",
  2569. ret);
  2570. continue;
  2571. }
  2572. /* start card; "initialize" will load runtime ucode */
  2573. iwl_nic_start(priv);
  2574. IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
  2575. return 0;
  2576. }
  2577. set_bit(STATUS_EXIT_PENDING, &priv->status);
  2578. __iwl_down(priv);
  2579. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  2580. /* tried to restart and config the device for as long as our
  2581. * patience could withstand */
  2582. IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
  2583. return -EIO;
  2584. }
  2585. /*****************************************************************************
  2586. *
  2587. * Workqueue callbacks
  2588. *
  2589. *****************************************************************************/
  2590. static void iwl_bg_init_alive_start(struct work_struct *data)
  2591. {
  2592. struct iwl_priv *priv =
  2593. container_of(data, struct iwl_priv, init_alive_start.work);
  2594. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2595. return;
  2596. mutex_lock(&priv->mutex);
  2597. priv->cfg->ops->lib->init_alive_start(priv);
  2598. mutex_unlock(&priv->mutex);
  2599. }
  2600. static void iwl_bg_alive_start(struct work_struct *data)
  2601. {
  2602. struct iwl_priv *priv =
  2603. container_of(data, struct iwl_priv, alive_start.work);
  2604. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2605. return;
  2606. /* enable dram interrupt */
  2607. iwl_reset_ict(priv);
  2608. mutex_lock(&priv->mutex);
  2609. iwl_alive_start(priv);
  2610. mutex_unlock(&priv->mutex);
  2611. }
  2612. static void iwl_bg_run_time_calib_work(struct work_struct *work)
  2613. {
  2614. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  2615. run_time_calib_work);
  2616. mutex_lock(&priv->mutex);
  2617. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  2618. test_bit(STATUS_SCANNING, &priv->status)) {
  2619. mutex_unlock(&priv->mutex);
  2620. return;
  2621. }
  2622. if (priv->start_calib) {
  2623. if (priv->cfg->bt_statistics) {
  2624. iwl_chain_noise_calibration(priv,
  2625. (void *)&priv->_agn.statistics_bt);
  2626. iwl_sensitivity_calibration(priv,
  2627. (void *)&priv->_agn.statistics_bt);
  2628. } else {
  2629. iwl_chain_noise_calibration(priv,
  2630. (void *)&priv->_agn.statistics);
  2631. iwl_sensitivity_calibration(priv,
  2632. (void *)&priv->_agn.statistics);
  2633. }
  2634. }
  2635. mutex_unlock(&priv->mutex);
  2636. }
  2637. static void iwl_bg_restart(struct work_struct *data)
  2638. {
  2639. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  2640. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2641. return;
  2642. if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
  2643. bool bt_sco, bt_full_concurrent;
  2644. u8 bt_ci_compliance;
  2645. u8 bt_load;
  2646. mutex_lock(&priv->mutex);
  2647. priv->vif = NULL;
  2648. priv->is_open = 0;
  2649. /*
  2650. * __iwl_down() will clear the BT status variables,
  2651. * which is correct, but when we restart we really
  2652. * want to keep them so restore them afterwards.
  2653. *
  2654. * The restart process will later pick them up and
  2655. * re-configure the hw when we reconfigure the BT
  2656. * command.
  2657. */
  2658. bt_sco = priv->bt_sco_active;
  2659. bt_full_concurrent = priv->bt_full_concurrent;
  2660. bt_ci_compliance = priv->bt_ci_compliance;
  2661. bt_load = priv->bt_traffic_load;
  2662. __iwl_down(priv);
  2663. priv->bt_sco_active = bt_sco;
  2664. priv->bt_full_concurrent = bt_full_concurrent;
  2665. priv->bt_ci_compliance = bt_ci_compliance;
  2666. priv->bt_traffic_load = bt_load;
  2667. mutex_unlock(&priv->mutex);
  2668. iwl_cancel_deferred_work(priv);
  2669. ieee80211_restart_hw(priv->hw);
  2670. } else {
  2671. iwl_down(priv);
  2672. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2673. return;
  2674. mutex_lock(&priv->mutex);
  2675. __iwl_up(priv);
  2676. mutex_unlock(&priv->mutex);
  2677. }
  2678. }
  2679. static void iwl_bg_rx_replenish(struct work_struct *data)
  2680. {
  2681. struct iwl_priv *priv =
  2682. container_of(data, struct iwl_priv, rx_replenish);
  2683. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2684. return;
  2685. mutex_lock(&priv->mutex);
  2686. iwlagn_rx_replenish(priv);
  2687. mutex_unlock(&priv->mutex);
  2688. }
  2689. #define IWL_DELAY_NEXT_SCAN (HZ*2)
  2690. void iwl_post_associate(struct iwl_priv *priv, struct ieee80211_vif *vif)
  2691. {
  2692. struct ieee80211_conf *conf = NULL;
  2693. int ret = 0;
  2694. if (!vif || !priv->is_open)
  2695. return;
  2696. if (vif->type == NL80211_IFTYPE_AP) {
  2697. IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
  2698. return;
  2699. }
  2700. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2701. return;
  2702. iwl_scan_cancel_timeout(priv, 200);
  2703. conf = ieee80211_get_hw_conf(priv->hw);
  2704. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2705. iwlcore_commit_rxon(priv);
  2706. ret = iwl_send_rxon_timing(priv, vif);
  2707. if (ret)
  2708. IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
  2709. "Attempting to continue.\n");
  2710. priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  2711. iwl_set_rxon_ht(priv, &priv->current_ht_config);
  2712. if (priv->cfg->ops->hcmd->set_rxon_chain)
  2713. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  2714. priv->staging_rxon.assoc_id = cpu_to_le16(vif->bss_conf.aid);
  2715. IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
  2716. vif->bss_conf.aid, vif->bss_conf.beacon_int);
  2717. if (vif->bss_conf.use_short_preamble)
  2718. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  2719. else
  2720. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  2721. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
  2722. if (vif->bss_conf.use_short_slot)
  2723. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  2724. else
  2725. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  2726. }
  2727. iwlcore_commit_rxon(priv);
  2728. IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
  2729. vif->bss_conf.aid, priv->active_rxon.bssid_addr);
  2730. switch (vif->type) {
  2731. case NL80211_IFTYPE_STATION:
  2732. break;
  2733. case NL80211_IFTYPE_ADHOC:
  2734. iwl_send_beacon_cmd(priv);
  2735. break;
  2736. default:
  2737. IWL_ERR(priv, "%s Should not be called in %d mode\n",
  2738. __func__, vif->type);
  2739. break;
  2740. }
  2741. /* the chain noise calibration will enabled PM upon completion
  2742. * If chain noise has already been run, then we need to enable
  2743. * power management here */
  2744. if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
  2745. iwl_power_update_mode(priv, false);
  2746. /* Enable Rx differential gain and sensitivity calibrations */
  2747. iwl_chain_noise_reset(priv);
  2748. priv->start_calib = 1;
  2749. }
  2750. /*****************************************************************************
  2751. *
  2752. * mac80211 entry point functions
  2753. *
  2754. *****************************************************************************/
  2755. #define UCODE_READY_TIMEOUT (4 * HZ)
  2756. /*
  2757. * Not a mac80211 entry point function, but it fits in with all the
  2758. * other mac80211 functions grouped here.
  2759. */
  2760. static int iwl_mac_setup_register(struct iwl_priv *priv,
  2761. struct iwlagn_ucode_capabilities *capa)
  2762. {
  2763. int ret;
  2764. struct ieee80211_hw *hw = priv->hw;
  2765. hw->rate_control_algorithm = "iwl-agn-rs";
  2766. /* Tell mac80211 our characteristics */
  2767. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  2768. IEEE80211_HW_AMPDU_AGGREGATION |
  2769. IEEE80211_HW_SPECTRUM_MGMT;
  2770. if (!priv->cfg->broken_powersave)
  2771. hw->flags |= IEEE80211_HW_SUPPORTS_PS |
  2772. IEEE80211_HW_SUPPORTS_DYNAMIC_PS;
  2773. if (priv->cfg->sku & IWL_SKU_N)
  2774. hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
  2775. IEEE80211_HW_SUPPORTS_STATIC_SMPS;
  2776. hw->sta_data_size = sizeof(struct iwl_station_priv);
  2777. hw->vif_data_size = sizeof(struct iwl_vif_priv);
  2778. hw->wiphy->interface_modes =
  2779. BIT(NL80211_IFTYPE_STATION) |
  2780. BIT(NL80211_IFTYPE_ADHOC);
  2781. hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
  2782. WIPHY_FLAG_DISABLE_BEACON_HINTS;
  2783. /*
  2784. * For now, disable PS by default because it affects
  2785. * RX performance significantly.
  2786. */
  2787. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  2788. hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
  2789. /* we create the 802.11 header and a zero-length SSID element */
  2790. hw->wiphy->max_scan_ie_len = capa->max_probe_length - 24 - 2;
  2791. /* Default value; 4 EDCA QOS priorities */
  2792. hw->queues = 4;
  2793. hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
  2794. if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
  2795. priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  2796. &priv->bands[IEEE80211_BAND_2GHZ];
  2797. if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
  2798. priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  2799. &priv->bands[IEEE80211_BAND_5GHZ];
  2800. ret = ieee80211_register_hw(priv->hw);
  2801. if (ret) {
  2802. IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
  2803. return ret;
  2804. }
  2805. priv->mac80211_registered = 1;
  2806. return 0;
  2807. }
  2808. static int iwl_mac_start(struct ieee80211_hw *hw)
  2809. {
  2810. struct iwl_priv *priv = hw->priv;
  2811. int ret;
  2812. IWL_DEBUG_MAC80211(priv, "enter\n");
  2813. /* we should be verifying the device is ready to be opened */
  2814. mutex_lock(&priv->mutex);
  2815. ret = __iwl_up(priv);
  2816. mutex_unlock(&priv->mutex);
  2817. if (ret)
  2818. return ret;
  2819. if (iwl_is_rfkill(priv))
  2820. goto out;
  2821. IWL_DEBUG_INFO(priv, "Start UP work done.\n");
  2822. /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
  2823. * mac80211 will not be run successfully. */
  2824. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  2825. test_bit(STATUS_READY, &priv->status),
  2826. UCODE_READY_TIMEOUT);
  2827. if (!ret) {
  2828. if (!test_bit(STATUS_READY, &priv->status)) {
  2829. IWL_ERR(priv, "START_ALIVE timeout after %dms.\n",
  2830. jiffies_to_msecs(UCODE_READY_TIMEOUT));
  2831. return -ETIMEDOUT;
  2832. }
  2833. }
  2834. iwl_led_start(priv);
  2835. out:
  2836. priv->is_open = 1;
  2837. IWL_DEBUG_MAC80211(priv, "leave\n");
  2838. return 0;
  2839. }
  2840. static void iwl_mac_stop(struct ieee80211_hw *hw)
  2841. {
  2842. struct iwl_priv *priv = hw->priv;
  2843. IWL_DEBUG_MAC80211(priv, "enter\n");
  2844. if (!priv->is_open)
  2845. return;
  2846. priv->is_open = 0;
  2847. if (iwl_is_ready_rf(priv) || test_bit(STATUS_SCAN_HW, &priv->status)) {
  2848. /* stop mac, cancel any scan request and clear
  2849. * RXON_FILTER_ASSOC_MSK BIT
  2850. */
  2851. mutex_lock(&priv->mutex);
  2852. iwl_scan_cancel_timeout(priv, 100);
  2853. mutex_unlock(&priv->mutex);
  2854. }
  2855. iwl_down(priv);
  2856. flush_workqueue(priv->workqueue);
  2857. /* enable interrupts again in order to receive rfkill changes */
  2858. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  2859. iwl_enable_interrupts(priv);
  2860. IWL_DEBUG_MAC80211(priv, "leave\n");
  2861. }
  2862. static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  2863. {
  2864. struct iwl_priv *priv = hw->priv;
  2865. IWL_DEBUG_MACDUMP(priv, "enter\n");
  2866. IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  2867. ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
  2868. if (iwlagn_tx_skb(priv, skb))
  2869. dev_kfree_skb_any(skb);
  2870. IWL_DEBUG_MACDUMP(priv, "leave\n");
  2871. return NETDEV_TX_OK;
  2872. }
  2873. void iwl_config_ap(struct iwl_priv *priv, struct ieee80211_vif *vif)
  2874. {
  2875. int ret = 0;
  2876. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2877. return;
  2878. /* The following should be done only at AP bring up */
  2879. if (!iwl_is_associated(priv)) {
  2880. /* RXON - unassoc (to set timing command) */
  2881. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2882. iwlcore_commit_rxon(priv);
  2883. /* RXON Timing */
  2884. ret = iwl_send_rxon_timing(priv, vif);
  2885. if (ret)
  2886. IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
  2887. "Attempting to continue.\n");
  2888. /* AP has all antennas */
  2889. priv->chain_noise_data.active_chains =
  2890. priv->hw_params.valid_rx_ant;
  2891. iwl_set_rxon_ht(priv, &priv->current_ht_config);
  2892. if (priv->cfg->ops->hcmd->set_rxon_chain)
  2893. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  2894. priv->staging_rxon.assoc_id = 0;
  2895. if (vif->bss_conf.use_short_preamble)
  2896. priv->staging_rxon.flags |=
  2897. RXON_FLG_SHORT_PREAMBLE_MSK;
  2898. else
  2899. priv->staging_rxon.flags &=
  2900. ~RXON_FLG_SHORT_PREAMBLE_MSK;
  2901. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
  2902. if (vif->bss_conf.use_short_slot)
  2903. priv->staging_rxon.flags |=
  2904. RXON_FLG_SHORT_SLOT_MSK;
  2905. else
  2906. priv->staging_rxon.flags &=
  2907. ~RXON_FLG_SHORT_SLOT_MSK;
  2908. }
  2909. /* restore RXON assoc */
  2910. priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  2911. iwlcore_commit_rxon(priv);
  2912. }
  2913. iwl_send_beacon_cmd(priv);
  2914. /* FIXME - we need to add code here to detect a totally new
  2915. * configuration, reset the AP, unassoc, rxon timing, assoc,
  2916. * clear sta table, add BCAST sta... */
  2917. }
  2918. static void iwl_mac_update_tkip_key(struct ieee80211_hw *hw,
  2919. struct ieee80211_vif *vif,
  2920. struct ieee80211_key_conf *keyconf,
  2921. struct ieee80211_sta *sta,
  2922. u32 iv32, u16 *phase1key)
  2923. {
  2924. struct iwl_priv *priv = hw->priv;
  2925. IWL_DEBUG_MAC80211(priv, "enter\n");
  2926. iwl_update_tkip_key(priv, keyconf, sta,
  2927. iv32, phase1key);
  2928. IWL_DEBUG_MAC80211(priv, "leave\n");
  2929. }
  2930. static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  2931. struct ieee80211_vif *vif,
  2932. struct ieee80211_sta *sta,
  2933. struct ieee80211_key_conf *key)
  2934. {
  2935. struct iwl_priv *priv = hw->priv;
  2936. int ret;
  2937. u8 sta_id;
  2938. bool is_default_wep_key = false;
  2939. IWL_DEBUG_MAC80211(priv, "enter\n");
  2940. if (priv->cfg->mod_params->sw_crypto) {
  2941. IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
  2942. return -EOPNOTSUPP;
  2943. }
  2944. sta_id = iwl_sta_id_or_broadcast(priv, sta);
  2945. if (sta_id == IWL_INVALID_STATION)
  2946. return -EINVAL;
  2947. mutex_lock(&priv->mutex);
  2948. iwl_scan_cancel_timeout(priv, 100);
  2949. /*
  2950. * If we are getting WEP group key and we didn't receive any key mapping
  2951. * so far, we are in legacy wep mode (group key only), otherwise we are
  2952. * in 1X mode.
  2953. * In legacy wep mode, we use another host command to the uCode.
  2954. */
  2955. if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  2956. key->cipher == WLAN_CIPHER_SUITE_WEP104) &&
  2957. !sta) {
  2958. if (cmd == SET_KEY)
  2959. is_default_wep_key = !priv->key_mapping_key;
  2960. else
  2961. is_default_wep_key =
  2962. (key->hw_key_idx == HW_KEY_DEFAULT);
  2963. }
  2964. switch (cmd) {
  2965. case SET_KEY:
  2966. if (is_default_wep_key)
  2967. ret = iwl_set_default_wep_key(priv, key);
  2968. else
  2969. ret = iwl_set_dynamic_key(priv, key, sta_id);
  2970. IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
  2971. break;
  2972. case DISABLE_KEY:
  2973. if (is_default_wep_key)
  2974. ret = iwl_remove_default_wep_key(priv, key);
  2975. else
  2976. ret = iwl_remove_dynamic_key(priv, key, sta_id);
  2977. IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
  2978. break;
  2979. default:
  2980. ret = -EINVAL;
  2981. }
  2982. mutex_unlock(&priv->mutex);
  2983. IWL_DEBUG_MAC80211(priv, "leave\n");
  2984. return ret;
  2985. }
  2986. static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
  2987. struct ieee80211_vif *vif,
  2988. enum ieee80211_ampdu_mlme_action action,
  2989. struct ieee80211_sta *sta, u16 tid, u16 *ssn)
  2990. {
  2991. struct iwl_priv *priv = hw->priv;
  2992. int ret = -EINVAL;
  2993. IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
  2994. sta->addr, tid);
  2995. if (!(priv->cfg->sku & IWL_SKU_N))
  2996. return -EACCES;
  2997. mutex_lock(&priv->mutex);
  2998. switch (action) {
  2999. case IEEE80211_AMPDU_RX_START:
  3000. IWL_DEBUG_HT(priv, "start Rx\n");
  3001. ret = iwl_sta_rx_agg_start(priv, sta, tid, *ssn);
  3002. break;
  3003. case IEEE80211_AMPDU_RX_STOP:
  3004. IWL_DEBUG_HT(priv, "stop Rx\n");
  3005. ret = iwl_sta_rx_agg_stop(priv, sta, tid);
  3006. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3007. ret = 0;
  3008. break;
  3009. case IEEE80211_AMPDU_TX_START:
  3010. IWL_DEBUG_HT(priv, "start Tx\n");
  3011. ret = iwlagn_tx_agg_start(priv, vif, sta, tid, ssn);
  3012. if (ret == 0) {
  3013. priv->_agn.agg_tids_count++;
  3014. IWL_DEBUG_HT(priv, "priv->_agn.agg_tids_count = %u\n",
  3015. priv->_agn.agg_tids_count);
  3016. }
  3017. break;
  3018. case IEEE80211_AMPDU_TX_STOP:
  3019. IWL_DEBUG_HT(priv, "stop Tx\n");
  3020. ret = iwlagn_tx_agg_stop(priv, vif, sta, tid);
  3021. if ((ret == 0) && (priv->_agn.agg_tids_count > 0)) {
  3022. priv->_agn.agg_tids_count--;
  3023. IWL_DEBUG_HT(priv, "priv->_agn.agg_tids_count = %u\n",
  3024. priv->_agn.agg_tids_count);
  3025. }
  3026. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3027. ret = 0;
  3028. if (priv->cfg->use_rts_for_aggregation) {
  3029. struct iwl_station_priv *sta_priv =
  3030. (void *) sta->drv_priv;
  3031. /*
  3032. * switch off RTS/CTS if it was previously enabled
  3033. */
  3034. sta_priv->lq_sta.lq.general_params.flags &=
  3035. ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
  3036. iwl_send_lq_cmd(priv, &sta_priv->lq_sta.lq,
  3037. CMD_ASYNC, false);
  3038. }
  3039. break;
  3040. case IEEE80211_AMPDU_TX_OPERATIONAL:
  3041. if (priv->cfg->use_rts_for_aggregation) {
  3042. struct iwl_station_priv *sta_priv =
  3043. (void *) sta->drv_priv;
  3044. /*
  3045. * switch to RTS/CTS if it is the prefer protection
  3046. * method for HT traffic
  3047. */
  3048. sta_priv->lq_sta.lq.general_params.flags |=
  3049. LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
  3050. iwl_send_lq_cmd(priv, &sta_priv->lq_sta.lq,
  3051. CMD_ASYNC, false);
  3052. }
  3053. ret = 0;
  3054. break;
  3055. }
  3056. mutex_unlock(&priv->mutex);
  3057. return ret;
  3058. }
  3059. static void iwl_mac_sta_notify(struct ieee80211_hw *hw,
  3060. struct ieee80211_vif *vif,
  3061. enum sta_notify_cmd cmd,
  3062. struct ieee80211_sta *sta)
  3063. {
  3064. struct iwl_priv *priv = hw->priv;
  3065. struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
  3066. int sta_id;
  3067. switch (cmd) {
  3068. case STA_NOTIFY_SLEEP:
  3069. WARN_ON(!sta_priv->client);
  3070. sta_priv->asleep = true;
  3071. if (atomic_read(&sta_priv->pending_frames) > 0)
  3072. ieee80211_sta_block_awake(hw, sta, true);
  3073. break;
  3074. case STA_NOTIFY_AWAKE:
  3075. WARN_ON(!sta_priv->client);
  3076. if (!sta_priv->asleep)
  3077. break;
  3078. sta_priv->asleep = false;
  3079. sta_id = iwl_sta_id(sta);
  3080. if (sta_id != IWL_INVALID_STATION)
  3081. iwl_sta_modify_ps_wake(priv, sta_id);
  3082. break;
  3083. default:
  3084. break;
  3085. }
  3086. }
  3087. static int iwlagn_mac_sta_add(struct ieee80211_hw *hw,
  3088. struct ieee80211_vif *vif,
  3089. struct ieee80211_sta *sta)
  3090. {
  3091. struct iwl_priv *priv = hw->priv;
  3092. struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
  3093. bool is_ap = vif->type == NL80211_IFTYPE_STATION;
  3094. int ret;
  3095. u8 sta_id;
  3096. IWL_DEBUG_INFO(priv, "received request to add station %pM\n",
  3097. sta->addr);
  3098. mutex_lock(&priv->mutex);
  3099. IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n",
  3100. sta->addr);
  3101. sta_priv->common.sta_id = IWL_INVALID_STATION;
  3102. atomic_set(&sta_priv->pending_frames, 0);
  3103. if (vif->type == NL80211_IFTYPE_AP)
  3104. sta_priv->client = true;
  3105. ret = iwl_add_station_common(priv, sta->addr, is_ap, &sta->ht_cap,
  3106. &sta_id);
  3107. if (ret) {
  3108. IWL_ERR(priv, "Unable to add station %pM (%d)\n",
  3109. sta->addr, ret);
  3110. /* Should we return success if return code is EEXIST ? */
  3111. mutex_unlock(&priv->mutex);
  3112. return ret;
  3113. }
  3114. sta_priv->common.sta_id = sta_id;
  3115. /* Initialize rate scaling */
  3116. IWL_DEBUG_INFO(priv, "Initializing rate scaling for station %pM\n",
  3117. sta->addr);
  3118. iwl_rs_rate_init(priv, sta, sta_id);
  3119. mutex_unlock(&priv->mutex);
  3120. return 0;
  3121. }
  3122. static void iwl_mac_channel_switch(struct ieee80211_hw *hw,
  3123. struct ieee80211_channel_switch *ch_switch)
  3124. {
  3125. struct iwl_priv *priv = hw->priv;
  3126. const struct iwl_channel_info *ch_info;
  3127. struct ieee80211_conf *conf = &hw->conf;
  3128. struct ieee80211_channel *channel = ch_switch->channel;
  3129. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  3130. u16 ch;
  3131. unsigned long flags = 0;
  3132. IWL_DEBUG_MAC80211(priv, "enter\n");
  3133. if (iwl_is_rfkill(priv))
  3134. goto out_exit;
  3135. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  3136. test_bit(STATUS_SCANNING, &priv->status))
  3137. goto out_exit;
  3138. if (!iwl_is_associated(priv))
  3139. goto out_exit;
  3140. /* channel switch in progress */
  3141. if (priv->switch_rxon.switch_in_progress == true)
  3142. goto out_exit;
  3143. mutex_lock(&priv->mutex);
  3144. if (priv->cfg->ops->lib->set_channel_switch) {
  3145. ch = channel->hw_value;
  3146. if (le16_to_cpu(priv->active_rxon.channel) != ch) {
  3147. ch_info = iwl_get_channel_info(priv,
  3148. channel->band,
  3149. ch);
  3150. if (!is_channel_valid(ch_info)) {
  3151. IWL_DEBUG_MAC80211(priv, "invalid channel\n");
  3152. goto out;
  3153. }
  3154. spin_lock_irqsave(&priv->lock, flags);
  3155. priv->current_ht_config.smps = conf->smps_mode;
  3156. /* Configure HT40 channels */
  3157. ht_conf->is_ht = conf_is_ht(conf);
  3158. if (ht_conf->is_ht) {
  3159. if (conf_is_ht40_minus(conf)) {
  3160. ht_conf->extension_chan_offset =
  3161. IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  3162. ht_conf->is_40mhz = true;
  3163. } else if (conf_is_ht40_plus(conf)) {
  3164. ht_conf->extension_chan_offset =
  3165. IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  3166. ht_conf->is_40mhz = true;
  3167. } else {
  3168. ht_conf->extension_chan_offset =
  3169. IEEE80211_HT_PARAM_CHA_SEC_NONE;
  3170. ht_conf->is_40mhz = false;
  3171. }
  3172. } else
  3173. ht_conf->is_40mhz = false;
  3174. if (le16_to_cpu(priv->staging_rxon.channel) != ch)
  3175. priv->staging_rxon.flags = 0;
  3176. iwl_set_rxon_channel(priv, channel);
  3177. iwl_set_rxon_ht(priv, ht_conf);
  3178. iwl_set_flags_for_band(priv, channel->band,
  3179. priv->vif);
  3180. spin_unlock_irqrestore(&priv->lock, flags);
  3181. iwl_set_rate(priv);
  3182. /*
  3183. * at this point, staging_rxon has the
  3184. * configuration for channel switch
  3185. */
  3186. if (priv->cfg->ops->lib->set_channel_switch(priv,
  3187. ch_switch))
  3188. priv->switch_rxon.switch_in_progress = false;
  3189. }
  3190. }
  3191. out:
  3192. mutex_unlock(&priv->mutex);
  3193. out_exit:
  3194. if (!priv->switch_rxon.switch_in_progress)
  3195. ieee80211_chswitch_done(priv->vif, false);
  3196. IWL_DEBUG_MAC80211(priv, "leave\n");
  3197. }
  3198. static void iwlagn_configure_filter(struct ieee80211_hw *hw,
  3199. unsigned int changed_flags,
  3200. unsigned int *total_flags,
  3201. u64 multicast)
  3202. {
  3203. struct iwl_priv *priv = hw->priv;
  3204. __le32 filter_or = 0, filter_nand = 0;
  3205. #define CHK(test, flag) do { \
  3206. if (*total_flags & (test)) \
  3207. filter_or |= (flag); \
  3208. else \
  3209. filter_nand |= (flag); \
  3210. } while (0)
  3211. IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
  3212. changed_flags, *total_flags);
  3213. CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
  3214. CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK);
  3215. CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
  3216. #undef CHK
  3217. mutex_lock(&priv->mutex);
  3218. priv->staging_rxon.filter_flags &= ~filter_nand;
  3219. priv->staging_rxon.filter_flags |= filter_or;
  3220. iwlcore_commit_rxon(priv);
  3221. mutex_unlock(&priv->mutex);
  3222. /*
  3223. * Receiving all multicast frames is always enabled by the
  3224. * default flags setup in iwl_connection_init_rx_config()
  3225. * since we currently do not support programming multicast
  3226. * filters into the device.
  3227. */
  3228. *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
  3229. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
  3230. }
  3231. static void iwl_mac_flush(struct ieee80211_hw *hw, bool drop)
  3232. {
  3233. struct iwl_priv *priv = hw->priv;
  3234. mutex_lock(&priv->mutex);
  3235. IWL_DEBUG_MAC80211(priv, "enter\n");
  3236. /* do not support "flush" */
  3237. if (!priv->cfg->ops->lib->txfifo_flush)
  3238. goto done;
  3239. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  3240. IWL_DEBUG_TX(priv, "Aborting flush due to device shutdown\n");
  3241. goto done;
  3242. }
  3243. if (iwl_is_rfkill(priv)) {
  3244. IWL_DEBUG_TX(priv, "Aborting flush due to RF Kill\n");
  3245. goto done;
  3246. }
  3247. /*
  3248. * mac80211 will not push any more frames for transmit
  3249. * until the flush is completed
  3250. */
  3251. if (drop) {
  3252. IWL_DEBUG_MAC80211(priv, "send flush command\n");
  3253. if (priv->cfg->ops->lib->txfifo_flush(priv, IWL_DROP_ALL)) {
  3254. IWL_ERR(priv, "flush request fail\n");
  3255. goto done;
  3256. }
  3257. }
  3258. IWL_DEBUG_MAC80211(priv, "wait transmit/flush all frames\n");
  3259. iwlagn_wait_tx_queue_empty(priv);
  3260. done:
  3261. mutex_unlock(&priv->mutex);
  3262. IWL_DEBUG_MAC80211(priv, "leave\n");
  3263. }
  3264. /*****************************************************************************
  3265. *
  3266. * driver setup and teardown
  3267. *
  3268. *****************************************************************************/
  3269. static void iwl_setup_deferred_work(struct iwl_priv *priv)
  3270. {
  3271. priv->workqueue = create_singlethread_workqueue(DRV_NAME);
  3272. init_waitqueue_head(&priv->wait_command_queue);
  3273. INIT_WORK(&priv->restart, iwl_bg_restart);
  3274. INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish);
  3275. INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
  3276. INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
  3277. INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
  3278. INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
  3279. INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
  3280. INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
  3281. INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
  3282. iwl_setup_scan_deferred_work(priv);
  3283. if (priv->cfg->ops->lib->setup_deferred_work)
  3284. priv->cfg->ops->lib->setup_deferred_work(priv);
  3285. init_timer(&priv->statistics_periodic);
  3286. priv->statistics_periodic.data = (unsigned long)priv;
  3287. priv->statistics_periodic.function = iwl_bg_statistics_periodic;
  3288. init_timer(&priv->ucode_trace);
  3289. priv->ucode_trace.data = (unsigned long)priv;
  3290. priv->ucode_trace.function = iwl_bg_ucode_trace;
  3291. if (priv->cfg->ops->lib->recover_from_tx_stall) {
  3292. init_timer(&priv->monitor_recover);
  3293. priv->monitor_recover.data = (unsigned long)priv;
  3294. priv->monitor_recover.function =
  3295. priv->cfg->ops->lib->recover_from_tx_stall;
  3296. }
  3297. if (!priv->cfg->use_isr_legacy)
  3298. tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
  3299. iwl_irq_tasklet, (unsigned long)priv);
  3300. else
  3301. tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
  3302. iwl_irq_tasklet_legacy, (unsigned long)priv);
  3303. }
  3304. static void iwl_cancel_deferred_work(struct iwl_priv *priv)
  3305. {
  3306. if (priv->cfg->ops->lib->cancel_deferred_work)
  3307. priv->cfg->ops->lib->cancel_deferred_work(priv);
  3308. cancel_delayed_work_sync(&priv->init_alive_start);
  3309. cancel_delayed_work(&priv->scan_check);
  3310. cancel_work_sync(&priv->start_internal_scan);
  3311. cancel_delayed_work(&priv->alive_start);
  3312. cancel_work_sync(&priv->run_time_calib_work);
  3313. cancel_work_sync(&priv->beacon_update);
  3314. cancel_work_sync(&priv->bt_full_concurrency);
  3315. cancel_work_sync(&priv->bt_runtime_config);
  3316. del_timer_sync(&priv->statistics_periodic);
  3317. del_timer_sync(&priv->ucode_trace);
  3318. }
  3319. static void iwl_init_hw_rates(struct iwl_priv *priv,
  3320. struct ieee80211_rate *rates)
  3321. {
  3322. int i;
  3323. for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
  3324. rates[i].bitrate = iwl_rates[i].ieee * 5;
  3325. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  3326. rates[i].hw_value_short = i;
  3327. rates[i].flags = 0;
  3328. if ((i >= IWL_FIRST_CCK_RATE) && (i <= IWL_LAST_CCK_RATE)) {
  3329. /*
  3330. * If CCK != 1M then set short preamble rate flag.
  3331. */
  3332. rates[i].flags |=
  3333. (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
  3334. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  3335. }
  3336. }
  3337. }
  3338. static int iwl_init_drv(struct iwl_priv *priv)
  3339. {
  3340. int ret;
  3341. priv->ibss_beacon = NULL;
  3342. spin_lock_init(&priv->sta_lock);
  3343. spin_lock_init(&priv->hcmd_lock);
  3344. INIT_LIST_HEAD(&priv->free_frames);
  3345. mutex_init(&priv->mutex);
  3346. mutex_init(&priv->sync_cmd_mutex);
  3347. priv->ieee_channels = NULL;
  3348. priv->ieee_rates = NULL;
  3349. priv->band = IEEE80211_BAND_2GHZ;
  3350. priv->iw_mode = NL80211_IFTYPE_STATION;
  3351. priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
  3352. priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
  3353. priv->_agn.agg_tids_count = 0;
  3354. /* initialize force reset */
  3355. priv->force_reset[IWL_RF_RESET].reset_duration =
  3356. IWL_DELAY_NEXT_FORCE_RF_RESET;
  3357. priv->force_reset[IWL_FW_RESET].reset_duration =
  3358. IWL_DELAY_NEXT_FORCE_FW_RELOAD;
  3359. /* Choose which receivers/antennas to use */
  3360. if (priv->cfg->ops->hcmd->set_rxon_chain)
  3361. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  3362. iwl_init_scan_params(priv);
  3363. /* init bt coex */
  3364. if (priv->cfg->advanced_bt_coexist) {
  3365. priv->kill_ack_mask = IWL6000G2B_BT_KILL_ACK_MASK_DEFAULT;
  3366. priv->kill_cts_mask = IWL6000G2B_BT_KILL_CTS_MASK_DEFAULT;
  3367. priv->bt_valid = IWL6000G2B_BT_ALL_VALID_MSK;
  3368. priv->bt_on_thresh = BT_ON_THRESHOLD_DEF;
  3369. priv->bt_duration = BT_DURATION_LIMIT_DEF;
  3370. priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF;
  3371. priv->dynamic_agg_thresh = BT_AGG_THRESHOLD_DEF;
  3372. }
  3373. /* Set the tx_power_user_lmt to the lowest power level
  3374. * this value will get overwritten by channel max power avg
  3375. * from eeprom */
  3376. priv->tx_power_user_lmt = IWLAGN_TX_POWER_TARGET_POWER_MIN;
  3377. ret = iwl_init_channel_map(priv);
  3378. if (ret) {
  3379. IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
  3380. goto err;
  3381. }
  3382. ret = iwlcore_init_geos(priv);
  3383. if (ret) {
  3384. IWL_ERR(priv, "initializing geos failed: %d\n", ret);
  3385. goto err_free_channel_map;
  3386. }
  3387. iwl_init_hw_rates(priv, priv->ieee_rates);
  3388. return 0;
  3389. err_free_channel_map:
  3390. iwl_free_channel_map(priv);
  3391. err:
  3392. return ret;
  3393. }
  3394. static void iwl_uninit_drv(struct iwl_priv *priv)
  3395. {
  3396. iwl_calib_free_results(priv);
  3397. iwlcore_free_geos(priv);
  3398. iwl_free_channel_map(priv);
  3399. kfree(priv->scan_cmd);
  3400. }
  3401. static struct ieee80211_ops iwl_hw_ops = {
  3402. .tx = iwl_mac_tx,
  3403. .start = iwl_mac_start,
  3404. .stop = iwl_mac_stop,
  3405. .add_interface = iwl_mac_add_interface,
  3406. .remove_interface = iwl_mac_remove_interface,
  3407. .config = iwl_mac_config,
  3408. .configure_filter = iwlagn_configure_filter,
  3409. .set_key = iwl_mac_set_key,
  3410. .update_tkip_key = iwl_mac_update_tkip_key,
  3411. .conf_tx = iwl_mac_conf_tx,
  3412. .reset_tsf = iwl_mac_reset_tsf,
  3413. .bss_info_changed = iwl_bss_info_changed,
  3414. .ampdu_action = iwl_mac_ampdu_action,
  3415. .hw_scan = iwl_mac_hw_scan,
  3416. .sta_notify = iwl_mac_sta_notify,
  3417. .sta_add = iwlagn_mac_sta_add,
  3418. .sta_remove = iwl_mac_sta_remove,
  3419. .channel_switch = iwl_mac_channel_switch,
  3420. .flush = iwl_mac_flush,
  3421. .tx_last_beacon = iwl_mac_tx_last_beacon,
  3422. };
  3423. static void iwl_hw_detect(struct iwl_priv *priv)
  3424. {
  3425. priv->hw_rev = _iwl_read32(priv, CSR_HW_REV);
  3426. priv->hw_wa_rev = _iwl_read32(priv, CSR_HW_REV_WA_REG);
  3427. pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &priv->rev_id);
  3428. IWL_DEBUG_INFO(priv, "HW Revision ID = 0x%X\n", priv->rev_id);
  3429. }
  3430. static int iwl_set_hw_params(struct iwl_priv *priv)
  3431. {
  3432. priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
  3433. priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
  3434. if (priv->cfg->mod_params->amsdu_size_8K)
  3435. priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_8K);
  3436. else
  3437. priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_4K);
  3438. priv->hw_params.max_beacon_itrvl = IWL_MAX_UCODE_BEACON_INTERVAL;
  3439. if (priv->cfg->mod_params->disable_11n)
  3440. priv->cfg->sku &= ~IWL_SKU_N;
  3441. /* Device-specific setup */
  3442. return priv->cfg->ops->lib->set_hw_params(priv);
  3443. }
  3444. static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  3445. {
  3446. int err = 0;
  3447. struct iwl_priv *priv;
  3448. struct ieee80211_hw *hw;
  3449. struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
  3450. unsigned long flags;
  3451. u16 pci_cmd, num_mac;
  3452. /************************
  3453. * 1. Allocating HW data
  3454. ************************/
  3455. /* Disabling hardware scan means that mac80211 will perform scans
  3456. * "the hard way", rather than using device's scan. */
  3457. if (cfg->mod_params->disable_hw_scan) {
  3458. if (iwl_debug_level & IWL_DL_INFO)
  3459. dev_printk(KERN_DEBUG, &(pdev->dev),
  3460. "Disabling hw_scan\n");
  3461. iwl_hw_ops.hw_scan = NULL;
  3462. }
  3463. hw = iwl_alloc_all(cfg, &iwl_hw_ops);
  3464. if (!hw) {
  3465. err = -ENOMEM;
  3466. goto out;
  3467. }
  3468. priv = hw->priv;
  3469. /* At this point both hw and priv are allocated. */
  3470. SET_IEEE80211_DEV(hw, &pdev->dev);
  3471. IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
  3472. priv->cfg = cfg;
  3473. priv->pci_dev = pdev;
  3474. priv->inta_mask = CSR_INI_SET_MASK;
  3475. /* is antenna coupling more than 35dB ? */
  3476. priv->bt_ant_couple_ok =
  3477. (iwlagn_ant_coupling > IWL_BT_ANTENNA_COUPLING_THRESHOLD) ?
  3478. true : false;
  3479. if (iwl_alloc_traffic_mem(priv))
  3480. IWL_ERR(priv, "Not enough memory to generate traffic log\n");
  3481. /**************************
  3482. * 2. Initializing PCI bus
  3483. **************************/
  3484. pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
  3485. PCIE_LINK_STATE_CLKPM);
  3486. if (pci_enable_device(pdev)) {
  3487. err = -ENODEV;
  3488. goto out_ieee80211_free_hw;
  3489. }
  3490. pci_set_master(pdev);
  3491. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
  3492. if (!err)
  3493. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
  3494. if (err) {
  3495. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  3496. if (!err)
  3497. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  3498. /* both attempts failed: */
  3499. if (err) {
  3500. IWL_WARN(priv, "No suitable DMA available.\n");
  3501. goto out_pci_disable_device;
  3502. }
  3503. }
  3504. err = pci_request_regions(pdev, DRV_NAME);
  3505. if (err)
  3506. goto out_pci_disable_device;
  3507. pci_set_drvdata(pdev, priv);
  3508. /***********************
  3509. * 3. Read REV register
  3510. ***********************/
  3511. priv->hw_base = pci_iomap(pdev, 0, 0);
  3512. if (!priv->hw_base) {
  3513. err = -ENODEV;
  3514. goto out_pci_release_regions;
  3515. }
  3516. IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
  3517. (unsigned long long) pci_resource_len(pdev, 0));
  3518. IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
  3519. /* these spin locks will be used in apm_ops.init and EEPROM access
  3520. * we should init now
  3521. */
  3522. spin_lock_init(&priv->reg_lock);
  3523. spin_lock_init(&priv->lock);
  3524. /*
  3525. * stop and reset the on-board processor just in case it is in a
  3526. * strange state ... like being left stranded by a primary kernel
  3527. * and this is now the kdump kernel trying to start up
  3528. */
  3529. iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  3530. iwl_hw_detect(priv);
  3531. IWL_INFO(priv, "Detected %s, REV=0x%X\n",
  3532. priv->cfg->name, priv->hw_rev);
  3533. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  3534. * PCI Tx retries from interfering with C3 CPU state */
  3535. pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
  3536. iwl_prepare_card_hw(priv);
  3537. if (!priv->hw_ready) {
  3538. IWL_WARN(priv, "Failed, HW not ready\n");
  3539. goto out_iounmap;
  3540. }
  3541. /*****************
  3542. * 4. Read EEPROM
  3543. *****************/
  3544. /* Read the EEPROM */
  3545. err = iwl_eeprom_init(priv);
  3546. if (err) {
  3547. IWL_ERR(priv, "Unable to init EEPROM\n");
  3548. goto out_iounmap;
  3549. }
  3550. err = iwl_eeprom_check_version(priv);
  3551. if (err)
  3552. goto out_free_eeprom;
  3553. /* extract MAC Address */
  3554. iwl_eeprom_get_mac(priv, priv->addresses[0].addr);
  3555. IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
  3556. priv->hw->wiphy->addresses = priv->addresses;
  3557. priv->hw->wiphy->n_addresses = 1;
  3558. num_mac = iwl_eeprom_query16(priv, EEPROM_NUM_MAC_ADDRESS);
  3559. if (num_mac > 1) {
  3560. memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
  3561. ETH_ALEN);
  3562. priv->addresses[1].addr[5]++;
  3563. priv->hw->wiphy->n_addresses++;
  3564. }
  3565. /************************
  3566. * 5. Setup HW constants
  3567. ************************/
  3568. if (iwl_set_hw_params(priv)) {
  3569. IWL_ERR(priv, "failed to set hw parameters\n");
  3570. goto out_free_eeprom;
  3571. }
  3572. /*******************
  3573. * 6. Setup priv
  3574. *******************/
  3575. err = iwl_init_drv(priv);
  3576. if (err)
  3577. goto out_free_eeprom;
  3578. /* At this point both hw and priv are initialized. */
  3579. /********************
  3580. * 7. Setup services
  3581. ********************/
  3582. spin_lock_irqsave(&priv->lock, flags);
  3583. iwl_disable_interrupts(priv);
  3584. spin_unlock_irqrestore(&priv->lock, flags);
  3585. pci_enable_msi(priv->pci_dev);
  3586. iwl_alloc_isr_ict(priv);
  3587. err = request_irq(priv->pci_dev->irq, priv->cfg->ops->lib->isr,
  3588. IRQF_SHARED, DRV_NAME, priv);
  3589. if (err) {
  3590. IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
  3591. goto out_disable_msi;
  3592. }
  3593. iwl_setup_deferred_work(priv);
  3594. iwl_setup_rx_handlers(priv);
  3595. /*********************************************
  3596. * 8. Enable interrupts and read RFKILL state
  3597. *********************************************/
  3598. /* enable interrupts if needed: hw bug w/a */
  3599. pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pci_cmd);
  3600. if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
  3601. pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
  3602. pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd);
  3603. }
  3604. iwl_enable_interrupts(priv);
  3605. /* If platform's RF_KILL switch is NOT set to KILL */
  3606. if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  3607. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  3608. else
  3609. set_bit(STATUS_RF_KILL_HW, &priv->status);
  3610. wiphy_rfkill_set_hw_state(priv->hw->wiphy,
  3611. test_bit(STATUS_RF_KILL_HW, &priv->status));
  3612. iwl_power_initialize(priv);
  3613. iwl_tt_initialize(priv);
  3614. init_completion(&priv->_agn.firmware_loading_complete);
  3615. err = iwl_request_firmware(priv, true);
  3616. if (err)
  3617. goto out_destroy_workqueue;
  3618. return 0;
  3619. out_destroy_workqueue:
  3620. destroy_workqueue(priv->workqueue);
  3621. priv->workqueue = NULL;
  3622. free_irq(priv->pci_dev->irq, priv);
  3623. iwl_free_isr_ict(priv);
  3624. out_disable_msi:
  3625. pci_disable_msi(priv->pci_dev);
  3626. iwl_uninit_drv(priv);
  3627. out_free_eeprom:
  3628. iwl_eeprom_free(priv);
  3629. out_iounmap:
  3630. pci_iounmap(pdev, priv->hw_base);
  3631. out_pci_release_regions:
  3632. pci_set_drvdata(pdev, NULL);
  3633. pci_release_regions(pdev);
  3634. out_pci_disable_device:
  3635. pci_disable_device(pdev);
  3636. out_ieee80211_free_hw:
  3637. iwl_free_traffic_mem(priv);
  3638. ieee80211_free_hw(priv->hw);
  3639. out:
  3640. return err;
  3641. }
  3642. static void __devexit iwl_pci_remove(struct pci_dev *pdev)
  3643. {
  3644. struct iwl_priv *priv = pci_get_drvdata(pdev);
  3645. unsigned long flags;
  3646. if (!priv)
  3647. return;
  3648. wait_for_completion(&priv->_agn.firmware_loading_complete);
  3649. IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
  3650. iwl_dbgfs_unregister(priv);
  3651. sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
  3652. /* ieee80211_unregister_hw call wil cause iwl_mac_stop to
  3653. * to be called and iwl_down since we are removing the device
  3654. * we need to set STATUS_EXIT_PENDING bit.
  3655. */
  3656. set_bit(STATUS_EXIT_PENDING, &priv->status);
  3657. if (priv->mac80211_registered) {
  3658. ieee80211_unregister_hw(priv->hw);
  3659. priv->mac80211_registered = 0;
  3660. } else {
  3661. iwl_down(priv);
  3662. }
  3663. /*
  3664. * Make sure device is reset to low power before unloading driver.
  3665. * This may be redundant with iwl_down(), but there are paths to
  3666. * run iwl_down() without calling apm_ops.stop(), and there are
  3667. * paths to avoid running iwl_down() at all before leaving driver.
  3668. * This (inexpensive) call *makes sure* device is reset.
  3669. */
  3670. priv->cfg->ops->lib->apm_ops.stop(priv);
  3671. iwl_tt_exit(priv);
  3672. /* make sure we flush any pending irq or
  3673. * tasklet for the driver
  3674. */
  3675. spin_lock_irqsave(&priv->lock, flags);
  3676. iwl_disable_interrupts(priv);
  3677. spin_unlock_irqrestore(&priv->lock, flags);
  3678. iwl_synchronize_irq(priv);
  3679. iwl_dealloc_ucode_pci(priv);
  3680. if (priv->rxq.bd)
  3681. iwlagn_rx_queue_free(priv, &priv->rxq);
  3682. iwlagn_hw_txq_ctx_free(priv);
  3683. iwl_eeprom_free(priv);
  3684. /*netif_stop_queue(dev); */
  3685. flush_workqueue(priv->workqueue);
  3686. /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes
  3687. * priv->workqueue... so we can't take down the workqueue
  3688. * until now... */
  3689. destroy_workqueue(priv->workqueue);
  3690. priv->workqueue = NULL;
  3691. iwl_free_traffic_mem(priv);
  3692. free_irq(priv->pci_dev->irq, priv);
  3693. pci_disable_msi(priv->pci_dev);
  3694. pci_iounmap(pdev, priv->hw_base);
  3695. pci_release_regions(pdev);
  3696. pci_disable_device(pdev);
  3697. pci_set_drvdata(pdev, NULL);
  3698. iwl_uninit_drv(priv);
  3699. iwl_free_isr_ict(priv);
  3700. if (priv->ibss_beacon)
  3701. dev_kfree_skb(priv->ibss_beacon);
  3702. ieee80211_free_hw(priv->hw);
  3703. }
  3704. /*****************************************************************************
  3705. *
  3706. * driver and module entry point
  3707. *
  3708. *****************************************************************************/
  3709. /* Hardware specific file defines the PCI IDs table for that hardware module */
  3710. static DEFINE_PCI_DEVICE_TABLE(iwl_hw_card_ids) = {
  3711. #ifdef CONFIG_IWL4965
  3712. {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
  3713. {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
  3714. #endif /* CONFIG_IWL4965 */
  3715. #ifdef CONFIG_IWL5000
  3716. /* 5100 Series WiFi */
  3717. {IWL_PCI_DEVICE(0x4232, 0x1201, iwl5100_agn_cfg)}, /* Mini Card */
  3718. {IWL_PCI_DEVICE(0x4232, 0x1301, iwl5100_agn_cfg)}, /* Half Mini Card */
  3719. {IWL_PCI_DEVICE(0x4232, 0x1204, iwl5100_agn_cfg)}, /* Mini Card */
  3720. {IWL_PCI_DEVICE(0x4232, 0x1304, iwl5100_agn_cfg)}, /* Half Mini Card */
  3721. {IWL_PCI_DEVICE(0x4232, 0x1205, iwl5100_bgn_cfg)}, /* Mini Card */
  3722. {IWL_PCI_DEVICE(0x4232, 0x1305, iwl5100_bgn_cfg)}, /* Half Mini Card */
  3723. {IWL_PCI_DEVICE(0x4232, 0x1206, iwl5100_abg_cfg)}, /* Mini Card */
  3724. {IWL_PCI_DEVICE(0x4232, 0x1306, iwl5100_abg_cfg)}, /* Half Mini Card */
  3725. {IWL_PCI_DEVICE(0x4232, 0x1221, iwl5100_agn_cfg)}, /* Mini Card */
  3726. {IWL_PCI_DEVICE(0x4232, 0x1321, iwl5100_agn_cfg)}, /* Half Mini Card */
  3727. {IWL_PCI_DEVICE(0x4232, 0x1224, iwl5100_agn_cfg)}, /* Mini Card */
  3728. {IWL_PCI_DEVICE(0x4232, 0x1324, iwl5100_agn_cfg)}, /* Half Mini Card */
  3729. {IWL_PCI_DEVICE(0x4232, 0x1225, iwl5100_bgn_cfg)}, /* Mini Card */
  3730. {IWL_PCI_DEVICE(0x4232, 0x1325, iwl5100_bgn_cfg)}, /* Half Mini Card */
  3731. {IWL_PCI_DEVICE(0x4232, 0x1226, iwl5100_abg_cfg)}, /* Mini Card */
  3732. {IWL_PCI_DEVICE(0x4232, 0x1326, iwl5100_abg_cfg)}, /* Half Mini Card */
  3733. {IWL_PCI_DEVICE(0x4237, 0x1211, iwl5100_agn_cfg)}, /* Mini Card */
  3734. {IWL_PCI_DEVICE(0x4237, 0x1311, iwl5100_agn_cfg)}, /* Half Mini Card */
  3735. {IWL_PCI_DEVICE(0x4237, 0x1214, iwl5100_agn_cfg)}, /* Mini Card */
  3736. {IWL_PCI_DEVICE(0x4237, 0x1314, iwl5100_agn_cfg)}, /* Half Mini Card */
  3737. {IWL_PCI_DEVICE(0x4237, 0x1215, iwl5100_bgn_cfg)}, /* Mini Card */
  3738. {IWL_PCI_DEVICE(0x4237, 0x1315, iwl5100_bgn_cfg)}, /* Half Mini Card */
  3739. {IWL_PCI_DEVICE(0x4237, 0x1216, iwl5100_abg_cfg)}, /* Mini Card */
  3740. {IWL_PCI_DEVICE(0x4237, 0x1316, iwl5100_abg_cfg)}, /* Half Mini Card */
  3741. /* 5300 Series WiFi */
  3742. {IWL_PCI_DEVICE(0x4235, 0x1021, iwl5300_agn_cfg)}, /* Mini Card */
  3743. {IWL_PCI_DEVICE(0x4235, 0x1121, iwl5300_agn_cfg)}, /* Half Mini Card */
  3744. {IWL_PCI_DEVICE(0x4235, 0x1024, iwl5300_agn_cfg)}, /* Mini Card */
  3745. {IWL_PCI_DEVICE(0x4235, 0x1124, iwl5300_agn_cfg)}, /* Half Mini Card */
  3746. {IWL_PCI_DEVICE(0x4235, 0x1001, iwl5300_agn_cfg)}, /* Mini Card */
  3747. {IWL_PCI_DEVICE(0x4235, 0x1101, iwl5300_agn_cfg)}, /* Half Mini Card */
  3748. {IWL_PCI_DEVICE(0x4235, 0x1004, iwl5300_agn_cfg)}, /* Mini Card */
  3749. {IWL_PCI_DEVICE(0x4235, 0x1104, iwl5300_agn_cfg)}, /* Half Mini Card */
  3750. {IWL_PCI_DEVICE(0x4236, 0x1011, iwl5300_agn_cfg)}, /* Mini Card */
  3751. {IWL_PCI_DEVICE(0x4236, 0x1111, iwl5300_agn_cfg)}, /* Half Mini Card */
  3752. {IWL_PCI_DEVICE(0x4236, 0x1014, iwl5300_agn_cfg)}, /* Mini Card */
  3753. {IWL_PCI_DEVICE(0x4236, 0x1114, iwl5300_agn_cfg)}, /* Half Mini Card */
  3754. /* 5350 Series WiFi/WiMax */
  3755. {IWL_PCI_DEVICE(0x423A, 0x1001, iwl5350_agn_cfg)}, /* Mini Card */
  3756. {IWL_PCI_DEVICE(0x423A, 0x1021, iwl5350_agn_cfg)}, /* Mini Card */
  3757. {IWL_PCI_DEVICE(0x423B, 0x1011, iwl5350_agn_cfg)}, /* Mini Card */
  3758. /* 5150 Series Wifi/WiMax */
  3759. {IWL_PCI_DEVICE(0x423C, 0x1201, iwl5150_agn_cfg)}, /* Mini Card */
  3760. {IWL_PCI_DEVICE(0x423C, 0x1301, iwl5150_agn_cfg)}, /* Half Mini Card */
  3761. {IWL_PCI_DEVICE(0x423C, 0x1206, iwl5150_abg_cfg)}, /* Mini Card */
  3762. {IWL_PCI_DEVICE(0x423C, 0x1306, iwl5150_abg_cfg)}, /* Half Mini Card */
  3763. {IWL_PCI_DEVICE(0x423C, 0x1221, iwl5150_agn_cfg)}, /* Mini Card */
  3764. {IWL_PCI_DEVICE(0x423C, 0x1321, iwl5150_agn_cfg)}, /* Half Mini Card */
  3765. {IWL_PCI_DEVICE(0x423D, 0x1211, iwl5150_agn_cfg)}, /* Mini Card */
  3766. {IWL_PCI_DEVICE(0x423D, 0x1311, iwl5150_agn_cfg)}, /* Half Mini Card */
  3767. {IWL_PCI_DEVICE(0x423D, 0x1216, iwl5150_abg_cfg)}, /* Mini Card */
  3768. {IWL_PCI_DEVICE(0x423D, 0x1316, iwl5150_abg_cfg)}, /* Half Mini Card */
  3769. /* 6x00 Series */
  3770. {IWL_PCI_DEVICE(0x422B, 0x1101, iwl6000_3agn_cfg)},
  3771. {IWL_PCI_DEVICE(0x422B, 0x1121, iwl6000_3agn_cfg)},
  3772. {IWL_PCI_DEVICE(0x422C, 0x1301, iwl6000i_2agn_cfg)},
  3773. {IWL_PCI_DEVICE(0x422C, 0x1306, iwl6000i_2abg_cfg)},
  3774. {IWL_PCI_DEVICE(0x422C, 0x1307, iwl6000i_2bg_cfg)},
  3775. {IWL_PCI_DEVICE(0x422C, 0x1321, iwl6000i_2agn_cfg)},
  3776. {IWL_PCI_DEVICE(0x422C, 0x1326, iwl6000i_2abg_cfg)},
  3777. {IWL_PCI_DEVICE(0x4238, 0x1111, iwl6000_3agn_cfg)},
  3778. {IWL_PCI_DEVICE(0x4239, 0x1311, iwl6000i_2agn_cfg)},
  3779. {IWL_PCI_DEVICE(0x4239, 0x1316, iwl6000i_2abg_cfg)},
  3780. /* 6x00 Series Gen2a */
  3781. {IWL_PCI_DEVICE(0x0082, 0x1201, iwl6000g2a_2agn_cfg)},
  3782. {IWL_PCI_DEVICE(0x0085, 0x1211, iwl6000g2a_2agn_cfg)},
  3783. {IWL_PCI_DEVICE(0x0082, 0x1221, iwl6000g2a_2agn_cfg)},
  3784. {IWL_PCI_DEVICE(0x0082, 0x1206, iwl6000g2a_2abg_cfg)},
  3785. {IWL_PCI_DEVICE(0x0085, 0x1216, iwl6000g2a_2abg_cfg)},
  3786. {IWL_PCI_DEVICE(0x0082, 0x1226, iwl6000g2a_2abg_cfg)},
  3787. {IWL_PCI_DEVICE(0x0082, 0x1207, iwl6000g2a_2bg_cfg)},
  3788. {IWL_PCI_DEVICE(0x0082, 0x1301, iwl6000g2a_2agn_cfg)},
  3789. {IWL_PCI_DEVICE(0x0082, 0x1306, iwl6000g2a_2abg_cfg)},
  3790. {IWL_PCI_DEVICE(0x0082, 0x1307, iwl6000g2a_2bg_cfg)},
  3791. {IWL_PCI_DEVICE(0x0082, 0x1321, iwl6000g2a_2agn_cfg)},
  3792. {IWL_PCI_DEVICE(0x0082, 0x1326, iwl6000g2a_2abg_cfg)},
  3793. {IWL_PCI_DEVICE(0x0085, 0x1311, iwl6000g2a_2agn_cfg)},
  3794. {IWL_PCI_DEVICE(0x0085, 0x1316, iwl6000g2a_2abg_cfg)},
  3795. /* 6x00 Series Gen2b */
  3796. {IWL_PCI_DEVICE(0x008F, 0x5105, iwl6000g2b_bgn_cfg)},
  3797. {IWL_PCI_DEVICE(0x0090, 0x5115, iwl6000g2b_bgn_cfg)},
  3798. {IWL_PCI_DEVICE(0x008F, 0x5125, iwl6000g2b_bgn_cfg)},
  3799. {IWL_PCI_DEVICE(0x008F, 0x5107, iwl6000g2b_bg_cfg)},
  3800. {IWL_PCI_DEVICE(0x008F, 0x5201, iwl6000g2b_2agn_cfg)},
  3801. {IWL_PCI_DEVICE(0x0090, 0x5211, iwl6000g2b_2agn_cfg)},
  3802. {IWL_PCI_DEVICE(0x008F, 0x5221, iwl6000g2b_2agn_cfg)},
  3803. {IWL_PCI_DEVICE(0x008F, 0x5206, iwl6000g2b_2abg_cfg)},
  3804. {IWL_PCI_DEVICE(0x0090, 0x5216, iwl6000g2b_2abg_cfg)},
  3805. {IWL_PCI_DEVICE(0x008F, 0x5226, iwl6000g2b_2abg_cfg)},
  3806. {IWL_PCI_DEVICE(0x008F, 0x5207, iwl6000g2b_2bg_cfg)},
  3807. {IWL_PCI_DEVICE(0x008A, 0x5301, iwl6000g2b_bgn_cfg)},
  3808. {IWL_PCI_DEVICE(0x008A, 0x5305, iwl6000g2b_bgn_cfg)},
  3809. {IWL_PCI_DEVICE(0x008A, 0x5307, iwl6000g2b_bg_cfg)},
  3810. {IWL_PCI_DEVICE(0x008A, 0x5321, iwl6000g2b_bgn_cfg)},
  3811. {IWL_PCI_DEVICE(0x008A, 0x5325, iwl6000g2b_bgn_cfg)},
  3812. {IWL_PCI_DEVICE(0x008B, 0x5311, iwl6000g2b_bgn_cfg)},
  3813. {IWL_PCI_DEVICE(0x008B, 0x5315, iwl6000g2b_bgn_cfg)},
  3814. {IWL_PCI_DEVICE(0x0090, 0x5211, iwl6000g2b_2agn_cfg)},
  3815. {IWL_PCI_DEVICE(0x0090, 0x5215, iwl6000g2b_2bgn_cfg)},
  3816. {IWL_PCI_DEVICE(0x0090, 0x5216, iwl6000g2b_2abg_cfg)},
  3817. {IWL_PCI_DEVICE(0x0091, 0x5201, iwl6000g2b_2agn_cfg)},
  3818. {IWL_PCI_DEVICE(0x0091, 0x5205, iwl6000g2b_2bgn_cfg)},
  3819. {IWL_PCI_DEVICE(0x0091, 0x5206, iwl6000g2b_2abg_cfg)},
  3820. {IWL_PCI_DEVICE(0x0091, 0x5207, iwl6000g2b_2bg_cfg)},
  3821. {IWL_PCI_DEVICE(0x0091, 0x5221, iwl6000g2b_2agn_cfg)},
  3822. {IWL_PCI_DEVICE(0x0091, 0x5225, iwl6000g2b_2bgn_cfg)},
  3823. {IWL_PCI_DEVICE(0x0091, 0x5226, iwl6000g2b_2abg_cfg)},
  3824. /* 6x50 WiFi/WiMax Series */
  3825. {IWL_PCI_DEVICE(0x0087, 0x1301, iwl6050_2agn_cfg)},
  3826. {IWL_PCI_DEVICE(0x0087, 0x1306, iwl6050_2abg_cfg)},
  3827. {IWL_PCI_DEVICE(0x0087, 0x1321, iwl6050_2agn_cfg)},
  3828. {IWL_PCI_DEVICE(0x0087, 0x1326, iwl6050_2abg_cfg)},
  3829. {IWL_PCI_DEVICE(0x0089, 0x1311, iwl6050_2agn_cfg)},
  3830. {IWL_PCI_DEVICE(0x0089, 0x1316, iwl6050_2abg_cfg)},
  3831. /* 6x50 WiFi/WiMax Series Gen2 */
  3832. {IWL_PCI_DEVICE(0x0885, 0x1305, iwl6050g2_bgn_cfg)},
  3833. {IWL_PCI_DEVICE(0x0885, 0x1306, iwl6050g2_bgn_cfg)},
  3834. {IWL_PCI_DEVICE(0x0885, 0x1325, iwl6050g2_bgn_cfg)},
  3835. {IWL_PCI_DEVICE(0x0885, 0x1326, iwl6050g2_bgn_cfg)},
  3836. {IWL_PCI_DEVICE(0x0886, 0x1315, iwl6050g2_bgn_cfg)},
  3837. {IWL_PCI_DEVICE(0x0886, 0x1316, iwl6050g2_bgn_cfg)},
  3838. /* 1000 Series WiFi */
  3839. {IWL_PCI_DEVICE(0x0083, 0x1205, iwl1000_bgn_cfg)},
  3840. {IWL_PCI_DEVICE(0x0083, 0x1305, iwl1000_bgn_cfg)},
  3841. {IWL_PCI_DEVICE(0x0083, 0x1225, iwl1000_bgn_cfg)},
  3842. {IWL_PCI_DEVICE(0x0083, 0x1325, iwl1000_bgn_cfg)},
  3843. {IWL_PCI_DEVICE(0x0084, 0x1215, iwl1000_bgn_cfg)},
  3844. {IWL_PCI_DEVICE(0x0084, 0x1315, iwl1000_bgn_cfg)},
  3845. {IWL_PCI_DEVICE(0x0083, 0x1206, iwl1000_bg_cfg)},
  3846. {IWL_PCI_DEVICE(0x0083, 0x1306, iwl1000_bg_cfg)},
  3847. {IWL_PCI_DEVICE(0x0083, 0x1226, iwl1000_bg_cfg)},
  3848. {IWL_PCI_DEVICE(0x0083, 0x1326, iwl1000_bg_cfg)},
  3849. {IWL_PCI_DEVICE(0x0084, 0x1216, iwl1000_bg_cfg)},
  3850. {IWL_PCI_DEVICE(0x0084, 0x1316, iwl1000_bg_cfg)},
  3851. #endif /* CONFIG_IWL5000 */
  3852. {0}
  3853. };
  3854. MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
  3855. static struct pci_driver iwl_driver = {
  3856. .name = DRV_NAME,
  3857. .id_table = iwl_hw_card_ids,
  3858. .probe = iwl_pci_probe,
  3859. .remove = __devexit_p(iwl_pci_remove),
  3860. #ifdef CONFIG_PM
  3861. .suspend = iwl_pci_suspend,
  3862. .resume = iwl_pci_resume,
  3863. #endif
  3864. };
  3865. static int __init iwl_init(void)
  3866. {
  3867. int ret;
  3868. pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
  3869. pr_info(DRV_COPYRIGHT "\n");
  3870. ret = iwlagn_rate_control_register();
  3871. if (ret) {
  3872. pr_err("Unable to register rate control algorithm: %d\n", ret);
  3873. return ret;
  3874. }
  3875. ret = pci_register_driver(&iwl_driver);
  3876. if (ret) {
  3877. pr_err("Unable to initialize PCI module\n");
  3878. goto error_register;
  3879. }
  3880. return ret;
  3881. error_register:
  3882. iwlagn_rate_control_unregister();
  3883. return ret;
  3884. }
  3885. static void __exit iwl_exit(void)
  3886. {
  3887. pci_unregister_driver(&iwl_driver);
  3888. iwlagn_rate_control_unregister();
  3889. }
  3890. module_exit(iwl_exit);
  3891. module_init(iwl_init);
  3892. #ifdef CONFIG_IWLWIFI_DEBUG
  3893. module_param_named(debug50, iwl_debug_level, uint, S_IRUGO);
  3894. MODULE_PARM_DESC(debug50, "50XX debug output mask (deprecated)");
  3895. module_param_named(debug, iwl_debug_level, uint, S_IRUGO | S_IWUSR);
  3896. MODULE_PARM_DESC(debug, "debug output mask");
  3897. #endif
  3898. module_param_named(swcrypto50, iwlagn_mod_params.sw_crypto, bool, S_IRUGO);
  3899. MODULE_PARM_DESC(swcrypto50,
  3900. "using crypto in software (default 0 [hardware]) (deprecated)");
  3901. module_param_named(swcrypto, iwlagn_mod_params.sw_crypto, int, S_IRUGO);
  3902. MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
  3903. module_param_named(queues_num50,
  3904. iwlagn_mod_params.num_of_queues, int, S_IRUGO);
  3905. MODULE_PARM_DESC(queues_num50,
  3906. "number of hw queues in 50xx series (deprecated)");
  3907. module_param_named(queues_num, iwlagn_mod_params.num_of_queues, int, S_IRUGO);
  3908. MODULE_PARM_DESC(queues_num, "number of hw queues.");
  3909. module_param_named(11n_disable50, iwlagn_mod_params.disable_11n, int, S_IRUGO);
  3910. MODULE_PARM_DESC(11n_disable50, "disable 50XX 11n functionality (deprecated)");
  3911. module_param_named(11n_disable, iwlagn_mod_params.disable_11n, int, S_IRUGO);
  3912. MODULE_PARM_DESC(11n_disable, "disable 11n functionality");
  3913. module_param_named(amsdu_size_8K50, iwlagn_mod_params.amsdu_size_8K,
  3914. int, S_IRUGO);
  3915. MODULE_PARM_DESC(amsdu_size_8K50,
  3916. "enable 8K amsdu size in 50XX series (deprecated)");
  3917. module_param_named(amsdu_size_8K, iwlagn_mod_params.amsdu_size_8K,
  3918. int, S_IRUGO);
  3919. MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
  3920. module_param_named(fw_restart50, iwlagn_mod_params.restart_fw, int, S_IRUGO);
  3921. MODULE_PARM_DESC(fw_restart50,
  3922. "restart firmware in case of error (deprecated)");
  3923. module_param_named(fw_restart, iwlagn_mod_params.restart_fw, int, S_IRUGO);
  3924. MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");
  3925. module_param_named(
  3926. disable_hw_scan, iwlagn_mod_params.disable_hw_scan, int, S_IRUGO);
  3927. MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
  3928. module_param_named(ucode_alternative, iwlagn_wanted_ucode_alternative, int,
  3929. S_IRUGO);
  3930. MODULE_PARM_DESC(ucode_alternative,
  3931. "specify ucode alternative to use from ucode file");
  3932. module_param_named(antenna_coupling, iwlagn_ant_coupling, int, S_IRUGO);
  3933. MODULE_PARM_DESC(antenna_coupling,
  3934. "specify antenna coupling in dB (defualt: 0 dB)");