iwl3945-base.c 178 KB

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