iwl4965-base.c 184 KB

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