iwl3945-base.c 247 KB

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