iwl4965-base.c 195 KB

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