iwl4965-base.c 222 KB

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