iwl4965-base.c 216 KB

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