iwl4965-base.c 235 KB

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