iwl3945-base.c 250 KB

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