iwl3945-base.c 151 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2009 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. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/init.h>
  32. #include <linux/pci.h>
  33. #include <linux/dma-mapping.h>
  34. #include <linux/delay.h>
  35. #include <linux/skbuff.h>
  36. #include <linux/netdevice.h>
  37. #include <linux/wireless.h>
  38. #include <linux/firmware.h>
  39. #include <linux/etherdevice.h>
  40. #include <linux/if_arp.h>
  41. #include <net/ieee80211_radiotap.h>
  42. #include <net/lib80211.h>
  43. #include <net/mac80211.h>
  44. #include <asm/div64.h>
  45. #define DRV_NAME "iwl3945"
  46. #include "iwl-fh.h"
  47. #include "iwl-3945-fh.h"
  48. #include "iwl-commands.h"
  49. #include "iwl-sta.h"
  50. #include "iwl-3945.h"
  51. #include "iwl-helpers.h"
  52. #include "iwl-core.h"
  53. #include "iwl-dev.h"
  54. /*
  55. * module name, copyright, version, etc.
  56. */
  57. #define DRV_DESCRIPTION \
  58. "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
  59. #ifdef CONFIG_IWLWIFI_DEBUG
  60. #define VD "d"
  61. #else
  62. #define VD
  63. #endif
  64. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  65. #define VS "s"
  66. #else
  67. #define VS
  68. #endif
  69. #define IWL39_VERSION "1.2.26k" VD VS
  70. #define DRV_COPYRIGHT "Copyright(c) 2003-2009 Intel Corporation"
  71. #define DRV_AUTHOR "<ilw@linux.intel.com>"
  72. #define DRV_VERSION IWL39_VERSION
  73. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  74. MODULE_VERSION(DRV_VERSION);
  75. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  76. MODULE_LICENSE("GPL");
  77. /* module parameters */
  78. struct iwl_mod_params iwl3945_mod_params = {
  79. .num_of_queues = IWL39_MAX_NUM_QUEUES,
  80. .sw_crypto = 1,
  81. .restart_fw = 1,
  82. /* the rest are 0 by default */
  83. };
  84. /*************** STATION TABLE MANAGEMENT ****
  85. * mac80211 should be examined to determine if sta_info is duplicating
  86. * the functionality provided here
  87. */
  88. /**************************************************************/
  89. #if 0 /* temporary disable till we add real remove station */
  90. /**
  91. * iwl3945_remove_station - Remove driver's knowledge of station.
  92. *
  93. * NOTE: This does not remove station from device's station table.
  94. */
  95. static u8 iwl3945_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
  96. {
  97. int index = IWL_INVALID_STATION;
  98. int i;
  99. unsigned long flags;
  100. spin_lock_irqsave(&priv->sta_lock, flags);
  101. if (is_ap)
  102. index = IWL_AP_ID;
  103. else if (is_broadcast_ether_addr(addr))
  104. index = priv->hw_params.bcast_sta_id;
  105. else
  106. for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
  107. if (priv->stations_39[i].used &&
  108. !compare_ether_addr(priv->stations_39[i].sta.sta.addr,
  109. addr)) {
  110. index = i;
  111. break;
  112. }
  113. if (unlikely(index == IWL_INVALID_STATION))
  114. goto out;
  115. if (priv->stations_39[index].used) {
  116. priv->stations_39[index].used = 0;
  117. priv->num_stations--;
  118. }
  119. BUG_ON(priv->num_stations < 0);
  120. out:
  121. spin_unlock_irqrestore(&priv->sta_lock, flags);
  122. return 0;
  123. }
  124. #endif
  125. /**
  126. * iwl3945_clear_stations_table - Clear the driver's station table
  127. *
  128. * NOTE: This does not clear or otherwise alter the device's station table.
  129. */
  130. static void iwl3945_clear_stations_table(struct iwl_priv *priv)
  131. {
  132. unsigned long flags;
  133. spin_lock_irqsave(&priv->sta_lock, flags);
  134. priv->num_stations = 0;
  135. memset(priv->stations_39, 0, sizeof(priv->stations_39));
  136. spin_unlock_irqrestore(&priv->sta_lock, flags);
  137. }
  138. /**
  139. * iwl3945_add_station - Add station to station tables in driver and device
  140. */
  141. u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags)
  142. {
  143. int i;
  144. int index = IWL_INVALID_STATION;
  145. struct iwl3945_station_entry *station;
  146. unsigned long flags_spin;
  147. u8 rate;
  148. spin_lock_irqsave(&priv->sta_lock, flags_spin);
  149. if (is_ap)
  150. index = IWL_AP_ID;
  151. else if (is_broadcast_ether_addr(addr))
  152. index = priv->hw_params.bcast_sta_id;
  153. else
  154. for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
  155. if (!compare_ether_addr(priv->stations_39[i].sta.sta.addr,
  156. addr)) {
  157. index = i;
  158. break;
  159. }
  160. if (!priv->stations_39[i].used &&
  161. index == IWL_INVALID_STATION)
  162. index = i;
  163. }
  164. /* These two conditions has the same outcome but keep them separate
  165. since they have different meaning */
  166. if (unlikely(index == IWL_INVALID_STATION)) {
  167. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  168. return index;
  169. }
  170. if (priv->stations_39[index].used &&
  171. !compare_ether_addr(priv->stations_39[index].sta.sta.addr, addr)) {
  172. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  173. return index;
  174. }
  175. IWL_DEBUG_ASSOC(priv, "Add STA ID %d: %pM\n", index, addr);
  176. station = &priv->stations_39[index];
  177. station->used = 1;
  178. priv->num_stations++;
  179. /* Set up the REPLY_ADD_STA command to send to device */
  180. memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd));
  181. memcpy(station->sta.sta.addr, addr, ETH_ALEN);
  182. station->sta.mode = 0;
  183. station->sta.sta.sta_id = index;
  184. station->sta.station_flags = 0;
  185. if (priv->band == IEEE80211_BAND_5GHZ)
  186. rate = IWL_RATE_6M_PLCP;
  187. else
  188. rate = IWL_RATE_1M_PLCP;
  189. /* Turn on both antennas for the station... */
  190. station->sta.rate_n_flags =
  191. iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK);
  192. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  193. /* Add station to device's station table */
  194. iwl_send_add_sta(priv,
  195. (struct iwl_addsta_cmd *)&station->sta, flags);
  196. return index;
  197. }
  198. static int iwl3945_send_rxon_assoc(struct iwl_priv *priv)
  199. {
  200. int rc = 0;
  201. struct iwl_rx_packet *res = NULL;
  202. struct iwl3945_rxon_assoc_cmd rxon_assoc;
  203. struct iwl_host_cmd cmd = {
  204. .id = REPLY_RXON_ASSOC,
  205. .len = sizeof(rxon_assoc),
  206. .meta.flags = CMD_WANT_SKB,
  207. .data = &rxon_assoc,
  208. };
  209. const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
  210. const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
  211. if ((rxon1->flags == rxon2->flags) &&
  212. (rxon1->filter_flags == rxon2->filter_flags) &&
  213. (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
  214. (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
  215. IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
  216. return 0;
  217. }
  218. rxon_assoc.flags = priv->staging_rxon.flags;
  219. rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
  220. rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
  221. rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
  222. rxon_assoc.reserved = 0;
  223. rc = iwl_send_cmd_sync(priv, &cmd);
  224. if (rc)
  225. return rc;
  226. res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
  227. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  228. IWL_ERR(priv, "Bad return from REPLY_RXON_ASSOC command\n");
  229. rc = -EIO;
  230. }
  231. priv->alloc_rxb_skb--;
  232. dev_kfree_skb_any(cmd.meta.u.skb);
  233. return rc;
  234. }
  235. /**
  236. * iwl3945_get_antenna_flags - Get antenna flags for RXON command
  237. * @priv: eeprom and antenna fields are used to determine antenna flags
  238. *
  239. * priv->eeprom39 is used to determine if antenna AUX/MAIN are reversed
  240. * iwl3945_mod_params.antenna specifies the antenna diversity mode:
  241. *
  242. * IWL_ANTENNA_DIVERSITY - NIC selects best antenna by itself
  243. * IWL_ANTENNA_MAIN - Force MAIN antenna
  244. * IWL_ANTENNA_AUX - Force AUX antenna
  245. */
  246. __le32 iwl3945_get_antenna_flags(const struct iwl_priv *priv)
  247. {
  248. struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
  249. switch (iwl3945_mod_params.antenna) {
  250. case IWL_ANTENNA_DIVERSITY:
  251. return 0;
  252. case IWL_ANTENNA_MAIN:
  253. if (eeprom->antenna_switch_type)
  254. return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
  255. return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
  256. case IWL_ANTENNA_AUX:
  257. if (eeprom->antenna_switch_type)
  258. return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
  259. return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
  260. }
  261. /* bad antenna selector value */
  262. IWL_ERR(priv, "Bad antenna selector value (0x%x)\n",
  263. iwl3945_mod_params.antenna);
  264. return 0; /* "diversity" is default if error */
  265. }
  266. /**
  267. * iwl3945_commit_rxon - commit staging_rxon to hardware
  268. *
  269. * The RXON command in staging_rxon is committed to the hardware and
  270. * the active_rxon structure is updated with the new data. This
  271. * function correctly transitions out of the RXON_ASSOC_MSK state if
  272. * a HW tune is required based on the RXON structure changes.
  273. */
  274. static int iwl3945_commit_rxon(struct iwl_priv *priv)
  275. {
  276. /* cast away the const for active_rxon in this function */
  277. struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
  278. struct iwl3945_rxon_cmd *staging_rxon = (void *)&priv->staging_rxon;
  279. int rc = 0;
  280. if (!iwl_is_alive(priv))
  281. return -1;
  282. /* always get timestamp with Rx frame */
  283. staging_rxon->flags |= RXON_FLG_TSF2HOST_MSK;
  284. /* select antenna */
  285. staging_rxon->flags &=
  286. ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
  287. staging_rxon->flags |= iwl3945_get_antenna_flags(priv);
  288. rc = iwl_check_rxon_cmd(priv);
  289. if (rc) {
  290. IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
  291. return -EINVAL;
  292. }
  293. /* If we don't need to send a full RXON, we can use
  294. * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
  295. * and other flags for the current radio configuration. */
  296. if (!iwl_full_rxon_required(priv)) {
  297. rc = iwl3945_send_rxon_assoc(priv);
  298. if (rc) {
  299. IWL_ERR(priv, "Error setting RXON_ASSOC "
  300. "configuration (%d).\n", rc);
  301. return rc;
  302. }
  303. memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
  304. return 0;
  305. }
  306. /* If we are currently associated and the new config requires
  307. * an RXON_ASSOC and the new config wants the associated mask enabled,
  308. * we must clear the associated from the active configuration
  309. * before we apply the new config */
  310. if (iwl_is_associated(priv) &&
  311. (staging_rxon->filter_flags & RXON_FILTER_ASSOC_MSK)) {
  312. IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
  313. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  314. /*
  315. * reserved4 and 5 could have been filled by the iwlcore code.
  316. * Let's clear them before pushing to the 3945.
  317. */
  318. active_rxon->reserved4 = 0;
  319. active_rxon->reserved5 = 0;
  320. rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
  321. sizeof(struct iwl3945_rxon_cmd),
  322. &priv->active_rxon);
  323. /* If the mask clearing failed then we set
  324. * active_rxon back to what it was previously */
  325. if (rc) {
  326. active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
  327. IWL_ERR(priv, "Error clearing ASSOC_MSK on current "
  328. "configuration (%d).\n", rc);
  329. return rc;
  330. }
  331. }
  332. IWL_DEBUG_INFO(priv, "Sending RXON\n"
  333. "* with%s RXON_FILTER_ASSOC_MSK\n"
  334. "* channel = %d\n"
  335. "* bssid = %pM\n",
  336. ((priv->staging_rxon.filter_flags &
  337. RXON_FILTER_ASSOC_MSK) ? "" : "out"),
  338. le16_to_cpu(staging_rxon->channel),
  339. staging_rxon->bssid_addr);
  340. /*
  341. * reserved4 and 5 could have been filled by the iwlcore code.
  342. * Let's clear them before pushing to the 3945.
  343. */
  344. staging_rxon->reserved4 = 0;
  345. staging_rxon->reserved5 = 0;
  346. /* Apply the new configuration */
  347. rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
  348. sizeof(struct iwl3945_rxon_cmd),
  349. staging_rxon);
  350. if (rc) {
  351. IWL_ERR(priv, "Error setting new configuration (%d).\n", rc);
  352. return rc;
  353. }
  354. memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
  355. iwl3945_clear_stations_table(priv);
  356. /* If we issue a new RXON command which required a tune then we must
  357. * send a new TXPOWER command or we won't be able to Tx any frames */
  358. rc = priv->cfg->ops->lib->send_tx_power(priv);
  359. if (rc) {
  360. IWL_ERR(priv, "Error setting Tx power (%d).\n", rc);
  361. return rc;
  362. }
  363. /* Add the broadcast address so we can send broadcast frames */
  364. if (iwl3945_add_station(priv, iwl_bcast_addr, 0, 0) ==
  365. IWL_INVALID_STATION) {
  366. IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
  367. return -EIO;
  368. }
  369. /* If we have set the ASSOC_MSK and we are in BSS mode then
  370. * add the IWL_AP_ID to the station rate table */
  371. if (iwl_is_associated(priv) &&
  372. (priv->iw_mode == NL80211_IFTYPE_STATION))
  373. if (iwl3945_add_station(priv, priv->active_rxon.bssid_addr,
  374. 1, 0)
  375. == IWL_INVALID_STATION) {
  376. IWL_ERR(priv, "Error adding AP address for transmit\n");
  377. return -EIO;
  378. }
  379. /* Init the hardware's rate fallback order based on the band */
  380. rc = iwl3945_init_hw_rate_table(priv);
  381. if (rc) {
  382. IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc);
  383. return -EIO;
  384. }
  385. return 0;
  386. }
  387. static int iwl3945_update_sta_key_info(struct iwl_priv *priv,
  388. struct ieee80211_key_conf *keyconf,
  389. u8 sta_id)
  390. {
  391. unsigned long flags;
  392. __le16 key_flags = 0;
  393. switch (keyconf->alg) {
  394. case ALG_CCMP:
  395. key_flags |= STA_KEY_FLG_CCMP;
  396. key_flags |= cpu_to_le16(
  397. keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  398. key_flags &= ~STA_KEY_FLG_INVALID;
  399. break;
  400. case ALG_TKIP:
  401. case ALG_WEP:
  402. default:
  403. return -EINVAL;
  404. }
  405. spin_lock_irqsave(&priv->sta_lock, flags);
  406. priv->stations_39[sta_id].keyinfo.alg = keyconf->alg;
  407. priv->stations_39[sta_id].keyinfo.keylen = keyconf->keylen;
  408. memcpy(priv->stations_39[sta_id].keyinfo.key, keyconf->key,
  409. keyconf->keylen);
  410. memcpy(priv->stations_39[sta_id].sta.key.key, keyconf->key,
  411. keyconf->keylen);
  412. priv->stations_39[sta_id].sta.key.key_flags = key_flags;
  413. priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  414. priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  415. spin_unlock_irqrestore(&priv->sta_lock, flags);
  416. IWL_DEBUG_INFO(priv, "hwcrypto: modify ucode station key info\n");
  417. iwl_send_add_sta(priv,
  418. (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, 0);
  419. return 0;
  420. }
  421. static int iwl3945_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
  422. {
  423. unsigned long flags;
  424. spin_lock_irqsave(&priv->sta_lock, flags);
  425. memset(&priv->stations_39[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key));
  426. memset(&priv->stations_39[sta_id].sta.key, 0,
  427. sizeof(struct iwl4965_keyinfo));
  428. priv->stations_39[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
  429. priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  430. priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  431. spin_unlock_irqrestore(&priv->sta_lock, flags);
  432. IWL_DEBUG_INFO(priv, "hwcrypto: clear ucode station key info\n");
  433. iwl_send_add_sta(priv,
  434. (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, 0);
  435. return 0;
  436. }
  437. static void iwl3945_clear_free_frames(struct iwl_priv *priv)
  438. {
  439. struct list_head *element;
  440. IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
  441. priv->frames_count);
  442. while (!list_empty(&priv->free_frames)) {
  443. element = priv->free_frames.next;
  444. list_del(element);
  445. kfree(list_entry(element, struct iwl3945_frame, list));
  446. priv->frames_count--;
  447. }
  448. if (priv->frames_count) {
  449. IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
  450. priv->frames_count);
  451. priv->frames_count = 0;
  452. }
  453. }
  454. static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv)
  455. {
  456. struct iwl3945_frame *frame;
  457. struct list_head *element;
  458. if (list_empty(&priv->free_frames)) {
  459. frame = kzalloc(sizeof(*frame), GFP_KERNEL);
  460. if (!frame) {
  461. IWL_ERR(priv, "Could not allocate frame!\n");
  462. return NULL;
  463. }
  464. priv->frames_count++;
  465. return frame;
  466. }
  467. element = priv->free_frames.next;
  468. list_del(element);
  469. return list_entry(element, struct iwl3945_frame, list);
  470. }
  471. static void iwl3945_free_frame(struct iwl_priv *priv, struct iwl3945_frame *frame)
  472. {
  473. memset(frame, 0, sizeof(*frame));
  474. list_add(&frame->list, &priv->free_frames);
  475. }
  476. unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv,
  477. struct ieee80211_hdr *hdr,
  478. int left)
  479. {
  480. if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
  481. ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
  482. (priv->iw_mode != NL80211_IFTYPE_AP)))
  483. return 0;
  484. if (priv->ibss_beacon->len > left)
  485. return 0;
  486. memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
  487. return priv->ibss_beacon->len;
  488. }
  489. static int iwl3945_send_beacon_cmd(struct iwl_priv *priv)
  490. {
  491. struct iwl3945_frame *frame;
  492. unsigned int frame_size;
  493. int rc;
  494. u8 rate;
  495. frame = iwl3945_get_free_frame(priv);
  496. if (!frame) {
  497. IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
  498. "command.\n");
  499. return -ENOMEM;
  500. }
  501. rate = iwl_rate_get_lowest_plcp(priv);
  502. frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
  503. rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
  504. &frame->u.cmd[0]);
  505. iwl3945_free_frame(priv, frame);
  506. return rc;
  507. }
  508. static void iwl3945_unset_hw_params(struct iwl_priv *priv)
  509. {
  510. if (priv->shared_virt)
  511. pci_free_consistent(priv->pci_dev,
  512. sizeof(struct iwl3945_shared),
  513. priv->shared_virt,
  514. priv->shared_phys);
  515. }
  516. /*
  517. * QoS support
  518. */
  519. static int iwl3945_send_qos_params_command(struct iwl_priv *priv,
  520. struct iwl_qosparam_cmd *qos)
  521. {
  522. return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM,
  523. sizeof(struct iwl_qosparam_cmd), qos);
  524. }
  525. static void iwl3945_activate_qos(struct iwl_priv *priv, u8 force)
  526. {
  527. unsigned long flags;
  528. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  529. return;
  530. spin_lock_irqsave(&priv->lock, flags);
  531. priv->qos_data.def_qos_parm.qos_flags = 0;
  532. if (priv->qos_data.qos_cap.q_AP.queue_request &&
  533. !priv->qos_data.qos_cap.q_AP.txop_request)
  534. priv->qos_data.def_qos_parm.qos_flags |=
  535. QOS_PARAM_FLG_TXOP_TYPE_MSK;
  536. if (priv->qos_data.qos_active)
  537. priv->qos_data.def_qos_parm.qos_flags |=
  538. QOS_PARAM_FLG_UPDATE_EDCA_MSK;
  539. spin_unlock_irqrestore(&priv->lock, flags);
  540. if (force || iwl_is_associated(priv)) {
  541. IWL_DEBUG_QOS(priv, "send QoS cmd with QoS active %d \n",
  542. priv->qos_data.qos_active);
  543. iwl3945_send_qos_params_command(priv,
  544. &(priv->qos_data.def_qos_parm));
  545. }
  546. }
  547. #define MAX_UCODE_BEACON_INTERVAL 1024
  548. #define INTEL_CONN_LISTEN_INTERVAL cpu_to_le16(0xA)
  549. static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val)
  550. {
  551. u16 new_val = 0;
  552. u16 beacon_factor = 0;
  553. beacon_factor =
  554. (beacon_val + MAX_UCODE_BEACON_INTERVAL)
  555. / MAX_UCODE_BEACON_INTERVAL;
  556. new_val = beacon_val / beacon_factor;
  557. return cpu_to_le16(new_val);
  558. }
  559. static void iwl3945_setup_rxon_timing(struct iwl_priv *priv)
  560. {
  561. u64 interval_tm_unit;
  562. u64 tsf, result;
  563. unsigned long flags;
  564. struct ieee80211_conf *conf = NULL;
  565. u16 beacon_int = 0;
  566. conf = ieee80211_get_hw_conf(priv->hw);
  567. spin_lock_irqsave(&priv->lock, flags);
  568. priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
  569. priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
  570. tsf = priv->timestamp;
  571. beacon_int = priv->beacon_int;
  572. spin_unlock_irqrestore(&priv->lock, flags);
  573. if (priv->iw_mode == NL80211_IFTYPE_STATION) {
  574. if (beacon_int == 0) {
  575. priv->rxon_timing.beacon_interval = cpu_to_le16(100);
  576. priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
  577. } else {
  578. priv->rxon_timing.beacon_interval =
  579. cpu_to_le16(beacon_int);
  580. priv->rxon_timing.beacon_interval =
  581. iwl3945_adjust_beacon_interval(
  582. le16_to_cpu(priv->rxon_timing.beacon_interval));
  583. }
  584. priv->rxon_timing.atim_window = 0;
  585. } else {
  586. priv->rxon_timing.beacon_interval =
  587. iwl3945_adjust_beacon_interval(conf->beacon_int);
  588. /* TODO: we need to get atim_window from upper stack
  589. * for now we set to 0 */
  590. priv->rxon_timing.atim_window = 0;
  591. }
  592. interval_tm_unit =
  593. (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
  594. result = do_div(tsf, interval_tm_unit);
  595. priv->rxon_timing.beacon_init_val =
  596. cpu_to_le32((u32) ((u64) interval_tm_unit - result));
  597. IWL_DEBUG_ASSOC(priv,
  598. "beacon interval %d beacon timer %d beacon tim %d\n",
  599. le16_to_cpu(priv->rxon_timing.beacon_interval),
  600. le32_to_cpu(priv->rxon_timing.beacon_init_val),
  601. le16_to_cpu(priv->rxon_timing.atim_window));
  602. }
  603. static int iwl3945_set_mode(struct iwl_priv *priv, int mode)
  604. {
  605. if (mode == NL80211_IFTYPE_ADHOC) {
  606. const struct iwl_channel_info *ch_info;
  607. ch_info = iwl_get_channel_info(priv,
  608. priv->band,
  609. le16_to_cpu(priv->staging_rxon.channel));
  610. if (!ch_info || !is_channel_ibss(ch_info)) {
  611. IWL_ERR(priv, "channel %d not IBSS channel\n",
  612. le16_to_cpu(priv->staging_rxon.channel));
  613. return -EINVAL;
  614. }
  615. }
  616. iwl_connection_init_rx_config(priv, mode);
  617. iwl3945_clear_stations_table(priv);
  618. /* don't commit rxon if rf-kill is on*/
  619. if (!iwl_is_ready_rf(priv))
  620. return -EAGAIN;
  621. cancel_delayed_work(&priv->scan_check);
  622. if (iwl_scan_cancel_timeout(priv, 100)) {
  623. IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
  624. IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
  625. return -EAGAIN;
  626. }
  627. iwl3945_commit_rxon(priv);
  628. return 0;
  629. }
  630. static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
  631. struct ieee80211_tx_info *info,
  632. struct iwl_cmd *cmd,
  633. struct sk_buff *skb_frag,
  634. int last_frag)
  635. {
  636. struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
  637. struct iwl3945_hw_key *keyinfo =
  638. &priv->stations_39[info->control.hw_key->hw_key_idx].keyinfo;
  639. switch (keyinfo->alg) {
  640. case ALG_CCMP:
  641. tx->sec_ctl = TX_CMD_SEC_CCM;
  642. memcpy(tx->key, keyinfo->key, keyinfo->keylen);
  643. IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
  644. break;
  645. case ALG_TKIP:
  646. #if 0
  647. tx->sec_ctl = TX_CMD_SEC_TKIP;
  648. if (last_frag)
  649. memcpy(tx->tkip_mic.byte, skb_frag->tail - 8,
  650. 8);
  651. else
  652. memset(tx->tkip_mic.byte, 0, 8);
  653. #endif
  654. break;
  655. case ALG_WEP:
  656. tx->sec_ctl = TX_CMD_SEC_WEP |
  657. (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
  658. if (keyinfo->keylen == 13)
  659. tx->sec_ctl |= TX_CMD_SEC_KEY128;
  660. memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen);
  661. IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
  662. "with key %d\n", info->control.hw_key->hw_key_idx);
  663. break;
  664. default:
  665. IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg);
  666. break;
  667. }
  668. }
  669. /*
  670. * handle build REPLY_TX command notification.
  671. */
  672. static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
  673. struct iwl_cmd *cmd,
  674. struct ieee80211_tx_info *info,
  675. struct ieee80211_hdr *hdr, u8 std_id)
  676. {
  677. struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
  678. __le32 tx_flags = tx->tx_flags;
  679. __le16 fc = hdr->frame_control;
  680. u8 rc_flags = info->control.rates[0].flags;
  681. tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  682. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
  683. tx_flags |= TX_CMD_FLG_ACK_MSK;
  684. if (ieee80211_is_mgmt(fc))
  685. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  686. if (ieee80211_is_probe_resp(fc) &&
  687. !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
  688. tx_flags |= TX_CMD_FLG_TSF_MSK;
  689. } else {
  690. tx_flags &= (~TX_CMD_FLG_ACK_MSK);
  691. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  692. }
  693. tx->sta_id = std_id;
  694. if (ieee80211_has_morefrags(fc))
  695. tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
  696. if (ieee80211_is_data_qos(fc)) {
  697. u8 *qc = ieee80211_get_qos_ctl(hdr);
  698. tx->tid_tspec = qc[0] & 0xf;
  699. tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
  700. } else {
  701. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  702. }
  703. if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
  704. tx_flags |= TX_CMD_FLG_RTS_MSK;
  705. tx_flags &= ~TX_CMD_FLG_CTS_MSK;
  706. } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
  707. tx_flags &= ~TX_CMD_FLG_RTS_MSK;
  708. tx_flags |= TX_CMD_FLG_CTS_MSK;
  709. }
  710. if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
  711. tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
  712. tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
  713. if (ieee80211_is_mgmt(fc)) {
  714. if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
  715. tx->timeout.pm_frame_timeout = cpu_to_le16(3);
  716. else
  717. tx->timeout.pm_frame_timeout = cpu_to_le16(2);
  718. } else {
  719. tx->timeout.pm_frame_timeout = 0;
  720. #ifdef CONFIG_IWL3945_LEDS
  721. priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
  722. #endif
  723. }
  724. tx->driver_txop = 0;
  725. tx->tx_flags = tx_flags;
  726. tx->next_frame_len = 0;
  727. }
  728. /**
  729. * iwl3945_get_sta_id - Find station's index within station table
  730. */
  731. static int iwl3945_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
  732. {
  733. int sta_id;
  734. u16 fc = le16_to_cpu(hdr->frame_control);
  735. /* If this frame is broadcast or management, use broadcast station id */
  736. if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
  737. is_multicast_ether_addr(hdr->addr1))
  738. return priv->hw_params.bcast_sta_id;
  739. switch (priv->iw_mode) {
  740. /* If we are a client station in a BSS network, use the special
  741. * AP station entry (that's the only station we communicate with) */
  742. case NL80211_IFTYPE_STATION:
  743. return IWL_AP_ID;
  744. /* If we are an AP, then find the station, or use BCAST */
  745. case NL80211_IFTYPE_AP:
  746. sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
  747. if (sta_id != IWL_INVALID_STATION)
  748. return sta_id;
  749. return priv->hw_params.bcast_sta_id;
  750. /* If this frame is going out to an IBSS network, find the station,
  751. * or create a new station table entry */
  752. case NL80211_IFTYPE_ADHOC: {
  753. /* Create new station table entry */
  754. sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
  755. if (sta_id != IWL_INVALID_STATION)
  756. return sta_id;
  757. sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
  758. if (sta_id != IWL_INVALID_STATION)
  759. return sta_id;
  760. IWL_DEBUG_DROP(priv, "Station %pM not in station map. "
  761. "Defaulting to broadcast...\n",
  762. hdr->addr1);
  763. iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
  764. return priv->hw_params.bcast_sta_id;
  765. }
  766. /* If we are in monitor mode, use BCAST. This is required for
  767. * packet injection. */
  768. case NL80211_IFTYPE_MONITOR:
  769. return priv->hw_params.bcast_sta_id;
  770. default:
  771. IWL_WARN(priv, "Unknown mode of operation: %d\n",
  772. priv->iw_mode);
  773. return priv->hw_params.bcast_sta_id;
  774. }
  775. }
  776. /*
  777. * start REPLY_TX command process
  778. */
  779. static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
  780. {
  781. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  782. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  783. struct iwl3945_tx_cmd *tx;
  784. struct iwl_tx_queue *txq = NULL;
  785. struct iwl_queue *q = NULL;
  786. struct iwl_cmd *out_cmd = NULL;
  787. dma_addr_t phys_addr;
  788. dma_addr_t txcmd_phys;
  789. int txq_id = skb_get_queue_mapping(skb);
  790. u16 len, idx, len_org, hdr_len;
  791. u8 id;
  792. u8 unicast;
  793. u8 sta_id;
  794. u8 tid = 0;
  795. u16 seq_number = 0;
  796. __le16 fc;
  797. u8 wait_write_ptr = 0;
  798. u8 *qc = NULL;
  799. unsigned long flags;
  800. int rc;
  801. spin_lock_irqsave(&priv->lock, flags);
  802. if (iwl_is_rfkill(priv)) {
  803. IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
  804. goto drop_unlock;
  805. }
  806. if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
  807. IWL_ERR(priv, "ERROR: No TX rate available.\n");
  808. goto drop_unlock;
  809. }
  810. unicast = !is_multicast_ether_addr(hdr->addr1);
  811. id = 0;
  812. fc = hdr->frame_control;
  813. #ifdef CONFIG_IWLWIFI_DEBUG
  814. if (ieee80211_is_auth(fc))
  815. IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
  816. else if (ieee80211_is_assoc_req(fc))
  817. IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
  818. else if (ieee80211_is_reassoc_req(fc))
  819. IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
  820. #endif
  821. /* drop all data frame if we are not associated */
  822. if (ieee80211_is_data(fc) &&
  823. (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */
  824. (!iwl_is_associated(priv) ||
  825. ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
  826. IWL_DEBUG_DROP(priv, "Dropping - !iwl_is_associated\n");
  827. goto drop_unlock;
  828. }
  829. spin_unlock_irqrestore(&priv->lock, flags);
  830. hdr_len = ieee80211_hdrlen(fc);
  831. /* Find (or create) index into station table for destination station */
  832. sta_id = iwl3945_get_sta_id(priv, hdr);
  833. if (sta_id == IWL_INVALID_STATION) {
  834. IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
  835. hdr->addr1);
  836. goto drop;
  837. }
  838. IWL_DEBUG_RATE(priv, "station Id %d\n", sta_id);
  839. if (ieee80211_is_data_qos(fc)) {
  840. qc = ieee80211_get_qos_ctl(hdr);
  841. tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
  842. seq_number = priv->stations_39[sta_id].tid[tid].seq_number &
  843. IEEE80211_SCTL_SEQ;
  844. hdr->seq_ctrl = cpu_to_le16(seq_number) |
  845. (hdr->seq_ctrl &
  846. cpu_to_le16(IEEE80211_SCTL_FRAG));
  847. seq_number += 0x10;
  848. }
  849. /* Descriptor for chosen Tx queue */
  850. txq = &priv->txq[txq_id];
  851. q = &txq->q;
  852. spin_lock_irqsave(&priv->lock, flags);
  853. idx = get_cmd_index(q, q->write_ptr, 0);
  854. /* Set up driver data for this TFD */
  855. memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
  856. txq->txb[q->write_ptr].skb[0] = skb;
  857. /* Init first empty entry in queue's array of Tx/cmd buffers */
  858. out_cmd = txq->cmd[idx];
  859. tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
  860. memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
  861. memset(tx, 0, sizeof(*tx));
  862. /*
  863. * Set up the Tx-command (not MAC!) header.
  864. * Store the chosen Tx queue and TFD index within the sequence field;
  865. * after Tx, uCode's Tx response will return this value so driver can
  866. * locate the frame within the tx queue and do post-tx processing.
  867. */
  868. out_cmd->hdr.cmd = REPLY_TX;
  869. out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
  870. INDEX_TO_SEQ(q->write_ptr)));
  871. /* Copy MAC header from skb into command buffer */
  872. memcpy(tx->hdr, hdr, hdr_len);
  873. /*
  874. * Use the first empty entry in this queue's command buffer array
  875. * to contain the Tx command and MAC header concatenated together
  876. * (payload data will be in another buffer).
  877. * Size of this varies, due to varying MAC header length.
  878. * If end is not dword aligned, we'll have 2 extra bytes at the end
  879. * of the MAC header (device reads on dword boundaries).
  880. * We'll tell device about this padding later.
  881. */
  882. len = sizeof(struct iwl3945_tx_cmd) +
  883. sizeof(struct iwl_cmd_header) + hdr_len;
  884. len_org = len;
  885. len = (len + 3) & ~3;
  886. if (len_org != len)
  887. len_org = 1;
  888. else
  889. len_org = 0;
  890. /* Physical address of this Tx command's header (not MAC header!),
  891. * within command buffer array. */
  892. txcmd_phys = pci_map_single(priv->pci_dev,
  893. out_cmd, sizeof(struct iwl_cmd),
  894. PCI_DMA_TODEVICE);
  895. pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys);
  896. pci_unmap_len_set(&out_cmd->meta, len, sizeof(struct iwl_cmd));
  897. /* Add buffer containing Tx command and MAC(!) header to TFD's
  898. * first entry */
  899. txcmd_phys += offsetof(struct iwl_cmd, hdr);
  900. /* Add buffer containing Tx command and MAC(!) header to TFD's
  901. * first entry */
  902. priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
  903. txcmd_phys, len, 1, 0);
  904. if (info->control.hw_key)
  905. iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, 0);
  906. /* Set up TFD's 2nd entry to point directly to remainder of skb,
  907. * if any (802.11 null frames have no payload). */
  908. len = skb->len - hdr_len;
  909. if (len) {
  910. phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
  911. len, PCI_DMA_TODEVICE);
  912. priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
  913. phys_addr, len,
  914. 0, U32_PAD(len));
  915. }
  916. /* Total # bytes to be transmitted */
  917. len = (u16)skb->len;
  918. tx->len = cpu_to_le16(len);
  919. /* TODO need this for burst mode later on */
  920. iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
  921. /* set is_hcca to 0; it probably will never be implemented */
  922. iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
  923. tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
  924. tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
  925. if (!ieee80211_has_morefrags(hdr->frame_control)) {
  926. txq->need_update = 1;
  927. if (qc)
  928. priv->stations_39[sta_id].tid[tid].seq_number = seq_number;
  929. } else {
  930. wait_write_ptr = 1;
  931. txq->need_update = 0;
  932. }
  933. iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx));
  934. iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr,
  935. ieee80211_hdrlen(fc));
  936. /* Tell device the write index *just past* this latest filled TFD */
  937. q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
  938. rc = iwl_txq_update_write_ptr(priv, txq);
  939. spin_unlock_irqrestore(&priv->lock, flags);
  940. if (rc)
  941. return rc;
  942. if ((iwl_queue_space(q) < q->high_mark)
  943. && priv->mac80211_registered) {
  944. if (wait_write_ptr) {
  945. spin_lock_irqsave(&priv->lock, flags);
  946. txq->need_update = 1;
  947. iwl_txq_update_write_ptr(priv, txq);
  948. spin_unlock_irqrestore(&priv->lock, flags);
  949. }
  950. ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb));
  951. }
  952. return 0;
  953. drop_unlock:
  954. spin_unlock_irqrestore(&priv->lock, flags);
  955. drop:
  956. return -1;
  957. }
  958. static void iwl3945_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
  959. {
  960. unsigned long flags;
  961. if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
  962. return;
  963. IWL_DEBUG_RF_KILL(priv, "Manual SW RF KILL set to: RADIO %s\n",
  964. disable_radio ? "OFF" : "ON");
  965. if (disable_radio) {
  966. iwl_scan_cancel(priv);
  967. /* FIXME: This is a workaround for AP */
  968. if (priv->iw_mode != NL80211_IFTYPE_AP) {
  969. spin_lock_irqsave(&priv->lock, flags);
  970. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  971. CSR_UCODE_SW_BIT_RFKILL);
  972. spin_unlock_irqrestore(&priv->lock, flags);
  973. iwl_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0);
  974. set_bit(STATUS_RF_KILL_SW, &priv->status);
  975. }
  976. return;
  977. }
  978. spin_lock_irqsave(&priv->lock, flags);
  979. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  980. clear_bit(STATUS_RF_KILL_SW, &priv->status);
  981. spin_unlock_irqrestore(&priv->lock, flags);
  982. /* wake up ucode */
  983. msleep(10);
  984. spin_lock_irqsave(&priv->lock, flags);
  985. iwl_read32(priv, CSR_UCODE_DRV_GP1);
  986. if (!iwl_grab_nic_access(priv))
  987. iwl_release_nic_access(priv);
  988. spin_unlock_irqrestore(&priv->lock, flags);
  989. if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
  990. IWL_DEBUG_RF_KILL(priv, "Can not turn radio back on - "
  991. "disabled by HW switch\n");
  992. return;
  993. }
  994. if (priv->is_open)
  995. queue_work(priv->workqueue, &priv->restart);
  996. return;
  997. }
  998. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  999. #include "iwl-spectrum.h"
  1000. #define BEACON_TIME_MASK_LOW 0x00FFFFFF
  1001. #define BEACON_TIME_MASK_HIGH 0xFF000000
  1002. #define TIME_UNIT 1024
  1003. /*
  1004. * extended beacon time format
  1005. * time in usec will be changed into a 32-bit value in 8:24 format
  1006. * the high 1 byte is the beacon counts
  1007. * the lower 3 bytes is the time in usec within one beacon interval
  1008. */
  1009. static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
  1010. {
  1011. u32 quot;
  1012. u32 rem;
  1013. u32 interval = beacon_interval * 1024;
  1014. if (!interval || !usec)
  1015. return 0;
  1016. quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
  1017. rem = (usec % interval) & BEACON_TIME_MASK_LOW;
  1018. return (quot << 24) + rem;
  1019. }
  1020. /* base is usually what we get from ucode with each received frame,
  1021. * the same as HW timer counter counting down
  1022. */
  1023. static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
  1024. {
  1025. u32 base_low = base & BEACON_TIME_MASK_LOW;
  1026. u32 addon_low = addon & BEACON_TIME_MASK_LOW;
  1027. u32 interval = beacon_interval * TIME_UNIT;
  1028. u32 res = (base & BEACON_TIME_MASK_HIGH) +
  1029. (addon & BEACON_TIME_MASK_HIGH);
  1030. if (base_low > addon_low)
  1031. res += base_low - addon_low;
  1032. else if (base_low < addon_low) {
  1033. res += interval + base_low - addon_low;
  1034. res += (1 << 24);
  1035. } else
  1036. res += (1 << 24);
  1037. return cpu_to_le32(res);
  1038. }
  1039. static int iwl3945_get_measurement(struct iwl_priv *priv,
  1040. struct ieee80211_measurement_params *params,
  1041. u8 type)
  1042. {
  1043. struct iwl_spectrum_cmd spectrum;
  1044. struct iwl_rx_packet *res;
  1045. struct iwl_host_cmd cmd = {
  1046. .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
  1047. .data = (void *)&spectrum,
  1048. .meta.flags = CMD_WANT_SKB,
  1049. };
  1050. u32 add_time = le64_to_cpu(params->start_time);
  1051. int rc;
  1052. int spectrum_resp_status;
  1053. int duration = le16_to_cpu(params->duration);
  1054. if (iwl_is_associated(priv))
  1055. add_time =
  1056. iwl3945_usecs_to_beacons(
  1057. le64_to_cpu(params->start_time) - priv->last_tsf,
  1058. le16_to_cpu(priv->rxon_timing.beacon_interval));
  1059. memset(&spectrum, 0, sizeof(spectrum));
  1060. spectrum.channel_count = cpu_to_le16(1);
  1061. spectrum.flags =
  1062. RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
  1063. spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
  1064. cmd.len = sizeof(spectrum);
  1065. spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
  1066. if (iwl_is_associated(priv))
  1067. spectrum.start_time =
  1068. iwl3945_add_beacon_time(priv->last_beacon_time,
  1069. add_time,
  1070. le16_to_cpu(priv->rxon_timing.beacon_interval));
  1071. else
  1072. spectrum.start_time = 0;
  1073. spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
  1074. spectrum.channels[0].channel = params->channel;
  1075. spectrum.channels[0].type = type;
  1076. if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
  1077. spectrum.flags |= RXON_FLG_BAND_24G_MSK |
  1078. RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
  1079. rc = iwl_send_cmd_sync(priv, &cmd);
  1080. if (rc)
  1081. return rc;
  1082. res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
  1083. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  1084. IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
  1085. rc = -EIO;
  1086. }
  1087. spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
  1088. switch (spectrum_resp_status) {
  1089. case 0: /* Command will be handled */
  1090. if (res->u.spectrum.id != 0xff) {
  1091. IWL_DEBUG_INFO(priv, "Replaced existing measurement: %d\n",
  1092. res->u.spectrum.id);
  1093. priv->measurement_status &= ~MEASUREMENT_READY;
  1094. }
  1095. priv->measurement_status |= MEASUREMENT_ACTIVE;
  1096. rc = 0;
  1097. break;
  1098. case 1: /* Command will not be handled */
  1099. rc = -EAGAIN;
  1100. break;
  1101. }
  1102. dev_kfree_skb_any(cmd.meta.u.skb);
  1103. return rc;
  1104. }
  1105. #endif
  1106. static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
  1107. struct iwl_rx_mem_buffer *rxb)
  1108. {
  1109. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1110. struct iwl_alive_resp *palive;
  1111. struct delayed_work *pwork;
  1112. palive = &pkt->u.alive_frame;
  1113. IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
  1114. "0x%01X 0x%01X\n",
  1115. palive->is_valid, palive->ver_type,
  1116. palive->ver_subtype);
  1117. if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
  1118. IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
  1119. memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
  1120. sizeof(struct iwl_alive_resp));
  1121. pwork = &priv->init_alive_start;
  1122. } else {
  1123. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  1124. memcpy(&priv->card_alive, &pkt->u.alive_frame,
  1125. sizeof(struct iwl_alive_resp));
  1126. pwork = &priv->alive_start;
  1127. iwl3945_disable_events(priv);
  1128. }
  1129. /* We delay the ALIVE response by 5ms to
  1130. * give the HW RF Kill time to activate... */
  1131. if (palive->is_valid == UCODE_VALID_OK)
  1132. queue_delayed_work(priv->workqueue, pwork,
  1133. msecs_to_jiffies(5));
  1134. else
  1135. IWL_WARN(priv, "uCode did not respond OK.\n");
  1136. }
  1137. static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
  1138. struct iwl_rx_mem_buffer *rxb)
  1139. {
  1140. #ifdef CONFIG_IWLWIFI_DEBUG
  1141. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1142. #endif
  1143. IWL_DEBUG_RX(priv, "Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
  1144. return;
  1145. }
  1146. static void iwl3945_bg_beacon_update(struct work_struct *work)
  1147. {
  1148. struct iwl_priv *priv =
  1149. container_of(work, struct iwl_priv, beacon_update);
  1150. struct sk_buff *beacon;
  1151. /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
  1152. beacon = ieee80211_beacon_get(priv->hw, priv->vif);
  1153. if (!beacon) {
  1154. IWL_ERR(priv, "update beacon failed\n");
  1155. return;
  1156. }
  1157. mutex_lock(&priv->mutex);
  1158. /* new beacon skb is allocated every time; dispose previous.*/
  1159. if (priv->ibss_beacon)
  1160. dev_kfree_skb(priv->ibss_beacon);
  1161. priv->ibss_beacon = beacon;
  1162. mutex_unlock(&priv->mutex);
  1163. iwl3945_send_beacon_cmd(priv);
  1164. }
  1165. static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
  1166. struct iwl_rx_mem_buffer *rxb)
  1167. {
  1168. #ifdef CONFIG_IWLWIFI_DEBUG
  1169. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1170. struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
  1171. u8 rate = beacon->beacon_notify_hdr.rate;
  1172. IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
  1173. "tsf %d %d rate %d\n",
  1174. le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
  1175. beacon->beacon_notify_hdr.failure_frame,
  1176. le32_to_cpu(beacon->ibss_mgr_status),
  1177. le32_to_cpu(beacon->high_tsf),
  1178. le32_to_cpu(beacon->low_tsf), rate);
  1179. #endif
  1180. if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
  1181. (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
  1182. queue_work(priv->workqueue, &priv->beacon_update);
  1183. }
  1184. /* Handle notification from uCode that card's power state is changing
  1185. * due to software, hardware, or critical temperature RFKILL */
  1186. static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
  1187. struct iwl_rx_mem_buffer *rxb)
  1188. {
  1189. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1190. u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
  1191. unsigned long status = priv->status;
  1192. IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n",
  1193. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  1194. (flags & SW_CARD_DISABLED) ? "Kill" : "On");
  1195. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  1196. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  1197. if (flags & HW_CARD_DISABLED)
  1198. set_bit(STATUS_RF_KILL_HW, &priv->status);
  1199. else
  1200. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  1201. if (flags & SW_CARD_DISABLED)
  1202. set_bit(STATUS_RF_KILL_SW, &priv->status);
  1203. else
  1204. clear_bit(STATUS_RF_KILL_SW, &priv->status);
  1205. iwl_scan_cancel(priv);
  1206. if ((test_bit(STATUS_RF_KILL_HW, &status) !=
  1207. test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
  1208. (test_bit(STATUS_RF_KILL_SW, &status) !=
  1209. test_bit(STATUS_RF_KILL_SW, &priv->status)))
  1210. queue_work(priv->workqueue, &priv->rf_kill);
  1211. else
  1212. wake_up_interruptible(&priv->wait_command_queue);
  1213. }
  1214. /**
  1215. * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
  1216. *
  1217. * Setup the RX handlers for each of the reply types sent from the uCode
  1218. * to the host.
  1219. *
  1220. * This function chains into the hardware specific files for them to setup
  1221. * any hardware specific handlers as well.
  1222. */
  1223. static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
  1224. {
  1225. priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
  1226. priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
  1227. priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
  1228. priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
  1229. priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
  1230. priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
  1231. iwl_rx_pm_debug_statistics_notif;
  1232. priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
  1233. /*
  1234. * The same handler is used for both the REPLY to a discrete
  1235. * statistics request from the host as well as for the periodic
  1236. * statistics notifications (after received beacons) from the uCode.
  1237. */
  1238. priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
  1239. priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
  1240. iwl_setup_spectrum_handlers(priv);
  1241. iwl_setup_rx_scan_handlers(priv);
  1242. priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
  1243. /* Set up hardware specific Rx handlers */
  1244. iwl3945_hw_rx_handler_setup(priv);
  1245. }
  1246. /**
  1247. * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries
  1248. * When FW advances 'R' index, all entries between old and new 'R' index
  1249. * need to be reclaimed.
  1250. */
  1251. static void iwl3945_cmd_queue_reclaim(struct iwl_priv *priv,
  1252. int txq_id, int index)
  1253. {
  1254. struct iwl_tx_queue *txq = &priv->txq[txq_id];
  1255. struct iwl_queue *q = &txq->q;
  1256. int nfreed = 0;
  1257. if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) {
  1258. IWL_ERR(priv, "Read index for DMA queue txq id (%d), index %d, "
  1259. "is out of range [0-%d] %d %d.\n", txq_id,
  1260. index, q->n_bd, q->write_ptr, q->read_ptr);
  1261. return;
  1262. }
  1263. for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
  1264. q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
  1265. if (nfreed > 1) {
  1266. IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", index,
  1267. q->write_ptr, q->read_ptr);
  1268. queue_work(priv->workqueue, &priv->restart);
  1269. break;
  1270. }
  1271. nfreed++;
  1272. }
  1273. }
  1274. /**
  1275. * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
  1276. * @rxb: Rx buffer to reclaim
  1277. *
  1278. * If an Rx buffer has an async callback associated with it the callback
  1279. * will be executed. The attached skb (if present) will only be freed
  1280. * if the callback returns 1
  1281. */
  1282. static void iwl3945_tx_cmd_complete(struct iwl_priv *priv,
  1283. struct iwl_rx_mem_buffer *rxb)
  1284. {
  1285. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1286. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  1287. int txq_id = SEQ_TO_QUEUE(sequence);
  1288. int index = SEQ_TO_INDEX(sequence);
  1289. int huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME);
  1290. int cmd_index;
  1291. struct iwl_cmd *cmd;
  1292. if (WARN(txq_id != IWL_CMD_QUEUE_NUM,
  1293. "wrong command queue %d, sequence 0x%X readp=%d writep=%d\n",
  1294. txq_id, sequence,
  1295. priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr,
  1296. priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) {
  1297. iwl_print_hex_dump(priv, IWL_DL_INFO , rxb, 32);
  1298. return;
  1299. }
  1300. cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
  1301. cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
  1302. /* Input error checking is done when commands are added to queue. */
  1303. if (cmd->meta.flags & CMD_WANT_SKB) {
  1304. cmd->meta.source->u.skb = rxb->skb;
  1305. rxb->skb = NULL;
  1306. } else if (cmd->meta.u.callback &&
  1307. !cmd->meta.u.callback(priv, cmd, rxb->skb))
  1308. rxb->skb = NULL;
  1309. iwl3945_cmd_queue_reclaim(priv, txq_id, index);
  1310. if (!(cmd->meta.flags & CMD_ASYNC)) {
  1311. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  1312. wake_up_interruptible(&priv->wait_command_queue);
  1313. }
  1314. }
  1315. /************************** RX-FUNCTIONS ****************************/
  1316. /*
  1317. * Rx theory of operation
  1318. *
  1319. * The host allocates 32 DMA target addresses and passes the host address
  1320. * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
  1321. * 0 to 31
  1322. *
  1323. * Rx Queue Indexes
  1324. * The host/firmware share two index registers for managing the Rx buffers.
  1325. *
  1326. * The READ index maps to the first position that the firmware may be writing
  1327. * to -- the driver can read up to (but not including) this position and get
  1328. * good data.
  1329. * The READ index is managed by the firmware once the card is enabled.
  1330. *
  1331. * The WRITE index maps to the last position the driver has read from -- the
  1332. * position preceding WRITE is the last slot the firmware can place a packet.
  1333. *
  1334. * The queue is empty (no good data) if WRITE = READ - 1, and is full if
  1335. * WRITE = READ.
  1336. *
  1337. * During initialization, the host sets up the READ queue position to the first
  1338. * INDEX position, and WRITE to the last (READ - 1 wrapped)
  1339. *
  1340. * When the firmware places a packet in a buffer, it will advance the READ index
  1341. * and fire the RX interrupt. The driver can then query the READ index and
  1342. * process as many packets as possible, moving the WRITE index forward as it
  1343. * resets the Rx queue buffers with new memory.
  1344. *
  1345. * The management in the driver is as follows:
  1346. * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
  1347. * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
  1348. * to replenish the iwl->rxq->rx_free.
  1349. * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
  1350. * iwl->rxq is replenished and the READ INDEX is updated (updating the
  1351. * 'processed' and 'read' driver indexes as well)
  1352. * + A received packet is processed and handed to the kernel network stack,
  1353. * detached from the iwl->rxq. The driver 'processed' index is updated.
  1354. * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
  1355. * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
  1356. * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
  1357. * were enough free buffers and RX_STALLED is set it is cleared.
  1358. *
  1359. *
  1360. * Driver sequence:
  1361. *
  1362. * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
  1363. * iwl3945_rx_queue_restock
  1364. * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
  1365. * queue, updates firmware pointers, and updates
  1366. * the WRITE index. If insufficient rx_free buffers
  1367. * are available, schedules iwl3945_rx_replenish
  1368. *
  1369. * -- enable interrupts --
  1370. * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
  1371. * READ INDEX, detaching the SKB from the pool.
  1372. * Moves the packet buffer from queue to rx_used.
  1373. * Calls iwl3945_rx_queue_restock to refill any empty
  1374. * slots.
  1375. * ...
  1376. *
  1377. */
  1378. /**
  1379. * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
  1380. */
  1381. static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
  1382. dma_addr_t dma_addr)
  1383. {
  1384. return cpu_to_le32((u32)dma_addr);
  1385. }
  1386. /**
  1387. * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
  1388. *
  1389. * If there are slots in the RX queue that need to be restocked,
  1390. * and we have free pre-allocated buffers, fill the ranks as much
  1391. * as we can, pulling from rx_free.
  1392. *
  1393. * This moves the 'write' index forward to catch up with 'processed', and
  1394. * also updates the memory address in the firmware to reference the new
  1395. * target buffer.
  1396. */
  1397. static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
  1398. {
  1399. struct iwl_rx_queue *rxq = &priv->rxq;
  1400. struct list_head *element;
  1401. struct iwl_rx_mem_buffer *rxb;
  1402. unsigned long flags;
  1403. int write, rc;
  1404. spin_lock_irqsave(&rxq->lock, flags);
  1405. write = rxq->write & ~0x7;
  1406. while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
  1407. /* Get next free Rx buffer, remove from free list */
  1408. element = rxq->rx_free.next;
  1409. rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
  1410. list_del(element);
  1411. /* Point to Rx buffer via next RBD in circular buffer */
  1412. rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr);
  1413. rxq->queue[rxq->write] = rxb;
  1414. rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
  1415. rxq->free_count--;
  1416. }
  1417. spin_unlock_irqrestore(&rxq->lock, flags);
  1418. /* If the pre-allocated buffer pool is dropping low, schedule to
  1419. * refill it */
  1420. if (rxq->free_count <= RX_LOW_WATERMARK)
  1421. queue_work(priv->workqueue, &priv->rx_replenish);
  1422. /* If we've added more space for the firmware to place data, tell it.
  1423. * Increment device's write pointer in multiples of 8. */
  1424. if ((write != (rxq->write & ~0x7))
  1425. || (abs(rxq->write - rxq->read) > 7)) {
  1426. spin_lock_irqsave(&rxq->lock, flags);
  1427. rxq->need_update = 1;
  1428. spin_unlock_irqrestore(&rxq->lock, flags);
  1429. rc = iwl_rx_queue_update_write_ptr(priv, rxq);
  1430. if (rc)
  1431. return rc;
  1432. }
  1433. return 0;
  1434. }
  1435. /**
  1436. * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
  1437. *
  1438. * When moving to rx_free an SKB is allocated for the slot.
  1439. *
  1440. * Also restock the Rx queue via iwl3945_rx_queue_restock.
  1441. * This is called as a scheduled work item (except for during initialization)
  1442. */
  1443. static void iwl3945_rx_allocate(struct iwl_priv *priv)
  1444. {
  1445. struct iwl_rx_queue *rxq = &priv->rxq;
  1446. struct list_head *element;
  1447. struct iwl_rx_mem_buffer *rxb;
  1448. unsigned long flags;
  1449. spin_lock_irqsave(&rxq->lock, flags);
  1450. while (!list_empty(&rxq->rx_used)) {
  1451. element = rxq->rx_used.next;
  1452. rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
  1453. /* Alloc a new receive buffer */
  1454. rxb->skb =
  1455. alloc_skb(priv->hw_params.rx_buf_size,
  1456. __GFP_NOWARN | GFP_ATOMIC);
  1457. if (!rxb->skb) {
  1458. if (net_ratelimit())
  1459. IWL_CRIT(priv, ": Can not allocate SKB buffers\n");
  1460. /* We don't reschedule replenish work here -- we will
  1461. * call the restock method and if it still needs
  1462. * more buffers it will schedule replenish */
  1463. break;
  1464. }
  1465. /* If radiotap head is required, reserve some headroom here.
  1466. * The physical head count is a variable rx_stats->phy_count.
  1467. * We reserve 4 bytes here. Plus these extra bytes, the
  1468. * headroom of the physical head should be enough for the
  1469. * radiotap head that iwl3945 supported. See iwl3945_rt.
  1470. */
  1471. skb_reserve(rxb->skb, 4);
  1472. priv->alloc_rxb_skb++;
  1473. list_del(element);
  1474. /* Get physical address of RB/SKB */
  1475. rxb->real_dma_addr = pci_map_single(priv->pci_dev,
  1476. rxb->skb->data,
  1477. priv->hw_params.rx_buf_size,
  1478. PCI_DMA_FROMDEVICE);
  1479. list_add_tail(&rxb->list, &rxq->rx_free);
  1480. rxq->free_count++;
  1481. }
  1482. spin_unlock_irqrestore(&rxq->lock, flags);
  1483. }
  1484. /*
  1485. * this should be called while priv->lock is locked
  1486. */
  1487. static void __iwl3945_rx_replenish(void *data)
  1488. {
  1489. struct iwl_priv *priv = data;
  1490. iwl3945_rx_allocate(priv);
  1491. iwl3945_rx_queue_restock(priv);
  1492. }
  1493. void iwl3945_rx_replenish(void *data)
  1494. {
  1495. struct iwl_priv *priv = data;
  1496. unsigned long flags;
  1497. iwl3945_rx_allocate(priv);
  1498. spin_lock_irqsave(&priv->lock, flags);
  1499. iwl3945_rx_queue_restock(priv);
  1500. spin_unlock_irqrestore(&priv->lock, flags);
  1501. }
  1502. /* Convert linear signal-to-noise ratio into dB */
  1503. static u8 ratio2dB[100] = {
  1504. /* 0 1 2 3 4 5 6 7 8 9 */
  1505. 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
  1506. 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
  1507. 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
  1508. 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
  1509. 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
  1510. 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
  1511. 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
  1512. 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
  1513. 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
  1514. 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
  1515. };
  1516. /* Calculates a relative dB value from a ratio of linear
  1517. * (i.e. not dB) signal levels.
  1518. * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
  1519. int iwl3945_calc_db_from_ratio(int sig_ratio)
  1520. {
  1521. /* 1000:1 or higher just report as 60 dB */
  1522. if (sig_ratio >= 1000)
  1523. return 60;
  1524. /* 100:1 or higher, divide by 10 and use table,
  1525. * add 20 dB to make up for divide by 10 */
  1526. if (sig_ratio >= 100)
  1527. return 20 + (int)ratio2dB[sig_ratio/10];
  1528. /* We shouldn't see this */
  1529. if (sig_ratio < 1)
  1530. return 0;
  1531. /* Use table for ratios 1:1 - 99:1 */
  1532. return (int)ratio2dB[sig_ratio];
  1533. }
  1534. #define PERFECT_RSSI (-20) /* dBm */
  1535. #define WORST_RSSI (-95) /* dBm */
  1536. #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
  1537. /* Calculate an indication of rx signal quality (a percentage, not dBm!).
  1538. * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
  1539. * about formulas used below. */
  1540. int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
  1541. {
  1542. int sig_qual;
  1543. int degradation = PERFECT_RSSI - rssi_dbm;
  1544. /* If we get a noise measurement, use signal-to-noise ratio (SNR)
  1545. * as indicator; formula is (signal dbm - noise dbm).
  1546. * SNR at or above 40 is a great signal (100%).
  1547. * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
  1548. * Weakest usable signal is usually 10 - 15 dB SNR. */
  1549. if (noise_dbm) {
  1550. if (rssi_dbm - noise_dbm >= 40)
  1551. return 100;
  1552. else if (rssi_dbm < noise_dbm)
  1553. return 0;
  1554. sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
  1555. /* Else use just the signal level.
  1556. * This formula is a least squares fit of data points collected and
  1557. * compared with a reference system that had a percentage (%) display
  1558. * for signal quality. */
  1559. } else
  1560. sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
  1561. (15 * RSSI_RANGE + 62 * degradation)) /
  1562. (RSSI_RANGE * RSSI_RANGE);
  1563. if (sig_qual > 100)
  1564. sig_qual = 100;
  1565. else if (sig_qual < 1)
  1566. sig_qual = 0;
  1567. return sig_qual;
  1568. }
  1569. /**
  1570. * iwl3945_rx_handle - Main entry function for receiving responses from uCode
  1571. *
  1572. * Uses the priv->rx_handlers callback function array to invoke
  1573. * the appropriate handlers, including command responses,
  1574. * frame-received notifications, and other notifications.
  1575. */
  1576. static void iwl3945_rx_handle(struct iwl_priv *priv)
  1577. {
  1578. struct iwl_rx_mem_buffer *rxb;
  1579. struct iwl_rx_packet *pkt;
  1580. struct iwl_rx_queue *rxq = &priv->rxq;
  1581. u32 r, i;
  1582. int reclaim;
  1583. unsigned long flags;
  1584. u8 fill_rx = 0;
  1585. u32 count = 8;
  1586. /* uCode's read index (stored in shared DRAM) indicates the last Rx
  1587. * buffer that the driver may process (last buffer filled by ucode). */
  1588. r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
  1589. i = rxq->read;
  1590. if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
  1591. fill_rx = 1;
  1592. /* Rx interrupt, but nothing sent from uCode */
  1593. if (i == r)
  1594. IWL_DEBUG(priv, IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
  1595. while (i != r) {
  1596. rxb = rxq->queue[i];
  1597. /* If an RXB doesn't have a Rx queue slot associated with it,
  1598. * then a bug has been introduced in the queue refilling
  1599. * routines -- catch it here */
  1600. BUG_ON(rxb == NULL);
  1601. rxq->queue[i] = NULL;
  1602. pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->real_dma_addr,
  1603. priv->hw_params.rx_buf_size,
  1604. PCI_DMA_FROMDEVICE);
  1605. pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1606. /* Reclaim a command buffer only if this packet is a response
  1607. * to a (driver-originated) command.
  1608. * If the packet (e.g. Rx frame) originated from uCode,
  1609. * there is no command buffer to reclaim.
  1610. * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
  1611. * but apparently a few don't get set; catch them here. */
  1612. reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
  1613. (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
  1614. (pkt->hdr.cmd != REPLY_TX);
  1615. /* Based on type of command response or notification,
  1616. * handle those that need handling via function in
  1617. * rx_handlers table. See iwl3945_setup_rx_handlers() */
  1618. if (priv->rx_handlers[pkt->hdr.cmd]) {
  1619. IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
  1620. "r = %d, i = %d, %s, 0x%02x\n", r, i,
  1621. get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
  1622. priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
  1623. } else {
  1624. /* No handling needed */
  1625. IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
  1626. "r %d i %d No handler needed for %s, 0x%02x\n",
  1627. r, i, get_cmd_string(pkt->hdr.cmd),
  1628. pkt->hdr.cmd);
  1629. }
  1630. if (reclaim) {
  1631. /* Invoke any callbacks, transfer the skb to caller, and
  1632. * fire off the (possibly) blocking iwl_send_cmd()
  1633. * as we reclaim the driver command queue */
  1634. if (rxb && rxb->skb)
  1635. iwl3945_tx_cmd_complete(priv, rxb);
  1636. else
  1637. IWL_WARN(priv, "Claim null rxb?\n");
  1638. }
  1639. /* For now we just don't re-use anything. We can tweak this
  1640. * later to try and re-use notification packets and SKBs that
  1641. * fail to Rx correctly */
  1642. if (rxb->skb != NULL) {
  1643. priv->alloc_rxb_skb--;
  1644. dev_kfree_skb_any(rxb->skb);
  1645. rxb->skb = NULL;
  1646. }
  1647. pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
  1648. priv->hw_params.rx_buf_size,
  1649. PCI_DMA_FROMDEVICE);
  1650. spin_lock_irqsave(&rxq->lock, flags);
  1651. list_add_tail(&rxb->list, &priv->rxq.rx_used);
  1652. spin_unlock_irqrestore(&rxq->lock, flags);
  1653. i = (i + 1) & RX_QUEUE_MASK;
  1654. /* If there are a lot of unused frames,
  1655. * restock the Rx queue so ucode won't assert. */
  1656. if (fill_rx) {
  1657. count++;
  1658. if (count >= 8) {
  1659. priv->rxq.read = i;
  1660. __iwl3945_rx_replenish(priv);
  1661. count = 0;
  1662. }
  1663. }
  1664. }
  1665. /* Backtrack one entry */
  1666. priv->rxq.read = i;
  1667. iwl3945_rx_queue_restock(priv);
  1668. }
  1669. static void iwl3945_enable_interrupts(struct iwl_priv *priv)
  1670. {
  1671. IWL_DEBUG_ISR(priv, "Enabling interrupts\n");
  1672. set_bit(STATUS_INT_ENABLED, &priv->status);
  1673. iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
  1674. }
  1675. /* call this function to flush any scheduled tasklet */
  1676. static inline void iwl_synchronize_irq(struct iwl_priv *priv)
  1677. {
  1678. /* wait to make sure we flush pending tasklet*/
  1679. synchronize_irq(priv->pci_dev->irq);
  1680. tasklet_kill(&priv->irq_tasklet);
  1681. }
  1682. static inline void iwl3945_disable_interrupts(struct iwl_priv *priv)
  1683. {
  1684. clear_bit(STATUS_INT_ENABLED, &priv->status);
  1685. /* disable interrupts from uCode/NIC to host */
  1686. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  1687. /* acknowledge/clear/reset any interrupts still pending
  1688. * from uCode or flow handler (Rx/Tx DMA) */
  1689. iwl_write32(priv, CSR_INT, 0xffffffff);
  1690. iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
  1691. IWL_DEBUG_ISR(priv, "Disabled interrupts\n");
  1692. }
  1693. static const char *desc_lookup(int i)
  1694. {
  1695. switch (i) {
  1696. case 1:
  1697. return "FAIL";
  1698. case 2:
  1699. return "BAD_PARAM";
  1700. case 3:
  1701. return "BAD_CHECKSUM";
  1702. case 4:
  1703. return "NMI_INTERRUPT";
  1704. case 5:
  1705. return "SYSASSERT";
  1706. case 6:
  1707. return "FATAL_ERROR";
  1708. }
  1709. return "UNKNOWN";
  1710. }
  1711. #define ERROR_START_OFFSET (1 * sizeof(u32))
  1712. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  1713. static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
  1714. {
  1715. u32 i;
  1716. u32 desc, time, count, base, data1;
  1717. u32 blink1, blink2, ilink1, ilink2;
  1718. int rc;
  1719. base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
  1720. if (!iwl3945_hw_valid_rtc_data_addr(base)) {
  1721. IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
  1722. return;
  1723. }
  1724. rc = iwl_grab_nic_access(priv);
  1725. if (rc) {
  1726. IWL_WARN(priv, "Can not read from adapter at this time.\n");
  1727. return;
  1728. }
  1729. count = iwl_read_targ_mem(priv, base);
  1730. if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
  1731. IWL_ERR(priv, "Start IWL Error Log Dump:\n");
  1732. IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
  1733. priv->status, count);
  1734. }
  1735. IWL_ERR(priv, "Desc Time asrtPC blink2 "
  1736. "ilink1 nmiPC Line\n");
  1737. for (i = ERROR_START_OFFSET;
  1738. i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
  1739. i += ERROR_ELEM_SIZE) {
  1740. desc = iwl_read_targ_mem(priv, base + i);
  1741. time =
  1742. iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
  1743. blink1 =
  1744. iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
  1745. blink2 =
  1746. iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
  1747. ilink1 =
  1748. iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
  1749. ilink2 =
  1750. iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
  1751. data1 =
  1752. iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
  1753. IWL_ERR(priv,
  1754. "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
  1755. desc_lookup(desc), desc, time, blink1, blink2,
  1756. ilink1, ilink2, data1);
  1757. }
  1758. iwl_release_nic_access(priv);
  1759. }
  1760. #define EVENT_START_OFFSET (6 * sizeof(u32))
  1761. /**
  1762. * iwl3945_print_event_log - Dump error event log to syslog
  1763. *
  1764. * NOTE: Must be called with iwl_grab_nic_access() already obtained!
  1765. */
  1766. static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
  1767. u32 num_events, u32 mode)
  1768. {
  1769. u32 i;
  1770. u32 base; /* SRAM byte address of event log header */
  1771. u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
  1772. u32 ptr; /* SRAM byte address of log data */
  1773. u32 ev, time, data; /* event log data */
  1774. if (num_events == 0)
  1775. return;
  1776. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  1777. if (mode == 0)
  1778. event_size = 2 * sizeof(u32);
  1779. else
  1780. event_size = 3 * sizeof(u32);
  1781. ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
  1782. /* "time" is actually "data" for mode 0 (no timestamp).
  1783. * place event id # at far right for easier visual parsing. */
  1784. for (i = 0; i < num_events; i++) {
  1785. ev = iwl_read_targ_mem(priv, ptr);
  1786. ptr += sizeof(u32);
  1787. time = iwl_read_targ_mem(priv, ptr);
  1788. ptr += sizeof(u32);
  1789. if (mode == 0) {
  1790. /* data, ev */
  1791. IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
  1792. } else {
  1793. data = iwl_read_targ_mem(priv, ptr);
  1794. ptr += sizeof(u32);
  1795. IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev);
  1796. }
  1797. }
  1798. }
  1799. static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
  1800. {
  1801. int rc;
  1802. u32 base; /* SRAM byte address of event log header */
  1803. u32 capacity; /* event log capacity in # entries */
  1804. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  1805. u32 num_wraps; /* # times uCode wrapped to top of log */
  1806. u32 next_entry; /* index of next entry to be written by uCode */
  1807. u32 size; /* # entries that we'll print */
  1808. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  1809. if (!iwl3945_hw_valid_rtc_data_addr(base)) {
  1810. IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
  1811. return;
  1812. }
  1813. rc = iwl_grab_nic_access(priv);
  1814. if (rc) {
  1815. IWL_WARN(priv, "Can not read from adapter at this time.\n");
  1816. return;
  1817. }
  1818. /* event log header */
  1819. capacity = iwl_read_targ_mem(priv, base);
  1820. mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
  1821. num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
  1822. next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
  1823. size = num_wraps ? capacity : next_entry;
  1824. /* bail out if nothing in log */
  1825. if (size == 0) {
  1826. IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
  1827. iwl_release_nic_access(priv);
  1828. return;
  1829. }
  1830. IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
  1831. size, num_wraps);
  1832. /* if uCode has wrapped back to top of log, start at the oldest entry,
  1833. * i.e the next one that uCode would fill. */
  1834. if (num_wraps)
  1835. iwl3945_print_event_log(priv, next_entry,
  1836. capacity - next_entry, mode);
  1837. /* (then/else) start at top of log */
  1838. iwl3945_print_event_log(priv, 0, next_entry, mode);
  1839. iwl_release_nic_access(priv);
  1840. }
  1841. static void iwl3945_error_recovery(struct iwl_priv *priv)
  1842. {
  1843. unsigned long flags;
  1844. memcpy(&priv->staging_rxon, &priv->recovery_rxon,
  1845. sizeof(priv->staging_rxon));
  1846. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1847. iwl3945_commit_rxon(priv);
  1848. iwl3945_add_station(priv, priv->bssid, 1, 0);
  1849. spin_lock_irqsave(&priv->lock, flags);
  1850. priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
  1851. priv->error_recovering = 0;
  1852. spin_unlock_irqrestore(&priv->lock, flags);
  1853. }
  1854. static void iwl3945_irq_tasklet(struct iwl_priv *priv)
  1855. {
  1856. u32 inta, handled = 0;
  1857. u32 inta_fh;
  1858. unsigned long flags;
  1859. #ifdef CONFIG_IWLWIFI_DEBUG
  1860. u32 inta_mask;
  1861. #endif
  1862. spin_lock_irqsave(&priv->lock, flags);
  1863. /* Ack/clear/reset pending uCode interrupts.
  1864. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
  1865. * and will clear only when CSR_FH_INT_STATUS gets cleared. */
  1866. inta = iwl_read32(priv, CSR_INT);
  1867. iwl_write32(priv, CSR_INT, inta);
  1868. /* Ack/clear/reset pending flow-handler (DMA) interrupts.
  1869. * Any new interrupts that happen after this, either while we're
  1870. * in this tasklet, or later, will show up in next ISR/tasklet. */
  1871. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  1872. iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
  1873. #ifdef CONFIG_IWLWIFI_DEBUG
  1874. if (priv->debug_level & IWL_DL_ISR) {
  1875. /* just for debug */
  1876. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  1877. IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  1878. inta, inta_mask, inta_fh);
  1879. }
  1880. #endif
  1881. /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
  1882. * atomic, make sure that inta covers all the interrupts that
  1883. * we've discovered, even if FH interrupt came in just after
  1884. * reading CSR_INT. */
  1885. if (inta_fh & CSR39_FH_INT_RX_MASK)
  1886. inta |= CSR_INT_BIT_FH_RX;
  1887. if (inta_fh & CSR39_FH_INT_TX_MASK)
  1888. inta |= CSR_INT_BIT_FH_TX;
  1889. /* Now service all interrupt bits discovered above. */
  1890. if (inta & CSR_INT_BIT_HW_ERR) {
  1891. IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
  1892. /* Tell the device to stop sending interrupts */
  1893. iwl3945_disable_interrupts(priv);
  1894. iwl_irq_handle_error(priv);
  1895. handled |= CSR_INT_BIT_HW_ERR;
  1896. spin_unlock_irqrestore(&priv->lock, flags);
  1897. return;
  1898. }
  1899. #ifdef CONFIG_IWLWIFI_DEBUG
  1900. if (priv->debug_level & (IWL_DL_ISR)) {
  1901. /* NIC fires this, but we don't use it, redundant with WAKEUP */
  1902. if (inta & CSR_INT_BIT_SCD)
  1903. IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
  1904. "the frame/frames.\n");
  1905. /* Alive notification via Rx interrupt will do the real work */
  1906. if (inta & CSR_INT_BIT_ALIVE)
  1907. IWL_DEBUG_ISR(priv, "Alive interrupt\n");
  1908. }
  1909. #endif
  1910. /* Safely ignore these bits for debug checks below */
  1911. inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
  1912. /* Error detected by uCode */
  1913. if (inta & CSR_INT_BIT_SW_ERR) {
  1914. IWL_ERR(priv, "Microcode SW error detected. "
  1915. "Restarting 0x%X.\n", inta);
  1916. iwl_irq_handle_error(priv);
  1917. handled |= CSR_INT_BIT_SW_ERR;
  1918. }
  1919. /* uCode wakes up after power-down sleep */
  1920. if (inta & CSR_INT_BIT_WAKEUP) {
  1921. IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
  1922. iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
  1923. iwl_txq_update_write_ptr(priv, &priv->txq[0]);
  1924. iwl_txq_update_write_ptr(priv, &priv->txq[1]);
  1925. iwl_txq_update_write_ptr(priv, &priv->txq[2]);
  1926. iwl_txq_update_write_ptr(priv, &priv->txq[3]);
  1927. iwl_txq_update_write_ptr(priv, &priv->txq[4]);
  1928. iwl_txq_update_write_ptr(priv, &priv->txq[5]);
  1929. handled |= CSR_INT_BIT_WAKEUP;
  1930. }
  1931. /* All uCode command responses, including Tx command responses,
  1932. * Rx "responses" (frame-received notification), and other
  1933. * notifications from uCode come through here*/
  1934. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
  1935. iwl3945_rx_handle(priv);
  1936. handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
  1937. }
  1938. if (inta & CSR_INT_BIT_FH_TX) {
  1939. IWL_DEBUG_ISR(priv, "Tx interrupt\n");
  1940. iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
  1941. if (!iwl_grab_nic_access(priv)) {
  1942. iwl_write_direct32(priv, FH39_TCSR_CREDIT
  1943. (FH39_SRVC_CHNL), 0x0);
  1944. iwl_release_nic_access(priv);
  1945. }
  1946. handled |= CSR_INT_BIT_FH_TX;
  1947. }
  1948. if (inta & ~handled)
  1949. IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
  1950. if (inta & ~CSR_INI_SET_MASK) {
  1951. IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
  1952. inta & ~CSR_INI_SET_MASK);
  1953. IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
  1954. }
  1955. /* Re-enable all interrupts */
  1956. /* only Re-enable if disabled by irq */
  1957. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  1958. iwl3945_enable_interrupts(priv);
  1959. #ifdef CONFIG_IWLWIFI_DEBUG
  1960. if (priv->debug_level & (IWL_DL_ISR)) {
  1961. inta = iwl_read32(priv, CSR_INT);
  1962. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  1963. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  1964. IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
  1965. "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
  1966. }
  1967. #endif
  1968. spin_unlock_irqrestore(&priv->lock, flags);
  1969. }
  1970. static irqreturn_t iwl3945_isr(int irq, void *data)
  1971. {
  1972. struct iwl_priv *priv = data;
  1973. u32 inta, inta_mask;
  1974. u32 inta_fh;
  1975. if (!priv)
  1976. return IRQ_NONE;
  1977. spin_lock(&priv->lock);
  1978. /* Disable (but don't clear!) interrupts here to avoid
  1979. * back-to-back ISRs and sporadic interrupts from our NIC.
  1980. * If we have something to service, the tasklet will re-enable ints.
  1981. * If we *don't* have something, we'll re-enable before leaving here. */
  1982. inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
  1983. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  1984. /* Discover which interrupts are active/pending */
  1985. inta = iwl_read32(priv, CSR_INT);
  1986. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  1987. /* Ignore interrupt if there's nothing in NIC to service.
  1988. * This may be due to IRQ shared with another device,
  1989. * or due to sporadic interrupts thrown from our NIC. */
  1990. if (!inta && !inta_fh) {
  1991. IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0, inta_fh == 0\n");
  1992. goto none;
  1993. }
  1994. if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
  1995. /* Hardware disappeared */
  1996. IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
  1997. goto unplugged;
  1998. }
  1999. IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  2000. inta, inta_mask, inta_fh);
  2001. inta &= ~CSR_INT_BIT_SCD;
  2002. /* iwl3945_irq_tasklet() will service interrupts and re-enable them */
  2003. if (likely(inta || inta_fh))
  2004. tasklet_schedule(&priv->irq_tasklet);
  2005. unplugged:
  2006. spin_unlock(&priv->lock);
  2007. return IRQ_HANDLED;
  2008. none:
  2009. /* re-enable interrupts here since we don't have anything to service. */
  2010. /* only Re-enable if disabled by irq */
  2011. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  2012. iwl3945_enable_interrupts(priv);
  2013. spin_unlock(&priv->lock);
  2014. return IRQ_NONE;
  2015. }
  2016. static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
  2017. enum ieee80211_band band,
  2018. u8 is_active, u8 n_probes,
  2019. struct iwl3945_scan_channel *scan_ch)
  2020. {
  2021. const struct ieee80211_channel *channels = NULL;
  2022. const struct ieee80211_supported_band *sband;
  2023. const struct iwl_channel_info *ch_info;
  2024. u16 passive_dwell = 0;
  2025. u16 active_dwell = 0;
  2026. int added, i;
  2027. sband = iwl_get_hw_mode(priv, band);
  2028. if (!sband)
  2029. return 0;
  2030. channels = sband->channels;
  2031. active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
  2032. passive_dwell = iwl_get_passive_dwell_time(priv, band);
  2033. if (passive_dwell <= active_dwell)
  2034. passive_dwell = active_dwell + 1;
  2035. for (i = 0, added = 0; i < sband->n_channels; i++) {
  2036. if (channels[i].flags & IEEE80211_CHAN_DISABLED)
  2037. continue;
  2038. scan_ch->channel = channels[i].hw_value;
  2039. ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
  2040. if (!is_channel_valid(ch_info)) {
  2041. IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
  2042. scan_ch->channel);
  2043. continue;
  2044. }
  2045. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  2046. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  2047. /* If passive , set up for auto-switch
  2048. * and use long active_dwell time.
  2049. */
  2050. if (!is_active || is_channel_passive(ch_info) ||
  2051. (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
  2052. scan_ch->type = 0; /* passive */
  2053. if (IWL_UCODE_API(priv->ucode_ver) == 1)
  2054. scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
  2055. } else {
  2056. scan_ch->type = 1; /* active */
  2057. }
  2058. /* Set direct probe bits. These may be used both for active
  2059. * scan channels (probes gets sent right away),
  2060. * or for passive channels (probes get se sent only after
  2061. * hearing clear Rx packet).*/
  2062. if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
  2063. if (n_probes)
  2064. scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
  2065. } else {
  2066. /* uCode v1 does not allow setting direct probe bits on
  2067. * passive channel. */
  2068. if ((scan_ch->type & 1) && n_probes)
  2069. scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
  2070. }
  2071. /* Set txpower levels to defaults */
  2072. scan_ch->tpc.dsp_atten = 110;
  2073. /* scan_pwr_info->tpc.dsp_atten; */
  2074. /*scan_pwr_info->tpc.tx_gain; */
  2075. if (band == IEEE80211_BAND_5GHZ)
  2076. scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
  2077. else {
  2078. scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
  2079. /* NOTE: if we were doing 6Mb OFDM for scans we'd use
  2080. * power level:
  2081. * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
  2082. */
  2083. }
  2084. IWL_DEBUG_SCAN(priv, "Scanning %d [%s %d]\n",
  2085. scan_ch->channel,
  2086. (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
  2087. (scan_ch->type & 1) ?
  2088. active_dwell : passive_dwell);
  2089. scan_ch++;
  2090. added++;
  2091. }
  2092. IWL_DEBUG_SCAN(priv, "total channels to scan %d \n", added);
  2093. return added;
  2094. }
  2095. static void iwl3945_init_hw_rates(struct iwl_priv *priv,
  2096. struct ieee80211_rate *rates)
  2097. {
  2098. int i;
  2099. for (i = 0; i < IWL_RATE_COUNT; i++) {
  2100. rates[i].bitrate = iwl3945_rates[i].ieee * 5;
  2101. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  2102. rates[i].hw_value_short = i;
  2103. rates[i].flags = 0;
  2104. if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
  2105. /*
  2106. * If CCK != 1M then set short preamble rate flag.
  2107. */
  2108. rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
  2109. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  2110. }
  2111. }
  2112. }
  2113. /******************************************************************************
  2114. *
  2115. * uCode download functions
  2116. *
  2117. ******************************************************************************/
  2118. static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
  2119. {
  2120. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
  2121. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
  2122. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  2123. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
  2124. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  2125. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
  2126. }
  2127. /**
  2128. * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
  2129. * looking at all data.
  2130. */
  2131. static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
  2132. {
  2133. u32 val;
  2134. u32 save_len = len;
  2135. int rc = 0;
  2136. u32 errcnt;
  2137. IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
  2138. rc = iwl_grab_nic_access(priv);
  2139. if (rc)
  2140. return rc;
  2141. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  2142. IWL39_RTC_INST_LOWER_BOUND);
  2143. errcnt = 0;
  2144. for (; len > 0; len -= sizeof(u32), image++) {
  2145. /* read data comes through single port, auto-incr addr */
  2146. /* NOTE: Use the debugless read so we don't flood kernel log
  2147. * if IWL_DL_IO is set */
  2148. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  2149. if (val != le32_to_cpu(*image)) {
  2150. IWL_ERR(priv, "uCode INST section is invalid at "
  2151. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  2152. save_len - len, val, le32_to_cpu(*image));
  2153. rc = -EIO;
  2154. errcnt++;
  2155. if (errcnt >= 20)
  2156. break;
  2157. }
  2158. }
  2159. iwl_release_nic_access(priv);
  2160. if (!errcnt)
  2161. IWL_DEBUG_INFO(priv,
  2162. "ucode image in INSTRUCTION memory is good\n");
  2163. return rc;
  2164. }
  2165. /**
  2166. * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
  2167. * using sample data 100 bytes apart. If these sample points are good,
  2168. * it's a pretty good bet that everything between them is good, too.
  2169. */
  2170. static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
  2171. {
  2172. u32 val;
  2173. int rc = 0;
  2174. u32 errcnt = 0;
  2175. u32 i;
  2176. IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
  2177. rc = iwl_grab_nic_access(priv);
  2178. if (rc)
  2179. return rc;
  2180. for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
  2181. /* read data comes through single port, auto-incr addr */
  2182. /* NOTE: Use the debugless read so we don't flood kernel log
  2183. * if IWL_DL_IO is set */
  2184. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  2185. i + IWL39_RTC_INST_LOWER_BOUND);
  2186. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  2187. if (val != le32_to_cpu(*image)) {
  2188. #if 0 /* Enable this if you want to see details */
  2189. IWL_ERR(priv, "uCode INST section is invalid at "
  2190. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  2191. i, val, *image);
  2192. #endif
  2193. rc = -EIO;
  2194. errcnt++;
  2195. if (errcnt >= 3)
  2196. break;
  2197. }
  2198. }
  2199. iwl_release_nic_access(priv);
  2200. return rc;
  2201. }
  2202. /**
  2203. * iwl3945_verify_ucode - determine which instruction image is in SRAM,
  2204. * and verify its contents
  2205. */
  2206. static int iwl3945_verify_ucode(struct iwl_priv *priv)
  2207. {
  2208. __le32 *image;
  2209. u32 len;
  2210. int rc = 0;
  2211. /* Try bootstrap */
  2212. image = (__le32 *)priv->ucode_boot.v_addr;
  2213. len = priv->ucode_boot.len;
  2214. rc = iwl3945_verify_inst_sparse(priv, image, len);
  2215. if (rc == 0) {
  2216. IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
  2217. return 0;
  2218. }
  2219. /* Try initialize */
  2220. image = (__le32 *)priv->ucode_init.v_addr;
  2221. len = priv->ucode_init.len;
  2222. rc = iwl3945_verify_inst_sparse(priv, image, len);
  2223. if (rc == 0) {
  2224. IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
  2225. return 0;
  2226. }
  2227. /* Try runtime/protocol */
  2228. image = (__le32 *)priv->ucode_code.v_addr;
  2229. len = priv->ucode_code.len;
  2230. rc = iwl3945_verify_inst_sparse(priv, image, len);
  2231. if (rc == 0) {
  2232. IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
  2233. return 0;
  2234. }
  2235. IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
  2236. /* Since nothing seems to match, show first several data entries in
  2237. * instruction SRAM, so maybe visual inspection will give a clue.
  2238. * Selection of bootstrap image (vs. other images) is arbitrary. */
  2239. image = (__le32 *)priv->ucode_boot.v_addr;
  2240. len = priv->ucode_boot.len;
  2241. rc = iwl3945_verify_inst_full(priv, image, len);
  2242. return rc;
  2243. }
  2244. static void iwl3945_nic_start(struct iwl_priv *priv)
  2245. {
  2246. /* Remove all resets to allow NIC to operate */
  2247. iwl_write32(priv, CSR_RESET, 0);
  2248. }
  2249. /**
  2250. * iwl3945_read_ucode - Read uCode images from disk file.
  2251. *
  2252. * Copy into buffers for card to fetch via bus-mastering
  2253. */
  2254. static int iwl3945_read_ucode(struct iwl_priv *priv)
  2255. {
  2256. struct iwl_ucode *ucode;
  2257. int ret = -EINVAL, index;
  2258. const struct firmware *ucode_raw;
  2259. /* firmware file name contains uCode/driver compatibility version */
  2260. const char *name_pre = priv->cfg->fw_name_pre;
  2261. const unsigned int api_max = priv->cfg->ucode_api_max;
  2262. const unsigned int api_min = priv->cfg->ucode_api_min;
  2263. char buf[25];
  2264. u8 *src;
  2265. size_t len;
  2266. u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
  2267. /* Ask kernel firmware_class module to get the boot firmware off disk.
  2268. * request_firmware() is synchronous, file is in memory on return. */
  2269. for (index = api_max; index >= api_min; index--) {
  2270. sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
  2271. ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
  2272. if (ret < 0) {
  2273. IWL_ERR(priv, "%s firmware file req failed: %d\n",
  2274. buf, ret);
  2275. if (ret == -ENOENT)
  2276. continue;
  2277. else
  2278. goto error;
  2279. } else {
  2280. if (index < api_max)
  2281. IWL_ERR(priv, "Loaded firmware %s, "
  2282. "which is deprecated. "
  2283. " Please use API v%u instead.\n",
  2284. buf, api_max);
  2285. IWL_DEBUG_INFO(priv, "Got firmware '%s' file "
  2286. "(%zd bytes) from disk\n",
  2287. buf, ucode_raw->size);
  2288. break;
  2289. }
  2290. }
  2291. if (ret < 0)
  2292. goto error;
  2293. /* Make sure that we got at least our header! */
  2294. if (ucode_raw->size < sizeof(*ucode)) {
  2295. IWL_ERR(priv, "File size way too small!\n");
  2296. ret = -EINVAL;
  2297. goto err_release;
  2298. }
  2299. /* Data from ucode file: header followed by uCode images */
  2300. ucode = (void *)ucode_raw->data;
  2301. priv->ucode_ver = le32_to_cpu(ucode->ver);
  2302. api_ver = IWL_UCODE_API(priv->ucode_ver);
  2303. inst_size = le32_to_cpu(ucode->inst_size);
  2304. data_size = le32_to_cpu(ucode->data_size);
  2305. init_size = le32_to_cpu(ucode->init_size);
  2306. init_data_size = le32_to_cpu(ucode->init_data_size);
  2307. boot_size = le32_to_cpu(ucode->boot_size);
  2308. /* api_ver should match the api version forming part of the
  2309. * firmware filename ... but we don't check for that and only rely
  2310. * on the API version read from firware header from here on forward */
  2311. if (api_ver < api_min || api_ver > api_max) {
  2312. IWL_ERR(priv, "Driver unable to support your firmware API. "
  2313. "Driver supports v%u, firmware is v%u.\n",
  2314. api_max, api_ver);
  2315. priv->ucode_ver = 0;
  2316. ret = -EINVAL;
  2317. goto err_release;
  2318. }
  2319. if (api_ver != api_max)
  2320. IWL_ERR(priv, "Firmware has old API version. Expected %u, "
  2321. "got %u. New firmware can be obtained "
  2322. "from http://www.intellinuxwireless.org.\n",
  2323. api_max, api_ver);
  2324. IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
  2325. IWL_UCODE_MAJOR(priv->ucode_ver),
  2326. IWL_UCODE_MINOR(priv->ucode_ver),
  2327. IWL_UCODE_API(priv->ucode_ver),
  2328. IWL_UCODE_SERIAL(priv->ucode_ver));
  2329. IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
  2330. priv->ucode_ver);
  2331. IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
  2332. inst_size);
  2333. IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
  2334. data_size);
  2335. IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
  2336. init_size);
  2337. IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
  2338. init_data_size);
  2339. IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
  2340. boot_size);
  2341. /* Verify size of file vs. image size info in file's header */
  2342. if (ucode_raw->size < sizeof(*ucode) +
  2343. inst_size + data_size + init_size +
  2344. init_data_size + boot_size) {
  2345. IWL_DEBUG_INFO(priv, "uCode file size %zd too small\n",
  2346. ucode_raw->size);
  2347. ret = -EINVAL;
  2348. goto err_release;
  2349. }
  2350. /* Verify that uCode images will fit in card's SRAM */
  2351. if (inst_size > IWL39_MAX_INST_SIZE) {
  2352. IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
  2353. inst_size);
  2354. ret = -EINVAL;
  2355. goto err_release;
  2356. }
  2357. if (data_size > IWL39_MAX_DATA_SIZE) {
  2358. IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
  2359. data_size);
  2360. ret = -EINVAL;
  2361. goto err_release;
  2362. }
  2363. if (init_size > IWL39_MAX_INST_SIZE) {
  2364. IWL_DEBUG_INFO(priv,
  2365. "uCode init instr len %d too large to fit in\n",
  2366. init_size);
  2367. ret = -EINVAL;
  2368. goto err_release;
  2369. }
  2370. if (init_data_size > IWL39_MAX_DATA_SIZE) {
  2371. IWL_DEBUG_INFO(priv,
  2372. "uCode init data len %d too large to fit in\n",
  2373. init_data_size);
  2374. ret = -EINVAL;
  2375. goto err_release;
  2376. }
  2377. if (boot_size > IWL39_MAX_BSM_SIZE) {
  2378. IWL_DEBUG_INFO(priv,
  2379. "uCode boot instr len %d too large to fit in\n",
  2380. boot_size);
  2381. ret = -EINVAL;
  2382. goto err_release;
  2383. }
  2384. /* Allocate ucode buffers for card's bus-master loading ... */
  2385. /* Runtime instructions and 2 copies of data:
  2386. * 1) unmodified from disk
  2387. * 2) backup cache for save/restore during power-downs */
  2388. priv->ucode_code.len = inst_size;
  2389. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
  2390. priv->ucode_data.len = data_size;
  2391. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
  2392. priv->ucode_data_backup.len = data_size;
  2393. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  2394. if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
  2395. !priv->ucode_data_backup.v_addr)
  2396. goto err_pci_alloc;
  2397. /* Initialization instructions and data */
  2398. if (init_size && init_data_size) {
  2399. priv->ucode_init.len = init_size;
  2400. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
  2401. priv->ucode_init_data.len = init_data_size;
  2402. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  2403. if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
  2404. goto err_pci_alloc;
  2405. }
  2406. /* Bootstrap (instructions only, no data) */
  2407. if (boot_size) {
  2408. priv->ucode_boot.len = boot_size;
  2409. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
  2410. if (!priv->ucode_boot.v_addr)
  2411. goto err_pci_alloc;
  2412. }
  2413. /* Copy images into buffers for card's bus-master reads ... */
  2414. /* Runtime instructions (first block of data in file) */
  2415. src = &ucode->data[0];
  2416. len = priv->ucode_code.len;
  2417. IWL_DEBUG_INFO(priv,
  2418. "Copying (but not loading) uCode instr len %zd\n", len);
  2419. memcpy(priv->ucode_code.v_addr, src, len);
  2420. IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
  2421. priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
  2422. /* Runtime data (2nd block)
  2423. * NOTE: Copy into backup buffer will be done in iwl3945_up() */
  2424. src = &ucode->data[inst_size];
  2425. len = priv->ucode_data.len;
  2426. IWL_DEBUG_INFO(priv,
  2427. "Copying (but not loading) uCode data len %zd\n", len);
  2428. memcpy(priv->ucode_data.v_addr, src, len);
  2429. memcpy(priv->ucode_data_backup.v_addr, src, len);
  2430. /* Initialization instructions (3rd block) */
  2431. if (init_size) {
  2432. src = &ucode->data[inst_size + data_size];
  2433. len = priv->ucode_init.len;
  2434. IWL_DEBUG_INFO(priv,
  2435. "Copying (but not loading) init instr len %zd\n", len);
  2436. memcpy(priv->ucode_init.v_addr, src, len);
  2437. }
  2438. /* Initialization data (4th block) */
  2439. if (init_data_size) {
  2440. src = &ucode->data[inst_size + data_size + init_size];
  2441. len = priv->ucode_init_data.len;
  2442. IWL_DEBUG_INFO(priv,
  2443. "Copying (but not loading) init data len %zd\n", len);
  2444. memcpy(priv->ucode_init_data.v_addr, src, len);
  2445. }
  2446. /* Bootstrap instructions (5th block) */
  2447. src = &ucode->data[inst_size + data_size + init_size + init_data_size];
  2448. len = priv->ucode_boot.len;
  2449. IWL_DEBUG_INFO(priv,
  2450. "Copying (but not loading) boot instr len %zd\n", len);
  2451. memcpy(priv->ucode_boot.v_addr, src, len);
  2452. /* We have our copies now, allow OS release its copies */
  2453. release_firmware(ucode_raw);
  2454. return 0;
  2455. err_pci_alloc:
  2456. IWL_ERR(priv, "failed to allocate pci memory\n");
  2457. ret = -ENOMEM;
  2458. iwl3945_dealloc_ucode_pci(priv);
  2459. err_release:
  2460. release_firmware(ucode_raw);
  2461. error:
  2462. return ret;
  2463. }
  2464. /**
  2465. * iwl3945_set_ucode_ptrs - Set uCode address location
  2466. *
  2467. * Tell initialization uCode where to find runtime uCode.
  2468. *
  2469. * BSM registers initially contain pointers to initialization uCode.
  2470. * We need to replace them to load runtime uCode inst and data,
  2471. * and to save runtime data when powering down.
  2472. */
  2473. static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
  2474. {
  2475. dma_addr_t pinst;
  2476. dma_addr_t pdata;
  2477. int rc = 0;
  2478. unsigned long flags;
  2479. /* bits 31:0 for 3945 */
  2480. pinst = priv->ucode_code.p_addr;
  2481. pdata = priv->ucode_data_backup.p_addr;
  2482. spin_lock_irqsave(&priv->lock, flags);
  2483. rc = iwl_grab_nic_access(priv);
  2484. if (rc) {
  2485. spin_unlock_irqrestore(&priv->lock, flags);
  2486. return rc;
  2487. }
  2488. /* Tell bootstrap uCode where to find image to load */
  2489. iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
  2490. iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
  2491. iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
  2492. priv->ucode_data.len);
  2493. /* Inst byte count must be last to set up, bit 31 signals uCode
  2494. * that all new ptr/size info is in place */
  2495. iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
  2496. priv->ucode_code.len | BSM_DRAM_INST_LOAD);
  2497. iwl_release_nic_access(priv);
  2498. spin_unlock_irqrestore(&priv->lock, flags);
  2499. IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n");
  2500. return rc;
  2501. }
  2502. /**
  2503. * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
  2504. *
  2505. * Called after REPLY_ALIVE notification received from "initialize" uCode.
  2506. *
  2507. * Tell "initialize" uCode to go ahead and load the runtime uCode.
  2508. */
  2509. static void iwl3945_init_alive_start(struct iwl_priv *priv)
  2510. {
  2511. /* Check alive response for "valid" sign from uCode */
  2512. if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
  2513. /* We had an error bringing up the hardware, so take it
  2514. * all the way back down so we can try again */
  2515. IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
  2516. goto restart;
  2517. }
  2518. /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
  2519. * This is a paranoid check, because we would not have gotten the
  2520. * "initialize" alive if code weren't properly loaded. */
  2521. if (iwl3945_verify_ucode(priv)) {
  2522. /* Runtime instruction load was bad;
  2523. * take it all the way back down so we can try again */
  2524. IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
  2525. goto restart;
  2526. }
  2527. /* Send pointers to protocol/runtime uCode image ... init code will
  2528. * load and launch runtime uCode, which will send us another "Alive"
  2529. * notification. */
  2530. IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
  2531. if (iwl3945_set_ucode_ptrs(priv)) {
  2532. /* Runtime instruction load won't happen;
  2533. * take it all the way back down so we can try again */
  2534. IWL_DEBUG_INFO(priv, "Couldn't set up uCode pointers.\n");
  2535. goto restart;
  2536. }
  2537. return;
  2538. restart:
  2539. queue_work(priv->workqueue, &priv->restart);
  2540. }
  2541. /* temporary */
  2542. static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw,
  2543. struct sk_buff *skb);
  2544. /**
  2545. * iwl3945_alive_start - called after REPLY_ALIVE notification received
  2546. * from protocol/runtime uCode (initialization uCode's
  2547. * Alive gets handled by iwl3945_init_alive_start()).
  2548. */
  2549. static void iwl3945_alive_start(struct iwl_priv *priv)
  2550. {
  2551. int rc = 0;
  2552. int thermal_spin = 0;
  2553. u32 rfkill;
  2554. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  2555. if (priv->card_alive.is_valid != UCODE_VALID_OK) {
  2556. /* We had an error bringing up the hardware, so take it
  2557. * all the way back down so we can try again */
  2558. IWL_DEBUG_INFO(priv, "Alive failed.\n");
  2559. goto restart;
  2560. }
  2561. /* Initialize uCode has loaded Runtime uCode ... verify inst image.
  2562. * This is a paranoid check, because we would not have gotten the
  2563. * "runtime" alive if code weren't properly loaded. */
  2564. if (iwl3945_verify_ucode(priv)) {
  2565. /* Runtime instruction load was bad;
  2566. * take it all the way back down so we can try again */
  2567. IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
  2568. goto restart;
  2569. }
  2570. iwl3945_clear_stations_table(priv);
  2571. rc = iwl_grab_nic_access(priv);
  2572. if (rc) {
  2573. IWL_WARN(priv, "Can not read RFKILL status from adapter\n");
  2574. return;
  2575. }
  2576. rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
  2577. IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill);
  2578. iwl_release_nic_access(priv);
  2579. if (rfkill & 0x1) {
  2580. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2581. /* if RFKILL is not on, then wait for thermal
  2582. * sensor in adapter to kick in */
  2583. while (iwl3945_hw_get_temperature(priv) == 0) {
  2584. thermal_spin++;
  2585. udelay(10);
  2586. }
  2587. if (thermal_spin)
  2588. IWL_DEBUG_INFO(priv, "Thermal calibration took %dus\n",
  2589. thermal_spin * 10);
  2590. } else
  2591. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2592. /* After the ALIVE response, we can send commands to 3945 uCode */
  2593. set_bit(STATUS_ALIVE, &priv->status);
  2594. /* Clear out the uCode error bit if it is set */
  2595. clear_bit(STATUS_FW_ERROR, &priv->status);
  2596. if (iwl_is_rfkill(priv))
  2597. return;
  2598. ieee80211_wake_queues(priv->hw);
  2599. priv->active_rate = priv->rates_mask;
  2600. priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
  2601. iwl_power_update_mode(priv, false);
  2602. if (iwl_is_associated(priv)) {
  2603. struct iwl3945_rxon_cmd *active_rxon =
  2604. (struct iwl3945_rxon_cmd *)(&priv->active_rxon);
  2605. memcpy(&priv->staging_rxon, &priv->active_rxon,
  2606. sizeof(priv->staging_rxon));
  2607. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2608. } else {
  2609. /* Initialize our rx_config data */
  2610. iwl_connection_init_rx_config(priv, priv->iw_mode);
  2611. }
  2612. /* Configure Bluetooth device coexistence support */
  2613. iwl_send_bt_config(priv);
  2614. /* Configure the adapter for unassociated operation */
  2615. iwl3945_commit_rxon(priv);
  2616. iwl3945_reg_txpower_periodic(priv);
  2617. iwl3945_led_register(priv);
  2618. IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
  2619. set_bit(STATUS_READY, &priv->status);
  2620. wake_up_interruptible(&priv->wait_command_queue);
  2621. if (priv->error_recovering)
  2622. iwl3945_error_recovery(priv);
  2623. /* reassociate for ADHOC mode */
  2624. if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
  2625. struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
  2626. priv->vif);
  2627. if (beacon)
  2628. iwl3945_mac_beacon_update(priv->hw, beacon);
  2629. }
  2630. return;
  2631. restart:
  2632. queue_work(priv->workqueue, &priv->restart);
  2633. }
  2634. static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
  2635. static void __iwl3945_down(struct iwl_priv *priv)
  2636. {
  2637. unsigned long flags;
  2638. int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
  2639. struct ieee80211_conf *conf = NULL;
  2640. IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
  2641. conf = ieee80211_get_hw_conf(priv->hw);
  2642. if (!exit_pending)
  2643. set_bit(STATUS_EXIT_PENDING, &priv->status);
  2644. iwl3945_led_unregister(priv);
  2645. iwl3945_clear_stations_table(priv);
  2646. /* Unblock any waiting calls */
  2647. wake_up_interruptible_all(&priv->wait_command_queue);
  2648. /* Wipe out the EXIT_PENDING status bit if we are not actually
  2649. * exiting the module */
  2650. if (!exit_pending)
  2651. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  2652. /* stop and reset the on-board processor */
  2653. iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  2654. /* tell the device to stop sending interrupts */
  2655. spin_lock_irqsave(&priv->lock, flags);
  2656. iwl3945_disable_interrupts(priv);
  2657. spin_unlock_irqrestore(&priv->lock, flags);
  2658. iwl_synchronize_irq(priv);
  2659. if (priv->mac80211_registered)
  2660. ieee80211_stop_queues(priv->hw);
  2661. /* If we have not previously called iwl3945_init() then
  2662. * clear all bits but the RF Kill and SUSPEND bits and return */
  2663. if (!iwl_is_init(priv)) {
  2664. priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  2665. STATUS_RF_KILL_HW |
  2666. test_bit(STATUS_RF_KILL_SW, &priv->status) <<
  2667. STATUS_RF_KILL_SW |
  2668. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  2669. STATUS_GEO_CONFIGURED |
  2670. test_bit(STATUS_IN_SUSPEND, &priv->status) <<
  2671. STATUS_IN_SUSPEND |
  2672. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  2673. STATUS_EXIT_PENDING;
  2674. goto exit;
  2675. }
  2676. /* ...otherwise clear out all the status bits but the RF Kill and
  2677. * SUSPEND bits and continue taking the NIC down. */
  2678. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  2679. STATUS_RF_KILL_HW |
  2680. test_bit(STATUS_RF_KILL_SW, &priv->status) <<
  2681. STATUS_RF_KILL_SW |
  2682. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  2683. STATUS_GEO_CONFIGURED |
  2684. test_bit(STATUS_IN_SUSPEND, &priv->status) <<
  2685. STATUS_IN_SUSPEND |
  2686. test_bit(STATUS_FW_ERROR, &priv->status) <<
  2687. STATUS_FW_ERROR |
  2688. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  2689. STATUS_EXIT_PENDING;
  2690. priv->cfg->ops->lib->apm_ops.reset(priv);
  2691. spin_lock_irqsave(&priv->lock, flags);
  2692. iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  2693. spin_unlock_irqrestore(&priv->lock, flags);
  2694. iwl3945_hw_txq_ctx_stop(priv);
  2695. iwl3945_hw_rxq_stop(priv);
  2696. spin_lock_irqsave(&priv->lock, flags);
  2697. if (!iwl_grab_nic_access(priv)) {
  2698. iwl_write_prph(priv, APMG_CLK_DIS_REG,
  2699. APMG_CLK_VAL_DMA_CLK_RQT);
  2700. iwl_release_nic_access(priv);
  2701. }
  2702. spin_unlock_irqrestore(&priv->lock, flags);
  2703. udelay(5);
  2704. if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
  2705. priv->cfg->ops->lib->apm_ops.stop(priv);
  2706. else
  2707. priv->cfg->ops->lib->apm_ops.reset(priv);
  2708. exit:
  2709. memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
  2710. if (priv->ibss_beacon)
  2711. dev_kfree_skb(priv->ibss_beacon);
  2712. priv->ibss_beacon = NULL;
  2713. /* clear out any free frames */
  2714. iwl3945_clear_free_frames(priv);
  2715. }
  2716. static void iwl3945_down(struct iwl_priv *priv)
  2717. {
  2718. mutex_lock(&priv->mutex);
  2719. __iwl3945_down(priv);
  2720. mutex_unlock(&priv->mutex);
  2721. iwl3945_cancel_deferred_work(priv);
  2722. }
  2723. #define MAX_HW_RESTARTS 5
  2724. static int __iwl3945_up(struct iwl_priv *priv)
  2725. {
  2726. int rc, i;
  2727. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  2728. IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
  2729. return -EIO;
  2730. }
  2731. if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
  2732. IWL_WARN(priv, "Radio disabled by SW RF kill (module "
  2733. "parameter)\n");
  2734. return -ENODEV;
  2735. }
  2736. if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
  2737. IWL_ERR(priv, "ucode not available for device bring up\n");
  2738. return -EIO;
  2739. }
  2740. /* If platform's RF_KILL switch is NOT set to KILL */
  2741. if (iwl_read32(priv, CSR_GP_CNTRL) &
  2742. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  2743. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2744. else {
  2745. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2746. if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
  2747. IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
  2748. return -ENODEV;
  2749. }
  2750. }
  2751. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  2752. rc = iwl3945_hw_nic_init(priv);
  2753. if (rc) {
  2754. IWL_ERR(priv, "Unable to int nic\n");
  2755. return rc;
  2756. }
  2757. /* make sure rfkill handshake bits are cleared */
  2758. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2759. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  2760. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  2761. /* clear (again), then enable host interrupts */
  2762. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  2763. iwl3945_enable_interrupts(priv);
  2764. /* really make sure rfkill handshake bits are cleared */
  2765. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2766. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2767. /* Copy original ucode data image from disk into backup cache.
  2768. * This will be used to initialize the on-board processor's
  2769. * data SRAM for a clean start when the runtime program first loads. */
  2770. memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
  2771. priv->ucode_data.len);
  2772. /* We return success when we resume from suspend and rf_kill is on. */
  2773. if (test_bit(STATUS_RF_KILL_HW, &priv->status))
  2774. return 0;
  2775. for (i = 0; i < MAX_HW_RESTARTS; i++) {
  2776. iwl3945_clear_stations_table(priv);
  2777. /* load bootstrap state machine,
  2778. * load bootstrap program into processor's memory,
  2779. * prepare to load the "initialize" uCode */
  2780. priv->cfg->ops->lib->load_ucode(priv);
  2781. if (rc) {
  2782. IWL_ERR(priv,
  2783. "Unable to set up bootstrap uCode: %d\n", rc);
  2784. continue;
  2785. }
  2786. /* start card; "initialize" will load runtime ucode */
  2787. iwl3945_nic_start(priv);
  2788. IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
  2789. return 0;
  2790. }
  2791. set_bit(STATUS_EXIT_PENDING, &priv->status);
  2792. __iwl3945_down(priv);
  2793. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  2794. /* tried to restart and config the device for as long as our
  2795. * patience could withstand */
  2796. IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
  2797. return -EIO;
  2798. }
  2799. /*****************************************************************************
  2800. *
  2801. * Workqueue callbacks
  2802. *
  2803. *****************************************************************************/
  2804. static void iwl3945_bg_init_alive_start(struct work_struct *data)
  2805. {
  2806. struct iwl_priv *priv =
  2807. container_of(data, struct iwl_priv, init_alive_start.work);
  2808. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2809. return;
  2810. mutex_lock(&priv->mutex);
  2811. iwl3945_init_alive_start(priv);
  2812. mutex_unlock(&priv->mutex);
  2813. }
  2814. static void iwl3945_bg_alive_start(struct work_struct *data)
  2815. {
  2816. struct iwl_priv *priv =
  2817. container_of(data, struct iwl_priv, alive_start.work);
  2818. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2819. return;
  2820. mutex_lock(&priv->mutex);
  2821. iwl3945_alive_start(priv);
  2822. mutex_unlock(&priv->mutex);
  2823. }
  2824. static void iwl3945_rfkill_poll(struct work_struct *data)
  2825. {
  2826. struct iwl_priv *priv =
  2827. container_of(data, struct iwl_priv, rfkill_poll.work);
  2828. unsigned long status = priv->status;
  2829. if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  2830. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2831. else
  2832. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2833. if (test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status))
  2834. queue_work(priv->workqueue, &priv->rf_kill);
  2835. queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
  2836. round_jiffies_relative(2 * HZ));
  2837. }
  2838. #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
  2839. static void iwl3945_bg_request_scan(struct work_struct *data)
  2840. {
  2841. struct iwl_priv *priv =
  2842. container_of(data, struct iwl_priv, request_scan);
  2843. struct iwl_host_cmd cmd = {
  2844. .id = REPLY_SCAN_CMD,
  2845. .len = sizeof(struct iwl3945_scan_cmd),
  2846. .meta.flags = CMD_SIZE_HUGE,
  2847. };
  2848. int rc = 0;
  2849. struct iwl3945_scan_cmd *scan;
  2850. struct ieee80211_conf *conf = NULL;
  2851. u8 n_probes = 2;
  2852. enum ieee80211_band band;
  2853. DECLARE_SSID_BUF(ssid);
  2854. conf = ieee80211_get_hw_conf(priv->hw);
  2855. mutex_lock(&priv->mutex);
  2856. if (!iwl_is_ready(priv)) {
  2857. IWL_WARN(priv, "request scan called when driver not ready.\n");
  2858. goto done;
  2859. }
  2860. /* Make sure the scan wasn't canceled before this queued work
  2861. * was given the chance to run... */
  2862. if (!test_bit(STATUS_SCANNING, &priv->status))
  2863. goto done;
  2864. /* This should never be called or scheduled if there is currently
  2865. * a scan active in the hardware. */
  2866. if (test_bit(STATUS_SCAN_HW, &priv->status)) {
  2867. IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests "
  2868. "Ignoring second request.\n");
  2869. rc = -EIO;
  2870. goto done;
  2871. }
  2872. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  2873. IWL_DEBUG_SCAN(priv, "Aborting scan due to device shutdown\n");
  2874. goto done;
  2875. }
  2876. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  2877. IWL_DEBUG_HC(priv,
  2878. "Scan request while abort pending. Queuing.\n");
  2879. goto done;
  2880. }
  2881. if (iwl_is_rfkill(priv)) {
  2882. IWL_DEBUG_HC(priv, "Aborting scan due to RF Kill activation\n");
  2883. goto done;
  2884. }
  2885. if (!test_bit(STATUS_READY, &priv->status)) {
  2886. IWL_DEBUG_HC(priv,
  2887. "Scan request while uninitialized. Queuing.\n");
  2888. goto done;
  2889. }
  2890. if (!priv->scan_bands) {
  2891. IWL_DEBUG_HC(priv, "Aborting scan due to no requested bands\n");
  2892. goto done;
  2893. }
  2894. if (!priv->scan) {
  2895. priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
  2896. IWL_MAX_SCAN_SIZE, GFP_KERNEL);
  2897. if (!priv->scan) {
  2898. rc = -ENOMEM;
  2899. goto done;
  2900. }
  2901. }
  2902. scan = priv->scan;
  2903. memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
  2904. scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
  2905. scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
  2906. if (iwl_is_associated(priv)) {
  2907. u16 interval = 0;
  2908. u32 extra;
  2909. u32 suspend_time = 100;
  2910. u32 scan_suspend_time = 100;
  2911. unsigned long flags;
  2912. IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
  2913. spin_lock_irqsave(&priv->lock, flags);
  2914. interval = priv->beacon_int;
  2915. spin_unlock_irqrestore(&priv->lock, flags);
  2916. scan->suspend_time = 0;
  2917. scan->max_out_time = cpu_to_le32(200 * 1024);
  2918. if (!interval)
  2919. interval = suspend_time;
  2920. /*
  2921. * suspend time format:
  2922. * 0-19: beacon interval in usec (time before exec.)
  2923. * 20-23: 0
  2924. * 24-31: number of beacons (suspend between channels)
  2925. */
  2926. extra = (suspend_time / interval) << 24;
  2927. scan_suspend_time = 0xFF0FFFFF &
  2928. (extra | ((suspend_time % interval) * 1024));
  2929. scan->suspend_time = cpu_to_le32(scan_suspend_time);
  2930. IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
  2931. scan_suspend_time, interval);
  2932. }
  2933. /* We should add the ability for user to lock to PASSIVE ONLY */
  2934. if (priv->one_direct_scan) {
  2935. IWL_DEBUG_SCAN(priv, "Kicking off one direct scan for '%s'\n",
  2936. print_ssid(ssid, priv->direct_ssid,
  2937. priv->direct_ssid_len));
  2938. scan->direct_scan[0].id = WLAN_EID_SSID;
  2939. scan->direct_scan[0].len = priv->direct_ssid_len;
  2940. memcpy(scan->direct_scan[0].ssid,
  2941. priv->direct_ssid, priv->direct_ssid_len);
  2942. n_probes++;
  2943. } else
  2944. IWL_DEBUG_SCAN(priv, "Kicking off one indirect scan.\n");
  2945. /* We don't build a direct scan probe request; the uCode will do
  2946. * that based on the direct_mask added to each channel entry */
  2947. scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
  2948. scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
  2949. scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  2950. /* flags + rate selection */
  2951. if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
  2952. scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
  2953. scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
  2954. scan->good_CRC_th = 0;
  2955. band = IEEE80211_BAND_2GHZ;
  2956. } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
  2957. scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
  2958. scan->good_CRC_th = IWL_GOOD_CRC_TH;
  2959. band = IEEE80211_BAND_5GHZ;
  2960. } else {
  2961. IWL_WARN(priv, "Invalid scan band count\n");
  2962. goto done;
  2963. }
  2964. scan->tx_cmd.len = cpu_to_le16(
  2965. iwl_fill_probe_req(priv, band,
  2966. (struct ieee80211_mgmt *)scan->data,
  2967. IWL_MAX_SCAN_SIZE - sizeof(*scan)));
  2968. /* select Rx antennas */
  2969. scan->flags |= iwl3945_get_antenna_flags(priv);
  2970. if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
  2971. scan->filter_flags = RXON_FILTER_PROMISC_MSK;
  2972. scan->channel_count =
  2973. iwl3945_get_channels_for_scan(priv, band, 1, /* active */
  2974. n_probes,
  2975. (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
  2976. if (scan->channel_count == 0) {
  2977. IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
  2978. goto done;
  2979. }
  2980. cmd.len += le16_to_cpu(scan->tx_cmd.len) +
  2981. scan->channel_count * sizeof(struct iwl3945_scan_channel);
  2982. cmd.data = scan;
  2983. scan->len = cpu_to_le16(cmd.len);
  2984. set_bit(STATUS_SCAN_HW, &priv->status);
  2985. rc = iwl_send_cmd_sync(priv, &cmd);
  2986. if (rc)
  2987. goto done;
  2988. queue_delayed_work(priv->workqueue, &priv->scan_check,
  2989. IWL_SCAN_CHECK_WATCHDOG);
  2990. mutex_unlock(&priv->mutex);
  2991. return;
  2992. done:
  2993. /* can not perform scan make sure we clear scanning
  2994. * bits from status so next scan request can be performed.
  2995. * if we dont clear scanning status bit here all next scan
  2996. * will fail
  2997. */
  2998. clear_bit(STATUS_SCAN_HW, &priv->status);
  2999. clear_bit(STATUS_SCANNING, &priv->status);
  3000. /* inform mac80211 scan aborted */
  3001. queue_work(priv->workqueue, &priv->scan_completed);
  3002. mutex_unlock(&priv->mutex);
  3003. }
  3004. static void iwl3945_bg_up(struct work_struct *data)
  3005. {
  3006. struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
  3007. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3008. return;
  3009. mutex_lock(&priv->mutex);
  3010. __iwl3945_up(priv);
  3011. mutex_unlock(&priv->mutex);
  3012. iwl_rfkill_set_hw_state(priv);
  3013. }
  3014. static void iwl3945_bg_restart(struct work_struct *data)
  3015. {
  3016. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  3017. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3018. return;
  3019. iwl3945_down(priv);
  3020. queue_work(priv->workqueue, &priv->up);
  3021. }
  3022. static void iwl3945_bg_rx_replenish(struct work_struct *data)
  3023. {
  3024. struct iwl_priv *priv =
  3025. container_of(data, struct iwl_priv, rx_replenish);
  3026. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3027. return;
  3028. mutex_lock(&priv->mutex);
  3029. iwl3945_rx_replenish(priv);
  3030. mutex_unlock(&priv->mutex);
  3031. }
  3032. #define IWL_DELAY_NEXT_SCAN (HZ*2)
  3033. static void iwl3945_post_associate(struct iwl_priv *priv)
  3034. {
  3035. int rc = 0;
  3036. struct ieee80211_conf *conf = NULL;
  3037. if (priv->iw_mode == NL80211_IFTYPE_AP) {
  3038. IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
  3039. return;
  3040. }
  3041. IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
  3042. priv->assoc_id, priv->active_rxon.bssid_addr);
  3043. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3044. return;
  3045. if (!priv->vif || !priv->is_open)
  3046. return;
  3047. iwl_scan_cancel_timeout(priv, 200);
  3048. conf = ieee80211_get_hw_conf(priv->hw);
  3049. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3050. iwl3945_commit_rxon(priv);
  3051. memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
  3052. iwl3945_setup_rxon_timing(priv);
  3053. rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
  3054. sizeof(priv->rxon_timing), &priv->rxon_timing);
  3055. if (rc)
  3056. IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
  3057. "Attempting to continue.\n");
  3058. priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  3059. priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
  3060. IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
  3061. priv->assoc_id, priv->beacon_int);
  3062. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  3063. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  3064. else
  3065. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  3066. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
  3067. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
  3068. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  3069. else
  3070. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  3071. if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
  3072. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  3073. }
  3074. iwl3945_commit_rxon(priv);
  3075. switch (priv->iw_mode) {
  3076. case NL80211_IFTYPE_STATION:
  3077. iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
  3078. break;
  3079. case NL80211_IFTYPE_ADHOC:
  3080. priv->assoc_id = 1;
  3081. iwl3945_add_station(priv, priv->bssid, 0, 0);
  3082. iwl3945_sync_sta(priv, IWL_STA_ID,
  3083. (priv->band == IEEE80211_BAND_5GHZ) ?
  3084. IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
  3085. CMD_ASYNC);
  3086. iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
  3087. iwl3945_send_beacon_cmd(priv);
  3088. break;
  3089. default:
  3090. IWL_ERR(priv, "%s Should not be called in %d mode\n",
  3091. __func__, priv->iw_mode);
  3092. break;
  3093. }
  3094. iwl3945_activate_qos(priv, 0);
  3095. /* we have just associated, don't start scan too early */
  3096. priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
  3097. }
  3098. static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed);
  3099. /*****************************************************************************
  3100. *
  3101. * mac80211 entry point functions
  3102. *
  3103. *****************************************************************************/
  3104. #define UCODE_READY_TIMEOUT (2 * HZ)
  3105. static int iwl3945_mac_start(struct ieee80211_hw *hw)
  3106. {
  3107. struct iwl_priv *priv = hw->priv;
  3108. int ret;
  3109. IWL_DEBUG_MAC80211(priv, "enter\n");
  3110. /* we should be verifying the device is ready to be opened */
  3111. mutex_lock(&priv->mutex);
  3112. memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
  3113. /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
  3114. * ucode filename and max sizes are card-specific. */
  3115. if (!priv->ucode_code.len) {
  3116. ret = iwl3945_read_ucode(priv);
  3117. if (ret) {
  3118. IWL_ERR(priv, "Could not read microcode: %d\n", ret);
  3119. mutex_unlock(&priv->mutex);
  3120. goto out_release_irq;
  3121. }
  3122. }
  3123. ret = __iwl3945_up(priv);
  3124. mutex_unlock(&priv->mutex);
  3125. iwl_rfkill_set_hw_state(priv);
  3126. if (ret)
  3127. goto out_release_irq;
  3128. IWL_DEBUG_INFO(priv, "Start UP work.\n");
  3129. if (test_bit(STATUS_IN_SUSPEND, &priv->status))
  3130. return 0;
  3131. /* Wait for START_ALIVE from ucode. Otherwise callbacks from
  3132. * mac80211 will not be run successfully. */
  3133. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  3134. test_bit(STATUS_READY, &priv->status),
  3135. UCODE_READY_TIMEOUT);
  3136. if (!ret) {
  3137. if (!test_bit(STATUS_READY, &priv->status)) {
  3138. IWL_ERR(priv,
  3139. "Wait for START_ALIVE timeout after %dms.\n",
  3140. jiffies_to_msecs(UCODE_READY_TIMEOUT));
  3141. ret = -ETIMEDOUT;
  3142. goto out_release_irq;
  3143. }
  3144. }
  3145. /* ucode is running and will send rfkill notifications,
  3146. * no need to poll the killswitch state anymore */
  3147. cancel_delayed_work(&priv->rfkill_poll);
  3148. priv->is_open = 1;
  3149. IWL_DEBUG_MAC80211(priv, "leave\n");
  3150. return 0;
  3151. out_release_irq:
  3152. priv->is_open = 0;
  3153. IWL_DEBUG_MAC80211(priv, "leave - failed\n");
  3154. return ret;
  3155. }
  3156. static void iwl3945_mac_stop(struct ieee80211_hw *hw)
  3157. {
  3158. struct iwl_priv *priv = hw->priv;
  3159. IWL_DEBUG_MAC80211(priv, "enter\n");
  3160. if (!priv->is_open) {
  3161. IWL_DEBUG_MAC80211(priv, "leave - skip\n");
  3162. return;
  3163. }
  3164. priv->is_open = 0;
  3165. if (iwl_is_ready_rf(priv)) {
  3166. /* stop mac, cancel any scan request and clear
  3167. * RXON_FILTER_ASSOC_MSK BIT
  3168. */
  3169. mutex_lock(&priv->mutex);
  3170. iwl_scan_cancel_timeout(priv, 100);
  3171. mutex_unlock(&priv->mutex);
  3172. }
  3173. iwl3945_down(priv);
  3174. flush_workqueue(priv->workqueue);
  3175. /* start polling the killswitch state again */
  3176. queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
  3177. round_jiffies_relative(2 * HZ));
  3178. IWL_DEBUG_MAC80211(priv, "leave\n");
  3179. }
  3180. static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  3181. {
  3182. struct iwl_priv *priv = hw->priv;
  3183. IWL_DEBUG_MAC80211(priv, "enter\n");
  3184. IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  3185. ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
  3186. if (iwl3945_tx_skb(priv, skb))
  3187. dev_kfree_skb_any(skb);
  3188. IWL_DEBUG_MAC80211(priv, "leave\n");
  3189. return NETDEV_TX_OK;
  3190. }
  3191. static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
  3192. struct ieee80211_if_init_conf *conf)
  3193. {
  3194. struct iwl_priv *priv = hw->priv;
  3195. unsigned long flags;
  3196. IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
  3197. if (priv->vif) {
  3198. IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
  3199. return -EOPNOTSUPP;
  3200. }
  3201. spin_lock_irqsave(&priv->lock, flags);
  3202. priv->vif = conf->vif;
  3203. priv->iw_mode = conf->type;
  3204. spin_unlock_irqrestore(&priv->lock, flags);
  3205. mutex_lock(&priv->mutex);
  3206. if (conf->mac_addr) {
  3207. IWL_DEBUG_MAC80211(priv, "Set: %pM\n", conf->mac_addr);
  3208. memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
  3209. }
  3210. if (iwl_is_ready(priv))
  3211. iwl3945_set_mode(priv, conf->type);
  3212. mutex_unlock(&priv->mutex);
  3213. IWL_DEBUG_MAC80211(priv, "leave\n");
  3214. return 0;
  3215. }
  3216. /**
  3217. * iwl3945_mac_config - mac80211 config callback
  3218. *
  3219. * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
  3220. * be set inappropriately and the driver currently sets the hardware up to
  3221. * use it whenever needed.
  3222. */
  3223. static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed)
  3224. {
  3225. struct iwl_priv *priv = hw->priv;
  3226. const struct iwl_channel_info *ch_info;
  3227. struct ieee80211_conf *conf = &hw->conf;
  3228. unsigned long flags;
  3229. int ret = 0;
  3230. mutex_lock(&priv->mutex);
  3231. IWL_DEBUG_MAC80211(priv, "enter to channel %d\n",
  3232. conf->channel->hw_value);
  3233. if (!iwl_is_ready(priv)) {
  3234. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  3235. ret = -EIO;
  3236. goto out;
  3237. }
  3238. if (unlikely(!iwl3945_mod_params.disable_hw_scan &&
  3239. test_bit(STATUS_SCANNING, &priv->status))) {
  3240. IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
  3241. set_bit(STATUS_CONF_PENDING, &priv->status);
  3242. mutex_unlock(&priv->mutex);
  3243. return 0;
  3244. }
  3245. spin_lock_irqsave(&priv->lock, flags);
  3246. ch_info = iwl_get_channel_info(priv, conf->channel->band,
  3247. conf->channel->hw_value);
  3248. if (!is_channel_valid(ch_info)) {
  3249. IWL_DEBUG_SCAN(priv,
  3250. "Channel %d [%d] is INVALID for this band.\n",
  3251. conf->channel->hw_value, conf->channel->band);
  3252. IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
  3253. spin_unlock_irqrestore(&priv->lock, flags);
  3254. ret = -EINVAL;
  3255. goto out;
  3256. }
  3257. iwl_set_rxon_channel(priv, conf->channel);
  3258. iwl_set_flags_for_band(priv, conf->channel->band);
  3259. /* The list of supported rates and rate mask can be different
  3260. * for each phymode; since the phymode may have changed, reset
  3261. * the rate mask to what mac80211 lists */
  3262. iwl_set_rate(priv);
  3263. spin_unlock_irqrestore(&priv->lock, flags);
  3264. #ifdef IEEE80211_CONF_CHANNEL_SWITCH
  3265. if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
  3266. iwl3945_hw_channel_switch(priv, conf->channel);
  3267. goto out;
  3268. }
  3269. #endif
  3270. iwl3945_radio_kill_sw(priv, !conf->radio_enabled);
  3271. if (!conf->radio_enabled) {
  3272. IWL_DEBUG_MAC80211(priv, "leave - radio disabled\n");
  3273. goto out;
  3274. }
  3275. if (iwl_is_rfkill(priv)) {
  3276. IWL_DEBUG_MAC80211(priv, "leave - RF kill\n");
  3277. ret = -EIO;
  3278. goto out;
  3279. }
  3280. iwl_set_rate(priv);
  3281. if (memcmp(&priv->active_rxon,
  3282. &priv->staging_rxon, sizeof(priv->staging_rxon)))
  3283. iwl3945_commit_rxon(priv);
  3284. else
  3285. IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration\n");
  3286. IWL_DEBUG_MAC80211(priv, "leave\n");
  3287. out:
  3288. clear_bit(STATUS_CONF_PENDING, &priv->status);
  3289. mutex_unlock(&priv->mutex);
  3290. return ret;
  3291. }
  3292. static void iwl3945_config_ap(struct iwl_priv *priv)
  3293. {
  3294. int rc = 0;
  3295. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3296. return;
  3297. /* The following should be done only at AP bring up */
  3298. if (!(iwl_is_associated(priv))) {
  3299. /* RXON - unassoc (to set timing command) */
  3300. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3301. iwl3945_commit_rxon(priv);
  3302. /* RXON Timing */
  3303. memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
  3304. iwl3945_setup_rxon_timing(priv);
  3305. rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
  3306. sizeof(priv->rxon_timing),
  3307. &priv->rxon_timing);
  3308. if (rc)
  3309. IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
  3310. "Attempting to continue.\n");
  3311. /* FIXME: what should be the assoc_id for AP? */
  3312. priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
  3313. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  3314. priv->staging_rxon.flags |=
  3315. RXON_FLG_SHORT_PREAMBLE_MSK;
  3316. else
  3317. priv->staging_rxon.flags &=
  3318. ~RXON_FLG_SHORT_PREAMBLE_MSK;
  3319. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
  3320. if (priv->assoc_capability &
  3321. WLAN_CAPABILITY_SHORT_SLOT_TIME)
  3322. priv->staging_rxon.flags |=
  3323. RXON_FLG_SHORT_SLOT_MSK;
  3324. else
  3325. priv->staging_rxon.flags &=
  3326. ~RXON_FLG_SHORT_SLOT_MSK;
  3327. if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
  3328. priv->staging_rxon.flags &=
  3329. ~RXON_FLG_SHORT_SLOT_MSK;
  3330. }
  3331. /* restore RXON assoc */
  3332. priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  3333. iwl3945_commit_rxon(priv);
  3334. iwl3945_add_station(priv, iwl_bcast_addr, 0, 0);
  3335. }
  3336. iwl3945_send_beacon_cmd(priv);
  3337. /* FIXME - we need to add code here to detect a totally new
  3338. * configuration, reset the AP, unassoc, rxon timing, assoc,
  3339. * clear sta table, add BCAST sta... */
  3340. }
  3341. static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
  3342. struct ieee80211_vif *vif,
  3343. struct ieee80211_if_conf *conf)
  3344. {
  3345. struct iwl_priv *priv = hw->priv;
  3346. int rc;
  3347. if (conf == NULL)
  3348. return -EIO;
  3349. if (priv->vif != vif) {
  3350. IWL_DEBUG_MAC80211(priv, "leave - priv->vif != vif\n");
  3351. return 0;
  3352. }
  3353. /* handle this temporarily here */
  3354. if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
  3355. conf->changed & IEEE80211_IFCC_BEACON) {
  3356. struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
  3357. if (!beacon)
  3358. return -ENOMEM;
  3359. mutex_lock(&priv->mutex);
  3360. rc = iwl3945_mac_beacon_update(hw, beacon);
  3361. mutex_unlock(&priv->mutex);
  3362. if (rc)
  3363. return rc;
  3364. }
  3365. if (!iwl_is_alive(priv))
  3366. return -EAGAIN;
  3367. mutex_lock(&priv->mutex);
  3368. if (conf->bssid)
  3369. IWL_DEBUG_MAC80211(priv, "bssid: %pM\n", conf->bssid);
  3370. /*
  3371. * very dubious code was here; the probe filtering flag is never set:
  3372. *
  3373. if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
  3374. !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
  3375. */
  3376. if (priv->iw_mode == NL80211_IFTYPE_AP) {
  3377. if (!conf->bssid) {
  3378. conf->bssid = priv->mac_addr;
  3379. memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
  3380. IWL_DEBUG_MAC80211(priv, "bssid was set to: %pM\n",
  3381. conf->bssid);
  3382. }
  3383. if (priv->ibss_beacon)
  3384. dev_kfree_skb(priv->ibss_beacon);
  3385. priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
  3386. }
  3387. if (iwl_is_rfkill(priv))
  3388. goto done;
  3389. if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
  3390. !is_multicast_ether_addr(conf->bssid)) {
  3391. /* If there is currently a HW scan going on in the background
  3392. * then we need to cancel it else the RXON below will fail. */
  3393. if (iwl_scan_cancel_timeout(priv, 100)) {
  3394. IWL_WARN(priv, "Aborted scan still in progress "
  3395. "after 100ms\n");
  3396. IWL_DEBUG_MAC80211(priv, "leaving:scan abort failed\n");
  3397. mutex_unlock(&priv->mutex);
  3398. return -EAGAIN;
  3399. }
  3400. memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
  3401. /* TODO: Audit driver for usage of these members and see
  3402. * if mac80211 deprecates them (priv->bssid looks like it
  3403. * shouldn't be there, but I haven't scanned the IBSS code
  3404. * to verify) - jpk */
  3405. memcpy(priv->bssid, conf->bssid, ETH_ALEN);
  3406. if (priv->iw_mode == NL80211_IFTYPE_AP)
  3407. iwl3945_config_ap(priv);
  3408. else {
  3409. rc = iwl3945_commit_rxon(priv);
  3410. if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
  3411. iwl3945_add_station(priv,
  3412. priv->active_rxon.bssid_addr, 1, 0);
  3413. }
  3414. } else {
  3415. iwl_scan_cancel_timeout(priv, 100);
  3416. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3417. iwl3945_commit_rxon(priv);
  3418. }
  3419. done:
  3420. IWL_DEBUG_MAC80211(priv, "leave\n");
  3421. mutex_unlock(&priv->mutex);
  3422. return 0;
  3423. }
  3424. static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
  3425. struct ieee80211_if_init_conf *conf)
  3426. {
  3427. struct iwl_priv *priv = hw->priv;
  3428. IWL_DEBUG_MAC80211(priv, "enter\n");
  3429. mutex_lock(&priv->mutex);
  3430. if (iwl_is_ready_rf(priv)) {
  3431. iwl_scan_cancel_timeout(priv, 100);
  3432. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3433. iwl3945_commit_rxon(priv);
  3434. }
  3435. if (priv->vif == conf->vif) {
  3436. priv->vif = NULL;
  3437. memset(priv->bssid, 0, ETH_ALEN);
  3438. }
  3439. mutex_unlock(&priv->mutex);
  3440. IWL_DEBUG_MAC80211(priv, "leave\n");
  3441. }
  3442. #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
  3443. static void iwl3945_bss_info_changed(struct ieee80211_hw *hw,
  3444. struct ieee80211_vif *vif,
  3445. struct ieee80211_bss_conf *bss_conf,
  3446. u32 changes)
  3447. {
  3448. struct iwl_priv *priv = hw->priv;
  3449. IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
  3450. if (changes & BSS_CHANGED_ERP_PREAMBLE) {
  3451. IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
  3452. bss_conf->use_short_preamble);
  3453. if (bss_conf->use_short_preamble)
  3454. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  3455. else
  3456. priv->staging_rxon.flags &=
  3457. ~RXON_FLG_SHORT_PREAMBLE_MSK;
  3458. }
  3459. if (changes & BSS_CHANGED_ERP_CTS_PROT) {
  3460. IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n",
  3461. bss_conf->use_cts_prot);
  3462. if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
  3463. priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
  3464. else
  3465. priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
  3466. }
  3467. if (changes & BSS_CHANGED_ASSOC) {
  3468. IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
  3469. /* This should never happen as this function should
  3470. * never be called from interrupt context. */
  3471. if (WARN_ON_ONCE(in_interrupt()))
  3472. return;
  3473. if (bss_conf->assoc) {
  3474. priv->assoc_id = bss_conf->aid;
  3475. priv->beacon_int = bss_conf->beacon_int;
  3476. priv->timestamp = bss_conf->timestamp;
  3477. priv->assoc_capability = bss_conf->assoc_capability;
  3478. priv->power_data.dtim_period = bss_conf->dtim_period;
  3479. priv->next_scan_jiffies = jiffies +
  3480. IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
  3481. mutex_lock(&priv->mutex);
  3482. iwl3945_post_associate(priv);
  3483. mutex_unlock(&priv->mutex);
  3484. } else {
  3485. priv->assoc_id = 0;
  3486. IWL_DEBUG_MAC80211(priv,
  3487. "DISASSOC %d\n", bss_conf->assoc);
  3488. }
  3489. } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
  3490. IWL_DEBUG_MAC80211(priv,
  3491. "Associated Changes %d\n", changes);
  3492. iwl3945_send_rxon_assoc(priv);
  3493. }
  3494. }
  3495. static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  3496. struct ieee80211_vif *vif,
  3497. struct ieee80211_sta *sta,
  3498. struct ieee80211_key_conf *key)
  3499. {
  3500. struct iwl_priv *priv = hw->priv;
  3501. const u8 *addr;
  3502. int ret;
  3503. u8 sta_id;
  3504. IWL_DEBUG_MAC80211(priv, "enter\n");
  3505. if (iwl3945_mod_params.sw_crypto) {
  3506. IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
  3507. return -EOPNOTSUPP;
  3508. }
  3509. addr = sta ? sta->addr : iwl_bcast_addr;
  3510. sta_id = iwl3945_hw_find_station(priv, addr);
  3511. if (sta_id == IWL_INVALID_STATION) {
  3512. IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
  3513. addr);
  3514. return -EINVAL;
  3515. }
  3516. mutex_lock(&priv->mutex);
  3517. iwl_scan_cancel_timeout(priv, 100);
  3518. switch (cmd) {
  3519. case SET_KEY:
  3520. ret = iwl3945_update_sta_key_info(priv, key, sta_id);
  3521. if (!ret) {
  3522. iwl_set_rxon_hwcrypto(priv, 1);
  3523. iwl3945_commit_rxon(priv);
  3524. key->hw_key_idx = sta_id;
  3525. IWL_DEBUG_MAC80211(priv,
  3526. "set_key success, using hwcrypto\n");
  3527. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  3528. }
  3529. break;
  3530. case DISABLE_KEY:
  3531. ret = iwl3945_clear_sta_key_info(priv, sta_id);
  3532. if (!ret) {
  3533. iwl_set_rxon_hwcrypto(priv, 0);
  3534. iwl3945_commit_rxon(priv);
  3535. IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
  3536. }
  3537. break;
  3538. default:
  3539. ret = -EINVAL;
  3540. }
  3541. IWL_DEBUG_MAC80211(priv, "leave\n");
  3542. mutex_unlock(&priv->mutex);
  3543. return ret;
  3544. }
  3545. static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  3546. const struct ieee80211_tx_queue_params *params)
  3547. {
  3548. struct iwl_priv *priv = hw->priv;
  3549. unsigned long flags;
  3550. int q;
  3551. IWL_DEBUG_MAC80211(priv, "enter\n");
  3552. if (!iwl_is_ready_rf(priv)) {
  3553. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  3554. return -EIO;
  3555. }
  3556. if (queue >= AC_NUM) {
  3557. IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
  3558. return 0;
  3559. }
  3560. q = AC_NUM - 1 - queue;
  3561. spin_lock_irqsave(&priv->lock, flags);
  3562. priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
  3563. priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
  3564. priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
  3565. priv->qos_data.def_qos_parm.ac[q].edca_txop =
  3566. cpu_to_le16((params->txop * 32));
  3567. priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
  3568. priv->qos_data.qos_active = 1;
  3569. spin_unlock_irqrestore(&priv->lock, flags);
  3570. mutex_lock(&priv->mutex);
  3571. if (priv->iw_mode == NL80211_IFTYPE_AP)
  3572. iwl3945_activate_qos(priv, 1);
  3573. else if (priv->assoc_id && iwl_is_associated(priv))
  3574. iwl3945_activate_qos(priv, 0);
  3575. mutex_unlock(&priv->mutex);
  3576. IWL_DEBUG_MAC80211(priv, "leave\n");
  3577. return 0;
  3578. }
  3579. static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
  3580. struct ieee80211_tx_queue_stats *stats)
  3581. {
  3582. struct iwl_priv *priv = hw->priv;
  3583. int i, avail;
  3584. struct iwl_tx_queue *txq;
  3585. struct iwl_queue *q;
  3586. unsigned long flags;
  3587. IWL_DEBUG_MAC80211(priv, "enter\n");
  3588. if (!iwl_is_ready_rf(priv)) {
  3589. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  3590. return -EIO;
  3591. }
  3592. spin_lock_irqsave(&priv->lock, flags);
  3593. for (i = 0; i < AC_NUM; i++) {
  3594. txq = &priv->txq[i];
  3595. q = &txq->q;
  3596. avail = iwl_queue_space(q);
  3597. stats[i].len = q->n_window - avail;
  3598. stats[i].limit = q->n_window - q->high_mark;
  3599. stats[i].count = q->n_window;
  3600. }
  3601. spin_unlock_irqrestore(&priv->lock, flags);
  3602. IWL_DEBUG_MAC80211(priv, "leave\n");
  3603. return 0;
  3604. }
  3605. static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
  3606. {
  3607. struct iwl_priv *priv = hw->priv;
  3608. unsigned long flags;
  3609. mutex_lock(&priv->mutex);
  3610. IWL_DEBUG_MAC80211(priv, "enter\n");
  3611. iwl_reset_qos(priv);
  3612. spin_lock_irqsave(&priv->lock, flags);
  3613. priv->assoc_id = 0;
  3614. priv->assoc_capability = 0;
  3615. /* new association get rid of ibss beacon skb */
  3616. if (priv->ibss_beacon)
  3617. dev_kfree_skb(priv->ibss_beacon);
  3618. priv->ibss_beacon = NULL;
  3619. priv->beacon_int = priv->hw->conf.beacon_int;
  3620. priv->timestamp = 0;
  3621. if ((priv->iw_mode == NL80211_IFTYPE_STATION))
  3622. priv->beacon_int = 0;
  3623. spin_unlock_irqrestore(&priv->lock, flags);
  3624. if (!iwl_is_ready_rf(priv)) {
  3625. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  3626. mutex_unlock(&priv->mutex);
  3627. return;
  3628. }
  3629. /* we are restarting association process
  3630. * clear RXON_FILTER_ASSOC_MSK bit
  3631. */
  3632. if (priv->iw_mode != NL80211_IFTYPE_AP) {
  3633. iwl_scan_cancel_timeout(priv, 100);
  3634. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3635. iwl3945_commit_rxon(priv);
  3636. }
  3637. /* Per mac80211.h: This is only used in IBSS mode... */
  3638. if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
  3639. IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
  3640. mutex_unlock(&priv->mutex);
  3641. return;
  3642. }
  3643. iwl_set_rate(priv);
  3644. mutex_unlock(&priv->mutex);
  3645. IWL_DEBUG_MAC80211(priv, "leave\n");
  3646. }
  3647. static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
  3648. {
  3649. struct iwl_priv *priv = hw->priv;
  3650. unsigned long flags;
  3651. IWL_DEBUG_MAC80211(priv, "enter\n");
  3652. if (!iwl_is_ready_rf(priv)) {
  3653. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  3654. return -EIO;
  3655. }
  3656. if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
  3657. IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n");
  3658. return -EIO;
  3659. }
  3660. spin_lock_irqsave(&priv->lock, flags);
  3661. if (priv->ibss_beacon)
  3662. dev_kfree_skb(priv->ibss_beacon);
  3663. priv->ibss_beacon = skb;
  3664. priv->assoc_id = 0;
  3665. IWL_DEBUG_MAC80211(priv, "leave\n");
  3666. spin_unlock_irqrestore(&priv->lock, flags);
  3667. iwl_reset_qos(priv);
  3668. iwl3945_post_associate(priv);
  3669. return 0;
  3670. }
  3671. /*****************************************************************************
  3672. *
  3673. * sysfs attributes
  3674. *
  3675. *****************************************************************************/
  3676. #ifdef CONFIG_IWLWIFI_DEBUG
  3677. /*
  3678. * The following adds a new attribute to the sysfs representation
  3679. * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
  3680. * used for controlling the debug level.
  3681. *
  3682. * See the level definitions in iwl for details.
  3683. */
  3684. static ssize_t show_debug_level(struct device *d,
  3685. struct device_attribute *attr, char *buf)
  3686. {
  3687. struct iwl_priv *priv = d->driver_data;
  3688. return sprintf(buf, "0x%08X\n", priv->debug_level);
  3689. }
  3690. static ssize_t store_debug_level(struct device *d,
  3691. struct device_attribute *attr,
  3692. const char *buf, size_t count)
  3693. {
  3694. struct iwl_priv *priv = d->driver_data;
  3695. unsigned long val;
  3696. int ret;
  3697. ret = strict_strtoul(buf, 0, &val);
  3698. if (ret)
  3699. IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
  3700. else
  3701. priv->debug_level = val;
  3702. return strnlen(buf, count);
  3703. }
  3704. static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
  3705. show_debug_level, store_debug_level);
  3706. #endif /* CONFIG_IWLWIFI_DEBUG */
  3707. static ssize_t show_temperature(struct device *d,
  3708. struct device_attribute *attr, char *buf)
  3709. {
  3710. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3711. if (!iwl_is_alive(priv))
  3712. return -EAGAIN;
  3713. return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
  3714. }
  3715. static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
  3716. static ssize_t show_tx_power(struct device *d,
  3717. struct device_attribute *attr, char *buf)
  3718. {
  3719. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3720. return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
  3721. }
  3722. static ssize_t store_tx_power(struct device *d,
  3723. struct device_attribute *attr,
  3724. const char *buf, size_t count)
  3725. {
  3726. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3727. char *p = (char *)buf;
  3728. u32 val;
  3729. val = simple_strtoul(p, &p, 10);
  3730. if (p == buf)
  3731. IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
  3732. else
  3733. iwl3945_hw_reg_set_txpower(priv, val);
  3734. return count;
  3735. }
  3736. static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
  3737. static ssize_t show_flags(struct device *d,
  3738. struct device_attribute *attr, char *buf)
  3739. {
  3740. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3741. return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
  3742. }
  3743. static ssize_t store_flags(struct device *d,
  3744. struct device_attribute *attr,
  3745. const char *buf, size_t count)
  3746. {
  3747. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3748. u32 flags = simple_strtoul(buf, NULL, 0);
  3749. mutex_lock(&priv->mutex);
  3750. if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
  3751. /* Cancel any currently running scans... */
  3752. if (iwl_scan_cancel_timeout(priv, 100))
  3753. IWL_WARN(priv, "Could not cancel scan.\n");
  3754. else {
  3755. IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
  3756. flags);
  3757. priv->staging_rxon.flags = cpu_to_le32(flags);
  3758. iwl3945_commit_rxon(priv);
  3759. }
  3760. }
  3761. mutex_unlock(&priv->mutex);
  3762. return count;
  3763. }
  3764. static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
  3765. static ssize_t show_filter_flags(struct device *d,
  3766. struct device_attribute *attr, char *buf)
  3767. {
  3768. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3769. return sprintf(buf, "0x%04X\n",
  3770. le32_to_cpu(priv->active_rxon.filter_flags));
  3771. }
  3772. static ssize_t store_filter_flags(struct device *d,
  3773. struct device_attribute *attr,
  3774. const char *buf, size_t count)
  3775. {
  3776. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  3777. u32 filter_flags = simple_strtoul(buf, NULL, 0);
  3778. mutex_lock(&priv->mutex);
  3779. if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
  3780. /* Cancel any currently running scans... */
  3781. if (iwl_scan_cancel_timeout(priv, 100))
  3782. IWL_WARN(priv, "Could not cancel scan.\n");
  3783. else {
  3784. IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
  3785. "0x%04X\n", filter_flags);
  3786. priv->staging_rxon.filter_flags =
  3787. cpu_to_le32(filter_flags);
  3788. iwl3945_commit_rxon(priv);
  3789. }
  3790. }
  3791. mutex_unlock(&priv->mutex);
  3792. return count;
  3793. }
  3794. static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
  3795. store_filter_flags);
  3796. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  3797. static ssize_t show_measurement(struct device *d,
  3798. struct device_attribute *attr, char *buf)
  3799. {
  3800. struct iwl_priv *priv = dev_get_drvdata(d);
  3801. struct iwl_spectrum_notification measure_report;
  3802. u32 size = sizeof(measure_report), len = 0, ofs = 0;
  3803. u8 *data = (u8 *)&measure_report;
  3804. unsigned long flags;
  3805. spin_lock_irqsave(&priv->lock, flags);
  3806. if (!(priv->measurement_status & MEASUREMENT_READY)) {
  3807. spin_unlock_irqrestore(&priv->lock, flags);
  3808. return 0;
  3809. }
  3810. memcpy(&measure_report, &priv->measure_report, size);
  3811. priv->measurement_status = 0;
  3812. spin_unlock_irqrestore(&priv->lock, flags);
  3813. while (size && (PAGE_SIZE - len)) {
  3814. hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
  3815. PAGE_SIZE - len, 1);
  3816. len = strlen(buf);
  3817. if (PAGE_SIZE - len)
  3818. buf[len++] = '\n';
  3819. ofs += 16;
  3820. size -= min(size, 16U);
  3821. }
  3822. return len;
  3823. }
  3824. static ssize_t store_measurement(struct device *d,
  3825. struct device_attribute *attr,
  3826. const char *buf, size_t count)
  3827. {
  3828. struct iwl_priv *priv = dev_get_drvdata(d);
  3829. struct ieee80211_measurement_params params = {
  3830. .channel = le16_to_cpu(priv->active_rxon.channel),
  3831. .start_time = cpu_to_le64(priv->last_tsf),
  3832. .duration = cpu_to_le16(1),
  3833. };
  3834. u8 type = IWL_MEASURE_BASIC;
  3835. u8 buffer[32];
  3836. u8 channel;
  3837. if (count) {
  3838. char *p = buffer;
  3839. strncpy(buffer, buf, min(sizeof(buffer), count));
  3840. channel = simple_strtoul(p, NULL, 0);
  3841. if (channel)
  3842. params.channel = channel;
  3843. p = buffer;
  3844. while (*p && *p != ' ')
  3845. p++;
  3846. if (*p)
  3847. type = simple_strtoul(p + 1, NULL, 0);
  3848. }
  3849. IWL_DEBUG_INFO(priv, "Invoking measurement of type %d on "
  3850. "channel %d (for '%s')\n", type, params.channel, buf);
  3851. iwl3945_get_measurement(priv, &params, type);
  3852. return count;
  3853. }
  3854. static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
  3855. show_measurement, store_measurement);
  3856. #endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
  3857. static ssize_t store_retry_rate(struct device *d,
  3858. struct device_attribute *attr,
  3859. const char *buf, size_t count)
  3860. {
  3861. struct iwl_priv *priv = dev_get_drvdata(d);
  3862. priv->retry_rate = simple_strtoul(buf, NULL, 0);
  3863. if (priv->retry_rate <= 0)
  3864. priv->retry_rate = 1;
  3865. return count;
  3866. }
  3867. static ssize_t show_retry_rate(struct device *d,
  3868. struct device_attribute *attr, char *buf)
  3869. {
  3870. struct iwl_priv *priv = dev_get_drvdata(d);
  3871. return sprintf(buf, "%d", priv->retry_rate);
  3872. }
  3873. static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
  3874. store_retry_rate);
  3875. static ssize_t store_power_level(struct device *d,
  3876. struct device_attribute *attr,
  3877. const char *buf, size_t count)
  3878. {
  3879. struct iwl_priv *priv = dev_get_drvdata(d);
  3880. int ret;
  3881. unsigned long mode;
  3882. mutex_lock(&priv->mutex);
  3883. if (!iwl_is_ready(priv)) {
  3884. ret = -EAGAIN;
  3885. goto out;
  3886. }
  3887. ret = strict_strtoul(buf, 10, &mode);
  3888. if (ret)
  3889. goto out;
  3890. ret = iwl_power_set_user_mode(priv, mode);
  3891. if (ret) {
  3892. IWL_DEBUG_MAC80211(priv, "failed setting power mode.\n");
  3893. goto out;
  3894. }
  3895. ret = count;
  3896. out:
  3897. mutex_unlock(&priv->mutex);
  3898. return ret;
  3899. }
  3900. static ssize_t show_power_level(struct device *d,
  3901. struct device_attribute *attr, char *buf)
  3902. {
  3903. struct iwl_priv *priv = dev_get_drvdata(d);
  3904. int mode = priv->power_data.user_power_setting;
  3905. int system = priv->power_data.system_power_setting;
  3906. int level = priv->power_data.power_mode;
  3907. char *p = buf;
  3908. switch (system) {
  3909. case IWL_POWER_SYS_AUTO:
  3910. p += sprintf(p, "SYSTEM:auto");
  3911. break;
  3912. case IWL_POWER_SYS_AC:
  3913. p += sprintf(p, "SYSTEM:ac");
  3914. break;
  3915. case IWL_POWER_SYS_BATTERY:
  3916. p += sprintf(p, "SYSTEM:battery");
  3917. break;
  3918. }
  3919. p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
  3920. "fixed" : "auto");
  3921. p += sprintf(p, "\tINDEX:%d", level);
  3922. p += sprintf(p, "\n");
  3923. return p - buf + 1;
  3924. }
  3925. static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR,
  3926. show_power_level, store_power_level);
  3927. #define MAX_WX_STRING 80
  3928. /* Values are in microsecond */
  3929. static const s32 timeout_duration[] = {
  3930. 350000,
  3931. 250000,
  3932. 75000,
  3933. 37000,
  3934. 25000,
  3935. };
  3936. static const s32 period_duration[] = {
  3937. 400000,
  3938. 700000,
  3939. 1000000,
  3940. 1000000,
  3941. 1000000
  3942. };
  3943. static ssize_t show_channels(struct device *d,
  3944. struct device_attribute *attr, char *buf)
  3945. {
  3946. /* all this shit doesn't belong into sysfs anyway */
  3947. return 0;
  3948. }
  3949. static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
  3950. static ssize_t show_statistics(struct device *d,
  3951. struct device_attribute *attr, char *buf)
  3952. {
  3953. struct iwl_priv *priv = dev_get_drvdata(d);
  3954. u32 size = sizeof(struct iwl3945_notif_statistics);
  3955. u32 len = 0, ofs = 0;
  3956. u8 *data = (u8 *)&priv->statistics_39;
  3957. int rc = 0;
  3958. if (!iwl_is_alive(priv))
  3959. return -EAGAIN;
  3960. mutex_lock(&priv->mutex);
  3961. rc = iwl_send_statistics_request(priv, 0);
  3962. mutex_unlock(&priv->mutex);
  3963. if (rc) {
  3964. len = sprintf(buf,
  3965. "Error sending statistics request: 0x%08X\n", rc);
  3966. return len;
  3967. }
  3968. while (size && (PAGE_SIZE - len)) {
  3969. hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
  3970. PAGE_SIZE - len, 1);
  3971. len = strlen(buf);
  3972. if (PAGE_SIZE - len)
  3973. buf[len++] = '\n';
  3974. ofs += 16;
  3975. size -= min(size, 16U);
  3976. }
  3977. return len;
  3978. }
  3979. static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
  3980. static ssize_t show_antenna(struct device *d,
  3981. struct device_attribute *attr, char *buf)
  3982. {
  3983. struct iwl_priv *priv = dev_get_drvdata(d);
  3984. if (!iwl_is_alive(priv))
  3985. return -EAGAIN;
  3986. return sprintf(buf, "%d\n", iwl3945_mod_params.antenna);
  3987. }
  3988. static ssize_t store_antenna(struct device *d,
  3989. struct device_attribute *attr,
  3990. const char *buf, size_t count)
  3991. {
  3992. struct iwl_priv *priv __maybe_unused = dev_get_drvdata(d);
  3993. int ant;
  3994. if (count == 0)
  3995. return 0;
  3996. if (sscanf(buf, "%1i", &ant) != 1) {
  3997. IWL_DEBUG_INFO(priv, "not in hex or decimal form.\n");
  3998. return count;
  3999. }
  4000. if ((ant >= 0) && (ant <= 2)) {
  4001. IWL_DEBUG_INFO(priv, "Setting antenna select to %d.\n", ant);
  4002. iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant;
  4003. } else
  4004. IWL_DEBUG_INFO(priv, "Bad antenna select value %d.\n", ant);
  4005. return count;
  4006. }
  4007. static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
  4008. static ssize_t show_status(struct device *d,
  4009. struct device_attribute *attr, char *buf)
  4010. {
  4011. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  4012. if (!iwl_is_alive(priv))
  4013. return -EAGAIN;
  4014. return sprintf(buf, "0x%08x\n", (int)priv->status);
  4015. }
  4016. static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
  4017. static ssize_t dump_error_log(struct device *d,
  4018. struct device_attribute *attr,
  4019. const char *buf, size_t count)
  4020. {
  4021. char *p = (char *)buf;
  4022. if (p[0] == '1')
  4023. iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data);
  4024. return strnlen(buf, count);
  4025. }
  4026. static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
  4027. static ssize_t dump_event_log(struct device *d,
  4028. struct device_attribute *attr,
  4029. const char *buf, size_t count)
  4030. {
  4031. char *p = (char *)buf;
  4032. if (p[0] == '1')
  4033. iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data);
  4034. return strnlen(buf, count);
  4035. }
  4036. static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
  4037. /*****************************************************************************
  4038. *
  4039. * driver setup and tear down
  4040. *
  4041. *****************************************************************************/
  4042. static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
  4043. {
  4044. priv->workqueue = create_singlethread_workqueue(DRV_NAME);
  4045. init_waitqueue_head(&priv->wait_command_queue);
  4046. INIT_WORK(&priv->up, iwl3945_bg_up);
  4047. INIT_WORK(&priv->restart, iwl3945_bg_restart);
  4048. INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
  4049. INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
  4050. INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
  4051. INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
  4052. INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
  4053. INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll);
  4054. INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
  4055. INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
  4056. INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
  4057. INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
  4058. iwl3945_hw_setup_deferred_work(priv);
  4059. tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
  4060. iwl3945_irq_tasklet, (unsigned long)priv);
  4061. }
  4062. static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
  4063. {
  4064. iwl3945_hw_cancel_deferred_work(priv);
  4065. cancel_delayed_work_sync(&priv->init_alive_start);
  4066. cancel_delayed_work(&priv->scan_check);
  4067. cancel_delayed_work(&priv->alive_start);
  4068. cancel_work_sync(&priv->beacon_update);
  4069. }
  4070. static struct attribute *iwl3945_sysfs_entries[] = {
  4071. &dev_attr_antenna.attr,
  4072. &dev_attr_channels.attr,
  4073. &dev_attr_dump_errors.attr,
  4074. &dev_attr_dump_events.attr,
  4075. &dev_attr_flags.attr,
  4076. &dev_attr_filter_flags.attr,
  4077. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  4078. &dev_attr_measurement.attr,
  4079. #endif
  4080. &dev_attr_power_level.attr,
  4081. &dev_attr_retry_rate.attr,
  4082. &dev_attr_statistics.attr,
  4083. &dev_attr_status.attr,
  4084. &dev_attr_temperature.attr,
  4085. &dev_attr_tx_power.attr,
  4086. #ifdef CONFIG_IWLWIFI_DEBUG
  4087. &dev_attr_debug_level.attr,
  4088. #endif
  4089. NULL
  4090. };
  4091. static struct attribute_group iwl3945_attribute_group = {
  4092. .name = NULL, /* put in device directory */
  4093. .attrs = iwl3945_sysfs_entries,
  4094. };
  4095. static struct ieee80211_ops iwl3945_hw_ops = {
  4096. .tx = iwl3945_mac_tx,
  4097. .start = iwl3945_mac_start,
  4098. .stop = iwl3945_mac_stop,
  4099. .add_interface = iwl3945_mac_add_interface,
  4100. .remove_interface = iwl3945_mac_remove_interface,
  4101. .config = iwl3945_mac_config,
  4102. .config_interface = iwl3945_mac_config_interface,
  4103. .configure_filter = iwl_configure_filter,
  4104. .set_key = iwl3945_mac_set_key,
  4105. .get_tx_stats = iwl3945_mac_get_tx_stats,
  4106. .conf_tx = iwl3945_mac_conf_tx,
  4107. .reset_tsf = iwl3945_mac_reset_tsf,
  4108. .bss_info_changed = iwl3945_bss_info_changed,
  4109. .hw_scan = iwl_mac_hw_scan
  4110. };
  4111. static int iwl3945_init_drv(struct iwl_priv *priv)
  4112. {
  4113. int ret;
  4114. struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
  4115. priv->retry_rate = 1;
  4116. priv->ibss_beacon = NULL;
  4117. spin_lock_init(&priv->lock);
  4118. spin_lock_init(&priv->power_data.lock);
  4119. spin_lock_init(&priv->sta_lock);
  4120. spin_lock_init(&priv->hcmd_lock);
  4121. INIT_LIST_HEAD(&priv->free_frames);
  4122. mutex_init(&priv->mutex);
  4123. /* Clear the driver's (not device's) station table */
  4124. iwl3945_clear_stations_table(priv);
  4125. priv->data_retry_limit = -1;
  4126. priv->ieee_channels = NULL;
  4127. priv->ieee_rates = NULL;
  4128. priv->band = IEEE80211_BAND_2GHZ;
  4129. priv->iw_mode = NL80211_IFTYPE_STATION;
  4130. iwl_reset_qos(priv);
  4131. priv->qos_data.qos_active = 0;
  4132. priv->qos_data.qos_cap.val = 0;
  4133. priv->rates_mask = IWL_RATES_MASK;
  4134. /* If power management is turned on, default to CAM mode */
  4135. priv->power_mode = IWL_POWER_MODE_CAM;
  4136. priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
  4137. if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
  4138. IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
  4139. eeprom->version);
  4140. ret = -EINVAL;
  4141. goto err;
  4142. }
  4143. ret = iwl_init_channel_map(priv);
  4144. if (ret) {
  4145. IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
  4146. goto err;
  4147. }
  4148. /* Set up txpower settings in driver for all channels */
  4149. if (iwl3945_txpower_set_from_eeprom(priv)) {
  4150. ret = -EIO;
  4151. goto err_free_channel_map;
  4152. }
  4153. ret = iwlcore_init_geos(priv);
  4154. if (ret) {
  4155. IWL_ERR(priv, "initializing geos failed: %d\n", ret);
  4156. goto err_free_channel_map;
  4157. }
  4158. iwl3945_init_hw_rates(priv, priv->ieee_rates);
  4159. if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
  4160. priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  4161. &priv->bands[IEEE80211_BAND_2GHZ];
  4162. if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
  4163. priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  4164. &priv->bands[IEEE80211_BAND_5GHZ];
  4165. return 0;
  4166. err_free_channel_map:
  4167. iwl_free_channel_map(priv);
  4168. err:
  4169. return ret;
  4170. }
  4171. static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  4172. {
  4173. int err = 0;
  4174. struct iwl_priv *priv;
  4175. struct ieee80211_hw *hw;
  4176. struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
  4177. struct iwl3945_eeprom *eeprom;
  4178. unsigned long flags;
  4179. /***********************
  4180. * 1. Allocating HW data
  4181. * ********************/
  4182. /* mac80211 allocates memory for this device instance, including
  4183. * space for this driver's private structure */
  4184. hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
  4185. if (hw == NULL) {
  4186. printk(KERN_ERR DRV_NAME "Can not allocate network device\n");
  4187. err = -ENOMEM;
  4188. goto out;
  4189. }
  4190. priv = hw->priv;
  4191. SET_IEEE80211_DEV(hw, &pdev->dev);
  4192. if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) ||
  4193. (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) {
  4194. IWL_ERR(priv,
  4195. "invalid queues_num, should be between %d and %d\n",
  4196. IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES);
  4197. err = -EINVAL;
  4198. goto out;
  4199. }
  4200. /*
  4201. * Disabling hardware scan means that mac80211 will perform scans
  4202. * "the hard way", rather than using device's scan.
  4203. */
  4204. if (iwl3945_mod_params.disable_hw_scan) {
  4205. IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
  4206. iwl3945_hw_ops.hw_scan = NULL;
  4207. }
  4208. IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
  4209. priv->cfg = cfg;
  4210. priv->pci_dev = pdev;
  4211. #ifdef CONFIG_IWLWIFI_DEBUG
  4212. priv->debug_level = iwl3945_mod_params.debug;
  4213. atomic_set(&priv->restrict_refcnt, 0);
  4214. #endif
  4215. hw->rate_control_algorithm = "iwl-3945-rs";
  4216. hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
  4217. /* Tell mac80211 our characteristics */
  4218. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  4219. IEEE80211_HW_NOISE_DBM;
  4220. hw->wiphy->interface_modes =
  4221. BIT(NL80211_IFTYPE_STATION) |
  4222. BIT(NL80211_IFTYPE_ADHOC);
  4223. hw->wiphy->custom_regulatory = true;
  4224. hw->wiphy->max_scan_ssids = 1;
  4225. /* 4 EDCA QOS priorities */
  4226. hw->queues = 4;
  4227. /***************************
  4228. * 2. Initializing PCI bus
  4229. * *************************/
  4230. if (pci_enable_device(pdev)) {
  4231. err = -ENODEV;
  4232. goto out_ieee80211_free_hw;
  4233. }
  4234. pci_set_master(pdev);
  4235. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  4236. if (!err)
  4237. err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  4238. if (err) {
  4239. IWL_WARN(priv, "No suitable DMA available.\n");
  4240. goto out_pci_disable_device;
  4241. }
  4242. pci_set_drvdata(pdev, priv);
  4243. err = pci_request_regions(pdev, DRV_NAME);
  4244. if (err)
  4245. goto out_pci_disable_device;
  4246. /***********************
  4247. * 3. Read REV Register
  4248. * ********************/
  4249. priv->hw_base = pci_iomap(pdev, 0, 0);
  4250. if (!priv->hw_base) {
  4251. err = -ENODEV;
  4252. goto out_pci_release_regions;
  4253. }
  4254. IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
  4255. (unsigned long long) pci_resource_len(pdev, 0));
  4256. IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
  4257. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  4258. * PCI Tx retries from interfering with C3 CPU state */
  4259. pci_write_config_byte(pdev, 0x41, 0x00);
  4260. /* amp init */
  4261. err = priv->cfg->ops->lib->apm_ops.init(priv);
  4262. if (err < 0) {
  4263. IWL_DEBUG_INFO(priv, "Failed to init APMG\n");
  4264. goto out_iounmap;
  4265. }
  4266. /***********************
  4267. * 4. Read EEPROM
  4268. * ********************/
  4269. /* Read the EEPROM */
  4270. err = iwl_eeprom_init(priv);
  4271. if (err) {
  4272. IWL_ERR(priv, "Unable to init EEPROM\n");
  4273. goto out_remove_sysfs;
  4274. }
  4275. /* MAC Address location in EEPROM same for 3945/4965 */
  4276. eeprom = (struct iwl3945_eeprom *)priv->eeprom;
  4277. memcpy(priv->mac_addr, eeprom->mac_address, ETH_ALEN);
  4278. IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
  4279. SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
  4280. /***********************
  4281. * 5. Setup HW Constants
  4282. * ********************/
  4283. /* Device-specific setup */
  4284. if (iwl3945_hw_set_hw_params(priv)) {
  4285. IWL_ERR(priv, "failed to set hw settings\n");
  4286. goto out_iounmap;
  4287. }
  4288. /***********************
  4289. * 6. Setup priv
  4290. * ********************/
  4291. err = iwl3945_init_drv(priv);
  4292. if (err) {
  4293. IWL_ERR(priv, "initializing driver failed\n");
  4294. goto out_free_geos;
  4295. }
  4296. IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
  4297. priv->cfg->name);
  4298. /***********************************
  4299. * 7. Initialize Module Parameters
  4300. * **********************************/
  4301. /* Initialize module parameter values here */
  4302. /* Disable radio (SW RF KILL) via parameter when loading driver */
  4303. if (iwl3945_mod_params.disable) {
  4304. set_bit(STATUS_RF_KILL_SW, &priv->status);
  4305. IWL_DEBUG_INFO(priv, "Radio disabled.\n");
  4306. }
  4307. /***********************
  4308. * 8. Setup Services
  4309. * ********************/
  4310. spin_lock_irqsave(&priv->lock, flags);
  4311. iwl3945_disable_interrupts(priv);
  4312. spin_unlock_irqrestore(&priv->lock, flags);
  4313. pci_enable_msi(priv->pci_dev);
  4314. err = request_irq(priv->pci_dev->irq, iwl3945_isr, IRQF_SHARED,
  4315. DRV_NAME, priv);
  4316. if (err) {
  4317. IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
  4318. goto out_disable_msi;
  4319. }
  4320. err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
  4321. if (err) {
  4322. IWL_ERR(priv, "failed to create sysfs device attributes\n");
  4323. goto out_release_irq;
  4324. }
  4325. iwl_set_rxon_channel(priv,
  4326. &priv->bands[IEEE80211_BAND_2GHZ].channels[5]);
  4327. iwl3945_setup_deferred_work(priv);
  4328. iwl3945_setup_rx_handlers(priv);
  4329. /*********************************
  4330. * 9. Setup and Register mac80211
  4331. * *******************************/
  4332. err = ieee80211_register_hw(priv->hw);
  4333. if (err) {
  4334. IWL_ERR(priv, "Failed to register network device: %d\n", err);
  4335. goto out_remove_sysfs;
  4336. }
  4337. priv->hw->conf.beacon_int = 100;
  4338. priv->mac80211_registered = 1;
  4339. err = iwl_rfkill_init(priv);
  4340. if (err)
  4341. IWL_ERR(priv, "Unable to initialize RFKILL system. "
  4342. "Ignoring error: %d\n", err);
  4343. /* Start monitoring the killswitch */
  4344. queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
  4345. 2 * HZ);
  4346. return 0;
  4347. out_remove_sysfs:
  4348. sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
  4349. out_free_geos:
  4350. iwlcore_free_geos(priv);
  4351. out_release_irq:
  4352. free_irq(priv->pci_dev->irq, priv);
  4353. destroy_workqueue(priv->workqueue);
  4354. priv->workqueue = NULL;
  4355. iwl3945_unset_hw_params(priv);
  4356. out_disable_msi:
  4357. pci_disable_msi(priv->pci_dev);
  4358. out_iounmap:
  4359. pci_iounmap(pdev, priv->hw_base);
  4360. out_pci_release_regions:
  4361. pci_release_regions(pdev);
  4362. out_pci_disable_device:
  4363. pci_disable_device(pdev);
  4364. pci_set_drvdata(pdev, NULL);
  4365. out_ieee80211_free_hw:
  4366. ieee80211_free_hw(priv->hw);
  4367. out:
  4368. return err;
  4369. }
  4370. static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
  4371. {
  4372. struct iwl_priv *priv = pci_get_drvdata(pdev);
  4373. unsigned long flags;
  4374. if (!priv)
  4375. return;
  4376. IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
  4377. set_bit(STATUS_EXIT_PENDING, &priv->status);
  4378. if (priv->mac80211_registered) {
  4379. ieee80211_unregister_hw(priv->hw);
  4380. priv->mac80211_registered = 0;
  4381. } else {
  4382. iwl3945_down(priv);
  4383. }
  4384. /* make sure we flush any pending irq or
  4385. * tasklet for the driver
  4386. */
  4387. spin_lock_irqsave(&priv->lock, flags);
  4388. iwl3945_disable_interrupts(priv);
  4389. spin_unlock_irqrestore(&priv->lock, flags);
  4390. iwl_synchronize_irq(priv);
  4391. sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
  4392. iwl_rfkill_unregister(priv);
  4393. cancel_delayed_work(&priv->rfkill_poll);
  4394. iwl3945_dealloc_ucode_pci(priv);
  4395. if (priv->rxq.bd)
  4396. iwl_rx_queue_free(priv, &priv->rxq);
  4397. iwl3945_hw_txq_ctx_free(priv);
  4398. iwl3945_unset_hw_params(priv);
  4399. iwl3945_clear_stations_table(priv);
  4400. /*netif_stop_queue(dev); */
  4401. flush_workqueue(priv->workqueue);
  4402. /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
  4403. * priv->workqueue... so we can't take down the workqueue
  4404. * until now... */
  4405. destroy_workqueue(priv->workqueue);
  4406. priv->workqueue = NULL;
  4407. free_irq(pdev->irq, priv);
  4408. pci_disable_msi(pdev);
  4409. pci_iounmap(pdev, priv->hw_base);
  4410. pci_release_regions(pdev);
  4411. pci_disable_device(pdev);
  4412. pci_set_drvdata(pdev, NULL);
  4413. iwl_free_channel_map(priv);
  4414. iwlcore_free_geos(priv);
  4415. kfree(priv->scan);
  4416. if (priv->ibss_beacon)
  4417. dev_kfree_skb(priv->ibss_beacon);
  4418. ieee80211_free_hw(priv->hw);
  4419. }
  4420. #ifdef CONFIG_PM
  4421. static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  4422. {
  4423. struct iwl_priv *priv = pci_get_drvdata(pdev);
  4424. if (priv->is_open) {
  4425. set_bit(STATUS_IN_SUSPEND, &priv->status);
  4426. iwl3945_mac_stop(priv->hw);
  4427. priv->is_open = 1;
  4428. }
  4429. pci_save_state(pdev);
  4430. pci_disable_device(pdev);
  4431. pci_set_power_state(pdev, PCI_D3hot);
  4432. return 0;
  4433. }
  4434. static int iwl3945_pci_resume(struct pci_dev *pdev)
  4435. {
  4436. struct iwl_priv *priv = pci_get_drvdata(pdev);
  4437. int ret;
  4438. pci_set_power_state(pdev, PCI_D0);
  4439. ret = pci_enable_device(pdev);
  4440. if (ret)
  4441. return ret;
  4442. pci_restore_state(pdev);
  4443. if (priv->is_open)
  4444. iwl3945_mac_start(priv->hw);
  4445. clear_bit(STATUS_IN_SUSPEND, &priv->status);
  4446. return 0;
  4447. }
  4448. #endif /* CONFIG_PM */
  4449. /*****************************************************************************
  4450. *
  4451. * driver and module entry point
  4452. *
  4453. *****************************************************************************/
  4454. static struct pci_driver iwl3945_driver = {
  4455. .name = DRV_NAME,
  4456. .id_table = iwl3945_hw_card_ids,
  4457. .probe = iwl3945_pci_probe,
  4458. .remove = __devexit_p(iwl3945_pci_remove),
  4459. #ifdef CONFIG_PM
  4460. .suspend = iwl3945_pci_suspend,
  4461. .resume = iwl3945_pci_resume,
  4462. #endif
  4463. };
  4464. static int __init iwl3945_init(void)
  4465. {
  4466. int ret;
  4467. printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
  4468. printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
  4469. ret = iwl3945_rate_control_register();
  4470. if (ret) {
  4471. printk(KERN_ERR DRV_NAME
  4472. "Unable to register rate control algorithm: %d\n", ret);
  4473. return ret;
  4474. }
  4475. ret = pci_register_driver(&iwl3945_driver);
  4476. if (ret) {
  4477. printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
  4478. goto error_register;
  4479. }
  4480. return ret;
  4481. error_register:
  4482. iwl3945_rate_control_unregister();
  4483. return ret;
  4484. }
  4485. static void __exit iwl3945_exit(void)
  4486. {
  4487. pci_unregister_driver(&iwl3945_driver);
  4488. iwl3945_rate_control_unregister();
  4489. }
  4490. MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
  4491. module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444);
  4492. MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
  4493. module_param_named(disable, iwl3945_mod_params.disable, int, 0444);
  4494. MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
  4495. module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444);
  4496. MODULE_PARM_DESC(swcrypto,
  4497. "using software crypto (default 1 [software])\n");
  4498. module_param_named(debug, iwl3945_mod_params.debug, uint, 0444);
  4499. MODULE_PARM_DESC(debug, "debug output mask");
  4500. module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, int, 0444);
  4501. MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
  4502. module_param_named(queues_num, iwl3945_mod_params.num_of_queues, int, 0444);
  4503. MODULE_PARM_DESC(queues_num, "number of hw queues.");
  4504. module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, 0444);
  4505. MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error");
  4506. module_exit(iwl3945_exit);
  4507. module_init(iwl3945_init);