iwl3945-base.c 242 KB

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