iwl4965-base.c 267 KB

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