iwl4965-base.c 162 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
  4. *
  5. * Portions of this file are derived from the ipw3945 project, as well
  6. * as portions of the ieee80211 subsystem header files.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of version 2 of the GNU General Public License as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  20. *
  21. * The full GNU General Public License is included in this distribution in the
  22. * file called LICENSE.
  23. *
  24. * Contact Information:
  25. * James P. Ketrenos <ipw2100-admin@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/version.h>
  32. #include <linux/init.h>
  33. #include <linux/pci.h>
  34. #include <linux/dma-mapping.h>
  35. #include <linux/delay.h>
  36. #include <linux/skbuff.h>
  37. #include <linux/netdevice.h>
  38. #include <linux/wireless.h>
  39. #include <linux/firmware.h>
  40. #include <linux/etherdevice.h>
  41. #include <linux/if_arp.h>
  42. #include <net/mac80211.h>
  43. #include <asm/div64.h>
  44. #include "iwl-eeprom.h"
  45. #include "iwl-dev.h"
  46. #include "iwl-core.h"
  47. #include "iwl-io.h"
  48. #include "iwl-helpers.h"
  49. #include "iwl-sta.h"
  50. #include "iwl-calib.h"
  51. /******************************************************************************
  52. *
  53. * module boiler plate
  54. *
  55. ******************************************************************************/
  56. /*
  57. * module name, copyright, version, etc.
  58. * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
  59. */
  60. #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux"
  61. #ifdef CONFIG_IWLWIFI_DEBUG
  62. #define VD "d"
  63. #else
  64. #define VD
  65. #endif
  66. #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
  67. #define VS "s"
  68. #else
  69. #define VS
  70. #endif
  71. #define DRV_VERSION IWLWIFI_VERSION VD VS
  72. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  73. MODULE_VERSION(DRV_VERSION);
  74. MODULE_AUTHOR(DRV_COPYRIGHT);
  75. MODULE_LICENSE("GPL");
  76. static const struct ieee80211_supported_band *iwl_get_hw_mode(
  77. struct iwl_priv *priv, enum ieee80211_band band)
  78. {
  79. return priv->hw->wiphy->bands[band];
  80. }
  81. static int iwl4965_is_empty_essid(const char *essid, int essid_len)
  82. {
  83. /* Single white space is for Linksys APs */
  84. if (essid_len == 1 && essid[0] == ' ')
  85. return 1;
  86. /* Otherwise, if the entire essid is 0, we assume it is hidden */
  87. while (essid_len) {
  88. essid_len--;
  89. if (essid[essid_len] != '\0')
  90. return 0;
  91. }
  92. return 1;
  93. }
  94. static const char *iwl4965_escape_essid(const char *essid, u8 essid_len)
  95. {
  96. static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
  97. const char *s = essid;
  98. char *d = escaped;
  99. if (iwl4965_is_empty_essid(essid, essid_len)) {
  100. memcpy(escaped, "<hidden>", sizeof("<hidden>"));
  101. return escaped;
  102. }
  103. essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE);
  104. while (essid_len--) {
  105. if (*s == '\0') {
  106. *d++ = '\\';
  107. *d++ = '0';
  108. s++;
  109. } else
  110. *d++ = *s++;
  111. }
  112. *d = '\0';
  113. return escaped;
  114. }
  115. /*************** STATION TABLE MANAGEMENT ****
  116. * mac80211 should be examined to determine if sta_info is duplicating
  117. * the functionality provided here
  118. */
  119. /**************************************************************/
  120. #if 0 /* temporary disable till we add real remove station */
  121. /**
  122. * iwl4965_remove_station - Remove driver's knowledge of station.
  123. *
  124. * NOTE: This does not remove station from device's station table.
  125. */
  126. static u8 iwl4965_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
  127. {
  128. int index = IWL_INVALID_STATION;
  129. int i;
  130. unsigned long flags;
  131. spin_lock_irqsave(&priv->sta_lock, flags);
  132. if (is_ap)
  133. index = IWL_AP_ID;
  134. else if (is_broadcast_ether_addr(addr))
  135. index = priv->hw_params.bcast_sta_id;
  136. else
  137. for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
  138. if (priv->stations[i].used &&
  139. !compare_ether_addr(priv->stations[i].sta.sta.addr,
  140. addr)) {
  141. index = i;
  142. break;
  143. }
  144. if (unlikely(index == IWL_INVALID_STATION))
  145. goto out;
  146. if (priv->stations[index].used) {
  147. priv->stations[index].used = 0;
  148. priv->num_stations--;
  149. }
  150. BUG_ON(priv->num_stations < 0);
  151. out:
  152. spin_unlock_irqrestore(&priv->sta_lock, flags);
  153. return 0;
  154. }
  155. #endif
  156. static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
  157. {
  158. struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
  159. if (hw_decrypt)
  160. rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
  161. else
  162. rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
  163. }
  164. /**
  165. * iwl4965_check_rxon_cmd - validate RXON structure is valid
  166. *
  167. * NOTE: This is really only useful during development and can eventually
  168. * be #ifdef'd out once the driver is stable and folks aren't actively
  169. * making changes
  170. */
  171. static int iwl4965_check_rxon_cmd(struct iwl_rxon_cmd *rxon)
  172. {
  173. int error = 0;
  174. int counter = 1;
  175. if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
  176. error |= le32_to_cpu(rxon->flags &
  177. (RXON_FLG_TGJ_NARROW_BAND_MSK |
  178. RXON_FLG_RADAR_DETECT_MSK));
  179. if (error)
  180. IWL_WARNING("check 24G fields %d | %d\n",
  181. counter++, error);
  182. } else {
  183. error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
  184. 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
  185. if (error)
  186. IWL_WARNING("check 52 fields %d | %d\n",
  187. counter++, error);
  188. error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
  189. if (error)
  190. IWL_WARNING("check 52 CCK %d | %d\n",
  191. counter++, error);
  192. }
  193. error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
  194. if (error)
  195. IWL_WARNING("check mac addr %d | %d\n", counter++, error);
  196. /* make sure basic rates 6Mbps and 1Mbps are supported */
  197. error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
  198. ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
  199. if (error)
  200. IWL_WARNING("check basic rate %d | %d\n", counter++, error);
  201. error |= (le16_to_cpu(rxon->assoc_id) > 2007);
  202. if (error)
  203. IWL_WARNING("check assoc id %d | %d\n", counter++, error);
  204. error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
  205. == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
  206. if (error)
  207. IWL_WARNING("check CCK and short slot %d | %d\n",
  208. counter++, error);
  209. error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
  210. == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
  211. if (error)
  212. IWL_WARNING("check CCK & auto detect %d | %d\n",
  213. counter++, error);
  214. error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
  215. RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
  216. if (error)
  217. IWL_WARNING("check TGG and auto detect %d | %d\n",
  218. counter++, error);
  219. if (error)
  220. IWL_WARNING("Tuning to channel %d\n",
  221. le16_to_cpu(rxon->channel));
  222. if (error) {
  223. IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n");
  224. return -1;
  225. }
  226. return 0;
  227. }
  228. /**
  229. * iwl4965_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
  230. * @priv: staging_rxon is compared to active_rxon
  231. *
  232. * If the RXON structure is changing enough to require a new tune,
  233. * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
  234. * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
  235. */
  236. static int iwl4965_full_rxon_required(struct iwl_priv *priv)
  237. {
  238. /* These items are only settable from the full RXON command */
  239. if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ||
  240. compare_ether_addr(priv->staging_rxon.bssid_addr,
  241. priv->active_rxon.bssid_addr) ||
  242. compare_ether_addr(priv->staging_rxon.node_addr,
  243. priv->active_rxon.node_addr) ||
  244. compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
  245. priv->active_rxon.wlap_bssid_addr) ||
  246. (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
  247. (priv->staging_rxon.channel != priv->active_rxon.channel) ||
  248. (priv->staging_rxon.air_propagation !=
  249. priv->active_rxon.air_propagation) ||
  250. (priv->staging_rxon.ofdm_ht_single_stream_basic_rates !=
  251. priv->active_rxon.ofdm_ht_single_stream_basic_rates) ||
  252. (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates !=
  253. priv->active_rxon.ofdm_ht_dual_stream_basic_rates) ||
  254. (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) ||
  255. (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
  256. return 1;
  257. /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
  258. * be updated with the RXON_ASSOC command -- however only some
  259. * flag transitions are allowed using RXON_ASSOC */
  260. /* Check if we are not switching bands */
  261. if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
  262. (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
  263. return 1;
  264. /* Check if we are switching association toggle */
  265. if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
  266. (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
  267. return 1;
  268. return 0;
  269. }
  270. /**
  271. * iwl4965_commit_rxon - commit staging_rxon to hardware
  272. *
  273. * The RXON command in staging_rxon is committed to the hardware and
  274. * the active_rxon structure is updated with the new data. This
  275. * function correctly transitions out of the RXON_ASSOC_MSK state if
  276. * a HW tune is required based on the RXON structure changes.
  277. */
  278. static int iwl4965_commit_rxon(struct iwl_priv *priv)
  279. {
  280. /* cast away the const for active_rxon in this function */
  281. struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
  282. DECLARE_MAC_BUF(mac);
  283. int rc = 0;
  284. if (!iwl_is_alive(priv))
  285. return -1;
  286. /* always get timestamp with Rx frame */
  287. priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
  288. rc = iwl4965_check_rxon_cmd(&priv->staging_rxon);
  289. if (rc) {
  290. IWL_ERROR("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. * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
  295. * and other flags for the current radio configuration. */
  296. if (!iwl4965_full_rxon_required(priv)) {
  297. rc = iwl_send_rxon_assoc(priv);
  298. if (rc) {
  299. IWL_ERROR("Error setting RXON_ASSOC "
  300. "configuration (%d).\n", rc);
  301. return rc;
  302. }
  303. memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
  304. return 0;
  305. }
  306. /* station table will be cleared */
  307. priv->assoc_station_added = 0;
  308. /* If we are currently associated and the new config requires
  309. * an RXON_ASSOC and the new config wants the associated mask enabled,
  310. * we must clear the associated from the active configuration
  311. * before we apply the new config */
  312. if (iwl_is_associated(priv) &&
  313. (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) {
  314. IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
  315. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  316. rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
  317. sizeof(struct iwl_rxon_cmd),
  318. &priv->active_rxon);
  319. /* If the mask clearing failed then we set
  320. * active_rxon back to what it was previously */
  321. if (rc) {
  322. active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
  323. IWL_ERROR("Error clearing ASSOC_MSK on current "
  324. "configuration (%d).\n", rc);
  325. return rc;
  326. }
  327. }
  328. IWL_DEBUG_INFO("Sending RXON\n"
  329. "* with%s RXON_FILTER_ASSOC_MSK\n"
  330. "* channel = %d\n"
  331. "* bssid = %s\n",
  332. ((priv->staging_rxon.filter_flags &
  333. RXON_FILTER_ASSOC_MSK) ? "" : "out"),
  334. le16_to_cpu(priv->staging_rxon.channel),
  335. print_mac(mac, priv->staging_rxon.bssid_addr));
  336. iwl4965_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
  337. /* Apply the new configuration */
  338. rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
  339. sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
  340. if (rc) {
  341. IWL_ERROR("Error setting new configuration (%d).\n", rc);
  342. return rc;
  343. }
  344. iwlcore_clear_stations_table(priv);
  345. if (!priv->error_recovering)
  346. priv->start_calib = 0;
  347. iwl_init_sensitivity(priv);
  348. memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
  349. /* If we issue a new RXON command which required a tune then we must
  350. * send a new TXPOWER command or we won't be able to Tx any frames */
  351. rc = iwl4965_hw_reg_send_txpower(priv);
  352. if (rc) {
  353. IWL_ERROR("Error setting Tx power (%d).\n", rc);
  354. return rc;
  355. }
  356. /* Add the broadcast address so we can send broadcast frames */
  357. if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) ==
  358. IWL_INVALID_STATION) {
  359. IWL_ERROR("Error adding BROADCAST address for transmit.\n");
  360. return -EIO;
  361. }
  362. /* If we have set the ASSOC_MSK and we are in BSS mode then
  363. * add the IWL_AP_ID to the station rate table */
  364. if (iwl_is_associated(priv) &&
  365. (priv->iw_mode == IEEE80211_IF_TYPE_STA)) {
  366. if (iwl_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1)
  367. == IWL_INVALID_STATION) {
  368. IWL_ERROR("Error adding AP address for transmit.\n");
  369. return -EIO;
  370. }
  371. priv->assoc_station_added = 1;
  372. if (priv->default_wep_key &&
  373. iwl_send_static_wepkey_cmd(priv, 0))
  374. IWL_ERROR("Could not send WEP static key.\n");
  375. }
  376. return 0;
  377. }
  378. void iwl4965_update_chain_flags(struct iwl_priv *priv)
  379. {
  380. iwl_set_rxon_chain(priv);
  381. iwl4965_commit_rxon(priv);
  382. }
  383. static int iwl4965_send_bt_config(struct iwl_priv *priv)
  384. {
  385. struct iwl4965_bt_cmd bt_cmd = {
  386. .flags = 3,
  387. .lead_time = 0xAA,
  388. .max_kill = 1,
  389. .kill_ack_mask = 0,
  390. .kill_cts_mask = 0,
  391. };
  392. return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  393. sizeof(struct iwl4965_bt_cmd), &bt_cmd);
  394. }
  395. static int iwl4965_send_scan_abort(struct iwl_priv *priv)
  396. {
  397. int ret = 0;
  398. struct iwl_rx_packet *res;
  399. struct iwl_host_cmd cmd = {
  400. .id = REPLY_SCAN_ABORT_CMD,
  401. .meta.flags = CMD_WANT_SKB,
  402. };
  403. /* If there isn't a scan actively going on in the hardware
  404. * then we are in between scan bands and not actually
  405. * actively scanning, so don't send the abort command */
  406. if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
  407. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  408. return 0;
  409. }
  410. ret = iwl_send_cmd_sync(priv, &cmd);
  411. if (ret) {
  412. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  413. return ret;
  414. }
  415. res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
  416. if (res->u.status != CAN_ABORT_STATUS) {
  417. /* The scan abort will return 1 for success or
  418. * 2 for "failure". A failure condition can be
  419. * due to simply not being in an active scan which
  420. * can occur if we send the scan abort before we
  421. * the microcode has notified us that a scan is
  422. * completed. */
  423. IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status);
  424. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  425. clear_bit(STATUS_SCAN_HW, &priv->status);
  426. }
  427. dev_kfree_skb_any(cmd.meta.u.skb);
  428. return ret;
  429. }
  430. /*
  431. * CARD_STATE_CMD
  432. *
  433. * Use: Sets the device's internal card state to enable, disable, or halt
  434. *
  435. * When in the 'enable' state the card operates as normal.
  436. * When in the 'disable' state, the card enters into a low power mode.
  437. * When in the 'halt' state, the card is shut down and must be fully
  438. * restarted to come back on.
  439. */
  440. static int iwl4965_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag)
  441. {
  442. struct iwl_host_cmd cmd = {
  443. .id = REPLY_CARD_STATE_CMD,
  444. .len = sizeof(u32),
  445. .data = &flags,
  446. .meta.flags = meta_flag,
  447. };
  448. return iwl_send_cmd(priv, &cmd);
  449. }
  450. static void iwl_clear_free_frames(struct iwl_priv *priv)
  451. {
  452. struct list_head *element;
  453. IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
  454. priv->frames_count);
  455. while (!list_empty(&priv->free_frames)) {
  456. element = priv->free_frames.next;
  457. list_del(element);
  458. kfree(list_entry(element, struct iwl_frame, list));
  459. priv->frames_count--;
  460. }
  461. if (priv->frames_count) {
  462. IWL_WARNING("%d frames still in use. Did we lose one?\n",
  463. priv->frames_count);
  464. priv->frames_count = 0;
  465. }
  466. }
  467. static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
  468. {
  469. struct iwl_frame *frame;
  470. struct list_head *element;
  471. if (list_empty(&priv->free_frames)) {
  472. frame = kzalloc(sizeof(*frame), GFP_KERNEL);
  473. if (!frame) {
  474. IWL_ERROR("Could not allocate frame!\n");
  475. return NULL;
  476. }
  477. priv->frames_count++;
  478. return frame;
  479. }
  480. element = priv->free_frames.next;
  481. list_del(element);
  482. return list_entry(element, struct iwl_frame, list);
  483. }
  484. static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
  485. {
  486. memset(frame, 0, sizeof(*frame));
  487. list_add(&frame->list, &priv->free_frames);
  488. }
  489. unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv,
  490. struct ieee80211_hdr *hdr,
  491. const u8 *dest, int left)
  492. {
  493. if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
  494. ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) &&
  495. (priv->iw_mode != IEEE80211_IF_TYPE_AP)))
  496. return 0;
  497. if (priv->ibss_beacon->len > left)
  498. return 0;
  499. memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
  500. return priv->ibss_beacon->len;
  501. }
  502. static u8 iwl4965_rate_get_lowest_plcp(struct iwl_priv *priv)
  503. {
  504. int i;
  505. int rate_mask;
  506. /* Set rate mask*/
  507. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
  508. rate_mask = priv->active_rate_basic & 0xF;
  509. else
  510. rate_mask = priv->active_rate_basic & 0xFF0;
  511. /* Find lowest valid rate */
  512. for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
  513. i = iwl_rates[i].next_ieee) {
  514. if (rate_mask & (1 << i))
  515. return iwl_rates[i].plcp;
  516. }
  517. /* No valid rate was found. Assign the lowest one */
  518. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
  519. return IWL_RATE_1M_PLCP;
  520. else
  521. return IWL_RATE_6M_PLCP;
  522. }
  523. static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
  524. {
  525. struct iwl_frame *frame;
  526. unsigned int frame_size;
  527. int rc;
  528. u8 rate;
  529. frame = iwl_get_free_frame(priv);
  530. if (!frame) {
  531. IWL_ERROR("Could not obtain free frame buffer for beacon "
  532. "command.\n");
  533. return -ENOMEM;
  534. }
  535. rate = iwl4965_rate_get_lowest_plcp(priv);
  536. frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate);
  537. rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
  538. &frame->u.cmd[0]);
  539. iwl_free_frame(priv, frame);
  540. return rc;
  541. }
  542. /******************************************************************************
  543. *
  544. * Misc. internal state and helper functions
  545. *
  546. ******************************************************************************/
  547. /**
  548. * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field
  549. *
  550. * return : set the bit for each supported rate insert in ie
  551. */
  552. static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate,
  553. u16 basic_rate, int *left)
  554. {
  555. u16 ret_rates = 0, bit;
  556. int i;
  557. u8 *cnt = ie;
  558. u8 *rates = ie + 1;
  559. for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) {
  560. if (bit & supported_rate) {
  561. ret_rates |= bit;
  562. rates[*cnt] = iwl_rates[i].ieee |
  563. ((bit & basic_rate) ? 0x80 : 0x00);
  564. (*cnt)++;
  565. (*left)--;
  566. if ((*left <= 0) ||
  567. (*cnt >= IWL_SUPPORTED_RATES_IE_LEN))
  568. break;
  569. }
  570. }
  571. return ret_rates;
  572. }
  573. #ifdef CONFIG_IWL4965_HT
  574. static void iwl4965_ht_conf(struct iwl_priv *priv,
  575. struct ieee80211_bss_conf *bss_conf)
  576. {
  577. struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf;
  578. struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf;
  579. struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
  580. IWL_DEBUG_MAC80211("enter: \n");
  581. iwl_conf->is_ht = bss_conf->assoc_ht;
  582. if (!iwl_conf->is_ht)
  583. return;
  584. priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
  585. if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
  586. iwl_conf->sgf |= HT_SHORT_GI_20MHZ;
  587. if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
  588. iwl_conf->sgf |= HT_SHORT_GI_40MHZ;
  589. iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
  590. iwl_conf->max_amsdu_size =
  591. !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
  592. iwl_conf->supported_chan_width =
  593. !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH);
  594. iwl_conf->extension_chan_offset =
  595. ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET;
  596. /* If no above or below channel supplied disable FAT channel */
  597. if (iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_ABOVE &&
  598. iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_BELOW)
  599. iwl_conf->supported_chan_width = 0;
  600. iwl_conf->tx_mimo_ps_mode =
  601. (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
  602. memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16);
  603. iwl_conf->control_channel = ht_bss_conf->primary_channel;
  604. iwl_conf->tx_chan_width =
  605. !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH);
  606. iwl_conf->ht_protection =
  607. ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION;
  608. iwl_conf->non_GF_STA_present =
  609. !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT);
  610. IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel);
  611. IWL_DEBUG_MAC80211("leave\n");
  612. }
  613. static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband,
  614. u8 *pos, int *left)
  615. {
  616. struct ieee80211_ht_cap *ht_cap;
  617. if (!sband || !sband->ht_info.ht_supported)
  618. return;
  619. if (*left < sizeof(struct ieee80211_ht_cap))
  620. return;
  621. *pos++ = sizeof(struct ieee80211_ht_cap);
  622. ht_cap = (struct ieee80211_ht_cap *) pos;
  623. ht_cap->cap_info = cpu_to_le16(sband->ht_info.cap);
  624. memcpy(ht_cap->supp_mcs_set, sband->ht_info.supp_mcs_set, 16);
  625. ht_cap->ampdu_params_info =
  626. (sband->ht_info.ampdu_factor & IEEE80211_HT_CAP_AMPDU_FACTOR) |
  627. ((sband->ht_info.ampdu_density << 2) &
  628. IEEE80211_HT_CAP_AMPDU_DENSITY);
  629. *left -= sizeof(struct ieee80211_ht_cap);
  630. }
  631. #else
  632. static inline void iwl4965_ht_conf(struct iwl_priv *priv,
  633. struct ieee80211_bss_conf *bss_conf)
  634. {
  635. }
  636. static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband,
  637. u8 *pos, int *left)
  638. {
  639. }
  640. #endif
  641. /**
  642. * iwl4965_fill_probe_req - fill in all required fields and IE for probe request
  643. */
  644. static u16 iwl4965_fill_probe_req(struct iwl_priv *priv,
  645. enum ieee80211_band band,
  646. struct ieee80211_mgmt *frame,
  647. int left, int is_direct)
  648. {
  649. int len = 0;
  650. u8 *pos = NULL;
  651. u16 active_rates, ret_rates, cck_rates, active_rate_basic;
  652. const struct ieee80211_supported_band *sband =
  653. iwl_get_hw_mode(priv, band);
  654. /* Make sure there is enough space for the probe request,
  655. * two mandatory IEs and the data */
  656. left -= 24;
  657. if (left < 0)
  658. return 0;
  659. len += 24;
  660. frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
  661. memcpy(frame->da, iwl_bcast_addr, ETH_ALEN);
  662. memcpy(frame->sa, priv->mac_addr, ETH_ALEN);
  663. memcpy(frame->bssid, iwl_bcast_addr, ETH_ALEN);
  664. frame->seq_ctrl = 0;
  665. /* fill in our indirect SSID IE */
  666. /* ...next IE... */
  667. left -= 2;
  668. if (left < 0)
  669. return 0;
  670. len += 2;
  671. pos = &(frame->u.probe_req.variable[0]);
  672. *pos++ = WLAN_EID_SSID;
  673. *pos++ = 0;
  674. /* fill in our direct SSID IE... */
  675. if (is_direct) {
  676. /* ...next IE... */
  677. left -= 2 + priv->essid_len;
  678. if (left < 0)
  679. return 0;
  680. /* ... fill it in... */
  681. *pos++ = WLAN_EID_SSID;
  682. *pos++ = priv->essid_len;
  683. memcpy(pos, priv->essid, priv->essid_len);
  684. pos += priv->essid_len;
  685. len += 2 + priv->essid_len;
  686. }
  687. /* fill in supported rate */
  688. /* ...next IE... */
  689. left -= 2;
  690. if (left < 0)
  691. return 0;
  692. /* ... fill it in... */
  693. *pos++ = WLAN_EID_SUPP_RATES;
  694. *pos = 0;
  695. /* exclude 60M rate */
  696. active_rates = priv->rates_mask;
  697. active_rates &= ~IWL_RATE_60M_MASK;
  698. active_rate_basic = active_rates & IWL_BASIC_RATES_MASK;
  699. cck_rates = IWL_CCK_RATES_MASK & active_rates;
  700. ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates,
  701. active_rate_basic, &left);
  702. active_rates &= ~ret_rates;
  703. ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates,
  704. active_rate_basic, &left);
  705. active_rates &= ~ret_rates;
  706. len += 2 + *pos;
  707. pos += (*pos) + 1;
  708. if (active_rates == 0)
  709. goto fill_end;
  710. /* fill in supported extended rate */
  711. /* ...next IE... */
  712. left -= 2;
  713. if (left < 0)
  714. return 0;
  715. /* ... fill it in... */
  716. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  717. *pos = 0;
  718. iwl4965_supported_rate_to_ie(pos, active_rates,
  719. active_rate_basic, &left);
  720. if (*pos > 0)
  721. len += 2 + *pos;
  722. fill_end:
  723. /* fill in HT IE */
  724. left -= 2;
  725. if (left < 0)
  726. return 0;
  727. *pos++ = WLAN_EID_HT_CAPABILITY;
  728. *pos = 0;
  729. iwl_ht_cap_to_ie(sband, pos, &left);
  730. if (*pos > 0)
  731. len += 2 + *pos;
  732. return (u16)len;
  733. }
  734. /*
  735. * QoS support
  736. */
  737. static int iwl4965_send_qos_params_command(struct iwl_priv *priv,
  738. struct iwl4965_qosparam_cmd *qos)
  739. {
  740. return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM,
  741. sizeof(struct iwl4965_qosparam_cmd), qos);
  742. }
  743. static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force)
  744. {
  745. unsigned long flags;
  746. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  747. return;
  748. if (!priv->qos_data.qos_enable)
  749. return;
  750. spin_lock_irqsave(&priv->lock, flags);
  751. priv->qos_data.def_qos_parm.qos_flags = 0;
  752. if (priv->qos_data.qos_cap.q_AP.queue_request &&
  753. !priv->qos_data.qos_cap.q_AP.txop_request)
  754. priv->qos_data.def_qos_parm.qos_flags |=
  755. QOS_PARAM_FLG_TXOP_TYPE_MSK;
  756. if (priv->qos_data.qos_active)
  757. priv->qos_data.def_qos_parm.qos_flags |=
  758. QOS_PARAM_FLG_UPDATE_EDCA_MSK;
  759. #ifdef CONFIG_IWL4965_HT
  760. if (priv->current_ht_config.is_ht)
  761. priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
  762. #endif /* CONFIG_IWL4965_HT */
  763. spin_unlock_irqrestore(&priv->lock, flags);
  764. if (force || iwl_is_associated(priv)) {
  765. IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
  766. priv->qos_data.qos_active,
  767. priv->qos_data.def_qos_parm.qos_flags);
  768. iwl4965_send_qos_params_command(priv,
  769. &(priv->qos_data.def_qos_parm));
  770. }
  771. }
  772. int iwl4965_is_network_packet(struct iwl_priv *priv, struct ieee80211_hdr *header)
  773. {
  774. /* Filter incoming packets to determine if they are targeted toward
  775. * this network, discarding packets coming from ourselves */
  776. switch (priv->iw_mode) {
  777. case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */
  778. /* packets from our adapter are dropped (echo) */
  779. if (!compare_ether_addr(header->addr2, priv->mac_addr))
  780. return 0;
  781. /* {broad,multi}cast packets to our IBSS go through */
  782. if (is_multicast_ether_addr(header->addr1))
  783. return !compare_ether_addr(header->addr3, priv->bssid);
  784. /* packets to our adapter go through */
  785. return !compare_ether_addr(header->addr1, priv->mac_addr);
  786. case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */
  787. /* packets from our adapter are dropped (echo) */
  788. if (!compare_ether_addr(header->addr3, priv->mac_addr))
  789. return 0;
  790. /* {broad,multi}cast packets to our BSS go through */
  791. if (is_multicast_ether_addr(header->addr1))
  792. return !compare_ether_addr(header->addr2, priv->bssid);
  793. /* packets to our adapter go through */
  794. return !compare_ether_addr(header->addr1, priv->mac_addr);
  795. default:
  796. break;
  797. }
  798. return 1;
  799. }
  800. #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
  801. static const char *iwl4965_get_tx_fail_reason(u32 status)
  802. {
  803. switch (status & TX_STATUS_MSK) {
  804. case TX_STATUS_SUCCESS:
  805. return "SUCCESS";
  806. TX_STATUS_ENTRY(SHORT_LIMIT);
  807. TX_STATUS_ENTRY(LONG_LIMIT);
  808. TX_STATUS_ENTRY(FIFO_UNDERRUN);
  809. TX_STATUS_ENTRY(MGMNT_ABORT);
  810. TX_STATUS_ENTRY(NEXT_FRAG);
  811. TX_STATUS_ENTRY(LIFE_EXPIRE);
  812. TX_STATUS_ENTRY(DEST_PS);
  813. TX_STATUS_ENTRY(ABORTED);
  814. TX_STATUS_ENTRY(BT_RETRY);
  815. TX_STATUS_ENTRY(STA_INVALID);
  816. TX_STATUS_ENTRY(FRAG_DROPPED);
  817. TX_STATUS_ENTRY(TID_DISABLE);
  818. TX_STATUS_ENTRY(FRAME_FLUSHED);
  819. TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL);
  820. TX_STATUS_ENTRY(TX_LOCKED);
  821. TX_STATUS_ENTRY(NO_BEACON_ON_RADAR);
  822. }
  823. return "UNKNOWN";
  824. }
  825. /**
  826. * iwl4965_scan_cancel - Cancel any currently executing HW scan
  827. *
  828. * NOTE: priv->mutex is not required before calling this function
  829. */
  830. static int iwl4965_scan_cancel(struct iwl_priv *priv)
  831. {
  832. if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
  833. clear_bit(STATUS_SCANNING, &priv->status);
  834. return 0;
  835. }
  836. if (test_bit(STATUS_SCANNING, &priv->status)) {
  837. if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  838. IWL_DEBUG_SCAN("Queuing scan abort.\n");
  839. set_bit(STATUS_SCAN_ABORTING, &priv->status);
  840. queue_work(priv->workqueue, &priv->abort_scan);
  841. } else
  842. IWL_DEBUG_SCAN("Scan abort already in progress.\n");
  843. return test_bit(STATUS_SCANNING, &priv->status);
  844. }
  845. return 0;
  846. }
  847. /**
  848. * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan
  849. * @ms: amount of time to wait (in milliseconds) for scan to abort
  850. *
  851. * NOTE: priv->mutex must be held before calling this function
  852. */
  853. static int iwl4965_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms)
  854. {
  855. unsigned long now = jiffies;
  856. int ret;
  857. ret = iwl4965_scan_cancel(priv);
  858. if (ret && ms) {
  859. mutex_unlock(&priv->mutex);
  860. while (!time_after(jiffies, now + msecs_to_jiffies(ms)) &&
  861. test_bit(STATUS_SCANNING, &priv->status))
  862. msleep(1);
  863. mutex_lock(&priv->mutex);
  864. return test_bit(STATUS_SCANNING, &priv->status);
  865. }
  866. return ret;
  867. }
  868. static void iwl4965_sequence_reset(struct iwl_priv *priv)
  869. {
  870. /* Reset ieee stats */
  871. /* We don't reset the net_device_stats (ieee->stats) on
  872. * re-association */
  873. priv->last_seq_num = -1;
  874. priv->last_frag_num = -1;
  875. priv->last_packet_time = 0;
  876. iwl4965_scan_cancel(priv);
  877. }
  878. #define MAX_UCODE_BEACON_INTERVAL 4096
  879. #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
  880. static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val)
  881. {
  882. u16 new_val = 0;
  883. u16 beacon_factor = 0;
  884. beacon_factor =
  885. (beacon_val + MAX_UCODE_BEACON_INTERVAL)
  886. / MAX_UCODE_BEACON_INTERVAL;
  887. new_val = beacon_val / beacon_factor;
  888. return cpu_to_le16(new_val);
  889. }
  890. static void iwl4965_setup_rxon_timing(struct iwl_priv *priv)
  891. {
  892. u64 interval_tm_unit;
  893. u64 tsf, result;
  894. unsigned long flags;
  895. struct ieee80211_conf *conf = NULL;
  896. u16 beacon_int = 0;
  897. conf = ieee80211_get_hw_conf(priv->hw);
  898. spin_lock_irqsave(&priv->lock, flags);
  899. priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp >> 32);
  900. priv->rxon_timing.timestamp.dw[0] =
  901. cpu_to_le32(priv->timestamp & 0xFFFFFFFF);
  902. priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
  903. tsf = priv->timestamp;
  904. beacon_int = priv->beacon_int;
  905. spin_unlock_irqrestore(&priv->lock, flags);
  906. if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
  907. if (beacon_int == 0) {
  908. priv->rxon_timing.beacon_interval = cpu_to_le16(100);
  909. priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
  910. } else {
  911. priv->rxon_timing.beacon_interval =
  912. cpu_to_le16(beacon_int);
  913. priv->rxon_timing.beacon_interval =
  914. iwl4965_adjust_beacon_interval(
  915. le16_to_cpu(priv->rxon_timing.beacon_interval));
  916. }
  917. priv->rxon_timing.atim_window = 0;
  918. } else {
  919. priv->rxon_timing.beacon_interval =
  920. iwl4965_adjust_beacon_interval(conf->beacon_int);
  921. /* TODO: we need to get atim_window from upper stack
  922. * for now we set to 0 */
  923. priv->rxon_timing.atim_window = 0;
  924. }
  925. interval_tm_unit =
  926. (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
  927. result = do_div(tsf, interval_tm_unit);
  928. priv->rxon_timing.beacon_init_val =
  929. cpu_to_le32((u32) ((u64) interval_tm_unit - result));
  930. IWL_DEBUG_ASSOC
  931. ("beacon interval %d beacon timer %d beacon tim %d\n",
  932. le16_to_cpu(priv->rxon_timing.beacon_interval),
  933. le32_to_cpu(priv->rxon_timing.beacon_init_val),
  934. le16_to_cpu(priv->rxon_timing.atim_window));
  935. }
  936. static int iwl4965_scan_initiate(struct iwl_priv *priv)
  937. {
  938. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  939. IWL_ERROR("APs don't scan.\n");
  940. return 0;
  941. }
  942. if (!iwl_is_ready_rf(priv)) {
  943. IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
  944. return -EIO;
  945. }
  946. if (test_bit(STATUS_SCANNING, &priv->status)) {
  947. IWL_DEBUG_SCAN("Scan already in progress.\n");
  948. return -EAGAIN;
  949. }
  950. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  951. IWL_DEBUG_SCAN("Scan request while abort pending. "
  952. "Queuing.\n");
  953. return -EAGAIN;
  954. }
  955. IWL_DEBUG_INFO("Starting scan...\n");
  956. priv->scan_bands = 2;
  957. set_bit(STATUS_SCANNING, &priv->status);
  958. priv->scan_start = jiffies;
  959. priv->scan_pass_start = priv->scan_start;
  960. queue_work(priv->workqueue, &priv->request_scan);
  961. return 0;
  962. }
  963. static void iwl4965_set_flags_for_phymode(struct iwl_priv *priv,
  964. enum ieee80211_band band)
  965. {
  966. if (band == IEEE80211_BAND_5GHZ) {
  967. priv->staging_rxon.flags &=
  968. ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
  969. | RXON_FLG_CCK_MSK);
  970. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  971. } else {
  972. /* Copied from iwl4965_post_associate() */
  973. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
  974. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  975. else
  976. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  977. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  978. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  979. priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
  980. priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
  981. priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
  982. }
  983. }
  984. /*
  985. * initialize rxon structure with default values from eeprom
  986. */
  987. static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
  988. {
  989. const struct iwl_channel_info *ch_info;
  990. memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
  991. switch (priv->iw_mode) {
  992. case IEEE80211_IF_TYPE_AP:
  993. priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
  994. break;
  995. case IEEE80211_IF_TYPE_STA:
  996. priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
  997. priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
  998. break;
  999. case IEEE80211_IF_TYPE_IBSS:
  1000. priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
  1001. priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
  1002. priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
  1003. RXON_FILTER_ACCEPT_GRP_MSK;
  1004. break;
  1005. case IEEE80211_IF_TYPE_MNTR:
  1006. priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
  1007. priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
  1008. RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
  1009. break;
  1010. default:
  1011. IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode);
  1012. break;
  1013. }
  1014. #if 0
  1015. /* TODO: Figure out when short_preamble would be set and cache from
  1016. * that */
  1017. if (!hw_to_local(priv->hw)->short_preamble)
  1018. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  1019. else
  1020. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  1021. #endif
  1022. ch_info = iwl_get_channel_info(priv, priv->band,
  1023. le16_to_cpu(priv->staging_rxon.channel));
  1024. if (!ch_info)
  1025. ch_info = &priv->channel_info[0];
  1026. /*
  1027. * in some case A channels are all non IBSS
  1028. * in this case force B/G channel
  1029. */
  1030. if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
  1031. !(is_channel_ibss(ch_info)))
  1032. ch_info = &priv->channel_info[0];
  1033. priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
  1034. priv->band = ch_info->band;
  1035. iwl4965_set_flags_for_phymode(priv, priv->band);
  1036. priv->staging_rxon.ofdm_basic_rates =
  1037. (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  1038. priv->staging_rxon.cck_basic_rates =
  1039. (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  1040. priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
  1041. RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
  1042. memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  1043. memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
  1044. priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
  1045. priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
  1046. iwl_set_rxon_chain(priv);
  1047. }
  1048. static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
  1049. {
  1050. if (mode == IEEE80211_IF_TYPE_IBSS) {
  1051. const struct iwl_channel_info *ch_info;
  1052. ch_info = iwl_get_channel_info(priv,
  1053. priv->band,
  1054. le16_to_cpu(priv->staging_rxon.channel));
  1055. if (!ch_info || !is_channel_ibss(ch_info)) {
  1056. IWL_ERROR("channel %d not IBSS channel\n",
  1057. le16_to_cpu(priv->staging_rxon.channel));
  1058. return -EINVAL;
  1059. }
  1060. }
  1061. priv->iw_mode = mode;
  1062. iwl4965_connection_init_rx_config(priv);
  1063. memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  1064. iwlcore_clear_stations_table(priv);
  1065. /* dont commit rxon if rf-kill is on*/
  1066. if (!iwl_is_ready_rf(priv))
  1067. return -EAGAIN;
  1068. cancel_delayed_work(&priv->scan_check);
  1069. if (iwl4965_scan_cancel_timeout(priv, 100)) {
  1070. IWL_WARNING("Aborted scan still in progress after 100ms\n");
  1071. IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
  1072. return -EAGAIN;
  1073. }
  1074. iwl4965_commit_rxon(priv);
  1075. return 0;
  1076. }
  1077. static void iwl4965_set_rate(struct iwl_priv *priv)
  1078. {
  1079. const struct ieee80211_supported_band *hw = NULL;
  1080. struct ieee80211_rate *rate;
  1081. int i;
  1082. hw = iwl_get_hw_mode(priv, priv->band);
  1083. if (!hw) {
  1084. IWL_ERROR("Failed to set rate: unable to get hw mode\n");
  1085. return;
  1086. }
  1087. priv->active_rate = 0;
  1088. priv->active_rate_basic = 0;
  1089. for (i = 0; i < hw->n_bitrates; i++) {
  1090. rate = &(hw->bitrates[i]);
  1091. if (rate->hw_value < IWL_RATE_COUNT)
  1092. priv->active_rate |= (1 << rate->hw_value);
  1093. }
  1094. IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
  1095. priv->active_rate, priv->active_rate_basic);
  1096. /*
  1097. * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
  1098. * otherwise set it to the default of all CCK rates and 6, 12, 24 for
  1099. * OFDM
  1100. */
  1101. if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
  1102. priv->staging_rxon.cck_basic_rates =
  1103. ((priv->active_rate_basic &
  1104. IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
  1105. else
  1106. priv->staging_rxon.cck_basic_rates =
  1107. (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  1108. if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
  1109. priv->staging_rxon.ofdm_basic_rates =
  1110. ((priv->active_rate_basic &
  1111. (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
  1112. IWL_FIRST_OFDM_RATE) & 0xFF;
  1113. else
  1114. priv->staging_rxon.ofdm_basic_rates =
  1115. (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  1116. }
  1117. void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
  1118. {
  1119. unsigned long flags;
  1120. if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
  1121. return;
  1122. IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
  1123. disable_radio ? "OFF" : "ON");
  1124. if (disable_radio) {
  1125. iwl4965_scan_cancel(priv);
  1126. /* FIXME: This is a workaround for AP */
  1127. if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
  1128. spin_lock_irqsave(&priv->lock, flags);
  1129. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  1130. CSR_UCODE_SW_BIT_RFKILL);
  1131. spin_unlock_irqrestore(&priv->lock, flags);
  1132. /* call the host command only if no hw rf-kill set */
  1133. if (!test_bit(STATUS_RF_KILL_HW, &priv->status) &&
  1134. iwl_is_ready(priv))
  1135. iwl4965_send_card_state(priv,
  1136. CARD_STATE_CMD_DISABLE,
  1137. 0);
  1138. set_bit(STATUS_RF_KILL_SW, &priv->status);
  1139. /* make sure mac80211 stop sending Tx frame */
  1140. if (priv->mac80211_registered)
  1141. ieee80211_stop_queues(priv->hw);
  1142. }
  1143. return;
  1144. }
  1145. spin_lock_irqsave(&priv->lock, flags);
  1146. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  1147. clear_bit(STATUS_RF_KILL_SW, &priv->status);
  1148. spin_unlock_irqrestore(&priv->lock, flags);
  1149. /* wake up ucode */
  1150. msleep(10);
  1151. spin_lock_irqsave(&priv->lock, flags);
  1152. iwl_read32(priv, CSR_UCODE_DRV_GP1);
  1153. if (!iwl_grab_nic_access(priv))
  1154. iwl_release_nic_access(priv);
  1155. spin_unlock_irqrestore(&priv->lock, flags);
  1156. if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
  1157. IWL_DEBUG_RF_KILL("Can not turn radio back on - "
  1158. "disabled by HW switch\n");
  1159. return;
  1160. }
  1161. queue_work(priv->workqueue, &priv->restart);
  1162. return;
  1163. }
  1164. #define IWL_PACKET_RETRY_TIME HZ
  1165. int iwl4965_is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header)
  1166. {
  1167. u16 sc = le16_to_cpu(header->seq_ctrl);
  1168. u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
  1169. u16 frag = sc & IEEE80211_SCTL_FRAG;
  1170. u16 *last_seq, *last_frag;
  1171. unsigned long *last_time;
  1172. switch (priv->iw_mode) {
  1173. case IEEE80211_IF_TYPE_IBSS:{
  1174. struct list_head *p;
  1175. struct iwl4965_ibss_seq *entry = NULL;
  1176. u8 *mac = header->addr2;
  1177. int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1);
  1178. __list_for_each(p, &priv->ibss_mac_hash[index]) {
  1179. entry = list_entry(p, struct iwl4965_ibss_seq, list);
  1180. if (!compare_ether_addr(entry->mac, mac))
  1181. break;
  1182. }
  1183. if (p == &priv->ibss_mac_hash[index]) {
  1184. entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
  1185. if (!entry) {
  1186. IWL_ERROR("Cannot malloc new mac entry\n");
  1187. return 0;
  1188. }
  1189. memcpy(entry->mac, mac, ETH_ALEN);
  1190. entry->seq_num = seq;
  1191. entry->frag_num = frag;
  1192. entry->packet_time = jiffies;
  1193. list_add(&entry->list, &priv->ibss_mac_hash[index]);
  1194. return 0;
  1195. }
  1196. last_seq = &entry->seq_num;
  1197. last_frag = &entry->frag_num;
  1198. last_time = &entry->packet_time;
  1199. break;
  1200. }
  1201. case IEEE80211_IF_TYPE_STA:
  1202. last_seq = &priv->last_seq_num;
  1203. last_frag = &priv->last_frag_num;
  1204. last_time = &priv->last_packet_time;
  1205. break;
  1206. default:
  1207. return 0;
  1208. }
  1209. if ((*last_seq == seq) &&
  1210. time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) {
  1211. if (*last_frag == frag)
  1212. goto drop;
  1213. if (*last_frag + 1 != frag)
  1214. /* out-of-order fragment */
  1215. goto drop;
  1216. } else
  1217. *last_seq = seq;
  1218. *last_frag = frag;
  1219. *last_time = jiffies;
  1220. return 0;
  1221. drop:
  1222. return 1;
  1223. }
  1224. #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
  1225. #include "iwl-spectrum.h"
  1226. #define BEACON_TIME_MASK_LOW 0x00FFFFFF
  1227. #define BEACON_TIME_MASK_HIGH 0xFF000000
  1228. #define TIME_UNIT 1024
  1229. /*
  1230. * extended beacon time format
  1231. * time in usec will be changed into a 32-bit value in 8:24 format
  1232. * the high 1 byte is the beacon counts
  1233. * the lower 3 bytes is the time in usec within one beacon interval
  1234. */
  1235. static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval)
  1236. {
  1237. u32 quot;
  1238. u32 rem;
  1239. u32 interval = beacon_interval * 1024;
  1240. if (!interval || !usec)
  1241. return 0;
  1242. quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
  1243. rem = (usec % interval) & BEACON_TIME_MASK_LOW;
  1244. return (quot << 24) + rem;
  1245. }
  1246. /* base is usually what we get from ucode with each received frame,
  1247. * the same as HW timer counter counting down
  1248. */
  1249. static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
  1250. {
  1251. u32 base_low = base & BEACON_TIME_MASK_LOW;
  1252. u32 addon_low = addon & BEACON_TIME_MASK_LOW;
  1253. u32 interval = beacon_interval * TIME_UNIT;
  1254. u32 res = (base & BEACON_TIME_MASK_HIGH) +
  1255. (addon & BEACON_TIME_MASK_HIGH);
  1256. if (base_low > addon_low)
  1257. res += base_low - addon_low;
  1258. else if (base_low < addon_low) {
  1259. res += interval + base_low - addon_low;
  1260. res += (1 << 24);
  1261. } else
  1262. res += (1 << 24);
  1263. return cpu_to_le32(res);
  1264. }
  1265. static int iwl4965_get_measurement(struct iwl_priv *priv,
  1266. struct ieee80211_measurement_params *params,
  1267. u8 type)
  1268. {
  1269. struct iwl4965_spectrum_cmd spectrum;
  1270. struct iwl_rx_packet *res;
  1271. struct iwl_host_cmd cmd = {
  1272. .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
  1273. .data = (void *)&spectrum,
  1274. .meta.flags = CMD_WANT_SKB,
  1275. };
  1276. u32 add_time = le64_to_cpu(params->start_time);
  1277. int rc;
  1278. int spectrum_resp_status;
  1279. int duration = le16_to_cpu(params->duration);
  1280. if (iwl_is_associated(priv))
  1281. add_time =
  1282. iwl4965_usecs_to_beacons(
  1283. le64_to_cpu(params->start_time) - priv->last_tsf,
  1284. le16_to_cpu(priv->rxon_timing.beacon_interval));
  1285. memset(&spectrum, 0, sizeof(spectrum));
  1286. spectrum.channel_count = cpu_to_le16(1);
  1287. spectrum.flags =
  1288. RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
  1289. spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
  1290. cmd.len = sizeof(spectrum);
  1291. spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
  1292. if (iwl_is_associated(priv))
  1293. spectrum.start_time =
  1294. iwl4965_add_beacon_time(priv->last_beacon_time,
  1295. add_time,
  1296. le16_to_cpu(priv->rxon_timing.beacon_interval));
  1297. else
  1298. spectrum.start_time = 0;
  1299. spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
  1300. spectrum.channels[0].channel = params->channel;
  1301. spectrum.channels[0].type = type;
  1302. if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
  1303. spectrum.flags |= RXON_FLG_BAND_24G_MSK |
  1304. RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
  1305. rc = iwl_send_cmd_sync(priv, &cmd);
  1306. if (rc)
  1307. return rc;
  1308. res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
  1309. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  1310. IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
  1311. rc = -EIO;
  1312. }
  1313. spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
  1314. switch (spectrum_resp_status) {
  1315. case 0: /* Command will be handled */
  1316. if (res->u.spectrum.id != 0xff) {
  1317. IWL_DEBUG_INFO
  1318. ("Replaced existing measurement: %d\n",
  1319. res->u.spectrum.id);
  1320. priv->measurement_status &= ~MEASUREMENT_READY;
  1321. }
  1322. priv->measurement_status |= MEASUREMENT_ACTIVE;
  1323. rc = 0;
  1324. break;
  1325. case 1: /* Command will not be handled */
  1326. rc = -EAGAIN;
  1327. break;
  1328. }
  1329. dev_kfree_skb_any(cmd.meta.u.skb);
  1330. return rc;
  1331. }
  1332. #endif
  1333. static void iwl4965_txstatus_to_ieee(struct iwl_priv *priv,
  1334. struct iwl_tx_info *tx_sta)
  1335. {
  1336. ieee80211_tx_status_irqsafe(priv->hw, tx_sta->skb[0]);
  1337. tx_sta->skb[0] = NULL;
  1338. }
  1339. /**
  1340. * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd
  1341. *
  1342. * When FW advances 'R' index, all entries between old and new 'R' index
  1343. * need to be reclaimed. As result, some free space forms. If there is
  1344. * enough free space (> low mark), wake the stack that feeds us.
  1345. */
  1346. int iwl4965_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index)
  1347. {
  1348. struct iwl_tx_queue *txq = &priv->txq[txq_id];
  1349. struct iwl_queue *q = &txq->q;
  1350. int nfreed = 0;
  1351. if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) {
  1352. IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
  1353. "is out of range [0-%d] %d %d.\n", txq_id,
  1354. index, q->n_bd, q->write_ptr, q->read_ptr);
  1355. return 0;
  1356. }
  1357. for (index = iwl_queue_inc_wrap(index, q->n_bd);
  1358. q->read_ptr != index;
  1359. q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
  1360. if (txq_id != IWL_CMD_QUEUE_NUM) {
  1361. iwl4965_txstatus_to_ieee(priv,
  1362. &(txq->txb[txq->q.read_ptr]));
  1363. iwl_hw_txq_free_tfd(priv, txq);
  1364. } else if (nfreed > 1) {
  1365. IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index,
  1366. q->write_ptr, q->read_ptr);
  1367. queue_work(priv->workqueue, &priv->restart);
  1368. }
  1369. nfreed++;
  1370. }
  1371. return nfreed;
  1372. }
  1373. static int iwl4965_is_tx_success(u32 status)
  1374. {
  1375. status &= TX_STATUS_MSK;
  1376. return (status == TX_STATUS_SUCCESS)
  1377. || (status == TX_STATUS_DIRECT_DONE);
  1378. }
  1379. /******************************************************************************
  1380. *
  1381. * Generic RX handler implementations
  1382. *
  1383. ******************************************************************************/
  1384. #ifdef CONFIG_IWL4965_HT
  1385. static inline int iwl4965_get_ra_sta_id(struct iwl_priv *priv,
  1386. struct ieee80211_hdr *hdr)
  1387. {
  1388. if (priv->iw_mode == IEEE80211_IF_TYPE_STA)
  1389. return IWL_AP_ID;
  1390. else {
  1391. u8 *da = ieee80211_get_DA(hdr);
  1392. return iwl_find_station(priv, da);
  1393. }
  1394. }
  1395. static struct ieee80211_hdr *iwl4965_tx_queue_get_hdr(
  1396. struct iwl_priv *priv, int txq_id, int idx)
  1397. {
  1398. if (priv->txq[txq_id].txb[idx].skb[0])
  1399. return (struct ieee80211_hdr *)priv->txq[txq_id].
  1400. txb[idx].skb[0]->data;
  1401. return NULL;
  1402. }
  1403. static inline u32 iwl4965_get_scd_ssn(struct iwl4965_tx_resp *tx_resp)
  1404. {
  1405. __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status +
  1406. tx_resp->frame_count);
  1407. return le32_to_cpu(*scd_ssn) & MAX_SN;
  1408. }
  1409. /**
  1410. * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue
  1411. */
  1412. static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv,
  1413. struct iwl_ht_agg *agg,
  1414. struct iwl4965_tx_resp_agg *tx_resp,
  1415. u16 start_idx)
  1416. {
  1417. u16 status;
  1418. struct agg_tx_status *frame_status = &tx_resp->status;
  1419. struct ieee80211_tx_info *info = NULL;
  1420. struct ieee80211_hdr *hdr = NULL;
  1421. int i, sh;
  1422. int txq_id, idx;
  1423. u16 seq;
  1424. if (agg->wait_for_ba)
  1425. IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
  1426. agg->frame_count = tx_resp->frame_count;
  1427. agg->start_idx = start_idx;
  1428. agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
  1429. agg->bitmap = 0;
  1430. /* # frames attempted by Tx command */
  1431. if (agg->frame_count == 1) {
  1432. /* Only one frame was attempted; no block-ack will arrive */
  1433. status = le16_to_cpu(frame_status[0].status);
  1434. seq = le16_to_cpu(frame_status[0].sequence);
  1435. idx = SEQ_TO_INDEX(seq);
  1436. txq_id = SEQ_TO_QUEUE(seq);
  1437. /* FIXME: code repetition */
  1438. IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
  1439. agg->frame_count, agg->start_idx, idx);
  1440. info = IEEE80211_SKB_CB(priv->txq[txq_id].txb[idx].skb[0]);
  1441. info->status.retry_count = tx_resp->failure_frame;
  1442. info->flags &= ~IEEE80211_TX_CTL_AMPDU;
  1443. info->flags |= iwl4965_is_tx_success(status)?
  1444. IEEE80211_TX_STAT_ACK : 0;
  1445. iwl4965_hwrate_to_tx_control(priv,
  1446. le32_to_cpu(tx_resp->rate_n_flags),
  1447. info);
  1448. /* FIXME: code repetition end */
  1449. IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
  1450. status & 0xff, tx_resp->failure_frame);
  1451. IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n",
  1452. iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags));
  1453. agg->wait_for_ba = 0;
  1454. } else {
  1455. /* Two or more frames were attempted; expect block-ack */
  1456. u64 bitmap = 0;
  1457. int start = agg->start_idx;
  1458. /* Construct bit-map of pending frames within Tx window */
  1459. for (i = 0; i < agg->frame_count; i++) {
  1460. u16 sc;
  1461. status = le16_to_cpu(frame_status[i].status);
  1462. seq = le16_to_cpu(frame_status[i].sequence);
  1463. idx = SEQ_TO_INDEX(seq);
  1464. txq_id = SEQ_TO_QUEUE(seq);
  1465. if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
  1466. AGG_TX_STATE_ABORT_MSK))
  1467. continue;
  1468. IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
  1469. agg->frame_count, txq_id, idx);
  1470. hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, idx);
  1471. sc = le16_to_cpu(hdr->seq_ctrl);
  1472. if (idx != (SEQ_TO_SN(sc) & 0xff)) {
  1473. IWL_ERROR("BUG_ON idx doesn't match seq control"
  1474. " idx=%d, seq_idx=%d, seq=%d\n",
  1475. idx, SEQ_TO_SN(sc),
  1476. hdr->seq_ctrl);
  1477. return -1;
  1478. }
  1479. IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
  1480. i, idx, SEQ_TO_SN(sc));
  1481. sh = idx - start;
  1482. if (sh > 64) {
  1483. sh = (start - idx) + 0xff;
  1484. bitmap = bitmap << sh;
  1485. sh = 0;
  1486. start = idx;
  1487. } else if (sh < -64)
  1488. sh = 0xff - (start - idx);
  1489. else if (sh < 0) {
  1490. sh = start - idx;
  1491. start = idx;
  1492. bitmap = bitmap << sh;
  1493. sh = 0;
  1494. }
  1495. bitmap |= (1 << sh);
  1496. IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
  1497. start, (u32)(bitmap & 0xFFFFFFFF));
  1498. }
  1499. agg->bitmap = bitmap;
  1500. agg->start_idx = start;
  1501. agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
  1502. IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
  1503. agg->frame_count, agg->start_idx,
  1504. (unsigned long long)agg->bitmap);
  1505. if (bitmap)
  1506. agg->wait_for_ba = 1;
  1507. }
  1508. return 0;
  1509. }
  1510. #endif
  1511. /**
  1512. * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
  1513. */
  1514. static void iwl4965_rx_reply_tx(struct iwl_priv *priv,
  1515. struct iwl_rx_mem_buffer *rxb)
  1516. {
  1517. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1518. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  1519. int txq_id = SEQ_TO_QUEUE(sequence);
  1520. int index = SEQ_TO_INDEX(sequence);
  1521. struct iwl_tx_queue *txq = &priv->txq[txq_id];
  1522. struct ieee80211_tx_info *info;
  1523. struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
  1524. u32 status = le32_to_cpu(tx_resp->status);
  1525. #ifdef CONFIG_IWL4965_HT
  1526. int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION;
  1527. u16 fc;
  1528. struct ieee80211_hdr *hdr;
  1529. u8 *qc = NULL;
  1530. #endif
  1531. if ((index >= txq->q.n_bd) || (iwl_queue_used(&txq->q, index) == 0)) {
  1532. IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
  1533. "is out of range [0-%d] %d %d\n", txq_id,
  1534. index, txq->q.n_bd, txq->q.write_ptr,
  1535. txq->q.read_ptr);
  1536. return;
  1537. }
  1538. info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]);
  1539. memset(&info->status, 0, sizeof(info->status));
  1540. #ifdef CONFIG_IWL4965_HT
  1541. hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, index);
  1542. fc = le16_to_cpu(hdr->frame_control);
  1543. if (ieee80211_is_qos_data(fc)) {
  1544. qc = ieee80211_get_qos_ctrl(hdr, ieee80211_get_hdrlen(fc));
  1545. tid = qc[0] & 0xf;
  1546. }
  1547. sta_id = iwl4965_get_ra_sta_id(priv, hdr);
  1548. if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) {
  1549. IWL_ERROR("Station not known\n");
  1550. return;
  1551. }
  1552. if (txq->sched_retry) {
  1553. const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp);
  1554. struct iwl_ht_agg *agg = NULL;
  1555. if (!qc)
  1556. return;
  1557. agg = &priv->stations[sta_id].tid[tid].agg;
  1558. iwl4965_tx_status_reply_tx(priv, agg,
  1559. (struct iwl4965_tx_resp_agg *)tx_resp, index);
  1560. if ((tx_resp->frame_count == 1) &&
  1561. !iwl4965_is_tx_success(status)) {
  1562. /* TODO: send BAR */
  1563. }
  1564. if (txq->q.read_ptr != (scd_ssn & 0xff)) {
  1565. int freed, ampdu_q;
  1566. index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
  1567. IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
  1568. "%d index %d\n", scd_ssn , index);
  1569. freed = iwl4965_tx_queue_reclaim(priv, txq_id, index);
  1570. priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
  1571. if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
  1572. txq_id >= 0 && priv->mac80211_registered &&
  1573. agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) {
  1574. /* calculate mac80211 ampdu sw queue to wake */
  1575. ampdu_q = txq_id - IWL_BACK_QUEUE_FIRST_ID +
  1576. priv->hw->queues;
  1577. if (agg->state == IWL_AGG_OFF)
  1578. ieee80211_wake_queue(priv->hw, txq_id);
  1579. else
  1580. ieee80211_wake_queue(priv->hw, ampdu_q);
  1581. }
  1582. iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id);
  1583. }
  1584. } else {
  1585. #endif /* CONFIG_IWL4965_HT */
  1586. info->status.retry_count = tx_resp->failure_frame;
  1587. info->flags |=
  1588. iwl4965_is_tx_success(status) ? IEEE80211_TX_STAT_ACK : 0;
  1589. iwl4965_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags),
  1590. info);
  1591. IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x "
  1592. "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status),
  1593. status, le32_to_cpu(tx_resp->rate_n_flags),
  1594. tx_resp->failure_frame);
  1595. IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
  1596. #ifdef CONFIG_IWL4965_HT
  1597. if (index != -1) {
  1598. int freed = iwl4965_tx_queue_reclaim(priv, txq_id, index);
  1599. if (tid != MAX_TID_COUNT)
  1600. priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
  1601. if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
  1602. (txq_id >= 0) && priv->mac80211_registered)
  1603. ieee80211_wake_queue(priv->hw, txq_id);
  1604. if (tid != MAX_TID_COUNT)
  1605. iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id);
  1606. }
  1607. }
  1608. #endif /* CONFIG_IWL4965_HT */
  1609. if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
  1610. IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
  1611. }
  1612. static void iwl4965_rx_reply_alive(struct iwl_priv *priv,
  1613. struct iwl_rx_mem_buffer *rxb)
  1614. {
  1615. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1616. struct iwl4965_alive_resp *palive;
  1617. struct delayed_work *pwork;
  1618. palive = &pkt->u.alive_frame;
  1619. IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
  1620. "0x%01X 0x%01X\n",
  1621. palive->is_valid, palive->ver_type,
  1622. palive->ver_subtype);
  1623. if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
  1624. IWL_DEBUG_INFO("Initialization Alive received.\n");
  1625. memcpy(&priv->card_alive_init,
  1626. &pkt->u.alive_frame,
  1627. sizeof(struct iwl4965_init_alive_resp));
  1628. pwork = &priv->init_alive_start;
  1629. } else {
  1630. IWL_DEBUG_INFO("Runtime Alive received.\n");
  1631. memcpy(&priv->card_alive, &pkt->u.alive_frame,
  1632. sizeof(struct iwl4965_alive_resp));
  1633. pwork = &priv->alive_start;
  1634. }
  1635. /* We delay the ALIVE response by 5ms to
  1636. * give the HW RF Kill time to activate... */
  1637. if (palive->is_valid == UCODE_VALID_OK)
  1638. queue_delayed_work(priv->workqueue, pwork,
  1639. msecs_to_jiffies(5));
  1640. else
  1641. IWL_WARNING("uCode did not respond OK.\n");
  1642. }
  1643. static void iwl4965_rx_reply_add_sta(struct iwl_priv *priv,
  1644. struct iwl_rx_mem_buffer *rxb)
  1645. {
  1646. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1647. IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
  1648. return;
  1649. }
  1650. static void iwl4965_rx_reply_error(struct iwl_priv *priv,
  1651. struct iwl_rx_mem_buffer *rxb)
  1652. {
  1653. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1654. IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
  1655. "seq 0x%04X ser 0x%08X\n",
  1656. le32_to_cpu(pkt->u.err_resp.error_type),
  1657. get_cmd_string(pkt->u.err_resp.cmd_id),
  1658. pkt->u.err_resp.cmd_id,
  1659. le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
  1660. le32_to_cpu(pkt->u.err_resp.error_info));
  1661. }
  1662. #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
  1663. static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
  1664. {
  1665. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1666. struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
  1667. struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif);
  1668. IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
  1669. le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
  1670. rxon->channel = csa->channel;
  1671. priv->staging_rxon.channel = csa->channel;
  1672. }
  1673. static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv,
  1674. struct iwl_rx_mem_buffer *rxb)
  1675. {
  1676. #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
  1677. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1678. struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif);
  1679. if (!report->state) {
  1680. IWL_DEBUG(IWL_DL_11H,
  1681. "Spectrum Measure Notification: Start\n");
  1682. return;
  1683. }
  1684. memcpy(&priv->measure_report, report, sizeof(*report));
  1685. priv->measurement_status |= MEASUREMENT_READY;
  1686. #endif
  1687. }
  1688. static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv,
  1689. struct iwl_rx_mem_buffer *rxb)
  1690. {
  1691. #ifdef CONFIG_IWLWIFI_DEBUG
  1692. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1693. struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif);
  1694. IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
  1695. sleep->pm_sleep_mode, sleep->pm_wakeup_src);
  1696. #endif
  1697. }
  1698. static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
  1699. struct iwl_rx_mem_buffer *rxb)
  1700. {
  1701. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1702. IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
  1703. "notification for %s:\n",
  1704. le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
  1705. iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
  1706. }
  1707. static void iwl4965_bg_beacon_update(struct work_struct *work)
  1708. {
  1709. struct iwl_priv *priv =
  1710. container_of(work, struct iwl_priv, beacon_update);
  1711. struct sk_buff *beacon;
  1712. /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
  1713. beacon = ieee80211_beacon_get(priv->hw, priv->vif);
  1714. if (!beacon) {
  1715. IWL_ERROR("update beacon failed\n");
  1716. return;
  1717. }
  1718. mutex_lock(&priv->mutex);
  1719. /* new beacon skb is allocated every time; dispose previous.*/
  1720. if (priv->ibss_beacon)
  1721. dev_kfree_skb(priv->ibss_beacon);
  1722. priv->ibss_beacon = beacon;
  1723. mutex_unlock(&priv->mutex);
  1724. iwl4965_send_beacon_cmd(priv);
  1725. }
  1726. static void iwl4965_rx_beacon_notif(struct iwl_priv *priv,
  1727. struct iwl_rx_mem_buffer *rxb)
  1728. {
  1729. #ifdef CONFIG_IWLWIFI_DEBUG
  1730. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1731. struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status);
  1732. u8 rate = iwl4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
  1733. IWL_DEBUG_RX("beacon status %x retries %d iss %d "
  1734. "tsf %d %d rate %d\n",
  1735. le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
  1736. beacon->beacon_notify_hdr.failure_frame,
  1737. le32_to_cpu(beacon->ibss_mgr_status),
  1738. le32_to_cpu(beacon->high_tsf),
  1739. le32_to_cpu(beacon->low_tsf), rate);
  1740. #endif
  1741. if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
  1742. (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
  1743. queue_work(priv->workqueue, &priv->beacon_update);
  1744. }
  1745. /* Service response to REPLY_SCAN_CMD (0x80) */
  1746. static void iwl4965_rx_reply_scan(struct iwl_priv *priv,
  1747. struct iwl_rx_mem_buffer *rxb)
  1748. {
  1749. #ifdef CONFIG_IWLWIFI_DEBUG
  1750. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1751. struct iwl4965_scanreq_notification *notif =
  1752. (struct iwl4965_scanreq_notification *)pkt->u.raw;
  1753. IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status);
  1754. #endif
  1755. }
  1756. /* Service SCAN_START_NOTIFICATION (0x82) */
  1757. static void iwl4965_rx_scan_start_notif(struct iwl_priv *priv,
  1758. struct iwl_rx_mem_buffer *rxb)
  1759. {
  1760. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1761. struct iwl4965_scanstart_notification *notif =
  1762. (struct iwl4965_scanstart_notification *)pkt->u.raw;
  1763. priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
  1764. IWL_DEBUG_SCAN("Scan start: "
  1765. "%d [802.11%s] "
  1766. "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
  1767. notif->channel,
  1768. notif->band ? "bg" : "a",
  1769. notif->tsf_high,
  1770. notif->tsf_low, notif->status, notif->beacon_timer);
  1771. }
  1772. /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
  1773. static void iwl4965_rx_scan_results_notif(struct iwl_priv *priv,
  1774. struct iwl_rx_mem_buffer *rxb)
  1775. {
  1776. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1777. struct iwl4965_scanresults_notification *notif =
  1778. (struct iwl4965_scanresults_notification *)pkt->u.raw;
  1779. IWL_DEBUG_SCAN("Scan ch.res: "
  1780. "%d [802.11%s] "
  1781. "(TSF: 0x%08X:%08X) - %d "
  1782. "elapsed=%lu usec (%dms since last)\n",
  1783. notif->channel,
  1784. notif->band ? "bg" : "a",
  1785. le32_to_cpu(notif->tsf_high),
  1786. le32_to_cpu(notif->tsf_low),
  1787. le32_to_cpu(notif->statistics[0]),
  1788. le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf,
  1789. jiffies_to_msecs(elapsed_jiffies
  1790. (priv->last_scan_jiffies, jiffies)));
  1791. priv->last_scan_jiffies = jiffies;
  1792. priv->next_scan_jiffies = 0;
  1793. }
  1794. /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
  1795. static void iwl4965_rx_scan_complete_notif(struct iwl_priv *priv,
  1796. struct iwl_rx_mem_buffer *rxb)
  1797. {
  1798. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1799. struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
  1800. IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
  1801. scan_notif->scanned_channels,
  1802. scan_notif->tsf_low,
  1803. scan_notif->tsf_high, scan_notif->status);
  1804. /* The HW is no longer scanning */
  1805. clear_bit(STATUS_SCAN_HW, &priv->status);
  1806. /* The scan completion notification came in, so kill that timer... */
  1807. cancel_delayed_work(&priv->scan_check);
  1808. IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
  1809. (priv->scan_bands == 2) ? "2.4" : "5.2",
  1810. jiffies_to_msecs(elapsed_jiffies
  1811. (priv->scan_pass_start, jiffies)));
  1812. /* Remove this scanned band from the list
  1813. * of pending bands to scan */
  1814. priv->scan_bands--;
  1815. /* If a request to abort was given, or the scan did not succeed
  1816. * then we reset the scan state machine and terminate,
  1817. * re-queuing another scan if one has been requested */
  1818. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  1819. IWL_DEBUG_INFO("Aborted scan completed.\n");
  1820. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  1821. } else {
  1822. /* If there are more bands on this scan pass reschedule */
  1823. if (priv->scan_bands > 0)
  1824. goto reschedule;
  1825. }
  1826. priv->last_scan_jiffies = jiffies;
  1827. priv->next_scan_jiffies = 0;
  1828. IWL_DEBUG_INFO("Setting scan to off\n");
  1829. clear_bit(STATUS_SCANNING, &priv->status);
  1830. IWL_DEBUG_INFO("Scan took %dms\n",
  1831. jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies)));
  1832. queue_work(priv->workqueue, &priv->scan_completed);
  1833. return;
  1834. reschedule:
  1835. priv->scan_pass_start = jiffies;
  1836. queue_work(priv->workqueue, &priv->request_scan);
  1837. }
  1838. /* Handle notification from uCode that card's power state is changing
  1839. * due to software, hardware, or critical temperature RFKILL */
  1840. static void iwl4965_rx_card_state_notif(struct iwl_priv *priv,
  1841. struct iwl_rx_mem_buffer *rxb)
  1842. {
  1843. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1844. u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
  1845. unsigned long status = priv->status;
  1846. IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
  1847. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  1848. (flags & SW_CARD_DISABLED) ? "Kill" : "On");
  1849. if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
  1850. RF_CARD_DISABLED)) {
  1851. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  1852. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  1853. if (!iwl_grab_nic_access(priv)) {
  1854. iwl_write_direct32(
  1855. priv, HBUS_TARG_MBX_C,
  1856. HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  1857. iwl_release_nic_access(priv);
  1858. }
  1859. if (!(flags & RXON_CARD_DISABLED)) {
  1860. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  1861. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  1862. if (!iwl_grab_nic_access(priv)) {
  1863. iwl_write_direct32(
  1864. priv, HBUS_TARG_MBX_C,
  1865. HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  1866. iwl_release_nic_access(priv);
  1867. }
  1868. }
  1869. if (flags & RF_CARD_DISABLED) {
  1870. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  1871. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  1872. iwl_read32(priv, CSR_UCODE_DRV_GP1);
  1873. if (!iwl_grab_nic_access(priv))
  1874. iwl_release_nic_access(priv);
  1875. }
  1876. }
  1877. if (flags & HW_CARD_DISABLED)
  1878. set_bit(STATUS_RF_KILL_HW, &priv->status);
  1879. else
  1880. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  1881. if (flags & SW_CARD_DISABLED)
  1882. set_bit(STATUS_RF_KILL_SW, &priv->status);
  1883. else
  1884. clear_bit(STATUS_RF_KILL_SW, &priv->status);
  1885. if (!(flags & RXON_CARD_DISABLED))
  1886. iwl4965_scan_cancel(priv);
  1887. if ((test_bit(STATUS_RF_KILL_HW, &status) !=
  1888. test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
  1889. (test_bit(STATUS_RF_KILL_SW, &status) !=
  1890. test_bit(STATUS_RF_KILL_SW, &priv->status)))
  1891. queue_work(priv->workqueue, &priv->rf_kill);
  1892. else
  1893. wake_up_interruptible(&priv->wait_command_queue);
  1894. }
  1895. /**
  1896. * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
  1897. *
  1898. * Setup the RX handlers for each of the reply types sent from the uCode
  1899. * to the host.
  1900. *
  1901. * This function chains into the hardware specific files for them to setup
  1902. * any hardware specific handlers as well.
  1903. */
  1904. static void iwl4965_setup_rx_handlers(struct iwl_priv *priv)
  1905. {
  1906. priv->rx_handlers[REPLY_ALIVE] = iwl4965_rx_reply_alive;
  1907. priv->rx_handlers[REPLY_ADD_STA] = iwl4965_rx_reply_add_sta;
  1908. priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error;
  1909. priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa;
  1910. priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
  1911. iwl4965_rx_spectrum_measure_notif;
  1912. priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif;
  1913. priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
  1914. iwl4965_rx_pm_debug_statistics_notif;
  1915. priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
  1916. /*
  1917. * The same handler is used for both the REPLY to a discrete
  1918. * statistics request from the host as well as for the periodic
  1919. * statistics notifications (after received beacons) from the uCode.
  1920. */
  1921. priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics;
  1922. priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics;
  1923. priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan;
  1924. priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif;
  1925. priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
  1926. iwl4965_rx_scan_results_notif;
  1927. priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
  1928. iwl4965_rx_scan_complete_notif;
  1929. priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif;
  1930. priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx;
  1931. /* Set up hardware specific Rx handlers */
  1932. priv->cfg->ops->lib->rx_handler_setup(priv);
  1933. }
  1934. /**
  1935. * iwl4965_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
  1936. * @rxb: Rx buffer to reclaim
  1937. *
  1938. * If an Rx buffer has an async callback associated with it the callback
  1939. * will be executed. The attached skb (if present) will only be freed
  1940. * if the callback returns 1
  1941. */
  1942. static void iwl4965_tx_cmd_complete(struct iwl_priv *priv,
  1943. struct iwl_rx_mem_buffer *rxb)
  1944. {
  1945. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1946. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  1947. int txq_id = SEQ_TO_QUEUE(sequence);
  1948. int index = SEQ_TO_INDEX(sequence);
  1949. int huge = sequence & SEQ_HUGE_FRAME;
  1950. int cmd_index;
  1951. struct iwl_cmd *cmd;
  1952. /* If a Tx command is being handled and it isn't in the actual
  1953. * command queue then there a command routing bug has been introduced
  1954. * in the queue management code. */
  1955. if (txq_id != IWL_CMD_QUEUE_NUM)
  1956. IWL_ERROR("Error wrong command queue %d command id 0x%X\n",
  1957. txq_id, pkt->hdr.cmd);
  1958. BUG_ON(txq_id != IWL_CMD_QUEUE_NUM);
  1959. cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
  1960. cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
  1961. /* Input error checking is done when commands are added to queue. */
  1962. if (cmd->meta.flags & CMD_WANT_SKB) {
  1963. cmd->meta.source->u.skb = rxb->skb;
  1964. rxb->skb = NULL;
  1965. } else if (cmd->meta.u.callback &&
  1966. !cmd->meta.u.callback(priv, cmd, rxb->skb))
  1967. rxb->skb = NULL;
  1968. iwl4965_tx_queue_reclaim(priv, txq_id, index);
  1969. if (!(cmd->meta.flags & CMD_ASYNC)) {
  1970. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  1971. wake_up_interruptible(&priv->wait_command_queue);
  1972. }
  1973. }
  1974. /*
  1975. * this should be called while priv->lock is locked
  1976. */
  1977. static void __iwl_rx_replenish(struct iwl_priv *priv)
  1978. {
  1979. iwl_rx_allocate(priv);
  1980. iwl_rx_queue_restock(priv);
  1981. }
  1982. /**
  1983. * iwl_rx_handle - Main entry function for receiving responses from uCode
  1984. *
  1985. * Uses the priv->rx_handlers callback function array to invoke
  1986. * the appropriate handlers, including command responses,
  1987. * frame-received notifications, and other notifications.
  1988. */
  1989. void iwl_rx_handle(struct iwl_priv *priv)
  1990. {
  1991. struct iwl_rx_mem_buffer *rxb;
  1992. struct iwl_rx_packet *pkt;
  1993. struct iwl_rx_queue *rxq = &priv->rxq;
  1994. u32 r, i;
  1995. int reclaim;
  1996. unsigned long flags;
  1997. u8 fill_rx = 0;
  1998. u32 count = 8;
  1999. /* uCode's read index (stored in shared DRAM) indicates the last Rx
  2000. * buffer that the driver may process (last buffer filled by ucode). */
  2001. r = priv->cfg->ops->lib->shared_mem_rx_idx(priv);
  2002. i = rxq->read;
  2003. /* Rx interrupt, but nothing sent from uCode */
  2004. if (i == r)
  2005. IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d\n", r, i);
  2006. if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
  2007. fill_rx = 1;
  2008. while (i != r) {
  2009. rxb = rxq->queue[i];
  2010. /* If an RXB doesn't have a Rx queue slot associated with it,
  2011. * then a bug has been introduced in the queue refilling
  2012. * routines -- catch it here */
  2013. BUG_ON(rxb == NULL);
  2014. rxq->queue[i] = NULL;
  2015. pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
  2016. priv->hw_params.rx_buf_size,
  2017. PCI_DMA_FROMDEVICE);
  2018. pkt = (struct iwl_rx_packet *)rxb->skb->data;
  2019. /* Reclaim a command buffer only if this packet is a response
  2020. * to a (driver-originated) command.
  2021. * If the packet (e.g. Rx frame) originated from uCode,
  2022. * there is no command buffer to reclaim.
  2023. * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
  2024. * but apparently a few don't get set; catch them here. */
  2025. reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
  2026. (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
  2027. (pkt->hdr.cmd != REPLY_RX) &&
  2028. (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
  2029. (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
  2030. (pkt->hdr.cmd != REPLY_TX);
  2031. /* Based on type of command response or notification,
  2032. * handle those that need handling via function in
  2033. * rx_handlers table. See iwl4965_setup_rx_handlers() */
  2034. if (priv->rx_handlers[pkt->hdr.cmd]) {
  2035. IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r,
  2036. i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
  2037. priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
  2038. } else {
  2039. /* No handling needed */
  2040. IWL_DEBUG(IWL_DL_RX,
  2041. "r %d i %d No handler needed for %s, 0x%02x\n",
  2042. r, i, get_cmd_string(pkt->hdr.cmd),
  2043. pkt->hdr.cmd);
  2044. }
  2045. if (reclaim) {
  2046. /* Invoke any callbacks, transfer the skb to caller, and
  2047. * fire off the (possibly) blocking iwl_send_cmd()
  2048. * as we reclaim the driver command queue */
  2049. if (rxb && rxb->skb)
  2050. iwl4965_tx_cmd_complete(priv, rxb);
  2051. else
  2052. IWL_WARNING("Claim null rxb?\n");
  2053. }
  2054. /* For now we just don't re-use anything. We can tweak this
  2055. * later to try and re-use notification packets and SKBs that
  2056. * fail to Rx correctly */
  2057. if (rxb->skb != NULL) {
  2058. priv->alloc_rxb_skb--;
  2059. dev_kfree_skb_any(rxb->skb);
  2060. rxb->skb = NULL;
  2061. }
  2062. pci_unmap_single(priv->pci_dev, rxb->dma_addr,
  2063. priv->hw_params.rx_buf_size,
  2064. PCI_DMA_FROMDEVICE);
  2065. spin_lock_irqsave(&rxq->lock, flags);
  2066. list_add_tail(&rxb->list, &priv->rxq.rx_used);
  2067. spin_unlock_irqrestore(&rxq->lock, flags);
  2068. i = (i + 1) & RX_QUEUE_MASK;
  2069. /* If there are a lot of unused frames,
  2070. * restock the Rx queue so ucode wont assert. */
  2071. if (fill_rx) {
  2072. count++;
  2073. if (count >= 8) {
  2074. priv->rxq.read = i;
  2075. __iwl_rx_replenish(priv);
  2076. count = 0;
  2077. }
  2078. }
  2079. }
  2080. /* Backtrack one entry */
  2081. priv->rxq.read = i;
  2082. iwl_rx_queue_restock(priv);
  2083. }
  2084. /* Convert linear signal-to-noise ratio into dB */
  2085. static u8 ratio2dB[100] = {
  2086. /* 0 1 2 3 4 5 6 7 8 9 */
  2087. 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
  2088. 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
  2089. 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
  2090. 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
  2091. 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
  2092. 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
  2093. 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
  2094. 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
  2095. 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
  2096. 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
  2097. };
  2098. /* Calculates a relative dB value from a ratio of linear
  2099. * (i.e. not dB) signal levels.
  2100. * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
  2101. int iwl4965_calc_db_from_ratio(int sig_ratio)
  2102. {
  2103. /* 1000:1 or higher just report as 60 dB */
  2104. if (sig_ratio >= 1000)
  2105. return 60;
  2106. /* 100:1 or higher, divide by 10 and use table,
  2107. * add 20 dB to make up for divide by 10 */
  2108. if (sig_ratio >= 100)
  2109. return (20 + (int)ratio2dB[sig_ratio/10]);
  2110. /* We shouldn't see this */
  2111. if (sig_ratio < 1)
  2112. return 0;
  2113. /* Use table for ratios 1:1 - 99:1 */
  2114. return (int)ratio2dB[sig_ratio];
  2115. }
  2116. #define PERFECT_RSSI (-20) /* dBm */
  2117. #define WORST_RSSI (-95) /* dBm */
  2118. #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
  2119. /* Calculate an indication of rx signal quality (a percentage, not dBm!).
  2120. * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
  2121. * about formulas used below. */
  2122. int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm)
  2123. {
  2124. int sig_qual;
  2125. int degradation = PERFECT_RSSI - rssi_dbm;
  2126. /* If we get a noise measurement, use signal-to-noise ratio (SNR)
  2127. * as indicator; formula is (signal dbm - noise dbm).
  2128. * SNR at or above 40 is a great signal (100%).
  2129. * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
  2130. * Weakest usable signal is usually 10 - 15 dB SNR. */
  2131. if (noise_dbm) {
  2132. if (rssi_dbm - noise_dbm >= 40)
  2133. return 100;
  2134. else if (rssi_dbm < noise_dbm)
  2135. return 0;
  2136. sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
  2137. /* Else use just the signal level.
  2138. * This formula is a least squares fit of data points collected and
  2139. * compared with a reference system that had a percentage (%) display
  2140. * for signal quality. */
  2141. } else
  2142. sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
  2143. (15 * RSSI_RANGE + 62 * degradation)) /
  2144. (RSSI_RANGE * RSSI_RANGE);
  2145. if (sig_qual > 100)
  2146. sig_qual = 100;
  2147. else if (sig_qual < 1)
  2148. sig_qual = 0;
  2149. return sig_qual;
  2150. }
  2151. #ifdef CONFIG_IWLWIFI_DEBUG
  2152. static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv)
  2153. {
  2154. struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
  2155. DECLARE_MAC_BUF(mac);
  2156. IWL_DEBUG_RADIO("RX CONFIG:\n");
  2157. iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
  2158. IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
  2159. IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
  2160. IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
  2161. le32_to_cpu(rxon->filter_flags));
  2162. IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
  2163. IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
  2164. rxon->ofdm_basic_rates);
  2165. IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
  2166. IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
  2167. print_mac(mac, rxon->node_addr));
  2168. IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
  2169. print_mac(mac, rxon->bssid_addr));
  2170. IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
  2171. }
  2172. #endif
  2173. static void iwl4965_enable_interrupts(struct iwl_priv *priv)
  2174. {
  2175. IWL_DEBUG_ISR("Enabling interrupts\n");
  2176. set_bit(STATUS_INT_ENABLED, &priv->status);
  2177. iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
  2178. }
  2179. /* call this function to flush any scheduled tasklet */
  2180. static inline void iwl_synchronize_irq(struct iwl_priv *priv)
  2181. {
  2182. /* wait to make sure we flush pedding tasklet*/
  2183. synchronize_irq(priv->pci_dev->irq);
  2184. tasklet_kill(&priv->irq_tasklet);
  2185. }
  2186. static inline void iwl4965_disable_interrupts(struct iwl_priv *priv)
  2187. {
  2188. clear_bit(STATUS_INT_ENABLED, &priv->status);
  2189. /* disable interrupts from uCode/NIC to host */
  2190. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  2191. /* acknowledge/clear/reset any interrupts still pending
  2192. * from uCode or flow handler (Rx/Tx DMA) */
  2193. iwl_write32(priv, CSR_INT, 0xffffffff);
  2194. iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
  2195. IWL_DEBUG_ISR("Disabled interrupts\n");
  2196. }
  2197. /**
  2198. * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
  2199. */
  2200. static void iwl4965_irq_handle_error(struct iwl_priv *priv)
  2201. {
  2202. /* Set the FW error flag -- cleared on iwl4965_down */
  2203. set_bit(STATUS_FW_ERROR, &priv->status);
  2204. /* Cancel currently queued command. */
  2205. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  2206. #ifdef CONFIG_IWLWIFI_DEBUG
  2207. if (priv->debug_level & IWL_DL_FW_ERRORS) {
  2208. iwl_dump_nic_error_log(priv);
  2209. iwl_dump_nic_event_log(priv);
  2210. iwl4965_print_rx_config_cmd(priv);
  2211. }
  2212. #endif
  2213. wake_up_interruptible(&priv->wait_command_queue);
  2214. /* Keep the restart process from trying to send host
  2215. * commands by clearing the INIT status bit */
  2216. clear_bit(STATUS_READY, &priv->status);
  2217. if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  2218. IWL_DEBUG(IWL_DL_FW_ERRORS,
  2219. "Restarting adapter due to uCode error.\n");
  2220. if (iwl_is_associated(priv)) {
  2221. memcpy(&priv->recovery_rxon, &priv->active_rxon,
  2222. sizeof(priv->recovery_rxon));
  2223. priv->error_recovering = 1;
  2224. }
  2225. if (priv->cfg->mod_params->restart_fw)
  2226. queue_work(priv->workqueue, &priv->restart);
  2227. }
  2228. }
  2229. static void iwl4965_error_recovery(struct iwl_priv *priv)
  2230. {
  2231. unsigned long flags;
  2232. memcpy(&priv->staging_rxon, &priv->recovery_rxon,
  2233. sizeof(priv->staging_rxon));
  2234. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2235. iwl4965_commit_rxon(priv);
  2236. iwl_rxon_add_station(priv, priv->bssid, 1);
  2237. spin_lock_irqsave(&priv->lock, flags);
  2238. priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
  2239. priv->error_recovering = 0;
  2240. spin_unlock_irqrestore(&priv->lock, flags);
  2241. }
  2242. static void iwl4965_irq_tasklet(struct iwl_priv *priv)
  2243. {
  2244. u32 inta, handled = 0;
  2245. u32 inta_fh;
  2246. unsigned long flags;
  2247. #ifdef CONFIG_IWLWIFI_DEBUG
  2248. u32 inta_mask;
  2249. #endif
  2250. spin_lock_irqsave(&priv->lock, flags);
  2251. /* Ack/clear/reset pending uCode interrupts.
  2252. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
  2253. * and will clear only when CSR_FH_INT_STATUS gets cleared. */
  2254. inta = iwl_read32(priv, CSR_INT);
  2255. iwl_write32(priv, CSR_INT, inta);
  2256. /* Ack/clear/reset pending flow-handler (DMA) interrupts.
  2257. * Any new interrupts that happen after this, either while we're
  2258. * in this tasklet, or later, will show up in next ISR/tasklet. */
  2259. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  2260. iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
  2261. #ifdef CONFIG_IWLWIFI_DEBUG
  2262. if (priv->debug_level & IWL_DL_ISR) {
  2263. /* just for debug */
  2264. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  2265. IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  2266. inta, inta_mask, inta_fh);
  2267. }
  2268. #endif
  2269. /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
  2270. * atomic, make sure that inta covers all the interrupts that
  2271. * we've discovered, even if FH interrupt came in just after
  2272. * reading CSR_INT. */
  2273. if (inta_fh & CSR49_FH_INT_RX_MASK)
  2274. inta |= CSR_INT_BIT_FH_RX;
  2275. if (inta_fh & CSR49_FH_INT_TX_MASK)
  2276. inta |= CSR_INT_BIT_FH_TX;
  2277. /* Now service all interrupt bits discovered above. */
  2278. if (inta & CSR_INT_BIT_HW_ERR) {
  2279. IWL_ERROR("Microcode HW error detected. Restarting.\n");
  2280. /* Tell the device to stop sending interrupts */
  2281. iwl4965_disable_interrupts(priv);
  2282. iwl4965_irq_handle_error(priv);
  2283. handled |= CSR_INT_BIT_HW_ERR;
  2284. spin_unlock_irqrestore(&priv->lock, flags);
  2285. return;
  2286. }
  2287. #ifdef CONFIG_IWLWIFI_DEBUG
  2288. if (priv->debug_level & (IWL_DL_ISR)) {
  2289. /* NIC fires this, but we don't use it, redundant with WAKEUP */
  2290. if (inta & CSR_INT_BIT_SCD)
  2291. IWL_DEBUG_ISR("Scheduler finished to transmit "
  2292. "the frame/frames.\n");
  2293. /* Alive notification via Rx interrupt will do the real work */
  2294. if (inta & CSR_INT_BIT_ALIVE)
  2295. IWL_DEBUG_ISR("Alive interrupt\n");
  2296. }
  2297. #endif
  2298. /* Safely ignore these bits for debug checks below */
  2299. inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
  2300. /* HW RF KILL switch toggled */
  2301. if (inta & CSR_INT_BIT_RF_KILL) {
  2302. int hw_rf_kill = 0;
  2303. if (!(iwl_read32(priv, CSR_GP_CNTRL) &
  2304. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
  2305. hw_rf_kill = 1;
  2306. IWL_DEBUG(IWL_DL_RF_KILL, "RF_KILL bit toggled to %s.\n",
  2307. hw_rf_kill ? "disable radio":"enable radio");
  2308. /* Queue restart only if RF_KILL switch was set to "kill"
  2309. * when we loaded driver, and is now set to "enable".
  2310. * After we're Alive, RF_KILL gets handled by
  2311. * iwl4965_rx_card_state_notif() */
  2312. if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) {
  2313. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2314. queue_work(priv->workqueue, &priv->restart);
  2315. }
  2316. handled |= CSR_INT_BIT_RF_KILL;
  2317. }
  2318. /* Chip got too hot and stopped itself */
  2319. if (inta & CSR_INT_BIT_CT_KILL) {
  2320. IWL_ERROR("Microcode CT kill error detected.\n");
  2321. handled |= CSR_INT_BIT_CT_KILL;
  2322. }
  2323. /* Error detected by uCode */
  2324. if (inta & CSR_INT_BIT_SW_ERR) {
  2325. IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
  2326. inta);
  2327. iwl4965_irq_handle_error(priv);
  2328. handled |= CSR_INT_BIT_SW_ERR;
  2329. }
  2330. /* uCode wakes up after power-down sleep */
  2331. if (inta & CSR_INT_BIT_WAKEUP) {
  2332. IWL_DEBUG_ISR("Wakeup interrupt\n");
  2333. iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
  2334. iwl_txq_update_write_ptr(priv, &priv->txq[0]);
  2335. iwl_txq_update_write_ptr(priv, &priv->txq[1]);
  2336. iwl_txq_update_write_ptr(priv, &priv->txq[2]);
  2337. iwl_txq_update_write_ptr(priv, &priv->txq[3]);
  2338. iwl_txq_update_write_ptr(priv, &priv->txq[4]);
  2339. iwl_txq_update_write_ptr(priv, &priv->txq[5]);
  2340. handled |= CSR_INT_BIT_WAKEUP;
  2341. }
  2342. /* All uCode command responses, including Tx command responses,
  2343. * Rx "responses" (frame-received notification), and other
  2344. * notifications from uCode come through here*/
  2345. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
  2346. iwl_rx_handle(priv);
  2347. handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
  2348. }
  2349. if (inta & CSR_INT_BIT_FH_TX) {
  2350. IWL_DEBUG_ISR("Tx interrupt\n");
  2351. handled |= CSR_INT_BIT_FH_TX;
  2352. /* FH finished to write, send event */
  2353. priv->ucode_write_complete = 1;
  2354. wake_up_interruptible(&priv->wait_command_queue);
  2355. }
  2356. if (inta & ~handled)
  2357. IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
  2358. if (inta & ~CSR_INI_SET_MASK) {
  2359. IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
  2360. inta & ~CSR_INI_SET_MASK);
  2361. IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh);
  2362. }
  2363. /* Re-enable all interrupts */
  2364. /* only Re-enable if diabled by irq */
  2365. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  2366. iwl4965_enable_interrupts(priv);
  2367. #ifdef CONFIG_IWLWIFI_DEBUG
  2368. if (priv->debug_level & (IWL_DL_ISR)) {
  2369. inta = iwl_read32(priv, CSR_INT);
  2370. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  2371. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  2372. IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
  2373. "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
  2374. }
  2375. #endif
  2376. spin_unlock_irqrestore(&priv->lock, flags);
  2377. }
  2378. static irqreturn_t iwl4965_isr(int irq, void *data)
  2379. {
  2380. struct iwl_priv *priv = data;
  2381. u32 inta, inta_mask;
  2382. u32 inta_fh;
  2383. if (!priv)
  2384. return IRQ_NONE;
  2385. spin_lock(&priv->lock);
  2386. /* Disable (but don't clear!) interrupts here to avoid
  2387. * back-to-back ISRs and sporadic interrupts from our NIC.
  2388. * If we have something to service, the tasklet will re-enable ints.
  2389. * If we *don't* have something, we'll re-enable before leaving here. */
  2390. inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
  2391. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  2392. /* Discover which interrupts are active/pending */
  2393. inta = iwl_read32(priv, CSR_INT);
  2394. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  2395. /* Ignore interrupt if there's nothing in NIC to service.
  2396. * This may be due to IRQ shared with another device,
  2397. * or due to sporadic interrupts thrown from our NIC. */
  2398. if (!inta && !inta_fh) {
  2399. IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
  2400. goto none;
  2401. }
  2402. if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
  2403. /* Hardware disappeared. It might have already raised
  2404. * an interrupt */
  2405. IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
  2406. goto unplugged;
  2407. }
  2408. IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  2409. inta, inta_mask, inta_fh);
  2410. inta &= ~CSR_INT_BIT_SCD;
  2411. /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
  2412. if (likely(inta || inta_fh))
  2413. tasklet_schedule(&priv->irq_tasklet);
  2414. unplugged:
  2415. spin_unlock(&priv->lock);
  2416. return IRQ_HANDLED;
  2417. none:
  2418. /* re-enable interrupts here since we don't have anything to service. */
  2419. /* only Re-enable if diabled by irq */
  2420. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  2421. iwl4965_enable_interrupts(priv);
  2422. spin_unlock(&priv->lock);
  2423. return IRQ_NONE;
  2424. }
  2425. /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
  2426. * sending probe req. This should be set long enough to hear probe responses
  2427. * from more than one AP. */
  2428. #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
  2429. #define IWL_ACTIVE_DWELL_TIME_52 (10)
  2430. /* For faster active scanning, scan will move to the next channel if fewer than
  2431. * PLCP_QUIET_THRESH packets are heard on this channel within
  2432. * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
  2433. * time if it's a quiet channel (nothing responded to our probe, and there's
  2434. * no other traffic).
  2435. * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
  2436. #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
  2437. #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
  2438. /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
  2439. * Must be set longer than active dwell time.
  2440. * For the most reliable scan, set > AP beacon interval (typically 100msec). */
  2441. #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
  2442. #define IWL_PASSIVE_DWELL_TIME_52 (10)
  2443. #define IWL_PASSIVE_DWELL_BASE (100)
  2444. #define IWL_CHANNEL_TUNE_TIME 5
  2445. static inline u16 iwl4965_get_active_dwell_time(struct iwl_priv *priv,
  2446. enum ieee80211_band band)
  2447. {
  2448. if (band == IEEE80211_BAND_5GHZ)
  2449. return IWL_ACTIVE_DWELL_TIME_52;
  2450. else
  2451. return IWL_ACTIVE_DWELL_TIME_24;
  2452. }
  2453. static u16 iwl4965_get_passive_dwell_time(struct iwl_priv *priv,
  2454. enum ieee80211_band band)
  2455. {
  2456. u16 active = iwl4965_get_active_dwell_time(priv, band);
  2457. u16 passive = (band != IEEE80211_BAND_5GHZ) ?
  2458. IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
  2459. IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
  2460. if (iwl_is_associated(priv)) {
  2461. /* If we're associated, we clamp the maximum passive
  2462. * dwell time to be 98% of the beacon interval (minus
  2463. * 2 * channel tune time) */
  2464. passive = priv->beacon_int;
  2465. if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive)
  2466. passive = IWL_PASSIVE_DWELL_BASE;
  2467. passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
  2468. }
  2469. if (passive <= active)
  2470. passive = active + 1;
  2471. return passive;
  2472. }
  2473. static int iwl4965_get_channels_for_scan(struct iwl_priv *priv,
  2474. enum ieee80211_band band,
  2475. u8 is_active, u8 direct_mask,
  2476. struct iwl4965_scan_channel *scan_ch)
  2477. {
  2478. const struct ieee80211_channel *channels = NULL;
  2479. const struct ieee80211_supported_band *sband;
  2480. const struct iwl_channel_info *ch_info;
  2481. u16 passive_dwell = 0;
  2482. u16 active_dwell = 0;
  2483. int added, i;
  2484. sband = iwl_get_hw_mode(priv, band);
  2485. if (!sband)
  2486. return 0;
  2487. channels = sband->channels;
  2488. active_dwell = iwl4965_get_active_dwell_time(priv, band);
  2489. passive_dwell = iwl4965_get_passive_dwell_time(priv, band);
  2490. for (i = 0, added = 0; i < sband->n_channels; i++) {
  2491. if (channels[i].flags & IEEE80211_CHAN_DISABLED)
  2492. continue;
  2493. scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq);
  2494. ch_info = iwl_get_channel_info(priv, band,
  2495. scan_ch->channel);
  2496. if (!is_channel_valid(ch_info)) {
  2497. IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
  2498. scan_ch->channel);
  2499. continue;
  2500. }
  2501. if (!is_active || is_channel_passive(ch_info) ||
  2502. (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN))
  2503. scan_ch->type = 0; /* passive */
  2504. else
  2505. scan_ch->type = 1; /* active */
  2506. if (scan_ch->type & 1)
  2507. scan_ch->type |= (direct_mask << 1);
  2508. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  2509. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  2510. /* Set txpower levels to defaults */
  2511. scan_ch->tpc.dsp_atten = 110;
  2512. /* scan_pwr_info->tpc.dsp_atten; */
  2513. /*scan_pwr_info->tpc.tx_gain; */
  2514. if (band == IEEE80211_BAND_5GHZ)
  2515. scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
  2516. else {
  2517. scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
  2518. /* NOTE: if we were doing 6Mb OFDM for scans we'd use
  2519. * power level:
  2520. * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
  2521. */
  2522. }
  2523. IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
  2524. scan_ch->channel,
  2525. (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
  2526. (scan_ch->type & 1) ?
  2527. active_dwell : passive_dwell);
  2528. scan_ch++;
  2529. added++;
  2530. }
  2531. IWL_DEBUG_SCAN("total channels to scan %d \n", added);
  2532. return added;
  2533. }
  2534. /******************************************************************************
  2535. *
  2536. * uCode download functions
  2537. *
  2538. ******************************************************************************/
  2539. static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv)
  2540. {
  2541. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
  2542. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
  2543. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  2544. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
  2545. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  2546. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
  2547. }
  2548. static void iwl4965_nic_start(struct iwl_priv *priv)
  2549. {
  2550. /* Remove all resets to allow NIC to operate */
  2551. iwl_write32(priv, CSR_RESET, 0);
  2552. }
  2553. /**
  2554. * iwl4965_read_ucode - Read uCode images from disk file.
  2555. *
  2556. * Copy into buffers for card to fetch via bus-mastering
  2557. */
  2558. static int iwl4965_read_ucode(struct iwl_priv *priv)
  2559. {
  2560. struct iwl4965_ucode *ucode;
  2561. int ret;
  2562. const struct firmware *ucode_raw;
  2563. const char *name = priv->cfg->fw_name;
  2564. u8 *src;
  2565. size_t len;
  2566. u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
  2567. /* Ask kernel firmware_class module to get the boot firmware off disk.
  2568. * request_firmware() is synchronous, file is in memory on return. */
  2569. ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
  2570. if (ret < 0) {
  2571. IWL_ERROR("%s firmware file req failed: Reason %d\n",
  2572. name, ret);
  2573. goto error;
  2574. }
  2575. IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
  2576. name, ucode_raw->size);
  2577. /* Make sure that we got at least our header! */
  2578. if (ucode_raw->size < sizeof(*ucode)) {
  2579. IWL_ERROR("File size way too small!\n");
  2580. ret = -EINVAL;
  2581. goto err_release;
  2582. }
  2583. /* Data from ucode file: header followed by uCode images */
  2584. ucode = (void *)ucode_raw->data;
  2585. ver = le32_to_cpu(ucode->ver);
  2586. inst_size = le32_to_cpu(ucode->inst_size);
  2587. data_size = le32_to_cpu(ucode->data_size);
  2588. init_size = le32_to_cpu(ucode->init_size);
  2589. init_data_size = le32_to_cpu(ucode->init_data_size);
  2590. boot_size = le32_to_cpu(ucode->boot_size);
  2591. IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver);
  2592. IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
  2593. inst_size);
  2594. IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
  2595. data_size);
  2596. IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
  2597. init_size);
  2598. IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
  2599. init_data_size);
  2600. IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
  2601. boot_size);
  2602. /* Verify size of file vs. image size info in file's header */
  2603. if (ucode_raw->size < sizeof(*ucode) +
  2604. inst_size + data_size + init_size +
  2605. init_data_size + boot_size) {
  2606. IWL_DEBUG_INFO("uCode file size %d too small\n",
  2607. (int)ucode_raw->size);
  2608. ret = -EINVAL;
  2609. goto err_release;
  2610. }
  2611. /* Verify that uCode images will fit in card's SRAM */
  2612. if (inst_size > priv->hw_params.max_inst_size) {
  2613. IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
  2614. inst_size);
  2615. ret = -EINVAL;
  2616. goto err_release;
  2617. }
  2618. if (data_size > priv->hw_params.max_data_size) {
  2619. IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
  2620. data_size);
  2621. ret = -EINVAL;
  2622. goto err_release;
  2623. }
  2624. if (init_size > priv->hw_params.max_inst_size) {
  2625. IWL_DEBUG_INFO
  2626. ("uCode init instr len %d too large to fit in\n",
  2627. init_size);
  2628. ret = -EINVAL;
  2629. goto err_release;
  2630. }
  2631. if (init_data_size > priv->hw_params.max_data_size) {
  2632. IWL_DEBUG_INFO
  2633. ("uCode init data len %d too large to fit in\n",
  2634. init_data_size);
  2635. ret = -EINVAL;
  2636. goto err_release;
  2637. }
  2638. if (boot_size > priv->hw_params.max_bsm_size) {
  2639. IWL_DEBUG_INFO
  2640. ("uCode boot instr len %d too large to fit in\n",
  2641. boot_size);
  2642. ret = -EINVAL;
  2643. goto err_release;
  2644. }
  2645. /* Allocate ucode buffers for card's bus-master loading ... */
  2646. /* Runtime instructions and 2 copies of data:
  2647. * 1) unmodified from disk
  2648. * 2) backup cache for save/restore during power-downs */
  2649. priv->ucode_code.len = inst_size;
  2650. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
  2651. priv->ucode_data.len = data_size;
  2652. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
  2653. priv->ucode_data_backup.len = data_size;
  2654. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  2655. /* Initialization instructions and data */
  2656. if (init_size && init_data_size) {
  2657. priv->ucode_init.len = init_size;
  2658. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
  2659. priv->ucode_init_data.len = init_data_size;
  2660. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  2661. if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
  2662. goto err_pci_alloc;
  2663. }
  2664. /* Bootstrap (instructions only, no data) */
  2665. if (boot_size) {
  2666. priv->ucode_boot.len = boot_size;
  2667. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
  2668. if (!priv->ucode_boot.v_addr)
  2669. goto err_pci_alloc;
  2670. }
  2671. /* Copy images into buffers for card's bus-master reads ... */
  2672. /* Runtime instructions (first block of data in file) */
  2673. src = &ucode->data[0];
  2674. len = priv->ucode_code.len;
  2675. IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
  2676. memcpy(priv->ucode_code.v_addr, src, len);
  2677. IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
  2678. priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
  2679. /* Runtime data (2nd block)
  2680. * NOTE: Copy into backup buffer will be done in iwl4965_up() */
  2681. src = &ucode->data[inst_size];
  2682. len = priv->ucode_data.len;
  2683. IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
  2684. memcpy(priv->ucode_data.v_addr, src, len);
  2685. memcpy(priv->ucode_data_backup.v_addr, src, len);
  2686. /* Initialization instructions (3rd block) */
  2687. if (init_size) {
  2688. src = &ucode->data[inst_size + data_size];
  2689. len = priv->ucode_init.len;
  2690. IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
  2691. len);
  2692. memcpy(priv->ucode_init.v_addr, src, len);
  2693. }
  2694. /* Initialization data (4th block) */
  2695. if (init_data_size) {
  2696. src = &ucode->data[inst_size + data_size + init_size];
  2697. len = priv->ucode_init_data.len;
  2698. IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
  2699. len);
  2700. memcpy(priv->ucode_init_data.v_addr, src, len);
  2701. }
  2702. /* Bootstrap instructions (5th block) */
  2703. src = &ucode->data[inst_size + data_size + init_size + init_data_size];
  2704. len = priv->ucode_boot.len;
  2705. IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len);
  2706. memcpy(priv->ucode_boot.v_addr, src, len);
  2707. /* We have our copies now, allow OS release its copies */
  2708. release_firmware(ucode_raw);
  2709. return 0;
  2710. err_pci_alloc:
  2711. IWL_ERROR("failed to allocate pci memory\n");
  2712. ret = -ENOMEM;
  2713. iwl4965_dealloc_ucode_pci(priv);
  2714. err_release:
  2715. release_firmware(ucode_raw);
  2716. error:
  2717. return ret;
  2718. }
  2719. /**
  2720. * iwl4965_alive_start - called after REPLY_ALIVE notification received
  2721. * from protocol/runtime uCode (initialization uCode's
  2722. * Alive gets handled by iwl4965_init_alive_start()).
  2723. */
  2724. static void iwl4965_alive_start(struct iwl_priv *priv)
  2725. {
  2726. int ret = 0;
  2727. IWL_DEBUG_INFO("Runtime Alive received.\n");
  2728. if (priv->card_alive.is_valid != UCODE_VALID_OK) {
  2729. /* We had an error bringing up the hardware, so take it
  2730. * all the way back down so we can try again */
  2731. IWL_DEBUG_INFO("Alive failed.\n");
  2732. goto restart;
  2733. }
  2734. /* Initialize uCode has loaded Runtime uCode ... verify inst image.
  2735. * This is a paranoid check, because we would not have gotten the
  2736. * "runtime" alive if code weren't properly loaded. */
  2737. if (iwl_verify_ucode(priv)) {
  2738. /* Runtime instruction load was bad;
  2739. * take it all the way back down so we can try again */
  2740. IWL_DEBUG_INFO("Bad runtime uCode load.\n");
  2741. goto restart;
  2742. }
  2743. iwlcore_clear_stations_table(priv);
  2744. ret = priv->cfg->ops->lib->alive_notify(priv);
  2745. if (ret) {
  2746. IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
  2747. ret);
  2748. goto restart;
  2749. }
  2750. /* After the ALIVE response, we can send host commands to 4965 uCode */
  2751. set_bit(STATUS_ALIVE, &priv->status);
  2752. /* Clear out the uCode error bit if it is set */
  2753. clear_bit(STATUS_FW_ERROR, &priv->status);
  2754. if (iwl_is_rfkill(priv))
  2755. return;
  2756. ieee80211_wake_queues(priv->hw);
  2757. priv->active_rate = priv->rates_mask;
  2758. priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
  2759. if (iwl_is_associated(priv)) {
  2760. struct iwl_rxon_cmd *active_rxon =
  2761. (struct iwl_rxon_cmd *)&priv->active_rxon;
  2762. memcpy(&priv->staging_rxon, &priv->active_rxon,
  2763. sizeof(priv->staging_rxon));
  2764. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2765. } else {
  2766. /* Initialize our rx_config data */
  2767. iwl4965_connection_init_rx_config(priv);
  2768. memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  2769. }
  2770. /* Configure Bluetooth device coexistence support */
  2771. iwl4965_send_bt_config(priv);
  2772. /* Configure the adapter for unassociated operation */
  2773. iwl4965_commit_rxon(priv);
  2774. /* At this point, the NIC is initialized and operational */
  2775. priv->notif_missed_beacons = 0;
  2776. iwl4965_rf_kill_ct_config(priv);
  2777. iwl_leds_register(priv);
  2778. IWL_DEBUG_INFO("ALIVE processing complete.\n");
  2779. set_bit(STATUS_READY, &priv->status);
  2780. wake_up_interruptible(&priv->wait_command_queue);
  2781. if (priv->error_recovering)
  2782. iwl4965_error_recovery(priv);
  2783. iwlcore_low_level_notify(priv, IWLCORE_START_EVT);
  2784. ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC);
  2785. return;
  2786. restart:
  2787. queue_work(priv->workqueue, &priv->restart);
  2788. }
  2789. static void iwl4965_cancel_deferred_work(struct iwl_priv *priv);
  2790. static void __iwl4965_down(struct iwl_priv *priv)
  2791. {
  2792. unsigned long flags;
  2793. int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
  2794. struct ieee80211_conf *conf = NULL;
  2795. IWL_DEBUG_INFO(DRV_NAME " is going down\n");
  2796. conf = ieee80211_get_hw_conf(priv->hw);
  2797. if (!exit_pending)
  2798. set_bit(STATUS_EXIT_PENDING, &priv->status);
  2799. iwl_leds_unregister(priv);
  2800. iwlcore_low_level_notify(priv, IWLCORE_STOP_EVT);
  2801. iwlcore_clear_stations_table(priv);
  2802. /* Unblock any waiting calls */
  2803. wake_up_interruptible_all(&priv->wait_command_queue);
  2804. /* Wipe out the EXIT_PENDING status bit if we are not actually
  2805. * exiting the module */
  2806. if (!exit_pending)
  2807. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  2808. /* stop and reset the on-board processor */
  2809. iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  2810. /* tell the device to stop sending interrupts */
  2811. spin_lock_irqsave(&priv->lock, flags);
  2812. iwl4965_disable_interrupts(priv);
  2813. spin_unlock_irqrestore(&priv->lock, flags);
  2814. iwl_synchronize_irq(priv);
  2815. if (priv->mac80211_registered)
  2816. ieee80211_stop_queues(priv->hw);
  2817. /* If we have not previously called iwl4965_init() then
  2818. * clear all bits but the RF Kill and SUSPEND bits and return */
  2819. if (!iwl_is_init(priv)) {
  2820. priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  2821. STATUS_RF_KILL_HW |
  2822. test_bit(STATUS_RF_KILL_SW, &priv->status) <<
  2823. STATUS_RF_KILL_SW |
  2824. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  2825. STATUS_GEO_CONFIGURED |
  2826. test_bit(STATUS_IN_SUSPEND, &priv->status) <<
  2827. STATUS_IN_SUSPEND;
  2828. goto exit;
  2829. }
  2830. /* ...otherwise clear out all the status bits but the RF Kill and
  2831. * SUSPEND bits and continue taking the NIC down. */
  2832. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  2833. STATUS_RF_KILL_HW |
  2834. test_bit(STATUS_RF_KILL_SW, &priv->status) <<
  2835. STATUS_RF_KILL_SW |
  2836. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  2837. STATUS_GEO_CONFIGURED |
  2838. test_bit(STATUS_IN_SUSPEND, &priv->status) <<
  2839. STATUS_IN_SUSPEND |
  2840. test_bit(STATUS_FW_ERROR, &priv->status) <<
  2841. STATUS_FW_ERROR;
  2842. spin_lock_irqsave(&priv->lock, flags);
  2843. iwl_clear_bit(priv, CSR_GP_CNTRL,
  2844. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  2845. spin_unlock_irqrestore(&priv->lock, flags);
  2846. iwl4965_hw_txq_ctx_stop(priv);
  2847. iwl4965_hw_rxq_stop(priv);
  2848. spin_lock_irqsave(&priv->lock, flags);
  2849. if (!iwl_grab_nic_access(priv)) {
  2850. iwl_write_prph(priv, APMG_CLK_DIS_REG,
  2851. APMG_CLK_VAL_DMA_CLK_RQT);
  2852. iwl_release_nic_access(priv);
  2853. }
  2854. spin_unlock_irqrestore(&priv->lock, flags);
  2855. udelay(5);
  2856. iwl4965_hw_nic_stop_master(priv);
  2857. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  2858. iwl4965_hw_nic_reset(priv);
  2859. priv->cfg->ops->lib->free_shared_mem(priv);
  2860. exit:
  2861. memset(&priv->card_alive, 0, sizeof(struct iwl4965_alive_resp));
  2862. if (priv->ibss_beacon)
  2863. dev_kfree_skb(priv->ibss_beacon);
  2864. priv->ibss_beacon = NULL;
  2865. /* clear out any free frames */
  2866. iwl_clear_free_frames(priv);
  2867. }
  2868. static void iwl4965_down(struct iwl_priv *priv)
  2869. {
  2870. mutex_lock(&priv->mutex);
  2871. __iwl4965_down(priv);
  2872. mutex_unlock(&priv->mutex);
  2873. iwl4965_cancel_deferred_work(priv);
  2874. }
  2875. #define MAX_HW_RESTARTS 5
  2876. static int __iwl4965_up(struct iwl_priv *priv)
  2877. {
  2878. int i;
  2879. int ret;
  2880. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  2881. IWL_WARNING("Exit pending; will not bring the NIC up\n");
  2882. return -EIO;
  2883. }
  2884. if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
  2885. IWL_WARNING("Radio disabled by SW RF kill (module "
  2886. "parameter)\n");
  2887. iwl_rfkill_set_hw_state(priv);
  2888. return -ENODEV;
  2889. }
  2890. if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
  2891. IWL_ERROR("ucode not available for device bringup\n");
  2892. return -EIO;
  2893. }
  2894. /* If platform's RF_KILL switch is NOT set to KILL */
  2895. if (iwl_read32(priv, CSR_GP_CNTRL) &
  2896. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  2897. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2898. else {
  2899. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2900. if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
  2901. iwl_rfkill_set_hw_state(priv);
  2902. IWL_WARNING("Radio disabled by HW RF Kill switch\n");
  2903. return -ENODEV;
  2904. }
  2905. }
  2906. iwl_rfkill_set_hw_state(priv);
  2907. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  2908. ret = priv->cfg->ops->lib->alloc_shared_mem(priv);
  2909. if (ret) {
  2910. IWL_ERROR("Unable to allocate shared memory\n");
  2911. return ret;
  2912. }
  2913. ret = iwl_hw_nic_init(priv);
  2914. if (ret) {
  2915. IWL_ERROR("Unable to init nic\n");
  2916. return ret;
  2917. }
  2918. /* make sure rfkill handshake bits are cleared */
  2919. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2920. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  2921. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  2922. /* clear (again), then enable host interrupts */
  2923. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  2924. iwl4965_enable_interrupts(priv);
  2925. /* really make sure rfkill handshake bits are cleared */
  2926. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2927. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2928. /* Copy original ucode data image from disk into backup cache.
  2929. * This will be used to initialize the on-board processor's
  2930. * data SRAM for a clean start when the runtime program first loads. */
  2931. memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
  2932. priv->ucode_data.len);
  2933. /* We return success when we resume from suspend and rf_kill is on. */
  2934. if (test_bit(STATUS_RF_KILL_HW, &priv->status))
  2935. return 0;
  2936. for (i = 0; i < MAX_HW_RESTARTS; i++) {
  2937. iwlcore_clear_stations_table(priv);
  2938. /* load bootstrap state machine,
  2939. * load bootstrap program into processor's memory,
  2940. * prepare to load the "initialize" uCode */
  2941. ret = priv->cfg->ops->lib->load_ucode(priv);
  2942. if (ret) {
  2943. IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret);
  2944. continue;
  2945. }
  2946. /* start card; "initialize" will load runtime ucode */
  2947. iwl4965_nic_start(priv);
  2948. IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
  2949. return 0;
  2950. }
  2951. set_bit(STATUS_EXIT_PENDING, &priv->status);
  2952. __iwl4965_down(priv);
  2953. /* tried to restart and config the device for as long as our
  2954. * patience could withstand */
  2955. IWL_ERROR("Unable to initialize device after %d attempts.\n", i);
  2956. return -EIO;
  2957. }
  2958. /*****************************************************************************
  2959. *
  2960. * Workqueue callbacks
  2961. *
  2962. *****************************************************************************/
  2963. static void iwl4965_bg_init_alive_start(struct work_struct *data)
  2964. {
  2965. struct iwl_priv *priv =
  2966. container_of(data, struct iwl_priv, init_alive_start.work);
  2967. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2968. return;
  2969. mutex_lock(&priv->mutex);
  2970. priv->cfg->ops->lib->init_alive_start(priv);
  2971. mutex_unlock(&priv->mutex);
  2972. }
  2973. static void iwl4965_bg_alive_start(struct work_struct *data)
  2974. {
  2975. struct iwl_priv *priv =
  2976. container_of(data, struct iwl_priv, alive_start.work);
  2977. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2978. return;
  2979. mutex_lock(&priv->mutex);
  2980. iwl4965_alive_start(priv);
  2981. mutex_unlock(&priv->mutex);
  2982. }
  2983. static void iwl4965_bg_rf_kill(struct work_struct *work)
  2984. {
  2985. struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill);
  2986. wake_up_interruptible(&priv->wait_command_queue);
  2987. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2988. return;
  2989. mutex_lock(&priv->mutex);
  2990. if (!iwl_is_rfkill(priv)) {
  2991. IWL_DEBUG(IWL_DL_RF_KILL,
  2992. "HW and/or SW RF Kill no longer active, restarting "
  2993. "device\n");
  2994. if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
  2995. queue_work(priv->workqueue, &priv->restart);
  2996. } else {
  2997. /* make sure mac80211 stop sending Tx frame */
  2998. if (priv->mac80211_registered)
  2999. ieee80211_stop_queues(priv->hw);
  3000. if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
  3001. IWL_DEBUG_RF_KILL("Can not turn radio back on - "
  3002. "disabled by SW switch\n");
  3003. else
  3004. IWL_WARNING("Radio Frequency Kill Switch is On:\n"
  3005. "Kill switch must be turned off for "
  3006. "wireless networking to work.\n");
  3007. }
  3008. iwl_rfkill_set_hw_state(priv);
  3009. mutex_unlock(&priv->mutex);
  3010. }
  3011. static void iwl4965_bg_set_monitor(struct work_struct *work)
  3012. {
  3013. struct iwl_priv *priv = container_of(work,
  3014. struct iwl_priv, set_monitor);
  3015. IWL_DEBUG(IWL_DL_STATE, "setting monitor mode\n");
  3016. mutex_lock(&priv->mutex);
  3017. if (!iwl_is_ready(priv))
  3018. IWL_DEBUG(IWL_DL_STATE, "leave - not ready\n");
  3019. else
  3020. if (iwl4965_set_mode(priv, IEEE80211_IF_TYPE_MNTR) != 0)
  3021. IWL_ERROR("iwl4965_set_mode() failed\n");
  3022. mutex_unlock(&priv->mutex);
  3023. }
  3024. #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
  3025. static void iwl4965_bg_scan_check(struct work_struct *data)
  3026. {
  3027. struct iwl_priv *priv =
  3028. container_of(data, struct iwl_priv, scan_check.work);
  3029. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3030. return;
  3031. mutex_lock(&priv->mutex);
  3032. if (test_bit(STATUS_SCANNING, &priv->status) ||
  3033. test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  3034. IWL_DEBUG(IWL_DL_SCAN, "Scan completion watchdog resetting "
  3035. "adapter (%dms)\n",
  3036. jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG));
  3037. if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
  3038. iwl4965_send_scan_abort(priv);
  3039. }
  3040. mutex_unlock(&priv->mutex);
  3041. }
  3042. static void iwl4965_bg_request_scan(struct work_struct *data)
  3043. {
  3044. struct iwl_priv *priv =
  3045. container_of(data, struct iwl_priv, request_scan);
  3046. struct iwl_host_cmd cmd = {
  3047. .id = REPLY_SCAN_CMD,
  3048. .len = sizeof(struct iwl4965_scan_cmd),
  3049. .meta.flags = CMD_SIZE_HUGE,
  3050. };
  3051. struct iwl4965_scan_cmd *scan;
  3052. struct ieee80211_conf *conf = NULL;
  3053. u16 cmd_len;
  3054. enum ieee80211_band band;
  3055. u8 direct_mask;
  3056. int ret = 0;
  3057. conf = ieee80211_get_hw_conf(priv->hw);
  3058. mutex_lock(&priv->mutex);
  3059. if (!iwl_is_ready(priv)) {
  3060. IWL_WARNING("request scan called when driver not ready.\n");
  3061. goto done;
  3062. }
  3063. /* Make sure the scan wasn't cancelled before this queued work
  3064. * was given the chance to run... */
  3065. if (!test_bit(STATUS_SCANNING, &priv->status))
  3066. goto done;
  3067. /* This should never be called or scheduled if there is currently
  3068. * a scan active in the hardware. */
  3069. if (test_bit(STATUS_SCAN_HW, &priv->status)) {
  3070. IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
  3071. "Ignoring second request.\n");
  3072. ret = -EIO;
  3073. goto done;
  3074. }
  3075. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  3076. IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
  3077. goto done;
  3078. }
  3079. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  3080. IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
  3081. goto done;
  3082. }
  3083. if (iwl_is_rfkill(priv)) {
  3084. IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
  3085. goto done;
  3086. }
  3087. if (!test_bit(STATUS_READY, &priv->status)) {
  3088. IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
  3089. goto done;
  3090. }
  3091. if (!priv->scan_bands) {
  3092. IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
  3093. goto done;
  3094. }
  3095. if (!priv->scan) {
  3096. priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) +
  3097. IWL_MAX_SCAN_SIZE, GFP_KERNEL);
  3098. if (!priv->scan) {
  3099. ret = -ENOMEM;
  3100. goto done;
  3101. }
  3102. }
  3103. scan = priv->scan;
  3104. memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE);
  3105. scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
  3106. scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
  3107. if (iwl_is_associated(priv)) {
  3108. u16 interval = 0;
  3109. u32 extra;
  3110. u32 suspend_time = 100;
  3111. u32 scan_suspend_time = 100;
  3112. unsigned long flags;
  3113. IWL_DEBUG_INFO("Scanning while associated...\n");
  3114. spin_lock_irqsave(&priv->lock, flags);
  3115. interval = priv->beacon_int;
  3116. spin_unlock_irqrestore(&priv->lock, flags);
  3117. scan->suspend_time = 0;
  3118. scan->max_out_time = cpu_to_le32(200 * 1024);
  3119. if (!interval)
  3120. interval = suspend_time;
  3121. extra = (suspend_time / interval) << 22;
  3122. scan_suspend_time = (extra |
  3123. ((suspend_time % interval) * 1024));
  3124. scan->suspend_time = cpu_to_le32(scan_suspend_time);
  3125. IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
  3126. scan_suspend_time, interval);
  3127. }
  3128. /* We should add the ability for user to lock to PASSIVE ONLY */
  3129. if (priv->one_direct_scan) {
  3130. IWL_DEBUG_SCAN
  3131. ("Kicking off one direct scan for '%s'\n",
  3132. iwl4965_escape_essid(priv->direct_ssid,
  3133. priv->direct_ssid_len));
  3134. scan->direct_scan[0].id = WLAN_EID_SSID;
  3135. scan->direct_scan[0].len = priv->direct_ssid_len;
  3136. memcpy(scan->direct_scan[0].ssid,
  3137. priv->direct_ssid, priv->direct_ssid_len);
  3138. direct_mask = 1;
  3139. } else if (!iwl_is_associated(priv) && priv->essid_len) {
  3140. IWL_DEBUG_SCAN
  3141. ("Kicking off one direct scan for '%s' when not associated\n",
  3142. iwl4965_escape_essid(priv->essid, priv->essid_len));
  3143. scan->direct_scan[0].id = WLAN_EID_SSID;
  3144. scan->direct_scan[0].len = priv->essid_len;
  3145. memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
  3146. direct_mask = 1;
  3147. } else {
  3148. IWL_DEBUG_SCAN("Kicking off one indirect scan.\n");
  3149. direct_mask = 0;
  3150. }
  3151. scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
  3152. scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
  3153. scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  3154. switch (priv->scan_bands) {
  3155. case 2:
  3156. scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
  3157. scan->tx_cmd.rate_n_flags =
  3158. iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP,
  3159. RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK);
  3160. scan->good_CRC_th = 0;
  3161. band = IEEE80211_BAND_2GHZ;
  3162. break;
  3163. case 1:
  3164. scan->tx_cmd.rate_n_flags =
  3165. iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP,
  3166. RATE_MCS_ANT_B_MSK);
  3167. scan->good_CRC_th = IWL_GOOD_CRC_TH;
  3168. band = IEEE80211_BAND_5GHZ;
  3169. break;
  3170. default:
  3171. IWL_WARNING("Invalid scan band count\n");
  3172. goto done;
  3173. }
  3174. /* We don't build a direct scan probe request; the uCode will do
  3175. * that based on the direct_mask added to each channel entry */
  3176. cmd_len = iwl4965_fill_probe_req(priv, band,
  3177. (struct ieee80211_mgmt *)scan->data,
  3178. IWL_MAX_SCAN_SIZE - sizeof(*scan), 0);
  3179. scan->tx_cmd.len = cpu_to_le16(cmd_len);
  3180. /* select Rx chains */
  3181. /* Force use of chains B and C (0x6) for scan Rx.
  3182. * Avoid A (0x1) because of its off-channel reception on A-band.
  3183. * MIMO is not used here, but value is required to make uCode happy. */
  3184. scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK |
  3185. cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) |
  3186. (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) |
  3187. (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS));
  3188. if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR)
  3189. scan->filter_flags = RXON_FILTER_PROMISC_MSK;
  3190. if (direct_mask)
  3191. scan->channel_count =
  3192. iwl4965_get_channels_for_scan(
  3193. priv, band, 1, /* active */
  3194. direct_mask,
  3195. (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
  3196. else
  3197. scan->channel_count =
  3198. iwl4965_get_channels_for_scan(
  3199. priv, band, 0, /* passive */
  3200. direct_mask,
  3201. (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
  3202. scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK |
  3203. RXON_FILTER_BCON_AWARE_MSK);
  3204. cmd.len += le16_to_cpu(scan->tx_cmd.len) +
  3205. scan->channel_count * sizeof(struct iwl4965_scan_channel);
  3206. cmd.data = scan;
  3207. scan->len = cpu_to_le16(cmd.len);
  3208. set_bit(STATUS_SCAN_HW, &priv->status);
  3209. ret = iwl_send_cmd_sync(priv, &cmd);
  3210. if (ret)
  3211. goto done;
  3212. queue_delayed_work(priv->workqueue, &priv->scan_check,
  3213. IWL_SCAN_CHECK_WATCHDOG);
  3214. mutex_unlock(&priv->mutex);
  3215. return;
  3216. done:
  3217. /* inform mac80211 scan aborted */
  3218. queue_work(priv->workqueue, &priv->scan_completed);
  3219. mutex_unlock(&priv->mutex);
  3220. }
  3221. static void iwl4965_bg_up(struct work_struct *data)
  3222. {
  3223. struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
  3224. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3225. return;
  3226. mutex_lock(&priv->mutex);
  3227. __iwl4965_up(priv);
  3228. mutex_unlock(&priv->mutex);
  3229. }
  3230. static void iwl4965_bg_restart(struct work_struct *data)
  3231. {
  3232. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  3233. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3234. return;
  3235. iwl4965_down(priv);
  3236. queue_work(priv->workqueue, &priv->up);
  3237. }
  3238. static void iwl4965_bg_rx_replenish(struct work_struct *data)
  3239. {
  3240. struct iwl_priv *priv =
  3241. container_of(data, struct iwl_priv, rx_replenish);
  3242. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3243. return;
  3244. mutex_lock(&priv->mutex);
  3245. iwl_rx_replenish(priv);
  3246. mutex_unlock(&priv->mutex);
  3247. }
  3248. #define IWL_DELAY_NEXT_SCAN (HZ*2)
  3249. static void iwl4965_post_associate(struct iwl_priv *priv)
  3250. {
  3251. struct ieee80211_conf *conf = NULL;
  3252. int ret = 0;
  3253. DECLARE_MAC_BUF(mac);
  3254. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  3255. IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__);
  3256. return;
  3257. }
  3258. IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
  3259. priv->assoc_id,
  3260. print_mac(mac, priv->active_rxon.bssid_addr));
  3261. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3262. return;
  3263. if (!priv->vif || !priv->is_open)
  3264. return;
  3265. iwl4965_scan_cancel_timeout(priv, 200);
  3266. conf = ieee80211_get_hw_conf(priv->hw);
  3267. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3268. iwl4965_commit_rxon(priv);
  3269. memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
  3270. iwl4965_setup_rxon_timing(priv);
  3271. ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
  3272. sizeof(priv->rxon_timing), &priv->rxon_timing);
  3273. if (ret)
  3274. IWL_WARNING("REPLY_RXON_TIMING failed - "
  3275. "Attempting to continue.\n");
  3276. priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  3277. #ifdef CONFIG_IWL4965_HT
  3278. if (priv->current_ht_config.is_ht)
  3279. iwl_set_rxon_ht(priv, &priv->current_ht_config);
  3280. #endif /* CONFIG_IWL4965_HT*/
  3281. iwl_set_rxon_chain(priv);
  3282. priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
  3283. IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
  3284. priv->assoc_id, priv->beacon_int);
  3285. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  3286. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  3287. else
  3288. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  3289. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
  3290. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
  3291. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  3292. else
  3293. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  3294. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  3295. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  3296. }
  3297. iwl4965_commit_rxon(priv);
  3298. switch (priv->iw_mode) {
  3299. case IEEE80211_IF_TYPE_STA:
  3300. iwl4965_rate_scale_init(priv->hw, IWL_AP_ID);
  3301. break;
  3302. case IEEE80211_IF_TYPE_IBSS:
  3303. /* clear out the station table */
  3304. iwlcore_clear_stations_table(priv);
  3305. iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
  3306. iwl_rxon_add_station(priv, priv->bssid, 0);
  3307. iwl4965_rate_scale_init(priv->hw, IWL_STA_ID);
  3308. iwl4965_send_beacon_cmd(priv);
  3309. break;
  3310. default:
  3311. IWL_ERROR("%s Should not be called in %d mode\n",
  3312. __FUNCTION__, priv->iw_mode);
  3313. break;
  3314. }
  3315. iwl4965_sequence_reset(priv);
  3316. /* Enable Rx differential gain and sensitivity calibrations */
  3317. iwl_chain_noise_reset(priv);
  3318. priv->start_calib = 1;
  3319. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  3320. priv->assoc_station_added = 1;
  3321. iwl4965_activate_qos(priv, 0);
  3322. iwl_power_update_mode(priv, 0);
  3323. /* we have just associated, don't start scan too early */
  3324. priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
  3325. }
  3326. static void iwl4965_bg_post_associate(struct work_struct *data)
  3327. {
  3328. struct iwl_priv *priv = container_of(data, struct iwl_priv,
  3329. post_associate.work);
  3330. mutex_lock(&priv->mutex);
  3331. iwl4965_post_associate(priv);
  3332. mutex_unlock(&priv->mutex);
  3333. }
  3334. static void iwl4965_bg_abort_scan(struct work_struct *work)
  3335. {
  3336. struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan);
  3337. if (!iwl_is_ready(priv))
  3338. return;
  3339. mutex_lock(&priv->mutex);
  3340. set_bit(STATUS_SCAN_ABORTING, &priv->status);
  3341. iwl4965_send_scan_abort(priv);
  3342. mutex_unlock(&priv->mutex);
  3343. }
  3344. static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
  3345. static void iwl4965_bg_scan_completed(struct work_struct *work)
  3346. {
  3347. struct iwl_priv *priv =
  3348. container_of(work, struct iwl_priv, scan_completed);
  3349. IWL_DEBUG(IWL_DL_SCAN, "SCAN complete scan\n");
  3350. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3351. return;
  3352. if (test_bit(STATUS_CONF_PENDING, &priv->status))
  3353. iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw));
  3354. ieee80211_scan_completed(priv->hw);
  3355. /* Since setting the TXPOWER may have been deferred while
  3356. * performing the scan, fire one off */
  3357. mutex_lock(&priv->mutex);
  3358. iwl4965_hw_reg_send_txpower(priv);
  3359. mutex_unlock(&priv->mutex);
  3360. }
  3361. /*****************************************************************************
  3362. *
  3363. * mac80211 entry point functions
  3364. *
  3365. *****************************************************************************/
  3366. #define UCODE_READY_TIMEOUT (2 * HZ)
  3367. static int iwl4965_mac_start(struct ieee80211_hw *hw)
  3368. {
  3369. struct iwl_priv *priv = hw->priv;
  3370. int ret;
  3371. IWL_DEBUG_MAC80211("enter\n");
  3372. if (pci_enable_device(priv->pci_dev)) {
  3373. IWL_ERROR("Fail to pci_enable_device\n");
  3374. return -ENODEV;
  3375. }
  3376. pci_restore_state(priv->pci_dev);
  3377. pci_enable_msi(priv->pci_dev);
  3378. ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED,
  3379. DRV_NAME, priv);
  3380. if (ret) {
  3381. IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq);
  3382. goto out_disable_msi;
  3383. }
  3384. /* we should be verifying the device is ready to be opened */
  3385. mutex_lock(&priv->mutex);
  3386. memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd));
  3387. /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
  3388. * ucode filename and max sizes are card-specific. */
  3389. if (!priv->ucode_code.len) {
  3390. ret = iwl4965_read_ucode(priv);
  3391. if (ret) {
  3392. IWL_ERROR("Could not read microcode: %d\n", ret);
  3393. mutex_unlock(&priv->mutex);
  3394. goto out_release_irq;
  3395. }
  3396. }
  3397. ret = __iwl4965_up(priv);
  3398. mutex_unlock(&priv->mutex);
  3399. if (ret)
  3400. goto out_release_irq;
  3401. IWL_DEBUG_INFO("Start UP work done.\n");
  3402. if (test_bit(STATUS_IN_SUSPEND, &priv->status))
  3403. return 0;
  3404. /* Wait for START_ALIVE from ucode. Otherwise callbacks from
  3405. * mac80211 will not be run successfully. */
  3406. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  3407. test_bit(STATUS_READY, &priv->status),
  3408. UCODE_READY_TIMEOUT);
  3409. if (!ret) {
  3410. if (!test_bit(STATUS_READY, &priv->status)) {
  3411. IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n",
  3412. jiffies_to_msecs(UCODE_READY_TIMEOUT));
  3413. ret = -ETIMEDOUT;
  3414. goto out_release_irq;
  3415. }
  3416. }
  3417. priv->is_open = 1;
  3418. IWL_DEBUG_MAC80211("leave\n");
  3419. return 0;
  3420. out_release_irq:
  3421. free_irq(priv->pci_dev->irq, priv);
  3422. out_disable_msi:
  3423. pci_disable_msi(priv->pci_dev);
  3424. pci_disable_device(priv->pci_dev);
  3425. priv->is_open = 0;
  3426. IWL_DEBUG_MAC80211("leave - failed\n");
  3427. return ret;
  3428. }
  3429. static void iwl4965_mac_stop(struct ieee80211_hw *hw)
  3430. {
  3431. struct iwl_priv *priv = hw->priv;
  3432. IWL_DEBUG_MAC80211("enter\n");
  3433. if (!priv->is_open) {
  3434. IWL_DEBUG_MAC80211("leave - skip\n");
  3435. return;
  3436. }
  3437. priv->is_open = 0;
  3438. if (iwl_is_ready_rf(priv)) {
  3439. /* stop mac, cancel any scan request and clear
  3440. * RXON_FILTER_ASSOC_MSK BIT
  3441. */
  3442. mutex_lock(&priv->mutex);
  3443. iwl4965_scan_cancel_timeout(priv, 100);
  3444. cancel_delayed_work(&priv->post_associate);
  3445. mutex_unlock(&priv->mutex);
  3446. }
  3447. iwl4965_down(priv);
  3448. flush_workqueue(priv->workqueue);
  3449. free_irq(priv->pci_dev->irq, priv);
  3450. pci_disable_msi(priv->pci_dev);
  3451. pci_save_state(priv->pci_dev);
  3452. pci_disable_device(priv->pci_dev);
  3453. IWL_DEBUG_MAC80211("leave\n");
  3454. }
  3455. static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  3456. {
  3457. struct iwl_priv *priv = hw->priv;
  3458. IWL_DEBUG_MAC80211("enter\n");
  3459. if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
  3460. IWL_DEBUG_MAC80211("leave - monitor\n");
  3461. return -1;
  3462. }
  3463. IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  3464. ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
  3465. if (iwl_tx_skb(priv, skb))
  3466. dev_kfree_skb_any(skb);
  3467. IWL_DEBUG_MAC80211("leave\n");
  3468. return 0;
  3469. }
  3470. static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
  3471. struct ieee80211_if_init_conf *conf)
  3472. {
  3473. struct iwl_priv *priv = hw->priv;
  3474. unsigned long flags;
  3475. DECLARE_MAC_BUF(mac);
  3476. IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
  3477. if (priv->vif) {
  3478. IWL_DEBUG_MAC80211("leave - vif != NULL\n");
  3479. return -EOPNOTSUPP;
  3480. }
  3481. spin_lock_irqsave(&priv->lock, flags);
  3482. priv->vif = conf->vif;
  3483. spin_unlock_irqrestore(&priv->lock, flags);
  3484. mutex_lock(&priv->mutex);
  3485. if (conf->mac_addr) {
  3486. IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr));
  3487. memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
  3488. }
  3489. if (iwl_is_ready(priv))
  3490. iwl4965_set_mode(priv, conf->type);
  3491. mutex_unlock(&priv->mutex);
  3492. IWL_DEBUG_MAC80211("leave\n");
  3493. return 0;
  3494. }
  3495. /**
  3496. * iwl4965_mac_config - mac80211 config callback
  3497. *
  3498. * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
  3499. * be set inappropriately and the driver currently sets the hardware up to
  3500. * use it whenever needed.
  3501. */
  3502. static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
  3503. {
  3504. struct iwl_priv *priv = hw->priv;
  3505. const struct iwl_channel_info *ch_info;
  3506. unsigned long flags;
  3507. int ret = 0;
  3508. mutex_lock(&priv->mutex);
  3509. IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
  3510. priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP);
  3511. if (!iwl_is_ready(priv)) {
  3512. IWL_DEBUG_MAC80211("leave - not ready\n");
  3513. ret = -EIO;
  3514. goto out;
  3515. }
  3516. if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
  3517. test_bit(STATUS_SCANNING, &priv->status))) {
  3518. IWL_DEBUG_MAC80211("leave - scanning\n");
  3519. set_bit(STATUS_CONF_PENDING, &priv->status);
  3520. mutex_unlock(&priv->mutex);
  3521. return 0;
  3522. }
  3523. spin_lock_irqsave(&priv->lock, flags);
  3524. ch_info = iwl_get_channel_info(priv, conf->channel->band,
  3525. ieee80211_frequency_to_channel(conf->channel->center_freq));
  3526. if (!is_channel_valid(ch_info)) {
  3527. IWL_DEBUG_MAC80211("leave - invalid channel\n");
  3528. spin_unlock_irqrestore(&priv->lock, flags);
  3529. ret = -EINVAL;
  3530. goto out;
  3531. }
  3532. #ifdef CONFIG_IWL4965_HT
  3533. /* if we are switching from ht to 2.4 clear flags
  3534. * from any ht related info since 2.4 does not
  3535. * support ht */
  3536. if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel->hw_value)
  3537. #ifdef IEEE80211_CONF_CHANNEL_SWITCH
  3538. && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH)
  3539. #endif
  3540. )
  3541. priv->staging_rxon.flags = 0;
  3542. #endif /* CONFIG_IWL4965_HT */
  3543. iwl_set_rxon_channel(priv, conf->channel->band,
  3544. ieee80211_frequency_to_channel(conf->channel->center_freq));
  3545. iwl4965_set_flags_for_phymode(priv, conf->channel->band);
  3546. /* The list of supported rates and rate mask can be different
  3547. * for each band; since the band may have changed, reset
  3548. * the rate mask to what mac80211 lists */
  3549. iwl4965_set_rate(priv);
  3550. spin_unlock_irqrestore(&priv->lock, flags);
  3551. #ifdef IEEE80211_CONF_CHANNEL_SWITCH
  3552. if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
  3553. iwl4965_hw_channel_switch(priv, conf->channel);
  3554. goto out;
  3555. }
  3556. #endif
  3557. if (priv->cfg->ops->lib->radio_kill_sw)
  3558. priv->cfg->ops->lib->radio_kill_sw(priv, !conf->radio_enabled);
  3559. if (!conf->radio_enabled) {
  3560. IWL_DEBUG_MAC80211("leave - radio disabled\n");
  3561. goto out;
  3562. }
  3563. if (iwl_is_rfkill(priv)) {
  3564. IWL_DEBUG_MAC80211("leave - RF kill\n");
  3565. ret = -EIO;
  3566. goto out;
  3567. }
  3568. iwl4965_set_rate(priv);
  3569. if (memcmp(&priv->active_rxon,
  3570. &priv->staging_rxon, sizeof(priv->staging_rxon)))
  3571. iwl4965_commit_rxon(priv);
  3572. else
  3573. IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
  3574. IWL_DEBUG_MAC80211("leave\n");
  3575. out:
  3576. clear_bit(STATUS_CONF_PENDING, &priv->status);
  3577. mutex_unlock(&priv->mutex);
  3578. return ret;
  3579. }
  3580. static void iwl4965_config_ap(struct iwl_priv *priv)
  3581. {
  3582. int ret = 0;
  3583. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3584. return;
  3585. /* The following should be done only at AP bring up */
  3586. if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) {
  3587. /* RXON - unassoc (to set timing command) */
  3588. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3589. iwl4965_commit_rxon(priv);
  3590. /* RXON Timing */
  3591. memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
  3592. iwl4965_setup_rxon_timing(priv);
  3593. ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
  3594. sizeof(priv->rxon_timing), &priv->rxon_timing);
  3595. if (ret)
  3596. IWL_WARNING("REPLY_RXON_TIMING failed - "
  3597. "Attempting to continue.\n");
  3598. iwl_set_rxon_chain(priv);
  3599. /* FIXME: what should be the assoc_id for AP? */
  3600. priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
  3601. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  3602. priv->staging_rxon.flags |=
  3603. RXON_FLG_SHORT_PREAMBLE_MSK;
  3604. else
  3605. priv->staging_rxon.flags &=
  3606. ~RXON_FLG_SHORT_PREAMBLE_MSK;
  3607. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
  3608. if (priv->assoc_capability &
  3609. WLAN_CAPABILITY_SHORT_SLOT_TIME)
  3610. priv->staging_rxon.flags |=
  3611. RXON_FLG_SHORT_SLOT_MSK;
  3612. else
  3613. priv->staging_rxon.flags &=
  3614. ~RXON_FLG_SHORT_SLOT_MSK;
  3615. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  3616. priv->staging_rxon.flags &=
  3617. ~RXON_FLG_SHORT_SLOT_MSK;
  3618. }
  3619. /* restore RXON assoc */
  3620. priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  3621. iwl4965_commit_rxon(priv);
  3622. iwl4965_activate_qos(priv, 1);
  3623. iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
  3624. }
  3625. iwl4965_send_beacon_cmd(priv);
  3626. /* FIXME - we need to add code here to detect a totally new
  3627. * configuration, reset the AP, unassoc, rxon timing, assoc,
  3628. * clear sta table, add BCAST sta... */
  3629. }
  3630. static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
  3631. struct ieee80211_vif *vif,
  3632. struct ieee80211_if_conf *conf)
  3633. {
  3634. struct iwl_priv *priv = hw->priv;
  3635. DECLARE_MAC_BUF(mac);
  3636. unsigned long flags;
  3637. int rc;
  3638. if (conf == NULL)
  3639. return -EIO;
  3640. if (priv->vif != vif) {
  3641. IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
  3642. return 0;
  3643. }
  3644. if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
  3645. (!conf->beacon || !conf->ssid_len)) {
  3646. IWL_DEBUG_MAC80211
  3647. ("Leaving in AP mode because HostAPD is not ready.\n");
  3648. return 0;
  3649. }
  3650. if (!iwl_is_alive(priv))
  3651. return -EAGAIN;
  3652. mutex_lock(&priv->mutex);
  3653. if (conf->bssid)
  3654. IWL_DEBUG_MAC80211("bssid: %s\n",
  3655. print_mac(mac, conf->bssid));
  3656. /*
  3657. * very dubious code was here; the probe filtering flag is never set:
  3658. *
  3659. if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
  3660. !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
  3661. */
  3662. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  3663. if (!conf->bssid) {
  3664. conf->bssid = priv->mac_addr;
  3665. memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
  3666. IWL_DEBUG_MAC80211("bssid was set to: %s\n",
  3667. print_mac(mac, conf->bssid));
  3668. }
  3669. if (priv->ibss_beacon)
  3670. dev_kfree_skb(priv->ibss_beacon);
  3671. priv->ibss_beacon = conf->beacon;
  3672. }
  3673. if (iwl_is_rfkill(priv))
  3674. goto done;
  3675. if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
  3676. !is_multicast_ether_addr(conf->bssid)) {
  3677. /* If there is currently a HW scan going on in the background
  3678. * then we need to cancel it else the RXON below will fail. */
  3679. if (iwl4965_scan_cancel_timeout(priv, 100)) {
  3680. IWL_WARNING("Aborted scan still in progress "
  3681. "after 100ms\n");
  3682. IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
  3683. mutex_unlock(&priv->mutex);
  3684. return -EAGAIN;
  3685. }
  3686. memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
  3687. /* TODO: Audit driver for usage of these members and see
  3688. * if mac80211 deprecates them (priv->bssid looks like it
  3689. * shouldn't be there, but I haven't scanned the IBSS code
  3690. * to verify) - jpk */
  3691. memcpy(priv->bssid, conf->bssid, ETH_ALEN);
  3692. if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
  3693. iwl4965_config_ap(priv);
  3694. else {
  3695. rc = iwl4965_commit_rxon(priv);
  3696. if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc)
  3697. iwl_rxon_add_station(
  3698. priv, priv->active_rxon.bssid_addr, 1);
  3699. }
  3700. } else {
  3701. iwl4965_scan_cancel_timeout(priv, 100);
  3702. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3703. iwl4965_commit_rxon(priv);
  3704. }
  3705. done:
  3706. spin_lock_irqsave(&priv->lock, flags);
  3707. if (!conf->ssid_len)
  3708. memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
  3709. else
  3710. memcpy(priv->essid, conf->ssid, conf->ssid_len);
  3711. priv->essid_len = conf->ssid_len;
  3712. spin_unlock_irqrestore(&priv->lock, flags);
  3713. IWL_DEBUG_MAC80211("leave\n");
  3714. mutex_unlock(&priv->mutex);
  3715. return 0;
  3716. }
  3717. static void iwl4965_configure_filter(struct ieee80211_hw *hw,
  3718. unsigned int changed_flags,
  3719. unsigned int *total_flags,
  3720. int mc_count, struct dev_addr_list *mc_list)
  3721. {
  3722. /*
  3723. * XXX: dummy
  3724. * see also iwl4965_connection_init_rx_config
  3725. */
  3726. struct iwl_priv *priv = hw->priv;
  3727. int new_flags = 0;
  3728. if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) {
  3729. if (*total_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) {
  3730. IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n",
  3731. IEEE80211_IF_TYPE_MNTR,
  3732. changed_flags, *total_flags);
  3733. /* queue work 'cuz mac80211 is holding a lock which
  3734. * prevents us from issuing (synchronous) f/w cmds */
  3735. queue_work(priv->workqueue, &priv->set_monitor);
  3736. new_flags &= FIF_PROMISC_IN_BSS |
  3737. FIF_OTHER_BSS |
  3738. FIF_ALLMULTI;
  3739. }
  3740. }
  3741. *total_flags = new_flags;
  3742. }
  3743. static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
  3744. struct ieee80211_if_init_conf *conf)
  3745. {
  3746. struct iwl_priv *priv = hw->priv;
  3747. IWL_DEBUG_MAC80211("enter\n");
  3748. mutex_lock(&priv->mutex);
  3749. if (iwl_is_ready_rf(priv)) {
  3750. iwl4965_scan_cancel_timeout(priv, 100);
  3751. cancel_delayed_work(&priv->post_associate);
  3752. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3753. iwl4965_commit_rxon(priv);
  3754. }
  3755. if (priv->vif == conf->vif) {
  3756. priv->vif = NULL;
  3757. memset(priv->bssid, 0, ETH_ALEN);
  3758. memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
  3759. priv->essid_len = 0;
  3760. }
  3761. mutex_unlock(&priv->mutex);
  3762. IWL_DEBUG_MAC80211("leave\n");
  3763. }
  3764. #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
  3765. static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
  3766. struct ieee80211_vif *vif,
  3767. struct ieee80211_bss_conf *bss_conf,
  3768. u32 changes)
  3769. {
  3770. struct iwl_priv *priv = hw->priv;
  3771. IWL_DEBUG_MAC80211("changes = 0x%X\n", changes);
  3772. if (changes & BSS_CHANGED_ERP_PREAMBLE) {
  3773. IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
  3774. bss_conf->use_short_preamble);
  3775. if (bss_conf->use_short_preamble)
  3776. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  3777. else
  3778. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  3779. }
  3780. if (changes & BSS_CHANGED_ERP_CTS_PROT) {
  3781. IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot);
  3782. if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
  3783. priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
  3784. else
  3785. priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
  3786. }
  3787. if (changes & BSS_CHANGED_HT) {
  3788. IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht);
  3789. iwl4965_ht_conf(priv, bss_conf);
  3790. iwl_set_rxon_chain(priv);
  3791. }
  3792. if (changes & BSS_CHANGED_ASSOC) {
  3793. IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc);
  3794. /* This should never happen as this function should
  3795. * never be called from interrupt context. */
  3796. if (WARN_ON_ONCE(in_interrupt()))
  3797. return;
  3798. if (bss_conf->assoc) {
  3799. priv->assoc_id = bss_conf->aid;
  3800. priv->beacon_int = bss_conf->beacon_int;
  3801. priv->timestamp = bss_conf->timestamp;
  3802. priv->assoc_capability = bss_conf->assoc_capability;
  3803. priv->next_scan_jiffies = jiffies +
  3804. IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
  3805. mutex_lock(&priv->mutex);
  3806. iwl4965_post_associate(priv);
  3807. mutex_unlock(&priv->mutex);
  3808. } else {
  3809. priv->assoc_id = 0;
  3810. IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc);
  3811. }
  3812. } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
  3813. IWL_DEBUG_MAC80211("Associated Changes %d\n", changes);
  3814. iwl_send_rxon_assoc(priv);
  3815. }
  3816. }
  3817. static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
  3818. {
  3819. int rc = 0;
  3820. unsigned long flags;
  3821. struct iwl_priv *priv = hw->priv;
  3822. IWL_DEBUG_MAC80211("enter\n");
  3823. mutex_lock(&priv->mutex);
  3824. spin_lock_irqsave(&priv->lock, flags);
  3825. if (!iwl_is_ready_rf(priv)) {
  3826. rc = -EIO;
  3827. IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
  3828. goto out_unlock;
  3829. }
  3830. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */
  3831. rc = -EIO;
  3832. IWL_ERROR("ERROR: APs don't scan\n");
  3833. goto out_unlock;
  3834. }
  3835. /* we don't schedule scan within next_scan_jiffies period */
  3836. if (priv->next_scan_jiffies &&
  3837. time_after(priv->next_scan_jiffies, jiffies)) {
  3838. rc = -EAGAIN;
  3839. goto out_unlock;
  3840. }
  3841. /* if we just finished scan ask for delay */
  3842. if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies +
  3843. IWL_DELAY_NEXT_SCAN, jiffies)) {
  3844. rc = -EAGAIN;
  3845. goto out_unlock;
  3846. }
  3847. if (len) {
  3848. IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
  3849. iwl4965_escape_essid(ssid, len), (int)len);
  3850. priv->one_direct_scan = 1;
  3851. priv->direct_ssid_len = (u8)
  3852. min((u8) len, (u8) IW_ESSID_MAX_SIZE);
  3853. memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
  3854. } else
  3855. priv->one_direct_scan = 0;
  3856. rc = iwl4965_scan_initiate(priv);
  3857. IWL_DEBUG_MAC80211("leave\n");
  3858. out_unlock:
  3859. spin_unlock_irqrestore(&priv->lock, flags);
  3860. mutex_unlock(&priv->mutex);
  3861. return rc;
  3862. }
  3863. static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw,
  3864. struct ieee80211_key_conf *keyconf, const u8 *addr,
  3865. u32 iv32, u16 *phase1key)
  3866. {
  3867. struct iwl_priv *priv = hw->priv;
  3868. u8 sta_id = IWL_INVALID_STATION;
  3869. unsigned long flags;
  3870. __le16 key_flags = 0;
  3871. int i;
  3872. DECLARE_MAC_BUF(mac);
  3873. IWL_DEBUG_MAC80211("enter\n");
  3874. sta_id = iwl_find_station(priv, addr);
  3875. if (sta_id == IWL_INVALID_STATION) {
  3876. IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
  3877. print_mac(mac, addr));
  3878. return;
  3879. }
  3880. iwl4965_scan_cancel_timeout(priv, 100);
  3881. key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
  3882. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  3883. key_flags &= ~STA_KEY_FLG_INVALID;
  3884. if (sta_id == priv->hw_params.bcast_sta_id)
  3885. key_flags |= STA_KEY_MULTICAST_MSK;
  3886. spin_lock_irqsave(&priv->sta_lock, flags);
  3887. priv->stations[sta_id].sta.key.key_flags = key_flags;
  3888. priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
  3889. for (i = 0; i < 5; i++)
  3890. priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
  3891. cpu_to_le16(phase1key[i]);
  3892. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  3893. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  3894. iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  3895. spin_unlock_irqrestore(&priv->sta_lock, flags);
  3896. IWL_DEBUG_MAC80211("leave\n");
  3897. }
  3898. static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  3899. const u8 *local_addr, const u8 *addr,
  3900. struct ieee80211_key_conf *key)
  3901. {
  3902. struct iwl_priv *priv = hw->priv;
  3903. DECLARE_MAC_BUF(mac);
  3904. int ret = 0;
  3905. u8 sta_id = IWL_INVALID_STATION;
  3906. u8 is_default_wep_key = 0;
  3907. IWL_DEBUG_MAC80211("enter\n");
  3908. if (priv->hw_params.sw_crypto) {
  3909. IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
  3910. return -EOPNOTSUPP;
  3911. }
  3912. if (is_zero_ether_addr(addr))
  3913. /* only support pairwise keys */
  3914. return -EOPNOTSUPP;
  3915. sta_id = iwl_find_station(priv, addr);
  3916. if (sta_id == IWL_INVALID_STATION) {
  3917. IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
  3918. print_mac(mac, addr));
  3919. return -EINVAL;
  3920. }
  3921. mutex_lock(&priv->mutex);
  3922. iwl4965_scan_cancel_timeout(priv, 100);
  3923. mutex_unlock(&priv->mutex);
  3924. /* If we are getting WEP group key and we didn't receive any key mapping
  3925. * so far, we are in legacy wep mode (group key only), otherwise we are
  3926. * in 1X mode.
  3927. * In legacy wep mode, we use another host command to the uCode */
  3928. if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id &&
  3929. priv->iw_mode != IEEE80211_IF_TYPE_AP) {
  3930. if (cmd == SET_KEY)
  3931. is_default_wep_key = !priv->key_mapping_key;
  3932. else
  3933. is_default_wep_key =
  3934. (key->hw_key_idx == HW_KEY_DEFAULT);
  3935. }
  3936. switch (cmd) {
  3937. case SET_KEY:
  3938. if (is_default_wep_key)
  3939. ret = iwl_set_default_wep_key(priv, key);
  3940. else
  3941. ret = iwl_set_dynamic_key(priv, key, sta_id);
  3942. IWL_DEBUG_MAC80211("enable hwcrypto key\n");
  3943. break;
  3944. case DISABLE_KEY:
  3945. if (is_default_wep_key)
  3946. ret = iwl_remove_default_wep_key(priv, key);
  3947. else
  3948. ret = iwl_remove_dynamic_key(priv, key, sta_id);
  3949. IWL_DEBUG_MAC80211("disable hwcrypto key\n");
  3950. break;
  3951. default:
  3952. ret = -EINVAL;
  3953. }
  3954. IWL_DEBUG_MAC80211("leave\n");
  3955. return ret;
  3956. }
  3957. static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  3958. const struct ieee80211_tx_queue_params *params)
  3959. {
  3960. struct iwl_priv *priv = hw->priv;
  3961. unsigned long flags;
  3962. int q;
  3963. IWL_DEBUG_MAC80211("enter\n");
  3964. if (!iwl_is_ready_rf(priv)) {
  3965. IWL_DEBUG_MAC80211("leave - RF not ready\n");
  3966. return -EIO;
  3967. }
  3968. if (queue >= AC_NUM) {
  3969. IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
  3970. return 0;
  3971. }
  3972. if (!priv->qos_data.qos_enable) {
  3973. priv->qos_data.qos_active = 0;
  3974. IWL_DEBUG_MAC80211("leave - qos not enabled\n");
  3975. return 0;
  3976. }
  3977. q = AC_NUM - 1 - queue;
  3978. spin_lock_irqsave(&priv->lock, flags);
  3979. priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
  3980. priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
  3981. priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
  3982. priv->qos_data.def_qos_parm.ac[q].edca_txop =
  3983. cpu_to_le16((params->txop * 32));
  3984. priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
  3985. priv->qos_data.qos_active = 1;
  3986. spin_unlock_irqrestore(&priv->lock, flags);
  3987. mutex_lock(&priv->mutex);
  3988. if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
  3989. iwl4965_activate_qos(priv, 1);
  3990. else if (priv->assoc_id && iwl_is_associated(priv))
  3991. iwl4965_activate_qos(priv, 0);
  3992. mutex_unlock(&priv->mutex);
  3993. IWL_DEBUG_MAC80211("leave\n");
  3994. return 0;
  3995. }
  3996. static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
  3997. struct ieee80211_tx_queue_stats *stats)
  3998. {
  3999. struct iwl_priv *priv = hw->priv;
  4000. int i, avail;
  4001. struct iwl_tx_queue *txq;
  4002. struct iwl_queue *q;
  4003. unsigned long flags;
  4004. IWL_DEBUG_MAC80211("enter\n");
  4005. if (!iwl_is_ready_rf(priv)) {
  4006. IWL_DEBUG_MAC80211("leave - RF not ready\n");
  4007. return -EIO;
  4008. }
  4009. spin_lock_irqsave(&priv->lock, flags);
  4010. for (i = 0; i < AC_NUM; i++) {
  4011. txq = &priv->txq[i];
  4012. q = &txq->q;
  4013. avail = iwl_queue_space(q);
  4014. stats[i].len = q->n_window - avail;
  4015. stats[i].limit = q->n_window - q->high_mark;
  4016. stats[i].count = q->n_window;
  4017. }
  4018. spin_unlock_irqrestore(&priv->lock, flags);
  4019. IWL_DEBUG_MAC80211("leave\n");
  4020. return 0;
  4021. }
  4022. static int iwl4965_mac_get_stats(struct ieee80211_hw *hw,
  4023. struct ieee80211_low_level_stats *stats)
  4024. {
  4025. struct iwl_priv *priv = hw->priv;
  4026. priv = hw->priv;
  4027. IWL_DEBUG_MAC80211("enter\n");
  4028. IWL_DEBUG_MAC80211("leave\n");
  4029. return 0;
  4030. }
  4031. static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw)
  4032. {
  4033. struct iwl_priv *priv;
  4034. priv = hw->priv;
  4035. IWL_DEBUG_MAC80211("enter\n");
  4036. IWL_DEBUG_MAC80211("leave\n");
  4037. return 0;
  4038. }
  4039. static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
  4040. {
  4041. struct iwl_priv *priv = hw->priv;
  4042. unsigned long flags;
  4043. mutex_lock(&priv->mutex);
  4044. IWL_DEBUG_MAC80211("enter\n");
  4045. priv->lq_mngr.lq_ready = 0;
  4046. #ifdef CONFIG_IWL4965_HT
  4047. spin_lock_irqsave(&priv->lock, flags);
  4048. memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
  4049. spin_unlock_irqrestore(&priv->lock, flags);
  4050. #endif /* CONFIG_IWL4965_HT */
  4051. iwl_reset_qos(priv);
  4052. cancel_delayed_work(&priv->post_associate);
  4053. spin_lock_irqsave(&priv->lock, flags);
  4054. priv->assoc_id = 0;
  4055. priv->assoc_capability = 0;
  4056. priv->assoc_station_added = 0;
  4057. /* new association get rid of ibss beacon skb */
  4058. if (priv->ibss_beacon)
  4059. dev_kfree_skb(priv->ibss_beacon);
  4060. priv->ibss_beacon = NULL;
  4061. priv->beacon_int = priv->hw->conf.beacon_int;
  4062. priv->timestamp = 0;
  4063. if ((priv->iw_mode == IEEE80211_IF_TYPE_STA))
  4064. priv->beacon_int = 0;
  4065. spin_unlock_irqrestore(&priv->lock, flags);
  4066. if (!iwl_is_ready_rf(priv)) {
  4067. IWL_DEBUG_MAC80211("leave - not ready\n");
  4068. mutex_unlock(&priv->mutex);
  4069. return;
  4070. }
  4071. /* we are restarting association process
  4072. * clear RXON_FILTER_ASSOC_MSK bit
  4073. */
  4074. if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
  4075. iwl4965_scan_cancel_timeout(priv, 100);
  4076. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  4077. iwl4965_commit_rxon(priv);
  4078. }
  4079. iwl_power_update_mode(priv, 0);
  4080. /* Per mac80211.h: This is only used in IBSS mode... */
  4081. if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
  4082. IWL_DEBUG_MAC80211("leave - not in IBSS\n");
  4083. mutex_unlock(&priv->mutex);
  4084. return;
  4085. }
  4086. iwl4965_set_rate(priv);
  4087. mutex_unlock(&priv->mutex);
  4088. IWL_DEBUG_MAC80211("leave\n");
  4089. }
  4090. static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
  4091. {
  4092. struct iwl_priv *priv = hw->priv;
  4093. unsigned long flags;
  4094. mutex_lock(&priv->mutex);
  4095. IWL_DEBUG_MAC80211("enter\n");
  4096. if (!iwl_is_ready_rf(priv)) {
  4097. IWL_DEBUG_MAC80211("leave - RF not ready\n");
  4098. mutex_unlock(&priv->mutex);
  4099. return -EIO;
  4100. }
  4101. if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
  4102. IWL_DEBUG_MAC80211("leave - not IBSS\n");
  4103. mutex_unlock(&priv->mutex);
  4104. return -EIO;
  4105. }
  4106. spin_lock_irqsave(&priv->lock, flags);
  4107. if (priv->ibss_beacon)
  4108. dev_kfree_skb(priv->ibss_beacon);
  4109. priv->ibss_beacon = skb;
  4110. priv->assoc_id = 0;
  4111. IWL_DEBUG_MAC80211("leave\n");
  4112. spin_unlock_irqrestore(&priv->lock, flags);
  4113. iwl_reset_qos(priv);
  4114. queue_work(priv->workqueue, &priv->post_associate.work);
  4115. mutex_unlock(&priv->mutex);
  4116. return 0;
  4117. }
  4118. /*****************************************************************************
  4119. *
  4120. * sysfs attributes
  4121. *
  4122. *****************************************************************************/
  4123. #ifdef CONFIG_IWLWIFI_DEBUG
  4124. /*
  4125. * The following adds a new attribute to the sysfs representation
  4126. * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
  4127. * used for controlling the debug level.
  4128. *
  4129. * See the level definitions in iwl for details.
  4130. */
  4131. static ssize_t show_debug_level(struct device *d,
  4132. struct device_attribute *attr, char *buf)
  4133. {
  4134. struct iwl_priv *priv = d->driver_data;
  4135. return sprintf(buf, "0x%08X\n", priv->debug_level);
  4136. }
  4137. static ssize_t store_debug_level(struct device *d,
  4138. struct device_attribute *attr,
  4139. const char *buf, size_t count)
  4140. {
  4141. struct iwl_priv *priv = d->driver_data;
  4142. char *p = (char *)buf;
  4143. u32 val;
  4144. val = simple_strtoul(p, &p, 0);
  4145. if (p == buf)
  4146. printk(KERN_INFO DRV_NAME
  4147. ": %s is not in hex or decimal form.\n", buf);
  4148. else
  4149. priv->debug_level = val;
  4150. return strnlen(buf, count);
  4151. }
  4152. static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
  4153. show_debug_level, store_debug_level);
  4154. #endif /* CONFIG_IWLWIFI_DEBUG */
  4155. static ssize_t show_version(struct device *d,
  4156. struct device_attribute *attr, char *buf)
  4157. {
  4158. struct iwl_priv *priv = d->driver_data;
  4159. struct iwl4965_alive_resp *palive = &priv->card_alive;
  4160. if (palive->is_valid)
  4161. return sprintf(buf, "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n"
  4162. "fw type: 0x%01X 0x%01X\n",
  4163. palive->ucode_major, palive->ucode_minor,
  4164. palive->sw_rev[0], palive->sw_rev[1],
  4165. palive->ver_type, palive->ver_subtype);
  4166. else
  4167. return sprintf(buf, "fw not loaded\n");
  4168. }
  4169. static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL);
  4170. static ssize_t show_temperature(struct device *d,
  4171. struct device_attribute *attr, char *buf)
  4172. {
  4173. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  4174. if (!iwl_is_alive(priv))
  4175. return -EAGAIN;
  4176. return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv));
  4177. }
  4178. static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
  4179. static ssize_t show_rs_window(struct device *d,
  4180. struct device_attribute *attr,
  4181. char *buf)
  4182. {
  4183. struct iwl_priv *priv = d->driver_data;
  4184. return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID);
  4185. }
  4186. static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL);
  4187. static ssize_t show_tx_power(struct device *d,
  4188. struct device_attribute *attr, char *buf)
  4189. {
  4190. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  4191. return sprintf(buf, "%d\n", priv->user_txpower_limit);
  4192. }
  4193. static ssize_t store_tx_power(struct device *d,
  4194. struct device_attribute *attr,
  4195. const char *buf, size_t count)
  4196. {
  4197. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  4198. char *p = (char *)buf;
  4199. u32 val;
  4200. val = simple_strtoul(p, &p, 10);
  4201. if (p == buf)
  4202. printk(KERN_INFO DRV_NAME
  4203. ": %s is not in decimal form.\n", buf);
  4204. else
  4205. iwl4965_hw_reg_set_txpower(priv, val);
  4206. return count;
  4207. }
  4208. static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
  4209. static ssize_t show_flags(struct device *d,
  4210. struct device_attribute *attr, char *buf)
  4211. {
  4212. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  4213. return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
  4214. }
  4215. static ssize_t store_flags(struct device *d,
  4216. struct device_attribute *attr,
  4217. const char *buf, size_t count)
  4218. {
  4219. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  4220. u32 flags = simple_strtoul(buf, NULL, 0);
  4221. mutex_lock(&priv->mutex);
  4222. if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
  4223. /* Cancel any currently running scans... */
  4224. if (iwl4965_scan_cancel_timeout(priv, 100))
  4225. IWL_WARNING("Could not cancel scan.\n");
  4226. else {
  4227. IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
  4228. flags);
  4229. priv->staging_rxon.flags = cpu_to_le32(flags);
  4230. iwl4965_commit_rxon(priv);
  4231. }
  4232. }
  4233. mutex_unlock(&priv->mutex);
  4234. return count;
  4235. }
  4236. static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
  4237. static ssize_t show_filter_flags(struct device *d,
  4238. struct device_attribute *attr, char *buf)
  4239. {
  4240. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  4241. return sprintf(buf, "0x%04X\n",
  4242. le32_to_cpu(priv->active_rxon.filter_flags));
  4243. }
  4244. static ssize_t store_filter_flags(struct device *d,
  4245. struct device_attribute *attr,
  4246. const char *buf, size_t count)
  4247. {
  4248. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  4249. u32 filter_flags = simple_strtoul(buf, NULL, 0);
  4250. mutex_lock(&priv->mutex);
  4251. if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
  4252. /* Cancel any currently running scans... */
  4253. if (iwl4965_scan_cancel_timeout(priv, 100))
  4254. IWL_WARNING("Could not cancel scan.\n");
  4255. else {
  4256. IWL_DEBUG_INFO("Committing rxon.filter_flags = "
  4257. "0x%04X\n", filter_flags);
  4258. priv->staging_rxon.filter_flags =
  4259. cpu_to_le32(filter_flags);
  4260. iwl4965_commit_rxon(priv);
  4261. }
  4262. }
  4263. mutex_unlock(&priv->mutex);
  4264. return count;
  4265. }
  4266. static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
  4267. store_filter_flags);
  4268. #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
  4269. static ssize_t show_measurement(struct device *d,
  4270. struct device_attribute *attr, char *buf)
  4271. {
  4272. struct iwl_priv *priv = dev_get_drvdata(d);
  4273. struct iwl4965_spectrum_notification measure_report;
  4274. u32 size = sizeof(measure_report), len = 0, ofs = 0;
  4275. u8 *data = (u8 *) & measure_report;
  4276. unsigned long flags;
  4277. spin_lock_irqsave(&priv->lock, flags);
  4278. if (!(priv->measurement_status & MEASUREMENT_READY)) {
  4279. spin_unlock_irqrestore(&priv->lock, flags);
  4280. return 0;
  4281. }
  4282. memcpy(&measure_report, &priv->measure_report, size);
  4283. priv->measurement_status = 0;
  4284. spin_unlock_irqrestore(&priv->lock, flags);
  4285. while (size && (PAGE_SIZE - len)) {
  4286. hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
  4287. PAGE_SIZE - len, 1);
  4288. len = strlen(buf);
  4289. if (PAGE_SIZE - len)
  4290. buf[len++] = '\n';
  4291. ofs += 16;
  4292. size -= min(size, 16U);
  4293. }
  4294. return len;
  4295. }
  4296. static ssize_t store_measurement(struct device *d,
  4297. struct device_attribute *attr,
  4298. const char *buf, size_t count)
  4299. {
  4300. struct iwl_priv *priv = dev_get_drvdata(d);
  4301. struct ieee80211_measurement_params params = {
  4302. .channel = le16_to_cpu(priv->active_rxon.channel),
  4303. .start_time = cpu_to_le64(priv->last_tsf),
  4304. .duration = cpu_to_le16(1),
  4305. };
  4306. u8 type = IWL_MEASURE_BASIC;
  4307. u8 buffer[32];
  4308. u8 channel;
  4309. if (count) {
  4310. char *p = buffer;
  4311. strncpy(buffer, buf, min(sizeof(buffer), count));
  4312. channel = simple_strtoul(p, NULL, 0);
  4313. if (channel)
  4314. params.channel = channel;
  4315. p = buffer;
  4316. while (*p && *p != ' ')
  4317. p++;
  4318. if (*p)
  4319. type = simple_strtoul(p + 1, NULL, 0);
  4320. }
  4321. IWL_DEBUG_INFO("Invoking measurement of type %d on "
  4322. "channel %d (for '%s')\n", type, params.channel, buf);
  4323. iwl4965_get_measurement(priv, &params, type);
  4324. return count;
  4325. }
  4326. static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
  4327. show_measurement, store_measurement);
  4328. #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
  4329. static ssize_t store_retry_rate(struct device *d,
  4330. struct device_attribute *attr,
  4331. const char *buf, size_t count)
  4332. {
  4333. struct iwl_priv *priv = dev_get_drvdata(d);
  4334. priv->retry_rate = simple_strtoul(buf, NULL, 0);
  4335. if (priv->retry_rate <= 0)
  4336. priv->retry_rate = 1;
  4337. return count;
  4338. }
  4339. static ssize_t show_retry_rate(struct device *d,
  4340. struct device_attribute *attr, char *buf)
  4341. {
  4342. struct iwl_priv *priv = dev_get_drvdata(d);
  4343. return sprintf(buf, "%d", priv->retry_rate);
  4344. }
  4345. static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
  4346. store_retry_rate);
  4347. static ssize_t store_power_level(struct device *d,
  4348. struct device_attribute *attr,
  4349. const char *buf, size_t count)
  4350. {
  4351. struct iwl_priv *priv = dev_get_drvdata(d);
  4352. int rc;
  4353. int mode;
  4354. mode = simple_strtoul(buf, NULL, 0);
  4355. mutex_lock(&priv->mutex);
  4356. if (!iwl_is_ready(priv)) {
  4357. rc = -EAGAIN;
  4358. goto out;
  4359. }
  4360. rc = iwl_power_set_user_mode(priv, mode);
  4361. if (rc) {
  4362. IWL_DEBUG_MAC80211("failed setting power mode.\n");
  4363. goto out;
  4364. }
  4365. rc = count;
  4366. out:
  4367. mutex_unlock(&priv->mutex);
  4368. return rc;
  4369. }
  4370. #define MAX_WX_STRING 80
  4371. /* Values are in microsecond */
  4372. static const s32 timeout_duration[] = {
  4373. 350000,
  4374. 250000,
  4375. 75000,
  4376. 37000,
  4377. 25000,
  4378. };
  4379. static const s32 period_duration[] = {
  4380. 400000,
  4381. 700000,
  4382. 1000000,
  4383. 1000000,
  4384. 1000000
  4385. };
  4386. static ssize_t show_power_level(struct device *d,
  4387. struct device_attribute *attr, char *buf)
  4388. {
  4389. struct iwl_priv *priv = dev_get_drvdata(d);
  4390. int level = priv->power_data.power_mode;
  4391. char *p = buf;
  4392. p += sprintf(p, "%d ", level);
  4393. switch (level) {
  4394. case IWL_POWER_MODE_CAM:
  4395. case IWL_POWER_AC:
  4396. p += sprintf(p, "(AC)");
  4397. break;
  4398. case IWL_POWER_BATTERY:
  4399. p += sprintf(p, "(BATTERY)");
  4400. break;
  4401. default:
  4402. p += sprintf(p,
  4403. "(Timeout %dms, Period %dms)",
  4404. timeout_duration[level - 1] / 1000,
  4405. period_duration[level - 1] / 1000);
  4406. }
  4407. /*
  4408. if (!(priv->power_mode & IWL_POWER_ENABLED))
  4409. p += sprintf(p, " OFF\n");
  4410. else
  4411. p += sprintf(p, " \n");
  4412. */
  4413. p += sprintf(p, " \n");
  4414. return (p - buf + 1);
  4415. }
  4416. static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
  4417. store_power_level);
  4418. static ssize_t show_channels(struct device *d,
  4419. struct device_attribute *attr, char *buf)
  4420. {
  4421. /* all this shit doesn't belong into sysfs anyway */
  4422. return 0;
  4423. }
  4424. static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
  4425. static ssize_t show_statistics(struct device *d,
  4426. struct device_attribute *attr, char *buf)
  4427. {
  4428. struct iwl_priv *priv = dev_get_drvdata(d);
  4429. u32 size = sizeof(struct iwl4965_notif_statistics);
  4430. u32 len = 0, ofs = 0;
  4431. u8 *data = (u8 *) & priv->statistics;
  4432. int rc = 0;
  4433. if (!iwl_is_alive(priv))
  4434. return -EAGAIN;
  4435. mutex_lock(&priv->mutex);
  4436. rc = iwl_send_statistics_request(priv, 0);
  4437. mutex_unlock(&priv->mutex);
  4438. if (rc) {
  4439. len = sprintf(buf,
  4440. "Error sending statistics request: 0x%08X\n", rc);
  4441. return len;
  4442. }
  4443. while (size && (PAGE_SIZE - len)) {
  4444. hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
  4445. PAGE_SIZE - len, 1);
  4446. len = strlen(buf);
  4447. if (PAGE_SIZE - len)
  4448. buf[len++] = '\n';
  4449. ofs += 16;
  4450. size -= min(size, 16U);
  4451. }
  4452. return len;
  4453. }
  4454. static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
  4455. static ssize_t show_status(struct device *d,
  4456. struct device_attribute *attr, char *buf)
  4457. {
  4458. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  4459. if (!iwl_is_alive(priv))
  4460. return -EAGAIN;
  4461. return sprintf(buf, "0x%08x\n", (int)priv->status);
  4462. }
  4463. static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
  4464. /*****************************************************************************
  4465. *
  4466. * driver setup and teardown
  4467. *
  4468. *****************************************************************************/
  4469. static void iwl4965_setup_deferred_work(struct iwl_priv *priv)
  4470. {
  4471. priv->workqueue = create_workqueue(DRV_NAME);
  4472. init_waitqueue_head(&priv->wait_command_queue);
  4473. INIT_WORK(&priv->up, iwl4965_bg_up);
  4474. INIT_WORK(&priv->restart, iwl4965_bg_restart);
  4475. INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish);
  4476. INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed);
  4477. INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan);
  4478. INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan);
  4479. INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill);
  4480. INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update);
  4481. INIT_WORK(&priv->set_monitor, iwl4965_bg_set_monitor);
  4482. INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate);
  4483. INIT_DELAYED_WORK(&priv->init_alive_start, iwl4965_bg_init_alive_start);
  4484. INIT_DELAYED_WORK(&priv->alive_start, iwl4965_bg_alive_start);
  4485. INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check);
  4486. iwl4965_hw_setup_deferred_work(priv);
  4487. tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
  4488. iwl4965_irq_tasklet, (unsigned long)priv);
  4489. }
  4490. static void iwl4965_cancel_deferred_work(struct iwl_priv *priv)
  4491. {
  4492. iwl4965_hw_cancel_deferred_work(priv);
  4493. cancel_delayed_work_sync(&priv->init_alive_start);
  4494. cancel_delayed_work(&priv->scan_check);
  4495. cancel_delayed_work(&priv->alive_start);
  4496. cancel_delayed_work(&priv->post_associate);
  4497. cancel_work_sync(&priv->beacon_update);
  4498. }
  4499. static struct attribute *iwl4965_sysfs_entries[] = {
  4500. &dev_attr_channels.attr,
  4501. &dev_attr_flags.attr,
  4502. &dev_attr_filter_flags.attr,
  4503. #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
  4504. &dev_attr_measurement.attr,
  4505. #endif
  4506. &dev_attr_power_level.attr,
  4507. &dev_attr_retry_rate.attr,
  4508. &dev_attr_rs_window.attr,
  4509. &dev_attr_statistics.attr,
  4510. &dev_attr_status.attr,
  4511. &dev_attr_temperature.attr,
  4512. &dev_attr_tx_power.attr,
  4513. #ifdef CONFIG_IWLWIFI_DEBUG
  4514. &dev_attr_debug_level.attr,
  4515. #endif
  4516. &dev_attr_version.attr,
  4517. NULL
  4518. };
  4519. static struct attribute_group iwl4965_attribute_group = {
  4520. .name = NULL, /* put in device directory */
  4521. .attrs = iwl4965_sysfs_entries,
  4522. };
  4523. static struct ieee80211_ops iwl4965_hw_ops = {
  4524. .tx = iwl4965_mac_tx,
  4525. .start = iwl4965_mac_start,
  4526. .stop = iwl4965_mac_stop,
  4527. .add_interface = iwl4965_mac_add_interface,
  4528. .remove_interface = iwl4965_mac_remove_interface,
  4529. .config = iwl4965_mac_config,
  4530. .config_interface = iwl4965_mac_config_interface,
  4531. .configure_filter = iwl4965_configure_filter,
  4532. .set_key = iwl4965_mac_set_key,
  4533. .update_tkip_key = iwl4965_mac_update_tkip_key,
  4534. .get_stats = iwl4965_mac_get_stats,
  4535. .get_tx_stats = iwl4965_mac_get_tx_stats,
  4536. .conf_tx = iwl4965_mac_conf_tx,
  4537. .get_tsf = iwl4965_mac_get_tsf,
  4538. .reset_tsf = iwl4965_mac_reset_tsf,
  4539. .beacon_update = iwl4965_mac_beacon_update,
  4540. .bss_info_changed = iwl4965_bss_info_changed,
  4541. #ifdef CONFIG_IWL4965_HT
  4542. .ampdu_action = iwl4965_mac_ampdu_action,
  4543. #endif /* CONFIG_IWL4965_HT */
  4544. .hw_scan = iwl4965_mac_hw_scan
  4545. };
  4546. static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  4547. {
  4548. int err = 0;
  4549. struct iwl_priv *priv;
  4550. struct ieee80211_hw *hw;
  4551. struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
  4552. unsigned long flags;
  4553. DECLARE_MAC_BUF(mac);
  4554. /************************
  4555. * 1. Allocating HW data
  4556. ************************/
  4557. /* Disabling hardware scan means that mac80211 will perform scans
  4558. * "the hard way", rather than using device's scan. */
  4559. if (cfg->mod_params->disable_hw_scan) {
  4560. if (cfg->mod_params->debug & IWL_DL_INFO)
  4561. dev_printk(KERN_DEBUG, &(pdev->dev),
  4562. "Disabling hw_scan\n");
  4563. iwl4965_hw_ops.hw_scan = NULL;
  4564. }
  4565. hw = iwl_alloc_all(cfg, &iwl4965_hw_ops);
  4566. if (!hw) {
  4567. err = -ENOMEM;
  4568. goto out;
  4569. }
  4570. priv = hw->priv;
  4571. /* At this point both hw and priv are allocated. */
  4572. SET_IEEE80211_DEV(hw, &pdev->dev);
  4573. IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
  4574. priv->cfg = cfg;
  4575. priv->pci_dev = pdev;
  4576. #ifdef CONFIG_IWLWIFI_DEBUG
  4577. priv->debug_level = priv->cfg->mod_params->debug;
  4578. atomic_set(&priv->restrict_refcnt, 0);
  4579. #endif
  4580. /**************************
  4581. * 2. Initializing PCI bus
  4582. **************************/
  4583. if (pci_enable_device(pdev)) {
  4584. err = -ENODEV;
  4585. goto out_ieee80211_free_hw;
  4586. }
  4587. pci_set_master(pdev);
  4588. err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
  4589. if (!err)
  4590. err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
  4591. if (err) {
  4592. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  4593. if (!err)
  4594. err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  4595. /* both attempts failed: */
  4596. if (err) {
  4597. printk(KERN_WARNING "%s: No suitable DMA available.\n",
  4598. DRV_NAME);
  4599. goto out_pci_disable_device;
  4600. }
  4601. }
  4602. err = pci_request_regions(pdev, DRV_NAME);
  4603. if (err)
  4604. goto out_pci_disable_device;
  4605. pci_set_drvdata(pdev, priv);
  4606. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  4607. * PCI Tx retries from interfering with C3 CPU state */
  4608. pci_write_config_byte(pdev, 0x41, 0x00);
  4609. /***********************
  4610. * 3. Read REV register
  4611. ***********************/
  4612. priv->hw_base = pci_iomap(pdev, 0, 0);
  4613. if (!priv->hw_base) {
  4614. err = -ENODEV;
  4615. goto out_pci_release_regions;
  4616. }
  4617. IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
  4618. (unsigned long long) pci_resource_len(pdev, 0));
  4619. IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
  4620. iwl_hw_detect(priv);
  4621. printk(KERN_INFO DRV_NAME
  4622. ": Detected Intel Wireless WiFi Link %s REV=0x%X\n",
  4623. priv->cfg->name, priv->hw_rev);
  4624. /* amp init */
  4625. err = priv->cfg->ops->lib->apm_ops.init(priv);
  4626. if (err < 0) {
  4627. IWL_DEBUG_INFO("Failed to init APMG\n");
  4628. goto out_iounmap;
  4629. }
  4630. /*****************
  4631. * 4. Read EEPROM
  4632. *****************/
  4633. /* Read the EEPROM */
  4634. err = iwl_eeprom_init(priv);
  4635. if (err) {
  4636. IWL_ERROR("Unable to init EEPROM\n");
  4637. goto out_iounmap;
  4638. }
  4639. err = iwl_eeprom_check_version(priv);
  4640. if (err)
  4641. goto out_iounmap;
  4642. /* extract MAC Address */
  4643. iwl_eeprom_get_mac(priv, priv->mac_addr);
  4644. IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr));
  4645. SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
  4646. /************************
  4647. * 5. Setup HW constants
  4648. ************************/
  4649. /* Device-specific setup */
  4650. if (priv->cfg->ops->lib->set_hw_params(priv)) {
  4651. IWL_ERROR("failed to set hw parameters\n");
  4652. goto out_free_eeprom;
  4653. }
  4654. /*******************
  4655. * 6. Setup priv
  4656. *******************/
  4657. err = iwl_init_drv(priv);
  4658. if (err)
  4659. goto out_free_eeprom;
  4660. /* At this point both hw and priv are initialized. */
  4661. /**********************************
  4662. * 7. Initialize module parameters
  4663. **********************************/
  4664. /* Disable radio (SW RF KILL) via parameter when loading driver */
  4665. if (priv->cfg->mod_params->disable) {
  4666. set_bit(STATUS_RF_KILL_SW, &priv->status);
  4667. IWL_DEBUG_INFO("Radio disabled.\n");
  4668. }
  4669. /********************
  4670. * 8. Setup services
  4671. ********************/
  4672. spin_lock_irqsave(&priv->lock, flags);
  4673. iwl4965_disable_interrupts(priv);
  4674. spin_unlock_irqrestore(&priv->lock, flags);
  4675. err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group);
  4676. if (err) {
  4677. IWL_ERROR("failed to create sysfs device attributes\n");
  4678. goto out_uninit_drv;
  4679. }
  4680. iwl4965_setup_deferred_work(priv);
  4681. iwl4965_setup_rx_handlers(priv);
  4682. /********************
  4683. * 9. Conclude
  4684. ********************/
  4685. pci_save_state(pdev);
  4686. pci_disable_device(pdev);
  4687. /**********************************
  4688. * 10. Setup and register mac80211
  4689. **********************************/
  4690. err = iwl_setup_mac(priv);
  4691. if (err)
  4692. goto out_remove_sysfs;
  4693. err = iwl_dbgfs_register(priv, DRV_NAME);
  4694. if (err)
  4695. IWL_ERROR("failed to create debugfs files\n");
  4696. /* notify iwlcore to init */
  4697. iwlcore_low_level_notify(priv, IWLCORE_INIT_EVT);
  4698. return 0;
  4699. out_remove_sysfs:
  4700. sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
  4701. out_uninit_drv:
  4702. iwl_uninit_drv(priv);
  4703. out_free_eeprom:
  4704. iwl_eeprom_free(priv);
  4705. out_iounmap:
  4706. pci_iounmap(pdev, priv->hw_base);
  4707. out_pci_release_regions:
  4708. pci_release_regions(pdev);
  4709. pci_set_drvdata(pdev, NULL);
  4710. out_pci_disable_device:
  4711. pci_disable_device(pdev);
  4712. out_ieee80211_free_hw:
  4713. ieee80211_free_hw(priv->hw);
  4714. out:
  4715. return err;
  4716. }
  4717. static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
  4718. {
  4719. struct iwl_priv *priv = pci_get_drvdata(pdev);
  4720. struct list_head *p, *q;
  4721. int i;
  4722. unsigned long flags;
  4723. if (!priv)
  4724. return;
  4725. IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
  4726. if (priv->mac80211_registered) {
  4727. ieee80211_unregister_hw(priv->hw);
  4728. priv->mac80211_registered = 0;
  4729. }
  4730. set_bit(STATUS_EXIT_PENDING, &priv->status);
  4731. iwl4965_down(priv);
  4732. /* make sure we flush any pending irq or
  4733. * tasklet for the driver
  4734. */
  4735. spin_lock_irqsave(&priv->lock, flags);
  4736. iwl4965_disable_interrupts(priv);
  4737. spin_unlock_irqrestore(&priv->lock, flags);
  4738. iwl_synchronize_irq(priv);
  4739. /* Free MAC hash list for ADHOC */
  4740. for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) {
  4741. list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
  4742. list_del(p);
  4743. kfree(list_entry(p, struct iwl4965_ibss_seq, list));
  4744. }
  4745. }
  4746. iwlcore_low_level_notify(priv, IWLCORE_REMOVE_EVT);
  4747. iwl_dbgfs_unregister(priv);
  4748. sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
  4749. iwl4965_dealloc_ucode_pci(priv);
  4750. if (priv->rxq.bd)
  4751. iwl_rx_queue_free(priv, &priv->rxq);
  4752. iwl_hw_txq_ctx_free(priv);
  4753. iwlcore_clear_stations_table(priv);
  4754. iwl_eeprom_free(priv);
  4755. /*netif_stop_queue(dev); */
  4756. flush_workqueue(priv->workqueue);
  4757. /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
  4758. * priv->workqueue... so we can't take down the workqueue
  4759. * until now... */
  4760. destroy_workqueue(priv->workqueue);
  4761. priv->workqueue = NULL;
  4762. pci_iounmap(pdev, priv->hw_base);
  4763. pci_release_regions(pdev);
  4764. pci_disable_device(pdev);
  4765. pci_set_drvdata(pdev, NULL);
  4766. iwl_uninit_drv(priv);
  4767. if (priv->ibss_beacon)
  4768. dev_kfree_skb(priv->ibss_beacon);
  4769. ieee80211_free_hw(priv->hw);
  4770. }
  4771. #ifdef CONFIG_PM
  4772. static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  4773. {
  4774. struct iwl_priv *priv = pci_get_drvdata(pdev);
  4775. if (priv->is_open) {
  4776. set_bit(STATUS_IN_SUSPEND, &priv->status);
  4777. iwl4965_mac_stop(priv->hw);
  4778. priv->is_open = 1;
  4779. }
  4780. pci_set_power_state(pdev, PCI_D3hot);
  4781. return 0;
  4782. }
  4783. static int iwl4965_pci_resume(struct pci_dev *pdev)
  4784. {
  4785. struct iwl_priv *priv = pci_get_drvdata(pdev);
  4786. pci_set_power_state(pdev, PCI_D0);
  4787. if (priv->is_open)
  4788. iwl4965_mac_start(priv->hw);
  4789. clear_bit(STATUS_IN_SUSPEND, &priv->status);
  4790. return 0;
  4791. }
  4792. #endif /* CONFIG_PM */
  4793. /*****************************************************************************
  4794. *
  4795. * driver and module entry point
  4796. *
  4797. *****************************************************************************/
  4798. /* Hardware specific file defines the PCI IDs table for that hardware module */
  4799. static struct pci_device_id iwl_hw_card_ids[] = {
  4800. {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
  4801. {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
  4802. #ifdef CONFIG_IWL5000
  4803. {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)},
  4804. {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)},
  4805. {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID, iwl5350_agn_cfg)},
  4806. #endif /* CONFIG_IWL5000 */
  4807. {0}
  4808. };
  4809. MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
  4810. static struct pci_driver iwl_driver = {
  4811. .name = DRV_NAME,
  4812. .id_table = iwl_hw_card_ids,
  4813. .probe = iwl4965_pci_probe,
  4814. .remove = __devexit_p(iwl4965_pci_remove),
  4815. #ifdef CONFIG_PM
  4816. .suspend = iwl4965_pci_suspend,
  4817. .resume = iwl4965_pci_resume,
  4818. #endif
  4819. };
  4820. static int __init iwl4965_init(void)
  4821. {
  4822. int ret;
  4823. printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
  4824. printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
  4825. ret = iwl4965_rate_control_register();
  4826. if (ret) {
  4827. IWL_ERROR("Unable to register rate control algorithm: %d\n", ret);
  4828. return ret;
  4829. }
  4830. ret = pci_register_driver(&iwl_driver);
  4831. if (ret) {
  4832. IWL_ERROR("Unable to initialize PCI module\n");
  4833. goto error_register;
  4834. }
  4835. return ret;
  4836. error_register:
  4837. iwl4965_rate_control_unregister();
  4838. return ret;
  4839. }
  4840. static void __exit iwl4965_exit(void)
  4841. {
  4842. pci_unregister_driver(&iwl_driver);
  4843. iwl4965_rate_control_unregister();
  4844. }
  4845. module_exit(iwl4965_exit);
  4846. module_init(iwl4965_init);