iwl4965-base.c 257 KB

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