iwl3945-base.c 155 KB

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