iwl3945-base.c 233 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
  4. *
  5. * Portions of this file are derived from the ipw3945 project, as well
  6. * as portions of the ieee80211 subsystem header files.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of version 2 of the GNU General Public License as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  20. *
  21. * The full GNU General Public License is included in this distribution in the
  22. * file called LICENSE.
  23. *
  24. * Contact Information:
  25. * James P. Ketrenos <ipw2100-admin@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/version.h>
  32. #include <linux/init.h>
  33. #include <linux/pci.h>
  34. #include <linux/dma-mapping.h>
  35. #include <linux/delay.h>
  36. #include <linux/skbuff.h>
  37. #include <linux/netdevice.h>
  38. #include <linux/wireless.h>
  39. #include <linux/firmware.h>
  40. #include <linux/etherdevice.h>
  41. #include <linux/if_arp.h>
  42. #include <net/ieee80211_radiotap.h>
  43. #include <net/mac80211.h>
  44. #include <asm/div64.h>
  45. #include "iwl-3945-core.h"
  46. #include "iwl-3945.h"
  47. #include "iwl-helpers.h"
  48. #ifdef CONFIG_IWL3945_DEBUG
  49. u32 iwl3945_debug_level;
  50. #endif
  51. static int iwl3945_tx_queue_update_write_ptr(struct iwl3945_priv *priv,
  52. struct iwl3945_tx_queue *txq);
  53. /******************************************************************************
  54. *
  55. * module boiler plate
  56. *
  57. ******************************************************************************/
  58. /* module parameters */
  59. static int iwl3945_param_disable_hw_scan; /* def: 0 = use 3945's h/w scan */
  60. static int iwl3945_param_debug; /* def: 0 = minimal debug log messages */
  61. static int iwl3945_param_disable; /* def: 0 = enable radio */
  62. static int iwl3945_param_antenna; /* def: 0 = both antennas (use diversity) */
  63. int iwl3945_param_hwcrypto; /* def: 0 = use software encryption */
  64. static int iwl3945_param_qos_enable = 1; /* def: 1 = use quality of service */
  65. int iwl3945_param_queues_num = IWL_MAX_NUM_QUEUES; /* def: 8 Tx queues */
  66. /*
  67. * module name, copyright, version, etc.
  68. * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
  69. */
  70. #define DRV_DESCRIPTION \
  71. "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
  72. #ifdef CONFIG_IWL3945_DEBUG
  73. #define VD "d"
  74. #else
  75. #define VD
  76. #endif
  77. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  78. #define VS "s"
  79. #else
  80. #define VS
  81. #endif
  82. #define IWLWIFI_VERSION "1.2.26k" VD VS
  83. #define DRV_COPYRIGHT "Copyright(c) 2003-2008 Intel Corporation"
  84. #define DRV_VERSION IWLWIFI_VERSION
  85. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  86. MODULE_VERSION(DRV_VERSION);
  87. MODULE_AUTHOR(DRV_COPYRIGHT);
  88. MODULE_LICENSE("GPL");
  89. static __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr)
  90. {
  91. u16 fc = le16_to_cpu(hdr->frame_control);
  92. int hdr_len = ieee80211_get_hdrlen(fc);
  93. if ((fc & 0x00cc) == (IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA))
  94. return (__le16 *) ((u8 *) hdr + hdr_len - QOS_CONTROL_LEN);
  95. return NULL;
  96. }
  97. static const struct ieee80211_supported_band *iwl3945_get_band(
  98. struct iwl3945_priv *priv, enum ieee80211_band band)
  99. {
  100. return priv->hw->wiphy->bands[band];
  101. }
  102. static int iwl3945_is_empty_essid(const char *essid, int essid_len)
  103. {
  104. /* Single white space is for Linksys APs */
  105. if (essid_len == 1 && essid[0] == ' ')
  106. return 1;
  107. /* Otherwise, if the entire essid is 0, we assume it is hidden */
  108. while (essid_len) {
  109. essid_len--;
  110. if (essid[essid_len] != '\0')
  111. return 0;
  112. }
  113. return 1;
  114. }
  115. static const char *iwl3945_escape_essid(const char *essid, u8 essid_len)
  116. {
  117. static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
  118. const char *s = essid;
  119. char *d = escaped;
  120. if (iwl3945_is_empty_essid(essid, essid_len)) {
  121. memcpy(escaped, "<hidden>", sizeof("<hidden>"));
  122. return escaped;
  123. }
  124. essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE);
  125. while (essid_len--) {
  126. if (*s == '\0') {
  127. *d++ = '\\';
  128. *d++ = '0';
  129. s++;
  130. } else
  131. *d++ = *s++;
  132. }
  133. *d = '\0';
  134. return escaped;
  135. }
  136. /*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
  137. * DMA services
  138. *
  139. * Theory of operation
  140. *
  141. * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
  142. * of buffer descriptors, each of which points to one or more data buffers for
  143. * the device to read from or fill. Driver and device exchange status of each
  144. * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
  145. * entries in each circular buffer, to protect against confusing empty and full
  146. * queue states.
  147. *
  148. * The device reads or writes the data in the queues via the device's several
  149. * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
  150. *
  151. * For Tx queue, there are low mark and high mark limits. If, after queuing
  152. * the packet for Tx, free space become < low mark, Tx queue stopped. When
  153. * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
  154. * Tx queue resumed.
  155. *
  156. * The 3945 operates with six queues: One receive queue, one transmit queue
  157. * (#4) for sending commands to the device firmware, and four transmit queues
  158. * (#0-3) for data tx via EDCA. An additional 2 HCCA queues are unused.
  159. ***************************************************/
  160. int iwl3945_queue_space(const struct iwl3945_queue *q)
  161. {
  162. int s = q->read_ptr - q->write_ptr;
  163. if (q->read_ptr > q->write_ptr)
  164. s -= q->n_bd;
  165. if (s <= 0)
  166. s += q->n_window;
  167. /* keep some reserve to not confuse empty and full situations */
  168. s -= 2;
  169. if (s < 0)
  170. s = 0;
  171. return s;
  172. }
  173. int iwl3945_x2_queue_used(const struct iwl3945_queue *q, int i)
  174. {
  175. return q->write_ptr > q->read_ptr ?
  176. (i >= q->read_ptr && i < q->write_ptr) :
  177. !(i < q->read_ptr && i >= q->write_ptr);
  178. }
  179. static inline u8 get_cmd_index(struct iwl3945_queue *q, u32 index, int is_huge)
  180. {
  181. /* This is for scan command, the big buffer at end of command array */
  182. if (is_huge)
  183. return q->n_window; /* must be power of 2 */
  184. /* Otherwise, use normal size buffers */
  185. return index & (q->n_window - 1);
  186. }
  187. /**
  188. * iwl3945_queue_init - Initialize queue's high/low-water and read/write indexes
  189. */
  190. static int iwl3945_queue_init(struct iwl3945_priv *priv, struct iwl3945_queue *q,
  191. int count, int slots_num, u32 id)
  192. {
  193. q->n_bd = count;
  194. q->n_window = slots_num;
  195. q->id = id;
  196. /* count must be power-of-two size, otherwise iwl_queue_inc_wrap
  197. * and iwl_queue_dec_wrap are broken. */
  198. BUG_ON(!is_power_of_2(count));
  199. /* slots_num must be power-of-two size, otherwise
  200. * get_cmd_index is broken. */
  201. BUG_ON(!is_power_of_2(slots_num));
  202. q->low_mark = q->n_window / 4;
  203. if (q->low_mark < 4)
  204. q->low_mark = 4;
  205. q->high_mark = q->n_window / 8;
  206. if (q->high_mark < 2)
  207. q->high_mark = 2;
  208. q->write_ptr = q->read_ptr = 0;
  209. return 0;
  210. }
  211. /**
  212. * iwl3945_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
  213. */
  214. static int iwl3945_tx_queue_alloc(struct iwl3945_priv *priv,
  215. struct iwl3945_tx_queue *txq, u32 id)
  216. {
  217. struct pci_dev *dev = priv->pci_dev;
  218. /* Driver private data, only for Tx (not command) queues,
  219. * not shared with device. */
  220. if (id != IWL_CMD_QUEUE_NUM) {
  221. txq->txb = kmalloc(sizeof(txq->txb[0]) *
  222. TFD_QUEUE_SIZE_MAX, GFP_KERNEL);
  223. if (!txq->txb) {
  224. IWL_ERROR("kmalloc for auxiliary BD "
  225. "structures failed\n");
  226. goto error;
  227. }
  228. } else
  229. txq->txb = NULL;
  230. /* Circular buffer of transmit frame descriptors (TFDs),
  231. * shared with device */
  232. txq->bd = pci_alloc_consistent(dev,
  233. sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX,
  234. &txq->q.dma_addr);
  235. if (!txq->bd) {
  236. IWL_ERROR("pci_alloc_consistent(%zd) failed\n",
  237. sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX);
  238. goto error;
  239. }
  240. txq->q.id = id;
  241. return 0;
  242. error:
  243. if (txq->txb) {
  244. kfree(txq->txb);
  245. txq->txb = NULL;
  246. }
  247. return -ENOMEM;
  248. }
  249. /**
  250. * iwl3945_tx_queue_init - Allocate and initialize one tx/cmd queue
  251. */
  252. int iwl3945_tx_queue_init(struct iwl3945_priv *priv,
  253. struct iwl3945_tx_queue *txq, int slots_num, u32 txq_id)
  254. {
  255. struct pci_dev *dev = priv->pci_dev;
  256. int len;
  257. int rc = 0;
  258. /*
  259. * Alloc buffer array for commands (Tx or other types of commands).
  260. * For the command queue (#4), allocate command space + one big
  261. * command for scan, since scan command is very huge; the system will
  262. * not have two scans at the same time, so only one is needed.
  263. * For data Tx queues (all other queues), no super-size command
  264. * space is needed.
  265. */
  266. len = sizeof(struct iwl3945_cmd) * slots_num;
  267. if (txq_id == IWL_CMD_QUEUE_NUM)
  268. len += IWL_MAX_SCAN_SIZE;
  269. txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd);
  270. if (!txq->cmd)
  271. return -ENOMEM;
  272. /* Alloc driver data array and TFD circular buffer */
  273. rc = iwl3945_tx_queue_alloc(priv, txq, txq_id);
  274. if (rc) {
  275. pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
  276. return -ENOMEM;
  277. }
  278. txq->need_update = 0;
  279. /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
  280. * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */
  281. BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1));
  282. /* Initialize queue high/low-water, head/tail indexes */
  283. iwl3945_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id);
  284. /* Tell device where to find queue, enable DMA channel. */
  285. iwl3945_hw_tx_queue_init(priv, txq);
  286. return 0;
  287. }
  288. /**
  289. * iwl3945_tx_queue_free - Deallocate DMA queue.
  290. * @txq: Transmit queue to deallocate.
  291. *
  292. * Empty queue by removing and destroying all BD's.
  293. * Free all buffers.
  294. * 0-fill, but do not free "txq" descriptor structure.
  295. */
  296. void iwl3945_tx_queue_free(struct iwl3945_priv *priv, struct iwl3945_tx_queue *txq)
  297. {
  298. struct iwl3945_queue *q = &txq->q;
  299. struct pci_dev *dev = priv->pci_dev;
  300. int len;
  301. if (q->n_bd == 0)
  302. return;
  303. /* first, empty all BD's */
  304. for (; q->write_ptr != q->read_ptr;
  305. q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd))
  306. iwl3945_hw_txq_free_tfd(priv, txq);
  307. len = sizeof(struct iwl3945_cmd) * q->n_window;
  308. if (q->id == IWL_CMD_QUEUE_NUM)
  309. len += IWL_MAX_SCAN_SIZE;
  310. /* De-alloc array of command/tx buffers */
  311. pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
  312. /* De-alloc circular buffer of TFDs */
  313. if (txq->q.n_bd)
  314. pci_free_consistent(dev, sizeof(struct iwl3945_tfd_frame) *
  315. txq->q.n_bd, txq->bd, txq->q.dma_addr);
  316. /* De-alloc array of per-TFD driver data */
  317. if (txq->txb) {
  318. kfree(txq->txb);
  319. txq->txb = NULL;
  320. }
  321. /* 0-fill queue descriptor structure */
  322. memset(txq, 0, sizeof(*txq));
  323. }
  324. const u8 iwl3945_broadcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  325. /*************** STATION TABLE MANAGEMENT ****
  326. * mac80211 should be examined to determine if sta_info is duplicating
  327. * the functionality provided here
  328. */
  329. /**************************************************************/
  330. #if 0 /* temporary disable till we add real remove station */
  331. /**
  332. * iwl3945_remove_station - Remove driver's knowledge of station.
  333. *
  334. * NOTE: This does not remove station from device's station table.
  335. */
  336. static u8 iwl3945_remove_station(struct iwl3945_priv *priv, const u8 *addr, int is_ap)
  337. {
  338. int index = IWL_INVALID_STATION;
  339. int i;
  340. unsigned long flags;
  341. spin_lock_irqsave(&priv->sta_lock, flags);
  342. if (is_ap)
  343. index = IWL_AP_ID;
  344. else if (is_broadcast_ether_addr(addr))
  345. index = priv->hw_setting.bcast_sta_id;
  346. else
  347. for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++)
  348. if (priv->stations[i].used &&
  349. !compare_ether_addr(priv->stations[i].sta.sta.addr,
  350. addr)) {
  351. index = i;
  352. break;
  353. }
  354. if (unlikely(index == IWL_INVALID_STATION))
  355. goto out;
  356. if (priv->stations[index].used) {
  357. priv->stations[index].used = 0;
  358. priv->num_stations--;
  359. }
  360. BUG_ON(priv->num_stations < 0);
  361. out:
  362. spin_unlock_irqrestore(&priv->sta_lock, flags);
  363. return 0;
  364. }
  365. #endif
  366. /**
  367. * iwl3945_clear_stations_table - Clear the driver's station table
  368. *
  369. * NOTE: This does not clear or otherwise alter the device's station table.
  370. */
  371. static void iwl3945_clear_stations_table(struct iwl3945_priv *priv)
  372. {
  373. unsigned long flags;
  374. spin_lock_irqsave(&priv->sta_lock, flags);
  375. priv->num_stations = 0;
  376. memset(priv->stations, 0, sizeof(priv->stations));
  377. spin_unlock_irqrestore(&priv->sta_lock, flags);
  378. }
  379. /**
  380. * iwl3945_add_station - Add station to station tables in driver and device
  381. */
  382. u8 iwl3945_add_station(struct iwl3945_priv *priv, const u8 *addr, int is_ap, u8 flags)
  383. {
  384. int i;
  385. int index = IWL_INVALID_STATION;
  386. struct iwl3945_station_entry *station;
  387. unsigned long flags_spin;
  388. DECLARE_MAC_BUF(mac);
  389. u8 rate;
  390. spin_lock_irqsave(&priv->sta_lock, flags_spin);
  391. if (is_ap)
  392. index = IWL_AP_ID;
  393. else if (is_broadcast_ether_addr(addr))
  394. index = priv->hw_setting.bcast_sta_id;
  395. else
  396. for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) {
  397. if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
  398. addr)) {
  399. index = i;
  400. break;
  401. }
  402. if (!priv->stations[i].used &&
  403. index == IWL_INVALID_STATION)
  404. index = i;
  405. }
  406. /* These two conditions has the same outcome but keep them separate
  407. since they have different meaning */
  408. if (unlikely(index == IWL_INVALID_STATION)) {
  409. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  410. return index;
  411. }
  412. if (priv->stations[index].used &&
  413. !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) {
  414. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  415. return index;
  416. }
  417. IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index, print_mac(mac, addr));
  418. station = &priv->stations[index];
  419. station->used = 1;
  420. priv->num_stations++;
  421. /* Set up the REPLY_ADD_STA command to send to device */
  422. memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd));
  423. memcpy(station->sta.sta.addr, addr, ETH_ALEN);
  424. station->sta.mode = 0;
  425. station->sta.sta.sta_id = index;
  426. station->sta.station_flags = 0;
  427. if (priv->band == IEEE80211_BAND_5GHZ)
  428. rate = IWL_RATE_6M_PLCP;
  429. else
  430. rate = IWL_RATE_1M_PLCP;
  431. /* Turn on both antennas for the station... */
  432. station->sta.rate_n_flags =
  433. iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK);
  434. station->current_rate.rate_n_flags =
  435. le16_to_cpu(station->sta.rate_n_flags);
  436. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  437. /* Add station to device's station table */
  438. iwl3945_send_add_station(priv, &station->sta, flags);
  439. return index;
  440. }
  441. /*************** DRIVER STATUS FUNCTIONS *****/
  442. static inline int iwl3945_is_ready(struct iwl3945_priv *priv)
  443. {
  444. /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are
  445. * set but EXIT_PENDING is not */
  446. return test_bit(STATUS_READY, &priv->status) &&
  447. test_bit(STATUS_GEO_CONFIGURED, &priv->status) &&
  448. !test_bit(STATUS_EXIT_PENDING, &priv->status);
  449. }
  450. static inline int iwl3945_is_alive(struct iwl3945_priv *priv)
  451. {
  452. return test_bit(STATUS_ALIVE, &priv->status);
  453. }
  454. static inline int iwl3945_is_init(struct iwl3945_priv *priv)
  455. {
  456. return test_bit(STATUS_INIT, &priv->status);
  457. }
  458. static inline int iwl3945_is_rfkill(struct iwl3945_priv *priv)
  459. {
  460. return test_bit(STATUS_RF_KILL_HW, &priv->status) ||
  461. test_bit(STATUS_RF_KILL_SW, &priv->status);
  462. }
  463. static inline int iwl3945_is_ready_rf(struct iwl3945_priv *priv)
  464. {
  465. if (iwl3945_is_rfkill(priv))
  466. return 0;
  467. return iwl3945_is_ready(priv);
  468. }
  469. /*************** HOST COMMAND QUEUE FUNCTIONS *****/
  470. #define IWL_CMD(x) case x : return #x
  471. static const char *get_cmd_string(u8 cmd)
  472. {
  473. switch (cmd) {
  474. IWL_CMD(REPLY_ALIVE);
  475. IWL_CMD(REPLY_ERROR);
  476. IWL_CMD(REPLY_RXON);
  477. IWL_CMD(REPLY_RXON_ASSOC);
  478. IWL_CMD(REPLY_QOS_PARAM);
  479. IWL_CMD(REPLY_RXON_TIMING);
  480. IWL_CMD(REPLY_ADD_STA);
  481. IWL_CMD(REPLY_REMOVE_STA);
  482. IWL_CMD(REPLY_REMOVE_ALL_STA);
  483. IWL_CMD(REPLY_3945_RX);
  484. IWL_CMD(REPLY_TX);
  485. IWL_CMD(REPLY_RATE_SCALE);
  486. IWL_CMD(REPLY_LEDS_CMD);
  487. IWL_CMD(REPLY_TX_LINK_QUALITY_CMD);
  488. IWL_CMD(RADAR_NOTIFICATION);
  489. IWL_CMD(REPLY_QUIET_CMD);
  490. IWL_CMD(REPLY_CHANNEL_SWITCH);
  491. IWL_CMD(CHANNEL_SWITCH_NOTIFICATION);
  492. IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD);
  493. IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION);
  494. IWL_CMD(POWER_TABLE_CMD);
  495. IWL_CMD(PM_SLEEP_NOTIFICATION);
  496. IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC);
  497. IWL_CMD(REPLY_SCAN_CMD);
  498. IWL_CMD(REPLY_SCAN_ABORT_CMD);
  499. IWL_CMD(SCAN_START_NOTIFICATION);
  500. IWL_CMD(SCAN_RESULTS_NOTIFICATION);
  501. IWL_CMD(SCAN_COMPLETE_NOTIFICATION);
  502. IWL_CMD(BEACON_NOTIFICATION);
  503. IWL_CMD(REPLY_TX_BEACON);
  504. IWL_CMD(WHO_IS_AWAKE_NOTIFICATION);
  505. IWL_CMD(QUIET_NOTIFICATION);
  506. IWL_CMD(REPLY_TX_PWR_TABLE_CMD);
  507. IWL_CMD(MEASURE_ABORT_NOTIFICATION);
  508. IWL_CMD(REPLY_BT_CONFIG);
  509. IWL_CMD(REPLY_STATISTICS_CMD);
  510. IWL_CMD(STATISTICS_NOTIFICATION);
  511. IWL_CMD(REPLY_CARD_STATE_CMD);
  512. IWL_CMD(CARD_STATE_NOTIFICATION);
  513. IWL_CMD(MISSED_BEACONS_NOTIFICATION);
  514. default:
  515. return "UNKNOWN";
  516. }
  517. }
  518. #define HOST_COMPLETE_TIMEOUT (HZ / 2)
  519. /**
  520. * iwl3945_enqueue_hcmd - enqueue a uCode command
  521. * @priv: device private data point
  522. * @cmd: a point to the ucode command structure
  523. *
  524. * The function returns < 0 values to indicate the operation is
  525. * failed. On success, it turns the index (> 0) of command in the
  526. * command queue.
  527. */
  528. static int iwl3945_enqueue_hcmd(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd)
  529. {
  530. struct iwl3945_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM];
  531. struct iwl3945_queue *q = &txq->q;
  532. struct iwl3945_tfd_frame *tfd;
  533. u32 *control_flags;
  534. struct iwl3945_cmd *out_cmd;
  535. u32 idx;
  536. u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
  537. dma_addr_t phys_addr;
  538. int pad;
  539. u16 count;
  540. int ret;
  541. unsigned long flags;
  542. /* If any of the command structures end up being larger than
  543. * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
  544. * we will need to increase the size of the TFD entries */
  545. BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) &&
  546. !(cmd->meta.flags & CMD_SIZE_HUGE));
  547. if (iwl3945_is_rfkill(priv)) {
  548. IWL_DEBUG_INFO("Not sending command - RF KILL");
  549. return -EIO;
  550. }
  551. if (iwl3945_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) {
  552. IWL_ERROR("No space for Tx\n");
  553. return -ENOSPC;
  554. }
  555. spin_lock_irqsave(&priv->hcmd_lock, flags);
  556. tfd = &txq->bd[q->write_ptr];
  557. memset(tfd, 0, sizeof(*tfd));
  558. control_flags = (u32 *) tfd;
  559. idx = get_cmd_index(q, q->write_ptr, cmd->meta.flags & CMD_SIZE_HUGE);
  560. out_cmd = &txq->cmd[idx];
  561. out_cmd->hdr.cmd = cmd->id;
  562. memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta));
  563. memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len);
  564. /* At this point, the out_cmd now has all of the incoming cmd
  565. * information */
  566. out_cmd->hdr.flags = 0;
  567. out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) |
  568. INDEX_TO_SEQ(q->write_ptr));
  569. if (out_cmd->meta.flags & CMD_SIZE_HUGE)
  570. out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME);
  571. phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx +
  572. offsetof(struct iwl3945_cmd, hdr);
  573. iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size);
  574. pad = U32_PAD(cmd->len);
  575. count = TFD_CTL_COUNT_GET(*control_flags);
  576. *control_flags = TFD_CTL_COUNT_SET(count) | TFD_CTL_PAD_SET(pad);
  577. IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
  578. "%d bytes at %d[%d]:%d\n",
  579. get_cmd_string(out_cmd->hdr.cmd),
  580. out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence),
  581. fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM);
  582. txq->need_update = 1;
  583. /* Increment and update queue's write index */
  584. q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
  585. ret = iwl3945_tx_queue_update_write_ptr(priv, txq);
  586. spin_unlock_irqrestore(&priv->hcmd_lock, flags);
  587. return ret ? ret : idx;
  588. }
  589. static int iwl3945_send_cmd_async(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd)
  590. {
  591. int ret;
  592. BUG_ON(!(cmd->meta.flags & CMD_ASYNC));
  593. /* An asynchronous command can not expect an SKB to be set. */
  594. BUG_ON(cmd->meta.flags & CMD_WANT_SKB);
  595. /* An asynchronous command MUST have a callback. */
  596. BUG_ON(!cmd->meta.u.callback);
  597. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  598. return -EBUSY;
  599. ret = iwl3945_enqueue_hcmd(priv, cmd);
  600. if (ret < 0) {
  601. IWL_ERROR("Error sending %s: iwl3945_enqueue_hcmd failed: %d\n",
  602. get_cmd_string(cmd->id), ret);
  603. return ret;
  604. }
  605. return 0;
  606. }
  607. static int iwl3945_send_cmd_sync(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd)
  608. {
  609. int cmd_idx;
  610. int ret;
  611. static atomic_t entry = ATOMIC_INIT(0); /* reentrance protection */
  612. BUG_ON(cmd->meta.flags & CMD_ASYNC);
  613. /* A synchronous command can not have a callback set. */
  614. BUG_ON(cmd->meta.u.callback != NULL);
  615. if (atomic_xchg(&entry, 1)) {
  616. IWL_ERROR("Error sending %s: Already sending a host command\n",
  617. get_cmd_string(cmd->id));
  618. return -EBUSY;
  619. }
  620. set_bit(STATUS_HCMD_ACTIVE, &priv->status);
  621. if (cmd->meta.flags & CMD_WANT_SKB)
  622. cmd->meta.source = &cmd->meta;
  623. cmd_idx = iwl3945_enqueue_hcmd(priv, cmd);
  624. if (cmd_idx < 0) {
  625. ret = cmd_idx;
  626. IWL_ERROR("Error sending %s: iwl3945_enqueue_hcmd failed: %d\n",
  627. get_cmd_string(cmd->id), ret);
  628. goto out;
  629. }
  630. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  631. !test_bit(STATUS_HCMD_ACTIVE, &priv->status),
  632. HOST_COMPLETE_TIMEOUT);
  633. if (!ret) {
  634. if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) {
  635. IWL_ERROR("Error sending %s: time out after %dms.\n",
  636. get_cmd_string(cmd->id),
  637. jiffies_to_msecs(HOST_COMPLETE_TIMEOUT));
  638. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  639. ret = -ETIMEDOUT;
  640. goto cancel;
  641. }
  642. }
  643. if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
  644. IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n",
  645. get_cmd_string(cmd->id));
  646. ret = -ECANCELED;
  647. goto fail;
  648. }
  649. if (test_bit(STATUS_FW_ERROR, &priv->status)) {
  650. IWL_DEBUG_INFO("Command %s failed: FW Error\n",
  651. get_cmd_string(cmd->id));
  652. ret = -EIO;
  653. goto fail;
  654. }
  655. if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) {
  656. IWL_ERROR("Error: Response NULL in '%s'\n",
  657. get_cmd_string(cmd->id));
  658. ret = -EIO;
  659. goto out;
  660. }
  661. ret = 0;
  662. goto out;
  663. cancel:
  664. if (cmd->meta.flags & CMD_WANT_SKB) {
  665. struct iwl3945_cmd *qcmd;
  666. /* Cancel the CMD_WANT_SKB flag for the cmd in the
  667. * TX cmd queue. Otherwise in case the cmd comes
  668. * in later, it will possibly set an invalid
  669. * address (cmd->meta.source). */
  670. qcmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_idx];
  671. qcmd->meta.flags &= ~CMD_WANT_SKB;
  672. }
  673. fail:
  674. if (cmd->meta.u.skb) {
  675. dev_kfree_skb_any(cmd->meta.u.skb);
  676. cmd->meta.u.skb = NULL;
  677. }
  678. out:
  679. atomic_set(&entry, 0);
  680. return ret;
  681. }
  682. int iwl3945_send_cmd(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd)
  683. {
  684. if (cmd->meta.flags & CMD_ASYNC)
  685. return iwl3945_send_cmd_async(priv, cmd);
  686. return iwl3945_send_cmd_sync(priv, cmd);
  687. }
  688. int iwl3945_send_cmd_pdu(struct iwl3945_priv *priv, u8 id, u16 len, const void *data)
  689. {
  690. struct iwl3945_host_cmd cmd = {
  691. .id = id,
  692. .len = len,
  693. .data = data,
  694. };
  695. return iwl3945_send_cmd_sync(priv, &cmd);
  696. }
  697. static int __must_check iwl3945_send_cmd_u32(struct iwl3945_priv *priv, u8 id, u32 val)
  698. {
  699. struct iwl3945_host_cmd cmd = {
  700. .id = id,
  701. .len = sizeof(val),
  702. .data = &val,
  703. };
  704. return iwl3945_send_cmd_sync(priv, &cmd);
  705. }
  706. int iwl3945_send_statistics_request(struct iwl3945_priv *priv)
  707. {
  708. return iwl3945_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0);
  709. }
  710. /**
  711. * iwl3945_set_rxon_channel - Set the phymode and channel values in staging RXON
  712. * @band: 2.4 or 5 GHz band
  713. * @channel: Any channel valid for the requested band
  714. * In addition to setting the staging RXON, priv->band is also set.
  715. *
  716. * NOTE: Does not commit to the hardware; it sets appropriate bit fields
  717. * in the staging RXON flag structure based on the band
  718. */
  719. static int iwl3945_set_rxon_channel(struct iwl3945_priv *priv,
  720. enum ieee80211_band band,
  721. u16 channel)
  722. {
  723. if (!iwl3945_get_channel_info(priv, band, channel)) {
  724. IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
  725. channel, band);
  726. return -EINVAL;
  727. }
  728. if ((le16_to_cpu(priv->staging_rxon.channel) == channel) &&
  729. (priv->band == band))
  730. return 0;
  731. priv->staging_rxon.channel = cpu_to_le16(channel);
  732. if (band == IEEE80211_BAND_5GHZ)
  733. priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
  734. else
  735. priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
  736. priv->band = band;
  737. IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, band);
  738. return 0;
  739. }
  740. /**
  741. * iwl3945_check_rxon_cmd - validate RXON structure is valid
  742. *
  743. * NOTE: This is really only useful during development and can eventually
  744. * be #ifdef'd out once the driver is stable and folks aren't actively
  745. * making changes
  746. */
  747. static int iwl3945_check_rxon_cmd(struct iwl3945_rxon_cmd *rxon)
  748. {
  749. int error = 0;
  750. int counter = 1;
  751. if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
  752. error |= le32_to_cpu(rxon->flags &
  753. (RXON_FLG_TGJ_NARROW_BAND_MSK |
  754. RXON_FLG_RADAR_DETECT_MSK));
  755. if (error)
  756. IWL_WARNING("check 24G fields %d | %d\n",
  757. counter++, error);
  758. } else {
  759. error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
  760. 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
  761. if (error)
  762. IWL_WARNING("check 52 fields %d | %d\n",
  763. counter++, error);
  764. error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
  765. if (error)
  766. IWL_WARNING("check 52 CCK %d | %d\n",
  767. counter++, error);
  768. }
  769. error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
  770. if (error)
  771. IWL_WARNING("check mac addr %d | %d\n", counter++, error);
  772. /* make sure basic rates 6Mbps and 1Mbps are supported */
  773. error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
  774. ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
  775. if (error)
  776. IWL_WARNING("check basic rate %d | %d\n", counter++, error);
  777. error |= (le16_to_cpu(rxon->assoc_id) > 2007);
  778. if (error)
  779. IWL_WARNING("check assoc id %d | %d\n", counter++, error);
  780. error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
  781. == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
  782. if (error)
  783. IWL_WARNING("check CCK and short slot %d | %d\n",
  784. counter++, error);
  785. error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
  786. == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
  787. if (error)
  788. IWL_WARNING("check CCK & auto detect %d | %d\n",
  789. counter++, error);
  790. error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
  791. RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
  792. if (error)
  793. IWL_WARNING("check TGG and auto detect %d | %d\n",
  794. counter++, error);
  795. if ((rxon->flags & RXON_FLG_DIS_DIV_MSK))
  796. error |= ((rxon->flags & (RXON_FLG_ANT_B_MSK |
  797. RXON_FLG_ANT_A_MSK)) == 0);
  798. if (error)
  799. IWL_WARNING("check antenna %d %d\n", counter++, error);
  800. if (error)
  801. IWL_WARNING("Tuning to channel %d\n",
  802. le16_to_cpu(rxon->channel));
  803. if (error) {
  804. IWL_ERROR("Not a valid iwl3945_rxon_assoc_cmd field values\n");
  805. return -1;
  806. }
  807. return 0;
  808. }
  809. /**
  810. * iwl3945_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
  811. * @priv: staging_rxon is compared to active_rxon
  812. *
  813. * If the RXON structure is changing enough to require a new tune,
  814. * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
  815. * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
  816. */
  817. static int iwl3945_full_rxon_required(struct iwl3945_priv *priv)
  818. {
  819. /* These items are only settable from the full RXON command */
  820. if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ||
  821. compare_ether_addr(priv->staging_rxon.bssid_addr,
  822. priv->active_rxon.bssid_addr) ||
  823. compare_ether_addr(priv->staging_rxon.node_addr,
  824. priv->active_rxon.node_addr) ||
  825. compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
  826. priv->active_rxon.wlap_bssid_addr) ||
  827. (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
  828. (priv->staging_rxon.channel != priv->active_rxon.channel) ||
  829. (priv->staging_rxon.air_propagation !=
  830. priv->active_rxon.air_propagation) ||
  831. (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
  832. return 1;
  833. /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
  834. * be updated with the RXON_ASSOC command -- however only some
  835. * flag transitions are allowed using RXON_ASSOC */
  836. /* Check if we are not switching bands */
  837. if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
  838. (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
  839. return 1;
  840. /* Check if we are switching association toggle */
  841. if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
  842. (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
  843. return 1;
  844. return 0;
  845. }
  846. static int iwl3945_send_rxon_assoc(struct iwl3945_priv *priv)
  847. {
  848. int rc = 0;
  849. struct iwl3945_rx_packet *res = NULL;
  850. struct iwl3945_rxon_assoc_cmd rxon_assoc;
  851. struct iwl3945_host_cmd cmd = {
  852. .id = REPLY_RXON_ASSOC,
  853. .len = sizeof(rxon_assoc),
  854. .meta.flags = CMD_WANT_SKB,
  855. .data = &rxon_assoc,
  856. };
  857. const struct iwl3945_rxon_cmd *rxon1 = &priv->staging_rxon;
  858. const struct iwl3945_rxon_cmd *rxon2 = &priv->active_rxon;
  859. if ((rxon1->flags == rxon2->flags) &&
  860. (rxon1->filter_flags == rxon2->filter_flags) &&
  861. (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
  862. (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
  863. IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
  864. return 0;
  865. }
  866. rxon_assoc.flags = priv->staging_rxon.flags;
  867. rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
  868. rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
  869. rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
  870. rxon_assoc.reserved = 0;
  871. rc = iwl3945_send_cmd_sync(priv, &cmd);
  872. if (rc)
  873. return rc;
  874. res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data;
  875. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  876. IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n");
  877. rc = -EIO;
  878. }
  879. priv->alloc_rxb_skb--;
  880. dev_kfree_skb_any(cmd.meta.u.skb);
  881. return rc;
  882. }
  883. /**
  884. * iwl3945_commit_rxon - commit staging_rxon to hardware
  885. *
  886. * The RXON command in staging_rxon is committed to the hardware and
  887. * the active_rxon structure is updated with the new data. This
  888. * function correctly transitions out of the RXON_ASSOC_MSK state if
  889. * a HW tune is required based on the RXON structure changes.
  890. */
  891. static int iwl3945_commit_rxon(struct iwl3945_priv *priv)
  892. {
  893. /* cast away the const for active_rxon in this function */
  894. struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
  895. int rc = 0;
  896. DECLARE_MAC_BUF(mac);
  897. if (!iwl3945_is_alive(priv))
  898. return -1;
  899. /* always get timestamp with Rx frame */
  900. priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
  901. /* select antenna */
  902. priv->staging_rxon.flags &=
  903. ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
  904. priv->staging_rxon.flags |= iwl3945_get_antenna_flags(priv);
  905. rc = iwl3945_check_rxon_cmd(&priv->staging_rxon);
  906. if (rc) {
  907. IWL_ERROR("Invalid RXON configuration. Not committing.\n");
  908. return -EINVAL;
  909. }
  910. /* If we don't need to send a full RXON, we can use
  911. * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
  912. * and other flags for the current radio configuration. */
  913. if (!iwl3945_full_rxon_required(priv)) {
  914. rc = iwl3945_send_rxon_assoc(priv);
  915. if (rc) {
  916. IWL_ERROR("Error setting RXON_ASSOC "
  917. "configuration (%d).\n", rc);
  918. return rc;
  919. }
  920. memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
  921. return 0;
  922. }
  923. /* If we are currently associated and the new config requires
  924. * an RXON_ASSOC and the new config wants the associated mask enabled,
  925. * we must clear the associated from the active configuration
  926. * before we apply the new config */
  927. if (iwl3945_is_associated(priv) &&
  928. (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) {
  929. IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
  930. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  931. rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON,
  932. sizeof(struct iwl3945_rxon_cmd),
  933. &priv->active_rxon);
  934. /* If the mask clearing failed then we set
  935. * active_rxon back to what it was previously */
  936. if (rc) {
  937. active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
  938. IWL_ERROR("Error clearing ASSOC_MSK on current "
  939. "configuration (%d).\n", rc);
  940. return rc;
  941. }
  942. }
  943. IWL_DEBUG_INFO("Sending RXON\n"
  944. "* with%s RXON_FILTER_ASSOC_MSK\n"
  945. "* channel = %d\n"
  946. "* bssid = %s\n",
  947. ((priv->staging_rxon.filter_flags &
  948. RXON_FILTER_ASSOC_MSK) ? "" : "out"),
  949. le16_to_cpu(priv->staging_rxon.channel),
  950. print_mac(mac, priv->staging_rxon.bssid_addr));
  951. /* Apply the new configuration */
  952. rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON,
  953. sizeof(struct iwl3945_rxon_cmd), &priv->staging_rxon);
  954. if (rc) {
  955. IWL_ERROR("Error setting new configuration (%d).\n", rc);
  956. return rc;
  957. }
  958. memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
  959. iwl3945_clear_stations_table(priv);
  960. /* If we issue a new RXON command which required a tune then we must
  961. * send a new TXPOWER command or we won't be able to Tx any frames */
  962. rc = iwl3945_hw_reg_send_txpower(priv);
  963. if (rc) {
  964. IWL_ERROR("Error setting Tx power (%d).\n", rc);
  965. return rc;
  966. }
  967. /* Add the broadcast address so we can send broadcast frames */
  968. if (iwl3945_add_station(priv, iwl3945_broadcast_addr, 0, 0) ==
  969. IWL_INVALID_STATION) {
  970. IWL_ERROR("Error adding BROADCAST address for transmit.\n");
  971. return -EIO;
  972. }
  973. /* If we have set the ASSOC_MSK and we are in BSS mode then
  974. * add the IWL_AP_ID to the station rate table */
  975. if (iwl3945_is_associated(priv) &&
  976. (priv->iw_mode == IEEE80211_IF_TYPE_STA))
  977. if (iwl3945_add_station(priv, priv->active_rxon.bssid_addr, 1, 0)
  978. == IWL_INVALID_STATION) {
  979. IWL_ERROR("Error adding AP address for transmit.\n");
  980. return -EIO;
  981. }
  982. /* Init the hardware's rate fallback order based on the band */
  983. rc = iwl3945_init_hw_rate_table(priv);
  984. if (rc) {
  985. IWL_ERROR("Error setting HW rate table: %02X\n", rc);
  986. return -EIO;
  987. }
  988. return 0;
  989. }
  990. static int iwl3945_send_bt_config(struct iwl3945_priv *priv)
  991. {
  992. struct iwl3945_bt_cmd bt_cmd = {
  993. .flags = 3,
  994. .lead_time = 0xAA,
  995. .max_kill = 1,
  996. .kill_ack_mask = 0,
  997. .kill_cts_mask = 0,
  998. };
  999. return iwl3945_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  1000. sizeof(struct iwl3945_bt_cmd), &bt_cmd);
  1001. }
  1002. static int iwl3945_send_scan_abort(struct iwl3945_priv *priv)
  1003. {
  1004. int rc = 0;
  1005. struct iwl3945_rx_packet *res;
  1006. struct iwl3945_host_cmd cmd = {
  1007. .id = REPLY_SCAN_ABORT_CMD,
  1008. .meta.flags = CMD_WANT_SKB,
  1009. };
  1010. /* If there isn't a scan actively going on in the hardware
  1011. * then we are in between scan bands and not actually
  1012. * actively scanning, so don't send the abort command */
  1013. if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
  1014. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  1015. return 0;
  1016. }
  1017. rc = iwl3945_send_cmd_sync(priv, &cmd);
  1018. if (rc) {
  1019. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  1020. return rc;
  1021. }
  1022. res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data;
  1023. if (res->u.status != CAN_ABORT_STATUS) {
  1024. /* The scan abort will return 1 for success or
  1025. * 2 for "failure". A failure condition can be
  1026. * due to simply not being in an active scan which
  1027. * can occur if we send the scan abort before we
  1028. * the microcode has notified us that a scan is
  1029. * completed. */
  1030. IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status);
  1031. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  1032. clear_bit(STATUS_SCAN_HW, &priv->status);
  1033. }
  1034. dev_kfree_skb_any(cmd.meta.u.skb);
  1035. return rc;
  1036. }
  1037. static int iwl3945_card_state_sync_callback(struct iwl3945_priv *priv,
  1038. struct iwl3945_cmd *cmd,
  1039. struct sk_buff *skb)
  1040. {
  1041. return 1;
  1042. }
  1043. /*
  1044. * CARD_STATE_CMD
  1045. *
  1046. * Use: Sets the device's internal card state to enable, disable, or halt
  1047. *
  1048. * When in the 'enable' state the card operates as normal.
  1049. * When in the 'disable' state, the card enters into a low power mode.
  1050. * When in the 'halt' state, the card is shut down and must be fully
  1051. * restarted to come back on.
  1052. */
  1053. static int iwl3945_send_card_state(struct iwl3945_priv *priv, u32 flags, u8 meta_flag)
  1054. {
  1055. struct iwl3945_host_cmd cmd = {
  1056. .id = REPLY_CARD_STATE_CMD,
  1057. .len = sizeof(u32),
  1058. .data = &flags,
  1059. .meta.flags = meta_flag,
  1060. };
  1061. if (meta_flag & CMD_ASYNC)
  1062. cmd.meta.u.callback = iwl3945_card_state_sync_callback;
  1063. return iwl3945_send_cmd(priv, &cmd);
  1064. }
  1065. static int iwl3945_add_sta_sync_callback(struct iwl3945_priv *priv,
  1066. struct iwl3945_cmd *cmd, struct sk_buff *skb)
  1067. {
  1068. struct iwl3945_rx_packet *res = NULL;
  1069. if (!skb) {
  1070. IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
  1071. return 1;
  1072. }
  1073. res = (struct iwl3945_rx_packet *)skb->data;
  1074. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  1075. IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
  1076. res->hdr.flags);
  1077. return 1;
  1078. }
  1079. switch (res->u.add_sta.status) {
  1080. case ADD_STA_SUCCESS_MSK:
  1081. break;
  1082. default:
  1083. break;
  1084. }
  1085. /* We didn't cache the SKB; let the caller free it */
  1086. return 1;
  1087. }
  1088. int iwl3945_send_add_station(struct iwl3945_priv *priv,
  1089. struct iwl3945_addsta_cmd *sta, u8 flags)
  1090. {
  1091. struct iwl3945_rx_packet *res = NULL;
  1092. int rc = 0;
  1093. struct iwl3945_host_cmd cmd = {
  1094. .id = REPLY_ADD_STA,
  1095. .len = sizeof(struct iwl3945_addsta_cmd),
  1096. .meta.flags = flags,
  1097. .data = sta,
  1098. };
  1099. if (flags & CMD_ASYNC)
  1100. cmd.meta.u.callback = iwl3945_add_sta_sync_callback;
  1101. else
  1102. cmd.meta.flags |= CMD_WANT_SKB;
  1103. rc = iwl3945_send_cmd(priv, &cmd);
  1104. if (rc || (flags & CMD_ASYNC))
  1105. return rc;
  1106. res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data;
  1107. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  1108. IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
  1109. res->hdr.flags);
  1110. rc = -EIO;
  1111. }
  1112. if (rc == 0) {
  1113. switch (res->u.add_sta.status) {
  1114. case ADD_STA_SUCCESS_MSK:
  1115. IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
  1116. break;
  1117. default:
  1118. rc = -EIO;
  1119. IWL_WARNING("REPLY_ADD_STA failed\n");
  1120. break;
  1121. }
  1122. }
  1123. priv->alloc_rxb_skb--;
  1124. dev_kfree_skb_any(cmd.meta.u.skb);
  1125. return rc;
  1126. }
  1127. static int iwl3945_update_sta_key_info(struct iwl3945_priv *priv,
  1128. struct ieee80211_key_conf *keyconf,
  1129. u8 sta_id)
  1130. {
  1131. unsigned long flags;
  1132. __le16 key_flags = 0;
  1133. switch (keyconf->alg) {
  1134. case ALG_CCMP:
  1135. key_flags |= STA_KEY_FLG_CCMP;
  1136. key_flags |= cpu_to_le16(
  1137. keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  1138. key_flags &= ~STA_KEY_FLG_INVALID;
  1139. break;
  1140. case ALG_TKIP:
  1141. case ALG_WEP:
  1142. default:
  1143. return -EINVAL;
  1144. }
  1145. spin_lock_irqsave(&priv->sta_lock, flags);
  1146. priv->stations[sta_id].keyinfo.alg = keyconf->alg;
  1147. priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
  1148. memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
  1149. keyconf->keylen);
  1150. memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
  1151. keyconf->keylen);
  1152. priv->stations[sta_id].sta.key.key_flags = key_flags;
  1153. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  1154. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  1155. spin_unlock_irqrestore(&priv->sta_lock, flags);
  1156. IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
  1157. iwl3945_send_add_station(priv, &priv->stations[sta_id].sta, 0);
  1158. return 0;
  1159. }
  1160. static int iwl3945_clear_sta_key_info(struct iwl3945_priv *priv, u8 sta_id)
  1161. {
  1162. unsigned long flags;
  1163. spin_lock_irqsave(&priv->sta_lock, flags);
  1164. memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key));
  1165. memset(&priv->stations[sta_id].sta.key, 0, sizeof(struct iwl3945_keyinfo));
  1166. priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
  1167. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  1168. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  1169. spin_unlock_irqrestore(&priv->sta_lock, flags);
  1170. IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
  1171. iwl3945_send_add_station(priv, &priv->stations[sta_id].sta, 0);
  1172. return 0;
  1173. }
  1174. static void iwl3945_clear_free_frames(struct iwl3945_priv *priv)
  1175. {
  1176. struct list_head *element;
  1177. IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
  1178. priv->frames_count);
  1179. while (!list_empty(&priv->free_frames)) {
  1180. element = priv->free_frames.next;
  1181. list_del(element);
  1182. kfree(list_entry(element, struct iwl3945_frame, list));
  1183. priv->frames_count--;
  1184. }
  1185. if (priv->frames_count) {
  1186. IWL_WARNING("%d frames still in use. Did we lose one?\n",
  1187. priv->frames_count);
  1188. priv->frames_count = 0;
  1189. }
  1190. }
  1191. static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl3945_priv *priv)
  1192. {
  1193. struct iwl3945_frame *frame;
  1194. struct list_head *element;
  1195. if (list_empty(&priv->free_frames)) {
  1196. frame = kzalloc(sizeof(*frame), GFP_KERNEL);
  1197. if (!frame) {
  1198. IWL_ERROR("Could not allocate frame!\n");
  1199. return NULL;
  1200. }
  1201. priv->frames_count++;
  1202. return frame;
  1203. }
  1204. element = priv->free_frames.next;
  1205. list_del(element);
  1206. return list_entry(element, struct iwl3945_frame, list);
  1207. }
  1208. static void iwl3945_free_frame(struct iwl3945_priv *priv, struct iwl3945_frame *frame)
  1209. {
  1210. memset(frame, 0, sizeof(*frame));
  1211. list_add(&frame->list, &priv->free_frames);
  1212. }
  1213. unsigned int iwl3945_fill_beacon_frame(struct iwl3945_priv *priv,
  1214. struct ieee80211_hdr *hdr,
  1215. const u8 *dest, int left)
  1216. {
  1217. if (!iwl3945_is_associated(priv) || !priv->ibss_beacon ||
  1218. ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) &&
  1219. (priv->iw_mode != IEEE80211_IF_TYPE_AP)))
  1220. return 0;
  1221. if (priv->ibss_beacon->len > left)
  1222. return 0;
  1223. memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
  1224. return priv->ibss_beacon->len;
  1225. }
  1226. static u8 iwl3945_rate_get_lowest_plcp(int rate_mask)
  1227. {
  1228. u8 i;
  1229. for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
  1230. i = iwl3945_rates[i].next_ieee) {
  1231. if (rate_mask & (1 << i))
  1232. return iwl3945_rates[i].plcp;
  1233. }
  1234. return IWL_RATE_INVALID;
  1235. }
  1236. static int iwl3945_send_beacon_cmd(struct iwl3945_priv *priv)
  1237. {
  1238. struct iwl3945_frame *frame;
  1239. unsigned int frame_size;
  1240. int rc;
  1241. u8 rate;
  1242. frame = iwl3945_get_free_frame(priv);
  1243. if (!frame) {
  1244. IWL_ERROR("Could not obtain free frame buffer for beacon "
  1245. "command.\n");
  1246. return -ENOMEM;
  1247. }
  1248. if (!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)) {
  1249. rate = iwl3945_rate_get_lowest_plcp(priv->active_rate_basic &
  1250. 0xFF0);
  1251. if (rate == IWL_INVALID_RATE)
  1252. rate = IWL_RATE_6M_PLCP;
  1253. } else {
  1254. rate = iwl3945_rate_get_lowest_plcp(priv->active_rate_basic & 0xF);
  1255. if (rate == IWL_INVALID_RATE)
  1256. rate = IWL_RATE_1M_PLCP;
  1257. }
  1258. frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
  1259. rc = iwl3945_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
  1260. &frame->u.cmd[0]);
  1261. iwl3945_free_frame(priv, frame);
  1262. return rc;
  1263. }
  1264. /******************************************************************************
  1265. *
  1266. * EEPROM related functions
  1267. *
  1268. ******************************************************************************/
  1269. static void get_eeprom_mac(struct iwl3945_priv *priv, u8 *mac)
  1270. {
  1271. memcpy(mac, priv->eeprom.mac_address, 6);
  1272. }
  1273. /*
  1274. * Clear the OWNER_MSK, to establish driver (instead of uCode running on
  1275. * embedded controller) as EEPROM reader; each read is a series of pulses
  1276. * to/from the EEPROM chip, not a single event, so even reads could conflict
  1277. * if they weren't arbitrated by some ownership mechanism. Here, the driver
  1278. * simply claims ownership, which should be safe when this function is called
  1279. * (i.e. before loading uCode!).
  1280. */
  1281. static inline int iwl3945_eeprom_acquire_semaphore(struct iwl3945_priv *priv)
  1282. {
  1283. _iwl3945_clear_bit(priv, CSR_EEPROM_GP, CSR_EEPROM_GP_IF_OWNER_MSK);
  1284. return 0;
  1285. }
  1286. /**
  1287. * iwl3945_eeprom_init - read EEPROM contents
  1288. *
  1289. * Load the EEPROM contents from adapter into priv->eeprom
  1290. *
  1291. * NOTE: This routine uses the non-debug IO access functions.
  1292. */
  1293. int iwl3945_eeprom_init(struct iwl3945_priv *priv)
  1294. {
  1295. u16 *e = (u16 *)&priv->eeprom;
  1296. u32 gp = iwl3945_read32(priv, CSR_EEPROM_GP);
  1297. u32 r;
  1298. int sz = sizeof(priv->eeprom);
  1299. int rc;
  1300. int i;
  1301. u16 addr;
  1302. /* The EEPROM structure has several padding buffers within it
  1303. * and when adding new EEPROM maps is subject to programmer errors
  1304. * which may be very difficult to identify without explicitly
  1305. * checking the resulting size of the eeprom map. */
  1306. BUILD_BUG_ON(sizeof(priv->eeprom) != IWL_EEPROM_IMAGE_SIZE);
  1307. if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) {
  1308. IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp);
  1309. return -ENOENT;
  1310. }
  1311. /* Make sure driver (instead of uCode) is allowed to read EEPROM */
  1312. rc = iwl3945_eeprom_acquire_semaphore(priv);
  1313. if (rc < 0) {
  1314. IWL_ERROR("Failed to acquire EEPROM semaphore.\n");
  1315. return -ENOENT;
  1316. }
  1317. /* eeprom is an array of 16bit values */
  1318. for (addr = 0; addr < sz; addr += sizeof(u16)) {
  1319. _iwl3945_write32(priv, CSR_EEPROM_REG, addr << 1);
  1320. _iwl3945_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD);
  1321. for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT;
  1322. i += IWL_EEPROM_ACCESS_DELAY) {
  1323. r = _iwl3945_read_direct32(priv, CSR_EEPROM_REG);
  1324. if (r & CSR_EEPROM_REG_READ_VALID_MSK)
  1325. break;
  1326. udelay(IWL_EEPROM_ACCESS_DELAY);
  1327. }
  1328. if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) {
  1329. IWL_ERROR("Time out reading EEPROM[%d]", addr);
  1330. return -ETIMEDOUT;
  1331. }
  1332. e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16));
  1333. }
  1334. return 0;
  1335. }
  1336. static void iwl3945_unset_hw_setting(struct iwl3945_priv *priv)
  1337. {
  1338. if (priv->hw_setting.shared_virt)
  1339. pci_free_consistent(priv->pci_dev,
  1340. sizeof(struct iwl3945_shared),
  1341. priv->hw_setting.shared_virt,
  1342. priv->hw_setting.shared_phys);
  1343. }
  1344. /**
  1345. * iwl3945_supported_rate_to_ie - fill in the supported rate in IE field
  1346. *
  1347. * return : set the bit for each supported rate insert in ie
  1348. */
  1349. static u16 iwl3945_supported_rate_to_ie(u8 *ie, u16 supported_rate,
  1350. u16 basic_rate, int *left)
  1351. {
  1352. u16 ret_rates = 0, bit;
  1353. int i;
  1354. u8 *cnt = ie;
  1355. u8 *rates = ie + 1;
  1356. for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) {
  1357. if (bit & supported_rate) {
  1358. ret_rates |= bit;
  1359. rates[*cnt] = iwl3945_rates[i].ieee |
  1360. ((bit & basic_rate) ? 0x80 : 0x00);
  1361. (*cnt)++;
  1362. (*left)--;
  1363. if ((*left <= 0) ||
  1364. (*cnt >= IWL_SUPPORTED_RATES_IE_LEN))
  1365. break;
  1366. }
  1367. }
  1368. return ret_rates;
  1369. }
  1370. /**
  1371. * iwl3945_fill_probe_req - fill in all required fields and IE for probe request
  1372. */
  1373. static u16 iwl3945_fill_probe_req(struct iwl3945_priv *priv,
  1374. struct ieee80211_mgmt *frame,
  1375. int left, int is_direct)
  1376. {
  1377. int len = 0;
  1378. u8 *pos = NULL;
  1379. u16 active_rates, ret_rates, cck_rates;
  1380. /* Make sure there is enough space for the probe request,
  1381. * two mandatory IEs and the data */
  1382. left -= 24;
  1383. if (left < 0)
  1384. return 0;
  1385. len += 24;
  1386. frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
  1387. memcpy(frame->da, iwl3945_broadcast_addr, ETH_ALEN);
  1388. memcpy(frame->sa, priv->mac_addr, ETH_ALEN);
  1389. memcpy(frame->bssid, iwl3945_broadcast_addr, ETH_ALEN);
  1390. frame->seq_ctrl = 0;
  1391. /* fill in our indirect SSID IE */
  1392. /* ...next IE... */
  1393. left -= 2;
  1394. if (left < 0)
  1395. return 0;
  1396. len += 2;
  1397. pos = &(frame->u.probe_req.variable[0]);
  1398. *pos++ = WLAN_EID_SSID;
  1399. *pos++ = 0;
  1400. /* fill in our direct SSID IE... */
  1401. if (is_direct) {
  1402. /* ...next IE... */
  1403. left -= 2 + priv->essid_len;
  1404. if (left < 0)
  1405. return 0;
  1406. /* ... fill it in... */
  1407. *pos++ = WLAN_EID_SSID;
  1408. *pos++ = priv->essid_len;
  1409. memcpy(pos, priv->essid, priv->essid_len);
  1410. pos += priv->essid_len;
  1411. len += 2 + priv->essid_len;
  1412. }
  1413. /* fill in supported rate */
  1414. /* ...next IE... */
  1415. left -= 2;
  1416. if (left < 0)
  1417. return 0;
  1418. /* ... fill it in... */
  1419. *pos++ = WLAN_EID_SUPP_RATES;
  1420. *pos = 0;
  1421. priv->active_rate = priv->rates_mask;
  1422. active_rates = priv->active_rate;
  1423. priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
  1424. cck_rates = IWL_CCK_RATES_MASK & active_rates;
  1425. ret_rates = iwl3945_supported_rate_to_ie(pos, cck_rates,
  1426. priv->active_rate_basic, &left);
  1427. active_rates &= ~ret_rates;
  1428. ret_rates = iwl3945_supported_rate_to_ie(pos, active_rates,
  1429. priv->active_rate_basic, &left);
  1430. active_rates &= ~ret_rates;
  1431. len += 2 + *pos;
  1432. pos += (*pos) + 1;
  1433. if (active_rates == 0)
  1434. goto fill_end;
  1435. /* fill in supported extended rate */
  1436. /* ...next IE... */
  1437. left -= 2;
  1438. if (left < 0)
  1439. return 0;
  1440. /* ... fill it in... */
  1441. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  1442. *pos = 0;
  1443. iwl3945_supported_rate_to_ie(pos, active_rates,
  1444. priv->active_rate_basic, &left);
  1445. if (*pos > 0)
  1446. len += 2 + *pos;
  1447. fill_end:
  1448. return (u16)len;
  1449. }
  1450. /*
  1451. * QoS support
  1452. */
  1453. static int iwl3945_send_qos_params_command(struct iwl3945_priv *priv,
  1454. struct iwl3945_qosparam_cmd *qos)
  1455. {
  1456. return iwl3945_send_cmd_pdu(priv, REPLY_QOS_PARAM,
  1457. sizeof(struct iwl3945_qosparam_cmd), qos);
  1458. }
  1459. static void iwl3945_reset_qos(struct iwl3945_priv *priv)
  1460. {
  1461. u16 cw_min = 15;
  1462. u16 cw_max = 1023;
  1463. u8 aifs = 2;
  1464. u8 is_legacy = 0;
  1465. unsigned long flags;
  1466. int i;
  1467. spin_lock_irqsave(&priv->lock, flags);
  1468. priv->qos_data.qos_active = 0;
  1469. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) {
  1470. if (priv->qos_data.qos_enable)
  1471. priv->qos_data.qos_active = 1;
  1472. if (!(priv->active_rate & 0xfff0)) {
  1473. cw_min = 31;
  1474. is_legacy = 1;
  1475. }
  1476. } else if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  1477. if (priv->qos_data.qos_enable)
  1478. priv->qos_data.qos_active = 1;
  1479. } else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) {
  1480. cw_min = 31;
  1481. is_legacy = 1;
  1482. }
  1483. if (priv->qos_data.qos_active)
  1484. aifs = 3;
  1485. priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min);
  1486. priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max);
  1487. priv->qos_data.def_qos_parm.ac[0].aifsn = aifs;
  1488. priv->qos_data.def_qos_parm.ac[0].edca_txop = 0;
  1489. priv->qos_data.def_qos_parm.ac[0].reserved1 = 0;
  1490. if (priv->qos_data.qos_active) {
  1491. i = 1;
  1492. priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min);
  1493. priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max);
  1494. priv->qos_data.def_qos_parm.ac[i].aifsn = 7;
  1495. priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
  1496. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  1497. i = 2;
  1498. priv->qos_data.def_qos_parm.ac[i].cw_min =
  1499. cpu_to_le16((cw_min + 1) / 2 - 1);
  1500. priv->qos_data.def_qos_parm.ac[i].cw_max =
  1501. cpu_to_le16(cw_max);
  1502. priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
  1503. if (is_legacy)
  1504. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  1505. cpu_to_le16(6016);
  1506. else
  1507. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  1508. cpu_to_le16(3008);
  1509. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  1510. i = 3;
  1511. priv->qos_data.def_qos_parm.ac[i].cw_min =
  1512. cpu_to_le16((cw_min + 1) / 4 - 1);
  1513. priv->qos_data.def_qos_parm.ac[i].cw_max =
  1514. cpu_to_le16((cw_max + 1) / 2 - 1);
  1515. priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
  1516. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  1517. if (is_legacy)
  1518. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  1519. cpu_to_le16(3264);
  1520. else
  1521. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  1522. cpu_to_le16(1504);
  1523. } else {
  1524. for (i = 1; i < 4; i++) {
  1525. priv->qos_data.def_qos_parm.ac[i].cw_min =
  1526. cpu_to_le16(cw_min);
  1527. priv->qos_data.def_qos_parm.ac[i].cw_max =
  1528. cpu_to_le16(cw_max);
  1529. priv->qos_data.def_qos_parm.ac[i].aifsn = aifs;
  1530. priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
  1531. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  1532. }
  1533. }
  1534. IWL_DEBUG_QOS("set QoS to default \n");
  1535. spin_unlock_irqrestore(&priv->lock, flags);
  1536. }
  1537. static void iwl3945_activate_qos(struct iwl3945_priv *priv, u8 force)
  1538. {
  1539. unsigned long flags;
  1540. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1541. return;
  1542. if (!priv->qos_data.qos_enable)
  1543. return;
  1544. spin_lock_irqsave(&priv->lock, flags);
  1545. priv->qos_data.def_qos_parm.qos_flags = 0;
  1546. if (priv->qos_data.qos_cap.q_AP.queue_request &&
  1547. !priv->qos_data.qos_cap.q_AP.txop_request)
  1548. priv->qos_data.def_qos_parm.qos_flags |=
  1549. QOS_PARAM_FLG_TXOP_TYPE_MSK;
  1550. if (priv->qos_data.qos_active)
  1551. priv->qos_data.def_qos_parm.qos_flags |=
  1552. QOS_PARAM_FLG_UPDATE_EDCA_MSK;
  1553. spin_unlock_irqrestore(&priv->lock, flags);
  1554. if (force || iwl3945_is_associated(priv)) {
  1555. IWL_DEBUG_QOS("send QoS cmd with Qos active %d \n",
  1556. priv->qos_data.qos_active);
  1557. iwl3945_send_qos_params_command(priv,
  1558. &(priv->qos_data.def_qos_parm));
  1559. }
  1560. }
  1561. /*
  1562. * Power management (not Tx power!) functions
  1563. */
  1564. #define MSEC_TO_USEC 1024
  1565. #define NOSLP __constant_cpu_to_le32(0)
  1566. #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK
  1567. #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
  1568. #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
  1569. __constant_cpu_to_le32(X1), \
  1570. __constant_cpu_to_le32(X2), \
  1571. __constant_cpu_to_le32(X3), \
  1572. __constant_cpu_to_le32(X4)}
  1573. /* default power management (not Tx power) table values */
  1574. /* for tim 0-10 */
  1575. static struct iwl3945_power_vec_entry range_0[IWL_POWER_AC] = {
  1576. {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
  1577. {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
  1578. {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
  1579. {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
  1580. {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
  1581. {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
  1582. };
  1583. /* for tim > 10 */
  1584. static struct iwl3945_power_vec_entry range_1[IWL_POWER_AC] = {
  1585. {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
  1586. {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500),
  1587. SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
  1588. {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300),
  1589. SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
  1590. {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100),
  1591. SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
  1592. {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
  1593. {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25),
  1594. SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
  1595. };
  1596. int iwl3945_power_init_handle(struct iwl3945_priv *priv)
  1597. {
  1598. int rc = 0, i;
  1599. struct iwl3945_power_mgr *pow_data;
  1600. int size = sizeof(struct iwl3945_power_vec_entry) * IWL_POWER_AC;
  1601. u16 pci_pm;
  1602. IWL_DEBUG_POWER("Initialize power \n");
  1603. pow_data = &(priv->power_data);
  1604. memset(pow_data, 0, sizeof(*pow_data));
  1605. pow_data->active_index = IWL_POWER_RANGE_0;
  1606. pow_data->dtim_val = 0xffff;
  1607. memcpy(&pow_data->pwr_range_0[0], &range_0[0], size);
  1608. memcpy(&pow_data->pwr_range_1[0], &range_1[0], size);
  1609. rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm);
  1610. if (rc != 0)
  1611. return 0;
  1612. else {
  1613. struct iwl3945_powertable_cmd *cmd;
  1614. IWL_DEBUG_POWER("adjust power command flags\n");
  1615. for (i = 0; i < IWL_POWER_AC; i++) {
  1616. cmd = &pow_data->pwr_range_0[i].cmd;
  1617. if (pci_pm & 0x1)
  1618. cmd->flags &= ~IWL_POWER_PCI_PM_MSK;
  1619. else
  1620. cmd->flags |= IWL_POWER_PCI_PM_MSK;
  1621. }
  1622. }
  1623. return rc;
  1624. }
  1625. static int iwl3945_update_power_cmd(struct iwl3945_priv *priv,
  1626. struct iwl3945_powertable_cmd *cmd, u32 mode)
  1627. {
  1628. int rc = 0, i;
  1629. u8 skip;
  1630. u32 max_sleep = 0;
  1631. struct iwl3945_power_vec_entry *range;
  1632. u8 period = 0;
  1633. struct iwl3945_power_mgr *pow_data;
  1634. if (mode > IWL_POWER_INDEX_5) {
  1635. IWL_DEBUG_POWER("Error invalid power mode \n");
  1636. return -1;
  1637. }
  1638. pow_data = &(priv->power_data);
  1639. if (pow_data->active_index == IWL_POWER_RANGE_0)
  1640. range = &pow_data->pwr_range_0[0];
  1641. else
  1642. range = &pow_data->pwr_range_1[1];
  1643. memcpy(cmd, &range[mode].cmd, sizeof(struct iwl3945_powertable_cmd));
  1644. #ifdef IWL_MAC80211_DISABLE
  1645. if (priv->assoc_network != NULL) {
  1646. unsigned long flags;
  1647. period = priv->assoc_network->tim.tim_period;
  1648. }
  1649. #endif /*IWL_MAC80211_DISABLE */
  1650. skip = range[mode].no_dtim;
  1651. if (period == 0) {
  1652. period = 1;
  1653. skip = 0;
  1654. }
  1655. if (skip == 0) {
  1656. max_sleep = period;
  1657. cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK;
  1658. } else {
  1659. __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1];
  1660. max_sleep = (le32_to_cpu(slp_itrvl) / period) * period;
  1661. cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK;
  1662. }
  1663. for (i = 0; i < IWL_POWER_VEC_SIZE; i++) {
  1664. if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep)
  1665. cmd->sleep_interval[i] = cpu_to_le32(max_sleep);
  1666. }
  1667. IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags);
  1668. IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout));
  1669. IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout));
  1670. IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
  1671. le32_to_cpu(cmd->sleep_interval[0]),
  1672. le32_to_cpu(cmd->sleep_interval[1]),
  1673. le32_to_cpu(cmd->sleep_interval[2]),
  1674. le32_to_cpu(cmd->sleep_interval[3]),
  1675. le32_to_cpu(cmd->sleep_interval[4]));
  1676. return rc;
  1677. }
  1678. static int iwl3945_send_power_mode(struct iwl3945_priv *priv, u32 mode)
  1679. {
  1680. u32 uninitialized_var(final_mode);
  1681. int rc;
  1682. struct iwl3945_powertable_cmd cmd;
  1683. /* If on battery, set to 3,
  1684. * if plugged into AC power, set to CAM ("continuously aware mode"),
  1685. * else user level */
  1686. switch (mode) {
  1687. case IWL_POWER_BATTERY:
  1688. final_mode = IWL_POWER_INDEX_3;
  1689. break;
  1690. case IWL_POWER_AC:
  1691. final_mode = IWL_POWER_MODE_CAM;
  1692. break;
  1693. default:
  1694. final_mode = mode;
  1695. break;
  1696. }
  1697. iwl3945_update_power_cmd(priv, &cmd, final_mode);
  1698. rc = iwl3945_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd);
  1699. if (final_mode == IWL_POWER_MODE_CAM)
  1700. clear_bit(STATUS_POWER_PMI, &priv->status);
  1701. else
  1702. set_bit(STATUS_POWER_PMI, &priv->status);
  1703. return rc;
  1704. }
  1705. int iwl3945_is_network_packet(struct iwl3945_priv *priv, struct ieee80211_hdr *header)
  1706. {
  1707. /* Filter incoming packets to determine if they are targeted toward
  1708. * this network, discarding packets coming from ourselves */
  1709. switch (priv->iw_mode) {
  1710. case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */
  1711. /* packets from our adapter are dropped (echo) */
  1712. if (!compare_ether_addr(header->addr2, priv->mac_addr))
  1713. return 0;
  1714. /* {broad,multi}cast packets to our IBSS go through */
  1715. if (is_multicast_ether_addr(header->addr1))
  1716. return !compare_ether_addr(header->addr3, priv->bssid);
  1717. /* packets to our adapter go through */
  1718. return !compare_ether_addr(header->addr1, priv->mac_addr);
  1719. case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */
  1720. /* packets from our adapter are dropped (echo) */
  1721. if (!compare_ether_addr(header->addr3, priv->mac_addr))
  1722. return 0;
  1723. /* {broad,multi}cast packets to our BSS go through */
  1724. if (is_multicast_ether_addr(header->addr1))
  1725. return !compare_ether_addr(header->addr2, priv->bssid);
  1726. /* packets to our adapter go through */
  1727. return !compare_ether_addr(header->addr1, priv->mac_addr);
  1728. default:
  1729. return 1;
  1730. }
  1731. return 1;
  1732. }
  1733. /**
  1734. * iwl3945_scan_cancel - Cancel any currently executing HW scan
  1735. *
  1736. * NOTE: priv->mutex is not required before calling this function
  1737. */
  1738. static int iwl3945_scan_cancel(struct iwl3945_priv *priv)
  1739. {
  1740. if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
  1741. clear_bit(STATUS_SCANNING, &priv->status);
  1742. return 0;
  1743. }
  1744. if (test_bit(STATUS_SCANNING, &priv->status)) {
  1745. if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  1746. IWL_DEBUG_SCAN("Queuing scan abort.\n");
  1747. set_bit(STATUS_SCAN_ABORTING, &priv->status);
  1748. queue_work(priv->workqueue, &priv->abort_scan);
  1749. } else
  1750. IWL_DEBUG_SCAN("Scan abort already in progress.\n");
  1751. return test_bit(STATUS_SCANNING, &priv->status);
  1752. }
  1753. return 0;
  1754. }
  1755. /**
  1756. * iwl3945_scan_cancel_timeout - Cancel any currently executing HW scan
  1757. * @ms: amount of time to wait (in milliseconds) for scan to abort
  1758. *
  1759. * NOTE: priv->mutex must be held before calling this function
  1760. */
  1761. static int iwl3945_scan_cancel_timeout(struct iwl3945_priv *priv, unsigned long ms)
  1762. {
  1763. unsigned long now = jiffies;
  1764. int ret;
  1765. ret = iwl3945_scan_cancel(priv);
  1766. if (ret && ms) {
  1767. mutex_unlock(&priv->mutex);
  1768. while (!time_after(jiffies, now + msecs_to_jiffies(ms)) &&
  1769. test_bit(STATUS_SCANNING, &priv->status))
  1770. msleep(1);
  1771. mutex_lock(&priv->mutex);
  1772. return test_bit(STATUS_SCANNING, &priv->status);
  1773. }
  1774. return ret;
  1775. }
  1776. static void iwl3945_sequence_reset(struct iwl3945_priv *priv)
  1777. {
  1778. /* Reset ieee stats */
  1779. /* We don't reset the net_device_stats (ieee->stats) on
  1780. * re-association */
  1781. priv->last_seq_num = -1;
  1782. priv->last_frag_num = -1;
  1783. priv->last_packet_time = 0;
  1784. iwl3945_scan_cancel(priv);
  1785. }
  1786. #define MAX_UCODE_BEACON_INTERVAL 1024
  1787. #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
  1788. static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val)
  1789. {
  1790. u16 new_val = 0;
  1791. u16 beacon_factor = 0;
  1792. beacon_factor =
  1793. (beacon_val + MAX_UCODE_BEACON_INTERVAL)
  1794. / MAX_UCODE_BEACON_INTERVAL;
  1795. new_val = beacon_val / beacon_factor;
  1796. return cpu_to_le16(new_val);
  1797. }
  1798. static void iwl3945_setup_rxon_timing(struct iwl3945_priv *priv)
  1799. {
  1800. u64 interval_tm_unit;
  1801. u64 tsf, result;
  1802. unsigned long flags;
  1803. struct ieee80211_conf *conf = NULL;
  1804. u16 beacon_int = 0;
  1805. conf = ieee80211_get_hw_conf(priv->hw);
  1806. spin_lock_irqsave(&priv->lock, flags);
  1807. priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp1);
  1808. priv->rxon_timing.timestamp.dw[0] = cpu_to_le32(priv->timestamp0);
  1809. priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
  1810. tsf = priv->timestamp1;
  1811. tsf = ((tsf << 32) | priv->timestamp0);
  1812. beacon_int = priv->beacon_int;
  1813. spin_unlock_irqrestore(&priv->lock, flags);
  1814. if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
  1815. if (beacon_int == 0) {
  1816. priv->rxon_timing.beacon_interval = cpu_to_le16(100);
  1817. priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
  1818. } else {
  1819. priv->rxon_timing.beacon_interval =
  1820. cpu_to_le16(beacon_int);
  1821. priv->rxon_timing.beacon_interval =
  1822. iwl3945_adjust_beacon_interval(
  1823. le16_to_cpu(priv->rxon_timing.beacon_interval));
  1824. }
  1825. priv->rxon_timing.atim_window = 0;
  1826. } else {
  1827. priv->rxon_timing.beacon_interval =
  1828. iwl3945_adjust_beacon_interval(conf->beacon_int);
  1829. /* TODO: we need to get atim_window from upper stack
  1830. * for now we set to 0 */
  1831. priv->rxon_timing.atim_window = 0;
  1832. }
  1833. interval_tm_unit =
  1834. (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
  1835. result = do_div(tsf, interval_tm_unit);
  1836. priv->rxon_timing.beacon_init_val =
  1837. cpu_to_le32((u32) ((u64) interval_tm_unit - result));
  1838. IWL_DEBUG_ASSOC
  1839. ("beacon interval %d beacon timer %d beacon tim %d\n",
  1840. le16_to_cpu(priv->rxon_timing.beacon_interval),
  1841. le32_to_cpu(priv->rxon_timing.beacon_init_val),
  1842. le16_to_cpu(priv->rxon_timing.atim_window));
  1843. }
  1844. static int iwl3945_scan_initiate(struct iwl3945_priv *priv)
  1845. {
  1846. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  1847. IWL_ERROR("APs don't scan.\n");
  1848. return 0;
  1849. }
  1850. if (!iwl3945_is_ready_rf(priv)) {
  1851. IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
  1852. return -EIO;
  1853. }
  1854. if (test_bit(STATUS_SCANNING, &priv->status)) {
  1855. IWL_DEBUG_SCAN("Scan already in progress.\n");
  1856. return -EAGAIN;
  1857. }
  1858. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  1859. IWL_DEBUG_SCAN("Scan request while abort pending. "
  1860. "Queuing.\n");
  1861. return -EAGAIN;
  1862. }
  1863. IWL_DEBUG_INFO("Starting scan...\n");
  1864. priv->scan_bands = 2;
  1865. set_bit(STATUS_SCANNING, &priv->status);
  1866. priv->scan_start = jiffies;
  1867. priv->scan_pass_start = priv->scan_start;
  1868. queue_work(priv->workqueue, &priv->request_scan);
  1869. return 0;
  1870. }
  1871. static int iwl3945_set_rxon_hwcrypto(struct iwl3945_priv *priv, int hw_decrypt)
  1872. {
  1873. struct iwl3945_rxon_cmd *rxon = &priv->staging_rxon;
  1874. if (hw_decrypt)
  1875. rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
  1876. else
  1877. rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
  1878. return 0;
  1879. }
  1880. static void iwl3945_set_flags_for_phymode(struct iwl3945_priv *priv,
  1881. enum ieee80211_band band)
  1882. {
  1883. if (band == IEEE80211_BAND_5GHZ) {
  1884. priv->staging_rxon.flags &=
  1885. ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
  1886. | RXON_FLG_CCK_MSK);
  1887. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  1888. } else {
  1889. /* Copied from iwl3945_bg_post_associate() */
  1890. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
  1891. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  1892. else
  1893. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  1894. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  1895. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  1896. priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
  1897. priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
  1898. priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
  1899. }
  1900. }
  1901. /*
  1902. * initialize rxon structure with default values from eeprom
  1903. */
  1904. static void iwl3945_connection_init_rx_config(struct iwl3945_priv *priv)
  1905. {
  1906. const struct iwl3945_channel_info *ch_info;
  1907. memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
  1908. switch (priv->iw_mode) {
  1909. case IEEE80211_IF_TYPE_AP:
  1910. priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
  1911. break;
  1912. case IEEE80211_IF_TYPE_STA:
  1913. priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
  1914. priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
  1915. break;
  1916. case IEEE80211_IF_TYPE_IBSS:
  1917. priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
  1918. priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
  1919. priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
  1920. RXON_FILTER_ACCEPT_GRP_MSK;
  1921. break;
  1922. case IEEE80211_IF_TYPE_MNTR:
  1923. priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
  1924. priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
  1925. RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
  1926. break;
  1927. default:
  1928. IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode);
  1929. break;
  1930. }
  1931. #if 0
  1932. /* TODO: Figure out when short_preamble would be set and cache from
  1933. * that */
  1934. if (!hw_to_local(priv->hw)->short_preamble)
  1935. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  1936. else
  1937. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  1938. #endif
  1939. ch_info = iwl3945_get_channel_info(priv, priv->band,
  1940. le16_to_cpu(priv->staging_rxon.channel));
  1941. if (!ch_info)
  1942. ch_info = &priv->channel_info[0];
  1943. /*
  1944. * in some case A channels are all non IBSS
  1945. * in this case force B/G channel
  1946. */
  1947. if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
  1948. !(is_channel_ibss(ch_info)))
  1949. ch_info = &priv->channel_info[0];
  1950. priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
  1951. if (is_channel_a_band(ch_info))
  1952. priv->band = IEEE80211_BAND_5GHZ;
  1953. else
  1954. priv->band = IEEE80211_BAND_2GHZ;
  1955. iwl3945_set_flags_for_phymode(priv, priv->band);
  1956. priv->staging_rxon.ofdm_basic_rates =
  1957. (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  1958. priv->staging_rxon.cck_basic_rates =
  1959. (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  1960. }
  1961. static int iwl3945_set_mode(struct iwl3945_priv *priv, int mode)
  1962. {
  1963. if (mode == IEEE80211_IF_TYPE_IBSS) {
  1964. const struct iwl3945_channel_info *ch_info;
  1965. ch_info = iwl3945_get_channel_info(priv,
  1966. priv->band,
  1967. le16_to_cpu(priv->staging_rxon.channel));
  1968. if (!ch_info || !is_channel_ibss(ch_info)) {
  1969. IWL_ERROR("channel %d not IBSS channel\n",
  1970. le16_to_cpu(priv->staging_rxon.channel));
  1971. return -EINVAL;
  1972. }
  1973. }
  1974. priv->iw_mode = mode;
  1975. iwl3945_connection_init_rx_config(priv);
  1976. memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  1977. iwl3945_clear_stations_table(priv);
  1978. /* dont commit rxon if rf-kill is on*/
  1979. if (!iwl3945_is_ready_rf(priv))
  1980. return -EAGAIN;
  1981. cancel_delayed_work(&priv->scan_check);
  1982. if (iwl3945_scan_cancel_timeout(priv, 100)) {
  1983. IWL_WARNING("Aborted scan still in progress after 100ms\n");
  1984. IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
  1985. return -EAGAIN;
  1986. }
  1987. iwl3945_commit_rxon(priv);
  1988. return 0;
  1989. }
  1990. static void iwl3945_build_tx_cmd_hwcrypto(struct iwl3945_priv *priv,
  1991. struct ieee80211_tx_control *ctl,
  1992. struct iwl3945_cmd *cmd,
  1993. struct sk_buff *skb_frag,
  1994. int last_frag)
  1995. {
  1996. struct iwl3945_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo;
  1997. switch (keyinfo->alg) {
  1998. case ALG_CCMP:
  1999. cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM;
  2000. memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen);
  2001. IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
  2002. break;
  2003. case ALG_TKIP:
  2004. #if 0
  2005. cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP;
  2006. if (last_frag)
  2007. memcpy(cmd->cmd.tx.tkip_mic.byte, skb_frag->tail - 8,
  2008. 8);
  2009. else
  2010. memset(cmd->cmd.tx.tkip_mic.byte, 0, 8);
  2011. #endif
  2012. break;
  2013. case ALG_WEP:
  2014. cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP |
  2015. (ctl->key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
  2016. if (keyinfo->keylen == 13)
  2017. cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128;
  2018. memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen);
  2019. IWL_DEBUG_TX("Configuring packet for WEP encryption "
  2020. "with key %d\n", ctl->key_idx);
  2021. break;
  2022. default:
  2023. printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg);
  2024. break;
  2025. }
  2026. }
  2027. /*
  2028. * handle build REPLY_TX command notification.
  2029. */
  2030. static void iwl3945_build_tx_cmd_basic(struct iwl3945_priv *priv,
  2031. struct iwl3945_cmd *cmd,
  2032. struct ieee80211_tx_control *ctrl,
  2033. struct ieee80211_hdr *hdr,
  2034. int is_unicast, u8 std_id)
  2035. {
  2036. __le16 *qc;
  2037. u16 fc = le16_to_cpu(hdr->frame_control);
  2038. __le32 tx_flags = cmd->cmd.tx.tx_flags;
  2039. cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  2040. if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) {
  2041. tx_flags |= TX_CMD_FLG_ACK_MSK;
  2042. if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
  2043. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  2044. if (ieee80211_is_probe_response(fc) &&
  2045. !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
  2046. tx_flags |= TX_CMD_FLG_TSF_MSK;
  2047. } else {
  2048. tx_flags &= (~TX_CMD_FLG_ACK_MSK);
  2049. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  2050. }
  2051. cmd->cmd.tx.sta_id = std_id;
  2052. if (ieee80211_get_morefrag(hdr))
  2053. tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
  2054. qc = ieee80211_get_qos_ctrl(hdr);
  2055. if (qc) {
  2056. cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf);
  2057. tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
  2058. } else
  2059. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  2060. if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) {
  2061. tx_flags |= TX_CMD_FLG_RTS_MSK;
  2062. tx_flags &= ~TX_CMD_FLG_CTS_MSK;
  2063. } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) {
  2064. tx_flags &= ~TX_CMD_FLG_RTS_MSK;
  2065. tx_flags |= TX_CMD_FLG_CTS_MSK;
  2066. }
  2067. if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
  2068. tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
  2069. tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
  2070. if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
  2071. if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ ||
  2072. (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
  2073. cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3);
  2074. else
  2075. cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2);
  2076. } else {
  2077. cmd->cmd.tx.timeout.pm_frame_timeout = 0;
  2078. #ifdef CONFIG_IWL3945_LEDS
  2079. priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
  2080. #endif
  2081. }
  2082. cmd->cmd.tx.driver_txop = 0;
  2083. cmd->cmd.tx.tx_flags = tx_flags;
  2084. cmd->cmd.tx.next_frame_len = 0;
  2085. }
  2086. /**
  2087. * iwl3945_get_sta_id - Find station's index within station table
  2088. */
  2089. static int iwl3945_get_sta_id(struct iwl3945_priv *priv, struct ieee80211_hdr *hdr)
  2090. {
  2091. int sta_id;
  2092. u16 fc = le16_to_cpu(hdr->frame_control);
  2093. /* If this frame is broadcast or management, use broadcast station id */
  2094. if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
  2095. is_multicast_ether_addr(hdr->addr1))
  2096. return priv->hw_setting.bcast_sta_id;
  2097. switch (priv->iw_mode) {
  2098. /* If we are a client station in a BSS network, use the special
  2099. * AP station entry (that's the only station we communicate with) */
  2100. case IEEE80211_IF_TYPE_STA:
  2101. return IWL_AP_ID;
  2102. /* If we are an AP, then find the station, or use BCAST */
  2103. case IEEE80211_IF_TYPE_AP:
  2104. sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
  2105. if (sta_id != IWL_INVALID_STATION)
  2106. return sta_id;
  2107. return priv->hw_setting.bcast_sta_id;
  2108. /* If this frame is going out to an IBSS network, find the station,
  2109. * or create a new station table entry */
  2110. case IEEE80211_IF_TYPE_IBSS: {
  2111. DECLARE_MAC_BUF(mac);
  2112. /* Create new station table entry */
  2113. sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
  2114. if (sta_id != IWL_INVALID_STATION)
  2115. return sta_id;
  2116. sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
  2117. if (sta_id != IWL_INVALID_STATION)
  2118. return sta_id;
  2119. IWL_DEBUG_DROP("Station %s not in station map. "
  2120. "Defaulting to broadcast...\n",
  2121. print_mac(mac, hdr->addr1));
  2122. iwl3945_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
  2123. return priv->hw_setting.bcast_sta_id;
  2124. }
  2125. default:
  2126. IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode);
  2127. return priv->hw_setting.bcast_sta_id;
  2128. }
  2129. }
  2130. /*
  2131. * start REPLY_TX command process
  2132. */
  2133. static int iwl3945_tx_skb(struct iwl3945_priv *priv,
  2134. struct sk_buff *skb, struct ieee80211_tx_control *ctl)
  2135. {
  2136. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  2137. struct iwl3945_tfd_frame *tfd;
  2138. u32 *control_flags;
  2139. int txq_id = ctl->queue;
  2140. struct iwl3945_tx_queue *txq = NULL;
  2141. struct iwl3945_queue *q = NULL;
  2142. dma_addr_t phys_addr;
  2143. dma_addr_t txcmd_phys;
  2144. struct iwl3945_cmd *out_cmd = NULL;
  2145. u16 len, idx, len_org;
  2146. u8 id, hdr_len, unicast;
  2147. u8 sta_id;
  2148. u16 seq_number = 0;
  2149. u16 fc;
  2150. __le16 *qc;
  2151. u8 wait_write_ptr = 0;
  2152. unsigned long flags;
  2153. int rc;
  2154. spin_lock_irqsave(&priv->lock, flags);
  2155. if (iwl3945_is_rfkill(priv)) {
  2156. IWL_DEBUG_DROP("Dropping - RF KILL\n");
  2157. goto drop_unlock;
  2158. }
  2159. if (!priv->vif) {
  2160. IWL_DEBUG_DROP("Dropping - !priv->vif\n");
  2161. goto drop_unlock;
  2162. }
  2163. if ((ctl->tx_rate->hw_value & 0xFF) == IWL_INVALID_RATE) {
  2164. IWL_ERROR("ERROR: No TX rate available.\n");
  2165. goto drop_unlock;
  2166. }
  2167. unicast = !is_multicast_ether_addr(hdr->addr1);
  2168. id = 0;
  2169. fc = le16_to_cpu(hdr->frame_control);
  2170. #ifdef CONFIG_IWL3945_DEBUG
  2171. if (ieee80211_is_auth(fc))
  2172. IWL_DEBUG_TX("Sending AUTH frame\n");
  2173. else if (ieee80211_is_assoc_request(fc))
  2174. IWL_DEBUG_TX("Sending ASSOC frame\n");
  2175. else if (ieee80211_is_reassoc_request(fc))
  2176. IWL_DEBUG_TX("Sending REASSOC frame\n");
  2177. #endif
  2178. /* drop all data frame if we are not associated */
  2179. if ((!iwl3945_is_associated(priv) ||
  2180. ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && !priv->assoc_id)) &&
  2181. ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)) {
  2182. IWL_DEBUG_DROP("Dropping - !iwl3945_is_associated\n");
  2183. goto drop_unlock;
  2184. }
  2185. spin_unlock_irqrestore(&priv->lock, flags);
  2186. hdr_len = ieee80211_get_hdrlen(fc);
  2187. /* Find (or create) index into station table for destination station */
  2188. sta_id = iwl3945_get_sta_id(priv, hdr);
  2189. if (sta_id == IWL_INVALID_STATION) {
  2190. DECLARE_MAC_BUF(mac);
  2191. IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n",
  2192. print_mac(mac, hdr->addr1));
  2193. goto drop;
  2194. }
  2195. IWL_DEBUG_RATE("station Id %d\n", sta_id);
  2196. qc = ieee80211_get_qos_ctrl(hdr);
  2197. if (qc) {
  2198. u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
  2199. seq_number = priv->stations[sta_id].tid[tid].seq_number &
  2200. IEEE80211_SCTL_SEQ;
  2201. hdr->seq_ctrl = cpu_to_le16(seq_number) |
  2202. (hdr->seq_ctrl &
  2203. __constant_cpu_to_le16(IEEE80211_SCTL_FRAG));
  2204. seq_number += 0x10;
  2205. }
  2206. /* Descriptor for chosen Tx queue */
  2207. txq = &priv->txq[txq_id];
  2208. q = &txq->q;
  2209. spin_lock_irqsave(&priv->lock, flags);
  2210. /* Set up first empty TFD within this queue's circular TFD buffer */
  2211. tfd = &txq->bd[q->write_ptr];
  2212. memset(tfd, 0, sizeof(*tfd));
  2213. control_flags = (u32 *) tfd;
  2214. idx = get_cmd_index(q, q->write_ptr, 0);
  2215. /* Set up driver data for this TFD */
  2216. memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl3945_tx_info));
  2217. txq->txb[q->write_ptr].skb[0] = skb;
  2218. memcpy(&(txq->txb[q->write_ptr].status.control),
  2219. ctl, sizeof(struct ieee80211_tx_control));
  2220. /* Init first empty entry in queue's array of Tx/cmd buffers */
  2221. out_cmd = &txq->cmd[idx];
  2222. memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
  2223. memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx));
  2224. /*
  2225. * Set up the Tx-command (not MAC!) header.
  2226. * Store the chosen Tx queue and TFD index within the sequence field;
  2227. * after Tx, uCode's Tx response will return this value so driver can
  2228. * locate the frame within the tx queue and do post-tx processing.
  2229. */
  2230. out_cmd->hdr.cmd = REPLY_TX;
  2231. out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
  2232. INDEX_TO_SEQ(q->write_ptr)));
  2233. /* Copy MAC header from skb into command buffer */
  2234. memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len);
  2235. /*
  2236. * Use the first empty entry in this queue's command buffer array
  2237. * to contain the Tx command and MAC header concatenated together
  2238. * (payload data will be in another buffer).
  2239. * Size of this varies, due to varying MAC header length.
  2240. * If end is not dword aligned, we'll have 2 extra bytes at the end
  2241. * of the MAC header (device reads on dword boundaries).
  2242. * We'll tell device about this padding later.
  2243. */
  2244. len = priv->hw_setting.tx_cmd_len +
  2245. sizeof(struct iwl3945_cmd_header) + hdr_len;
  2246. len_org = len;
  2247. len = (len + 3) & ~3;
  2248. if (len_org != len)
  2249. len_org = 1;
  2250. else
  2251. len_org = 0;
  2252. /* Physical address of this Tx command's header (not MAC header!),
  2253. * within command buffer array. */
  2254. txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl3945_cmd) * idx +
  2255. offsetof(struct iwl3945_cmd, hdr);
  2256. /* Add buffer containing Tx command and MAC(!) header to TFD's
  2257. * first entry */
  2258. iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len);
  2259. if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT))
  2260. iwl3945_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0);
  2261. /* Set up TFD's 2nd entry to point directly to remainder of skb,
  2262. * if any (802.11 null frames have no payload). */
  2263. len = skb->len - hdr_len;
  2264. if (len) {
  2265. phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
  2266. len, PCI_DMA_TODEVICE);
  2267. iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len);
  2268. }
  2269. if (!len)
  2270. /* If there is no payload, then we use only one Tx buffer */
  2271. *control_flags = TFD_CTL_COUNT_SET(1);
  2272. else
  2273. /* Else use 2 buffers.
  2274. * Tell 3945 about any padding after MAC header */
  2275. *control_flags = TFD_CTL_COUNT_SET(2) |
  2276. TFD_CTL_PAD_SET(U32_PAD(len));
  2277. /* Total # bytes to be transmitted */
  2278. len = (u16)skb->len;
  2279. out_cmd->cmd.tx.len = cpu_to_le16(len);
  2280. /* TODO need this for burst mode later on */
  2281. iwl3945_build_tx_cmd_basic(priv, out_cmd, ctl, hdr, unicast, sta_id);
  2282. /* set is_hcca to 0; it probably will never be implemented */
  2283. iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, ctl, hdr, sta_id, 0);
  2284. out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
  2285. out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
  2286. if (!ieee80211_get_morefrag(hdr)) {
  2287. txq->need_update = 1;
  2288. if (qc) {
  2289. u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
  2290. priv->stations[sta_id].tid[tid].seq_number = seq_number;
  2291. }
  2292. } else {
  2293. wait_write_ptr = 1;
  2294. txq->need_update = 0;
  2295. }
  2296. iwl3945_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload,
  2297. sizeof(out_cmd->cmd.tx));
  2298. iwl3945_print_hex_dump(IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr,
  2299. ieee80211_get_hdrlen(fc));
  2300. /* Tell device the write index *just past* this latest filled TFD */
  2301. q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
  2302. rc = iwl3945_tx_queue_update_write_ptr(priv, txq);
  2303. spin_unlock_irqrestore(&priv->lock, flags);
  2304. if (rc)
  2305. return rc;
  2306. if ((iwl3945_queue_space(q) < q->high_mark)
  2307. && priv->mac80211_registered) {
  2308. if (wait_write_ptr) {
  2309. spin_lock_irqsave(&priv->lock, flags);
  2310. txq->need_update = 1;
  2311. iwl3945_tx_queue_update_write_ptr(priv, txq);
  2312. spin_unlock_irqrestore(&priv->lock, flags);
  2313. }
  2314. ieee80211_stop_queue(priv->hw, ctl->queue);
  2315. }
  2316. return 0;
  2317. drop_unlock:
  2318. spin_unlock_irqrestore(&priv->lock, flags);
  2319. drop:
  2320. return -1;
  2321. }
  2322. static void iwl3945_set_rate(struct iwl3945_priv *priv)
  2323. {
  2324. const struct ieee80211_supported_band *sband = NULL;
  2325. struct ieee80211_rate *rate;
  2326. int i;
  2327. sband = iwl3945_get_band(priv, priv->band);
  2328. if (!sband) {
  2329. IWL_ERROR("Failed to set rate: unable to get hw mode\n");
  2330. return;
  2331. }
  2332. priv->active_rate = 0;
  2333. priv->active_rate_basic = 0;
  2334. IWL_DEBUG_RATE("Setting rates for %s GHz\n",
  2335. sband->band == IEEE80211_BAND_2GHZ ? "2.4" : "5");
  2336. for (i = 0; i < sband->n_bitrates; i++) {
  2337. rate = &sband->bitrates[i];
  2338. if ((rate->hw_value < IWL_RATE_COUNT) &&
  2339. !(rate->flags & IEEE80211_CHAN_DISABLED)) {
  2340. IWL_DEBUG_RATE("Adding rate index %d (plcp %d)\n",
  2341. rate->hw_value, iwl3945_rates[rate->hw_value].plcp);
  2342. priv->active_rate |= (1 << rate->hw_value);
  2343. }
  2344. }
  2345. IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
  2346. priv->active_rate, priv->active_rate_basic);
  2347. /*
  2348. * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
  2349. * otherwise set it to the default of all CCK rates and 6, 12, 24 for
  2350. * OFDM
  2351. */
  2352. if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
  2353. priv->staging_rxon.cck_basic_rates =
  2354. ((priv->active_rate_basic &
  2355. IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
  2356. else
  2357. priv->staging_rxon.cck_basic_rates =
  2358. (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  2359. if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
  2360. priv->staging_rxon.ofdm_basic_rates =
  2361. ((priv->active_rate_basic &
  2362. (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
  2363. IWL_FIRST_OFDM_RATE) & 0xFF;
  2364. else
  2365. priv->staging_rxon.ofdm_basic_rates =
  2366. (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  2367. }
  2368. static void iwl3945_radio_kill_sw(struct iwl3945_priv *priv, int disable_radio)
  2369. {
  2370. unsigned long flags;
  2371. if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
  2372. return;
  2373. IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
  2374. disable_radio ? "OFF" : "ON");
  2375. if (disable_radio) {
  2376. iwl3945_scan_cancel(priv);
  2377. /* FIXME: This is a workaround for AP */
  2378. if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
  2379. spin_lock_irqsave(&priv->lock, flags);
  2380. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_SET,
  2381. CSR_UCODE_SW_BIT_RFKILL);
  2382. spin_unlock_irqrestore(&priv->lock, flags);
  2383. iwl3945_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0);
  2384. set_bit(STATUS_RF_KILL_SW, &priv->status);
  2385. }
  2386. return;
  2387. }
  2388. spin_lock_irqsave(&priv->lock, flags);
  2389. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2390. clear_bit(STATUS_RF_KILL_SW, &priv->status);
  2391. spin_unlock_irqrestore(&priv->lock, flags);
  2392. /* wake up ucode */
  2393. msleep(10);
  2394. spin_lock_irqsave(&priv->lock, flags);
  2395. iwl3945_read32(priv, CSR_UCODE_DRV_GP1);
  2396. if (!iwl3945_grab_nic_access(priv))
  2397. iwl3945_release_nic_access(priv);
  2398. spin_unlock_irqrestore(&priv->lock, flags);
  2399. if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
  2400. IWL_DEBUG_RF_KILL("Can not turn radio back on - "
  2401. "disabled by HW switch\n");
  2402. return;
  2403. }
  2404. queue_work(priv->workqueue, &priv->restart);
  2405. return;
  2406. }
  2407. void iwl3945_set_decrypted_flag(struct iwl3945_priv *priv, struct sk_buff *skb,
  2408. u32 decrypt_res, struct ieee80211_rx_status *stats)
  2409. {
  2410. u16 fc =
  2411. le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control);
  2412. if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
  2413. return;
  2414. if (!(fc & IEEE80211_FCTL_PROTECTED))
  2415. return;
  2416. IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
  2417. switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
  2418. case RX_RES_STATUS_SEC_TYPE_TKIP:
  2419. if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
  2420. RX_RES_STATUS_BAD_ICV_MIC)
  2421. stats->flag |= RX_FLAG_MMIC_ERROR;
  2422. case RX_RES_STATUS_SEC_TYPE_WEP:
  2423. case RX_RES_STATUS_SEC_TYPE_CCMP:
  2424. if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
  2425. RX_RES_STATUS_DECRYPT_OK) {
  2426. IWL_DEBUG_RX("hw decrypt successfully!!!\n");
  2427. stats->flag |= RX_FLAG_DECRYPTED;
  2428. }
  2429. break;
  2430. default:
  2431. break;
  2432. }
  2433. }
  2434. #define IWL_PACKET_RETRY_TIME HZ
  2435. int iwl3945_is_duplicate_packet(struct iwl3945_priv *priv, struct ieee80211_hdr *header)
  2436. {
  2437. u16 sc = le16_to_cpu(header->seq_ctrl);
  2438. u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
  2439. u16 frag = sc & IEEE80211_SCTL_FRAG;
  2440. u16 *last_seq, *last_frag;
  2441. unsigned long *last_time;
  2442. switch (priv->iw_mode) {
  2443. case IEEE80211_IF_TYPE_IBSS:{
  2444. struct list_head *p;
  2445. struct iwl3945_ibss_seq *entry = NULL;
  2446. u8 *mac = header->addr2;
  2447. int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1);
  2448. __list_for_each(p, &priv->ibss_mac_hash[index]) {
  2449. entry = list_entry(p, struct iwl3945_ibss_seq, list);
  2450. if (!compare_ether_addr(entry->mac, mac))
  2451. break;
  2452. }
  2453. if (p == &priv->ibss_mac_hash[index]) {
  2454. entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
  2455. if (!entry) {
  2456. IWL_ERROR("Cannot malloc new mac entry\n");
  2457. return 0;
  2458. }
  2459. memcpy(entry->mac, mac, ETH_ALEN);
  2460. entry->seq_num = seq;
  2461. entry->frag_num = frag;
  2462. entry->packet_time = jiffies;
  2463. list_add(&entry->list, &priv->ibss_mac_hash[index]);
  2464. return 0;
  2465. }
  2466. last_seq = &entry->seq_num;
  2467. last_frag = &entry->frag_num;
  2468. last_time = &entry->packet_time;
  2469. break;
  2470. }
  2471. case IEEE80211_IF_TYPE_STA:
  2472. last_seq = &priv->last_seq_num;
  2473. last_frag = &priv->last_frag_num;
  2474. last_time = &priv->last_packet_time;
  2475. break;
  2476. default:
  2477. return 0;
  2478. }
  2479. if ((*last_seq == seq) &&
  2480. time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) {
  2481. if (*last_frag == frag)
  2482. goto drop;
  2483. if (*last_frag + 1 != frag)
  2484. /* out-of-order fragment */
  2485. goto drop;
  2486. } else
  2487. *last_seq = seq;
  2488. *last_frag = frag;
  2489. *last_time = jiffies;
  2490. return 0;
  2491. drop:
  2492. return 1;
  2493. }
  2494. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  2495. #include "iwl-spectrum.h"
  2496. #define BEACON_TIME_MASK_LOW 0x00FFFFFF
  2497. #define BEACON_TIME_MASK_HIGH 0xFF000000
  2498. #define TIME_UNIT 1024
  2499. /*
  2500. * extended beacon time format
  2501. * time in usec will be changed into a 32-bit value in 8:24 format
  2502. * the high 1 byte is the beacon counts
  2503. * the lower 3 bytes is the time in usec within one beacon interval
  2504. */
  2505. static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
  2506. {
  2507. u32 quot;
  2508. u32 rem;
  2509. u32 interval = beacon_interval * 1024;
  2510. if (!interval || !usec)
  2511. return 0;
  2512. quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
  2513. rem = (usec % interval) & BEACON_TIME_MASK_LOW;
  2514. return (quot << 24) + rem;
  2515. }
  2516. /* base is usually what we get from ucode with each received frame,
  2517. * the same as HW timer counter counting down
  2518. */
  2519. static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
  2520. {
  2521. u32 base_low = base & BEACON_TIME_MASK_LOW;
  2522. u32 addon_low = addon & BEACON_TIME_MASK_LOW;
  2523. u32 interval = beacon_interval * TIME_UNIT;
  2524. u32 res = (base & BEACON_TIME_MASK_HIGH) +
  2525. (addon & BEACON_TIME_MASK_HIGH);
  2526. if (base_low > addon_low)
  2527. res += base_low - addon_low;
  2528. else if (base_low < addon_low) {
  2529. res += interval + base_low - addon_low;
  2530. res += (1 << 24);
  2531. } else
  2532. res += (1 << 24);
  2533. return cpu_to_le32(res);
  2534. }
  2535. static int iwl3945_get_measurement(struct iwl3945_priv *priv,
  2536. struct ieee80211_measurement_params *params,
  2537. u8 type)
  2538. {
  2539. struct iwl3945_spectrum_cmd spectrum;
  2540. struct iwl3945_rx_packet *res;
  2541. struct iwl3945_host_cmd cmd = {
  2542. .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
  2543. .data = (void *)&spectrum,
  2544. .meta.flags = CMD_WANT_SKB,
  2545. };
  2546. u32 add_time = le64_to_cpu(params->start_time);
  2547. int rc;
  2548. int spectrum_resp_status;
  2549. int duration = le16_to_cpu(params->duration);
  2550. if (iwl3945_is_associated(priv))
  2551. add_time =
  2552. iwl3945_usecs_to_beacons(
  2553. le64_to_cpu(params->start_time) - priv->last_tsf,
  2554. le16_to_cpu(priv->rxon_timing.beacon_interval));
  2555. memset(&spectrum, 0, sizeof(spectrum));
  2556. spectrum.channel_count = cpu_to_le16(1);
  2557. spectrum.flags =
  2558. RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
  2559. spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
  2560. cmd.len = sizeof(spectrum);
  2561. spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
  2562. if (iwl3945_is_associated(priv))
  2563. spectrum.start_time =
  2564. iwl3945_add_beacon_time(priv->last_beacon_time,
  2565. add_time,
  2566. le16_to_cpu(priv->rxon_timing.beacon_interval));
  2567. else
  2568. spectrum.start_time = 0;
  2569. spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
  2570. spectrum.channels[0].channel = params->channel;
  2571. spectrum.channels[0].type = type;
  2572. if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
  2573. spectrum.flags |= RXON_FLG_BAND_24G_MSK |
  2574. RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
  2575. rc = iwl3945_send_cmd_sync(priv, &cmd);
  2576. if (rc)
  2577. return rc;
  2578. res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data;
  2579. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  2580. IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
  2581. rc = -EIO;
  2582. }
  2583. spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
  2584. switch (spectrum_resp_status) {
  2585. case 0: /* Command will be handled */
  2586. if (res->u.spectrum.id != 0xff) {
  2587. IWL_DEBUG_INFO("Replaced existing measurement: %d\n",
  2588. res->u.spectrum.id);
  2589. priv->measurement_status &= ~MEASUREMENT_READY;
  2590. }
  2591. priv->measurement_status |= MEASUREMENT_ACTIVE;
  2592. rc = 0;
  2593. break;
  2594. case 1: /* Command will not be handled */
  2595. rc = -EAGAIN;
  2596. break;
  2597. }
  2598. dev_kfree_skb_any(cmd.meta.u.skb);
  2599. return rc;
  2600. }
  2601. #endif
  2602. static void iwl3945_rx_reply_alive(struct iwl3945_priv *priv,
  2603. struct iwl3945_rx_mem_buffer *rxb)
  2604. {
  2605. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2606. struct iwl3945_alive_resp *palive;
  2607. struct delayed_work *pwork;
  2608. palive = &pkt->u.alive_frame;
  2609. IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
  2610. "0x%01X 0x%01X\n",
  2611. palive->is_valid, palive->ver_type,
  2612. palive->ver_subtype);
  2613. if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
  2614. IWL_DEBUG_INFO("Initialization Alive received.\n");
  2615. memcpy(&priv->card_alive_init,
  2616. &pkt->u.alive_frame,
  2617. sizeof(struct iwl3945_init_alive_resp));
  2618. pwork = &priv->init_alive_start;
  2619. } else {
  2620. IWL_DEBUG_INFO("Runtime Alive received.\n");
  2621. memcpy(&priv->card_alive, &pkt->u.alive_frame,
  2622. sizeof(struct iwl3945_alive_resp));
  2623. pwork = &priv->alive_start;
  2624. iwl3945_disable_events(priv);
  2625. }
  2626. /* We delay the ALIVE response by 5ms to
  2627. * give the HW RF Kill time to activate... */
  2628. if (palive->is_valid == UCODE_VALID_OK)
  2629. queue_delayed_work(priv->workqueue, pwork,
  2630. msecs_to_jiffies(5));
  2631. else
  2632. IWL_WARNING("uCode did not respond OK.\n");
  2633. }
  2634. static void iwl3945_rx_reply_add_sta(struct iwl3945_priv *priv,
  2635. struct iwl3945_rx_mem_buffer *rxb)
  2636. {
  2637. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2638. IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
  2639. return;
  2640. }
  2641. static void iwl3945_rx_reply_error(struct iwl3945_priv *priv,
  2642. struct iwl3945_rx_mem_buffer *rxb)
  2643. {
  2644. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2645. IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
  2646. "seq 0x%04X ser 0x%08X\n",
  2647. le32_to_cpu(pkt->u.err_resp.error_type),
  2648. get_cmd_string(pkt->u.err_resp.cmd_id),
  2649. pkt->u.err_resp.cmd_id,
  2650. le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
  2651. le32_to_cpu(pkt->u.err_resp.error_info));
  2652. }
  2653. #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
  2654. static void iwl3945_rx_csa(struct iwl3945_priv *priv, struct iwl3945_rx_mem_buffer *rxb)
  2655. {
  2656. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2657. struct iwl3945_rxon_cmd *rxon = (void *)&priv->active_rxon;
  2658. struct iwl3945_csa_notification *csa = &(pkt->u.csa_notif);
  2659. IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
  2660. le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
  2661. rxon->channel = csa->channel;
  2662. priv->staging_rxon.channel = csa->channel;
  2663. }
  2664. static void iwl3945_rx_spectrum_measure_notif(struct iwl3945_priv *priv,
  2665. struct iwl3945_rx_mem_buffer *rxb)
  2666. {
  2667. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  2668. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2669. struct iwl3945_spectrum_notification *report = &(pkt->u.spectrum_notif);
  2670. if (!report->state) {
  2671. IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO,
  2672. "Spectrum Measure Notification: Start\n");
  2673. return;
  2674. }
  2675. memcpy(&priv->measure_report, report, sizeof(*report));
  2676. priv->measurement_status |= MEASUREMENT_READY;
  2677. #endif
  2678. }
  2679. static void iwl3945_rx_pm_sleep_notif(struct iwl3945_priv *priv,
  2680. struct iwl3945_rx_mem_buffer *rxb)
  2681. {
  2682. #ifdef CONFIG_IWL3945_DEBUG
  2683. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2684. struct iwl3945_sleep_notification *sleep = &(pkt->u.sleep_notif);
  2685. IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
  2686. sleep->pm_sleep_mode, sleep->pm_wakeup_src);
  2687. #endif
  2688. }
  2689. static void iwl3945_rx_pm_debug_statistics_notif(struct iwl3945_priv *priv,
  2690. struct iwl3945_rx_mem_buffer *rxb)
  2691. {
  2692. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2693. IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
  2694. "notification for %s:\n",
  2695. le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
  2696. iwl3945_print_hex_dump(IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
  2697. }
  2698. static void iwl3945_bg_beacon_update(struct work_struct *work)
  2699. {
  2700. struct iwl3945_priv *priv =
  2701. container_of(work, struct iwl3945_priv, beacon_update);
  2702. struct sk_buff *beacon;
  2703. /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
  2704. beacon = ieee80211_beacon_get(priv->hw, priv->vif, NULL);
  2705. if (!beacon) {
  2706. IWL_ERROR("update beacon failed\n");
  2707. return;
  2708. }
  2709. mutex_lock(&priv->mutex);
  2710. /* new beacon skb is allocated every time; dispose previous.*/
  2711. if (priv->ibss_beacon)
  2712. dev_kfree_skb(priv->ibss_beacon);
  2713. priv->ibss_beacon = beacon;
  2714. mutex_unlock(&priv->mutex);
  2715. iwl3945_send_beacon_cmd(priv);
  2716. }
  2717. static void iwl3945_rx_beacon_notif(struct iwl3945_priv *priv,
  2718. struct iwl3945_rx_mem_buffer *rxb)
  2719. {
  2720. #ifdef CONFIG_IWL3945_DEBUG
  2721. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2722. struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
  2723. u8 rate = beacon->beacon_notify_hdr.rate;
  2724. IWL_DEBUG_RX("beacon status %x retries %d iss %d "
  2725. "tsf %d %d rate %d\n",
  2726. le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
  2727. beacon->beacon_notify_hdr.failure_frame,
  2728. le32_to_cpu(beacon->ibss_mgr_status),
  2729. le32_to_cpu(beacon->high_tsf),
  2730. le32_to_cpu(beacon->low_tsf), rate);
  2731. #endif
  2732. if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
  2733. (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
  2734. queue_work(priv->workqueue, &priv->beacon_update);
  2735. }
  2736. /* Service response to REPLY_SCAN_CMD (0x80) */
  2737. static void iwl3945_rx_reply_scan(struct iwl3945_priv *priv,
  2738. struct iwl3945_rx_mem_buffer *rxb)
  2739. {
  2740. #ifdef CONFIG_IWL3945_DEBUG
  2741. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2742. struct iwl3945_scanreq_notification *notif =
  2743. (struct iwl3945_scanreq_notification *)pkt->u.raw;
  2744. IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status);
  2745. #endif
  2746. }
  2747. /* Service SCAN_START_NOTIFICATION (0x82) */
  2748. static void iwl3945_rx_scan_start_notif(struct iwl3945_priv *priv,
  2749. struct iwl3945_rx_mem_buffer *rxb)
  2750. {
  2751. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2752. struct iwl3945_scanstart_notification *notif =
  2753. (struct iwl3945_scanstart_notification *)pkt->u.raw;
  2754. priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
  2755. IWL_DEBUG_SCAN("Scan start: "
  2756. "%d [802.11%s] "
  2757. "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
  2758. notif->channel,
  2759. notif->band ? "bg" : "a",
  2760. notif->tsf_high,
  2761. notif->tsf_low, notif->status, notif->beacon_timer);
  2762. }
  2763. /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
  2764. static void iwl3945_rx_scan_results_notif(struct iwl3945_priv *priv,
  2765. struct iwl3945_rx_mem_buffer *rxb)
  2766. {
  2767. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2768. struct iwl3945_scanresults_notification *notif =
  2769. (struct iwl3945_scanresults_notification *)pkt->u.raw;
  2770. IWL_DEBUG_SCAN("Scan ch.res: "
  2771. "%d [802.11%s] "
  2772. "(TSF: 0x%08X:%08X) - %d "
  2773. "elapsed=%lu usec (%dms since last)\n",
  2774. notif->channel,
  2775. notif->band ? "bg" : "a",
  2776. le32_to_cpu(notif->tsf_high),
  2777. le32_to_cpu(notif->tsf_low),
  2778. le32_to_cpu(notif->statistics[0]),
  2779. le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf,
  2780. jiffies_to_msecs(elapsed_jiffies
  2781. (priv->last_scan_jiffies, jiffies)));
  2782. priv->last_scan_jiffies = jiffies;
  2783. priv->next_scan_jiffies = 0;
  2784. }
  2785. /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
  2786. static void iwl3945_rx_scan_complete_notif(struct iwl3945_priv *priv,
  2787. struct iwl3945_rx_mem_buffer *rxb)
  2788. {
  2789. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2790. struct iwl3945_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
  2791. IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
  2792. scan_notif->scanned_channels,
  2793. scan_notif->tsf_low,
  2794. scan_notif->tsf_high, scan_notif->status);
  2795. /* The HW is no longer scanning */
  2796. clear_bit(STATUS_SCAN_HW, &priv->status);
  2797. /* The scan completion notification came in, so kill that timer... */
  2798. cancel_delayed_work(&priv->scan_check);
  2799. IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
  2800. (priv->scan_bands == 2) ? "2.4" : "5.2",
  2801. jiffies_to_msecs(elapsed_jiffies
  2802. (priv->scan_pass_start, jiffies)));
  2803. /* Remove this scanned band from the list
  2804. * of pending bands to scan */
  2805. priv->scan_bands--;
  2806. /* If a request to abort was given, or the scan did not succeed
  2807. * then we reset the scan state machine and terminate,
  2808. * re-queuing another scan if one has been requested */
  2809. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  2810. IWL_DEBUG_INFO("Aborted scan completed.\n");
  2811. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  2812. } else {
  2813. /* If there are more bands on this scan pass reschedule */
  2814. if (priv->scan_bands > 0)
  2815. goto reschedule;
  2816. }
  2817. priv->last_scan_jiffies = jiffies;
  2818. priv->next_scan_jiffies = 0;
  2819. IWL_DEBUG_INFO("Setting scan to off\n");
  2820. clear_bit(STATUS_SCANNING, &priv->status);
  2821. IWL_DEBUG_INFO("Scan took %dms\n",
  2822. jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies)));
  2823. queue_work(priv->workqueue, &priv->scan_completed);
  2824. return;
  2825. reschedule:
  2826. priv->scan_pass_start = jiffies;
  2827. queue_work(priv->workqueue, &priv->request_scan);
  2828. }
  2829. /* Handle notification from uCode that card's power state is changing
  2830. * due to software, hardware, or critical temperature RFKILL */
  2831. static void iwl3945_rx_card_state_notif(struct iwl3945_priv *priv,
  2832. struct iwl3945_rx_mem_buffer *rxb)
  2833. {
  2834. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2835. u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
  2836. unsigned long status = priv->status;
  2837. IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
  2838. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  2839. (flags & SW_CARD_DISABLED) ? "Kill" : "On");
  2840. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_SET,
  2841. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  2842. if (flags & HW_CARD_DISABLED)
  2843. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2844. else
  2845. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2846. if (flags & SW_CARD_DISABLED)
  2847. set_bit(STATUS_RF_KILL_SW, &priv->status);
  2848. else
  2849. clear_bit(STATUS_RF_KILL_SW, &priv->status);
  2850. iwl3945_scan_cancel(priv);
  2851. if ((test_bit(STATUS_RF_KILL_HW, &status) !=
  2852. test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
  2853. (test_bit(STATUS_RF_KILL_SW, &status) !=
  2854. test_bit(STATUS_RF_KILL_SW, &priv->status)))
  2855. queue_work(priv->workqueue, &priv->rf_kill);
  2856. else
  2857. wake_up_interruptible(&priv->wait_command_queue);
  2858. }
  2859. /**
  2860. * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
  2861. *
  2862. * Setup the RX handlers for each of the reply types sent from the uCode
  2863. * to the host.
  2864. *
  2865. * This function chains into the hardware specific files for them to setup
  2866. * any hardware specific handlers as well.
  2867. */
  2868. static void iwl3945_setup_rx_handlers(struct iwl3945_priv *priv)
  2869. {
  2870. priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
  2871. priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
  2872. priv->rx_handlers[REPLY_ERROR] = iwl3945_rx_reply_error;
  2873. priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl3945_rx_csa;
  2874. priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
  2875. iwl3945_rx_spectrum_measure_notif;
  2876. priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl3945_rx_pm_sleep_notif;
  2877. priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
  2878. iwl3945_rx_pm_debug_statistics_notif;
  2879. priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
  2880. /*
  2881. * The same handler is used for both the REPLY to a discrete
  2882. * statistics request from the host as well as for the periodic
  2883. * statistics notifications (after received beacons) from the uCode.
  2884. */
  2885. priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
  2886. priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
  2887. priv->rx_handlers[REPLY_SCAN_CMD] = iwl3945_rx_reply_scan;
  2888. priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl3945_rx_scan_start_notif;
  2889. priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
  2890. iwl3945_rx_scan_results_notif;
  2891. priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
  2892. iwl3945_rx_scan_complete_notif;
  2893. priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
  2894. /* Set up hardware specific Rx handlers */
  2895. iwl3945_hw_rx_handler_setup(priv);
  2896. }
  2897. /**
  2898. * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries
  2899. * When FW advances 'R' index, all entries between old and new 'R' index
  2900. * need to be reclaimed.
  2901. */
  2902. static void iwl3945_cmd_queue_reclaim(struct iwl3945_priv *priv,
  2903. int txq_id, int index)
  2904. {
  2905. struct iwl3945_tx_queue *txq = &priv->txq[txq_id];
  2906. struct iwl3945_queue *q = &txq->q;
  2907. int nfreed = 0;
  2908. if ((index >= q->n_bd) || (iwl3945_x2_queue_used(q, index) == 0)) {
  2909. IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
  2910. "is out of range [0-%d] %d %d.\n", txq_id,
  2911. index, q->n_bd, q->write_ptr, q->read_ptr);
  2912. return;
  2913. }
  2914. for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
  2915. q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
  2916. if (nfreed > 1) {
  2917. IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index,
  2918. q->write_ptr, q->read_ptr);
  2919. queue_work(priv->workqueue, &priv->restart);
  2920. break;
  2921. }
  2922. nfreed++;
  2923. }
  2924. }
  2925. /**
  2926. * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
  2927. * @rxb: Rx buffer to reclaim
  2928. *
  2929. * If an Rx buffer has an async callback associated with it the callback
  2930. * will be executed. The attached skb (if present) will only be freed
  2931. * if the callback returns 1
  2932. */
  2933. static void iwl3945_tx_cmd_complete(struct iwl3945_priv *priv,
  2934. struct iwl3945_rx_mem_buffer *rxb)
  2935. {
  2936. struct iwl3945_rx_packet *pkt = (struct iwl3945_rx_packet *)rxb->skb->data;
  2937. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  2938. int txq_id = SEQ_TO_QUEUE(sequence);
  2939. int index = SEQ_TO_INDEX(sequence);
  2940. int huge = sequence & SEQ_HUGE_FRAME;
  2941. int cmd_index;
  2942. struct iwl3945_cmd *cmd;
  2943. BUG_ON(txq_id != IWL_CMD_QUEUE_NUM);
  2944. cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
  2945. cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
  2946. /* Input error checking is done when commands are added to queue. */
  2947. if (cmd->meta.flags & CMD_WANT_SKB) {
  2948. cmd->meta.source->u.skb = rxb->skb;
  2949. rxb->skb = NULL;
  2950. } else if (cmd->meta.u.callback &&
  2951. !cmd->meta.u.callback(priv, cmd, rxb->skb))
  2952. rxb->skb = NULL;
  2953. iwl3945_cmd_queue_reclaim(priv, txq_id, index);
  2954. if (!(cmd->meta.flags & CMD_ASYNC)) {
  2955. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  2956. wake_up_interruptible(&priv->wait_command_queue);
  2957. }
  2958. }
  2959. /************************** RX-FUNCTIONS ****************************/
  2960. /*
  2961. * Rx theory of operation
  2962. *
  2963. * The host allocates 32 DMA target addresses and passes the host address
  2964. * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
  2965. * 0 to 31
  2966. *
  2967. * Rx Queue Indexes
  2968. * The host/firmware share two index registers for managing the Rx buffers.
  2969. *
  2970. * The READ index maps to the first position that the firmware may be writing
  2971. * to -- the driver can read up to (but not including) this position and get
  2972. * good data.
  2973. * The READ index is managed by the firmware once the card is enabled.
  2974. *
  2975. * The WRITE index maps to the last position the driver has read from -- the
  2976. * position preceding WRITE is the last slot the firmware can place a packet.
  2977. *
  2978. * The queue is empty (no good data) if WRITE = READ - 1, and is full if
  2979. * WRITE = READ.
  2980. *
  2981. * During initialization, the host sets up the READ queue position to the first
  2982. * INDEX position, and WRITE to the last (READ - 1 wrapped)
  2983. *
  2984. * When the firmware places a packet in a buffer, it will advance the READ index
  2985. * and fire the RX interrupt. The driver can then query the READ index and
  2986. * process as many packets as possible, moving the WRITE index forward as it
  2987. * resets the Rx queue buffers with new memory.
  2988. *
  2989. * The management in the driver is as follows:
  2990. * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
  2991. * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
  2992. * to replenish the iwl->rxq->rx_free.
  2993. * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
  2994. * iwl->rxq is replenished and the READ INDEX is updated (updating the
  2995. * 'processed' and 'read' driver indexes as well)
  2996. * + A received packet is processed and handed to the kernel network stack,
  2997. * detached from the iwl->rxq. The driver 'processed' index is updated.
  2998. * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
  2999. * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
  3000. * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
  3001. * were enough free buffers and RX_STALLED is set it is cleared.
  3002. *
  3003. *
  3004. * Driver sequence:
  3005. *
  3006. * iwl3945_rx_queue_alloc() Allocates rx_free
  3007. * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
  3008. * iwl3945_rx_queue_restock
  3009. * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
  3010. * queue, updates firmware pointers, and updates
  3011. * the WRITE index. If insufficient rx_free buffers
  3012. * are available, schedules iwl3945_rx_replenish
  3013. *
  3014. * -- enable interrupts --
  3015. * ISR - iwl3945_rx() Detach iwl3945_rx_mem_buffers from pool up to the
  3016. * READ INDEX, detaching the SKB from the pool.
  3017. * Moves the packet buffer from queue to rx_used.
  3018. * Calls iwl3945_rx_queue_restock to refill any empty
  3019. * slots.
  3020. * ...
  3021. *
  3022. */
  3023. /**
  3024. * iwl3945_rx_queue_space - Return number of free slots available in queue.
  3025. */
  3026. static int iwl3945_rx_queue_space(const struct iwl3945_rx_queue *q)
  3027. {
  3028. int s = q->read - q->write;
  3029. if (s <= 0)
  3030. s += RX_QUEUE_SIZE;
  3031. /* keep some buffer to not confuse full and empty queue */
  3032. s -= 2;
  3033. if (s < 0)
  3034. s = 0;
  3035. return s;
  3036. }
  3037. /**
  3038. * iwl3945_rx_queue_update_write_ptr - Update the write pointer for the RX queue
  3039. */
  3040. int iwl3945_rx_queue_update_write_ptr(struct iwl3945_priv *priv, struct iwl3945_rx_queue *q)
  3041. {
  3042. u32 reg = 0;
  3043. int rc = 0;
  3044. unsigned long flags;
  3045. spin_lock_irqsave(&q->lock, flags);
  3046. if (q->need_update == 0)
  3047. goto exit_unlock;
  3048. /* If power-saving is in use, make sure device is awake */
  3049. if (test_bit(STATUS_POWER_PMI, &priv->status)) {
  3050. reg = iwl3945_read32(priv, CSR_UCODE_DRV_GP1);
  3051. if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
  3052. iwl3945_set_bit(priv, CSR_GP_CNTRL,
  3053. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  3054. goto exit_unlock;
  3055. }
  3056. rc = iwl3945_grab_nic_access(priv);
  3057. if (rc)
  3058. goto exit_unlock;
  3059. /* Device expects a multiple of 8 */
  3060. iwl3945_write_direct32(priv, FH_RSCSR_CHNL0_WPTR,
  3061. q->write & ~0x7);
  3062. iwl3945_release_nic_access(priv);
  3063. /* Else device is assumed to be awake */
  3064. } else
  3065. /* Device expects a multiple of 8 */
  3066. iwl3945_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7);
  3067. q->need_update = 0;
  3068. exit_unlock:
  3069. spin_unlock_irqrestore(&q->lock, flags);
  3070. return rc;
  3071. }
  3072. /**
  3073. * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
  3074. */
  3075. static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl3945_priv *priv,
  3076. dma_addr_t dma_addr)
  3077. {
  3078. return cpu_to_le32((u32)dma_addr);
  3079. }
  3080. /**
  3081. * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
  3082. *
  3083. * If there are slots in the RX queue that need to be restocked,
  3084. * and we have free pre-allocated buffers, fill the ranks as much
  3085. * as we can, pulling from rx_free.
  3086. *
  3087. * This moves the 'write' index forward to catch up with 'processed', and
  3088. * also updates the memory address in the firmware to reference the new
  3089. * target buffer.
  3090. */
  3091. static int iwl3945_rx_queue_restock(struct iwl3945_priv *priv)
  3092. {
  3093. struct iwl3945_rx_queue *rxq = &priv->rxq;
  3094. struct list_head *element;
  3095. struct iwl3945_rx_mem_buffer *rxb;
  3096. unsigned long flags;
  3097. int write, rc;
  3098. spin_lock_irqsave(&rxq->lock, flags);
  3099. write = rxq->write & ~0x7;
  3100. while ((iwl3945_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
  3101. /* Get next free Rx buffer, remove from free list */
  3102. element = rxq->rx_free.next;
  3103. rxb = list_entry(element, struct iwl3945_rx_mem_buffer, list);
  3104. list_del(element);
  3105. /* Point to Rx buffer via next RBD in circular buffer */
  3106. rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->dma_addr);
  3107. rxq->queue[rxq->write] = rxb;
  3108. rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
  3109. rxq->free_count--;
  3110. }
  3111. spin_unlock_irqrestore(&rxq->lock, flags);
  3112. /* If the pre-allocated buffer pool is dropping low, schedule to
  3113. * refill it */
  3114. if (rxq->free_count <= RX_LOW_WATERMARK)
  3115. queue_work(priv->workqueue, &priv->rx_replenish);
  3116. /* If we've added more space for the firmware to place data, tell it.
  3117. * Increment device's write pointer in multiples of 8. */
  3118. if ((write != (rxq->write & ~0x7))
  3119. || (abs(rxq->write - rxq->read) > 7)) {
  3120. spin_lock_irqsave(&rxq->lock, flags);
  3121. rxq->need_update = 1;
  3122. spin_unlock_irqrestore(&rxq->lock, flags);
  3123. rc = iwl3945_rx_queue_update_write_ptr(priv, rxq);
  3124. if (rc)
  3125. return rc;
  3126. }
  3127. return 0;
  3128. }
  3129. /**
  3130. * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
  3131. *
  3132. * When moving to rx_free an SKB is allocated for the slot.
  3133. *
  3134. * Also restock the Rx queue via iwl3945_rx_queue_restock.
  3135. * This is called as a scheduled work item (except for during initialization)
  3136. */
  3137. static void iwl3945_rx_allocate(struct iwl3945_priv *priv)
  3138. {
  3139. struct iwl3945_rx_queue *rxq = &priv->rxq;
  3140. struct list_head *element;
  3141. struct iwl3945_rx_mem_buffer *rxb;
  3142. unsigned long flags;
  3143. spin_lock_irqsave(&rxq->lock, flags);
  3144. while (!list_empty(&rxq->rx_used)) {
  3145. element = rxq->rx_used.next;
  3146. rxb = list_entry(element, struct iwl3945_rx_mem_buffer, list);
  3147. /* Alloc a new receive buffer */
  3148. rxb->skb =
  3149. alloc_skb(IWL_RX_BUF_SIZE, __GFP_NOWARN | GFP_ATOMIC);
  3150. if (!rxb->skb) {
  3151. if (net_ratelimit())
  3152. printk(KERN_CRIT DRV_NAME
  3153. ": Can not allocate SKB buffers\n");
  3154. /* We don't reschedule replenish work here -- we will
  3155. * call the restock method and if it still needs
  3156. * more buffers it will schedule replenish */
  3157. break;
  3158. }
  3159. /* If radiotap head is required, reserve some headroom here.
  3160. * The physical head count is a variable rx_stats->phy_count.
  3161. * We reserve 4 bytes here. Plus these extra bytes, the
  3162. * headroom of the physical head should be enough for the
  3163. * radiotap head that iwl3945 supported. See iwl3945_rt.
  3164. */
  3165. skb_reserve(rxb->skb, 4);
  3166. priv->alloc_rxb_skb++;
  3167. list_del(element);
  3168. /* Get physical address of RB/SKB */
  3169. rxb->dma_addr =
  3170. pci_map_single(priv->pci_dev, rxb->skb->data,
  3171. IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
  3172. list_add_tail(&rxb->list, &rxq->rx_free);
  3173. rxq->free_count++;
  3174. }
  3175. spin_unlock_irqrestore(&rxq->lock, flags);
  3176. }
  3177. /*
  3178. * this should be called while priv->lock is locked
  3179. */
  3180. static void __iwl3945_rx_replenish(void *data)
  3181. {
  3182. struct iwl3945_priv *priv = data;
  3183. iwl3945_rx_allocate(priv);
  3184. iwl3945_rx_queue_restock(priv);
  3185. }
  3186. void iwl3945_rx_replenish(void *data)
  3187. {
  3188. struct iwl3945_priv *priv = data;
  3189. unsigned long flags;
  3190. iwl3945_rx_allocate(priv);
  3191. spin_lock_irqsave(&priv->lock, flags);
  3192. iwl3945_rx_queue_restock(priv);
  3193. spin_unlock_irqrestore(&priv->lock, flags);
  3194. }
  3195. /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
  3196. * If an SKB has been detached, the POOL needs to have its SKB set to NULL
  3197. * This free routine walks the list of POOL entries and if SKB is set to
  3198. * non NULL it is unmapped and freed
  3199. */
  3200. static void iwl3945_rx_queue_free(struct iwl3945_priv *priv, struct iwl3945_rx_queue *rxq)
  3201. {
  3202. int i;
  3203. for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
  3204. if (rxq->pool[i].skb != NULL) {
  3205. pci_unmap_single(priv->pci_dev,
  3206. rxq->pool[i].dma_addr,
  3207. IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
  3208. dev_kfree_skb(rxq->pool[i].skb);
  3209. }
  3210. }
  3211. pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd,
  3212. rxq->dma_addr);
  3213. rxq->bd = NULL;
  3214. }
  3215. int iwl3945_rx_queue_alloc(struct iwl3945_priv *priv)
  3216. {
  3217. struct iwl3945_rx_queue *rxq = &priv->rxq;
  3218. struct pci_dev *dev = priv->pci_dev;
  3219. int i;
  3220. spin_lock_init(&rxq->lock);
  3221. INIT_LIST_HEAD(&rxq->rx_free);
  3222. INIT_LIST_HEAD(&rxq->rx_used);
  3223. /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */
  3224. rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr);
  3225. if (!rxq->bd)
  3226. return -ENOMEM;
  3227. /* Fill the rx_used queue with _all_ of the Rx buffers */
  3228. for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
  3229. list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
  3230. /* Set us so that we have processed and used all buffers, but have
  3231. * not restocked the Rx queue with fresh buffers */
  3232. rxq->read = rxq->write = 0;
  3233. rxq->free_count = 0;
  3234. rxq->need_update = 0;
  3235. return 0;
  3236. }
  3237. void iwl3945_rx_queue_reset(struct iwl3945_priv *priv, struct iwl3945_rx_queue *rxq)
  3238. {
  3239. unsigned long flags;
  3240. int i;
  3241. spin_lock_irqsave(&rxq->lock, flags);
  3242. INIT_LIST_HEAD(&rxq->rx_free);
  3243. INIT_LIST_HEAD(&rxq->rx_used);
  3244. /* Fill the rx_used queue with _all_ of the Rx buffers */
  3245. for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
  3246. /* In the reset function, these buffers may have been allocated
  3247. * to an SKB, so we need to unmap and free potential storage */
  3248. if (rxq->pool[i].skb != NULL) {
  3249. pci_unmap_single(priv->pci_dev,
  3250. rxq->pool[i].dma_addr,
  3251. IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
  3252. priv->alloc_rxb_skb--;
  3253. dev_kfree_skb(rxq->pool[i].skb);
  3254. rxq->pool[i].skb = NULL;
  3255. }
  3256. list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
  3257. }
  3258. /* Set us so that we have processed and used all buffers, but have
  3259. * not restocked the Rx queue with fresh buffers */
  3260. rxq->read = rxq->write = 0;
  3261. rxq->free_count = 0;
  3262. spin_unlock_irqrestore(&rxq->lock, flags);
  3263. }
  3264. /* Convert linear signal-to-noise ratio into dB */
  3265. static u8 ratio2dB[100] = {
  3266. /* 0 1 2 3 4 5 6 7 8 9 */
  3267. 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
  3268. 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
  3269. 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
  3270. 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
  3271. 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
  3272. 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
  3273. 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
  3274. 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
  3275. 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
  3276. 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
  3277. };
  3278. /* Calculates a relative dB value from a ratio of linear
  3279. * (i.e. not dB) signal levels.
  3280. * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
  3281. int iwl3945_calc_db_from_ratio(int sig_ratio)
  3282. {
  3283. /* 1000:1 or higher just report as 60 dB */
  3284. if (sig_ratio >= 1000)
  3285. return 60;
  3286. /* 100:1 or higher, divide by 10 and use table,
  3287. * add 20 dB to make up for divide by 10 */
  3288. if (sig_ratio >= 100)
  3289. return (20 + (int)ratio2dB[sig_ratio/10]);
  3290. /* We shouldn't see this */
  3291. if (sig_ratio < 1)
  3292. return 0;
  3293. /* Use table for ratios 1:1 - 99:1 */
  3294. return (int)ratio2dB[sig_ratio];
  3295. }
  3296. #define PERFECT_RSSI (-20) /* dBm */
  3297. #define WORST_RSSI (-95) /* dBm */
  3298. #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
  3299. /* Calculate an indication of rx signal quality (a percentage, not dBm!).
  3300. * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
  3301. * about formulas used below. */
  3302. int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
  3303. {
  3304. int sig_qual;
  3305. int degradation = PERFECT_RSSI - rssi_dbm;
  3306. /* If we get a noise measurement, use signal-to-noise ratio (SNR)
  3307. * as indicator; formula is (signal dbm - noise dbm).
  3308. * SNR at or above 40 is a great signal (100%).
  3309. * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
  3310. * Weakest usable signal is usually 10 - 15 dB SNR. */
  3311. if (noise_dbm) {
  3312. if (rssi_dbm - noise_dbm >= 40)
  3313. return 100;
  3314. else if (rssi_dbm < noise_dbm)
  3315. return 0;
  3316. sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
  3317. /* Else use just the signal level.
  3318. * This formula is a least squares fit of data points collected and
  3319. * compared with a reference system that had a percentage (%) display
  3320. * for signal quality. */
  3321. } else
  3322. sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
  3323. (15 * RSSI_RANGE + 62 * degradation)) /
  3324. (RSSI_RANGE * RSSI_RANGE);
  3325. if (sig_qual > 100)
  3326. sig_qual = 100;
  3327. else if (sig_qual < 1)
  3328. sig_qual = 0;
  3329. return sig_qual;
  3330. }
  3331. /**
  3332. * iwl3945_rx_handle - Main entry function for receiving responses from uCode
  3333. *
  3334. * Uses the priv->rx_handlers callback function array to invoke
  3335. * the appropriate handlers, including command responses,
  3336. * frame-received notifications, and other notifications.
  3337. */
  3338. static void iwl3945_rx_handle(struct iwl3945_priv *priv)
  3339. {
  3340. struct iwl3945_rx_mem_buffer *rxb;
  3341. struct iwl3945_rx_packet *pkt;
  3342. struct iwl3945_rx_queue *rxq = &priv->rxq;
  3343. u32 r, i;
  3344. int reclaim;
  3345. unsigned long flags;
  3346. u8 fill_rx = 0;
  3347. u32 count = 8;
  3348. /* uCode's read index (stored in shared DRAM) indicates the last Rx
  3349. * buffer that the driver may process (last buffer filled by ucode). */
  3350. r = iwl3945_hw_get_rx_read(priv);
  3351. i = rxq->read;
  3352. if (iwl3945_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
  3353. fill_rx = 1;
  3354. /* Rx interrupt, but nothing sent from uCode */
  3355. if (i == r)
  3356. IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
  3357. while (i != r) {
  3358. rxb = rxq->queue[i];
  3359. /* If an RXB doesn't have a Rx queue slot associated with it,
  3360. * then a bug has been introduced in the queue refilling
  3361. * routines -- catch it here */
  3362. BUG_ON(rxb == NULL);
  3363. rxq->queue[i] = NULL;
  3364. pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
  3365. IWL_RX_BUF_SIZE,
  3366. PCI_DMA_FROMDEVICE);
  3367. pkt = (struct iwl3945_rx_packet *)rxb->skb->data;
  3368. /* Reclaim a command buffer only if this packet is a response
  3369. * to a (driver-originated) command.
  3370. * If the packet (e.g. Rx frame) originated from uCode,
  3371. * there is no command buffer to reclaim.
  3372. * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
  3373. * but apparently a few don't get set; catch them here. */
  3374. reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
  3375. (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
  3376. (pkt->hdr.cmd != REPLY_TX);
  3377. /* Based on type of command response or notification,
  3378. * handle those that need handling via function in
  3379. * rx_handlers table. See iwl3945_setup_rx_handlers() */
  3380. if (priv->rx_handlers[pkt->hdr.cmd]) {
  3381. IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR,
  3382. "r = %d, i = %d, %s, 0x%02x\n", r, i,
  3383. get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
  3384. priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
  3385. } else {
  3386. /* No handling needed */
  3387. IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR,
  3388. "r %d i %d No handler needed for %s, 0x%02x\n",
  3389. r, i, get_cmd_string(pkt->hdr.cmd),
  3390. pkt->hdr.cmd);
  3391. }
  3392. if (reclaim) {
  3393. /* Invoke any callbacks, transfer the skb to caller, and
  3394. * fire off the (possibly) blocking iwl3945_send_cmd()
  3395. * as we reclaim the driver command queue */
  3396. if (rxb && rxb->skb)
  3397. iwl3945_tx_cmd_complete(priv, rxb);
  3398. else
  3399. IWL_WARNING("Claim null rxb?\n");
  3400. }
  3401. /* For now we just don't re-use anything. We can tweak this
  3402. * later to try and re-use notification packets and SKBs that
  3403. * fail to Rx correctly */
  3404. if (rxb->skb != NULL) {
  3405. priv->alloc_rxb_skb--;
  3406. dev_kfree_skb_any(rxb->skb);
  3407. rxb->skb = NULL;
  3408. }
  3409. pci_unmap_single(priv->pci_dev, rxb->dma_addr,
  3410. IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
  3411. spin_lock_irqsave(&rxq->lock, flags);
  3412. list_add_tail(&rxb->list, &priv->rxq.rx_used);
  3413. spin_unlock_irqrestore(&rxq->lock, flags);
  3414. i = (i + 1) & RX_QUEUE_MASK;
  3415. /* If there are a lot of unused frames,
  3416. * restock the Rx queue so ucode won't assert. */
  3417. if (fill_rx) {
  3418. count++;
  3419. if (count >= 8) {
  3420. priv->rxq.read = i;
  3421. __iwl3945_rx_replenish(priv);
  3422. count = 0;
  3423. }
  3424. }
  3425. }
  3426. /* Backtrack one entry */
  3427. priv->rxq.read = i;
  3428. iwl3945_rx_queue_restock(priv);
  3429. }
  3430. /**
  3431. * iwl3945_tx_queue_update_write_ptr - Send new write index to hardware
  3432. */
  3433. static int iwl3945_tx_queue_update_write_ptr(struct iwl3945_priv *priv,
  3434. struct iwl3945_tx_queue *txq)
  3435. {
  3436. u32 reg = 0;
  3437. int rc = 0;
  3438. int txq_id = txq->q.id;
  3439. if (txq->need_update == 0)
  3440. return rc;
  3441. /* if we're trying to save power */
  3442. if (test_bit(STATUS_POWER_PMI, &priv->status)) {
  3443. /* wake up nic if it's powered down ...
  3444. * uCode will wake up, and interrupt us again, so next
  3445. * time we'll skip this part. */
  3446. reg = iwl3945_read32(priv, CSR_UCODE_DRV_GP1);
  3447. if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
  3448. IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg);
  3449. iwl3945_set_bit(priv, CSR_GP_CNTRL,
  3450. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  3451. return rc;
  3452. }
  3453. /* restore this queue's parameters in nic hardware. */
  3454. rc = iwl3945_grab_nic_access(priv);
  3455. if (rc)
  3456. return rc;
  3457. iwl3945_write_direct32(priv, HBUS_TARG_WRPTR,
  3458. txq->q.write_ptr | (txq_id << 8));
  3459. iwl3945_release_nic_access(priv);
  3460. /* else not in power-save mode, uCode will never sleep when we're
  3461. * trying to tx (during RFKILL, we're not trying to tx). */
  3462. } else
  3463. iwl3945_write32(priv, HBUS_TARG_WRPTR,
  3464. txq->q.write_ptr | (txq_id << 8));
  3465. txq->need_update = 0;
  3466. return rc;
  3467. }
  3468. #ifdef CONFIG_IWL3945_DEBUG
  3469. static void iwl3945_print_rx_config_cmd(struct iwl3945_rxon_cmd *rxon)
  3470. {
  3471. DECLARE_MAC_BUF(mac);
  3472. IWL_DEBUG_RADIO("RX CONFIG:\n");
  3473. iwl3945_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
  3474. IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
  3475. IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
  3476. IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
  3477. le32_to_cpu(rxon->filter_flags));
  3478. IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
  3479. IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
  3480. rxon->ofdm_basic_rates);
  3481. IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
  3482. IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
  3483. print_mac(mac, rxon->node_addr));
  3484. IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
  3485. print_mac(mac, rxon->bssid_addr));
  3486. IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
  3487. }
  3488. #endif
  3489. static void iwl3945_enable_interrupts(struct iwl3945_priv *priv)
  3490. {
  3491. IWL_DEBUG_ISR("Enabling interrupts\n");
  3492. set_bit(STATUS_INT_ENABLED, &priv->status);
  3493. iwl3945_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
  3494. }
  3495. static inline void iwl3945_disable_interrupts(struct iwl3945_priv *priv)
  3496. {
  3497. clear_bit(STATUS_INT_ENABLED, &priv->status);
  3498. /* disable interrupts from uCode/NIC to host */
  3499. iwl3945_write32(priv, CSR_INT_MASK, 0x00000000);
  3500. /* acknowledge/clear/reset any interrupts still pending
  3501. * from uCode or flow handler (Rx/Tx DMA) */
  3502. iwl3945_write32(priv, CSR_INT, 0xffffffff);
  3503. iwl3945_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
  3504. IWL_DEBUG_ISR("Disabled interrupts\n");
  3505. }
  3506. static const char *desc_lookup(int i)
  3507. {
  3508. switch (i) {
  3509. case 1:
  3510. return "FAIL";
  3511. case 2:
  3512. return "BAD_PARAM";
  3513. case 3:
  3514. return "BAD_CHECKSUM";
  3515. case 4:
  3516. return "NMI_INTERRUPT";
  3517. case 5:
  3518. return "SYSASSERT";
  3519. case 6:
  3520. return "FATAL_ERROR";
  3521. }
  3522. return "UNKNOWN";
  3523. }
  3524. #define ERROR_START_OFFSET (1 * sizeof(u32))
  3525. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  3526. static void iwl3945_dump_nic_error_log(struct iwl3945_priv *priv)
  3527. {
  3528. u32 i;
  3529. u32 desc, time, count, base, data1;
  3530. u32 blink1, blink2, ilink1, ilink2;
  3531. int rc;
  3532. base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
  3533. if (!iwl3945_hw_valid_rtc_data_addr(base)) {
  3534. IWL_ERROR("Not valid error log pointer 0x%08X\n", base);
  3535. return;
  3536. }
  3537. rc = iwl3945_grab_nic_access(priv);
  3538. if (rc) {
  3539. IWL_WARNING("Can not read from adapter at this time.\n");
  3540. return;
  3541. }
  3542. count = iwl3945_read_targ_mem(priv, base);
  3543. if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
  3544. IWL_ERROR("Start IWL Error Log Dump:\n");
  3545. IWL_ERROR("Status: 0x%08lX, count: %d\n", priv->status, count);
  3546. }
  3547. IWL_ERROR("Desc Time asrtPC blink2 "
  3548. "ilink1 nmiPC Line\n");
  3549. for (i = ERROR_START_OFFSET;
  3550. i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
  3551. i += ERROR_ELEM_SIZE) {
  3552. desc = iwl3945_read_targ_mem(priv, base + i);
  3553. time =
  3554. iwl3945_read_targ_mem(priv, base + i + 1 * sizeof(u32));
  3555. blink1 =
  3556. iwl3945_read_targ_mem(priv, base + i + 2 * sizeof(u32));
  3557. blink2 =
  3558. iwl3945_read_targ_mem(priv, base + i + 3 * sizeof(u32));
  3559. ilink1 =
  3560. iwl3945_read_targ_mem(priv, base + i + 4 * sizeof(u32));
  3561. ilink2 =
  3562. iwl3945_read_targ_mem(priv, base + i + 5 * sizeof(u32));
  3563. data1 =
  3564. iwl3945_read_targ_mem(priv, base + i + 6 * sizeof(u32));
  3565. IWL_ERROR
  3566. ("%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
  3567. desc_lookup(desc), desc, time, blink1, blink2,
  3568. ilink1, ilink2, data1);
  3569. }
  3570. iwl3945_release_nic_access(priv);
  3571. }
  3572. #define EVENT_START_OFFSET (6 * sizeof(u32))
  3573. /**
  3574. * iwl3945_print_event_log - Dump error event log to syslog
  3575. *
  3576. * NOTE: Must be called with iwl3945_grab_nic_access() already obtained!
  3577. */
  3578. static void iwl3945_print_event_log(struct iwl3945_priv *priv, u32 start_idx,
  3579. u32 num_events, u32 mode)
  3580. {
  3581. u32 i;
  3582. u32 base; /* SRAM byte address of event log header */
  3583. u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
  3584. u32 ptr; /* SRAM byte address of log data */
  3585. u32 ev, time, data; /* event log data */
  3586. if (num_events == 0)
  3587. return;
  3588. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  3589. if (mode == 0)
  3590. event_size = 2 * sizeof(u32);
  3591. else
  3592. event_size = 3 * sizeof(u32);
  3593. ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
  3594. /* "time" is actually "data" for mode 0 (no timestamp).
  3595. * place event id # at far right for easier visual parsing. */
  3596. for (i = 0; i < num_events; i++) {
  3597. ev = iwl3945_read_targ_mem(priv, ptr);
  3598. ptr += sizeof(u32);
  3599. time = iwl3945_read_targ_mem(priv, ptr);
  3600. ptr += sizeof(u32);
  3601. if (mode == 0)
  3602. IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */
  3603. else {
  3604. data = iwl3945_read_targ_mem(priv, ptr);
  3605. ptr += sizeof(u32);
  3606. IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev);
  3607. }
  3608. }
  3609. }
  3610. static void iwl3945_dump_nic_event_log(struct iwl3945_priv *priv)
  3611. {
  3612. int rc;
  3613. u32 base; /* SRAM byte address of event log header */
  3614. u32 capacity; /* event log capacity in # entries */
  3615. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  3616. u32 num_wraps; /* # times uCode wrapped to top of log */
  3617. u32 next_entry; /* index of next entry to be written by uCode */
  3618. u32 size; /* # entries that we'll print */
  3619. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  3620. if (!iwl3945_hw_valid_rtc_data_addr(base)) {
  3621. IWL_ERROR("Invalid event log pointer 0x%08X\n", base);
  3622. return;
  3623. }
  3624. rc = iwl3945_grab_nic_access(priv);
  3625. if (rc) {
  3626. IWL_WARNING("Can not read from adapter at this time.\n");
  3627. return;
  3628. }
  3629. /* event log header */
  3630. capacity = iwl3945_read_targ_mem(priv, base);
  3631. mode = iwl3945_read_targ_mem(priv, base + (1 * sizeof(u32)));
  3632. num_wraps = iwl3945_read_targ_mem(priv, base + (2 * sizeof(u32)));
  3633. next_entry = iwl3945_read_targ_mem(priv, base + (3 * sizeof(u32)));
  3634. size = num_wraps ? capacity : next_entry;
  3635. /* bail out if nothing in log */
  3636. if (size == 0) {
  3637. IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
  3638. iwl3945_release_nic_access(priv);
  3639. return;
  3640. }
  3641. IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
  3642. size, num_wraps);
  3643. /* if uCode has wrapped back to top of log, start at the oldest entry,
  3644. * i.e the next one that uCode would fill. */
  3645. if (num_wraps)
  3646. iwl3945_print_event_log(priv, next_entry,
  3647. capacity - next_entry, mode);
  3648. /* (then/else) start at top of log */
  3649. iwl3945_print_event_log(priv, 0, next_entry, mode);
  3650. iwl3945_release_nic_access(priv);
  3651. }
  3652. /**
  3653. * iwl3945_irq_handle_error - called for HW or SW error interrupt from card
  3654. */
  3655. static void iwl3945_irq_handle_error(struct iwl3945_priv *priv)
  3656. {
  3657. /* Set the FW error flag -- cleared on iwl3945_down */
  3658. set_bit(STATUS_FW_ERROR, &priv->status);
  3659. /* Cancel currently queued command. */
  3660. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  3661. #ifdef CONFIG_IWL3945_DEBUG
  3662. if (iwl3945_debug_level & IWL_DL_FW_ERRORS) {
  3663. iwl3945_dump_nic_error_log(priv);
  3664. iwl3945_dump_nic_event_log(priv);
  3665. iwl3945_print_rx_config_cmd(&priv->staging_rxon);
  3666. }
  3667. #endif
  3668. wake_up_interruptible(&priv->wait_command_queue);
  3669. /* Keep the restart process from trying to send host
  3670. * commands by clearing the INIT status bit */
  3671. clear_bit(STATUS_READY, &priv->status);
  3672. if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  3673. IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS,
  3674. "Restarting adapter due to uCode error.\n");
  3675. if (iwl3945_is_associated(priv)) {
  3676. memcpy(&priv->recovery_rxon, &priv->active_rxon,
  3677. sizeof(priv->recovery_rxon));
  3678. priv->error_recovering = 1;
  3679. }
  3680. queue_work(priv->workqueue, &priv->restart);
  3681. }
  3682. }
  3683. static void iwl3945_error_recovery(struct iwl3945_priv *priv)
  3684. {
  3685. unsigned long flags;
  3686. memcpy(&priv->staging_rxon, &priv->recovery_rxon,
  3687. sizeof(priv->staging_rxon));
  3688. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3689. iwl3945_commit_rxon(priv);
  3690. iwl3945_add_station(priv, priv->bssid, 1, 0);
  3691. spin_lock_irqsave(&priv->lock, flags);
  3692. priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
  3693. priv->error_recovering = 0;
  3694. spin_unlock_irqrestore(&priv->lock, flags);
  3695. }
  3696. static void iwl3945_irq_tasklet(struct iwl3945_priv *priv)
  3697. {
  3698. u32 inta, handled = 0;
  3699. u32 inta_fh;
  3700. unsigned long flags;
  3701. #ifdef CONFIG_IWL3945_DEBUG
  3702. u32 inta_mask;
  3703. #endif
  3704. spin_lock_irqsave(&priv->lock, flags);
  3705. /* Ack/clear/reset pending uCode interrupts.
  3706. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
  3707. * and will clear only when CSR_FH_INT_STATUS gets cleared. */
  3708. inta = iwl3945_read32(priv, CSR_INT);
  3709. iwl3945_write32(priv, CSR_INT, inta);
  3710. /* Ack/clear/reset pending flow-handler (DMA) interrupts.
  3711. * Any new interrupts that happen after this, either while we're
  3712. * in this tasklet, or later, will show up in next ISR/tasklet. */
  3713. inta_fh = iwl3945_read32(priv, CSR_FH_INT_STATUS);
  3714. iwl3945_write32(priv, CSR_FH_INT_STATUS, inta_fh);
  3715. #ifdef CONFIG_IWL3945_DEBUG
  3716. if (iwl3945_debug_level & IWL_DL_ISR) {
  3717. /* just for debug */
  3718. inta_mask = iwl3945_read32(priv, CSR_INT_MASK);
  3719. IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  3720. inta, inta_mask, inta_fh);
  3721. }
  3722. #endif
  3723. /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
  3724. * atomic, make sure that inta covers all the interrupts that
  3725. * we've discovered, even if FH interrupt came in just after
  3726. * reading CSR_INT. */
  3727. if (inta_fh & CSR39_FH_INT_RX_MASK)
  3728. inta |= CSR_INT_BIT_FH_RX;
  3729. if (inta_fh & CSR39_FH_INT_TX_MASK)
  3730. inta |= CSR_INT_BIT_FH_TX;
  3731. /* Now service all interrupt bits discovered above. */
  3732. if (inta & CSR_INT_BIT_HW_ERR) {
  3733. IWL_ERROR("Microcode HW error detected. Restarting.\n");
  3734. /* Tell the device to stop sending interrupts */
  3735. iwl3945_disable_interrupts(priv);
  3736. iwl3945_irq_handle_error(priv);
  3737. handled |= CSR_INT_BIT_HW_ERR;
  3738. spin_unlock_irqrestore(&priv->lock, flags);
  3739. return;
  3740. }
  3741. #ifdef CONFIG_IWL3945_DEBUG
  3742. if (iwl3945_debug_level & (IWL_DL_ISR)) {
  3743. /* NIC fires this, but we don't use it, redundant with WAKEUP */
  3744. if (inta & CSR_INT_BIT_SCD)
  3745. IWL_DEBUG_ISR("Scheduler finished to transmit "
  3746. "the frame/frames.\n");
  3747. /* Alive notification via Rx interrupt will do the real work */
  3748. if (inta & CSR_INT_BIT_ALIVE)
  3749. IWL_DEBUG_ISR("Alive interrupt\n");
  3750. }
  3751. #endif
  3752. /* Safely ignore these bits for debug checks below */
  3753. inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
  3754. /* HW RF KILL switch toggled (4965 only) */
  3755. if (inta & CSR_INT_BIT_RF_KILL) {
  3756. int hw_rf_kill = 0;
  3757. if (!(iwl3945_read32(priv, CSR_GP_CNTRL) &
  3758. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
  3759. hw_rf_kill = 1;
  3760. IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL | IWL_DL_ISR,
  3761. "RF_KILL bit toggled to %s.\n",
  3762. hw_rf_kill ? "disable radio":"enable radio");
  3763. /* Queue restart only if RF_KILL switch was set to "kill"
  3764. * when we loaded driver, and is now set to "enable".
  3765. * After we're Alive, RF_KILL gets handled by
  3766. * iwl3945_rx_card_state_notif() */
  3767. if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) {
  3768. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  3769. queue_work(priv->workqueue, &priv->restart);
  3770. }
  3771. handled |= CSR_INT_BIT_RF_KILL;
  3772. }
  3773. /* Chip got too hot and stopped itself (4965 only) */
  3774. if (inta & CSR_INT_BIT_CT_KILL) {
  3775. IWL_ERROR("Microcode CT kill error detected.\n");
  3776. handled |= CSR_INT_BIT_CT_KILL;
  3777. }
  3778. /* Error detected by uCode */
  3779. if (inta & CSR_INT_BIT_SW_ERR) {
  3780. IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
  3781. inta);
  3782. iwl3945_irq_handle_error(priv);
  3783. handled |= CSR_INT_BIT_SW_ERR;
  3784. }
  3785. /* uCode wakes up after power-down sleep */
  3786. if (inta & CSR_INT_BIT_WAKEUP) {
  3787. IWL_DEBUG_ISR("Wakeup interrupt\n");
  3788. iwl3945_rx_queue_update_write_ptr(priv, &priv->rxq);
  3789. iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[0]);
  3790. iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[1]);
  3791. iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[2]);
  3792. iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[3]);
  3793. iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[4]);
  3794. iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[5]);
  3795. handled |= CSR_INT_BIT_WAKEUP;
  3796. }
  3797. /* All uCode command responses, including Tx command responses,
  3798. * Rx "responses" (frame-received notification), and other
  3799. * notifications from uCode come through here*/
  3800. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
  3801. iwl3945_rx_handle(priv);
  3802. handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
  3803. }
  3804. if (inta & CSR_INT_BIT_FH_TX) {
  3805. IWL_DEBUG_ISR("Tx interrupt\n");
  3806. iwl3945_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
  3807. if (!iwl3945_grab_nic_access(priv)) {
  3808. iwl3945_write_direct32(priv,
  3809. FH_TCSR_CREDIT
  3810. (ALM_FH_SRVC_CHNL), 0x0);
  3811. iwl3945_release_nic_access(priv);
  3812. }
  3813. handled |= CSR_INT_BIT_FH_TX;
  3814. }
  3815. if (inta & ~handled)
  3816. IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
  3817. if (inta & ~CSR_INI_SET_MASK) {
  3818. IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
  3819. inta & ~CSR_INI_SET_MASK);
  3820. IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh);
  3821. }
  3822. /* Re-enable all interrupts */
  3823. iwl3945_enable_interrupts(priv);
  3824. #ifdef CONFIG_IWL3945_DEBUG
  3825. if (iwl3945_debug_level & (IWL_DL_ISR)) {
  3826. inta = iwl3945_read32(priv, CSR_INT);
  3827. inta_mask = iwl3945_read32(priv, CSR_INT_MASK);
  3828. inta_fh = iwl3945_read32(priv, CSR_FH_INT_STATUS);
  3829. IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
  3830. "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
  3831. }
  3832. #endif
  3833. spin_unlock_irqrestore(&priv->lock, flags);
  3834. }
  3835. static irqreturn_t iwl3945_isr(int irq, void *data)
  3836. {
  3837. struct iwl3945_priv *priv = data;
  3838. u32 inta, inta_mask;
  3839. u32 inta_fh;
  3840. if (!priv)
  3841. return IRQ_NONE;
  3842. spin_lock(&priv->lock);
  3843. /* Disable (but don't clear!) interrupts here to avoid
  3844. * back-to-back ISRs and sporadic interrupts from our NIC.
  3845. * If we have something to service, the tasklet will re-enable ints.
  3846. * If we *don't* have something, we'll re-enable before leaving here. */
  3847. inta_mask = iwl3945_read32(priv, CSR_INT_MASK); /* just for debug */
  3848. iwl3945_write32(priv, CSR_INT_MASK, 0x00000000);
  3849. /* Discover which interrupts are active/pending */
  3850. inta = iwl3945_read32(priv, CSR_INT);
  3851. inta_fh = iwl3945_read32(priv, CSR_FH_INT_STATUS);
  3852. /* Ignore interrupt if there's nothing in NIC to service.
  3853. * This may be due to IRQ shared with another device,
  3854. * or due to sporadic interrupts thrown from our NIC. */
  3855. if (!inta && !inta_fh) {
  3856. IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
  3857. goto none;
  3858. }
  3859. if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
  3860. /* Hardware disappeared */
  3861. IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
  3862. goto unplugged;
  3863. }
  3864. IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  3865. inta, inta_mask, inta_fh);
  3866. inta &= ~CSR_INT_BIT_SCD;
  3867. /* iwl3945_irq_tasklet() will service interrupts and re-enable them */
  3868. if (likely(inta || inta_fh))
  3869. tasklet_schedule(&priv->irq_tasklet);
  3870. unplugged:
  3871. spin_unlock(&priv->lock);
  3872. return IRQ_HANDLED;
  3873. none:
  3874. /* re-enable interrupts here since we don't have anything to service. */
  3875. iwl3945_enable_interrupts(priv);
  3876. spin_unlock(&priv->lock);
  3877. return IRQ_NONE;
  3878. }
  3879. /************************** EEPROM BANDS ****************************
  3880. *
  3881. * The iwl3945_eeprom_band definitions below provide the mapping from the
  3882. * EEPROM contents to the specific channel number supported for each
  3883. * band.
  3884. *
  3885. * For example, iwl3945_priv->eeprom.band_3_channels[4] from the band_3
  3886. * definition below maps to physical channel 42 in the 5.2GHz spectrum.
  3887. * The specific geography and calibration information for that channel
  3888. * is contained in the eeprom map itself.
  3889. *
  3890. * During init, we copy the eeprom information and channel map
  3891. * information into priv->channel_info_24/52 and priv->channel_map_24/52
  3892. *
  3893. * channel_map_24/52 provides the index in the channel_info array for a
  3894. * given channel. We have to have two separate maps as there is channel
  3895. * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
  3896. * band_2
  3897. *
  3898. * A value of 0xff stored in the channel_map indicates that the channel
  3899. * is not supported by the hardware at all.
  3900. *
  3901. * A value of 0xfe in the channel_map indicates that the channel is not
  3902. * valid for Tx with the current hardware. This means that
  3903. * while the system can tune and receive on a given channel, it may not
  3904. * be able to associate or transmit any frames on that
  3905. * channel. There is no corresponding channel information for that
  3906. * entry.
  3907. *
  3908. *********************************************************************/
  3909. /* 2.4 GHz */
  3910. static const u8 iwl3945_eeprom_band_1[14] = {
  3911. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
  3912. };
  3913. /* 5.2 GHz bands */
  3914. static const u8 iwl3945_eeprom_band_2[] = { /* 4915-5080MHz */
  3915. 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
  3916. };
  3917. static const u8 iwl3945_eeprom_band_3[] = { /* 5170-5320MHz */
  3918. 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
  3919. };
  3920. static const u8 iwl3945_eeprom_band_4[] = { /* 5500-5700MHz */
  3921. 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
  3922. };
  3923. static const u8 iwl3945_eeprom_band_5[] = { /* 5725-5825MHz */
  3924. 145, 149, 153, 157, 161, 165
  3925. };
  3926. static void iwl3945_init_band_reference(const struct iwl3945_priv *priv, int band,
  3927. int *eeprom_ch_count,
  3928. const struct iwl3945_eeprom_channel
  3929. **eeprom_ch_info,
  3930. const u8 **eeprom_ch_index)
  3931. {
  3932. switch (band) {
  3933. case 1: /* 2.4GHz band */
  3934. *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_1);
  3935. *eeprom_ch_info = priv->eeprom.band_1_channels;
  3936. *eeprom_ch_index = iwl3945_eeprom_band_1;
  3937. break;
  3938. case 2: /* 4.9GHz band */
  3939. *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_2);
  3940. *eeprom_ch_info = priv->eeprom.band_2_channels;
  3941. *eeprom_ch_index = iwl3945_eeprom_band_2;
  3942. break;
  3943. case 3: /* 5.2GHz band */
  3944. *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_3);
  3945. *eeprom_ch_info = priv->eeprom.band_3_channels;
  3946. *eeprom_ch_index = iwl3945_eeprom_band_3;
  3947. break;
  3948. case 4: /* 5.5GHz band */
  3949. *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_4);
  3950. *eeprom_ch_info = priv->eeprom.band_4_channels;
  3951. *eeprom_ch_index = iwl3945_eeprom_band_4;
  3952. break;
  3953. case 5: /* 5.7GHz band */
  3954. *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_5);
  3955. *eeprom_ch_info = priv->eeprom.band_5_channels;
  3956. *eeprom_ch_index = iwl3945_eeprom_band_5;
  3957. break;
  3958. default:
  3959. BUG();
  3960. return;
  3961. }
  3962. }
  3963. /**
  3964. * iwl3945_get_channel_info - Find driver's private channel info
  3965. *
  3966. * Based on band and channel number.
  3967. */
  3968. const struct iwl3945_channel_info *iwl3945_get_channel_info(const struct iwl3945_priv *priv,
  3969. enum ieee80211_band band, u16 channel)
  3970. {
  3971. int i;
  3972. switch (band) {
  3973. case IEEE80211_BAND_5GHZ:
  3974. for (i = 14; i < priv->channel_count; i++) {
  3975. if (priv->channel_info[i].channel == channel)
  3976. return &priv->channel_info[i];
  3977. }
  3978. break;
  3979. case IEEE80211_BAND_2GHZ:
  3980. if (channel >= 1 && channel <= 14)
  3981. return &priv->channel_info[channel - 1];
  3982. break;
  3983. case IEEE80211_NUM_BANDS:
  3984. WARN_ON(1);
  3985. }
  3986. return NULL;
  3987. }
  3988. #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
  3989. ? # x " " : "")
  3990. /**
  3991. * iwl3945_init_channel_map - Set up driver's info for all possible channels
  3992. */
  3993. static int iwl3945_init_channel_map(struct iwl3945_priv *priv)
  3994. {
  3995. int eeprom_ch_count = 0;
  3996. const u8 *eeprom_ch_index = NULL;
  3997. const struct iwl3945_eeprom_channel *eeprom_ch_info = NULL;
  3998. int band, ch;
  3999. struct iwl3945_channel_info *ch_info;
  4000. if (priv->channel_count) {
  4001. IWL_DEBUG_INFO("Channel map already initialized.\n");
  4002. return 0;
  4003. }
  4004. if (priv->eeprom.version < 0x2f) {
  4005. IWL_WARNING("Unsupported EEPROM version: 0x%04X\n",
  4006. priv->eeprom.version);
  4007. return -EINVAL;
  4008. }
  4009. IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n");
  4010. priv->channel_count =
  4011. ARRAY_SIZE(iwl3945_eeprom_band_1) +
  4012. ARRAY_SIZE(iwl3945_eeprom_band_2) +
  4013. ARRAY_SIZE(iwl3945_eeprom_band_3) +
  4014. ARRAY_SIZE(iwl3945_eeprom_band_4) +
  4015. ARRAY_SIZE(iwl3945_eeprom_band_5);
  4016. IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count);
  4017. priv->channel_info = kzalloc(sizeof(struct iwl3945_channel_info) *
  4018. priv->channel_count, GFP_KERNEL);
  4019. if (!priv->channel_info) {
  4020. IWL_ERROR("Could not allocate channel_info\n");
  4021. priv->channel_count = 0;
  4022. return -ENOMEM;
  4023. }
  4024. ch_info = priv->channel_info;
  4025. /* Loop through the 5 EEPROM bands adding them in order to the
  4026. * channel map we maintain (that contains additional information than
  4027. * what just in the EEPROM) */
  4028. for (band = 1; band <= 5; band++) {
  4029. iwl3945_init_band_reference(priv, band, &eeprom_ch_count,
  4030. &eeprom_ch_info, &eeprom_ch_index);
  4031. /* Loop through each band adding each of the channels */
  4032. for (ch = 0; ch < eeprom_ch_count; ch++) {
  4033. ch_info->channel = eeprom_ch_index[ch];
  4034. ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ :
  4035. IEEE80211_BAND_5GHZ;
  4036. /* permanently store EEPROM's channel regulatory flags
  4037. * and max power in channel info database. */
  4038. ch_info->eeprom = eeprom_ch_info[ch];
  4039. /* Copy the run-time flags so they are there even on
  4040. * invalid channels */
  4041. ch_info->flags = eeprom_ch_info[ch].flags;
  4042. if (!(is_channel_valid(ch_info))) {
  4043. IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - "
  4044. "No traffic\n",
  4045. ch_info->channel,
  4046. ch_info->flags,
  4047. is_channel_a_band(ch_info) ?
  4048. "5.2" : "2.4");
  4049. ch_info++;
  4050. continue;
  4051. }
  4052. /* Initialize regulatory-based run-time data */
  4053. ch_info->max_power_avg = ch_info->curr_txpow =
  4054. eeprom_ch_info[ch].max_power_avg;
  4055. ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
  4056. ch_info->min_power = 0;
  4057. IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s%s(0x%02x"
  4058. " %ddBm): Ad-Hoc %ssupported\n",
  4059. ch_info->channel,
  4060. is_channel_a_band(ch_info) ?
  4061. "5.2" : "2.4",
  4062. CHECK_AND_PRINT(VALID),
  4063. CHECK_AND_PRINT(IBSS),
  4064. CHECK_AND_PRINT(ACTIVE),
  4065. CHECK_AND_PRINT(RADAR),
  4066. CHECK_AND_PRINT(WIDE),
  4067. CHECK_AND_PRINT(NARROW),
  4068. CHECK_AND_PRINT(DFS),
  4069. eeprom_ch_info[ch].flags,
  4070. eeprom_ch_info[ch].max_power_avg,
  4071. ((eeprom_ch_info[ch].
  4072. flags & EEPROM_CHANNEL_IBSS)
  4073. && !(eeprom_ch_info[ch].
  4074. flags & EEPROM_CHANNEL_RADAR))
  4075. ? "" : "not ");
  4076. /* Set the user_txpower_limit to the highest power
  4077. * supported by any channel */
  4078. if (eeprom_ch_info[ch].max_power_avg >
  4079. priv->user_txpower_limit)
  4080. priv->user_txpower_limit =
  4081. eeprom_ch_info[ch].max_power_avg;
  4082. ch_info++;
  4083. }
  4084. }
  4085. /* Set up txpower settings in driver for all channels */
  4086. if (iwl3945_txpower_set_from_eeprom(priv))
  4087. return -EIO;
  4088. return 0;
  4089. }
  4090. /*
  4091. * iwl3945_free_channel_map - undo allocations in iwl3945_init_channel_map
  4092. */
  4093. static void iwl3945_free_channel_map(struct iwl3945_priv *priv)
  4094. {
  4095. kfree(priv->channel_info);
  4096. priv->channel_count = 0;
  4097. }
  4098. /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
  4099. * sending probe req. This should be set long enough to hear probe responses
  4100. * from more than one AP. */
  4101. #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
  4102. #define IWL_ACTIVE_DWELL_TIME_52 (10)
  4103. /* For faster active scanning, scan will move to the next channel if fewer than
  4104. * PLCP_QUIET_THRESH packets are heard on this channel within
  4105. * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
  4106. * time if it's a quiet channel (nothing responded to our probe, and there's
  4107. * no other traffic).
  4108. * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
  4109. #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
  4110. #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
  4111. /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
  4112. * Must be set longer than active dwell time.
  4113. * For the most reliable scan, set > AP beacon interval (typically 100msec). */
  4114. #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
  4115. #define IWL_PASSIVE_DWELL_TIME_52 (10)
  4116. #define IWL_PASSIVE_DWELL_BASE (100)
  4117. #define IWL_CHANNEL_TUNE_TIME 5
  4118. static inline u16 iwl3945_get_active_dwell_time(struct iwl3945_priv *priv,
  4119. enum ieee80211_band band)
  4120. {
  4121. if (band == IEEE80211_BAND_5GHZ)
  4122. return IWL_ACTIVE_DWELL_TIME_52;
  4123. else
  4124. return IWL_ACTIVE_DWELL_TIME_24;
  4125. }
  4126. static u16 iwl3945_get_passive_dwell_time(struct iwl3945_priv *priv,
  4127. enum ieee80211_band band)
  4128. {
  4129. u16 active = iwl3945_get_active_dwell_time(priv, band);
  4130. u16 passive = (band == IEEE80211_BAND_2GHZ) ?
  4131. IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
  4132. IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
  4133. if (iwl3945_is_associated(priv)) {
  4134. /* If we're associated, we clamp the maximum passive
  4135. * dwell time to be 98% of the beacon interval (minus
  4136. * 2 * channel tune time) */
  4137. passive = priv->beacon_int;
  4138. if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive)
  4139. passive = IWL_PASSIVE_DWELL_BASE;
  4140. passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
  4141. }
  4142. if (passive <= active)
  4143. passive = active + 1;
  4144. return passive;
  4145. }
  4146. static int iwl3945_get_channels_for_scan(struct iwl3945_priv *priv,
  4147. enum ieee80211_band band,
  4148. u8 is_active, u8 direct_mask,
  4149. struct iwl3945_scan_channel *scan_ch)
  4150. {
  4151. const struct ieee80211_channel *channels = NULL;
  4152. const struct ieee80211_supported_band *sband;
  4153. const struct iwl3945_channel_info *ch_info;
  4154. u16 passive_dwell = 0;
  4155. u16 active_dwell = 0;
  4156. int added, i;
  4157. sband = iwl3945_get_band(priv, band);
  4158. if (!sband)
  4159. return 0;
  4160. channels = sband->channels;
  4161. active_dwell = iwl3945_get_active_dwell_time(priv, band);
  4162. passive_dwell = iwl3945_get_passive_dwell_time(priv, band);
  4163. for (i = 0, added = 0; i < sband->n_channels; i++) {
  4164. if (channels[i].hw_value ==
  4165. le16_to_cpu(priv->active_rxon.channel)) {
  4166. if (iwl3945_is_associated(priv)) {
  4167. IWL_DEBUG_SCAN
  4168. ("Skipping current channel %d\n",
  4169. le16_to_cpu(priv->active_rxon.channel));
  4170. continue;
  4171. }
  4172. } else if (priv->only_active_channel)
  4173. continue;
  4174. scan_ch->channel = channels[i].hw_value;
  4175. ch_info = iwl3945_get_channel_info(priv, band, scan_ch->channel);
  4176. if (!is_channel_valid(ch_info)) {
  4177. IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
  4178. scan_ch->channel);
  4179. continue;
  4180. }
  4181. if (!is_active || is_channel_passive(ch_info) ||
  4182. (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN))
  4183. scan_ch->type = 0; /* passive */
  4184. else
  4185. scan_ch->type = 1; /* active */
  4186. if (scan_ch->type & 1)
  4187. scan_ch->type |= (direct_mask << 1);
  4188. if (is_channel_narrow(ch_info))
  4189. scan_ch->type |= (1 << 7);
  4190. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  4191. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  4192. /* Set txpower levels to defaults */
  4193. scan_ch->tpc.dsp_atten = 110;
  4194. /* scan_pwr_info->tpc.dsp_atten; */
  4195. /*scan_pwr_info->tpc.tx_gain; */
  4196. if (band == IEEE80211_BAND_5GHZ)
  4197. scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
  4198. else {
  4199. scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
  4200. /* NOTE: if we were doing 6Mb OFDM for scans we'd use
  4201. * power level:
  4202. * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
  4203. */
  4204. }
  4205. IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
  4206. scan_ch->channel,
  4207. (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
  4208. (scan_ch->type & 1) ?
  4209. active_dwell : passive_dwell);
  4210. scan_ch++;
  4211. added++;
  4212. }
  4213. IWL_DEBUG_SCAN("total channels to scan %d \n", added);
  4214. return added;
  4215. }
  4216. static void iwl3945_init_hw_rates(struct iwl3945_priv *priv,
  4217. struct ieee80211_rate *rates)
  4218. {
  4219. int i;
  4220. for (i = 0; i < IWL_RATE_COUNT; i++) {
  4221. rates[i].bitrate = iwl3945_rates[i].ieee * 5;
  4222. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  4223. rates[i].hw_value_short = i;
  4224. rates[i].flags = 0;
  4225. if ((i > IWL_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
  4226. /*
  4227. * If CCK != 1M then set short preamble rate flag.
  4228. */
  4229. rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
  4230. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  4231. }
  4232. }
  4233. }
  4234. /**
  4235. * iwl3945_init_geos - Initialize mac80211's geo/channel info based from eeprom
  4236. */
  4237. static int iwl3945_init_geos(struct iwl3945_priv *priv)
  4238. {
  4239. struct iwl3945_channel_info *ch;
  4240. struct ieee80211_supported_band *sband;
  4241. struct ieee80211_channel *channels;
  4242. struct ieee80211_channel *geo_ch;
  4243. struct ieee80211_rate *rates;
  4244. int i = 0;
  4245. if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
  4246. priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
  4247. IWL_DEBUG_INFO("Geography modes already initialized.\n");
  4248. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  4249. return 0;
  4250. }
  4251. channels = kzalloc(sizeof(struct ieee80211_channel) *
  4252. priv->channel_count, GFP_KERNEL);
  4253. if (!channels)
  4254. return -ENOMEM;
  4255. rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)),
  4256. GFP_KERNEL);
  4257. if (!rates) {
  4258. kfree(channels);
  4259. return -ENOMEM;
  4260. }
  4261. /* 5.2GHz channels start after the 2.4GHz channels */
  4262. sband = &priv->bands[IEEE80211_BAND_5GHZ];
  4263. sband->channels = &channels[ARRAY_SIZE(iwl3945_eeprom_band_1)];
  4264. /* just OFDM */
  4265. sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
  4266. sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE;
  4267. sband = &priv->bands[IEEE80211_BAND_2GHZ];
  4268. sband->channels = channels;
  4269. /* OFDM & CCK */
  4270. sband->bitrates = rates;
  4271. sband->n_bitrates = IWL_RATE_COUNT;
  4272. priv->ieee_channels = channels;
  4273. priv->ieee_rates = rates;
  4274. iwl3945_init_hw_rates(priv, rates);
  4275. for (i = 0; i < priv->channel_count; i++) {
  4276. ch = &priv->channel_info[i];
  4277. /* FIXME: might be removed if scan is OK*/
  4278. if (!is_channel_valid(ch))
  4279. continue;
  4280. if (is_channel_a_band(ch))
  4281. sband = &priv->bands[IEEE80211_BAND_5GHZ];
  4282. else
  4283. sband = &priv->bands[IEEE80211_BAND_2GHZ];
  4284. geo_ch = &sband->channels[sband->n_channels++];
  4285. geo_ch->center_freq = ieee80211_channel_to_frequency(ch->channel);
  4286. geo_ch->max_power = ch->max_power_avg;
  4287. geo_ch->max_antenna_gain = 0xff;
  4288. geo_ch->hw_value = ch->channel;
  4289. if (is_channel_valid(ch)) {
  4290. if (!(ch->flags & EEPROM_CHANNEL_IBSS))
  4291. geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
  4292. if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
  4293. geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
  4294. if (ch->flags & EEPROM_CHANNEL_RADAR)
  4295. geo_ch->flags |= IEEE80211_CHAN_RADAR;
  4296. if (ch->max_power_avg > priv->max_channel_txpower_limit)
  4297. priv->max_channel_txpower_limit =
  4298. ch->max_power_avg;
  4299. } else {
  4300. geo_ch->flags |= IEEE80211_CHAN_DISABLED;
  4301. }
  4302. /* Save flags for reg domain usage */
  4303. geo_ch->orig_flags = geo_ch->flags;
  4304. IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n",
  4305. ch->channel, geo_ch->center_freq,
  4306. is_channel_a_band(ch) ? "5.2" : "2.4",
  4307. geo_ch->flags & IEEE80211_CHAN_DISABLED ?
  4308. "restricted" : "valid",
  4309. geo_ch->flags);
  4310. }
  4311. if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
  4312. priv->cfg->sku & IWL_SKU_A) {
  4313. printk(KERN_INFO DRV_NAME
  4314. ": Incorrectly detected BG card as ABG. Please send "
  4315. "your PCI ID 0x%04X:0x%04X to maintainer.\n",
  4316. priv->pci_dev->device, priv->pci_dev->subsystem_device);
  4317. priv->cfg->sku &= ~IWL_SKU_A;
  4318. }
  4319. printk(KERN_INFO DRV_NAME
  4320. ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
  4321. priv->bands[IEEE80211_BAND_2GHZ].n_channels,
  4322. priv->bands[IEEE80211_BAND_5GHZ].n_channels);
  4323. if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
  4324. priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  4325. &priv->bands[IEEE80211_BAND_2GHZ];
  4326. if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
  4327. priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  4328. &priv->bands[IEEE80211_BAND_5GHZ];
  4329. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  4330. return 0;
  4331. }
  4332. /*
  4333. * iwl3945_free_geos - undo allocations in iwl3945_init_geos
  4334. */
  4335. static void iwl3945_free_geos(struct iwl3945_priv *priv)
  4336. {
  4337. kfree(priv->ieee_channels);
  4338. kfree(priv->ieee_rates);
  4339. clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
  4340. }
  4341. /******************************************************************************
  4342. *
  4343. * uCode download functions
  4344. *
  4345. ******************************************************************************/
  4346. static void iwl3945_dealloc_ucode_pci(struct iwl3945_priv *priv)
  4347. {
  4348. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
  4349. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
  4350. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  4351. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
  4352. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  4353. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
  4354. }
  4355. /**
  4356. * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
  4357. * looking at all data.
  4358. */
  4359. static int iwl3945_verify_inst_full(struct iwl3945_priv *priv, __le32 * image, u32 len)
  4360. {
  4361. u32 val;
  4362. u32 save_len = len;
  4363. int rc = 0;
  4364. u32 errcnt;
  4365. IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
  4366. rc = iwl3945_grab_nic_access(priv);
  4367. if (rc)
  4368. return rc;
  4369. iwl3945_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND);
  4370. errcnt = 0;
  4371. for (; len > 0; len -= sizeof(u32), image++) {
  4372. /* read data comes through single port, auto-incr addr */
  4373. /* NOTE: Use the debugless read so we don't flood kernel log
  4374. * if IWL_DL_IO is set */
  4375. val = _iwl3945_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  4376. if (val != le32_to_cpu(*image)) {
  4377. IWL_ERROR("uCode INST section is invalid at "
  4378. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  4379. save_len - len, val, le32_to_cpu(*image));
  4380. rc = -EIO;
  4381. errcnt++;
  4382. if (errcnt >= 20)
  4383. break;
  4384. }
  4385. }
  4386. iwl3945_release_nic_access(priv);
  4387. if (!errcnt)
  4388. IWL_DEBUG_INFO("ucode image in INSTRUCTION memory is good\n");
  4389. return rc;
  4390. }
  4391. /**
  4392. * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
  4393. * using sample data 100 bytes apart. If these sample points are good,
  4394. * it's a pretty good bet that everything between them is good, too.
  4395. */
  4396. static int iwl3945_verify_inst_sparse(struct iwl3945_priv *priv, __le32 *image, u32 len)
  4397. {
  4398. u32 val;
  4399. int rc = 0;
  4400. u32 errcnt = 0;
  4401. u32 i;
  4402. IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
  4403. rc = iwl3945_grab_nic_access(priv);
  4404. if (rc)
  4405. return rc;
  4406. for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
  4407. /* read data comes through single port, auto-incr addr */
  4408. /* NOTE: Use the debugless read so we don't flood kernel log
  4409. * if IWL_DL_IO is set */
  4410. iwl3945_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  4411. i + RTC_INST_LOWER_BOUND);
  4412. val = _iwl3945_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  4413. if (val != le32_to_cpu(*image)) {
  4414. #if 0 /* Enable this if you want to see details */
  4415. IWL_ERROR("uCode INST section is invalid at "
  4416. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  4417. i, val, *image);
  4418. #endif
  4419. rc = -EIO;
  4420. errcnt++;
  4421. if (errcnt >= 3)
  4422. break;
  4423. }
  4424. }
  4425. iwl3945_release_nic_access(priv);
  4426. return rc;
  4427. }
  4428. /**
  4429. * iwl3945_verify_ucode - determine which instruction image is in SRAM,
  4430. * and verify its contents
  4431. */
  4432. static int iwl3945_verify_ucode(struct iwl3945_priv *priv)
  4433. {
  4434. __le32 *image;
  4435. u32 len;
  4436. int rc = 0;
  4437. /* Try bootstrap */
  4438. image = (__le32 *)priv->ucode_boot.v_addr;
  4439. len = priv->ucode_boot.len;
  4440. rc = iwl3945_verify_inst_sparse(priv, image, len);
  4441. if (rc == 0) {
  4442. IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
  4443. return 0;
  4444. }
  4445. /* Try initialize */
  4446. image = (__le32 *)priv->ucode_init.v_addr;
  4447. len = priv->ucode_init.len;
  4448. rc = iwl3945_verify_inst_sparse(priv, image, len);
  4449. if (rc == 0) {
  4450. IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
  4451. return 0;
  4452. }
  4453. /* Try runtime/protocol */
  4454. image = (__le32 *)priv->ucode_code.v_addr;
  4455. len = priv->ucode_code.len;
  4456. rc = iwl3945_verify_inst_sparse(priv, image, len);
  4457. if (rc == 0) {
  4458. IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
  4459. return 0;
  4460. }
  4461. IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
  4462. /* Since nothing seems to match, show first several data entries in
  4463. * instruction SRAM, so maybe visual inspection will give a clue.
  4464. * Selection of bootstrap image (vs. other images) is arbitrary. */
  4465. image = (__le32 *)priv->ucode_boot.v_addr;
  4466. len = priv->ucode_boot.len;
  4467. rc = iwl3945_verify_inst_full(priv, image, len);
  4468. return rc;
  4469. }
  4470. /* check contents of special bootstrap uCode SRAM */
  4471. static int iwl3945_verify_bsm(struct iwl3945_priv *priv)
  4472. {
  4473. __le32 *image = priv->ucode_boot.v_addr;
  4474. u32 len = priv->ucode_boot.len;
  4475. u32 reg;
  4476. u32 val;
  4477. IWL_DEBUG_INFO("Begin verify bsm\n");
  4478. /* verify BSM SRAM contents */
  4479. val = iwl3945_read_prph(priv, BSM_WR_DWCOUNT_REG);
  4480. for (reg = BSM_SRAM_LOWER_BOUND;
  4481. reg < BSM_SRAM_LOWER_BOUND + len;
  4482. reg += sizeof(u32), image ++) {
  4483. val = iwl3945_read_prph(priv, reg);
  4484. if (val != le32_to_cpu(*image)) {
  4485. IWL_ERROR("BSM uCode verification failed at "
  4486. "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
  4487. BSM_SRAM_LOWER_BOUND,
  4488. reg - BSM_SRAM_LOWER_BOUND, len,
  4489. val, le32_to_cpu(*image));
  4490. return -EIO;
  4491. }
  4492. }
  4493. IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n");
  4494. return 0;
  4495. }
  4496. /**
  4497. * iwl3945_load_bsm - Load bootstrap instructions
  4498. *
  4499. * BSM operation:
  4500. *
  4501. * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
  4502. * in special SRAM that does not power down during RFKILL. When powering back
  4503. * up after power-saving sleeps (or during initial uCode load), the BSM loads
  4504. * the bootstrap program into the on-board processor, and starts it.
  4505. *
  4506. * The bootstrap program loads (via DMA) instructions and data for a new
  4507. * program from host DRAM locations indicated by the host driver in the
  4508. * BSM_DRAM_* registers. Once the new program is loaded, it starts
  4509. * automatically.
  4510. *
  4511. * When initializing the NIC, the host driver points the BSM to the
  4512. * "initialize" uCode image. This uCode sets up some internal data, then
  4513. * notifies host via "initialize alive" that it is complete.
  4514. *
  4515. * The host then replaces the BSM_DRAM_* pointer values to point to the
  4516. * normal runtime uCode instructions and a backup uCode data cache buffer
  4517. * (filled initially with starting data values for the on-board processor),
  4518. * then triggers the "initialize" uCode to load and launch the runtime uCode,
  4519. * which begins normal operation.
  4520. *
  4521. * When doing a power-save shutdown, runtime uCode saves data SRAM into
  4522. * the backup data cache in DRAM before SRAM is powered down.
  4523. *
  4524. * When powering back up, the BSM loads the bootstrap program. This reloads
  4525. * the runtime uCode instructions and the backup data cache into SRAM,
  4526. * and re-launches the runtime uCode from where it left off.
  4527. */
  4528. static int iwl3945_load_bsm(struct iwl3945_priv *priv)
  4529. {
  4530. __le32 *image = priv->ucode_boot.v_addr;
  4531. u32 len = priv->ucode_boot.len;
  4532. dma_addr_t pinst;
  4533. dma_addr_t pdata;
  4534. u32 inst_len;
  4535. u32 data_len;
  4536. int rc;
  4537. int i;
  4538. u32 done;
  4539. u32 reg_offset;
  4540. IWL_DEBUG_INFO("Begin load bsm\n");
  4541. /* make sure bootstrap program is no larger than BSM's SRAM size */
  4542. if (len > IWL_MAX_BSM_SIZE)
  4543. return -EINVAL;
  4544. /* Tell bootstrap uCode where to find the "Initialize" uCode
  4545. * in host DRAM ... host DRAM physical address bits 31:0 for 3945.
  4546. * NOTE: iwl3945_initialize_alive_start() will replace these values,
  4547. * after the "initialize" uCode has run, to point to
  4548. * runtime/protocol instructions and backup data cache. */
  4549. pinst = priv->ucode_init.p_addr;
  4550. pdata = priv->ucode_init_data.p_addr;
  4551. inst_len = priv->ucode_init.len;
  4552. data_len = priv->ucode_init_data.len;
  4553. rc = iwl3945_grab_nic_access(priv);
  4554. if (rc)
  4555. return rc;
  4556. iwl3945_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
  4557. iwl3945_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
  4558. iwl3945_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
  4559. iwl3945_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len);
  4560. /* Fill BSM memory with bootstrap instructions */
  4561. for (reg_offset = BSM_SRAM_LOWER_BOUND;
  4562. reg_offset < BSM_SRAM_LOWER_BOUND + len;
  4563. reg_offset += sizeof(u32), image++)
  4564. _iwl3945_write_prph(priv, reg_offset,
  4565. le32_to_cpu(*image));
  4566. rc = iwl3945_verify_bsm(priv);
  4567. if (rc) {
  4568. iwl3945_release_nic_access(priv);
  4569. return rc;
  4570. }
  4571. /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
  4572. iwl3945_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0);
  4573. iwl3945_write_prph(priv, BSM_WR_MEM_DST_REG,
  4574. RTC_INST_LOWER_BOUND);
  4575. iwl3945_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
  4576. /* Load bootstrap code into instruction SRAM now,
  4577. * to prepare to load "initialize" uCode */
  4578. iwl3945_write_prph(priv, BSM_WR_CTRL_REG,
  4579. BSM_WR_CTRL_REG_BIT_START);
  4580. /* Wait for load of bootstrap uCode to finish */
  4581. for (i = 0; i < 100; i++) {
  4582. done = iwl3945_read_prph(priv, BSM_WR_CTRL_REG);
  4583. if (!(done & BSM_WR_CTRL_REG_BIT_START))
  4584. break;
  4585. udelay(10);
  4586. }
  4587. if (i < 100)
  4588. IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i);
  4589. else {
  4590. IWL_ERROR("BSM write did not complete!\n");
  4591. return -EIO;
  4592. }
  4593. /* Enable future boot loads whenever power management unit triggers it
  4594. * (e.g. when powering back up after power-save shutdown) */
  4595. iwl3945_write_prph(priv, BSM_WR_CTRL_REG,
  4596. BSM_WR_CTRL_REG_BIT_START_EN);
  4597. iwl3945_release_nic_access(priv);
  4598. return 0;
  4599. }
  4600. static void iwl3945_nic_start(struct iwl3945_priv *priv)
  4601. {
  4602. /* Remove all resets to allow NIC to operate */
  4603. iwl3945_write32(priv, CSR_RESET, 0);
  4604. }
  4605. /**
  4606. * iwl3945_read_ucode - Read uCode images from disk file.
  4607. *
  4608. * Copy into buffers for card to fetch via bus-mastering
  4609. */
  4610. static int iwl3945_read_ucode(struct iwl3945_priv *priv)
  4611. {
  4612. struct iwl3945_ucode *ucode;
  4613. int ret = 0;
  4614. const struct firmware *ucode_raw;
  4615. /* firmware file name contains uCode/driver compatibility version */
  4616. const char *name = priv->cfg->fw_name;
  4617. u8 *src;
  4618. size_t len;
  4619. u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
  4620. /* Ask kernel firmware_class module to get the boot firmware off disk.
  4621. * request_firmware() is synchronous, file is in memory on return. */
  4622. ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
  4623. if (ret < 0) {
  4624. IWL_ERROR("%s firmware file req failed: Reason %d\n",
  4625. name, ret);
  4626. goto error;
  4627. }
  4628. IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
  4629. name, ucode_raw->size);
  4630. /* Make sure that we got at least our header! */
  4631. if (ucode_raw->size < sizeof(*ucode)) {
  4632. IWL_ERROR("File size way too small!\n");
  4633. ret = -EINVAL;
  4634. goto err_release;
  4635. }
  4636. /* Data from ucode file: header followed by uCode images */
  4637. ucode = (void *)ucode_raw->data;
  4638. ver = le32_to_cpu(ucode->ver);
  4639. inst_size = le32_to_cpu(ucode->inst_size);
  4640. data_size = le32_to_cpu(ucode->data_size);
  4641. init_size = le32_to_cpu(ucode->init_size);
  4642. init_data_size = le32_to_cpu(ucode->init_data_size);
  4643. boot_size = le32_to_cpu(ucode->boot_size);
  4644. IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver);
  4645. IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", inst_size);
  4646. IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", data_size);
  4647. IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", init_size);
  4648. IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", init_data_size);
  4649. IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", boot_size);
  4650. /* Verify size of file vs. image size info in file's header */
  4651. if (ucode_raw->size < sizeof(*ucode) +
  4652. inst_size + data_size + init_size +
  4653. init_data_size + boot_size) {
  4654. IWL_DEBUG_INFO("uCode file size %d too small\n",
  4655. (int)ucode_raw->size);
  4656. ret = -EINVAL;
  4657. goto err_release;
  4658. }
  4659. /* Verify that uCode images will fit in card's SRAM */
  4660. if (inst_size > IWL_MAX_INST_SIZE) {
  4661. IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
  4662. inst_size);
  4663. ret = -EINVAL;
  4664. goto err_release;
  4665. }
  4666. if (data_size > IWL_MAX_DATA_SIZE) {
  4667. IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
  4668. data_size);
  4669. ret = -EINVAL;
  4670. goto err_release;
  4671. }
  4672. if (init_size > IWL_MAX_INST_SIZE) {
  4673. IWL_DEBUG_INFO("uCode init instr len %d too large to fit in\n",
  4674. init_size);
  4675. ret = -EINVAL;
  4676. goto err_release;
  4677. }
  4678. if (init_data_size > IWL_MAX_DATA_SIZE) {
  4679. IWL_DEBUG_INFO("uCode init data len %d too large to fit in\n",
  4680. init_data_size);
  4681. ret = -EINVAL;
  4682. goto err_release;
  4683. }
  4684. if (boot_size > IWL_MAX_BSM_SIZE) {
  4685. IWL_DEBUG_INFO("uCode boot instr len %d too large to fit in\n",
  4686. boot_size);
  4687. ret = -EINVAL;
  4688. goto err_release;
  4689. }
  4690. /* Allocate ucode buffers for card's bus-master loading ... */
  4691. /* Runtime instructions and 2 copies of data:
  4692. * 1) unmodified from disk
  4693. * 2) backup cache for save/restore during power-downs */
  4694. priv->ucode_code.len = inst_size;
  4695. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
  4696. priv->ucode_data.len = data_size;
  4697. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
  4698. priv->ucode_data_backup.len = data_size;
  4699. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  4700. if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
  4701. !priv->ucode_data_backup.v_addr)
  4702. goto err_pci_alloc;
  4703. /* Initialization instructions and data */
  4704. if (init_size && init_data_size) {
  4705. priv->ucode_init.len = init_size;
  4706. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
  4707. priv->ucode_init_data.len = init_data_size;
  4708. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  4709. if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
  4710. goto err_pci_alloc;
  4711. }
  4712. /* Bootstrap (instructions only, no data) */
  4713. if (boot_size) {
  4714. priv->ucode_boot.len = boot_size;
  4715. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
  4716. if (!priv->ucode_boot.v_addr)
  4717. goto err_pci_alloc;
  4718. }
  4719. /* Copy images into buffers for card's bus-master reads ... */
  4720. /* Runtime instructions (first block of data in file) */
  4721. src = &ucode->data[0];
  4722. len = priv->ucode_code.len;
  4723. IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
  4724. memcpy(priv->ucode_code.v_addr, src, len);
  4725. IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
  4726. priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
  4727. /* Runtime data (2nd block)
  4728. * NOTE: Copy into backup buffer will be done in iwl3945_up() */
  4729. src = &ucode->data[inst_size];
  4730. len = priv->ucode_data.len;
  4731. IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
  4732. memcpy(priv->ucode_data.v_addr, src, len);
  4733. memcpy(priv->ucode_data_backup.v_addr, src, len);
  4734. /* Initialization instructions (3rd block) */
  4735. if (init_size) {
  4736. src = &ucode->data[inst_size + data_size];
  4737. len = priv->ucode_init.len;
  4738. IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
  4739. len);
  4740. memcpy(priv->ucode_init.v_addr, src, len);
  4741. }
  4742. /* Initialization data (4th block) */
  4743. if (init_data_size) {
  4744. src = &ucode->data[inst_size + data_size + init_size];
  4745. len = priv->ucode_init_data.len;
  4746. IWL_DEBUG_INFO("Copying (but not loading) init data len %d\n",
  4747. (int)len);
  4748. memcpy(priv->ucode_init_data.v_addr, src, len);
  4749. }
  4750. /* Bootstrap instructions (5th block) */
  4751. src = &ucode->data[inst_size + data_size + init_size + init_data_size];
  4752. len = priv->ucode_boot.len;
  4753. IWL_DEBUG_INFO("Copying (but not loading) boot instr len %d\n",
  4754. (int)len);
  4755. memcpy(priv->ucode_boot.v_addr, src, len);
  4756. /* We have our copies now, allow OS release its copies */
  4757. release_firmware(ucode_raw);
  4758. return 0;
  4759. err_pci_alloc:
  4760. IWL_ERROR("failed to allocate pci memory\n");
  4761. ret = -ENOMEM;
  4762. iwl3945_dealloc_ucode_pci(priv);
  4763. err_release:
  4764. release_firmware(ucode_raw);
  4765. error:
  4766. return ret;
  4767. }
  4768. /**
  4769. * iwl3945_set_ucode_ptrs - Set uCode address location
  4770. *
  4771. * Tell initialization uCode where to find runtime uCode.
  4772. *
  4773. * BSM registers initially contain pointers to initialization uCode.
  4774. * We need to replace them to load runtime uCode inst and data,
  4775. * and to save runtime data when powering down.
  4776. */
  4777. static int iwl3945_set_ucode_ptrs(struct iwl3945_priv *priv)
  4778. {
  4779. dma_addr_t pinst;
  4780. dma_addr_t pdata;
  4781. int rc = 0;
  4782. unsigned long flags;
  4783. /* bits 31:0 for 3945 */
  4784. pinst = priv->ucode_code.p_addr;
  4785. pdata = priv->ucode_data_backup.p_addr;
  4786. spin_lock_irqsave(&priv->lock, flags);
  4787. rc = iwl3945_grab_nic_access(priv);
  4788. if (rc) {
  4789. spin_unlock_irqrestore(&priv->lock, flags);
  4790. return rc;
  4791. }
  4792. /* Tell bootstrap uCode where to find image to load */
  4793. iwl3945_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
  4794. iwl3945_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
  4795. iwl3945_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
  4796. priv->ucode_data.len);
  4797. /* Inst bytecount must be last to set up, bit 31 signals uCode
  4798. * that all new ptr/size info is in place */
  4799. iwl3945_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
  4800. priv->ucode_code.len | BSM_DRAM_INST_LOAD);
  4801. iwl3945_release_nic_access(priv);
  4802. spin_unlock_irqrestore(&priv->lock, flags);
  4803. IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
  4804. return rc;
  4805. }
  4806. /**
  4807. * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
  4808. *
  4809. * Called after REPLY_ALIVE notification received from "initialize" uCode.
  4810. *
  4811. * Tell "initialize" uCode to go ahead and load the runtime uCode.
  4812. */
  4813. static void iwl3945_init_alive_start(struct iwl3945_priv *priv)
  4814. {
  4815. /* Check alive response for "valid" sign from uCode */
  4816. if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
  4817. /* We had an error bringing up the hardware, so take it
  4818. * all the way back down so we can try again */
  4819. IWL_DEBUG_INFO("Initialize Alive failed.\n");
  4820. goto restart;
  4821. }
  4822. /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
  4823. * This is a paranoid check, because we would not have gotten the
  4824. * "initialize" alive if code weren't properly loaded. */
  4825. if (iwl3945_verify_ucode(priv)) {
  4826. /* Runtime instruction load was bad;
  4827. * take it all the way back down so we can try again */
  4828. IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
  4829. goto restart;
  4830. }
  4831. /* Send pointers to protocol/runtime uCode image ... init code will
  4832. * load and launch runtime uCode, which will send us another "Alive"
  4833. * notification. */
  4834. IWL_DEBUG_INFO("Initialization Alive received.\n");
  4835. if (iwl3945_set_ucode_ptrs(priv)) {
  4836. /* Runtime instruction load won't happen;
  4837. * take it all the way back down so we can try again */
  4838. IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
  4839. goto restart;
  4840. }
  4841. return;
  4842. restart:
  4843. queue_work(priv->workqueue, &priv->restart);
  4844. }
  4845. /**
  4846. * iwl3945_alive_start - called after REPLY_ALIVE notification received
  4847. * from protocol/runtime uCode (initialization uCode's
  4848. * Alive gets handled by iwl3945_init_alive_start()).
  4849. */
  4850. static void iwl3945_alive_start(struct iwl3945_priv *priv)
  4851. {
  4852. int rc = 0;
  4853. int thermal_spin = 0;
  4854. u32 rfkill;
  4855. IWL_DEBUG_INFO("Runtime Alive received.\n");
  4856. if (priv->card_alive.is_valid != UCODE_VALID_OK) {
  4857. /* We had an error bringing up the hardware, so take it
  4858. * all the way back down so we can try again */
  4859. IWL_DEBUG_INFO("Alive failed.\n");
  4860. goto restart;
  4861. }
  4862. /* Initialize uCode has loaded Runtime uCode ... verify inst image.
  4863. * This is a paranoid check, because we would not have gotten the
  4864. * "runtime" alive if code weren't properly loaded. */
  4865. if (iwl3945_verify_ucode(priv)) {
  4866. /* Runtime instruction load was bad;
  4867. * take it all the way back down so we can try again */
  4868. IWL_DEBUG_INFO("Bad runtime uCode load.\n");
  4869. goto restart;
  4870. }
  4871. iwl3945_clear_stations_table(priv);
  4872. rc = iwl3945_grab_nic_access(priv);
  4873. if (rc) {
  4874. IWL_WARNING("Can not read rfkill status from adapter\n");
  4875. return;
  4876. }
  4877. rfkill = iwl3945_read_prph(priv, APMG_RFKILL_REG);
  4878. IWL_DEBUG_INFO("RFKILL status: 0x%x\n", rfkill);
  4879. iwl3945_release_nic_access(priv);
  4880. if (rfkill & 0x1) {
  4881. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  4882. /* if rfkill is not on, then wait for thermal
  4883. * sensor in adapter to kick in */
  4884. while (iwl3945_hw_get_temperature(priv) == 0) {
  4885. thermal_spin++;
  4886. udelay(10);
  4887. }
  4888. if (thermal_spin)
  4889. IWL_DEBUG_INFO("Thermal calibration took %dus\n",
  4890. thermal_spin * 10);
  4891. } else
  4892. set_bit(STATUS_RF_KILL_HW, &priv->status);
  4893. /* After the ALIVE response, we can send commands to 3945 uCode */
  4894. set_bit(STATUS_ALIVE, &priv->status);
  4895. /* Clear out the uCode error bit if it is set */
  4896. clear_bit(STATUS_FW_ERROR, &priv->status);
  4897. if (iwl3945_is_rfkill(priv))
  4898. return;
  4899. ieee80211_start_queues(priv->hw);
  4900. priv->active_rate = priv->rates_mask;
  4901. priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
  4902. iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode));
  4903. if (iwl3945_is_associated(priv)) {
  4904. struct iwl3945_rxon_cmd *active_rxon =
  4905. (struct iwl3945_rxon_cmd *)(&priv->active_rxon);
  4906. memcpy(&priv->staging_rxon, &priv->active_rxon,
  4907. sizeof(priv->staging_rxon));
  4908. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  4909. } else {
  4910. /* Initialize our rx_config data */
  4911. iwl3945_connection_init_rx_config(priv);
  4912. memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  4913. }
  4914. /* Configure Bluetooth device coexistence support */
  4915. iwl3945_send_bt_config(priv);
  4916. /* Configure the adapter for unassociated operation */
  4917. iwl3945_commit_rxon(priv);
  4918. /* At this point, the NIC is initialized and operational */
  4919. priv->notif_missed_beacons = 0;
  4920. iwl3945_reg_txpower_periodic(priv);
  4921. IWL_DEBUG_INFO("ALIVE processing complete.\n");
  4922. set_bit(STATUS_READY, &priv->status);
  4923. wake_up_interruptible(&priv->wait_command_queue);
  4924. iwl3945_led_register(priv);
  4925. if (priv->error_recovering)
  4926. iwl3945_error_recovery(priv);
  4927. return;
  4928. restart:
  4929. queue_work(priv->workqueue, &priv->restart);
  4930. }
  4931. static void iwl3945_cancel_deferred_work(struct iwl3945_priv *priv);
  4932. static void __iwl3945_down(struct iwl3945_priv *priv)
  4933. {
  4934. unsigned long flags;
  4935. int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
  4936. struct ieee80211_conf *conf = NULL;
  4937. IWL_DEBUG_INFO(DRV_NAME " is going down\n");
  4938. conf = ieee80211_get_hw_conf(priv->hw);
  4939. if (!exit_pending)
  4940. set_bit(STATUS_EXIT_PENDING, &priv->status);
  4941. iwl3945_led_unregister(priv);
  4942. iwl3945_clear_stations_table(priv);
  4943. /* Unblock any waiting calls */
  4944. wake_up_interruptible_all(&priv->wait_command_queue);
  4945. /* Wipe out the EXIT_PENDING status bit if we are not actually
  4946. * exiting the module */
  4947. if (!exit_pending)
  4948. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  4949. /* stop and reset the on-board processor */
  4950. iwl3945_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  4951. /* tell the device to stop sending interrupts */
  4952. iwl3945_disable_interrupts(priv);
  4953. if (priv->mac80211_registered)
  4954. ieee80211_stop_queues(priv->hw);
  4955. /* If we have not previously called iwl3945_init() then
  4956. * clear all bits but the RF Kill and SUSPEND bits and return */
  4957. if (!iwl3945_is_init(priv)) {
  4958. priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  4959. STATUS_RF_KILL_HW |
  4960. test_bit(STATUS_RF_KILL_SW, &priv->status) <<
  4961. STATUS_RF_KILL_SW |
  4962. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  4963. STATUS_GEO_CONFIGURED |
  4964. test_bit(STATUS_IN_SUSPEND, &priv->status) <<
  4965. STATUS_IN_SUSPEND;
  4966. goto exit;
  4967. }
  4968. /* ...otherwise clear out all the status bits but the RF Kill and
  4969. * SUSPEND bits and continue taking the NIC down. */
  4970. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  4971. STATUS_RF_KILL_HW |
  4972. test_bit(STATUS_RF_KILL_SW, &priv->status) <<
  4973. STATUS_RF_KILL_SW |
  4974. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  4975. STATUS_GEO_CONFIGURED |
  4976. test_bit(STATUS_IN_SUSPEND, &priv->status) <<
  4977. STATUS_IN_SUSPEND |
  4978. test_bit(STATUS_FW_ERROR, &priv->status) <<
  4979. STATUS_FW_ERROR;
  4980. spin_lock_irqsave(&priv->lock, flags);
  4981. iwl3945_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  4982. spin_unlock_irqrestore(&priv->lock, flags);
  4983. iwl3945_hw_txq_ctx_stop(priv);
  4984. iwl3945_hw_rxq_stop(priv);
  4985. spin_lock_irqsave(&priv->lock, flags);
  4986. if (!iwl3945_grab_nic_access(priv)) {
  4987. iwl3945_write_prph(priv, APMG_CLK_DIS_REG,
  4988. APMG_CLK_VAL_DMA_CLK_RQT);
  4989. iwl3945_release_nic_access(priv);
  4990. }
  4991. spin_unlock_irqrestore(&priv->lock, flags);
  4992. udelay(5);
  4993. iwl3945_hw_nic_stop_master(priv);
  4994. iwl3945_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  4995. iwl3945_hw_nic_reset(priv);
  4996. exit:
  4997. memset(&priv->card_alive, 0, sizeof(struct iwl3945_alive_resp));
  4998. if (priv->ibss_beacon)
  4999. dev_kfree_skb(priv->ibss_beacon);
  5000. priv->ibss_beacon = NULL;
  5001. /* clear out any free frames */
  5002. iwl3945_clear_free_frames(priv);
  5003. }
  5004. static void iwl3945_down(struct iwl3945_priv *priv)
  5005. {
  5006. mutex_lock(&priv->mutex);
  5007. __iwl3945_down(priv);
  5008. mutex_unlock(&priv->mutex);
  5009. iwl3945_cancel_deferred_work(priv);
  5010. }
  5011. #define MAX_HW_RESTARTS 5
  5012. static int __iwl3945_up(struct iwl3945_priv *priv)
  5013. {
  5014. int rc, i;
  5015. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  5016. IWL_WARNING("Exit pending; will not bring the NIC up\n");
  5017. return -EIO;
  5018. }
  5019. if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
  5020. IWL_WARNING("Radio disabled by SW RF kill (module "
  5021. "parameter)\n");
  5022. return -ENODEV;
  5023. }
  5024. if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
  5025. IWL_ERROR("ucode not available for device bringup\n");
  5026. return -EIO;
  5027. }
  5028. /* If platform's RF_KILL switch is NOT set to KILL */
  5029. if (iwl3945_read32(priv, CSR_GP_CNTRL) &
  5030. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  5031. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  5032. else {
  5033. set_bit(STATUS_RF_KILL_HW, &priv->status);
  5034. if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
  5035. IWL_WARNING("Radio disabled by HW RF Kill switch\n");
  5036. return -ENODEV;
  5037. }
  5038. }
  5039. iwl3945_write32(priv, CSR_INT, 0xFFFFFFFF);
  5040. rc = iwl3945_hw_nic_init(priv);
  5041. if (rc) {
  5042. IWL_ERROR("Unable to int nic\n");
  5043. return rc;
  5044. }
  5045. /* make sure rfkill handshake bits are cleared */
  5046. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  5047. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  5048. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  5049. /* clear (again), then enable host interrupts */
  5050. iwl3945_write32(priv, CSR_INT, 0xFFFFFFFF);
  5051. iwl3945_enable_interrupts(priv);
  5052. /* really make sure rfkill handshake bits are cleared */
  5053. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  5054. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  5055. /* Copy original ucode data image from disk into backup cache.
  5056. * This will be used to initialize the on-board processor's
  5057. * data SRAM for a clean start when the runtime program first loads. */
  5058. memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
  5059. priv->ucode_data.len);
  5060. /* We return success when we resume from suspend and rf_kill is on. */
  5061. if (test_bit(STATUS_RF_KILL_HW, &priv->status))
  5062. return 0;
  5063. for (i = 0; i < MAX_HW_RESTARTS; i++) {
  5064. iwl3945_clear_stations_table(priv);
  5065. /* load bootstrap state machine,
  5066. * load bootstrap program into processor's memory,
  5067. * prepare to load the "initialize" uCode */
  5068. rc = iwl3945_load_bsm(priv);
  5069. if (rc) {
  5070. IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc);
  5071. continue;
  5072. }
  5073. /* start card; "initialize" will load runtime ucode */
  5074. iwl3945_nic_start(priv);
  5075. IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
  5076. return 0;
  5077. }
  5078. set_bit(STATUS_EXIT_PENDING, &priv->status);
  5079. __iwl3945_down(priv);
  5080. /* tried to restart and config the device for as long as our
  5081. * patience could withstand */
  5082. IWL_ERROR("Unable to initialize device after %d attempts.\n", i);
  5083. return -EIO;
  5084. }
  5085. /*****************************************************************************
  5086. *
  5087. * Workqueue callbacks
  5088. *
  5089. *****************************************************************************/
  5090. static void iwl3945_bg_init_alive_start(struct work_struct *data)
  5091. {
  5092. struct iwl3945_priv *priv =
  5093. container_of(data, struct iwl3945_priv, init_alive_start.work);
  5094. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5095. return;
  5096. mutex_lock(&priv->mutex);
  5097. iwl3945_init_alive_start(priv);
  5098. mutex_unlock(&priv->mutex);
  5099. }
  5100. static void iwl3945_bg_alive_start(struct work_struct *data)
  5101. {
  5102. struct iwl3945_priv *priv =
  5103. container_of(data, struct iwl3945_priv, alive_start.work);
  5104. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5105. return;
  5106. mutex_lock(&priv->mutex);
  5107. iwl3945_alive_start(priv);
  5108. mutex_unlock(&priv->mutex);
  5109. }
  5110. static void iwl3945_bg_rf_kill(struct work_struct *work)
  5111. {
  5112. struct iwl3945_priv *priv = container_of(work, struct iwl3945_priv, rf_kill);
  5113. wake_up_interruptible(&priv->wait_command_queue);
  5114. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5115. return;
  5116. mutex_lock(&priv->mutex);
  5117. if (!iwl3945_is_rfkill(priv)) {
  5118. IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL,
  5119. "HW and/or SW RF Kill no longer active, restarting "
  5120. "device\n");
  5121. if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
  5122. queue_work(priv->workqueue, &priv->restart);
  5123. } else {
  5124. if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
  5125. IWL_DEBUG_RF_KILL("Can not turn radio back on - "
  5126. "disabled by SW switch\n");
  5127. else
  5128. IWL_WARNING("Radio Frequency Kill Switch is On:\n"
  5129. "Kill switch must be turned off for "
  5130. "wireless networking to work.\n");
  5131. }
  5132. mutex_unlock(&priv->mutex);
  5133. }
  5134. #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
  5135. static void iwl3945_bg_scan_check(struct work_struct *data)
  5136. {
  5137. struct iwl3945_priv *priv =
  5138. container_of(data, struct iwl3945_priv, scan_check.work);
  5139. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5140. return;
  5141. mutex_lock(&priv->mutex);
  5142. if (test_bit(STATUS_SCANNING, &priv->status) ||
  5143. test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  5144. IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN,
  5145. "Scan completion watchdog resetting adapter (%dms)\n",
  5146. jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG));
  5147. if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
  5148. iwl3945_send_scan_abort(priv);
  5149. }
  5150. mutex_unlock(&priv->mutex);
  5151. }
  5152. static void iwl3945_bg_request_scan(struct work_struct *data)
  5153. {
  5154. struct iwl3945_priv *priv =
  5155. container_of(data, struct iwl3945_priv, request_scan);
  5156. struct iwl3945_host_cmd cmd = {
  5157. .id = REPLY_SCAN_CMD,
  5158. .len = sizeof(struct iwl3945_scan_cmd),
  5159. .meta.flags = CMD_SIZE_HUGE,
  5160. };
  5161. int rc = 0;
  5162. struct iwl3945_scan_cmd *scan;
  5163. struct ieee80211_conf *conf = NULL;
  5164. u8 direct_mask;
  5165. enum ieee80211_band band;
  5166. conf = ieee80211_get_hw_conf(priv->hw);
  5167. mutex_lock(&priv->mutex);
  5168. if (!iwl3945_is_ready(priv)) {
  5169. IWL_WARNING("request scan called when driver not ready.\n");
  5170. goto done;
  5171. }
  5172. /* Make sure the scan wasn't cancelled before this queued work
  5173. * was given the chance to run... */
  5174. if (!test_bit(STATUS_SCANNING, &priv->status))
  5175. goto done;
  5176. /* This should never be called or scheduled if there is currently
  5177. * a scan active in the hardware. */
  5178. if (test_bit(STATUS_SCAN_HW, &priv->status)) {
  5179. IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
  5180. "Ignoring second request.\n");
  5181. rc = -EIO;
  5182. goto done;
  5183. }
  5184. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  5185. IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
  5186. goto done;
  5187. }
  5188. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  5189. IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
  5190. goto done;
  5191. }
  5192. if (iwl3945_is_rfkill(priv)) {
  5193. IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
  5194. goto done;
  5195. }
  5196. if (!test_bit(STATUS_READY, &priv->status)) {
  5197. IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
  5198. goto done;
  5199. }
  5200. if (!priv->scan_bands) {
  5201. IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
  5202. goto done;
  5203. }
  5204. if (!priv->scan) {
  5205. priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
  5206. IWL_MAX_SCAN_SIZE, GFP_KERNEL);
  5207. if (!priv->scan) {
  5208. rc = -ENOMEM;
  5209. goto done;
  5210. }
  5211. }
  5212. scan = priv->scan;
  5213. memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
  5214. scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
  5215. scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
  5216. if (iwl3945_is_associated(priv)) {
  5217. u16 interval = 0;
  5218. u32 extra;
  5219. u32 suspend_time = 100;
  5220. u32 scan_suspend_time = 100;
  5221. unsigned long flags;
  5222. IWL_DEBUG_INFO("Scanning while associated...\n");
  5223. spin_lock_irqsave(&priv->lock, flags);
  5224. interval = priv->beacon_int;
  5225. spin_unlock_irqrestore(&priv->lock, flags);
  5226. scan->suspend_time = 0;
  5227. scan->max_out_time = cpu_to_le32(200 * 1024);
  5228. if (!interval)
  5229. interval = suspend_time;
  5230. /*
  5231. * suspend time format:
  5232. * 0-19: beacon interval in usec (time before exec.)
  5233. * 20-23: 0
  5234. * 24-31: number of beacons (suspend between channels)
  5235. */
  5236. extra = (suspend_time / interval) << 24;
  5237. scan_suspend_time = 0xFF0FFFFF &
  5238. (extra | ((suspend_time % interval) * 1024));
  5239. scan->suspend_time = cpu_to_le32(scan_suspend_time);
  5240. IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
  5241. scan_suspend_time, interval);
  5242. }
  5243. /* We should add the ability for user to lock to PASSIVE ONLY */
  5244. if (priv->one_direct_scan) {
  5245. IWL_DEBUG_SCAN
  5246. ("Kicking off one direct scan for '%s'\n",
  5247. iwl3945_escape_essid(priv->direct_ssid,
  5248. priv->direct_ssid_len));
  5249. scan->direct_scan[0].id = WLAN_EID_SSID;
  5250. scan->direct_scan[0].len = priv->direct_ssid_len;
  5251. memcpy(scan->direct_scan[0].ssid,
  5252. priv->direct_ssid, priv->direct_ssid_len);
  5253. direct_mask = 1;
  5254. } else if (!iwl3945_is_associated(priv) && priv->essid_len) {
  5255. scan->direct_scan[0].id = WLAN_EID_SSID;
  5256. scan->direct_scan[0].len = priv->essid_len;
  5257. memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
  5258. direct_mask = 1;
  5259. } else
  5260. direct_mask = 0;
  5261. /* We don't build a direct scan probe request; the uCode will do
  5262. * that based on the direct_mask added to each channel entry */
  5263. scan->tx_cmd.len = cpu_to_le16(
  5264. iwl3945_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data,
  5265. IWL_MAX_SCAN_SIZE - sizeof(*scan), 0));
  5266. scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
  5267. scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id;
  5268. scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  5269. /* flags + rate selection */
  5270. switch (priv->scan_bands) {
  5271. case 2:
  5272. scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
  5273. scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
  5274. scan->good_CRC_th = 0;
  5275. band = IEEE80211_BAND_2GHZ;
  5276. break;
  5277. case 1:
  5278. scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
  5279. scan->good_CRC_th = IWL_GOOD_CRC_TH;
  5280. band = IEEE80211_BAND_5GHZ;
  5281. break;
  5282. default:
  5283. IWL_WARNING("Invalid scan band count\n");
  5284. goto done;
  5285. }
  5286. /* select Rx antennas */
  5287. scan->flags |= iwl3945_get_antenna_flags(priv);
  5288. if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR)
  5289. scan->filter_flags = RXON_FILTER_PROMISC_MSK;
  5290. if (direct_mask) {
  5291. IWL_DEBUG_SCAN
  5292. ("Initiating direct scan for %s.\n",
  5293. iwl3945_escape_essid(priv->essid, priv->essid_len));
  5294. scan->channel_count =
  5295. iwl3945_get_channels_for_scan(
  5296. priv, band, 1, /* active */
  5297. direct_mask,
  5298. (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
  5299. } else {
  5300. IWL_DEBUG_SCAN("Initiating indirect scan.\n");
  5301. scan->channel_count =
  5302. iwl3945_get_channels_for_scan(
  5303. priv, band, 0, /* passive */
  5304. direct_mask,
  5305. (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
  5306. }
  5307. cmd.len += le16_to_cpu(scan->tx_cmd.len) +
  5308. scan->channel_count * sizeof(struct iwl3945_scan_channel);
  5309. cmd.data = scan;
  5310. scan->len = cpu_to_le16(cmd.len);
  5311. set_bit(STATUS_SCAN_HW, &priv->status);
  5312. rc = iwl3945_send_cmd_sync(priv, &cmd);
  5313. if (rc)
  5314. goto done;
  5315. queue_delayed_work(priv->workqueue, &priv->scan_check,
  5316. IWL_SCAN_CHECK_WATCHDOG);
  5317. mutex_unlock(&priv->mutex);
  5318. return;
  5319. done:
  5320. /* inform mac80211 scan aborted */
  5321. queue_work(priv->workqueue, &priv->scan_completed);
  5322. mutex_unlock(&priv->mutex);
  5323. }
  5324. static void iwl3945_bg_up(struct work_struct *data)
  5325. {
  5326. struct iwl3945_priv *priv = container_of(data, struct iwl3945_priv, up);
  5327. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5328. return;
  5329. mutex_lock(&priv->mutex);
  5330. __iwl3945_up(priv);
  5331. mutex_unlock(&priv->mutex);
  5332. }
  5333. static void iwl3945_bg_restart(struct work_struct *data)
  5334. {
  5335. struct iwl3945_priv *priv = container_of(data, struct iwl3945_priv, restart);
  5336. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5337. return;
  5338. iwl3945_down(priv);
  5339. queue_work(priv->workqueue, &priv->up);
  5340. }
  5341. static void iwl3945_bg_rx_replenish(struct work_struct *data)
  5342. {
  5343. struct iwl3945_priv *priv =
  5344. container_of(data, struct iwl3945_priv, rx_replenish);
  5345. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5346. return;
  5347. mutex_lock(&priv->mutex);
  5348. iwl3945_rx_replenish(priv);
  5349. mutex_unlock(&priv->mutex);
  5350. }
  5351. #define IWL_DELAY_NEXT_SCAN (HZ*2)
  5352. static void iwl3945_bg_post_associate(struct work_struct *data)
  5353. {
  5354. struct iwl3945_priv *priv = container_of(data, struct iwl3945_priv,
  5355. post_associate.work);
  5356. int rc = 0;
  5357. struct ieee80211_conf *conf = NULL;
  5358. DECLARE_MAC_BUF(mac);
  5359. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  5360. IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__);
  5361. return;
  5362. }
  5363. IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
  5364. priv->assoc_id,
  5365. print_mac(mac, priv->active_rxon.bssid_addr));
  5366. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5367. return;
  5368. mutex_lock(&priv->mutex);
  5369. if (!priv->vif || !priv->is_open) {
  5370. mutex_unlock(&priv->mutex);
  5371. return;
  5372. }
  5373. iwl3945_scan_cancel_timeout(priv, 200);
  5374. conf = ieee80211_get_hw_conf(priv->hw);
  5375. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  5376. iwl3945_commit_rxon(priv);
  5377. memset(&priv->rxon_timing, 0, sizeof(struct iwl3945_rxon_time_cmd));
  5378. iwl3945_setup_rxon_timing(priv);
  5379. rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING,
  5380. sizeof(priv->rxon_timing), &priv->rxon_timing);
  5381. if (rc)
  5382. IWL_WARNING("REPLY_RXON_TIMING failed - "
  5383. "Attempting to continue.\n");
  5384. priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  5385. priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
  5386. IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
  5387. priv->assoc_id, priv->beacon_int);
  5388. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  5389. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  5390. else
  5391. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  5392. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
  5393. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
  5394. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  5395. else
  5396. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  5397. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  5398. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  5399. }
  5400. iwl3945_commit_rxon(priv);
  5401. switch (priv->iw_mode) {
  5402. case IEEE80211_IF_TYPE_STA:
  5403. iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
  5404. break;
  5405. case IEEE80211_IF_TYPE_IBSS:
  5406. /* clear out the station table */
  5407. iwl3945_clear_stations_table(priv);
  5408. iwl3945_add_station(priv, iwl3945_broadcast_addr, 0, 0);
  5409. iwl3945_add_station(priv, priv->bssid, 0, 0);
  5410. iwl3945_sync_sta(priv, IWL_STA_ID,
  5411. (priv->band == IEEE80211_BAND_5GHZ) ?
  5412. IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
  5413. CMD_ASYNC);
  5414. iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
  5415. iwl3945_send_beacon_cmd(priv);
  5416. break;
  5417. default:
  5418. IWL_ERROR("%s Should not be called in %d mode\n",
  5419. __FUNCTION__, priv->iw_mode);
  5420. break;
  5421. }
  5422. iwl3945_sequence_reset(priv);
  5423. iwl3945_activate_qos(priv, 0);
  5424. /* we have just associated, don't start scan too early */
  5425. priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
  5426. mutex_unlock(&priv->mutex);
  5427. }
  5428. static void iwl3945_bg_abort_scan(struct work_struct *work)
  5429. {
  5430. struct iwl3945_priv *priv = container_of(work, struct iwl3945_priv, abort_scan);
  5431. if (!iwl3945_is_ready(priv))
  5432. return;
  5433. mutex_lock(&priv->mutex);
  5434. set_bit(STATUS_SCAN_ABORTING, &priv->status);
  5435. iwl3945_send_scan_abort(priv);
  5436. mutex_unlock(&priv->mutex);
  5437. }
  5438. static int iwl3945_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
  5439. static void iwl3945_bg_scan_completed(struct work_struct *work)
  5440. {
  5441. struct iwl3945_priv *priv =
  5442. container_of(work, struct iwl3945_priv, scan_completed);
  5443. IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n");
  5444. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5445. return;
  5446. if (test_bit(STATUS_CONF_PENDING, &priv->status))
  5447. iwl3945_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw));
  5448. ieee80211_scan_completed(priv->hw);
  5449. /* Since setting the TXPOWER may have been deferred while
  5450. * performing the scan, fire one off */
  5451. mutex_lock(&priv->mutex);
  5452. iwl3945_hw_reg_send_txpower(priv);
  5453. mutex_unlock(&priv->mutex);
  5454. }
  5455. /*****************************************************************************
  5456. *
  5457. * mac80211 entry point functions
  5458. *
  5459. *****************************************************************************/
  5460. #define UCODE_READY_TIMEOUT (2 * HZ)
  5461. static int iwl3945_mac_start(struct ieee80211_hw *hw)
  5462. {
  5463. struct iwl3945_priv *priv = hw->priv;
  5464. int ret;
  5465. IWL_DEBUG_MAC80211("enter\n");
  5466. if (pci_enable_device(priv->pci_dev)) {
  5467. IWL_ERROR("Fail to pci_enable_device\n");
  5468. return -ENODEV;
  5469. }
  5470. pci_restore_state(priv->pci_dev);
  5471. pci_enable_msi(priv->pci_dev);
  5472. ret = request_irq(priv->pci_dev->irq, iwl3945_isr, IRQF_SHARED,
  5473. DRV_NAME, priv);
  5474. if (ret) {
  5475. IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq);
  5476. goto out_disable_msi;
  5477. }
  5478. /* we should be verifying the device is ready to be opened */
  5479. mutex_lock(&priv->mutex);
  5480. memset(&priv->staging_rxon, 0, sizeof(struct iwl3945_rxon_cmd));
  5481. /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
  5482. * ucode filename and max sizes are card-specific. */
  5483. if (!priv->ucode_code.len) {
  5484. ret = iwl3945_read_ucode(priv);
  5485. if (ret) {
  5486. IWL_ERROR("Could not read microcode: %d\n", ret);
  5487. mutex_unlock(&priv->mutex);
  5488. goto out_release_irq;
  5489. }
  5490. }
  5491. ret = __iwl3945_up(priv);
  5492. mutex_unlock(&priv->mutex);
  5493. if (ret)
  5494. goto out_release_irq;
  5495. IWL_DEBUG_INFO("Start UP work.\n");
  5496. if (test_bit(STATUS_IN_SUSPEND, &priv->status))
  5497. return 0;
  5498. /* Wait for START_ALIVE from ucode. Otherwise callbacks from
  5499. * mac80211 will not be run successfully. */
  5500. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  5501. test_bit(STATUS_READY, &priv->status),
  5502. UCODE_READY_TIMEOUT);
  5503. if (!ret) {
  5504. if (!test_bit(STATUS_READY, &priv->status)) {
  5505. IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n",
  5506. jiffies_to_msecs(UCODE_READY_TIMEOUT));
  5507. ret = -ETIMEDOUT;
  5508. goto out_release_irq;
  5509. }
  5510. }
  5511. priv->is_open = 1;
  5512. IWL_DEBUG_MAC80211("leave\n");
  5513. return 0;
  5514. out_release_irq:
  5515. free_irq(priv->pci_dev->irq, priv);
  5516. out_disable_msi:
  5517. pci_disable_msi(priv->pci_dev);
  5518. pci_disable_device(priv->pci_dev);
  5519. priv->is_open = 0;
  5520. IWL_DEBUG_MAC80211("leave - failed\n");
  5521. return ret;
  5522. }
  5523. static void iwl3945_mac_stop(struct ieee80211_hw *hw)
  5524. {
  5525. struct iwl3945_priv *priv = hw->priv;
  5526. IWL_DEBUG_MAC80211("enter\n");
  5527. if (!priv->is_open) {
  5528. IWL_DEBUG_MAC80211("leave - skip\n");
  5529. return;
  5530. }
  5531. priv->is_open = 0;
  5532. if (iwl3945_is_ready_rf(priv)) {
  5533. /* stop mac, cancel any scan request and clear
  5534. * RXON_FILTER_ASSOC_MSK BIT
  5535. */
  5536. mutex_lock(&priv->mutex);
  5537. iwl3945_scan_cancel_timeout(priv, 100);
  5538. cancel_delayed_work(&priv->post_associate);
  5539. mutex_unlock(&priv->mutex);
  5540. }
  5541. iwl3945_down(priv);
  5542. flush_workqueue(priv->workqueue);
  5543. free_irq(priv->pci_dev->irq, priv);
  5544. pci_disable_msi(priv->pci_dev);
  5545. pci_save_state(priv->pci_dev);
  5546. pci_disable_device(priv->pci_dev);
  5547. IWL_DEBUG_MAC80211("leave\n");
  5548. }
  5549. static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
  5550. struct ieee80211_tx_control *ctl)
  5551. {
  5552. struct iwl3945_priv *priv = hw->priv;
  5553. IWL_DEBUG_MAC80211("enter\n");
  5554. if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
  5555. IWL_DEBUG_MAC80211("leave - monitor\n");
  5556. return -1;
  5557. }
  5558. IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  5559. ctl->tx_rate->bitrate);
  5560. if (iwl3945_tx_skb(priv, skb, ctl))
  5561. dev_kfree_skb_any(skb);
  5562. IWL_DEBUG_MAC80211("leave\n");
  5563. return 0;
  5564. }
  5565. static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
  5566. struct ieee80211_if_init_conf *conf)
  5567. {
  5568. struct iwl3945_priv *priv = hw->priv;
  5569. unsigned long flags;
  5570. DECLARE_MAC_BUF(mac);
  5571. IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
  5572. if (priv->vif) {
  5573. IWL_DEBUG_MAC80211("leave - vif != NULL\n");
  5574. return -EOPNOTSUPP;
  5575. }
  5576. spin_lock_irqsave(&priv->lock, flags);
  5577. priv->vif = conf->vif;
  5578. spin_unlock_irqrestore(&priv->lock, flags);
  5579. mutex_lock(&priv->mutex);
  5580. if (conf->mac_addr) {
  5581. IWL_DEBUG_MAC80211("Set: %s\n", print_mac(mac, conf->mac_addr));
  5582. memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
  5583. }
  5584. if (iwl3945_is_ready(priv))
  5585. iwl3945_set_mode(priv, conf->type);
  5586. mutex_unlock(&priv->mutex);
  5587. IWL_DEBUG_MAC80211("leave\n");
  5588. return 0;
  5589. }
  5590. /**
  5591. * iwl3945_mac_config - mac80211 config callback
  5592. *
  5593. * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
  5594. * be set inappropriately and the driver currently sets the hardware up to
  5595. * use it whenever needed.
  5596. */
  5597. static int iwl3945_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
  5598. {
  5599. struct iwl3945_priv *priv = hw->priv;
  5600. const struct iwl3945_channel_info *ch_info;
  5601. unsigned long flags;
  5602. int ret = 0;
  5603. mutex_lock(&priv->mutex);
  5604. IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
  5605. priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP);
  5606. if (!iwl3945_is_ready(priv)) {
  5607. IWL_DEBUG_MAC80211("leave - not ready\n");
  5608. ret = -EIO;
  5609. goto out;
  5610. }
  5611. if (unlikely(!iwl3945_param_disable_hw_scan &&
  5612. test_bit(STATUS_SCANNING, &priv->status))) {
  5613. IWL_DEBUG_MAC80211("leave - scanning\n");
  5614. set_bit(STATUS_CONF_PENDING, &priv->status);
  5615. mutex_unlock(&priv->mutex);
  5616. return 0;
  5617. }
  5618. spin_lock_irqsave(&priv->lock, flags);
  5619. ch_info = iwl3945_get_channel_info(priv, conf->channel->band,
  5620. conf->channel->hw_value);
  5621. if (!is_channel_valid(ch_info)) {
  5622. IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this SKU.\n",
  5623. conf->channel->hw_value, conf->channel->band);
  5624. IWL_DEBUG_MAC80211("leave - invalid channel\n");
  5625. spin_unlock_irqrestore(&priv->lock, flags);
  5626. ret = -EINVAL;
  5627. goto out;
  5628. }
  5629. iwl3945_set_rxon_channel(priv, conf->channel->band, conf->channel->hw_value);
  5630. iwl3945_set_flags_for_phymode(priv, conf->channel->band);
  5631. /* The list of supported rates and rate mask can be different
  5632. * for each phymode; since the phymode may have changed, reset
  5633. * the rate mask to what mac80211 lists */
  5634. iwl3945_set_rate(priv);
  5635. spin_unlock_irqrestore(&priv->lock, flags);
  5636. #ifdef IEEE80211_CONF_CHANNEL_SWITCH
  5637. if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
  5638. iwl3945_hw_channel_switch(priv, conf->channel);
  5639. goto out;
  5640. }
  5641. #endif
  5642. iwl3945_radio_kill_sw(priv, !conf->radio_enabled);
  5643. if (!conf->radio_enabled) {
  5644. IWL_DEBUG_MAC80211("leave - radio disabled\n");
  5645. goto out;
  5646. }
  5647. if (iwl3945_is_rfkill(priv)) {
  5648. IWL_DEBUG_MAC80211("leave - RF kill\n");
  5649. ret = -EIO;
  5650. goto out;
  5651. }
  5652. iwl3945_set_rate(priv);
  5653. if (memcmp(&priv->active_rxon,
  5654. &priv->staging_rxon, sizeof(priv->staging_rxon)))
  5655. iwl3945_commit_rxon(priv);
  5656. else
  5657. IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
  5658. IWL_DEBUG_MAC80211("leave\n");
  5659. out:
  5660. clear_bit(STATUS_CONF_PENDING, &priv->status);
  5661. mutex_unlock(&priv->mutex);
  5662. return ret;
  5663. }
  5664. static void iwl3945_config_ap(struct iwl3945_priv *priv)
  5665. {
  5666. int rc = 0;
  5667. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5668. return;
  5669. /* The following should be done only at AP bring up */
  5670. if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) {
  5671. /* RXON - unassoc (to set timing command) */
  5672. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  5673. iwl3945_commit_rxon(priv);
  5674. /* RXON Timing */
  5675. memset(&priv->rxon_timing, 0, sizeof(struct iwl3945_rxon_time_cmd));
  5676. iwl3945_setup_rxon_timing(priv);
  5677. rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING,
  5678. sizeof(priv->rxon_timing), &priv->rxon_timing);
  5679. if (rc)
  5680. IWL_WARNING("REPLY_RXON_TIMING failed - "
  5681. "Attempting to continue.\n");
  5682. /* FIXME: what should be the assoc_id for AP? */
  5683. priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
  5684. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  5685. priv->staging_rxon.flags |=
  5686. RXON_FLG_SHORT_PREAMBLE_MSK;
  5687. else
  5688. priv->staging_rxon.flags &=
  5689. ~RXON_FLG_SHORT_PREAMBLE_MSK;
  5690. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
  5691. if (priv->assoc_capability &
  5692. WLAN_CAPABILITY_SHORT_SLOT_TIME)
  5693. priv->staging_rxon.flags |=
  5694. RXON_FLG_SHORT_SLOT_MSK;
  5695. else
  5696. priv->staging_rxon.flags &=
  5697. ~RXON_FLG_SHORT_SLOT_MSK;
  5698. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  5699. priv->staging_rxon.flags &=
  5700. ~RXON_FLG_SHORT_SLOT_MSK;
  5701. }
  5702. /* restore RXON assoc */
  5703. priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  5704. iwl3945_commit_rxon(priv);
  5705. iwl3945_add_station(priv, iwl3945_broadcast_addr, 0, 0);
  5706. }
  5707. iwl3945_send_beacon_cmd(priv);
  5708. /* FIXME - we need to add code here to detect a totally new
  5709. * configuration, reset the AP, unassoc, rxon timing, assoc,
  5710. * clear sta table, add BCAST sta... */
  5711. }
  5712. static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
  5713. struct ieee80211_vif *vif,
  5714. struct ieee80211_if_conf *conf)
  5715. {
  5716. struct iwl3945_priv *priv = hw->priv;
  5717. DECLARE_MAC_BUF(mac);
  5718. unsigned long flags;
  5719. int rc;
  5720. if (conf == NULL)
  5721. return -EIO;
  5722. if (priv->vif != vif) {
  5723. IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
  5724. mutex_unlock(&priv->mutex);
  5725. return 0;
  5726. }
  5727. /* XXX: this MUST use conf->mac_addr */
  5728. if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
  5729. (!conf->beacon || !conf->ssid_len)) {
  5730. IWL_DEBUG_MAC80211
  5731. ("Leaving in AP mode because HostAPD is not ready.\n");
  5732. return 0;
  5733. }
  5734. if (!iwl3945_is_alive(priv))
  5735. return -EAGAIN;
  5736. mutex_lock(&priv->mutex);
  5737. if (conf->bssid)
  5738. IWL_DEBUG_MAC80211("bssid: %s\n",
  5739. print_mac(mac, conf->bssid));
  5740. /*
  5741. * very dubious code was here; the probe filtering flag is never set:
  5742. *
  5743. if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
  5744. !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
  5745. */
  5746. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  5747. if (!conf->bssid) {
  5748. conf->bssid = priv->mac_addr;
  5749. memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
  5750. IWL_DEBUG_MAC80211("bssid was set to: %s\n",
  5751. print_mac(mac, conf->bssid));
  5752. }
  5753. if (priv->ibss_beacon)
  5754. dev_kfree_skb(priv->ibss_beacon);
  5755. priv->ibss_beacon = conf->beacon;
  5756. }
  5757. if (iwl3945_is_rfkill(priv))
  5758. goto done;
  5759. if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
  5760. !is_multicast_ether_addr(conf->bssid)) {
  5761. /* If there is currently a HW scan going on in the background
  5762. * then we need to cancel it else the RXON below will fail. */
  5763. if (iwl3945_scan_cancel_timeout(priv, 100)) {
  5764. IWL_WARNING("Aborted scan still in progress "
  5765. "after 100ms\n");
  5766. IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
  5767. mutex_unlock(&priv->mutex);
  5768. return -EAGAIN;
  5769. }
  5770. memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
  5771. /* TODO: Audit driver for usage of these members and see
  5772. * if mac80211 deprecates them (priv->bssid looks like it
  5773. * shouldn't be there, but I haven't scanned the IBSS code
  5774. * to verify) - jpk */
  5775. memcpy(priv->bssid, conf->bssid, ETH_ALEN);
  5776. if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
  5777. iwl3945_config_ap(priv);
  5778. else {
  5779. rc = iwl3945_commit_rxon(priv);
  5780. if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc)
  5781. iwl3945_add_station(priv,
  5782. priv->active_rxon.bssid_addr, 1, 0);
  5783. }
  5784. } else {
  5785. iwl3945_scan_cancel_timeout(priv, 100);
  5786. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  5787. iwl3945_commit_rxon(priv);
  5788. }
  5789. done:
  5790. spin_lock_irqsave(&priv->lock, flags);
  5791. if (!conf->ssid_len)
  5792. memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
  5793. else
  5794. memcpy(priv->essid, conf->ssid, conf->ssid_len);
  5795. priv->essid_len = conf->ssid_len;
  5796. spin_unlock_irqrestore(&priv->lock, flags);
  5797. IWL_DEBUG_MAC80211("leave\n");
  5798. mutex_unlock(&priv->mutex);
  5799. return 0;
  5800. }
  5801. static void iwl3945_configure_filter(struct ieee80211_hw *hw,
  5802. unsigned int changed_flags,
  5803. unsigned int *total_flags,
  5804. int mc_count, struct dev_addr_list *mc_list)
  5805. {
  5806. /*
  5807. * XXX: dummy
  5808. * see also iwl3945_connection_init_rx_config
  5809. */
  5810. *total_flags = 0;
  5811. }
  5812. static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
  5813. struct ieee80211_if_init_conf *conf)
  5814. {
  5815. struct iwl3945_priv *priv = hw->priv;
  5816. IWL_DEBUG_MAC80211("enter\n");
  5817. mutex_lock(&priv->mutex);
  5818. if (iwl3945_is_ready_rf(priv)) {
  5819. iwl3945_scan_cancel_timeout(priv, 100);
  5820. cancel_delayed_work(&priv->post_associate);
  5821. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  5822. iwl3945_commit_rxon(priv);
  5823. }
  5824. if (priv->vif == conf->vif) {
  5825. priv->vif = NULL;
  5826. memset(priv->bssid, 0, ETH_ALEN);
  5827. memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
  5828. priv->essid_len = 0;
  5829. }
  5830. mutex_unlock(&priv->mutex);
  5831. IWL_DEBUG_MAC80211("leave\n");
  5832. }
  5833. static int iwl3945_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
  5834. {
  5835. int rc = 0;
  5836. unsigned long flags;
  5837. struct iwl3945_priv *priv = hw->priv;
  5838. IWL_DEBUG_MAC80211("enter\n");
  5839. mutex_lock(&priv->mutex);
  5840. spin_lock_irqsave(&priv->lock, flags);
  5841. if (!iwl3945_is_ready_rf(priv)) {
  5842. rc = -EIO;
  5843. IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
  5844. goto out_unlock;
  5845. }
  5846. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */
  5847. rc = -EIO;
  5848. IWL_ERROR("ERROR: APs don't scan\n");
  5849. goto out_unlock;
  5850. }
  5851. /* we don't schedule scan within next_scan_jiffies period */
  5852. if (priv->next_scan_jiffies &&
  5853. time_after(priv->next_scan_jiffies, jiffies)) {
  5854. rc = -EAGAIN;
  5855. goto out_unlock;
  5856. }
  5857. /* if we just finished scan ask for delay */
  5858. if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies +
  5859. IWL_DELAY_NEXT_SCAN, jiffies)) {
  5860. rc = -EAGAIN;
  5861. goto out_unlock;
  5862. }
  5863. if (len) {
  5864. IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
  5865. iwl3945_escape_essid(ssid, len), (int)len);
  5866. priv->one_direct_scan = 1;
  5867. priv->direct_ssid_len = (u8)
  5868. min((u8) len, (u8) IW_ESSID_MAX_SIZE);
  5869. memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
  5870. } else
  5871. priv->one_direct_scan = 0;
  5872. rc = iwl3945_scan_initiate(priv);
  5873. IWL_DEBUG_MAC80211("leave\n");
  5874. out_unlock:
  5875. spin_unlock_irqrestore(&priv->lock, flags);
  5876. mutex_unlock(&priv->mutex);
  5877. return rc;
  5878. }
  5879. static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  5880. const u8 *local_addr, const u8 *addr,
  5881. struct ieee80211_key_conf *key)
  5882. {
  5883. struct iwl3945_priv *priv = hw->priv;
  5884. int rc = 0;
  5885. u8 sta_id;
  5886. IWL_DEBUG_MAC80211("enter\n");
  5887. if (!iwl3945_param_hwcrypto) {
  5888. IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
  5889. return -EOPNOTSUPP;
  5890. }
  5891. if (is_zero_ether_addr(addr))
  5892. /* only support pairwise keys */
  5893. return -EOPNOTSUPP;
  5894. sta_id = iwl3945_hw_find_station(priv, addr);
  5895. if (sta_id == IWL_INVALID_STATION) {
  5896. DECLARE_MAC_BUF(mac);
  5897. IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
  5898. print_mac(mac, addr));
  5899. return -EINVAL;
  5900. }
  5901. mutex_lock(&priv->mutex);
  5902. iwl3945_scan_cancel_timeout(priv, 100);
  5903. switch (cmd) {
  5904. case SET_KEY:
  5905. rc = iwl3945_update_sta_key_info(priv, key, sta_id);
  5906. if (!rc) {
  5907. iwl3945_set_rxon_hwcrypto(priv, 1);
  5908. iwl3945_commit_rxon(priv);
  5909. key->hw_key_idx = sta_id;
  5910. IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n");
  5911. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  5912. }
  5913. break;
  5914. case DISABLE_KEY:
  5915. rc = iwl3945_clear_sta_key_info(priv, sta_id);
  5916. if (!rc) {
  5917. iwl3945_set_rxon_hwcrypto(priv, 0);
  5918. iwl3945_commit_rxon(priv);
  5919. IWL_DEBUG_MAC80211("disable hwcrypto key\n");
  5920. }
  5921. break;
  5922. default:
  5923. rc = -EINVAL;
  5924. }
  5925. IWL_DEBUG_MAC80211("leave\n");
  5926. mutex_unlock(&priv->mutex);
  5927. return rc;
  5928. }
  5929. static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, int queue,
  5930. const struct ieee80211_tx_queue_params *params)
  5931. {
  5932. struct iwl3945_priv *priv = hw->priv;
  5933. unsigned long flags;
  5934. int q;
  5935. IWL_DEBUG_MAC80211("enter\n");
  5936. if (!iwl3945_is_ready_rf(priv)) {
  5937. IWL_DEBUG_MAC80211("leave - RF not ready\n");
  5938. return -EIO;
  5939. }
  5940. if (queue >= AC_NUM) {
  5941. IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
  5942. return 0;
  5943. }
  5944. if (!priv->qos_data.qos_enable) {
  5945. priv->qos_data.qos_active = 0;
  5946. IWL_DEBUG_MAC80211("leave - qos not enabled\n");
  5947. return 0;
  5948. }
  5949. q = AC_NUM - 1 - queue;
  5950. spin_lock_irqsave(&priv->lock, flags);
  5951. priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
  5952. priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
  5953. priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
  5954. priv->qos_data.def_qos_parm.ac[q].edca_txop =
  5955. cpu_to_le16((params->txop * 32));
  5956. priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
  5957. priv->qos_data.qos_active = 1;
  5958. spin_unlock_irqrestore(&priv->lock, flags);
  5959. mutex_lock(&priv->mutex);
  5960. if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
  5961. iwl3945_activate_qos(priv, 1);
  5962. else if (priv->assoc_id && iwl3945_is_associated(priv))
  5963. iwl3945_activate_qos(priv, 0);
  5964. mutex_unlock(&priv->mutex);
  5965. IWL_DEBUG_MAC80211("leave\n");
  5966. return 0;
  5967. }
  5968. static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
  5969. struct ieee80211_tx_queue_stats *stats)
  5970. {
  5971. struct iwl3945_priv *priv = hw->priv;
  5972. int i, avail;
  5973. struct iwl3945_tx_queue *txq;
  5974. struct iwl3945_queue *q;
  5975. unsigned long flags;
  5976. IWL_DEBUG_MAC80211("enter\n");
  5977. if (!iwl3945_is_ready_rf(priv)) {
  5978. IWL_DEBUG_MAC80211("leave - RF not ready\n");
  5979. return -EIO;
  5980. }
  5981. spin_lock_irqsave(&priv->lock, flags);
  5982. for (i = 0; i < AC_NUM; i++) {
  5983. txq = &priv->txq[i];
  5984. q = &txq->q;
  5985. avail = iwl3945_queue_space(q);
  5986. stats->data[i].len = q->n_window - avail;
  5987. stats->data[i].limit = q->n_window - q->high_mark;
  5988. stats->data[i].count = q->n_window;
  5989. }
  5990. spin_unlock_irqrestore(&priv->lock, flags);
  5991. IWL_DEBUG_MAC80211("leave\n");
  5992. return 0;
  5993. }
  5994. static int iwl3945_mac_get_stats(struct ieee80211_hw *hw,
  5995. struct ieee80211_low_level_stats *stats)
  5996. {
  5997. IWL_DEBUG_MAC80211("enter\n");
  5998. IWL_DEBUG_MAC80211("leave\n");
  5999. return 0;
  6000. }
  6001. static u64 iwl3945_mac_get_tsf(struct ieee80211_hw *hw)
  6002. {
  6003. IWL_DEBUG_MAC80211("enter\n");
  6004. IWL_DEBUG_MAC80211("leave\n");
  6005. return 0;
  6006. }
  6007. static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
  6008. {
  6009. struct iwl3945_priv *priv = hw->priv;
  6010. unsigned long flags;
  6011. mutex_lock(&priv->mutex);
  6012. IWL_DEBUG_MAC80211("enter\n");
  6013. iwl3945_reset_qos(priv);
  6014. cancel_delayed_work(&priv->post_associate);
  6015. spin_lock_irqsave(&priv->lock, flags);
  6016. priv->assoc_id = 0;
  6017. priv->assoc_capability = 0;
  6018. priv->call_post_assoc_from_beacon = 0;
  6019. /* new association get rid of ibss beacon skb */
  6020. if (priv->ibss_beacon)
  6021. dev_kfree_skb(priv->ibss_beacon);
  6022. priv->ibss_beacon = NULL;
  6023. priv->beacon_int = priv->hw->conf.beacon_int;
  6024. priv->timestamp1 = 0;
  6025. priv->timestamp0 = 0;
  6026. if ((priv->iw_mode == IEEE80211_IF_TYPE_STA))
  6027. priv->beacon_int = 0;
  6028. spin_unlock_irqrestore(&priv->lock, flags);
  6029. if (!iwl3945_is_ready_rf(priv)) {
  6030. IWL_DEBUG_MAC80211("leave - not ready\n");
  6031. mutex_unlock(&priv->mutex);
  6032. return;
  6033. }
  6034. /* we are restarting association process
  6035. * clear RXON_FILTER_ASSOC_MSK bit
  6036. */
  6037. if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
  6038. iwl3945_scan_cancel_timeout(priv, 100);
  6039. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  6040. iwl3945_commit_rxon(priv);
  6041. }
  6042. /* Per mac80211.h: This is only used in IBSS mode... */
  6043. if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
  6044. IWL_DEBUG_MAC80211("leave - not in IBSS\n");
  6045. mutex_unlock(&priv->mutex);
  6046. return;
  6047. }
  6048. priv->only_active_channel = 0;
  6049. iwl3945_set_rate(priv);
  6050. mutex_unlock(&priv->mutex);
  6051. IWL_DEBUG_MAC80211("leave\n");
  6052. }
  6053. static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb,
  6054. struct ieee80211_tx_control *control)
  6055. {
  6056. struct iwl3945_priv *priv = hw->priv;
  6057. unsigned long flags;
  6058. mutex_lock(&priv->mutex);
  6059. IWL_DEBUG_MAC80211("enter\n");
  6060. if (!iwl3945_is_ready_rf(priv)) {
  6061. IWL_DEBUG_MAC80211("leave - RF not ready\n");
  6062. mutex_unlock(&priv->mutex);
  6063. return -EIO;
  6064. }
  6065. if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
  6066. IWL_DEBUG_MAC80211("leave - not IBSS\n");
  6067. mutex_unlock(&priv->mutex);
  6068. return -EIO;
  6069. }
  6070. spin_lock_irqsave(&priv->lock, flags);
  6071. if (priv->ibss_beacon)
  6072. dev_kfree_skb(priv->ibss_beacon);
  6073. priv->ibss_beacon = skb;
  6074. priv->assoc_id = 0;
  6075. IWL_DEBUG_MAC80211("leave\n");
  6076. spin_unlock_irqrestore(&priv->lock, flags);
  6077. iwl3945_reset_qos(priv);
  6078. queue_work(priv->workqueue, &priv->post_associate.work);
  6079. mutex_unlock(&priv->mutex);
  6080. return 0;
  6081. }
  6082. /*****************************************************************************
  6083. *
  6084. * sysfs attributes
  6085. *
  6086. *****************************************************************************/
  6087. #ifdef CONFIG_IWL3945_DEBUG
  6088. /*
  6089. * The following adds a new attribute to the sysfs representation
  6090. * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
  6091. * used for controlling the debug level.
  6092. *
  6093. * See the level definitions in iwl for details.
  6094. */
  6095. static ssize_t show_debug_level(struct device_driver *d, char *buf)
  6096. {
  6097. return sprintf(buf, "0x%08X\n", iwl3945_debug_level);
  6098. }
  6099. static ssize_t store_debug_level(struct device_driver *d,
  6100. const char *buf, size_t count)
  6101. {
  6102. char *p = (char *)buf;
  6103. u32 val;
  6104. val = simple_strtoul(p, &p, 0);
  6105. if (p == buf)
  6106. printk(KERN_INFO DRV_NAME
  6107. ": %s is not in hex or decimal form.\n", buf);
  6108. else
  6109. iwl3945_debug_level = val;
  6110. return strnlen(buf, count);
  6111. }
  6112. static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
  6113. show_debug_level, store_debug_level);
  6114. #endif /* CONFIG_IWL3945_DEBUG */
  6115. static ssize_t show_rf_kill(struct device *d,
  6116. struct device_attribute *attr, char *buf)
  6117. {
  6118. /*
  6119. * 0 - RF kill not enabled
  6120. * 1 - SW based RF kill active (sysfs)
  6121. * 2 - HW based RF kill active
  6122. * 3 - Both HW and SW based RF kill active
  6123. */
  6124. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6125. int val = (test_bit(STATUS_RF_KILL_SW, &priv->status) ? 0x1 : 0x0) |
  6126. (test_bit(STATUS_RF_KILL_HW, &priv->status) ? 0x2 : 0x0);
  6127. return sprintf(buf, "%i\n", val);
  6128. }
  6129. static ssize_t store_rf_kill(struct device *d,
  6130. struct device_attribute *attr,
  6131. const char *buf, size_t count)
  6132. {
  6133. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6134. mutex_lock(&priv->mutex);
  6135. iwl3945_radio_kill_sw(priv, buf[0] == '1');
  6136. mutex_unlock(&priv->mutex);
  6137. return count;
  6138. }
  6139. static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
  6140. static ssize_t show_temperature(struct device *d,
  6141. struct device_attribute *attr, char *buf)
  6142. {
  6143. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6144. if (!iwl3945_is_alive(priv))
  6145. return -EAGAIN;
  6146. return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
  6147. }
  6148. static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
  6149. static ssize_t show_rs_window(struct device *d,
  6150. struct device_attribute *attr,
  6151. char *buf)
  6152. {
  6153. struct iwl3945_priv *priv = d->driver_data;
  6154. return iwl3945_fill_rs_info(priv->hw, buf, IWL_AP_ID);
  6155. }
  6156. static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL);
  6157. static ssize_t show_tx_power(struct device *d,
  6158. struct device_attribute *attr, char *buf)
  6159. {
  6160. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6161. return sprintf(buf, "%d\n", priv->user_txpower_limit);
  6162. }
  6163. static ssize_t store_tx_power(struct device *d,
  6164. struct device_attribute *attr,
  6165. const char *buf, size_t count)
  6166. {
  6167. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6168. char *p = (char *)buf;
  6169. u32 val;
  6170. val = simple_strtoul(p, &p, 10);
  6171. if (p == buf)
  6172. printk(KERN_INFO DRV_NAME
  6173. ": %s is not in decimal form.\n", buf);
  6174. else
  6175. iwl3945_hw_reg_set_txpower(priv, val);
  6176. return count;
  6177. }
  6178. static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
  6179. static ssize_t show_flags(struct device *d,
  6180. struct device_attribute *attr, char *buf)
  6181. {
  6182. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6183. return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
  6184. }
  6185. static ssize_t store_flags(struct device *d,
  6186. struct device_attribute *attr,
  6187. const char *buf, size_t count)
  6188. {
  6189. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6190. u32 flags = simple_strtoul(buf, NULL, 0);
  6191. mutex_lock(&priv->mutex);
  6192. if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
  6193. /* Cancel any currently running scans... */
  6194. if (iwl3945_scan_cancel_timeout(priv, 100))
  6195. IWL_WARNING("Could not cancel scan.\n");
  6196. else {
  6197. IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
  6198. flags);
  6199. priv->staging_rxon.flags = cpu_to_le32(flags);
  6200. iwl3945_commit_rxon(priv);
  6201. }
  6202. }
  6203. mutex_unlock(&priv->mutex);
  6204. return count;
  6205. }
  6206. static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
  6207. static ssize_t show_filter_flags(struct device *d,
  6208. struct device_attribute *attr, char *buf)
  6209. {
  6210. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6211. return sprintf(buf, "0x%04X\n",
  6212. le32_to_cpu(priv->active_rxon.filter_flags));
  6213. }
  6214. static ssize_t store_filter_flags(struct device *d,
  6215. struct device_attribute *attr,
  6216. const char *buf, size_t count)
  6217. {
  6218. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6219. u32 filter_flags = simple_strtoul(buf, NULL, 0);
  6220. mutex_lock(&priv->mutex);
  6221. if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
  6222. /* Cancel any currently running scans... */
  6223. if (iwl3945_scan_cancel_timeout(priv, 100))
  6224. IWL_WARNING("Could not cancel scan.\n");
  6225. else {
  6226. IWL_DEBUG_INFO("Committing rxon.filter_flags = "
  6227. "0x%04X\n", filter_flags);
  6228. priv->staging_rxon.filter_flags =
  6229. cpu_to_le32(filter_flags);
  6230. iwl3945_commit_rxon(priv);
  6231. }
  6232. }
  6233. mutex_unlock(&priv->mutex);
  6234. return count;
  6235. }
  6236. static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
  6237. store_filter_flags);
  6238. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  6239. static ssize_t show_measurement(struct device *d,
  6240. struct device_attribute *attr, char *buf)
  6241. {
  6242. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6243. struct iwl3945_spectrum_notification measure_report;
  6244. u32 size = sizeof(measure_report), len = 0, ofs = 0;
  6245. u8 *data = (u8 *) & measure_report;
  6246. unsigned long flags;
  6247. spin_lock_irqsave(&priv->lock, flags);
  6248. if (!(priv->measurement_status & MEASUREMENT_READY)) {
  6249. spin_unlock_irqrestore(&priv->lock, flags);
  6250. return 0;
  6251. }
  6252. memcpy(&measure_report, &priv->measure_report, size);
  6253. priv->measurement_status = 0;
  6254. spin_unlock_irqrestore(&priv->lock, flags);
  6255. while (size && (PAGE_SIZE - len)) {
  6256. hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
  6257. PAGE_SIZE - len, 1);
  6258. len = strlen(buf);
  6259. if (PAGE_SIZE - len)
  6260. buf[len++] = '\n';
  6261. ofs += 16;
  6262. size -= min(size, 16U);
  6263. }
  6264. return len;
  6265. }
  6266. static ssize_t store_measurement(struct device *d,
  6267. struct device_attribute *attr,
  6268. const char *buf, size_t count)
  6269. {
  6270. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6271. struct ieee80211_measurement_params params = {
  6272. .channel = le16_to_cpu(priv->active_rxon.channel),
  6273. .start_time = cpu_to_le64(priv->last_tsf),
  6274. .duration = cpu_to_le16(1),
  6275. };
  6276. u8 type = IWL_MEASURE_BASIC;
  6277. u8 buffer[32];
  6278. u8 channel;
  6279. if (count) {
  6280. char *p = buffer;
  6281. strncpy(buffer, buf, min(sizeof(buffer), count));
  6282. channel = simple_strtoul(p, NULL, 0);
  6283. if (channel)
  6284. params.channel = channel;
  6285. p = buffer;
  6286. while (*p && *p != ' ')
  6287. p++;
  6288. if (*p)
  6289. type = simple_strtoul(p + 1, NULL, 0);
  6290. }
  6291. IWL_DEBUG_INFO("Invoking measurement of type %d on "
  6292. "channel %d (for '%s')\n", type, params.channel, buf);
  6293. iwl3945_get_measurement(priv, &params, type);
  6294. return count;
  6295. }
  6296. static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
  6297. show_measurement, store_measurement);
  6298. #endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
  6299. static ssize_t store_retry_rate(struct device *d,
  6300. struct device_attribute *attr,
  6301. const char *buf, size_t count)
  6302. {
  6303. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6304. priv->retry_rate = simple_strtoul(buf, NULL, 0);
  6305. if (priv->retry_rate <= 0)
  6306. priv->retry_rate = 1;
  6307. return count;
  6308. }
  6309. static ssize_t show_retry_rate(struct device *d,
  6310. struct device_attribute *attr, char *buf)
  6311. {
  6312. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6313. return sprintf(buf, "%d", priv->retry_rate);
  6314. }
  6315. static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
  6316. store_retry_rate);
  6317. static ssize_t store_power_level(struct device *d,
  6318. struct device_attribute *attr,
  6319. const char *buf, size_t count)
  6320. {
  6321. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6322. int rc;
  6323. int mode;
  6324. mode = simple_strtoul(buf, NULL, 0);
  6325. mutex_lock(&priv->mutex);
  6326. if (!iwl3945_is_ready(priv)) {
  6327. rc = -EAGAIN;
  6328. goto out;
  6329. }
  6330. if ((mode < 1) || (mode > IWL_POWER_LIMIT) || (mode == IWL_POWER_AC))
  6331. mode = IWL_POWER_AC;
  6332. else
  6333. mode |= IWL_POWER_ENABLED;
  6334. if (mode != priv->power_mode) {
  6335. rc = iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(mode));
  6336. if (rc) {
  6337. IWL_DEBUG_MAC80211("failed setting power mode.\n");
  6338. goto out;
  6339. }
  6340. priv->power_mode = mode;
  6341. }
  6342. rc = count;
  6343. out:
  6344. mutex_unlock(&priv->mutex);
  6345. return rc;
  6346. }
  6347. #define MAX_WX_STRING 80
  6348. /* Values are in microsecond */
  6349. static const s32 timeout_duration[] = {
  6350. 350000,
  6351. 250000,
  6352. 75000,
  6353. 37000,
  6354. 25000,
  6355. };
  6356. static const s32 period_duration[] = {
  6357. 400000,
  6358. 700000,
  6359. 1000000,
  6360. 1000000,
  6361. 1000000
  6362. };
  6363. static ssize_t show_power_level(struct device *d,
  6364. struct device_attribute *attr, char *buf)
  6365. {
  6366. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6367. int level = IWL_POWER_LEVEL(priv->power_mode);
  6368. char *p = buf;
  6369. p += sprintf(p, "%d ", level);
  6370. switch (level) {
  6371. case IWL_POWER_MODE_CAM:
  6372. case IWL_POWER_AC:
  6373. p += sprintf(p, "(AC)");
  6374. break;
  6375. case IWL_POWER_BATTERY:
  6376. p += sprintf(p, "(BATTERY)");
  6377. break;
  6378. default:
  6379. p += sprintf(p,
  6380. "(Timeout %dms, Period %dms)",
  6381. timeout_duration[level - 1] / 1000,
  6382. period_duration[level - 1] / 1000);
  6383. }
  6384. if (!(priv->power_mode & IWL_POWER_ENABLED))
  6385. p += sprintf(p, " OFF\n");
  6386. else
  6387. p += sprintf(p, " \n");
  6388. return (p - buf + 1);
  6389. }
  6390. static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
  6391. store_power_level);
  6392. static ssize_t show_channels(struct device *d,
  6393. struct device_attribute *attr, char *buf)
  6394. {
  6395. /* all this shit doesn't belong into sysfs anyway */
  6396. return 0;
  6397. }
  6398. static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
  6399. static ssize_t show_statistics(struct device *d,
  6400. struct device_attribute *attr, char *buf)
  6401. {
  6402. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6403. u32 size = sizeof(struct iwl3945_notif_statistics);
  6404. u32 len = 0, ofs = 0;
  6405. u8 *data = (u8 *) & priv->statistics;
  6406. int rc = 0;
  6407. if (!iwl3945_is_alive(priv))
  6408. return -EAGAIN;
  6409. mutex_lock(&priv->mutex);
  6410. rc = iwl3945_send_statistics_request(priv);
  6411. mutex_unlock(&priv->mutex);
  6412. if (rc) {
  6413. len = sprintf(buf,
  6414. "Error sending statistics request: 0x%08X\n", rc);
  6415. return len;
  6416. }
  6417. while (size && (PAGE_SIZE - len)) {
  6418. hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
  6419. PAGE_SIZE - len, 1);
  6420. len = strlen(buf);
  6421. if (PAGE_SIZE - len)
  6422. buf[len++] = '\n';
  6423. ofs += 16;
  6424. size -= min(size, 16U);
  6425. }
  6426. return len;
  6427. }
  6428. static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
  6429. static ssize_t show_antenna(struct device *d,
  6430. struct device_attribute *attr, char *buf)
  6431. {
  6432. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6433. if (!iwl3945_is_alive(priv))
  6434. return -EAGAIN;
  6435. return sprintf(buf, "%d\n", priv->antenna);
  6436. }
  6437. static ssize_t store_antenna(struct device *d,
  6438. struct device_attribute *attr,
  6439. const char *buf, size_t count)
  6440. {
  6441. int ant;
  6442. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6443. if (count == 0)
  6444. return 0;
  6445. if (sscanf(buf, "%1i", &ant) != 1) {
  6446. IWL_DEBUG_INFO("not in hex or decimal form.\n");
  6447. return count;
  6448. }
  6449. if ((ant >= 0) && (ant <= 2)) {
  6450. IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant);
  6451. priv->antenna = (enum iwl3945_antenna)ant;
  6452. } else
  6453. IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant);
  6454. return count;
  6455. }
  6456. static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
  6457. static ssize_t show_status(struct device *d,
  6458. struct device_attribute *attr, char *buf)
  6459. {
  6460. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6461. if (!iwl3945_is_alive(priv))
  6462. return -EAGAIN;
  6463. return sprintf(buf, "0x%08x\n", (int)priv->status);
  6464. }
  6465. static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
  6466. static ssize_t dump_error_log(struct device *d,
  6467. struct device_attribute *attr,
  6468. const char *buf, size_t count)
  6469. {
  6470. char *p = (char *)buf;
  6471. if (p[0] == '1')
  6472. iwl3945_dump_nic_error_log((struct iwl3945_priv *)d->driver_data);
  6473. return strnlen(buf, count);
  6474. }
  6475. static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
  6476. static ssize_t dump_event_log(struct device *d,
  6477. struct device_attribute *attr,
  6478. const char *buf, size_t count)
  6479. {
  6480. char *p = (char *)buf;
  6481. if (p[0] == '1')
  6482. iwl3945_dump_nic_event_log((struct iwl3945_priv *)d->driver_data);
  6483. return strnlen(buf, count);
  6484. }
  6485. static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
  6486. /*****************************************************************************
  6487. *
  6488. * driver setup and teardown
  6489. *
  6490. *****************************************************************************/
  6491. static void iwl3945_setup_deferred_work(struct iwl3945_priv *priv)
  6492. {
  6493. priv->workqueue = create_workqueue(DRV_NAME);
  6494. init_waitqueue_head(&priv->wait_command_queue);
  6495. INIT_WORK(&priv->up, iwl3945_bg_up);
  6496. INIT_WORK(&priv->restart, iwl3945_bg_restart);
  6497. INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
  6498. INIT_WORK(&priv->scan_completed, iwl3945_bg_scan_completed);
  6499. INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
  6500. INIT_WORK(&priv->abort_scan, iwl3945_bg_abort_scan);
  6501. INIT_WORK(&priv->rf_kill, iwl3945_bg_rf_kill);
  6502. INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
  6503. INIT_DELAYED_WORK(&priv->post_associate, iwl3945_bg_post_associate);
  6504. INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
  6505. INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
  6506. INIT_DELAYED_WORK(&priv->scan_check, iwl3945_bg_scan_check);
  6507. iwl3945_hw_setup_deferred_work(priv);
  6508. tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
  6509. iwl3945_irq_tasklet, (unsigned long)priv);
  6510. }
  6511. static void iwl3945_cancel_deferred_work(struct iwl3945_priv *priv)
  6512. {
  6513. iwl3945_hw_cancel_deferred_work(priv);
  6514. cancel_delayed_work_sync(&priv->init_alive_start);
  6515. cancel_delayed_work(&priv->scan_check);
  6516. cancel_delayed_work(&priv->alive_start);
  6517. cancel_delayed_work(&priv->post_associate);
  6518. cancel_work_sync(&priv->beacon_update);
  6519. }
  6520. static struct attribute *iwl3945_sysfs_entries[] = {
  6521. &dev_attr_antenna.attr,
  6522. &dev_attr_channels.attr,
  6523. &dev_attr_dump_errors.attr,
  6524. &dev_attr_dump_events.attr,
  6525. &dev_attr_flags.attr,
  6526. &dev_attr_filter_flags.attr,
  6527. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  6528. &dev_attr_measurement.attr,
  6529. #endif
  6530. &dev_attr_power_level.attr,
  6531. &dev_attr_retry_rate.attr,
  6532. &dev_attr_rf_kill.attr,
  6533. &dev_attr_rs_window.attr,
  6534. &dev_attr_statistics.attr,
  6535. &dev_attr_status.attr,
  6536. &dev_attr_temperature.attr,
  6537. &dev_attr_tx_power.attr,
  6538. NULL
  6539. };
  6540. static struct attribute_group iwl3945_attribute_group = {
  6541. .name = NULL, /* put in device directory */
  6542. .attrs = iwl3945_sysfs_entries,
  6543. };
  6544. static struct ieee80211_ops iwl3945_hw_ops = {
  6545. .tx = iwl3945_mac_tx,
  6546. .start = iwl3945_mac_start,
  6547. .stop = iwl3945_mac_stop,
  6548. .add_interface = iwl3945_mac_add_interface,
  6549. .remove_interface = iwl3945_mac_remove_interface,
  6550. .config = iwl3945_mac_config,
  6551. .config_interface = iwl3945_mac_config_interface,
  6552. .configure_filter = iwl3945_configure_filter,
  6553. .set_key = iwl3945_mac_set_key,
  6554. .get_stats = iwl3945_mac_get_stats,
  6555. .get_tx_stats = iwl3945_mac_get_tx_stats,
  6556. .conf_tx = iwl3945_mac_conf_tx,
  6557. .get_tsf = iwl3945_mac_get_tsf,
  6558. .reset_tsf = iwl3945_mac_reset_tsf,
  6559. .beacon_update = iwl3945_mac_beacon_update,
  6560. .hw_scan = iwl3945_mac_hw_scan
  6561. };
  6562. static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  6563. {
  6564. int err = 0;
  6565. struct iwl3945_priv *priv;
  6566. struct ieee80211_hw *hw;
  6567. struct iwl_3945_cfg *cfg = (struct iwl_3945_cfg *)(ent->driver_data);
  6568. int i;
  6569. DECLARE_MAC_BUF(mac);
  6570. /* Disabling hardware scan means that mac80211 will perform scans
  6571. * "the hard way", rather than using device's scan. */
  6572. if (iwl3945_param_disable_hw_scan) {
  6573. IWL_DEBUG_INFO("Disabling hw_scan\n");
  6574. iwl3945_hw_ops.hw_scan = NULL;
  6575. }
  6576. if ((iwl3945_param_queues_num > IWL_MAX_NUM_QUEUES) ||
  6577. (iwl3945_param_queues_num < IWL_MIN_NUM_QUEUES)) {
  6578. IWL_ERROR("invalid queues_num, should be between %d and %d\n",
  6579. IWL_MIN_NUM_QUEUES, IWL_MAX_NUM_QUEUES);
  6580. err = -EINVAL;
  6581. goto out;
  6582. }
  6583. /* mac80211 allocates memory for this device instance, including
  6584. * space for this driver's private structure */
  6585. hw = ieee80211_alloc_hw(sizeof(struct iwl3945_priv), &iwl3945_hw_ops);
  6586. if (hw == NULL) {
  6587. IWL_ERROR("Can not allocate network device\n");
  6588. err = -ENOMEM;
  6589. goto out;
  6590. }
  6591. SET_IEEE80211_DEV(hw, &pdev->dev);
  6592. hw->rate_control_algorithm = "iwl-3945-rs";
  6593. IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
  6594. priv = hw->priv;
  6595. priv->hw = hw;
  6596. priv->pci_dev = pdev;
  6597. priv->cfg = cfg;
  6598. /* Select antenna (may be helpful if only one antenna is connected) */
  6599. priv->antenna = (enum iwl3945_antenna)iwl3945_param_antenna;
  6600. #ifdef CONFIG_IWL3945_DEBUG
  6601. iwl3945_debug_level = iwl3945_param_debug;
  6602. atomic_set(&priv->restrict_refcnt, 0);
  6603. #endif
  6604. priv->retry_rate = 1;
  6605. priv->ibss_beacon = NULL;
  6606. /* Tell mac80211 and its clients (e.g. Wireless Extensions)
  6607. * the range of signal quality values that we'll provide.
  6608. * Negative values for level/noise indicate that we'll provide dBm.
  6609. * For WE, at least, non-0 values here *enable* display of values
  6610. * in app (iwconfig). */
  6611. hw->max_rssi = -20; /* signal level, negative indicates dBm */
  6612. hw->max_noise = -20; /* noise level, negative indicates dBm */
  6613. hw->max_signal = 100; /* link quality indication (%) */
  6614. /* Tell mac80211 our Tx characteristics */
  6615. hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE;
  6616. /* 4 EDCA QOS priorities */
  6617. hw->queues = 4;
  6618. spin_lock_init(&priv->lock);
  6619. spin_lock_init(&priv->power_data.lock);
  6620. spin_lock_init(&priv->sta_lock);
  6621. spin_lock_init(&priv->hcmd_lock);
  6622. for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++)
  6623. INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
  6624. INIT_LIST_HEAD(&priv->free_frames);
  6625. mutex_init(&priv->mutex);
  6626. if (pci_enable_device(pdev)) {
  6627. err = -ENODEV;
  6628. goto out_ieee80211_free_hw;
  6629. }
  6630. pci_set_master(pdev);
  6631. /* Clear the driver's (not device's) station table */
  6632. iwl3945_clear_stations_table(priv);
  6633. priv->data_retry_limit = -1;
  6634. priv->ieee_channels = NULL;
  6635. priv->ieee_rates = NULL;
  6636. priv->band = IEEE80211_BAND_2GHZ;
  6637. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  6638. if (!err)
  6639. err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  6640. if (err) {
  6641. printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
  6642. goto out_pci_disable_device;
  6643. }
  6644. pci_set_drvdata(pdev, priv);
  6645. err = pci_request_regions(pdev, DRV_NAME);
  6646. if (err)
  6647. goto out_pci_disable_device;
  6648. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  6649. * PCI Tx retries from interfering with C3 CPU state */
  6650. pci_write_config_byte(pdev, 0x41, 0x00);
  6651. priv->hw_base = pci_iomap(pdev, 0, 0);
  6652. if (!priv->hw_base) {
  6653. err = -ENODEV;
  6654. goto out_pci_release_regions;
  6655. }
  6656. IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
  6657. (unsigned long long) pci_resource_len(pdev, 0));
  6658. IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
  6659. /* Initialize module parameter values here */
  6660. /* Disable radio (SW RF KILL) via parameter when loading driver */
  6661. if (iwl3945_param_disable) {
  6662. set_bit(STATUS_RF_KILL_SW, &priv->status);
  6663. IWL_DEBUG_INFO("Radio disabled.\n");
  6664. }
  6665. priv->iw_mode = IEEE80211_IF_TYPE_STA;
  6666. printk(KERN_INFO DRV_NAME
  6667. ": Detected Intel Wireless WiFi Link %s\n", priv->cfg->name);
  6668. /* Device-specific setup */
  6669. if (iwl3945_hw_set_hw_setting(priv)) {
  6670. IWL_ERROR("failed to set hw settings\n");
  6671. goto out_iounmap;
  6672. }
  6673. if (iwl3945_param_qos_enable)
  6674. priv->qos_data.qos_enable = 1;
  6675. iwl3945_reset_qos(priv);
  6676. priv->qos_data.qos_active = 0;
  6677. priv->qos_data.qos_cap.val = 0;
  6678. iwl3945_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
  6679. iwl3945_setup_deferred_work(priv);
  6680. iwl3945_setup_rx_handlers(priv);
  6681. priv->rates_mask = IWL_RATES_MASK;
  6682. /* If power management is turned on, default to AC mode */
  6683. priv->power_mode = IWL_POWER_AC;
  6684. priv->user_txpower_limit = IWL_DEFAULT_TX_POWER;
  6685. iwl3945_disable_interrupts(priv);
  6686. err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
  6687. if (err) {
  6688. IWL_ERROR("failed to create sysfs device attributes\n");
  6689. goto out_release_irq;
  6690. }
  6691. /* nic init */
  6692. iwl3945_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  6693. CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
  6694. iwl3945_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  6695. err = iwl3945_poll_bit(priv, CSR_GP_CNTRL,
  6696. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  6697. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  6698. if (err < 0) {
  6699. IWL_DEBUG_INFO("Failed to init the card\n");
  6700. goto out_remove_sysfs;
  6701. }
  6702. /* Read the EEPROM */
  6703. err = iwl3945_eeprom_init(priv);
  6704. if (err) {
  6705. IWL_ERROR("Unable to init EEPROM\n");
  6706. goto out_remove_sysfs;
  6707. }
  6708. /* MAC Address location in EEPROM same for 3945/4965 */
  6709. get_eeprom_mac(priv, priv->mac_addr);
  6710. IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr));
  6711. SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
  6712. err = iwl3945_init_channel_map(priv);
  6713. if (err) {
  6714. IWL_ERROR("initializing regulatory failed: %d\n", err);
  6715. goto out_remove_sysfs;
  6716. }
  6717. err = iwl3945_init_geos(priv);
  6718. if (err) {
  6719. IWL_ERROR("initializing geos failed: %d\n", err);
  6720. goto out_free_channel_map;
  6721. }
  6722. iwl3945_rate_control_register(priv->hw);
  6723. err = ieee80211_register_hw(priv->hw);
  6724. if (err) {
  6725. IWL_ERROR("Failed to register network device (error %d)\n", err);
  6726. goto out_free_geos;
  6727. }
  6728. priv->hw->conf.beacon_int = 100;
  6729. priv->mac80211_registered = 1;
  6730. pci_save_state(pdev);
  6731. pci_disable_device(pdev);
  6732. return 0;
  6733. out_free_geos:
  6734. iwl3945_free_geos(priv);
  6735. out_free_channel_map:
  6736. iwl3945_free_channel_map(priv);
  6737. out_remove_sysfs:
  6738. sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
  6739. out_release_irq:
  6740. destroy_workqueue(priv->workqueue);
  6741. priv->workqueue = NULL;
  6742. iwl3945_unset_hw_setting(priv);
  6743. out_iounmap:
  6744. pci_iounmap(pdev, priv->hw_base);
  6745. out_pci_release_regions:
  6746. pci_release_regions(pdev);
  6747. out_pci_disable_device:
  6748. pci_disable_device(pdev);
  6749. pci_set_drvdata(pdev, NULL);
  6750. out_ieee80211_free_hw:
  6751. ieee80211_free_hw(priv->hw);
  6752. out:
  6753. return err;
  6754. }
  6755. static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
  6756. {
  6757. struct iwl3945_priv *priv = pci_get_drvdata(pdev);
  6758. struct list_head *p, *q;
  6759. int i;
  6760. if (!priv)
  6761. return;
  6762. IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
  6763. set_bit(STATUS_EXIT_PENDING, &priv->status);
  6764. iwl3945_down(priv);
  6765. /* Free MAC hash list for ADHOC */
  6766. for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) {
  6767. list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
  6768. list_del(p);
  6769. kfree(list_entry(p, struct iwl3945_ibss_seq, list));
  6770. }
  6771. }
  6772. sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
  6773. iwl3945_dealloc_ucode_pci(priv);
  6774. if (priv->rxq.bd)
  6775. iwl3945_rx_queue_free(priv, &priv->rxq);
  6776. iwl3945_hw_txq_ctx_free(priv);
  6777. iwl3945_unset_hw_setting(priv);
  6778. iwl3945_clear_stations_table(priv);
  6779. if (priv->mac80211_registered) {
  6780. ieee80211_unregister_hw(priv->hw);
  6781. iwl3945_rate_control_unregister(priv->hw);
  6782. }
  6783. /*netif_stop_queue(dev); */
  6784. flush_workqueue(priv->workqueue);
  6785. /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
  6786. * priv->workqueue... so we can't take down the workqueue
  6787. * until now... */
  6788. destroy_workqueue(priv->workqueue);
  6789. priv->workqueue = NULL;
  6790. pci_iounmap(pdev, priv->hw_base);
  6791. pci_release_regions(pdev);
  6792. pci_disable_device(pdev);
  6793. pci_set_drvdata(pdev, NULL);
  6794. iwl3945_free_channel_map(priv);
  6795. iwl3945_free_geos(priv);
  6796. if (priv->ibss_beacon)
  6797. dev_kfree_skb(priv->ibss_beacon);
  6798. ieee80211_free_hw(priv->hw);
  6799. }
  6800. #ifdef CONFIG_PM
  6801. static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  6802. {
  6803. struct iwl3945_priv *priv = pci_get_drvdata(pdev);
  6804. if (priv->is_open) {
  6805. set_bit(STATUS_IN_SUSPEND, &priv->status);
  6806. iwl3945_mac_stop(priv->hw);
  6807. priv->is_open = 1;
  6808. }
  6809. pci_set_power_state(pdev, PCI_D3hot);
  6810. return 0;
  6811. }
  6812. static int iwl3945_pci_resume(struct pci_dev *pdev)
  6813. {
  6814. struct iwl3945_priv *priv = pci_get_drvdata(pdev);
  6815. pci_set_power_state(pdev, PCI_D0);
  6816. if (priv->is_open)
  6817. iwl3945_mac_start(priv->hw);
  6818. clear_bit(STATUS_IN_SUSPEND, &priv->status);
  6819. return 0;
  6820. }
  6821. #endif /* CONFIG_PM */
  6822. /*****************************************************************************
  6823. *
  6824. * driver and module entry point
  6825. *
  6826. *****************************************************************************/
  6827. static struct pci_driver iwl3945_driver = {
  6828. .name = DRV_NAME,
  6829. .id_table = iwl3945_hw_card_ids,
  6830. .probe = iwl3945_pci_probe,
  6831. .remove = __devexit_p(iwl3945_pci_remove),
  6832. #ifdef CONFIG_PM
  6833. .suspend = iwl3945_pci_suspend,
  6834. .resume = iwl3945_pci_resume,
  6835. #endif
  6836. };
  6837. static int __init iwl3945_init(void)
  6838. {
  6839. int ret;
  6840. printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
  6841. printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
  6842. ret = pci_register_driver(&iwl3945_driver);
  6843. if (ret) {
  6844. IWL_ERROR("Unable to initialize PCI module\n");
  6845. return ret;
  6846. }
  6847. #ifdef CONFIG_IWL3945_DEBUG
  6848. ret = driver_create_file(&iwl3945_driver.driver, &driver_attr_debug_level);
  6849. if (ret) {
  6850. IWL_ERROR("Unable to create driver sysfs file\n");
  6851. pci_unregister_driver(&iwl3945_driver);
  6852. return ret;
  6853. }
  6854. #endif
  6855. return ret;
  6856. }
  6857. static void __exit iwl3945_exit(void)
  6858. {
  6859. #ifdef CONFIG_IWL3945_DEBUG
  6860. driver_remove_file(&iwl3945_driver.driver, &driver_attr_debug_level);
  6861. #endif
  6862. pci_unregister_driver(&iwl3945_driver);
  6863. }
  6864. module_param_named(antenna, iwl3945_param_antenna, int, 0444);
  6865. MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
  6866. module_param_named(disable, iwl3945_param_disable, int, 0444);
  6867. MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
  6868. module_param_named(hwcrypto, iwl3945_param_hwcrypto, int, 0444);
  6869. MODULE_PARM_DESC(hwcrypto,
  6870. "using hardware crypto engine (default 0 [software])\n");
  6871. module_param_named(debug, iwl3945_param_debug, int, 0444);
  6872. MODULE_PARM_DESC(debug, "debug output mask");
  6873. module_param_named(disable_hw_scan, iwl3945_param_disable_hw_scan, int, 0444);
  6874. MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
  6875. module_param_named(queues_num, iwl3945_param_queues_num, int, 0444);
  6876. MODULE_PARM_DESC(queues_num, "number of hw queues.");
  6877. /* QoS */
  6878. module_param_named(qos_enable, iwl3945_param_qos_enable, int, 0444);
  6879. MODULE_PARM_DESC(qos_enable, "enable all QoS functionality");
  6880. module_exit(iwl3945_exit);
  6881. module_init(iwl3945_init);