iwl3945-base.c 247 KB

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