iwl4965-base.c 236 KB

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