iwl4965-base.c 223 KB

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