iwl3945-base.c 204 KB

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