ipw2200.c 300 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346
  1. /******************************************************************************
  2. Copyright(c) 2003 - 2005 Intel Corporation. All rights reserved.
  3. 802.11 status code portion of this file from ethereal-0.10.6:
  4. Copyright 2000, Axis Communications AB
  5. Ethereal - Network traffic analyzer
  6. By Gerald Combs <gerald@ethereal.com>
  7. Copyright 1998 Gerald Combs
  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. This program is distributed in the hope that it will be useful, but WITHOUT
  12. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. more details.
  15. You should have received a copy of the GNU General Public License along with
  16. this program; if not, write to the Free Software Foundation, Inc., 59
  17. Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. The full GNU General Public License is included in this distribution in the
  19. file called LICENSE.
  20. Contact Information:
  21. James P. Ketrenos <ipw2100-admin@linux.intel.com>
  22. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  23. ******************************************************************************/
  24. #include "ipw2200.h"
  25. #define IPW2200_VERSION "1.0.5"
  26. #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
  27. #define DRV_COPYRIGHT "Copyright(c) 2003-2005 Intel Corporation"
  28. #define DRV_VERSION IPW2200_VERSION
  29. #define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
  30. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  31. MODULE_VERSION(DRV_VERSION);
  32. MODULE_AUTHOR(DRV_COPYRIGHT);
  33. MODULE_LICENSE("GPL");
  34. static int debug = 0;
  35. static int channel = 0;
  36. static int mode = 0;
  37. static u32 ipw_debug_level;
  38. static int associate = 1;
  39. static int auto_create = 1;
  40. static int led = 0;
  41. static int disable = 0;
  42. static int hwcrypto = 1;
  43. static const char ipw_modes[] = {
  44. 'a', 'b', 'g', '?'
  45. };
  46. #ifdef CONFIG_IPW_QOS
  47. static int qos_enable = 0;
  48. static int qos_burst_enable = 0;
  49. static int qos_no_ack_mask = 0;
  50. static int burst_duration_CCK = 0;
  51. static int burst_duration_OFDM = 0;
  52. static struct ieee80211_qos_parameters def_qos_parameters_OFDM = {
  53. {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
  54. QOS_TX3_CW_MIN_OFDM},
  55. {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
  56. QOS_TX3_CW_MAX_OFDM},
  57. {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
  58. {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
  59. {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
  60. QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
  61. };
  62. static struct ieee80211_qos_parameters def_qos_parameters_CCK = {
  63. {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
  64. QOS_TX3_CW_MIN_CCK},
  65. {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
  66. QOS_TX3_CW_MAX_CCK},
  67. {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
  68. {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
  69. {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
  70. QOS_TX3_TXOP_LIMIT_CCK}
  71. };
  72. static struct ieee80211_qos_parameters def_parameters_OFDM = {
  73. {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
  74. DEF_TX3_CW_MIN_OFDM},
  75. {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
  76. DEF_TX3_CW_MAX_OFDM},
  77. {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
  78. {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
  79. {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
  80. DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
  81. };
  82. static struct ieee80211_qos_parameters def_parameters_CCK = {
  83. {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
  84. DEF_TX3_CW_MIN_CCK},
  85. {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
  86. DEF_TX3_CW_MAX_CCK},
  87. {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
  88. {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
  89. {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
  90. DEF_TX3_TXOP_LIMIT_CCK}
  91. };
  92. static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
  93. static int from_priority_to_tx_queue[] = {
  94. IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
  95. IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
  96. };
  97. static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
  98. static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
  99. *qos_param);
  100. static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
  101. *qos_param);
  102. #endif /* CONFIG_IPW_QOS */
  103. static void ipw_remove_current_network(struct ipw_priv *priv);
  104. static void ipw_rx(struct ipw_priv *priv);
  105. static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
  106. struct clx2_tx_queue *txq, int qindex);
  107. static int ipw_queue_reset(struct ipw_priv *priv);
  108. static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
  109. int len, int sync);
  110. static void ipw_tx_queue_free(struct ipw_priv *);
  111. static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
  112. static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
  113. static void ipw_rx_queue_replenish(void *);
  114. static int ipw_up(struct ipw_priv *);
  115. static void ipw_bg_up(void *);
  116. static void ipw_down(struct ipw_priv *);
  117. static void ipw_bg_down(void *);
  118. static int ipw_config(struct ipw_priv *);
  119. static int init_supported_rates(struct ipw_priv *priv,
  120. struct ipw_supported_rates *prates);
  121. static void ipw_set_hwcrypto_keys(struct ipw_priv *);
  122. static void ipw_send_wep_keys(struct ipw_priv *, int);
  123. static char *snprint_line(char *buf, size_t count,
  124. const u8 * data, u32 len, u32 ofs)
  125. {
  126. int out, i, j, l;
  127. char c;
  128. out = snprintf(buf, count, "%08X", ofs);
  129. for (l = 0, i = 0; i < 2; i++) {
  130. out += snprintf(buf + out, count - out, " ");
  131. for (j = 0; j < 8 && l < len; j++, l++)
  132. out += snprintf(buf + out, count - out, "%02X ",
  133. data[(i * 8 + j)]);
  134. for (; j < 8; j++)
  135. out += snprintf(buf + out, count - out, " ");
  136. }
  137. out += snprintf(buf + out, count - out, " ");
  138. for (l = 0, i = 0; i < 2; i++) {
  139. out += snprintf(buf + out, count - out, " ");
  140. for (j = 0; j < 8 && l < len; j++, l++) {
  141. c = data[(i * 8 + j)];
  142. if (!isascii(c) || !isprint(c))
  143. c = '.';
  144. out += snprintf(buf + out, count - out, "%c", c);
  145. }
  146. for (; j < 8; j++)
  147. out += snprintf(buf + out, count - out, " ");
  148. }
  149. return buf;
  150. }
  151. static void printk_buf(int level, const u8 * data, u32 len)
  152. {
  153. char line[81];
  154. u32 ofs = 0;
  155. if (!(ipw_debug_level & level))
  156. return;
  157. while (len) {
  158. printk(KERN_DEBUG "%s\n",
  159. snprint_line(line, sizeof(line), &data[ofs],
  160. min(len, 16U), ofs));
  161. ofs += 16;
  162. len -= min(len, 16U);
  163. }
  164. }
  165. static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
  166. #define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
  167. static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
  168. #define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
  169. static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
  170. static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
  171. {
  172. IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
  173. __LINE__, (u32) (b), (u32) (c));
  174. _ipw_write_reg8(a, b, c);
  175. }
  176. static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
  177. static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
  178. {
  179. IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
  180. __LINE__, (u32) (b), (u32) (c));
  181. _ipw_write_reg16(a, b, c);
  182. }
  183. static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
  184. static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
  185. {
  186. IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
  187. __LINE__, (u32) (b), (u32) (c));
  188. _ipw_write_reg32(a, b, c);
  189. }
  190. #define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs))
  191. #define ipw_write8(ipw, ofs, val) \
  192. IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
  193. _ipw_write8(ipw, ofs, val)
  194. #define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs))
  195. #define ipw_write16(ipw, ofs, val) \
  196. IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
  197. _ipw_write16(ipw, ofs, val)
  198. #define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs))
  199. #define ipw_write32(ipw, ofs, val) \
  200. IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
  201. _ipw_write32(ipw, ofs, val)
  202. #define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs))
  203. static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
  204. {
  205. IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs));
  206. return _ipw_read8(ipw, ofs);
  207. }
  208. #define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs)
  209. #define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs))
  210. static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
  211. {
  212. IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs));
  213. return _ipw_read16(ipw, ofs);
  214. }
  215. #define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs)
  216. #define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs))
  217. static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
  218. {
  219. IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs));
  220. return _ipw_read32(ipw, ofs);
  221. }
  222. #define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
  223. static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
  224. #define ipw_read_indirect(a, b, c, d) \
  225. IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
  226. _ipw_read_indirect(a, b, c, d)
  227. static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
  228. int num);
  229. #define ipw_write_indirect(a, b, c, d) \
  230. IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
  231. _ipw_write_indirect(a, b, c, d)
  232. /* indirect write s */
  233. static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
  234. {
  235. IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
  236. _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
  237. _ipw_write32(priv, IPW_INDIRECT_DATA, value);
  238. }
  239. static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
  240. {
  241. IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
  242. _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
  243. _ipw_write8(priv, IPW_INDIRECT_DATA, value);
  244. }
  245. static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
  246. {
  247. IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
  248. _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
  249. _ipw_write16(priv, IPW_INDIRECT_DATA, value);
  250. }
  251. /* indirect read s */
  252. static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
  253. {
  254. u32 word;
  255. _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
  256. IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
  257. word = _ipw_read32(priv, IPW_INDIRECT_DATA);
  258. return (word >> ((reg & 0x3) * 8)) & 0xff;
  259. }
  260. static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
  261. {
  262. u32 value;
  263. IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
  264. _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
  265. value = _ipw_read32(priv, IPW_INDIRECT_DATA);
  266. IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
  267. return value;
  268. }
  269. /* iterative/auto-increment 32 bit reads and writes */
  270. static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
  271. int num)
  272. {
  273. u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK;
  274. u32 dif_len = addr - aligned_addr;
  275. u32 i;
  276. IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
  277. if (num <= 0) {
  278. return;
  279. }
  280. /* Read the first nibble byte by byte */
  281. if (unlikely(dif_len)) {
  282. _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
  283. /* Start reading at aligned_addr + dif_len */
  284. for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
  285. *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
  286. aligned_addr += 4;
  287. }
  288. _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
  289. for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
  290. *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
  291. /* Copy the last nibble */
  292. if (unlikely(num)) {
  293. _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
  294. for (i = 0; num > 0; i++, num--)
  295. *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
  296. }
  297. }
  298. static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
  299. int num)
  300. {
  301. u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK;
  302. u32 dif_len = addr - aligned_addr;
  303. u32 i;
  304. IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
  305. if (num <= 0) {
  306. return;
  307. }
  308. /* Write the first nibble byte by byte */
  309. if (unlikely(dif_len)) {
  310. _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
  311. /* Start reading at aligned_addr + dif_len */
  312. for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
  313. _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
  314. aligned_addr += 4;
  315. }
  316. _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
  317. for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
  318. _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
  319. /* Copy the last nibble */
  320. if (unlikely(num)) {
  321. _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
  322. for (i = 0; num > 0; i++, num--, buf++)
  323. _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
  324. }
  325. }
  326. static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
  327. int num)
  328. {
  329. memcpy_toio((priv->hw_base + addr), buf, num);
  330. }
  331. static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
  332. {
  333. ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
  334. }
  335. static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
  336. {
  337. ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
  338. }
  339. static inline void ipw_enable_interrupts(struct ipw_priv *priv)
  340. {
  341. if (priv->status & STATUS_INT_ENABLED)
  342. return;
  343. priv->status |= STATUS_INT_ENABLED;
  344. ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
  345. }
  346. static inline void ipw_disable_interrupts(struct ipw_priv *priv)
  347. {
  348. if (!(priv->status & STATUS_INT_ENABLED))
  349. return;
  350. priv->status &= ~STATUS_INT_ENABLED;
  351. ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
  352. }
  353. static char *ipw_error_desc(u32 val)
  354. {
  355. switch (val) {
  356. case IPW_FW_ERROR_OK:
  357. return "ERROR_OK";
  358. case IPW_FW_ERROR_FAIL:
  359. return "ERROR_FAIL";
  360. case IPW_FW_ERROR_MEMORY_UNDERFLOW:
  361. return "MEMORY_UNDERFLOW";
  362. case IPW_FW_ERROR_MEMORY_OVERFLOW:
  363. return "MEMORY_OVERFLOW";
  364. case IPW_FW_ERROR_BAD_PARAM:
  365. return "BAD_PARAM";
  366. case IPW_FW_ERROR_BAD_CHECKSUM:
  367. return "BAD_CHECKSUM";
  368. case IPW_FW_ERROR_NMI_INTERRUPT:
  369. return "NMI_INTERRUPT";
  370. case IPW_FW_ERROR_BAD_DATABASE:
  371. return "BAD_DATABASE";
  372. case IPW_FW_ERROR_ALLOC_FAIL:
  373. return "ALLOC_FAIL";
  374. case IPW_FW_ERROR_DMA_UNDERRUN:
  375. return "DMA_UNDERRUN";
  376. case IPW_FW_ERROR_DMA_STATUS:
  377. return "DMA_STATUS";
  378. case IPW_FW_ERROR_DINO_ERROR:
  379. return "DINO_ERROR";
  380. case IPW_FW_ERROR_EEPROM_ERROR:
  381. return "EEPROM_ERROR";
  382. case IPW_FW_ERROR_SYSASSERT:
  383. return "SYSASSERT";
  384. case IPW_FW_ERROR_FATAL_ERROR:
  385. return "FATAL_ERROR";
  386. default:
  387. return "UNKNOWN_ERROR";
  388. }
  389. }
  390. static void ipw_dump_nic_error_log(struct ipw_priv *priv)
  391. {
  392. u32 desc, time, blink1, blink2, ilink1, ilink2, idata, i, count, base;
  393. base = ipw_read32(priv, IPWSTATUS_ERROR_LOG);
  394. count = ipw_read_reg32(priv, base);
  395. if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
  396. IPW_ERROR("Start IPW Error Log Dump:\n");
  397. IPW_ERROR("Status: 0x%08X, Config: %08X\n",
  398. priv->status, priv->config);
  399. }
  400. for (i = ERROR_START_OFFSET;
  401. i <= count * ERROR_ELEM_SIZE; i += ERROR_ELEM_SIZE) {
  402. desc = ipw_read_reg32(priv, base + i);
  403. time = ipw_read_reg32(priv, base + i + 1 * sizeof(u32));
  404. blink1 = ipw_read_reg32(priv, base + i + 2 * sizeof(u32));
  405. blink2 = ipw_read_reg32(priv, base + i + 3 * sizeof(u32));
  406. ilink1 = ipw_read_reg32(priv, base + i + 4 * sizeof(u32));
  407. ilink2 = ipw_read_reg32(priv, base + i + 5 * sizeof(u32));
  408. idata = ipw_read_reg32(priv, base + i + 6 * sizeof(u32));
  409. IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
  410. ipw_error_desc(desc), time, blink1, blink2,
  411. ilink1, ilink2, idata);
  412. }
  413. }
  414. static void ipw_dump_nic_event_log(struct ipw_priv *priv)
  415. {
  416. u32 ev, time, data, i, count, base;
  417. base = ipw_read32(priv, IPW_EVENT_LOG);
  418. count = ipw_read_reg32(priv, base);
  419. if (EVENT_START_OFFSET <= count * EVENT_ELEM_SIZE)
  420. IPW_ERROR("Start IPW Event Log Dump:\n");
  421. for (i = EVENT_START_OFFSET;
  422. i <= count * EVENT_ELEM_SIZE; i += EVENT_ELEM_SIZE) {
  423. ev = ipw_read_reg32(priv, base + i);
  424. time = ipw_read_reg32(priv, base + i + 1 * sizeof(u32));
  425. data = ipw_read_reg32(priv, base + i + 2 * sizeof(u32));
  426. #ifdef CONFIG_IPW_DEBUG
  427. IPW_ERROR("%i\t0x%08x\t%i\n", time, data, ev);
  428. #endif
  429. }
  430. }
  431. static inline int ipw_is_init(struct ipw_priv *priv)
  432. {
  433. return (priv->status & STATUS_INIT) ? 1 : 0;
  434. }
  435. static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
  436. {
  437. u32 addr, field_info, field_len, field_count, total_len;
  438. IPW_DEBUG_ORD("ordinal = %i\n", ord);
  439. if (!priv || !val || !len) {
  440. IPW_DEBUG_ORD("Invalid argument\n");
  441. return -EINVAL;
  442. }
  443. /* verify device ordinal tables have been initialized */
  444. if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
  445. IPW_DEBUG_ORD("Access ordinals before initialization\n");
  446. return -EINVAL;
  447. }
  448. switch (IPW_ORD_TABLE_ID_MASK & ord) {
  449. case IPW_ORD_TABLE_0_MASK:
  450. /*
  451. * TABLE 0: Direct access to a table of 32 bit values
  452. *
  453. * This is a very simple table with the data directly
  454. * read from the table
  455. */
  456. /* remove the table id from the ordinal */
  457. ord &= IPW_ORD_TABLE_VALUE_MASK;
  458. /* boundary check */
  459. if (ord > priv->table0_len) {
  460. IPW_DEBUG_ORD("ordinal value (%i) longer then "
  461. "max (%i)\n", ord, priv->table0_len);
  462. return -EINVAL;
  463. }
  464. /* verify we have enough room to store the value */
  465. if (*len < sizeof(u32)) {
  466. IPW_DEBUG_ORD("ordinal buffer length too small, "
  467. "need %zd\n", sizeof(u32));
  468. return -EINVAL;
  469. }
  470. IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
  471. ord, priv->table0_addr + (ord << 2));
  472. *len = sizeof(u32);
  473. ord <<= 2;
  474. *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
  475. break;
  476. case IPW_ORD_TABLE_1_MASK:
  477. /*
  478. * TABLE 1: Indirect access to a table of 32 bit values
  479. *
  480. * This is a fairly large table of u32 values each
  481. * representing starting addr for the data (which is
  482. * also a u32)
  483. */
  484. /* remove the table id from the ordinal */
  485. ord &= IPW_ORD_TABLE_VALUE_MASK;
  486. /* boundary check */
  487. if (ord > priv->table1_len) {
  488. IPW_DEBUG_ORD("ordinal value too long\n");
  489. return -EINVAL;
  490. }
  491. /* verify we have enough room to store the value */
  492. if (*len < sizeof(u32)) {
  493. IPW_DEBUG_ORD("ordinal buffer length too small, "
  494. "need %zd\n", sizeof(u32));
  495. return -EINVAL;
  496. }
  497. *((u32 *) val) =
  498. ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
  499. *len = sizeof(u32);
  500. break;
  501. case IPW_ORD_TABLE_2_MASK:
  502. /*
  503. * TABLE 2: Indirect access to a table of variable sized values
  504. *
  505. * This table consist of six values, each containing
  506. * - dword containing the starting offset of the data
  507. * - dword containing the lengh in the first 16bits
  508. * and the count in the second 16bits
  509. */
  510. /* remove the table id from the ordinal */
  511. ord &= IPW_ORD_TABLE_VALUE_MASK;
  512. /* boundary check */
  513. if (ord > priv->table2_len) {
  514. IPW_DEBUG_ORD("ordinal value too long\n");
  515. return -EINVAL;
  516. }
  517. /* get the address of statistic */
  518. addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
  519. /* get the second DW of statistics ;
  520. * two 16-bit words - first is length, second is count */
  521. field_info =
  522. ipw_read_reg32(priv,
  523. priv->table2_addr + (ord << 3) +
  524. sizeof(u32));
  525. /* get each entry length */
  526. field_len = *((u16 *) & field_info);
  527. /* get number of entries */
  528. field_count = *(((u16 *) & field_info) + 1);
  529. /* abort if not enought memory */
  530. total_len = field_len * field_count;
  531. if (total_len > *len) {
  532. *len = total_len;
  533. return -EINVAL;
  534. }
  535. *len = total_len;
  536. if (!total_len)
  537. return 0;
  538. IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
  539. "field_info = 0x%08x\n",
  540. addr, total_len, field_info);
  541. ipw_read_indirect(priv, addr, val, total_len);
  542. break;
  543. default:
  544. IPW_DEBUG_ORD("Invalid ordinal!\n");
  545. return -EINVAL;
  546. }
  547. return 0;
  548. }
  549. static void ipw_init_ordinals(struct ipw_priv *priv)
  550. {
  551. priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
  552. priv->table0_len = ipw_read32(priv, priv->table0_addr);
  553. IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
  554. priv->table0_addr, priv->table0_len);
  555. priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
  556. priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
  557. IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
  558. priv->table1_addr, priv->table1_len);
  559. priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
  560. priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
  561. priv->table2_len &= 0x0000ffff; /* use first two bytes */
  562. IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
  563. priv->table2_addr, priv->table2_len);
  564. }
  565. u32 ipw_register_toggle(u32 reg)
  566. {
  567. reg &= ~IPW_START_STANDBY;
  568. if (reg & IPW_GATE_ODMA)
  569. reg &= ~IPW_GATE_ODMA;
  570. if (reg & IPW_GATE_IDMA)
  571. reg &= ~IPW_GATE_IDMA;
  572. if (reg & IPW_GATE_ADMA)
  573. reg &= ~IPW_GATE_ADMA;
  574. return reg;
  575. }
  576. /*
  577. * LED behavior:
  578. * - On radio ON, turn on any LEDs that require to be on during start
  579. * - On initialization, start unassociated blink
  580. * - On association, disable unassociated blink
  581. * - On disassociation, start unassociated blink
  582. * - On radio OFF, turn off any LEDs started during radio on
  583. *
  584. */
  585. #define LD_TIME_LINK_ON 300
  586. #define LD_TIME_LINK_OFF 2700
  587. #define LD_TIME_ACT_ON 250
  588. void ipw_led_link_on(struct ipw_priv *priv)
  589. {
  590. unsigned long flags;
  591. u32 led;
  592. /* If configured to not use LEDs, or nic_type is 1,
  593. * then we don't toggle a LINK led */
  594. if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
  595. return;
  596. spin_lock_irqsave(&priv->lock, flags);
  597. if (!(priv->status & STATUS_RF_KILL_MASK) &&
  598. !(priv->status & STATUS_LED_LINK_ON)) {
  599. IPW_DEBUG_LED("Link LED On\n");
  600. led = ipw_read_reg32(priv, IPW_EVENT_REG);
  601. led |= priv->led_association_on;
  602. led = ipw_register_toggle(led);
  603. IPW_DEBUG_LED("Reg: 0x%08X\n", led);
  604. ipw_write_reg32(priv, IPW_EVENT_REG, led);
  605. priv->status |= STATUS_LED_LINK_ON;
  606. /* If we aren't associated, schedule turning the LED off */
  607. if (!(priv->status & STATUS_ASSOCIATED))
  608. queue_delayed_work(priv->workqueue,
  609. &priv->led_link_off,
  610. LD_TIME_LINK_ON);
  611. }
  612. spin_unlock_irqrestore(&priv->lock, flags);
  613. }
  614. static void ipw_bg_led_link_on(void *data)
  615. {
  616. struct ipw_priv *priv = data;
  617. down(&priv->sem);
  618. ipw_led_link_on(data);
  619. up(&priv->sem);
  620. }
  621. void ipw_led_link_off(struct ipw_priv *priv)
  622. {
  623. unsigned long flags;
  624. u32 led;
  625. /* If configured not to use LEDs, or nic type is 1,
  626. * then we don't goggle the LINK led. */
  627. if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
  628. return;
  629. spin_lock_irqsave(&priv->lock, flags);
  630. if (priv->status & STATUS_LED_LINK_ON) {
  631. led = ipw_read_reg32(priv, IPW_EVENT_REG);
  632. led &= priv->led_association_off;
  633. led = ipw_register_toggle(led);
  634. IPW_DEBUG_LED("Reg: 0x%08X\n", led);
  635. ipw_write_reg32(priv, IPW_EVENT_REG, led);
  636. IPW_DEBUG_LED("Link LED Off\n");
  637. priv->status &= ~STATUS_LED_LINK_ON;
  638. /* If we aren't associated and the radio is on, schedule
  639. * turning the LED on (blink while unassociated) */
  640. if (!(priv->status & STATUS_RF_KILL_MASK) &&
  641. !(priv->status & STATUS_ASSOCIATED))
  642. queue_delayed_work(priv->workqueue, &priv->led_link_on,
  643. LD_TIME_LINK_OFF);
  644. }
  645. spin_unlock_irqrestore(&priv->lock, flags);
  646. }
  647. static void ipw_bg_led_link_off(void *data)
  648. {
  649. struct ipw_priv *priv = data;
  650. down(&priv->sem);
  651. ipw_led_link_off(data);
  652. up(&priv->sem);
  653. }
  654. static inline void __ipw_led_activity_on(struct ipw_priv *priv)
  655. {
  656. u32 led;
  657. if (priv->config & CFG_NO_LED)
  658. return;
  659. if (priv->status & STATUS_RF_KILL_MASK)
  660. return;
  661. if (!(priv->status & STATUS_LED_ACT_ON)) {
  662. led = ipw_read_reg32(priv, IPW_EVENT_REG);
  663. led |= priv->led_activity_on;
  664. led = ipw_register_toggle(led);
  665. IPW_DEBUG_LED("Reg: 0x%08X\n", led);
  666. ipw_write_reg32(priv, IPW_EVENT_REG, led);
  667. IPW_DEBUG_LED("Activity LED On\n");
  668. priv->status |= STATUS_LED_ACT_ON;
  669. cancel_delayed_work(&priv->led_act_off);
  670. queue_delayed_work(priv->workqueue, &priv->led_act_off,
  671. LD_TIME_ACT_ON);
  672. } else {
  673. /* Reschedule LED off for full time period */
  674. cancel_delayed_work(&priv->led_act_off);
  675. queue_delayed_work(priv->workqueue, &priv->led_act_off,
  676. LD_TIME_ACT_ON);
  677. }
  678. }
  679. void ipw_led_activity_on(struct ipw_priv *priv)
  680. {
  681. unsigned long flags;
  682. spin_lock_irqsave(&priv->lock, flags);
  683. __ipw_led_activity_on(priv);
  684. spin_unlock_irqrestore(&priv->lock, flags);
  685. }
  686. void ipw_led_activity_off(struct ipw_priv *priv)
  687. {
  688. unsigned long flags;
  689. u32 led;
  690. if (priv->config & CFG_NO_LED)
  691. return;
  692. spin_lock_irqsave(&priv->lock, flags);
  693. if (priv->status & STATUS_LED_ACT_ON) {
  694. led = ipw_read_reg32(priv, IPW_EVENT_REG);
  695. led &= priv->led_activity_off;
  696. led = ipw_register_toggle(led);
  697. IPW_DEBUG_LED("Reg: 0x%08X\n", led);
  698. ipw_write_reg32(priv, IPW_EVENT_REG, led);
  699. IPW_DEBUG_LED("Activity LED Off\n");
  700. priv->status &= ~STATUS_LED_ACT_ON;
  701. }
  702. spin_unlock_irqrestore(&priv->lock, flags);
  703. }
  704. static void ipw_bg_led_activity_off(void *data)
  705. {
  706. struct ipw_priv *priv = data;
  707. down(&priv->sem);
  708. ipw_led_activity_off(data);
  709. up(&priv->sem);
  710. }
  711. void ipw_led_band_on(struct ipw_priv *priv)
  712. {
  713. unsigned long flags;
  714. u32 led;
  715. /* Only nic type 1 supports mode LEDs */
  716. if (priv->config & CFG_NO_LED ||
  717. priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
  718. return;
  719. spin_lock_irqsave(&priv->lock, flags);
  720. led = ipw_read_reg32(priv, IPW_EVENT_REG);
  721. if (priv->assoc_network->mode == IEEE_A) {
  722. led |= priv->led_ofdm_on;
  723. led &= priv->led_association_off;
  724. IPW_DEBUG_LED("Mode LED On: 802.11a\n");
  725. } else if (priv->assoc_network->mode == IEEE_G) {
  726. led |= priv->led_ofdm_on;
  727. led |= priv->led_association_on;
  728. IPW_DEBUG_LED("Mode LED On: 802.11g\n");
  729. } else {
  730. led &= priv->led_ofdm_off;
  731. led |= priv->led_association_on;
  732. IPW_DEBUG_LED("Mode LED On: 802.11b\n");
  733. }
  734. led = ipw_register_toggle(led);
  735. IPW_DEBUG_LED("Reg: 0x%08X\n", led);
  736. ipw_write_reg32(priv, IPW_EVENT_REG, led);
  737. spin_unlock_irqrestore(&priv->lock, flags);
  738. }
  739. void ipw_led_band_off(struct ipw_priv *priv)
  740. {
  741. unsigned long flags;
  742. u32 led;
  743. /* Only nic type 1 supports mode LEDs */
  744. if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
  745. return;
  746. spin_lock_irqsave(&priv->lock, flags);
  747. led = ipw_read_reg32(priv, IPW_EVENT_REG);
  748. led &= priv->led_ofdm_off;
  749. led &= priv->led_association_off;
  750. led = ipw_register_toggle(led);
  751. IPW_DEBUG_LED("Reg: 0x%08X\n", led);
  752. ipw_write_reg32(priv, IPW_EVENT_REG, led);
  753. spin_unlock_irqrestore(&priv->lock, flags);
  754. }
  755. void ipw_led_radio_on(struct ipw_priv *priv)
  756. {
  757. ipw_led_link_on(priv);
  758. }
  759. void ipw_led_radio_off(struct ipw_priv *priv)
  760. {
  761. ipw_led_activity_off(priv);
  762. ipw_led_link_off(priv);
  763. }
  764. void ipw_led_link_up(struct ipw_priv *priv)
  765. {
  766. /* Set the Link Led on for all nic types */
  767. ipw_led_link_on(priv);
  768. }
  769. void ipw_led_link_down(struct ipw_priv *priv)
  770. {
  771. ipw_led_activity_off(priv);
  772. ipw_led_link_off(priv);
  773. if (priv->status & STATUS_RF_KILL_MASK)
  774. ipw_led_radio_off(priv);
  775. }
  776. void ipw_led_init(struct ipw_priv *priv)
  777. {
  778. priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
  779. /* Set the default PINs for the link and activity leds */
  780. priv->led_activity_on = IPW_ACTIVITY_LED;
  781. priv->led_activity_off = ~(IPW_ACTIVITY_LED);
  782. priv->led_association_on = IPW_ASSOCIATED_LED;
  783. priv->led_association_off = ~(IPW_ASSOCIATED_LED);
  784. /* Set the default PINs for the OFDM leds */
  785. priv->led_ofdm_on = IPW_OFDM_LED;
  786. priv->led_ofdm_off = ~(IPW_OFDM_LED);
  787. switch (priv->nic_type) {
  788. case EEPROM_NIC_TYPE_1:
  789. /* In this NIC type, the LEDs are reversed.... */
  790. priv->led_activity_on = IPW_ASSOCIATED_LED;
  791. priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
  792. priv->led_association_on = IPW_ACTIVITY_LED;
  793. priv->led_association_off = ~(IPW_ACTIVITY_LED);
  794. if (!(priv->config & CFG_NO_LED))
  795. ipw_led_band_on(priv);
  796. /* And we don't blink link LEDs for this nic, so
  797. * just return here */
  798. return;
  799. case EEPROM_NIC_TYPE_3:
  800. case EEPROM_NIC_TYPE_2:
  801. case EEPROM_NIC_TYPE_4:
  802. case EEPROM_NIC_TYPE_0:
  803. break;
  804. default:
  805. IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
  806. priv->nic_type);
  807. priv->nic_type = EEPROM_NIC_TYPE_0;
  808. break;
  809. }
  810. if (!(priv->config & CFG_NO_LED)) {
  811. if (priv->status & STATUS_ASSOCIATED)
  812. ipw_led_link_on(priv);
  813. else
  814. ipw_led_link_off(priv);
  815. }
  816. }
  817. void ipw_led_shutdown(struct ipw_priv *priv)
  818. {
  819. ipw_led_activity_off(priv);
  820. ipw_led_link_off(priv);
  821. ipw_led_band_off(priv);
  822. cancel_delayed_work(&priv->led_link_on);
  823. cancel_delayed_work(&priv->led_link_off);
  824. cancel_delayed_work(&priv->led_act_off);
  825. }
  826. /*
  827. * The following adds a new attribute to the sysfs representation
  828. * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
  829. * used for controling the debug level.
  830. *
  831. * See the level definitions in ipw for details.
  832. */
  833. static ssize_t show_debug_level(struct device_driver *d, char *buf)
  834. {
  835. return sprintf(buf, "0x%08X\n", ipw_debug_level);
  836. }
  837. static ssize_t store_debug_level(struct device_driver *d, const char *buf,
  838. size_t count)
  839. {
  840. char *p = (char *)buf;
  841. u32 val;
  842. if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
  843. p++;
  844. if (p[0] == 'x' || p[0] == 'X')
  845. p++;
  846. val = simple_strtoul(p, &p, 16);
  847. } else
  848. val = simple_strtoul(p, &p, 10);
  849. if (p == buf)
  850. printk(KERN_INFO DRV_NAME
  851. ": %s is not in hex or decimal form.\n", buf);
  852. else
  853. ipw_debug_level = val;
  854. return strnlen(buf, count);
  855. }
  856. static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
  857. show_debug_level, store_debug_level);
  858. static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
  859. char *buf)
  860. {
  861. struct ipw_priv *priv = dev_get_drvdata(d);
  862. return sprintf(buf, "%d\n", priv->ieee->scan_age);
  863. }
  864. static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
  865. const char *buf, size_t count)
  866. {
  867. struct ipw_priv *priv = dev_get_drvdata(d);
  868. #ifdef CONFIG_IPW_DEBUG
  869. struct net_device *dev = priv->net_dev;
  870. #endif
  871. char buffer[] = "00000000";
  872. unsigned long len =
  873. (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
  874. unsigned long val;
  875. char *p = buffer;
  876. IPW_DEBUG_INFO("enter\n");
  877. strncpy(buffer, buf, len);
  878. buffer[len] = 0;
  879. if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
  880. p++;
  881. if (p[0] == 'x' || p[0] == 'X')
  882. p++;
  883. val = simple_strtoul(p, &p, 16);
  884. } else
  885. val = simple_strtoul(p, &p, 10);
  886. if (p == buffer) {
  887. IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
  888. } else {
  889. priv->ieee->scan_age = val;
  890. IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
  891. }
  892. IPW_DEBUG_INFO("exit\n");
  893. return len;
  894. }
  895. static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
  896. static ssize_t show_led(struct device *d, struct device_attribute *attr,
  897. char *buf)
  898. {
  899. struct ipw_priv *priv = dev_get_drvdata(d);
  900. return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
  901. }
  902. static ssize_t store_led(struct device *d, struct device_attribute *attr,
  903. const char *buf, size_t count)
  904. {
  905. struct ipw_priv *priv = dev_get_drvdata(d);
  906. IPW_DEBUG_INFO("enter\n");
  907. if (count == 0)
  908. return 0;
  909. if (*buf == 0) {
  910. IPW_DEBUG_LED("Disabling LED control.\n");
  911. priv->config |= CFG_NO_LED;
  912. ipw_led_shutdown(priv);
  913. } else {
  914. IPW_DEBUG_LED("Enabling LED control.\n");
  915. priv->config &= ~CFG_NO_LED;
  916. ipw_led_init(priv);
  917. }
  918. IPW_DEBUG_INFO("exit\n");
  919. return count;
  920. }
  921. static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
  922. static ssize_t show_status(struct device *d,
  923. struct device_attribute *attr, char *buf)
  924. {
  925. struct ipw_priv *p = d->driver_data;
  926. return sprintf(buf, "0x%08x\n", (int)p->status);
  927. }
  928. static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
  929. static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
  930. char *buf)
  931. {
  932. struct ipw_priv *p = d->driver_data;
  933. return sprintf(buf, "0x%08x\n", (int)p->config);
  934. }
  935. static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
  936. static ssize_t show_nic_type(struct device *d,
  937. struct device_attribute *attr, char *buf)
  938. {
  939. struct ipw_priv *priv = d->driver_data;
  940. return sprintf(buf, "TYPE: %d\n", priv->nic_type);
  941. }
  942. static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
  943. static ssize_t dump_error_log(struct device *d,
  944. struct device_attribute *attr, const char *buf,
  945. size_t count)
  946. {
  947. char *p = (char *)buf;
  948. if (p[0] == '1')
  949. ipw_dump_nic_error_log((struct ipw_priv *)d->driver_data);
  950. return strnlen(buf, count);
  951. }
  952. static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
  953. static ssize_t dump_event_log(struct device *d,
  954. struct device_attribute *attr, const char *buf,
  955. size_t count)
  956. {
  957. char *p = (char *)buf;
  958. if (p[0] == '1')
  959. ipw_dump_nic_event_log((struct ipw_priv *)d->driver_data);
  960. return strnlen(buf, count);
  961. }
  962. static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
  963. static ssize_t show_ucode_version(struct device *d,
  964. struct device_attribute *attr, char *buf)
  965. {
  966. u32 len = sizeof(u32), tmp = 0;
  967. struct ipw_priv *p = d->driver_data;
  968. if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
  969. return 0;
  970. return sprintf(buf, "0x%08x\n", tmp);
  971. }
  972. static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
  973. static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
  974. char *buf)
  975. {
  976. u32 len = sizeof(u32), tmp = 0;
  977. struct ipw_priv *p = d->driver_data;
  978. if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
  979. return 0;
  980. return sprintf(buf, "0x%08x\n", tmp);
  981. }
  982. static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
  983. /*
  984. * Add a device attribute to view/control the delay between eeprom
  985. * operations.
  986. */
  987. static ssize_t show_eeprom_delay(struct device *d,
  988. struct device_attribute *attr, char *buf)
  989. {
  990. int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
  991. return sprintf(buf, "%i\n", n);
  992. }
  993. static ssize_t store_eeprom_delay(struct device *d,
  994. struct device_attribute *attr,
  995. const char *buf, size_t count)
  996. {
  997. struct ipw_priv *p = d->driver_data;
  998. sscanf(buf, "%i", &p->eeprom_delay);
  999. return strnlen(buf, count);
  1000. }
  1001. static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
  1002. show_eeprom_delay, store_eeprom_delay);
  1003. static ssize_t show_command_event_reg(struct device *d,
  1004. struct device_attribute *attr, char *buf)
  1005. {
  1006. u32 reg = 0;
  1007. struct ipw_priv *p = d->driver_data;
  1008. reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
  1009. return sprintf(buf, "0x%08x\n", reg);
  1010. }
  1011. static ssize_t store_command_event_reg(struct device *d,
  1012. struct device_attribute *attr,
  1013. const char *buf, size_t count)
  1014. {
  1015. u32 reg;
  1016. struct ipw_priv *p = d->driver_data;
  1017. sscanf(buf, "%x", &reg);
  1018. ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
  1019. return strnlen(buf, count);
  1020. }
  1021. static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
  1022. show_command_event_reg, store_command_event_reg);
  1023. static ssize_t show_mem_gpio_reg(struct device *d,
  1024. struct device_attribute *attr, char *buf)
  1025. {
  1026. u32 reg = 0;
  1027. struct ipw_priv *p = d->driver_data;
  1028. reg = ipw_read_reg32(p, 0x301100);
  1029. return sprintf(buf, "0x%08x\n", reg);
  1030. }
  1031. static ssize_t store_mem_gpio_reg(struct device *d,
  1032. struct device_attribute *attr,
  1033. const char *buf, size_t count)
  1034. {
  1035. u32 reg;
  1036. struct ipw_priv *p = d->driver_data;
  1037. sscanf(buf, "%x", &reg);
  1038. ipw_write_reg32(p, 0x301100, reg);
  1039. return strnlen(buf, count);
  1040. }
  1041. static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
  1042. show_mem_gpio_reg, store_mem_gpio_reg);
  1043. static ssize_t show_indirect_dword(struct device *d,
  1044. struct device_attribute *attr, char *buf)
  1045. {
  1046. u32 reg = 0;
  1047. struct ipw_priv *priv = d->driver_data;
  1048. if (priv->status & STATUS_INDIRECT_DWORD)
  1049. reg = ipw_read_reg32(priv, priv->indirect_dword);
  1050. else
  1051. reg = 0;
  1052. return sprintf(buf, "0x%08x\n", reg);
  1053. }
  1054. static ssize_t store_indirect_dword(struct device *d,
  1055. struct device_attribute *attr,
  1056. const char *buf, size_t count)
  1057. {
  1058. struct ipw_priv *priv = d->driver_data;
  1059. sscanf(buf, "%x", &priv->indirect_dword);
  1060. priv->status |= STATUS_INDIRECT_DWORD;
  1061. return strnlen(buf, count);
  1062. }
  1063. static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
  1064. show_indirect_dword, store_indirect_dword);
  1065. static ssize_t show_indirect_byte(struct device *d,
  1066. struct device_attribute *attr, char *buf)
  1067. {
  1068. u8 reg = 0;
  1069. struct ipw_priv *priv = d->driver_data;
  1070. if (priv->status & STATUS_INDIRECT_BYTE)
  1071. reg = ipw_read_reg8(priv, priv->indirect_byte);
  1072. else
  1073. reg = 0;
  1074. return sprintf(buf, "0x%02x\n", reg);
  1075. }
  1076. static ssize_t store_indirect_byte(struct device *d,
  1077. struct device_attribute *attr,
  1078. const char *buf, size_t count)
  1079. {
  1080. struct ipw_priv *priv = d->driver_data;
  1081. sscanf(buf, "%x", &priv->indirect_byte);
  1082. priv->status |= STATUS_INDIRECT_BYTE;
  1083. return strnlen(buf, count);
  1084. }
  1085. static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
  1086. show_indirect_byte, store_indirect_byte);
  1087. static ssize_t show_direct_dword(struct device *d,
  1088. struct device_attribute *attr, char *buf)
  1089. {
  1090. u32 reg = 0;
  1091. struct ipw_priv *priv = d->driver_data;
  1092. if (priv->status & STATUS_DIRECT_DWORD)
  1093. reg = ipw_read32(priv, priv->direct_dword);
  1094. else
  1095. reg = 0;
  1096. return sprintf(buf, "0x%08x\n", reg);
  1097. }
  1098. static ssize_t store_direct_dword(struct device *d,
  1099. struct device_attribute *attr,
  1100. const char *buf, size_t count)
  1101. {
  1102. struct ipw_priv *priv = d->driver_data;
  1103. sscanf(buf, "%x", &priv->direct_dword);
  1104. priv->status |= STATUS_DIRECT_DWORD;
  1105. return strnlen(buf, count);
  1106. }
  1107. static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
  1108. show_direct_dword, store_direct_dword);
  1109. static inline int rf_kill_active(struct ipw_priv *priv)
  1110. {
  1111. if (0 == (ipw_read32(priv, 0x30) & 0x10000))
  1112. priv->status |= STATUS_RF_KILL_HW;
  1113. else
  1114. priv->status &= ~STATUS_RF_KILL_HW;
  1115. return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
  1116. }
  1117. static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
  1118. char *buf)
  1119. {
  1120. /* 0 - RF kill not enabled
  1121. 1 - SW based RF kill active (sysfs)
  1122. 2 - HW based RF kill active
  1123. 3 - Both HW and SW baed RF kill active */
  1124. struct ipw_priv *priv = d->driver_data;
  1125. int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
  1126. (rf_kill_active(priv) ? 0x2 : 0x0);
  1127. return sprintf(buf, "%i\n", val);
  1128. }
  1129. static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
  1130. {
  1131. if ((disable_radio ? 1 : 0) ==
  1132. ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
  1133. return 0;
  1134. IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
  1135. disable_radio ? "OFF" : "ON");
  1136. if (disable_radio) {
  1137. priv->status |= STATUS_RF_KILL_SW;
  1138. if (priv->workqueue)
  1139. cancel_delayed_work(&priv->request_scan);
  1140. queue_work(priv->workqueue, &priv->down);
  1141. } else {
  1142. priv->status &= ~STATUS_RF_KILL_SW;
  1143. if (rf_kill_active(priv)) {
  1144. IPW_DEBUG_RF_KILL("Can not turn radio back on - "
  1145. "disabled by HW switch\n");
  1146. /* Make sure the RF_KILL check timer is running */
  1147. cancel_delayed_work(&priv->rf_kill);
  1148. queue_delayed_work(priv->workqueue, &priv->rf_kill,
  1149. 2 * HZ);
  1150. } else
  1151. queue_work(priv->workqueue, &priv->up);
  1152. }
  1153. return 1;
  1154. }
  1155. static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
  1156. const char *buf, size_t count)
  1157. {
  1158. struct ipw_priv *priv = d->driver_data;
  1159. ipw_radio_kill_sw(priv, buf[0] == '1');
  1160. return count;
  1161. }
  1162. static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
  1163. static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
  1164. char *buf)
  1165. {
  1166. struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
  1167. int pos = 0, len = 0;
  1168. if (priv->config & CFG_SPEED_SCAN) {
  1169. while (priv->speed_scan[pos] != 0)
  1170. len += sprintf(&buf[len], "%d ",
  1171. priv->speed_scan[pos++]);
  1172. return len + sprintf(&buf[len], "\n");
  1173. }
  1174. return sprintf(buf, "0\n");
  1175. }
  1176. static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
  1177. const char *buf, size_t count)
  1178. {
  1179. struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
  1180. int channel, pos = 0;
  1181. const char *p = buf;
  1182. /* list of space separated channels to scan, optionally ending with 0 */
  1183. while ((channel = simple_strtol(p, NULL, 0))) {
  1184. if (pos == MAX_SPEED_SCAN - 1) {
  1185. priv->speed_scan[pos] = 0;
  1186. break;
  1187. }
  1188. if (ieee80211_is_valid_channel(priv->ieee, channel))
  1189. priv->speed_scan[pos++] = channel;
  1190. else
  1191. IPW_WARNING("Skipping invalid channel request: %d\n",
  1192. channel);
  1193. p = strchr(p, ' ');
  1194. if (!p)
  1195. break;
  1196. while (*p == ' ' || *p == '\t')
  1197. p++;
  1198. }
  1199. if (pos == 0)
  1200. priv->config &= ~CFG_SPEED_SCAN;
  1201. else {
  1202. priv->speed_scan_pos = 0;
  1203. priv->config |= CFG_SPEED_SCAN;
  1204. }
  1205. return count;
  1206. }
  1207. static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
  1208. store_speed_scan);
  1209. static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
  1210. char *buf)
  1211. {
  1212. struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
  1213. return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
  1214. }
  1215. static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
  1216. const char *buf, size_t count)
  1217. {
  1218. struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
  1219. if (buf[0] == '1')
  1220. priv->config |= CFG_NET_STATS;
  1221. else
  1222. priv->config &= ~CFG_NET_STATS;
  1223. return count;
  1224. }
  1225. static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
  1226. show_net_stats, store_net_stats);
  1227. static void notify_wx_assoc_event(struct ipw_priv *priv)
  1228. {
  1229. union iwreq_data wrqu;
  1230. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  1231. if (priv->status & STATUS_ASSOCIATED)
  1232. memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
  1233. else
  1234. memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
  1235. wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
  1236. }
  1237. static void ipw_irq_tasklet(struct ipw_priv *priv)
  1238. {
  1239. u32 inta, inta_mask, handled = 0;
  1240. unsigned long flags;
  1241. int rc = 0;
  1242. spin_lock_irqsave(&priv->lock, flags);
  1243. inta = ipw_read32(priv, IPW_INTA_RW);
  1244. inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
  1245. inta &= (IPW_INTA_MASK_ALL & inta_mask);
  1246. /* Add any cached INTA values that need to be handled */
  1247. inta |= priv->isr_inta;
  1248. /* handle all the justifications for the interrupt */
  1249. if (inta & IPW_INTA_BIT_RX_TRANSFER) {
  1250. ipw_rx(priv);
  1251. handled |= IPW_INTA_BIT_RX_TRANSFER;
  1252. }
  1253. if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
  1254. IPW_DEBUG_HC("Command completed.\n");
  1255. rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
  1256. priv->status &= ~STATUS_HCMD_ACTIVE;
  1257. wake_up_interruptible(&priv->wait_command_queue);
  1258. handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
  1259. }
  1260. if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
  1261. IPW_DEBUG_TX("TX_QUEUE_1\n");
  1262. rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
  1263. handled |= IPW_INTA_BIT_TX_QUEUE_1;
  1264. }
  1265. if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
  1266. IPW_DEBUG_TX("TX_QUEUE_2\n");
  1267. rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
  1268. handled |= IPW_INTA_BIT_TX_QUEUE_2;
  1269. }
  1270. if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
  1271. IPW_DEBUG_TX("TX_QUEUE_3\n");
  1272. rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
  1273. handled |= IPW_INTA_BIT_TX_QUEUE_3;
  1274. }
  1275. if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
  1276. IPW_DEBUG_TX("TX_QUEUE_4\n");
  1277. rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
  1278. handled |= IPW_INTA_BIT_TX_QUEUE_4;
  1279. }
  1280. if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
  1281. IPW_WARNING("STATUS_CHANGE\n");
  1282. handled |= IPW_INTA_BIT_STATUS_CHANGE;
  1283. }
  1284. if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
  1285. IPW_WARNING("TX_PERIOD_EXPIRED\n");
  1286. handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
  1287. }
  1288. if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
  1289. IPW_WARNING("HOST_CMD_DONE\n");
  1290. handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
  1291. }
  1292. if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
  1293. IPW_WARNING("FW_INITIALIZATION_DONE\n");
  1294. handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
  1295. }
  1296. if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
  1297. IPW_WARNING("PHY_OFF_DONE\n");
  1298. handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
  1299. }
  1300. if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
  1301. IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
  1302. priv->status |= STATUS_RF_KILL_HW;
  1303. wake_up_interruptible(&priv->wait_command_queue);
  1304. priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
  1305. cancel_delayed_work(&priv->request_scan);
  1306. schedule_work(&priv->link_down);
  1307. queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
  1308. handled |= IPW_INTA_BIT_RF_KILL_DONE;
  1309. }
  1310. if (inta & IPW_INTA_BIT_FATAL_ERROR) {
  1311. IPW_ERROR("Firmware error detected. Restarting.\n");
  1312. #ifdef CONFIG_IPW_DEBUG
  1313. if (ipw_debug_level & IPW_DL_FW_ERRORS) {
  1314. ipw_dump_nic_error_log(priv);
  1315. ipw_dump_nic_event_log(priv);
  1316. }
  1317. #endif
  1318. /* XXX: If hardware encryption is for WPA/WPA2,
  1319. * we have to notify the supplicant. */
  1320. if (priv->ieee->sec.encrypt) {
  1321. priv->status &= ~STATUS_ASSOCIATED;
  1322. notify_wx_assoc_event(priv);
  1323. }
  1324. /* Keep the restart process from trying to send host
  1325. * commands by clearing the INIT status bit */
  1326. priv->status &= ~STATUS_INIT;
  1327. /* Cancel currently queued command. */
  1328. priv->status &= ~STATUS_HCMD_ACTIVE;
  1329. wake_up_interruptible(&priv->wait_command_queue);
  1330. queue_work(priv->workqueue, &priv->adapter_restart);
  1331. handled |= IPW_INTA_BIT_FATAL_ERROR;
  1332. }
  1333. if (inta & IPW_INTA_BIT_PARITY_ERROR) {
  1334. IPW_ERROR("Parity error\n");
  1335. handled |= IPW_INTA_BIT_PARITY_ERROR;
  1336. }
  1337. if (handled != inta) {
  1338. IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
  1339. }
  1340. /* enable all interrupts */
  1341. ipw_enable_interrupts(priv);
  1342. spin_unlock_irqrestore(&priv->lock, flags);
  1343. }
  1344. #ifdef CONFIG_IPW_DEBUG
  1345. #define IPW_CMD(x) case IPW_CMD_ ## x : return #x
  1346. static char *get_cmd_string(u8 cmd)
  1347. {
  1348. switch (cmd) {
  1349. IPW_CMD(HOST_COMPLETE);
  1350. IPW_CMD(POWER_DOWN);
  1351. IPW_CMD(SYSTEM_CONFIG);
  1352. IPW_CMD(MULTICAST_ADDRESS);
  1353. IPW_CMD(SSID);
  1354. IPW_CMD(ADAPTER_ADDRESS);
  1355. IPW_CMD(PORT_TYPE);
  1356. IPW_CMD(RTS_THRESHOLD);
  1357. IPW_CMD(FRAG_THRESHOLD);
  1358. IPW_CMD(POWER_MODE);
  1359. IPW_CMD(WEP_KEY);
  1360. IPW_CMD(TGI_TX_KEY);
  1361. IPW_CMD(SCAN_REQUEST);
  1362. IPW_CMD(SCAN_REQUEST_EXT);
  1363. IPW_CMD(ASSOCIATE);
  1364. IPW_CMD(SUPPORTED_RATES);
  1365. IPW_CMD(SCAN_ABORT);
  1366. IPW_CMD(TX_FLUSH);
  1367. IPW_CMD(QOS_PARAMETERS);
  1368. IPW_CMD(DINO_CONFIG);
  1369. IPW_CMD(RSN_CAPABILITIES);
  1370. IPW_CMD(RX_KEY);
  1371. IPW_CMD(CARD_DISABLE);
  1372. IPW_CMD(SEED_NUMBER);
  1373. IPW_CMD(TX_POWER);
  1374. IPW_CMD(COUNTRY_INFO);
  1375. IPW_CMD(AIRONET_INFO);
  1376. IPW_CMD(AP_TX_POWER);
  1377. IPW_CMD(CCKM_INFO);
  1378. IPW_CMD(CCX_VER_INFO);
  1379. IPW_CMD(SET_CALIBRATION);
  1380. IPW_CMD(SENSITIVITY_CALIB);
  1381. IPW_CMD(RETRY_LIMIT);
  1382. IPW_CMD(IPW_PRE_POWER_DOWN);
  1383. IPW_CMD(VAP_BEACON_TEMPLATE);
  1384. IPW_CMD(VAP_DTIM_PERIOD);
  1385. IPW_CMD(EXT_SUPPORTED_RATES);
  1386. IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
  1387. IPW_CMD(VAP_QUIET_INTERVALS);
  1388. IPW_CMD(VAP_CHANNEL_SWITCH);
  1389. IPW_CMD(VAP_MANDATORY_CHANNELS);
  1390. IPW_CMD(VAP_CELL_PWR_LIMIT);
  1391. IPW_CMD(VAP_CF_PARAM_SET);
  1392. IPW_CMD(VAP_SET_BEACONING_STATE);
  1393. IPW_CMD(MEASUREMENT);
  1394. IPW_CMD(POWER_CAPABILITY);
  1395. IPW_CMD(SUPPORTED_CHANNELS);
  1396. IPW_CMD(TPC_REPORT);
  1397. IPW_CMD(WME_INFO);
  1398. IPW_CMD(PRODUCTION_COMMAND);
  1399. default:
  1400. return "UNKNOWN";
  1401. }
  1402. }
  1403. #endif
  1404. #define HOST_COMPLETE_TIMEOUT HZ
  1405. static int ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
  1406. {
  1407. int rc = 0;
  1408. unsigned long flags;
  1409. spin_lock_irqsave(&priv->lock, flags);
  1410. if (priv->status & STATUS_HCMD_ACTIVE) {
  1411. IPW_ERROR("Already sending a command\n");
  1412. spin_unlock_irqrestore(&priv->lock, flags);
  1413. return -1;
  1414. }
  1415. priv->status |= STATUS_HCMD_ACTIVE;
  1416. IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
  1417. get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
  1418. priv->status);
  1419. printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
  1420. rc = ipw_queue_tx_hcmd(priv, cmd->cmd, &cmd->param, cmd->len, 0);
  1421. if (rc) {
  1422. priv->status &= ~STATUS_HCMD_ACTIVE;
  1423. spin_unlock_irqrestore(&priv->lock, flags);
  1424. return rc;
  1425. }
  1426. spin_unlock_irqrestore(&priv->lock, flags);
  1427. rc = wait_event_interruptible_timeout(priv->wait_command_queue,
  1428. !(priv->
  1429. status & STATUS_HCMD_ACTIVE),
  1430. HOST_COMPLETE_TIMEOUT);
  1431. if (rc == 0) {
  1432. spin_lock_irqsave(&priv->lock, flags);
  1433. if (priv->status & STATUS_HCMD_ACTIVE) {
  1434. IPW_DEBUG_INFO("Command completion failed out after "
  1435. "%dms.\n",
  1436. 1000 * (HOST_COMPLETE_TIMEOUT / HZ));
  1437. priv->status &= ~STATUS_HCMD_ACTIVE;
  1438. spin_unlock_irqrestore(&priv->lock, flags);
  1439. return -EIO;
  1440. }
  1441. spin_unlock_irqrestore(&priv->lock, flags);
  1442. }
  1443. if (priv->status & STATUS_RF_KILL_HW) {
  1444. IPW_DEBUG_INFO("Command aborted due to RF Kill Switch\n");
  1445. return -EIO;
  1446. }
  1447. return 0;
  1448. }
  1449. static int ipw_send_host_complete(struct ipw_priv *priv)
  1450. {
  1451. struct host_cmd cmd = {
  1452. .cmd = IPW_CMD_HOST_COMPLETE,
  1453. .len = 0
  1454. };
  1455. if (!priv) {
  1456. IPW_ERROR("Invalid args\n");
  1457. return -1;
  1458. }
  1459. if (ipw_send_cmd(priv, &cmd)) {
  1460. IPW_ERROR("failed to send HOST_COMPLETE command\n");
  1461. return -1;
  1462. }
  1463. return 0;
  1464. }
  1465. static int ipw_send_system_config(struct ipw_priv *priv,
  1466. struct ipw_sys_config *config)
  1467. {
  1468. struct host_cmd cmd = {
  1469. .cmd = IPW_CMD_SYSTEM_CONFIG,
  1470. .len = sizeof(*config)
  1471. };
  1472. if (!priv || !config) {
  1473. IPW_ERROR("Invalid args\n");
  1474. return -1;
  1475. }
  1476. memcpy(cmd.param, config, sizeof(*config));
  1477. if (ipw_send_cmd(priv, &cmd)) {
  1478. IPW_ERROR("failed to send SYSTEM_CONFIG command\n");
  1479. return -1;
  1480. }
  1481. return 0;
  1482. }
  1483. static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
  1484. {
  1485. struct host_cmd cmd = {
  1486. .cmd = IPW_CMD_SSID,
  1487. .len = min(len, IW_ESSID_MAX_SIZE)
  1488. };
  1489. if (!priv || !ssid) {
  1490. IPW_ERROR("Invalid args\n");
  1491. return -1;
  1492. }
  1493. memcpy(cmd.param, ssid, cmd.len);
  1494. if (ipw_send_cmd(priv, &cmd)) {
  1495. IPW_ERROR("failed to send SSID command\n");
  1496. return -1;
  1497. }
  1498. return 0;
  1499. }
  1500. static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
  1501. {
  1502. struct host_cmd cmd = {
  1503. .cmd = IPW_CMD_ADAPTER_ADDRESS,
  1504. .len = ETH_ALEN
  1505. };
  1506. if (!priv || !mac) {
  1507. IPW_ERROR("Invalid args\n");
  1508. return -1;
  1509. }
  1510. IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
  1511. priv->net_dev->name, MAC_ARG(mac));
  1512. memcpy(cmd.param, mac, ETH_ALEN);
  1513. if (ipw_send_cmd(priv, &cmd)) {
  1514. IPW_ERROR("failed to send ADAPTER_ADDRESS command\n");
  1515. return -1;
  1516. }
  1517. return 0;
  1518. }
  1519. /*
  1520. * NOTE: This must be executed from our workqueue as it results in udelay
  1521. * being called which may corrupt the keyboard if executed on default
  1522. * workqueue
  1523. */
  1524. static void ipw_adapter_restart(void *adapter)
  1525. {
  1526. struct ipw_priv *priv = adapter;
  1527. if (priv->status & STATUS_RF_KILL_MASK)
  1528. return;
  1529. ipw_down(priv);
  1530. if (priv->assoc_network &&
  1531. (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
  1532. ipw_remove_current_network(priv);
  1533. if (ipw_up(priv)) {
  1534. IPW_ERROR("Failed to up device\n");
  1535. return;
  1536. }
  1537. }
  1538. static void ipw_bg_adapter_restart(void *data)
  1539. {
  1540. struct ipw_priv *priv = data;
  1541. down(&priv->sem);
  1542. ipw_adapter_restart(data);
  1543. up(&priv->sem);
  1544. }
  1545. #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
  1546. static void ipw_scan_check(void *data)
  1547. {
  1548. struct ipw_priv *priv = data;
  1549. if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
  1550. IPW_DEBUG_SCAN("Scan completion watchdog resetting "
  1551. "adapter (%dms).\n",
  1552. IPW_SCAN_CHECK_WATCHDOG / 100);
  1553. queue_work(priv->workqueue, &priv->adapter_restart);
  1554. }
  1555. }
  1556. static void ipw_bg_scan_check(void *data)
  1557. {
  1558. struct ipw_priv *priv = data;
  1559. down(&priv->sem);
  1560. ipw_scan_check(data);
  1561. up(&priv->sem);
  1562. }
  1563. static int ipw_send_scan_request_ext(struct ipw_priv *priv,
  1564. struct ipw_scan_request_ext *request)
  1565. {
  1566. struct host_cmd cmd = {
  1567. .cmd = IPW_CMD_SCAN_REQUEST_EXT,
  1568. .len = sizeof(*request)
  1569. };
  1570. memcpy(cmd.param, request, sizeof(*request));
  1571. if (ipw_send_cmd(priv, &cmd)) {
  1572. IPW_ERROR("failed to send SCAN_REQUEST_EXT command\n");
  1573. return -1;
  1574. }
  1575. return 0;
  1576. }
  1577. static int ipw_send_scan_abort(struct ipw_priv *priv)
  1578. {
  1579. struct host_cmd cmd = {
  1580. .cmd = IPW_CMD_SCAN_ABORT,
  1581. .len = 0
  1582. };
  1583. if (!priv) {
  1584. IPW_ERROR("Invalid args\n");
  1585. return -1;
  1586. }
  1587. if (ipw_send_cmd(priv, &cmd)) {
  1588. IPW_ERROR("failed to send SCAN_ABORT command\n");
  1589. return -1;
  1590. }
  1591. return 0;
  1592. }
  1593. static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
  1594. {
  1595. struct host_cmd cmd = {
  1596. .cmd = IPW_CMD_SENSITIVITY_CALIB,
  1597. .len = sizeof(struct ipw_sensitivity_calib)
  1598. };
  1599. struct ipw_sensitivity_calib *calib = (struct ipw_sensitivity_calib *)
  1600. &cmd.param;
  1601. calib->beacon_rssi_raw = sens;
  1602. if (ipw_send_cmd(priv, &cmd)) {
  1603. IPW_ERROR("failed to send SENSITIVITY CALIB command\n");
  1604. return -1;
  1605. }
  1606. return 0;
  1607. }
  1608. static int ipw_send_associate(struct ipw_priv *priv,
  1609. struct ipw_associate *associate)
  1610. {
  1611. struct host_cmd cmd = {
  1612. .cmd = IPW_CMD_ASSOCIATE,
  1613. .len = sizeof(*associate)
  1614. };
  1615. struct ipw_associate tmp_associate;
  1616. memcpy(&tmp_associate, associate, sizeof(*associate));
  1617. tmp_associate.policy_support =
  1618. cpu_to_le16(tmp_associate.policy_support);
  1619. tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
  1620. tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
  1621. tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
  1622. tmp_associate.listen_interval =
  1623. cpu_to_le16(tmp_associate.listen_interval);
  1624. tmp_associate.beacon_interval =
  1625. cpu_to_le16(tmp_associate.beacon_interval);
  1626. tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
  1627. if (!priv || !associate) {
  1628. IPW_ERROR("Invalid args\n");
  1629. return -1;
  1630. }
  1631. memcpy(cmd.param, &tmp_associate, sizeof(*associate));
  1632. if (ipw_send_cmd(priv, &cmd)) {
  1633. IPW_ERROR("failed to send ASSOCIATE command\n");
  1634. return -1;
  1635. }
  1636. return 0;
  1637. }
  1638. static int ipw_send_supported_rates(struct ipw_priv *priv,
  1639. struct ipw_supported_rates *rates)
  1640. {
  1641. struct host_cmd cmd = {
  1642. .cmd = IPW_CMD_SUPPORTED_RATES,
  1643. .len = sizeof(*rates)
  1644. };
  1645. if (!priv || !rates) {
  1646. IPW_ERROR("Invalid args\n");
  1647. return -1;
  1648. }
  1649. memcpy(cmd.param, rates, sizeof(*rates));
  1650. if (ipw_send_cmd(priv, &cmd)) {
  1651. IPW_ERROR("failed to send SUPPORTED_RATES command\n");
  1652. return -1;
  1653. }
  1654. return 0;
  1655. }
  1656. static int ipw_set_random_seed(struct ipw_priv *priv)
  1657. {
  1658. struct host_cmd cmd = {
  1659. .cmd = IPW_CMD_SEED_NUMBER,
  1660. .len = sizeof(u32)
  1661. };
  1662. if (!priv) {
  1663. IPW_ERROR("Invalid args\n");
  1664. return -1;
  1665. }
  1666. get_random_bytes(&cmd.param, sizeof(u32));
  1667. if (ipw_send_cmd(priv, &cmd)) {
  1668. IPW_ERROR("failed to send SEED_NUMBER command\n");
  1669. return -1;
  1670. }
  1671. return 0;
  1672. }
  1673. static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
  1674. {
  1675. struct host_cmd cmd = {
  1676. .cmd = IPW_CMD_CARD_DISABLE,
  1677. .len = sizeof(u32)
  1678. };
  1679. if (!priv) {
  1680. IPW_ERROR("Invalid args\n");
  1681. return -1;
  1682. }
  1683. *((u32 *) & cmd.param) = phy_off;
  1684. if (ipw_send_cmd(priv, &cmd)) {
  1685. IPW_ERROR("failed to send CARD_DISABLE command\n");
  1686. return -1;
  1687. }
  1688. return 0;
  1689. }
  1690. static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
  1691. {
  1692. struct host_cmd cmd = {
  1693. .cmd = IPW_CMD_TX_POWER,
  1694. .len = sizeof(*power)
  1695. };
  1696. if (!priv || !power) {
  1697. IPW_ERROR("Invalid args\n");
  1698. return -1;
  1699. }
  1700. memcpy(cmd.param, power, sizeof(*power));
  1701. if (ipw_send_cmd(priv, &cmd)) {
  1702. IPW_ERROR("failed to send TX_POWER command\n");
  1703. return -1;
  1704. }
  1705. return 0;
  1706. }
  1707. static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
  1708. {
  1709. struct ipw_rts_threshold rts_threshold = {
  1710. .rts_threshold = rts,
  1711. };
  1712. struct host_cmd cmd = {
  1713. .cmd = IPW_CMD_RTS_THRESHOLD,
  1714. .len = sizeof(rts_threshold)
  1715. };
  1716. if (!priv) {
  1717. IPW_ERROR("Invalid args\n");
  1718. return -1;
  1719. }
  1720. memcpy(cmd.param, &rts_threshold, sizeof(rts_threshold));
  1721. if (ipw_send_cmd(priv, &cmd)) {
  1722. IPW_ERROR("failed to send RTS_THRESHOLD command\n");
  1723. return -1;
  1724. }
  1725. return 0;
  1726. }
  1727. static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
  1728. {
  1729. struct ipw_frag_threshold frag_threshold = {
  1730. .frag_threshold = frag,
  1731. };
  1732. struct host_cmd cmd = {
  1733. .cmd = IPW_CMD_FRAG_THRESHOLD,
  1734. .len = sizeof(frag_threshold)
  1735. };
  1736. if (!priv) {
  1737. IPW_ERROR("Invalid args\n");
  1738. return -1;
  1739. }
  1740. memcpy(cmd.param, &frag_threshold, sizeof(frag_threshold));
  1741. if (ipw_send_cmd(priv, &cmd)) {
  1742. IPW_ERROR("failed to send FRAG_THRESHOLD command\n");
  1743. return -1;
  1744. }
  1745. return 0;
  1746. }
  1747. static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
  1748. {
  1749. struct host_cmd cmd = {
  1750. .cmd = IPW_CMD_POWER_MODE,
  1751. .len = sizeof(u32)
  1752. };
  1753. u32 *param = (u32 *) (&cmd.param);
  1754. if (!priv) {
  1755. IPW_ERROR("Invalid args\n");
  1756. return -1;
  1757. }
  1758. /* If on battery, set to 3, if AC set to CAM, else user
  1759. * level */
  1760. switch (mode) {
  1761. case IPW_POWER_BATTERY:
  1762. *param = IPW_POWER_INDEX_3;
  1763. break;
  1764. case IPW_POWER_AC:
  1765. *param = IPW_POWER_MODE_CAM;
  1766. break;
  1767. default:
  1768. *param = mode;
  1769. break;
  1770. }
  1771. if (ipw_send_cmd(priv, &cmd)) {
  1772. IPW_ERROR("failed to send POWER_MODE command\n");
  1773. return -1;
  1774. }
  1775. return 0;
  1776. }
  1777. static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
  1778. {
  1779. struct ipw_retry_limit retry_limit = {
  1780. .short_retry_limit = slimit,
  1781. .long_retry_limit = llimit
  1782. };
  1783. struct host_cmd cmd = {
  1784. .cmd = IPW_CMD_RETRY_LIMIT,
  1785. .len = sizeof(retry_limit)
  1786. };
  1787. if (!priv) {
  1788. IPW_ERROR("Invalid args\n");
  1789. return -1;
  1790. }
  1791. memcpy(cmd.param, &retry_limit, sizeof(retry_limit));
  1792. if (ipw_send_cmd(priv, &cmd)) {
  1793. IPW_ERROR("failed to send RETRY_LIMIT command\n");
  1794. return -1;
  1795. }
  1796. return 0;
  1797. }
  1798. /*
  1799. * The IPW device contains a Microwire compatible EEPROM that stores
  1800. * various data like the MAC address. Usually the firmware has exclusive
  1801. * access to the eeprom, but during device initialization (before the
  1802. * device driver has sent the HostComplete command to the firmware) the
  1803. * device driver has read access to the EEPROM by way of indirect addressing
  1804. * through a couple of memory mapped registers.
  1805. *
  1806. * The following is a simplified implementation for pulling data out of the
  1807. * the eeprom, along with some helper functions to find information in
  1808. * the per device private data's copy of the eeprom.
  1809. *
  1810. * NOTE: To better understand how these functions work (i.e what is a chip
  1811. * select and why do have to keep driving the eeprom clock?), read
  1812. * just about any data sheet for a Microwire compatible EEPROM.
  1813. */
  1814. /* write a 32 bit value into the indirect accessor register */
  1815. static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
  1816. {
  1817. ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
  1818. /* the eeprom requires some time to complete the operation */
  1819. udelay(p->eeprom_delay);
  1820. return;
  1821. }
  1822. /* perform a chip select operation */
  1823. static inline void eeprom_cs(struct ipw_priv *priv)
  1824. {
  1825. eeprom_write_reg(priv, 0);
  1826. eeprom_write_reg(priv, EEPROM_BIT_CS);
  1827. eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
  1828. eeprom_write_reg(priv, EEPROM_BIT_CS);
  1829. }
  1830. /* perform a chip select operation */
  1831. static inline void eeprom_disable_cs(struct ipw_priv *priv)
  1832. {
  1833. eeprom_write_reg(priv, EEPROM_BIT_CS);
  1834. eeprom_write_reg(priv, 0);
  1835. eeprom_write_reg(priv, EEPROM_BIT_SK);
  1836. }
  1837. /* push a single bit down to the eeprom */
  1838. static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
  1839. {
  1840. int d = (bit ? EEPROM_BIT_DI : 0);
  1841. eeprom_write_reg(p, EEPROM_BIT_CS | d);
  1842. eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
  1843. }
  1844. /* push an opcode followed by an address down to the eeprom */
  1845. static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
  1846. {
  1847. int i;
  1848. eeprom_cs(priv);
  1849. eeprom_write_bit(priv, 1);
  1850. eeprom_write_bit(priv, op & 2);
  1851. eeprom_write_bit(priv, op & 1);
  1852. for (i = 7; i >= 0; i--) {
  1853. eeprom_write_bit(priv, addr & (1 << i));
  1854. }
  1855. }
  1856. /* pull 16 bits off the eeprom, one bit at a time */
  1857. static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
  1858. {
  1859. int i;
  1860. u16 r = 0;
  1861. /* Send READ Opcode */
  1862. eeprom_op(priv, EEPROM_CMD_READ, addr);
  1863. /* Send dummy bit */
  1864. eeprom_write_reg(priv, EEPROM_BIT_CS);
  1865. /* Read the byte off the eeprom one bit at a time */
  1866. for (i = 0; i < 16; i++) {
  1867. u32 data = 0;
  1868. eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
  1869. eeprom_write_reg(priv, EEPROM_BIT_CS);
  1870. data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
  1871. r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
  1872. }
  1873. /* Send another dummy bit */
  1874. eeprom_write_reg(priv, 0);
  1875. eeprom_disable_cs(priv);
  1876. return r;
  1877. }
  1878. /* helper function for pulling the mac address out of the private */
  1879. /* data's copy of the eeprom data */
  1880. static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
  1881. {
  1882. memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
  1883. }
  1884. /*
  1885. * Either the device driver (i.e. the host) or the firmware can
  1886. * load eeprom data into the designated region in SRAM. If neither
  1887. * happens then the FW will shutdown with a fatal error.
  1888. *
  1889. * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
  1890. * bit needs region of shared SRAM needs to be non-zero.
  1891. */
  1892. static void ipw_eeprom_init_sram(struct ipw_priv *priv)
  1893. {
  1894. int i;
  1895. u16 *eeprom = (u16 *) priv->eeprom;
  1896. IPW_DEBUG_TRACE(">>\n");
  1897. /* read entire contents of eeprom into private buffer */
  1898. for (i = 0; i < 128; i++)
  1899. eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
  1900. /*
  1901. If the data looks correct, then copy it to our private
  1902. copy. Otherwise let the firmware know to perform the operation
  1903. on it's own
  1904. */
  1905. if ((priv->eeprom + EEPROM_VERSION) != 0) {
  1906. IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
  1907. /* write the eeprom data to sram */
  1908. for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
  1909. ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
  1910. /* Do not load eeprom data on fatal error or suspend */
  1911. ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
  1912. } else {
  1913. IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
  1914. /* Load eeprom data on fatal error or suspend */
  1915. ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
  1916. }
  1917. IPW_DEBUG_TRACE("<<\n");
  1918. }
  1919. static inline void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
  1920. {
  1921. count >>= 2;
  1922. if (!count)
  1923. return;
  1924. _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
  1925. while (count--)
  1926. _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
  1927. }
  1928. static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
  1929. {
  1930. ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
  1931. CB_NUMBER_OF_ELEMENTS_SMALL *
  1932. sizeof(struct command_block));
  1933. }
  1934. static int ipw_fw_dma_enable(struct ipw_priv *priv)
  1935. { /* start dma engine but no transfers yet */
  1936. IPW_DEBUG_FW(">> : \n");
  1937. /* Start the dma */
  1938. ipw_fw_dma_reset_command_blocks(priv);
  1939. /* Write CB base address */
  1940. ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
  1941. IPW_DEBUG_FW("<< : \n");
  1942. return 0;
  1943. }
  1944. static void ipw_fw_dma_abort(struct ipw_priv *priv)
  1945. {
  1946. u32 control = 0;
  1947. IPW_DEBUG_FW(">> :\n");
  1948. //set the Stop and Abort bit
  1949. control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
  1950. ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
  1951. priv->sram_desc.last_cb_index = 0;
  1952. IPW_DEBUG_FW("<< \n");
  1953. }
  1954. static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
  1955. struct command_block *cb)
  1956. {
  1957. u32 address =
  1958. IPW_SHARED_SRAM_DMA_CONTROL +
  1959. (sizeof(struct command_block) * index);
  1960. IPW_DEBUG_FW(">> :\n");
  1961. ipw_write_indirect(priv, address, (u8 *) cb,
  1962. (int)sizeof(struct command_block));
  1963. IPW_DEBUG_FW("<< :\n");
  1964. return 0;
  1965. }
  1966. static int ipw_fw_dma_kick(struct ipw_priv *priv)
  1967. {
  1968. u32 control = 0;
  1969. u32 index = 0;
  1970. IPW_DEBUG_FW(">> :\n");
  1971. for (index = 0; index < priv->sram_desc.last_cb_index; index++)
  1972. ipw_fw_dma_write_command_block(priv, index,
  1973. &priv->sram_desc.cb_list[index]);
  1974. /* Enable the DMA in the CSR register */
  1975. ipw_clear_bit(priv, IPW_RESET_REG,
  1976. IPW_RESET_REG_MASTER_DISABLED |
  1977. IPW_RESET_REG_STOP_MASTER);
  1978. /* Set the Start bit. */
  1979. control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
  1980. ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
  1981. IPW_DEBUG_FW("<< :\n");
  1982. return 0;
  1983. }
  1984. static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
  1985. {
  1986. u32 address;
  1987. u32 register_value = 0;
  1988. u32 cb_fields_address = 0;
  1989. IPW_DEBUG_FW(">> :\n");
  1990. address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
  1991. IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
  1992. /* Read the DMA Controlor register */
  1993. register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
  1994. IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
  1995. /* Print the CB values */
  1996. cb_fields_address = address;
  1997. register_value = ipw_read_reg32(priv, cb_fields_address);
  1998. IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
  1999. cb_fields_address += sizeof(u32);
  2000. register_value = ipw_read_reg32(priv, cb_fields_address);
  2001. IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
  2002. cb_fields_address += sizeof(u32);
  2003. register_value = ipw_read_reg32(priv, cb_fields_address);
  2004. IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
  2005. register_value);
  2006. cb_fields_address += sizeof(u32);
  2007. register_value = ipw_read_reg32(priv, cb_fields_address);
  2008. IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
  2009. IPW_DEBUG_FW(">> :\n");
  2010. }
  2011. static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
  2012. {
  2013. u32 current_cb_address = 0;
  2014. u32 current_cb_index = 0;
  2015. IPW_DEBUG_FW("<< :\n");
  2016. current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
  2017. current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
  2018. sizeof(struct command_block);
  2019. IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
  2020. current_cb_index, current_cb_address);
  2021. IPW_DEBUG_FW(">> :\n");
  2022. return current_cb_index;
  2023. }
  2024. static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
  2025. u32 src_address,
  2026. u32 dest_address,
  2027. u32 length,
  2028. int interrupt_enabled, int is_last)
  2029. {
  2030. u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
  2031. CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
  2032. CB_DEST_SIZE_LONG;
  2033. struct command_block *cb;
  2034. u32 last_cb_element = 0;
  2035. IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
  2036. src_address, dest_address, length);
  2037. if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
  2038. return -1;
  2039. last_cb_element = priv->sram_desc.last_cb_index;
  2040. cb = &priv->sram_desc.cb_list[last_cb_element];
  2041. priv->sram_desc.last_cb_index++;
  2042. /* Calculate the new CB control word */
  2043. if (interrupt_enabled)
  2044. control |= CB_INT_ENABLED;
  2045. if (is_last)
  2046. control |= CB_LAST_VALID;
  2047. control |= length;
  2048. /* Calculate the CB Element's checksum value */
  2049. cb->status = control ^ src_address ^ dest_address;
  2050. /* Copy the Source and Destination addresses */
  2051. cb->dest_addr = dest_address;
  2052. cb->source_addr = src_address;
  2053. /* Copy the Control Word last */
  2054. cb->control = control;
  2055. return 0;
  2056. }
  2057. static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
  2058. u32 src_phys, u32 dest_address, u32 length)
  2059. {
  2060. u32 bytes_left = length;
  2061. u32 src_offset = 0;
  2062. u32 dest_offset = 0;
  2063. int status = 0;
  2064. IPW_DEBUG_FW(">> \n");
  2065. IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
  2066. src_phys, dest_address, length);
  2067. while (bytes_left > CB_MAX_LENGTH) {
  2068. status = ipw_fw_dma_add_command_block(priv,
  2069. src_phys + src_offset,
  2070. dest_address +
  2071. dest_offset,
  2072. CB_MAX_LENGTH, 0, 0);
  2073. if (status) {
  2074. IPW_DEBUG_FW_INFO(": Failed\n");
  2075. return -1;
  2076. } else
  2077. IPW_DEBUG_FW_INFO(": Added new cb\n");
  2078. src_offset += CB_MAX_LENGTH;
  2079. dest_offset += CB_MAX_LENGTH;
  2080. bytes_left -= CB_MAX_LENGTH;
  2081. }
  2082. /* add the buffer tail */
  2083. if (bytes_left > 0) {
  2084. status =
  2085. ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
  2086. dest_address + dest_offset,
  2087. bytes_left, 0, 0);
  2088. if (status) {
  2089. IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
  2090. return -1;
  2091. } else
  2092. IPW_DEBUG_FW_INFO
  2093. (": Adding new cb - the buffer tail\n");
  2094. }
  2095. IPW_DEBUG_FW("<< \n");
  2096. return 0;
  2097. }
  2098. static int ipw_fw_dma_wait(struct ipw_priv *priv)
  2099. {
  2100. u32 current_index = 0;
  2101. u32 watchdog = 0;
  2102. IPW_DEBUG_FW(">> : \n");
  2103. current_index = ipw_fw_dma_command_block_index(priv);
  2104. IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%8X\n",
  2105. (int)priv->sram_desc.last_cb_index);
  2106. while (current_index < priv->sram_desc.last_cb_index) {
  2107. udelay(50);
  2108. current_index = ipw_fw_dma_command_block_index(priv);
  2109. watchdog++;
  2110. if (watchdog > 400) {
  2111. IPW_DEBUG_FW_INFO("Timeout\n");
  2112. ipw_fw_dma_dump_command_block(priv);
  2113. ipw_fw_dma_abort(priv);
  2114. return -1;
  2115. }
  2116. }
  2117. ipw_fw_dma_abort(priv);
  2118. /*Disable the DMA in the CSR register */
  2119. ipw_set_bit(priv, IPW_RESET_REG,
  2120. IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
  2121. IPW_DEBUG_FW("<< dmaWaitSync \n");
  2122. return 0;
  2123. }
  2124. static void ipw_remove_current_network(struct ipw_priv *priv)
  2125. {
  2126. struct list_head *element, *safe;
  2127. struct ieee80211_network *network = NULL;
  2128. unsigned long flags;
  2129. spin_lock_irqsave(&priv->ieee->lock, flags);
  2130. list_for_each_safe(element, safe, &priv->ieee->network_list) {
  2131. network = list_entry(element, struct ieee80211_network, list);
  2132. if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
  2133. list_del(element);
  2134. list_add_tail(&network->list,
  2135. &priv->ieee->network_free_list);
  2136. }
  2137. }
  2138. spin_unlock_irqrestore(&priv->ieee->lock, flags);
  2139. }
  2140. /**
  2141. * Check that card is still alive.
  2142. * Reads debug register from domain0.
  2143. * If card is present, pre-defined value should
  2144. * be found there.
  2145. *
  2146. * @param priv
  2147. * @return 1 if card is present, 0 otherwise
  2148. */
  2149. static inline int ipw_alive(struct ipw_priv *priv)
  2150. {
  2151. return ipw_read32(priv, 0x90) == 0xd55555d5;
  2152. }
  2153. static inline int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
  2154. int timeout)
  2155. {
  2156. int i = 0;
  2157. do {
  2158. if ((ipw_read32(priv, addr) & mask) == mask)
  2159. return i;
  2160. mdelay(10);
  2161. i += 10;
  2162. } while (i < timeout);
  2163. return -ETIME;
  2164. }
  2165. /* These functions load the firmware and micro code for the operation of
  2166. * the ipw hardware. It assumes the buffer has all the bits for the
  2167. * image and the caller is handling the memory allocation and clean up.
  2168. */
  2169. static int ipw_stop_master(struct ipw_priv *priv)
  2170. {
  2171. int rc;
  2172. IPW_DEBUG_TRACE(">> \n");
  2173. /* stop master. typical delay - 0 */
  2174. ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
  2175. rc = ipw_poll_bit(priv, IPW_RESET_REG,
  2176. IPW_RESET_REG_MASTER_DISABLED, 100);
  2177. if (rc < 0) {
  2178. IPW_ERROR("stop master failed in 10ms\n");
  2179. return -1;
  2180. }
  2181. IPW_DEBUG_INFO("stop master %dms\n", rc);
  2182. return rc;
  2183. }
  2184. static void ipw_arc_release(struct ipw_priv *priv)
  2185. {
  2186. IPW_DEBUG_TRACE(">> \n");
  2187. mdelay(5);
  2188. ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
  2189. /* no one knows timing, for safety add some delay */
  2190. mdelay(5);
  2191. }
  2192. struct fw_header {
  2193. u32 version;
  2194. u32 mode;
  2195. };
  2196. struct fw_chunk {
  2197. u32 address;
  2198. u32 length;
  2199. };
  2200. #define IPW_FW_MAJOR_VERSION 2
  2201. #define IPW_FW_MINOR_VERSION 3
  2202. #define IPW_FW_MINOR(x) ((x & 0xff) >> 8)
  2203. #define IPW_FW_MAJOR(x) (x & 0xff)
  2204. #define IPW_FW_VERSION ((IPW_FW_MINOR_VERSION << 8) | IPW_FW_MAJOR_VERSION)
  2205. #define IPW_FW_PREFIX "ipw-" __stringify(IPW_FW_MAJOR_VERSION) \
  2206. "." __stringify(IPW_FW_MINOR_VERSION) "-"
  2207. #if IPW_FW_MAJOR_VERSION >= 2 && IPW_FW_MINOR_VERSION > 0
  2208. #define IPW_FW_NAME(x) IPW_FW_PREFIX "" x ".fw"
  2209. #else
  2210. #define IPW_FW_NAME(x) "ipw2200_" x ".fw"
  2211. #endif
  2212. static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
  2213. {
  2214. int rc = 0, i, addr;
  2215. u8 cr = 0;
  2216. u16 *image;
  2217. image = (u16 *) data;
  2218. IPW_DEBUG_TRACE(">> \n");
  2219. rc = ipw_stop_master(priv);
  2220. if (rc < 0)
  2221. return rc;
  2222. // spin_lock_irqsave(&priv->lock, flags);
  2223. for (addr = IPW_SHARED_LOWER_BOUND;
  2224. addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
  2225. ipw_write32(priv, addr, 0);
  2226. }
  2227. /* no ucode (yet) */
  2228. memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
  2229. /* destroy DMA queues */
  2230. /* reset sequence */
  2231. ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
  2232. ipw_arc_release(priv);
  2233. ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
  2234. mdelay(1);
  2235. /* reset PHY */
  2236. ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
  2237. mdelay(1);
  2238. ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
  2239. mdelay(1);
  2240. /* enable ucode store */
  2241. ipw_write_reg8(priv, DINO_CONTROL_REG, 0x0);
  2242. ipw_write_reg8(priv, DINO_CONTROL_REG, DINO_ENABLE_CS);
  2243. mdelay(1);
  2244. /* write ucode */
  2245. /**
  2246. * @bug
  2247. * Do NOT set indirect address register once and then
  2248. * store data to indirect data register in the loop.
  2249. * It seems very reasonable, but in this case DINO do not
  2250. * accept ucode. It is essential to set address each time.
  2251. */
  2252. /* load new ipw uCode */
  2253. for (i = 0; i < len / 2; i++)
  2254. ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
  2255. cpu_to_le16(image[i]));
  2256. /* enable DINO */
  2257. ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
  2258. ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
  2259. /* this is where the igx / win driver deveates from the VAP driver. */
  2260. /* wait for alive response */
  2261. for (i = 0; i < 100; i++) {
  2262. /* poll for incoming data */
  2263. cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
  2264. if (cr & DINO_RXFIFO_DATA)
  2265. break;
  2266. mdelay(1);
  2267. }
  2268. if (cr & DINO_RXFIFO_DATA) {
  2269. /* alive_command_responce size is NOT multiple of 4 */
  2270. u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
  2271. for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
  2272. response_buffer[i] =
  2273. le32_to_cpu(ipw_read_reg32(priv,
  2274. IPW_BASEBAND_RX_FIFO_READ));
  2275. memcpy(&priv->dino_alive, response_buffer,
  2276. sizeof(priv->dino_alive));
  2277. if (priv->dino_alive.alive_command == 1
  2278. && priv->dino_alive.ucode_valid == 1) {
  2279. rc = 0;
  2280. IPW_DEBUG_INFO
  2281. ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
  2282. "of %02d/%02d/%02d %02d:%02d\n",
  2283. priv->dino_alive.software_revision,
  2284. priv->dino_alive.software_revision,
  2285. priv->dino_alive.device_identifier,
  2286. priv->dino_alive.device_identifier,
  2287. priv->dino_alive.time_stamp[0],
  2288. priv->dino_alive.time_stamp[1],
  2289. priv->dino_alive.time_stamp[2],
  2290. priv->dino_alive.time_stamp[3],
  2291. priv->dino_alive.time_stamp[4]);
  2292. } else {
  2293. IPW_DEBUG_INFO("Microcode is not alive\n");
  2294. rc = -EINVAL;
  2295. }
  2296. } else {
  2297. IPW_DEBUG_INFO("No alive response from DINO\n");
  2298. rc = -ETIME;
  2299. }
  2300. /* disable DINO, otherwise for some reason
  2301. firmware have problem getting alive resp. */
  2302. ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
  2303. // spin_unlock_irqrestore(&priv->lock, flags);
  2304. return rc;
  2305. }
  2306. static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
  2307. {
  2308. int rc = -1;
  2309. int offset = 0;
  2310. struct fw_chunk *chunk;
  2311. dma_addr_t shared_phys;
  2312. u8 *shared_virt;
  2313. IPW_DEBUG_TRACE("<< : \n");
  2314. shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
  2315. if (!shared_virt)
  2316. return -ENOMEM;
  2317. memmove(shared_virt, data, len);
  2318. /* Start the Dma */
  2319. rc = ipw_fw_dma_enable(priv);
  2320. if (priv->sram_desc.last_cb_index > 0) {
  2321. /* the DMA is already ready this would be a bug. */
  2322. BUG();
  2323. goto out;
  2324. }
  2325. do {
  2326. chunk = (struct fw_chunk *)(data + offset);
  2327. offset += sizeof(struct fw_chunk);
  2328. /* build DMA packet and queue up for sending */
  2329. /* dma to chunk->address, the chunk->length bytes from data +
  2330. * offeset*/
  2331. /* Dma loading */
  2332. rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
  2333. le32_to_cpu(chunk->address),
  2334. le32_to_cpu(chunk->length));
  2335. if (rc) {
  2336. IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
  2337. goto out;
  2338. }
  2339. offset += le32_to_cpu(chunk->length);
  2340. } while (offset < len);
  2341. /* Run the DMA and wait for the answer */
  2342. rc = ipw_fw_dma_kick(priv);
  2343. if (rc) {
  2344. IPW_ERROR("dmaKick Failed\n");
  2345. goto out;
  2346. }
  2347. rc = ipw_fw_dma_wait(priv);
  2348. if (rc) {
  2349. IPW_ERROR("dmaWaitSync Failed\n");
  2350. goto out;
  2351. }
  2352. out:
  2353. pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
  2354. return rc;
  2355. }
  2356. /* stop nic */
  2357. static int ipw_stop_nic(struct ipw_priv *priv)
  2358. {
  2359. int rc = 0;
  2360. /* stop */
  2361. ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
  2362. rc = ipw_poll_bit(priv, IPW_RESET_REG,
  2363. IPW_RESET_REG_MASTER_DISABLED, 500);
  2364. if (rc < 0) {
  2365. IPW_ERROR("wait for reg master disabled failed\n");
  2366. return rc;
  2367. }
  2368. ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
  2369. return rc;
  2370. }
  2371. static void ipw_start_nic(struct ipw_priv *priv)
  2372. {
  2373. IPW_DEBUG_TRACE(">>\n");
  2374. /* prvHwStartNic release ARC */
  2375. ipw_clear_bit(priv, IPW_RESET_REG,
  2376. IPW_RESET_REG_MASTER_DISABLED |
  2377. IPW_RESET_REG_STOP_MASTER |
  2378. CBD_RESET_REG_PRINCETON_RESET);
  2379. /* enable power management */
  2380. ipw_set_bit(priv, IPW_GP_CNTRL_RW,
  2381. IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
  2382. IPW_DEBUG_TRACE("<<\n");
  2383. }
  2384. static int ipw_init_nic(struct ipw_priv *priv)
  2385. {
  2386. int rc;
  2387. IPW_DEBUG_TRACE(">>\n");
  2388. /* reset */
  2389. /*prvHwInitNic */
  2390. /* set "initialization complete" bit to move adapter to D0 state */
  2391. ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
  2392. /* low-level PLL activation */
  2393. ipw_write32(priv, IPW_READ_INT_REGISTER,
  2394. IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
  2395. /* wait for clock stabilization */
  2396. rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
  2397. IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
  2398. if (rc < 0)
  2399. IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
  2400. /* assert SW reset */
  2401. ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
  2402. udelay(10);
  2403. /* set "initialization complete" bit to move adapter to D0 state */
  2404. ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
  2405. IPW_DEBUG_TRACE(">>\n");
  2406. return 0;
  2407. }
  2408. /* Call this function from process context, it will sleep in request_firmware.
  2409. * Probe is an ok place to call this from.
  2410. */
  2411. static int ipw_reset_nic(struct ipw_priv *priv)
  2412. {
  2413. int rc = 0;
  2414. unsigned long flags;
  2415. IPW_DEBUG_TRACE(">>\n");
  2416. rc = ipw_init_nic(priv);
  2417. spin_lock_irqsave(&priv->lock, flags);
  2418. /* Clear the 'host command active' bit... */
  2419. priv->status &= ~STATUS_HCMD_ACTIVE;
  2420. wake_up_interruptible(&priv->wait_command_queue);
  2421. priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
  2422. wake_up_interruptible(&priv->wait_state);
  2423. spin_unlock_irqrestore(&priv->lock, flags);
  2424. IPW_DEBUG_TRACE("<<\n");
  2425. return rc;
  2426. }
  2427. static int ipw_get_fw(struct ipw_priv *priv,
  2428. const struct firmware **fw, const char *name)
  2429. {
  2430. struct fw_header *header;
  2431. int rc;
  2432. /* ask firmware_class module to get the boot firmware off disk */
  2433. rc = request_firmware(fw, name, &priv->pci_dev->dev);
  2434. if (rc < 0) {
  2435. IPW_ERROR("%s load failed: Reason %d\n", name, rc);
  2436. return rc;
  2437. }
  2438. header = (struct fw_header *)(*fw)->data;
  2439. if (IPW_FW_MAJOR(le32_to_cpu(header->version)) != IPW_FW_MAJOR_VERSION) {
  2440. IPW_ERROR("'%s' firmware version not compatible (%d != %d)\n",
  2441. name,
  2442. IPW_FW_MAJOR(le32_to_cpu(header->version)),
  2443. IPW_FW_MAJOR_VERSION);
  2444. return -EINVAL;
  2445. }
  2446. IPW_DEBUG_INFO("Loading firmware '%s' file v%d.%d (%zd bytes)\n",
  2447. name,
  2448. IPW_FW_MAJOR(le32_to_cpu(header->version)),
  2449. IPW_FW_MINOR(le32_to_cpu(header->version)),
  2450. (*fw)->size - sizeof(struct fw_header));
  2451. return 0;
  2452. }
  2453. #define IPW_RX_BUF_SIZE (3000)
  2454. static inline void ipw_rx_queue_reset(struct ipw_priv *priv,
  2455. struct ipw_rx_queue *rxq)
  2456. {
  2457. unsigned long flags;
  2458. int i;
  2459. spin_lock_irqsave(&rxq->lock, flags);
  2460. INIT_LIST_HEAD(&rxq->rx_free);
  2461. INIT_LIST_HEAD(&rxq->rx_used);
  2462. /* Fill the rx_used queue with _all_ of the Rx buffers */
  2463. for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
  2464. /* In the reset function, these buffers may have been allocated
  2465. * to an SKB, so we need to unmap and free potential storage */
  2466. if (rxq->pool[i].skb != NULL) {
  2467. pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
  2468. IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
  2469. dev_kfree_skb(rxq->pool[i].skb);
  2470. rxq->pool[i].skb = NULL;
  2471. }
  2472. list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
  2473. }
  2474. /* Set us so that we have processed and used all buffers, but have
  2475. * not restocked the Rx queue with fresh buffers */
  2476. rxq->read = rxq->write = 0;
  2477. rxq->processed = RX_QUEUE_SIZE - 1;
  2478. rxq->free_count = 0;
  2479. spin_unlock_irqrestore(&rxq->lock, flags);
  2480. }
  2481. #ifdef CONFIG_PM
  2482. static int fw_loaded = 0;
  2483. static const struct firmware *bootfw = NULL;
  2484. static const struct firmware *firmware = NULL;
  2485. static const struct firmware *ucode = NULL;
  2486. static void free_firmware(void)
  2487. {
  2488. if (fw_loaded) {
  2489. release_firmware(bootfw);
  2490. release_firmware(ucode);
  2491. release_firmware(firmware);
  2492. bootfw = ucode = firmware = NULL;
  2493. fw_loaded = 0;
  2494. }
  2495. }
  2496. #else
  2497. #define free_firmware() do {} while (0)
  2498. #endif
  2499. static int ipw_load(struct ipw_priv *priv)
  2500. {
  2501. #ifndef CONFIG_PM
  2502. const struct firmware *bootfw = NULL;
  2503. const struct firmware *firmware = NULL;
  2504. const struct firmware *ucode = NULL;
  2505. #endif
  2506. int rc = 0, retries = 3;
  2507. #ifdef CONFIG_PM
  2508. if (!fw_loaded) {
  2509. #endif
  2510. rc = ipw_get_fw(priv, &bootfw, IPW_FW_NAME("boot"));
  2511. if (rc)
  2512. goto error;
  2513. switch (priv->ieee->iw_mode) {
  2514. case IW_MODE_ADHOC:
  2515. rc = ipw_get_fw(priv, &ucode,
  2516. IPW_FW_NAME("ibss_ucode"));
  2517. if (rc)
  2518. goto error;
  2519. rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("ibss"));
  2520. break;
  2521. #ifdef CONFIG_IPW2200_MONITOR
  2522. case IW_MODE_MONITOR:
  2523. rc = ipw_get_fw(priv, &ucode,
  2524. IPW_FW_NAME("sniffer_ucode"));
  2525. if (rc)
  2526. goto error;
  2527. rc = ipw_get_fw(priv, &firmware,
  2528. IPW_FW_NAME("sniffer"));
  2529. break;
  2530. #endif
  2531. case IW_MODE_INFRA:
  2532. rc = ipw_get_fw(priv, &ucode, IPW_FW_NAME("bss_ucode"));
  2533. if (rc)
  2534. goto error;
  2535. rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("bss"));
  2536. break;
  2537. default:
  2538. rc = -EINVAL;
  2539. }
  2540. if (rc)
  2541. goto error;
  2542. #ifdef CONFIG_PM
  2543. fw_loaded = 1;
  2544. }
  2545. #endif
  2546. if (!priv->rxq)
  2547. priv->rxq = ipw_rx_queue_alloc(priv);
  2548. else
  2549. ipw_rx_queue_reset(priv, priv->rxq);
  2550. if (!priv->rxq) {
  2551. IPW_ERROR("Unable to initialize Rx queue\n");
  2552. goto error;
  2553. }
  2554. retry:
  2555. /* Ensure interrupts are disabled */
  2556. ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
  2557. priv->status &= ~STATUS_INT_ENABLED;
  2558. /* ack pending interrupts */
  2559. ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
  2560. ipw_stop_nic(priv);
  2561. rc = ipw_reset_nic(priv);
  2562. if (rc) {
  2563. IPW_ERROR("Unable to reset NIC\n");
  2564. goto error;
  2565. }
  2566. ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
  2567. IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
  2568. /* DMA the initial boot firmware into the device */
  2569. rc = ipw_load_firmware(priv, bootfw->data + sizeof(struct fw_header),
  2570. bootfw->size - sizeof(struct fw_header));
  2571. if (rc < 0) {
  2572. IPW_ERROR("Unable to load boot firmware\n");
  2573. goto error;
  2574. }
  2575. /* kick start the device */
  2576. ipw_start_nic(priv);
  2577. /* wait for the device to finish it's initial startup sequence */
  2578. rc = ipw_poll_bit(priv, IPW_INTA_RW,
  2579. IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
  2580. if (rc < 0) {
  2581. IPW_ERROR("device failed to boot initial fw image\n");
  2582. goto error;
  2583. }
  2584. IPW_DEBUG_INFO("initial device response after %dms\n", rc);
  2585. /* ack fw init done interrupt */
  2586. ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
  2587. /* DMA the ucode into the device */
  2588. rc = ipw_load_ucode(priv, ucode->data + sizeof(struct fw_header),
  2589. ucode->size - sizeof(struct fw_header));
  2590. if (rc < 0) {
  2591. IPW_ERROR("Unable to load ucode\n");
  2592. goto error;
  2593. }
  2594. /* stop nic */
  2595. ipw_stop_nic(priv);
  2596. /* DMA bss firmware into the device */
  2597. rc = ipw_load_firmware(priv, firmware->data +
  2598. sizeof(struct fw_header),
  2599. firmware->size - sizeof(struct fw_header));
  2600. if (rc < 0) {
  2601. IPW_ERROR("Unable to load firmware\n");
  2602. goto error;
  2603. }
  2604. ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
  2605. rc = ipw_queue_reset(priv);
  2606. if (rc) {
  2607. IPW_ERROR("Unable to initialize queues\n");
  2608. goto error;
  2609. }
  2610. /* Ensure interrupts are disabled */
  2611. ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
  2612. /* ack pending interrupts */
  2613. ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
  2614. /* kick start the device */
  2615. ipw_start_nic(priv);
  2616. if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
  2617. if (retries > 0) {
  2618. IPW_WARNING("Parity error. Retrying init.\n");
  2619. retries--;
  2620. goto retry;
  2621. }
  2622. IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
  2623. rc = -EIO;
  2624. goto error;
  2625. }
  2626. /* wait for the device */
  2627. rc = ipw_poll_bit(priv, IPW_INTA_RW,
  2628. IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
  2629. if (rc < 0) {
  2630. IPW_ERROR("device failed to start after 500ms\n");
  2631. goto error;
  2632. }
  2633. IPW_DEBUG_INFO("device response after %dms\n", rc);
  2634. /* ack fw init done interrupt */
  2635. ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
  2636. /* read eeprom data and initialize the eeprom region of sram */
  2637. priv->eeprom_delay = 1;
  2638. ipw_eeprom_init_sram(priv);
  2639. /* enable interrupts */
  2640. ipw_enable_interrupts(priv);
  2641. /* Ensure our queue has valid packets */
  2642. ipw_rx_queue_replenish(priv);
  2643. ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
  2644. /* ack pending interrupts */
  2645. ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
  2646. #ifndef CONFIG_PM
  2647. release_firmware(bootfw);
  2648. release_firmware(ucode);
  2649. release_firmware(firmware);
  2650. #endif
  2651. return 0;
  2652. error:
  2653. if (priv->rxq) {
  2654. ipw_rx_queue_free(priv, priv->rxq);
  2655. priv->rxq = NULL;
  2656. }
  2657. ipw_tx_queue_free(priv);
  2658. if (bootfw)
  2659. release_firmware(bootfw);
  2660. if (ucode)
  2661. release_firmware(ucode);
  2662. if (firmware)
  2663. release_firmware(firmware);
  2664. #ifdef CONFIG_PM
  2665. fw_loaded = 0;
  2666. bootfw = ucode = firmware = NULL;
  2667. #endif
  2668. return rc;
  2669. }
  2670. /**
  2671. * DMA services
  2672. *
  2673. * Theory of operation
  2674. *
  2675. * A queue is a circular buffers with 'Read' and 'Write' pointers.
  2676. * 2 empty entries always kept in the buffer to protect from overflow.
  2677. *
  2678. * For Tx queue, there are low mark and high mark limits. If, after queuing
  2679. * the packet for Tx, free space become < low mark, Tx queue stopped. When
  2680. * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
  2681. * Tx queue resumed.
  2682. *
  2683. * The IPW operates with six queues, one receive queue in the device's
  2684. * sram, one transmit queue for sending commands to the device firmware,
  2685. * and four transmit queues for data.
  2686. *
  2687. * The four transmit queues allow for performing quality of service (qos)
  2688. * transmissions as per the 802.11 protocol. Currently Linux does not
  2689. * provide a mechanism to the user for utilizing prioritized queues, so
  2690. * we only utilize the first data transmit queue (queue1).
  2691. */
  2692. /**
  2693. * Driver allocates buffers of this size for Rx
  2694. */
  2695. static inline int ipw_queue_space(const struct clx2_queue *q)
  2696. {
  2697. int s = q->last_used - q->first_empty;
  2698. if (s <= 0)
  2699. s += q->n_bd;
  2700. s -= 2; /* keep some reserve to not confuse empty and full situations */
  2701. if (s < 0)
  2702. s = 0;
  2703. return s;
  2704. }
  2705. static inline int ipw_queue_inc_wrap(int index, int n_bd)
  2706. {
  2707. return (++index == n_bd) ? 0 : index;
  2708. }
  2709. /**
  2710. * Initialize common DMA queue structure
  2711. *
  2712. * @param q queue to init
  2713. * @param count Number of BD's to allocate. Should be power of 2
  2714. * @param read_register Address for 'read' register
  2715. * (not offset within BAR, full address)
  2716. * @param write_register Address for 'write' register
  2717. * (not offset within BAR, full address)
  2718. * @param base_register Address for 'base' register
  2719. * (not offset within BAR, full address)
  2720. * @param size Address for 'size' register
  2721. * (not offset within BAR, full address)
  2722. */
  2723. static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
  2724. int count, u32 read, u32 write, u32 base, u32 size)
  2725. {
  2726. q->n_bd = count;
  2727. q->low_mark = q->n_bd / 4;
  2728. if (q->low_mark < 4)
  2729. q->low_mark = 4;
  2730. q->high_mark = q->n_bd / 8;
  2731. if (q->high_mark < 2)
  2732. q->high_mark = 2;
  2733. q->first_empty = q->last_used = 0;
  2734. q->reg_r = read;
  2735. q->reg_w = write;
  2736. ipw_write32(priv, base, q->dma_addr);
  2737. ipw_write32(priv, size, count);
  2738. ipw_write32(priv, read, 0);
  2739. ipw_write32(priv, write, 0);
  2740. _ipw_read32(priv, 0x90);
  2741. }
  2742. static int ipw_queue_tx_init(struct ipw_priv *priv,
  2743. struct clx2_tx_queue *q,
  2744. int count, u32 read, u32 write, u32 base, u32 size)
  2745. {
  2746. struct pci_dev *dev = priv->pci_dev;
  2747. q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
  2748. if (!q->txb) {
  2749. IPW_ERROR("vmalloc for auxilary BD structures failed\n");
  2750. return -ENOMEM;
  2751. }
  2752. q->bd =
  2753. pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
  2754. if (!q->bd) {
  2755. IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
  2756. sizeof(q->bd[0]) * count);
  2757. kfree(q->txb);
  2758. q->txb = NULL;
  2759. return -ENOMEM;
  2760. }
  2761. ipw_queue_init(priv, &q->q, count, read, write, base, size);
  2762. return 0;
  2763. }
  2764. /**
  2765. * Free one TFD, those at index [txq->q.last_used].
  2766. * Do NOT advance any indexes
  2767. *
  2768. * @param dev
  2769. * @param txq
  2770. */
  2771. static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
  2772. struct clx2_tx_queue *txq)
  2773. {
  2774. struct tfd_frame *bd = &txq->bd[txq->q.last_used];
  2775. struct pci_dev *dev = priv->pci_dev;
  2776. int i;
  2777. /* classify bd */
  2778. if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
  2779. /* nothing to cleanup after for host commands */
  2780. return;
  2781. /* sanity check */
  2782. if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
  2783. IPW_ERROR("Too many chunks: %i\n",
  2784. le32_to_cpu(bd->u.data.num_chunks));
  2785. /** @todo issue fatal error, it is quite serious situation */
  2786. return;
  2787. }
  2788. /* unmap chunks if any */
  2789. for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
  2790. pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
  2791. le16_to_cpu(bd->u.data.chunk_len[i]),
  2792. PCI_DMA_TODEVICE);
  2793. if (txq->txb[txq->q.last_used]) {
  2794. ieee80211_txb_free(txq->txb[txq->q.last_used]);
  2795. txq->txb[txq->q.last_used] = NULL;
  2796. }
  2797. }
  2798. }
  2799. /**
  2800. * Deallocate DMA queue.
  2801. *
  2802. * Empty queue by removing and destroying all BD's.
  2803. * Free all buffers.
  2804. *
  2805. * @param dev
  2806. * @param q
  2807. */
  2808. static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
  2809. {
  2810. struct clx2_queue *q = &txq->q;
  2811. struct pci_dev *dev = priv->pci_dev;
  2812. if (q->n_bd == 0)
  2813. return;
  2814. /* first, empty all BD's */
  2815. for (; q->first_empty != q->last_used;
  2816. q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
  2817. ipw_queue_tx_free_tfd(priv, txq);
  2818. }
  2819. /* free buffers belonging to queue itself */
  2820. pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
  2821. q->dma_addr);
  2822. kfree(txq->txb);
  2823. /* 0 fill whole structure */
  2824. memset(txq, 0, sizeof(*txq));
  2825. }
  2826. /**
  2827. * Destroy all DMA queues and structures
  2828. *
  2829. * @param priv
  2830. */
  2831. static void ipw_tx_queue_free(struct ipw_priv *priv)
  2832. {
  2833. /* Tx CMD queue */
  2834. ipw_queue_tx_free(priv, &priv->txq_cmd);
  2835. /* Tx queues */
  2836. ipw_queue_tx_free(priv, &priv->txq[0]);
  2837. ipw_queue_tx_free(priv, &priv->txq[1]);
  2838. ipw_queue_tx_free(priv, &priv->txq[2]);
  2839. ipw_queue_tx_free(priv, &priv->txq[3]);
  2840. }
  2841. static void inline __maybe_wake_tx(struct ipw_priv *priv)
  2842. {
  2843. if (netif_running(priv->net_dev)) {
  2844. switch (priv->port_type) {
  2845. case DCR_TYPE_MU_BSS:
  2846. case DCR_TYPE_MU_IBSS:
  2847. if (!(priv->status & STATUS_ASSOCIATED))
  2848. return;
  2849. }
  2850. netif_wake_queue(priv->net_dev);
  2851. }
  2852. }
  2853. static inline void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
  2854. {
  2855. /* First 3 bytes are manufacturer */
  2856. bssid[0] = priv->mac_addr[0];
  2857. bssid[1] = priv->mac_addr[1];
  2858. bssid[2] = priv->mac_addr[2];
  2859. /* Last bytes are random */
  2860. get_random_bytes(&bssid[3], ETH_ALEN - 3);
  2861. bssid[0] &= 0xfe; /* clear multicast bit */
  2862. bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
  2863. }
  2864. static inline u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
  2865. {
  2866. struct ipw_station_entry entry;
  2867. int i;
  2868. for (i = 0; i < priv->num_stations; i++) {
  2869. if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
  2870. /* Another node is active in network */
  2871. priv->missed_adhoc_beacons = 0;
  2872. if (!(priv->config & CFG_STATIC_CHANNEL))
  2873. /* when other nodes drop out, we drop out */
  2874. priv->config &= ~CFG_ADHOC_PERSIST;
  2875. return i;
  2876. }
  2877. }
  2878. if (i == MAX_STATIONS)
  2879. return IPW_INVALID_STATION;
  2880. IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
  2881. entry.reserved = 0;
  2882. entry.support_mode = 0;
  2883. memcpy(entry.mac_addr, bssid, ETH_ALEN);
  2884. memcpy(priv->stations[i], bssid, ETH_ALEN);
  2885. ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
  2886. &entry, sizeof(entry));
  2887. priv->num_stations++;
  2888. return i;
  2889. }
  2890. static inline u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
  2891. {
  2892. int i;
  2893. for (i = 0; i < priv->num_stations; i++)
  2894. if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
  2895. return i;
  2896. return IPW_INVALID_STATION;
  2897. }
  2898. static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
  2899. {
  2900. int err;
  2901. if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))) {
  2902. IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
  2903. return;
  2904. }
  2905. IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
  2906. "on channel %d.\n",
  2907. MAC_ARG(priv->assoc_request.bssid),
  2908. priv->assoc_request.channel);
  2909. priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
  2910. priv->status |= STATUS_DISASSOCIATING;
  2911. if (quiet)
  2912. priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
  2913. else
  2914. priv->assoc_request.assoc_type = HC_DISASSOCIATE;
  2915. err = ipw_send_associate(priv, &priv->assoc_request);
  2916. if (err) {
  2917. IPW_DEBUG_HC("Attempt to send [dis]associate command "
  2918. "failed.\n");
  2919. return;
  2920. }
  2921. }
  2922. static int ipw_disassociate(void *data)
  2923. {
  2924. struct ipw_priv *priv = data;
  2925. if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
  2926. return 0;
  2927. ipw_send_disassociate(data, 0);
  2928. return 1;
  2929. }
  2930. static void ipw_bg_disassociate(void *data)
  2931. {
  2932. struct ipw_priv *priv = data;
  2933. down(&priv->sem);
  2934. ipw_disassociate(data);
  2935. up(&priv->sem);
  2936. }
  2937. static void ipw_system_config(void *data)
  2938. {
  2939. struct ipw_priv *priv = data;
  2940. ipw_send_system_config(priv, &priv->sys_config);
  2941. }
  2942. struct ipw_status_code {
  2943. u16 status;
  2944. const char *reason;
  2945. };
  2946. static const struct ipw_status_code ipw_status_codes[] = {
  2947. {0x00, "Successful"},
  2948. {0x01, "Unspecified failure"},
  2949. {0x0A, "Cannot support all requested capabilities in the "
  2950. "Capability information field"},
  2951. {0x0B, "Reassociation denied due to inability to confirm that "
  2952. "association exists"},
  2953. {0x0C, "Association denied due to reason outside the scope of this "
  2954. "standard"},
  2955. {0x0D,
  2956. "Responding station does not support the specified authentication "
  2957. "algorithm"},
  2958. {0x0E,
  2959. "Received an Authentication frame with authentication sequence "
  2960. "transaction sequence number out of expected sequence"},
  2961. {0x0F, "Authentication rejected because of challenge failure"},
  2962. {0x10, "Authentication rejected due to timeout waiting for next "
  2963. "frame in sequence"},
  2964. {0x11, "Association denied because AP is unable to handle additional "
  2965. "associated stations"},
  2966. {0x12,
  2967. "Association denied due to requesting station not supporting all "
  2968. "of the datarates in the BSSBasicServiceSet Parameter"},
  2969. {0x13,
  2970. "Association denied due to requesting station not supporting "
  2971. "short preamble operation"},
  2972. {0x14,
  2973. "Association denied due to requesting station not supporting "
  2974. "PBCC encoding"},
  2975. {0x15,
  2976. "Association denied due to requesting station not supporting "
  2977. "channel agility"},
  2978. {0x19,
  2979. "Association denied due to requesting station not supporting "
  2980. "short slot operation"},
  2981. {0x1A,
  2982. "Association denied due to requesting station not supporting "
  2983. "DSSS-OFDM operation"},
  2984. {0x28, "Invalid Information Element"},
  2985. {0x29, "Group Cipher is not valid"},
  2986. {0x2A, "Pairwise Cipher is not valid"},
  2987. {0x2B, "AKMP is not valid"},
  2988. {0x2C, "Unsupported RSN IE version"},
  2989. {0x2D, "Invalid RSN IE Capabilities"},
  2990. {0x2E, "Cipher suite is rejected per security policy"},
  2991. };
  2992. #ifdef CONFIG_IPW_DEBUG
  2993. static const char *ipw_get_status_code(u16 status)
  2994. {
  2995. int i;
  2996. for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
  2997. if (ipw_status_codes[i].status == (status & 0xff))
  2998. return ipw_status_codes[i].reason;
  2999. return "Unknown status value.";
  3000. }
  3001. #endif
  3002. static void inline average_init(struct average *avg)
  3003. {
  3004. memset(avg, 0, sizeof(*avg));
  3005. }
  3006. static void inline average_add(struct average *avg, s16 val)
  3007. {
  3008. avg->sum -= avg->entries[avg->pos];
  3009. avg->sum += val;
  3010. avg->entries[avg->pos++] = val;
  3011. if (unlikely(avg->pos == AVG_ENTRIES)) {
  3012. avg->init = 1;
  3013. avg->pos = 0;
  3014. }
  3015. }
  3016. static s16 inline average_value(struct average *avg)
  3017. {
  3018. if (!unlikely(avg->init)) {
  3019. if (avg->pos)
  3020. return avg->sum / avg->pos;
  3021. return 0;
  3022. }
  3023. return avg->sum / AVG_ENTRIES;
  3024. }
  3025. static void ipw_reset_stats(struct ipw_priv *priv)
  3026. {
  3027. u32 len = sizeof(u32);
  3028. priv->quality = 0;
  3029. average_init(&priv->average_missed_beacons);
  3030. average_init(&priv->average_rssi);
  3031. average_init(&priv->average_noise);
  3032. priv->last_rate = 0;
  3033. priv->last_missed_beacons = 0;
  3034. priv->last_rx_packets = 0;
  3035. priv->last_tx_packets = 0;
  3036. priv->last_tx_failures = 0;
  3037. /* Firmware managed, reset only when NIC is restarted, so we have to
  3038. * normalize on the current value */
  3039. ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
  3040. &priv->last_rx_err, &len);
  3041. ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
  3042. &priv->last_tx_failures, &len);
  3043. /* Driver managed, reset with each association */
  3044. priv->missed_adhoc_beacons = 0;
  3045. priv->missed_beacons = 0;
  3046. priv->tx_packets = 0;
  3047. priv->rx_packets = 0;
  3048. }
  3049. static inline u32 ipw_get_max_rate(struct ipw_priv *priv)
  3050. {
  3051. u32 i = 0x80000000;
  3052. u32 mask = priv->rates_mask;
  3053. /* If currently associated in B mode, restrict the maximum
  3054. * rate match to B rates */
  3055. if (priv->assoc_request.ieee_mode == IPW_B_MODE)
  3056. mask &= IEEE80211_CCK_RATES_MASK;
  3057. /* TODO: Verify that the rate is supported by the current rates
  3058. * list. */
  3059. while (i && !(mask & i))
  3060. i >>= 1;
  3061. switch (i) {
  3062. case IEEE80211_CCK_RATE_1MB_MASK:
  3063. return 1000000;
  3064. case IEEE80211_CCK_RATE_2MB_MASK:
  3065. return 2000000;
  3066. case IEEE80211_CCK_RATE_5MB_MASK:
  3067. return 5500000;
  3068. case IEEE80211_OFDM_RATE_6MB_MASK:
  3069. return 6000000;
  3070. case IEEE80211_OFDM_RATE_9MB_MASK:
  3071. return 9000000;
  3072. case IEEE80211_CCK_RATE_11MB_MASK:
  3073. return 11000000;
  3074. case IEEE80211_OFDM_RATE_12MB_MASK:
  3075. return 12000000;
  3076. case IEEE80211_OFDM_RATE_18MB_MASK:
  3077. return 18000000;
  3078. case IEEE80211_OFDM_RATE_24MB_MASK:
  3079. return 24000000;
  3080. case IEEE80211_OFDM_RATE_36MB_MASK:
  3081. return 36000000;
  3082. case IEEE80211_OFDM_RATE_48MB_MASK:
  3083. return 48000000;
  3084. case IEEE80211_OFDM_RATE_54MB_MASK:
  3085. return 54000000;
  3086. }
  3087. if (priv->ieee->mode == IEEE_B)
  3088. return 11000000;
  3089. else
  3090. return 54000000;
  3091. }
  3092. static u32 ipw_get_current_rate(struct ipw_priv *priv)
  3093. {
  3094. u32 rate, len = sizeof(rate);
  3095. int err;
  3096. if (!(priv->status & STATUS_ASSOCIATED))
  3097. return 0;
  3098. if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
  3099. err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
  3100. &len);
  3101. if (err) {
  3102. IPW_DEBUG_INFO("failed querying ordinals.\n");
  3103. return 0;
  3104. }
  3105. } else
  3106. return ipw_get_max_rate(priv);
  3107. switch (rate) {
  3108. case IPW_TX_RATE_1MB:
  3109. return 1000000;
  3110. case IPW_TX_RATE_2MB:
  3111. return 2000000;
  3112. case IPW_TX_RATE_5MB:
  3113. return 5500000;
  3114. case IPW_TX_RATE_6MB:
  3115. return 6000000;
  3116. case IPW_TX_RATE_9MB:
  3117. return 9000000;
  3118. case IPW_TX_RATE_11MB:
  3119. return 11000000;
  3120. case IPW_TX_RATE_12MB:
  3121. return 12000000;
  3122. case IPW_TX_RATE_18MB:
  3123. return 18000000;
  3124. case IPW_TX_RATE_24MB:
  3125. return 24000000;
  3126. case IPW_TX_RATE_36MB:
  3127. return 36000000;
  3128. case IPW_TX_RATE_48MB:
  3129. return 48000000;
  3130. case IPW_TX_RATE_54MB:
  3131. return 54000000;
  3132. }
  3133. return 0;
  3134. }
  3135. #define IPW_STATS_INTERVAL (2 * HZ)
  3136. static void ipw_gather_stats(struct ipw_priv *priv)
  3137. {
  3138. u32 rx_err, rx_err_delta, rx_packets_delta;
  3139. u32 tx_failures, tx_failures_delta, tx_packets_delta;
  3140. u32 missed_beacons_percent, missed_beacons_delta;
  3141. u32 quality = 0;
  3142. u32 len = sizeof(u32);
  3143. s16 rssi;
  3144. u32 beacon_quality, signal_quality, tx_quality, rx_quality,
  3145. rate_quality;
  3146. u32 max_rate;
  3147. if (!(priv->status & STATUS_ASSOCIATED)) {
  3148. priv->quality = 0;
  3149. return;
  3150. }
  3151. /* Update the statistics */
  3152. ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
  3153. &priv->missed_beacons, &len);
  3154. missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
  3155. priv->last_missed_beacons = priv->missed_beacons;
  3156. if (priv->assoc_request.beacon_interval) {
  3157. missed_beacons_percent = missed_beacons_delta *
  3158. (HZ * priv->assoc_request.beacon_interval) /
  3159. (IPW_STATS_INTERVAL * 10);
  3160. } else {
  3161. missed_beacons_percent = 0;
  3162. }
  3163. average_add(&priv->average_missed_beacons, missed_beacons_percent);
  3164. ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
  3165. rx_err_delta = rx_err - priv->last_rx_err;
  3166. priv->last_rx_err = rx_err;
  3167. ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
  3168. tx_failures_delta = tx_failures - priv->last_tx_failures;
  3169. priv->last_tx_failures = tx_failures;
  3170. rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
  3171. priv->last_rx_packets = priv->rx_packets;
  3172. tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
  3173. priv->last_tx_packets = priv->tx_packets;
  3174. /* Calculate quality based on the following:
  3175. *
  3176. * Missed beacon: 100% = 0, 0% = 70% missed
  3177. * Rate: 60% = 1Mbs, 100% = Max
  3178. * Rx and Tx errors represent a straight % of total Rx/Tx
  3179. * RSSI: 100% = > -50, 0% = < -80
  3180. * Rx errors: 100% = 0, 0% = 50% missed
  3181. *
  3182. * The lowest computed quality is used.
  3183. *
  3184. */
  3185. #define BEACON_THRESHOLD 5
  3186. beacon_quality = 100 - missed_beacons_percent;
  3187. if (beacon_quality < BEACON_THRESHOLD)
  3188. beacon_quality = 0;
  3189. else
  3190. beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
  3191. (100 - BEACON_THRESHOLD);
  3192. IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
  3193. beacon_quality, missed_beacons_percent);
  3194. priv->last_rate = ipw_get_current_rate(priv);
  3195. max_rate = ipw_get_max_rate(priv);
  3196. rate_quality = priv->last_rate * 40 / max_rate + 60;
  3197. IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
  3198. rate_quality, priv->last_rate / 1000000);
  3199. if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
  3200. rx_quality = 100 - (rx_err_delta * 100) /
  3201. (rx_packets_delta + rx_err_delta);
  3202. else
  3203. rx_quality = 100;
  3204. IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
  3205. rx_quality, rx_err_delta, rx_packets_delta);
  3206. if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
  3207. tx_quality = 100 - (tx_failures_delta * 100) /
  3208. (tx_packets_delta + tx_failures_delta);
  3209. else
  3210. tx_quality = 100;
  3211. IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
  3212. tx_quality, tx_failures_delta, tx_packets_delta);
  3213. rssi = average_value(&priv->average_rssi);
  3214. signal_quality =
  3215. (100 *
  3216. (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
  3217. (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
  3218. (priv->ieee->perfect_rssi - rssi) *
  3219. (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
  3220. 62 * (priv->ieee->perfect_rssi - rssi))) /
  3221. ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
  3222. (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
  3223. if (signal_quality > 100)
  3224. signal_quality = 100;
  3225. else if (signal_quality < 1)
  3226. signal_quality = 0;
  3227. IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
  3228. signal_quality, rssi);
  3229. quality = min(beacon_quality,
  3230. min(rate_quality,
  3231. min(tx_quality, min(rx_quality, signal_quality))));
  3232. if (quality == beacon_quality)
  3233. IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
  3234. quality);
  3235. if (quality == rate_quality)
  3236. IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
  3237. quality);
  3238. if (quality == tx_quality)
  3239. IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
  3240. quality);
  3241. if (quality == rx_quality)
  3242. IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
  3243. quality);
  3244. if (quality == signal_quality)
  3245. IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
  3246. quality);
  3247. priv->quality = quality;
  3248. queue_delayed_work(priv->workqueue, &priv->gather_stats,
  3249. IPW_STATS_INTERVAL);
  3250. }
  3251. static void ipw_bg_gather_stats(void *data)
  3252. {
  3253. struct ipw_priv *priv = data;
  3254. down(&priv->sem);
  3255. ipw_gather_stats(data);
  3256. up(&priv->sem);
  3257. }
  3258. static inline void ipw_handle_missed_beacon(struct ipw_priv *priv,
  3259. int missed_count)
  3260. {
  3261. priv->notif_missed_beacons = missed_count;
  3262. if (missed_count > priv->disassociate_threshold &&
  3263. priv->status & STATUS_ASSOCIATED) {
  3264. /* If associated and we've hit the missed
  3265. * beacon threshold, disassociate, turn
  3266. * off roaming, and abort any active scans */
  3267. IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
  3268. IPW_DL_STATE | IPW_DL_ASSOC,
  3269. "Missed beacon: %d - disassociate\n", missed_count);
  3270. priv->status &= ~STATUS_ROAMING;
  3271. if (priv->status & STATUS_SCANNING) {
  3272. IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
  3273. IPW_DL_STATE,
  3274. "Aborting scan with missed beacon.\n");
  3275. queue_work(priv->workqueue, &priv->abort_scan);
  3276. }
  3277. queue_work(priv->workqueue, &priv->disassociate);
  3278. return;
  3279. }
  3280. if (priv->status & STATUS_ROAMING) {
  3281. /* If we are currently roaming, then just
  3282. * print a debug statement... */
  3283. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
  3284. "Missed beacon: %d - roam in progress\n",
  3285. missed_count);
  3286. return;
  3287. }
  3288. if (missed_count > priv->roaming_threshold) {
  3289. /* If we are not already roaming, set the ROAM
  3290. * bit in the status and kick off a scan */
  3291. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
  3292. "Missed beacon: %d - initiate "
  3293. "roaming\n", missed_count);
  3294. if (!(priv->status & STATUS_ROAMING)) {
  3295. priv->status |= STATUS_ROAMING;
  3296. if (!(priv->status & STATUS_SCANNING))
  3297. queue_work(priv->workqueue,
  3298. &priv->request_scan);
  3299. }
  3300. return;
  3301. }
  3302. if (priv->status & STATUS_SCANNING) {
  3303. /* Stop scan to keep fw from getting
  3304. * stuck (only if we aren't roaming --
  3305. * otherwise we'll never scan more than 2 or 3
  3306. * channels..) */
  3307. IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
  3308. "Aborting scan with missed beacon.\n");
  3309. queue_work(priv->workqueue, &priv->abort_scan);
  3310. }
  3311. IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
  3312. }
  3313. /**
  3314. * Handle host notification packet.
  3315. * Called from interrupt routine
  3316. */
  3317. static inline void ipw_rx_notification(struct ipw_priv *priv,
  3318. struct ipw_rx_notification *notif)
  3319. {
  3320. notif->size = le16_to_cpu(notif->size);
  3321. IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
  3322. switch (notif->subtype) {
  3323. case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
  3324. struct notif_association *assoc = &notif->u.assoc;
  3325. switch (assoc->state) {
  3326. case CMAS_ASSOCIATED:{
  3327. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3328. IPW_DL_ASSOC,
  3329. "associated: '%s' " MAC_FMT
  3330. " \n",
  3331. escape_essid(priv->essid,
  3332. priv->essid_len),
  3333. MAC_ARG(priv->bssid));
  3334. switch (priv->ieee->iw_mode) {
  3335. case IW_MODE_INFRA:
  3336. memcpy(priv->ieee->bssid,
  3337. priv->bssid, ETH_ALEN);
  3338. break;
  3339. case IW_MODE_ADHOC:
  3340. memcpy(priv->ieee->bssid,
  3341. priv->bssid, ETH_ALEN);
  3342. /* clear out the station table */
  3343. priv->num_stations = 0;
  3344. IPW_DEBUG_ASSOC
  3345. ("queueing adhoc check\n");
  3346. queue_delayed_work(priv->
  3347. workqueue,
  3348. &priv->
  3349. adhoc_check,
  3350. priv->
  3351. assoc_request.
  3352. beacon_interval);
  3353. break;
  3354. }
  3355. priv->status &= ~STATUS_ASSOCIATING;
  3356. priv->status |= STATUS_ASSOCIATED;
  3357. queue_work(priv->workqueue,
  3358. &priv->system_config);
  3359. #ifdef CONFIG_IPW_QOS
  3360. #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
  3361. le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
  3362. if ((priv->status & STATUS_AUTH) &&
  3363. (IPW_GET_PACKET_STYPE(&notif->u.raw)
  3364. == IEEE80211_STYPE_ASSOC_RESP)) {
  3365. if ((sizeof
  3366. (struct
  3367. ieee80211_assoc_response)
  3368. <= notif->size)
  3369. && (notif->size <= 2314)) {
  3370. struct
  3371. ieee80211_rx_stats
  3372. stats = {
  3373. .len =
  3374. notif->
  3375. size - 1,
  3376. };
  3377. IPW_DEBUG_QOS
  3378. ("QoS Associate "
  3379. "size %d\n",
  3380. notif->size);
  3381. ieee80211_rx_mgt(priv->
  3382. ieee,
  3383. (struct
  3384. ieee80211_hdr_4addr
  3385. *)
  3386. &notif->u.raw, &stats);
  3387. }
  3388. }
  3389. #endif
  3390. schedule_work(&priv->link_up);
  3391. break;
  3392. }
  3393. case CMAS_AUTHENTICATED:{
  3394. if (priv->
  3395. status & (STATUS_ASSOCIATED |
  3396. STATUS_AUTH)) {
  3397. #ifdef CONFIG_IPW_DEBUG
  3398. struct notif_authenticate *auth
  3399. = &notif->u.auth;
  3400. IPW_DEBUG(IPW_DL_NOTIF |
  3401. IPW_DL_STATE |
  3402. IPW_DL_ASSOC,
  3403. "deauthenticated: '%s' "
  3404. MAC_FMT
  3405. ": (0x%04X) - %s \n",
  3406. escape_essid(priv->
  3407. essid,
  3408. priv->
  3409. essid_len),
  3410. MAC_ARG(priv->bssid),
  3411. ntohs(auth->status),
  3412. ipw_get_status_code
  3413. (ntohs
  3414. (auth->status)));
  3415. #endif
  3416. priv->status &=
  3417. ~(STATUS_ASSOCIATING |
  3418. STATUS_AUTH |
  3419. STATUS_ASSOCIATED);
  3420. schedule_work(&priv->link_down);
  3421. break;
  3422. }
  3423. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3424. IPW_DL_ASSOC,
  3425. "authenticated: '%s' " MAC_FMT
  3426. "\n",
  3427. escape_essid(priv->essid,
  3428. priv->essid_len),
  3429. MAC_ARG(priv->bssid));
  3430. break;
  3431. }
  3432. case CMAS_INIT:{
  3433. if (priv->status & STATUS_AUTH) {
  3434. struct
  3435. ieee80211_assoc_response
  3436. *resp;
  3437. resp =
  3438. (struct
  3439. ieee80211_assoc_response
  3440. *)&notif->u.raw;
  3441. IPW_DEBUG(IPW_DL_NOTIF |
  3442. IPW_DL_STATE |
  3443. IPW_DL_ASSOC,
  3444. "association failed (0x%04X): %s\n",
  3445. ntohs(resp->status),
  3446. ipw_get_status_code
  3447. (ntohs
  3448. (resp->status)));
  3449. }
  3450. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3451. IPW_DL_ASSOC,
  3452. "disassociated: '%s' " MAC_FMT
  3453. " \n",
  3454. escape_essid(priv->essid,
  3455. priv->essid_len),
  3456. MAC_ARG(priv->bssid));
  3457. priv->status &=
  3458. ~(STATUS_DISASSOCIATING |
  3459. STATUS_ASSOCIATING |
  3460. STATUS_ASSOCIATED | STATUS_AUTH);
  3461. if (priv->assoc_network
  3462. && (priv->assoc_network->
  3463. capability &
  3464. WLAN_CAPABILITY_IBSS))
  3465. ipw_remove_current_network
  3466. (priv);
  3467. schedule_work(&priv->link_down);
  3468. break;
  3469. }
  3470. case CMAS_RX_ASSOC_RESP:
  3471. break;
  3472. default:
  3473. IPW_ERROR("assoc: unknown (%d)\n",
  3474. assoc->state);
  3475. break;
  3476. }
  3477. break;
  3478. }
  3479. case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
  3480. struct notif_authenticate *auth = &notif->u.auth;
  3481. switch (auth->state) {
  3482. case CMAS_AUTHENTICATED:
  3483. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
  3484. "authenticated: '%s' " MAC_FMT " \n",
  3485. escape_essid(priv->essid,
  3486. priv->essid_len),
  3487. MAC_ARG(priv->bssid));
  3488. priv->status |= STATUS_AUTH;
  3489. break;
  3490. case CMAS_INIT:
  3491. if (priv->status & STATUS_AUTH) {
  3492. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3493. IPW_DL_ASSOC,
  3494. "authentication failed (0x%04X): %s\n",
  3495. ntohs(auth->status),
  3496. ipw_get_status_code(ntohs
  3497. (auth->
  3498. status)));
  3499. }
  3500. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3501. IPW_DL_ASSOC,
  3502. "deauthenticated: '%s' " MAC_FMT "\n",
  3503. escape_essid(priv->essid,
  3504. priv->essid_len),
  3505. MAC_ARG(priv->bssid));
  3506. priv->status &= ~(STATUS_ASSOCIATING |
  3507. STATUS_AUTH |
  3508. STATUS_ASSOCIATED);
  3509. schedule_work(&priv->link_down);
  3510. break;
  3511. case CMAS_TX_AUTH_SEQ_1:
  3512. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3513. IPW_DL_ASSOC, "AUTH_SEQ_1\n");
  3514. break;
  3515. case CMAS_RX_AUTH_SEQ_2:
  3516. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3517. IPW_DL_ASSOC, "AUTH_SEQ_2\n");
  3518. break;
  3519. case CMAS_AUTH_SEQ_1_PASS:
  3520. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3521. IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
  3522. break;
  3523. case CMAS_AUTH_SEQ_1_FAIL:
  3524. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3525. IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
  3526. break;
  3527. case CMAS_TX_AUTH_SEQ_3:
  3528. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3529. IPW_DL_ASSOC, "AUTH_SEQ_3\n");
  3530. break;
  3531. case CMAS_RX_AUTH_SEQ_4:
  3532. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3533. IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
  3534. break;
  3535. case CMAS_AUTH_SEQ_2_PASS:
  3536. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3537. IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
  3538. break;
  3539. case CMAS_AUTH_SEQ_2_FAIL:
  3540. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3541. IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
  3542. break;
  3543. case CMAS_TX_ASSOC:
  3544. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3545. IPW_DL_ASSOC, "TX_ASSOC\n");
  3546. break;
  3547. case CMAS_RX_ASSOC_RESP:
  3548. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3549. IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
  3550. break;
  3551. case CMAS_ASSOCIATED:
  3552. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3553. IPW_DL_ASSOC, "ASSOCIATED\n");
  3554. break;
  3555. default:
  3556. IPW_DEBUG_NOTIF("auth: failure - %d\n",
  3557. auth->state);
  3558. break;
  3559. }
  3560. break;
  3561. }
  3562. case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
  3563. struct notif_channel_result *x =
  3564. &notif->u.channel_result;
  3565. if (notif->size == sizeof(*x)) {
  3566. IPW_DEBUG_SCAN("Scan result for channel %d\n",
  3567. x->channel_num);
  3568. } else {
  3569. IPW_DEBUG_SCAN("Scan result of wrong size %d "
  3570. "(should be %zd)\n",
  3571. notif->size, sizeof(*x));
  3572. }
  3573. break;
  3574. }
  3575. case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
  3576. struct notif_scan_complete *x = &notif->u.scan_complete;
  3577. if (notif->size == sizeof(*x)) {
  3578. IPW_DEBUG_SCAN
  3579. ("Scan completed: type %d, %d channels, "
  3580. "%d status\n", x->scan_type,
  3581. x->num_channels, x->status);
  3582. } else {
  3583. IPW_ERROR("Scan completed of wrong size %d "
  3584. "(should be %zd)\n",
  3585. notif->size, sizeof(*x));
  3586. }
  3587. priv->status &=
  3588. ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
  3589. cancel_delayed_work(&priv->scan_check);
  3590. if (priv->status & STATUS_EXIT_PENDING)
  3591. break;
  3592. priv->ieee->scans++;
  3593. #ifdef CONFIG_IPW2200_MONITOR
  3594. if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
  3595. priv->status |= STATUS_SCAN_FORCED;
  3596. queue_work(priv->workqueue,
  3597. &priv->request_scan);
  3598. break;
  3599. }
  3600. priv->status &= ~STATUS_SCAN_FORCED;
  3601. #endif /* CONFIG_IPW2200_MONITOR */
  3602. if (!(priv->status & (STATUS_ASSOCIATED |
  3603. STATUS_ASSOCIATING |
  3604. STATUS_ROAMING |
  3605. STATUS_DISASSOCIATING)))
  3606. queue_work(priv->workqueue, &priv->associate);
  3607. else if (priv->status & STATUS_ROAMING) {
  3608. /* If a scan completed and we are in roam mode, then
  3609. * the scan that completed was the one requested as a
  3610. * result of entering roam... so, schedule the
  3611. * roam work */
  3612. queue_work(priv->workqueue, &priv->roam);
  3613. } else if (priv->status & STATUS_SCAN_PENDING)
  3614. queue_work(priv->workqueue,
  3615. &priv->request_scan);
  3616. else if (priv->config & CFG_BACKGROUND_SCAN
  3617. && priv->status & STATUS_ASSOCIATED)
  3618. queue_delayed_work(priv->workqueue,
  3619. &priv->request_scan, HZ);
  3620. break;
  3621. }
  3622. case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
  3623. struct notif_frag_length *x = &notif->u.frag_len;
  3624. if (notif->size == sizeof(*x))
  3625. IPW_ERROR("Frag length: %d\n",
  3626. le16_to_cpu(x->frag_length));
  3627. else
  3628. IPW_ERROR("Frag length of wrong size %d "
  3629. "(should be %zd)\n",
  3630. notif->size, sizeof(*x));
  3631. break;
  3632. }
  3633. case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
  3634. struct notif_link_deterioration *x =
  3635. &notif->u.link_deterioration;
  3636. if (notif->size == sizeof(*x)) {
  3637. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
  3638. "link deterioration: '%s' " MAC_FMT
  3639. " \n", escape_essid(priv->essid,
  3640. priv->essid_len),
  3641. MAC_ARG(priv->bssid));
  3642. memcpy(&priv->last_link_deterioration, x,
  3643. sizeof(*x));
  3644. } else {
  3645. IPW_ERROR("Link Deterioration of wrong size %d "
  3646. "(should be %zd)\n",
  3647. notif->size, sizeof(*x));
  3648. }
  3649. break;
  3650. }
  3651. case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
  3652. IPW_ERROR("Dino config\n");
  3653. if (priv->hcmd
  3654. && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
  3655. IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
  3656. break;
  3657. }
  3658. case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
  3659. struct notif_beacon_state *x = &notif->u.beacon_state;
  3660. if (notif->size != sizeof(*x)) {
  3661. IPW_ERROR
  3662. ("Beacon state of wrong size %d (should "
  3663. "be %zd)\n", notif->size, sizeof(*x));
  3664. break;
  3665. }
  3666. if (le32_to_cpu(x->state) ==
  3667. HOST_NOTIFICATION_STATUS_BEACON_MISSING)
  3668. ipw_handle_missed_beacon(priv,
  3669. le32_to_cpu(x->
  3670. number));
  3671. break;
  3672. }
  3673. case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
  3674. struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
  3675. if (notif->size == sizeof(*x)) {
  3676. IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
  3677. "0x%02x station %d\n",
  3678. x->key_state, x->security_type,
  3679. x->station_index);
  3680. break;
  3681. }
  3682. IPW_ERROR
  3683. ("TGi Tx Key of wrong size %d (should be %zd)\n",
  3684. notif->size, sizeof(*x));
  3685. break;
  3686. }
  3687. case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
  3688. struct notif_calibration *x = &notif->u.calibration;
  3689. if (notif->size == sizeof(*x)) {
  3690. memcpy(&priv->calib, x, sizeof(*x));
  3691. IPW_DEBUG_INFO("TODO: Calibration\n");
  3692. break;
  3693. }
  3694. IPW_ERROR
  3695. ("Calibration of wrong size %d (should be %zd)\n",
  3696. notif->size, sizeof(*x));
  3697. break;
  3698. }
  3699. case HOST_NOTIFICATION_NOISE_STATS:{
  3700. if (notif->size == sizeof(u32)) {
  3701. priv->last_noise =
  3702. (u8) (le32_to_cpu(notif->u.noise.value) &
  3703. 0xff);
  3704. average_add(&priv->average_noise,
  3705. priv->last_noise);
  3706. break;
  3707. }
  3708. IPW_ERROR
  3709. ("Noise stat is wrong size %d (should be %zd)\n",
  3710. notif->size, sizeof(u32));
  3711. break;
  3712. }
  3713. default:
  3714. IPW_ERROR("Unknown notification: "
  3715. "subtype=%d,flags=0x%2x,size=%d\n",
  3716. notif->subtype, notif->flags, notif->size);
  3717. }
  3718. }
  3719. /**
  3720. * Destroys all DMA structures and initialise them again
  3721. *
  3722. * @param priv
  3723. * @return error code
  3724. */
  3725. static int ipw_queue_reset(struct ipw_priv *priv)
  3726. {
  3727. int rc = 0;
  3728. /** @todo customize queue sizes */
  3729. int nTx = 64, nTxCmd = 8;
  3730. ipw_tx_queue_free(priv);
  3731. /* Tx CMD queue */
  3732. rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
  3733. IPW_TX_CMD_QUEUE_READ_INDEX,
  3734. IPW_TX_CMD_QUEUE_WRITE_INDEX,
  3735. IPW_TX_CMD_QUEUE_BD_BASE,
  3736. IPW_TX_CMD_QUEUE_BD_SIZE);
  3737. if (rc) {
  3738. IPW_ERROR("Tx Cmd queue init failed\n");
  3739. goto error;
  3740. }
  3741. /* Tx queue(s) */
  3742. rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
  3743. IPW_TX_QUEUE_0_READ_INDEX,
  3744. IPW_TX_QUEUE_0_WRITE_INDEX,
  3745. IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
  3746. if (rc) {
  3747. IPW_ERROR("Tx 0 queue init failed\n");
  3748. goto error;
  3749. }
  3750. rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
  3751. IPW_TX_QUEUE_1_READ_INDEX,
  3752. IPW_TX_QUEUE_1_WRITE_INDEX,
  3753. IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
  3754. if (rc) {
  3755. IPW_ERROR("Tx 1 queue init failed\n");
  3756. goto error;
  3757. }
  3758. rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
  3759. IPW_TX_QUEUE_2_READ_INDEX,
  3760. IPW_TX_QUEUE_2_WRITE_INDEX,
  3761. IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
  3762. if (rc) {
  3763. IPW_ERROR("Tx 2 queue init failed\n");
  3764. goto error;
  3765. }
  3766. rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
  3767. IPW_TX_QUEUE_3_READ_INDEX,
  3768. IPW_TX_QUEUE_3_WRITE_INDEX,
  3769. IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
  3770. if (rc) {
  3771. IPW_ERROR("Tx 3 queue init failed\n");
  3772. goto error;
  3773. }
  3774. /* statistics */
  3775. priv->rx_bufs_min = 0;
  3776. priv->rx_pend_max = 0;
  3777. return rc;
  3778. error:
  3779. ipw_tx_queue_free(priv);
  3780. return rc;
  3781. }
  3782. /**
  3783. * Reclaim Tx queue entries no more used by NIC.
  3784. *
  3785. * When FW adwances 'R' index, all entries between old and
  3786. * new 'R' index need to be reclaimed. As result, some free space
  3787. * forms. If there is enough free space (> low mark), wake Tx queue.
  3788. *
  3789. * @note Need to protect against garbage in 'R' index
  3790. * @param priv
  3791. * @param txq
  3792. * @param qindex
  3793. * @return Number of used entries remains in the queue
  3794. */
  3795. static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
  3796. struct clx2_tx_queue *txq, int qindex)
  3797. {
  3798. u32 hw_tail;
  3799. int used;
  3800. struct clx2_queue *q = &txq->q;
  3801. hw_tail = ipw_read32(priv, q->reg_r);
  3802. if (hw_tail >= q->n_bd) {
  3803. IPW_ERROR
  3804. ("Read index for DMA queue (%d) is out of range [0-%d)\n",
  3805. hw_tail, q->n_bd);
  3806. goto done;
  3807. }
  3808. for (; q->last_used != hw_tail;
  3809. q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
  3810. ipw_queue_tx_free_tfd(priv, txq);
  3811. priv->tx_packets++;
  3812. }
  3813. done:
  3814. if (ipw_queue_space(q) > q->low_mark && qindex >= 0)
  3815. __maybe_wake_tx(priv);
  3816. used = q->first_empty - q->last_used;
  3817. if (used < 0)
  3818. used += q->n_bd;
  3819. return used;
  3820. }
  3821. static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
  3822. int len, int sync)
  3823. {
  3824. struct clx2_tx_queue *txq = &priv->txq_cmd;
  3825. struct clx2_queue *q = &txq->q;
  3826. struct tfd_frame *tfd;
  3827. if (ipw_queue_space(q) < (sync ? 1 : 2)) {
  3828. IPW_ERROR("No space for Tx\n");
  3829. return -EBUSY;
  3830. }
  3831. tfd = &txq->bd[q->first_empty];
  3832. txq->txb[q->first_empty] = NULL;
  3833. memset(tfd, 0, sizeof(*tfd));
  3834. tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
  3835. tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
  3836. priv->hcmd_seq++;
  3837. tfd->u.cmd.index = hcmd;
  3838. tfd->u.cmd.length = len;
  3839. memcpy(tfd->u.cmd.payload, buf, len);
  3840. q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
  3841. ipw_write32(priv, q->reg_w, q->first_empty);
  3842. _ipw_read32(priv, 0x90);
  3843. return 0;
  3844. }
  3845. /*
  3846. * Rx theory of operation
  3847. *
  3848. * The host allocates 32 DMA target addresses and passes the host address
  3849. * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
  3850. * 0 to 31
  3851. *
  3852. * Rx Queue Indexes
  3853. * The host/firmware share two index registers for managing the Rx buffers.
  3854. *
  3855. * The READ index maps to the first position that the firmware may be writing
  3856. * to -- the driver can read up to (but not including) this position and get
  3857. * good data.
  3858. * The READ index is managed by the firmware once the card is enabled.
  3859. *
  3860. * The WRITE index maps to the last position the driver has read from -- the
  3861. * position preceding WRITE is the last slot the firmware can place a packet.
  3862. *
  3863. * The queue is empty (no good data) if WRITE = READ - 1, and is full if
  3864. * WRITE = READ.
  3865. *
  3866. * During initialization the host sets up the READ queue position to the first
  3867. * INDEX position, and WRITE to the last (READ - 1 wrapped)
  3868. *
  3869. * When the firmware places a packet in a buffer it will advance the READ index
  3870. * and fire the RX interrupt. The driver can then query the READ index and
  3871. * process as many packets as possible, moving the WRITE index forward as it
  3872. * resets the Rx queue buffers with new memory.
  3873. *
  3874. * The management in the driver is as follows:
  3875. * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
  3876. * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
  3877. * to replensish the ipw->rxq->rx_free.
  3878. * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
  3879. * ipw->rxq is replenished and the READ INDEX is updated (updating the
  3880. * 'processed' and 'read' driver indexes as well)
  3881. * + A received packet is processed and handed to the kernel network stack,
  3882. * detached from the ipw->rxq. The driver 'processed' index is updated.
  3883. * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
  3884. * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
  3885. * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
  3886. * were enough free buffers and RX_STALLED is set it is cleared.
  3887. *
  3888. *
  3889. * Driver sequence:
  3890. *
  3891. * ipw_rx_queue_alloc() Allocates rx_free
  3892. * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
  3893. * ipw_rx_queue_restock
  3894. * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
  3895. * queue, updates firmware pointers, and updates
  3896. * the WRITE index. If insufficient rx_free buffers
  3897. * are available, schedules ipw_rx_queue_replenish
  3898. *
  3899. * -- enable interrupts --
  3900. * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
  3901. * READ INDEX, detaching the SKB from the pool.
  3902. * Moves the packet buffer from queue to rx_used.
  3903. * Calls ipw_rx_queue_restock to refill any empty
  3904. * slots.
  3905. * ...
  3906. *
  3907. */
  3908. /*
  3909. * If there are slots in the RX queue that need to be restocked,
  3910. * and we have free pre-allocated buffers, fill the ranks as much
  3911. * as we can pulling from rx_free.
  3912. *
  3913. * This moves the 'write' index forward to catch up with 'processed', and
  3914. * also updates the memory address in the firmware to reference the new
  3915. * target buffer.
  3916. */
  3917. static void ipw_rx_queue_restock(struct ipw_priv *priv)
  3918. {
  3919. struct ipw_rx_queue *rxq = priv->rxq;
  3920. struct list_head *element;
  3921. struct ipw_rx_mem_buffer *rxb;
  3922. unsigned long flags;
  3923. int write;
  3924. spin_lock_irqsave(&rxq->lock, flags);
  3925. write = rxq->write;
  3926. while ((rxq->write != rxq->processed) && (rxq->free_count)) {
  3927. element = rxq->rx_free.next;
  3928. rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
  3929. list_del(element);
  3930. ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
  3931. rxb->dma_addr);
  3932. rxq->queue[rxq->write] = rxb;
  3933. rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
  3934. rxq->free_count--;
  3935. }
  3936. spin_unlock_irqrestore(&rxq->lock, flags);
  3937. /* If the pre-allocated buffer pool is dropping low, schedule to
  3938. * refill it */
  3939. if (rxq->free_count <= RX_LOW_WATERMARK)
  3940. queue_work(priv->workqueue, &priv->rx_replenish);
  3941. /* If we've added more space for the firmware to place data, tell it */
  3942. if (write != rxq->write)
  3943. ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
  3944. }
  3945. /*
  3946. * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
  3947. * Also restock the Rx queue via ipw_rx_queue_restock.
  3948. *
  3949. * This is called as a scheduled work item (except for during intialization)
  3950. */
  3951. static void ipw_rx_queue_replenish(void *data)
  3952. {
  3953. struct ipw_priv *priv = data;
  3954. struct ipw_rx_queue *rxq = priv->rxq;
  3955. struct list_head *element;
  3956. struct ipw_rx_mem_buffer *rxb;
  3957. unsigned long flags;
  3958. spin_lock_irqsave(&rxq->lock, flags);
  3959. while (!list_empty(&rxq->rx_used)) {
  3960. element = rxq->rx_used.next;
  3961. rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
  3962. rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
  3963. if (!rxb->skb) {
  3964. printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
  3965. priv->net_dev->name);
  3966. /* We don't reschedule replenish work here -- we will
  3967. * call the restock method and if it still needs
  3968. * more buffers it will schedule replenish */
  3969. break;
  3970. }
  3971. list_del(element);
  3972. rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
  3973. rxb->dma_addr =
  3974. pci_map_single(priv->pci_dev, rxb->skb->data,
  3975. IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
  3976. list_add_tail(&rxb->list, &rxq->rx_free);
  3977. rxq->free_count++;
  3978. }
  3979. spin_unlock_irqrestore(&rxq->lock, flags);
  3980. ipw_rx_queue_restock(priv);
  3981. }
  3982. static void ipw_bg_rx_queue_replenish(void *data)
  3983. {
  3984. struct ipw_priv *priv = data;
  3985. down(&priv->sem);
  3986. ipw_rx_queue_replenish(data);
  3987. up(&priv->sem);
  3988. }
  3989. /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
  3990. * If an SKB has been detached, the POOL needs to have it's SKB set to NULL
  3991. * This free routine walks the list of POOL entries and if SKB is set to
  3992. * non NULL it is unmapped and freed
  3993. */
  3994. static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
  3995. {
  3996. int i;
  3997. if (!rxq)
  3998. return;
  3999. for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
  4000. if (rxq->pool[i].skb != NULL) {
  4001. pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
  4002. IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
  4003. dev_kfree_skb(rxq->pool[i].skb);
  4004. }
  4005. }
  4006. kfree(rxq);
  4007. }
  4008. static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
  4009. {
  4010. struct ipw_rx_queue *rxq;
  4011. int i;
  4012. rxq = (struct ipw_rx_queue *)kmalloc(sizeof(*rxq), GFP_KERNEL);
  4013. if (unlikely(!rxq)) {
  4014. IPW_ERROR("memory allocation failed\n");
  4015. return NULL;
  4016. }
  4017. memset(rxq, 0, sizeof(*rxq));
  4018. spin_lock_init(&rxq->lock);
  4019. INIT_LIST_HEAD(&rxq->rx_free);
  4020. INIT_LIST_HEAD(&rxq->rx_used);
  4021. /* Fill the rx_used queue with _all_ of the Rx buffers */
  4022. for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
  4023. list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
  4024. /* Set us so that we have processed and used all buffers, but have
  4025. * not restocked the Rx queue with fresh buffers */
  4026. rxq->read = rxq->write = 0;
  4027. rxq->processed = RX_QUEUE_SIZE - 1;
  4028. rxq->free_count = 0;
  4029. return rxq;
  4030. }
  4031. static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
  4032. {
  4033. rate &= ~IEEE80211_BASIC_RATE_MASK;
  4034. if (ieee_mode == IEEE_A) {
  4035. switch (rate) {
  4036. case IEEE80211_OFDM_RATE_6MB:
  4037. return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
  4038. 1 : 0;
  4039. case IEEE80211_OFDM_RATE_9MB:
  4040. return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
  4041. 1 : 0;
  4042. case IEEE80211_OFDM_RATE_12MB:
  4043. return priv->
  4044. rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
  4045. case IEEE80211_OFDM_RATE_18MB:
  4046. return priv->
  4047. rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
  4048. case IEEE80211_OFDM_RATE_24MB:
  4049. return priv->
  4050. rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
  4051. case IEEE80211_OFDM_RATE_36MB:
  4052. return priv->
  4053. rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
  4054. case IEEE80211_OFDM_RATE_48MB:
  4055. return priv->
  4056. rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
  4057. case IEEE80211_OFDM_RATE_54MB:
  4058. return priv->
  4059. rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
  4060. default:
  4061. return 0;
  4062. }
  4063. }
  4064. /* B and G mixed */
  4065. switch (rate) {
  4066. case IEEE80211_CCK_RATE_1MB:
  4067. return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
  4068. case IEEE80211_CCK_RATE_2MB:
  4069. return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
  4070. case IEEE80211_CCK_RATE_5MB:
  4071. return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
  4072. case IEEE80211_CCK_RATE_11MB:
  4073. return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
  4074. }
  4075. /* If we are limited to B modulations, bail at this point */
  4076. if (ieee_mode == IEEE_B)
  4077. return 0;
  4078. /* G */
  4079. switch (rate) {
  4080. case IEEE80211_OFDM_RATE_6MB:
  4081. return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
  4082. case IEEE80211_OFDM_RATE_9MB:
  4083. return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
  4084. case IEEE80211_OFDM_RATE_12MB:
  4085. return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
  4086. case IEEE80211_OFDM_RATE_18MB:
  4087. return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
  4088. case IEEE80211_OFDM_RATE_24MB:
  4089. return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
  4090. case IEEE80211_OFDM_RATE_36MB:
  4091. return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
  4092. case IEEE80211_OFDM_RATE_48MB:
  4093. return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
  4094. case IEEE80211_OFDM_RATE_54MB:
  4095. return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
  4096. }
  4097. return 0;
  4098. }
  4099. static int ipw_compatible_rates(struct ipw_priv *priv,
  4100. const struct ieee80211_network *network,
  4101. struct ipw_supported_rates *rates)
  4102. {
  4103. int num_rates, i;
  4104. memset(rates, 0, sizeof(*rates));
  4105. num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
  4106. rates->num_rates = 0;
  4107. for (i = 0; i < num_rates; i++) {
  4108. if (!ipw_is_rate_in_mask(priv, network->mode,
  4109. network->rates[i])) {
  4110. if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
  4111. IPW_DEBUG_SCAN("Adding masked mandatory "
  4112. "rate %02X\n",
  4113. network->rates[i]);
  4114. rates->supported_rates[rates->num_rates++] =
  4115. network->rates[i];
  4116. continue;
  4117. }
  4118. IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
  4119. network->rates[i], priv->rates_mask);
  4120. continue;
  4121. }
  4122. rates->supported_rates[rates->num_rates++] = network->rates[i];
  4123. }
  4124. num_rates = min(network->rates_ex_len,
  4125. (u8) (IPW_MAX_RATES - num_rates));
  4126. for (i = 0; i < num_rates; i++) {
  4127. if (!ipw_is_rate_in_mask(priv, network->mode,
  4128. network->rates_ex[i])) {
  4129. if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
  4130. IPW_DEBUG_SCAN("Adding masked mandatory "
  4131. "rate %02X\n",
  4132. network->rates_ex[i]);
  4133. rates->supported_rates[rates->num_rates++] =
  4134. network->rates[i];
  4135. continue;
  4136. }
  4137. IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
  4138. network->rates_ex[i], priv->rates_mask);
  4139. continue;
  4140. }
  4141. rates->supported_rates[rates->num_rates++] =
  4142. network->rates_ex[i];
  4143. }
  4144. return 1;
  4145. }
  4146. static inline void ipw_copy_rates(struct ipw_supported_rates *dest,
  4147. const struct ipw_supported_rates *src)
  4148. {
  4149. u8 i;
  4150. for (i = 0; i < src->num_rates; i++)
  4151. dest->supported_rates[i] = src->supported_rates[i];
  4152. dest->num_rates = src->num_rates;
  4153. }
  4154. /* TODO: Look at sniffed packets in the air to determine if the basic rate
  4155. * mask should ever be used -- right now all callers to add the scan rates are
  4156. * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
  4157. static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
  4158. u8 modulation, u32 rate_mask)
  4159. {
  4160. u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
  4161. IEEE80211_BASIC_RATE_MASK : 0;
  4162. if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
  4163. rates->supported_rates[rates->num_rates++] =
  4164. IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
  4165. if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
  4166. rates->supported_rates[rates->num_rates++] =
  4167. IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
  4168. if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
  4169. rates->supported_rates[rates->num_rates++] = basic_mask |
  4170. IEEE80211_CCK_RATE_5MB;
  4171. if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
  4172. rates->supported_rates[rates->num_rates++] = basic_mask |
  4173. IEEE80211_CCK_RATE_11MB;
  4174. }
  4175. static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
  4176. u8 modulation, u32 rate_mask)
  4177. {
  4178. u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
  4179. IEEE80211_BASIC_RATE_MASK : 0;
  4180. if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
  4181. rates->supported_rates[rates->num_rates++] = basic_mask |
  4182. IEEE80211_OFDM_RATE_6MB;
  4183. if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
  4184. rates->supported_rates[rates->num_rates++] =
  4185. IEEE80211_OFDM_RATE_9MB;
  4186. if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
  4187. rates->supported_rates[rates->num_rates++] = basic_mask |
  4188. IEEE80211_OFDM_RATE_12MB;
  4189. if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
  4190. rates->supported_rates[rates->num_rates++] =
  4191. IEEE80211_OFDM_RATE_18MB;
  4192. if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
  4193. rates->supported_rates[rates->num_rates++] = basic_mask |
  4194. IEEE80211_OFDM_RATE_24MB;
  4195. if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
  4196. rates->supported_rates[rates->num_rates++] =
  4197. IEEE80211_OFDM_RATE_36MB;
  4198. if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
  4199. rates->supported_rates[rates->num_rates++] =
  4200. IEEE80211_OFDM_RATE_48MB;
  4201. if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
  4202. rates->supported_rates[rates->num_rates++] =
  4203. IEEE80211_OFDM_RATE_54MB;
  4204. }
  4205. struct ipw_network_match {
  4206. struct ieee80211_network *network;
  4207. struct ipw_supported_rates rates;
  4208. };
  4209. static int ipw_find_adhoc_network(struct ipw_priv *priv,
  4210. struct ipw_network_match *match,
  4211. struct ieee80211_network *network,
  4212. int roaming)
  4213. {
  4214. struct ipw_supported_rates rates;
  4215. /* Verify that this network's capability is compatible with the
  4216. * current mode (AdHoc or Infrastructure) */
  4217. if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
  4218. !(network->capability & WLAN_CAPABILITY_IBSS))) {
  4219. IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
  4220. "capability mismatch.\n",
  4221. escape_essid(network->ssid, network->ssid_len),
  4222. MAC_ARG(network->bssid));
  4223. return 0;
  4224. }
  4225. /* If we do not have an ESSID for this AP, we can not associate with
  4226. * it */
  4227. if (network->flags & NETWORK_EMPTY_ESSID) {
  4228. IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
  4229. "because of hidden ESSID.\n",
  4230. escape_essid(network->ssid, network->ssid_len),
  4231. MAC_ARG(network->bssid));
  4232. return 0;
  4233. }
  4234. if (unlikely(roaming)) {
  4235. /* If we are roaming, then ensure check if this is a valid
  4236. * network to try and roam to */
  4237. if ((network->ssid_len != match->network->ssid_len) ||
  4238. memcmp(network->ssid, match->network->ssid,
  4239. network->ssid_len)) {
  4240. IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
  4241. "because of non-network ESSID.\n",
  4242. escape_essid(network->ssid,
  4243. network->ssid_len),
  4244. MAC_ARG(network->bssid));
  4245. return 0;
  4246. }
  4247. } else {
  4248. /* If an ESSID has been configured then compare the broadcast
  4249. * ESSID to ours */
  4250. if ((priv->config & CFG_STATIC_ESSID) &&
  4251. ((network->ssid_len != priv->essid_len) ||
  4252. memcmp(network->ssid, priv->essid,
  4253. min(network->ssid_len, priv->essid_len)))) {
  4254. char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
  4255. strncpy(escaped,
  4256. escape_essid(network->ssid, network->ssid_len),
  4257. sizeof(escaped));
  4258. IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
  4259. "because of ESSID mismatch: '%s'.\n",
  4260. escaped, MAC_ARG(network->bssid),
  4261. escape_essid(priv->essid,
  4262. priv->essid_len));
  4263. return 0;
  4264. }
  4265. }
  4266. /* If the old network rate is better than this one, don't bother
  4267. * testing everything else. */
  4268. if (network->time_stamp[0] < match->network->time_stamp[0]) {
  4269. IPW_DEBUG_MERGE("Network '%s excluded because newer than "
  4270. "current network.\n",
  4271. escape_essid(match->network->ssid,
  4272. match->network->ssid_len));
  4273. return 0;
  4274. } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
  4275. IPW_DEBUG_MERGE("Network '%s excluded because newer than "
  4276. "current network.\n",
  4277. escape_essid(match->network->ssid,
  4278. match->network->ssid_len));
  4279. return 0;
  4280. }
  4281. /* Now go through and see if the requested network is valid... */
  4282. if (priv->ieee->scan_age != 0 &&
  4283. time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
  4284. IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
  4285. "because of age: %lums.\n",
  4286. escape_essid(network->ssid, network->ssid_len),
  4287. MAC_ARG(network->bssid),
  4288. 1000 * (jiffies - network->last_scanned) / HZ);
  4289. return 0;
  4290. }
  4291. if ((priv->config & CFG_STATIC_CHANNEL) &&
  4292. (network->channel != priv->channel)) {
  4293. IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
  4294. "because of channel mismatch: %d != %d.\n",
  4295. escape_essid(network->ssid, network->ssid_len),
  4296. MAC_ARG(network->bssid),
  4297. network->channel, priv->channel);
  4298. return 0;
  4299. }
  4300. /* Verify privacy compatability */
  4301. if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
  4302. ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
  4303. IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
  4304. "because of privacy mismatch: %s != %s.\n",
  4305. escape_essid(network->ssid, network->ssid_len),
  4306. MAC_ARG(network->bssid),
  4307. priv->
  4308. capability & CAP_PRIVACY_ON ? "on" : "off",
  4309. network->
  4310. capability & WLAN_CAPABILITY_PRIVACY ? "on" :
  4311. "off");
  4312. return 0;
  4313. }
  4314. if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
  4315. IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
  4316. "because of the same BSSID match: " MAC_FMT
  4317. ".\n", escape_essid(network->ssid,
  4318. network->ssid_len),
  4319. MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
  4320. return 0;
  4321. }
  4322. /* Filter out any incompatible freq / mode combinations */
  4323. if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
  4324. IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
  4325. "because of invalid frequency/mode "
  4326. "combination.\n",
  4327. escape_essid(network->ssid, network->ssid_len),
  4328. MAC_ARG(network->bssid));
  4329. return 0;
  4330. }
  4331. /* Ensure that the rates supported by the driver are compatible with
  4332. * this AP, including verification of basic rates (mandatory) */
  4333. if (!ipw_compatible_rates(priv, network, &rates)) {
  4334. IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
  4335. "because configured rate mask excludes "
  4336. "AP mandatory rate.\n",
  4337. escape_essid(network->ssid, network->ssid_len),
  4338. MAC_ARG(network->bssid));
  4339. return 0;
  4340. }
  4341. if (rates.num_rates == 0) {
  4342. IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
  4343. "because of no compatible rates.\n",
  4344. escape_essid(network->ssid, network->ssid_len),
  4345. MAC_ARG(network->bssid));
  4346. return 0;
  4347. }
  4348. /* TODO: Perform any further minimal comparititive tests. We do not
  4349. * want to put too much policy logic here; intelligent scan selection
  4350. * should occur within a generic IEEE 802.11 user space tool. */
  4351. /* Set up 'new' AP to this network */
  4352. ipw_copy_rates(&match->rates, &rates);
  4353. match->network = network;
  4354. IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
  4355. escape_essid(network->ssid, network->ssid_len),
  4356. MAC_ARG(network->bssid));
  4357. return 1;
  4358. }
  4359. static void ipw_merge_adhoc_network(void *data)
  4360. {
  4361. struct ipw_priv *priv = data;
  4362. struct ieee80211_network *network = NULL;
  4363. struct ipw_network_match match = {
  4364. .network = priv->assoc_network
  4365. };
  4366. if ((priv->status & STATUS_ASSOCIATED) &&
  4367. (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
  4368. /* First pass through ROAM process -- look for a better
  4369. * network */
  4370. unsigned long flags;
  4371. spin_lock_irqsave(&priv->ieee->lock, flags);
  4372. list_for_each_entry(network, &priv->ieee->network_list, list) {
  4373. if (network != priv->assoc_network)
  4374. ipw_find_adhoc_network(priv, &match, network,
  4375. 1);
  4376. }
  4377. spin_unlock_irqrestore(&priv->ieee->lock, flags);
  4378. if (match.network == priv->assoc_network) {
  4379. IPW_DEBUG_MERGE("No better ADHOC in this network to "
  4380. "merge to.\n");
  4381. return;
  4382. }
  4383. down(&priv->sem);
  4384. if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
  4385. IPW_DEBUG_MERGE("remove network %s\n",
  4386. escape_essid(priv->essid,
  4387. priv->essid_len));
  4388. ipw_remove_current_network(priv);
  4389. }
  4390. ipw_disassociate(priv);
  4391. priv->assoc_network = match.network;
  4392. up(&priv->sem);
  4393. return;
  4394. }
  4395. }
  4396. static int ipw_best_network(struct ipw_priv *priv,
  4397. struct ipw_network_match *match,
  4398. struct ieee80211_network *network, int roaming)
  4399. {
  4400. struct ipw_supported_rates rates;
  4401. /* Verify that this network's capability is compatible with the
  4402. * current mode (AdHoc or Infrastructure) */
  4403. if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
  4404. !(network->capability & WLAN_CAPABILITY_ESS)) ||
  4405. (priv->ieee->iw_mode == IW_MODE_ADHOC &&
  4406. !(network->capability & WLAN_CAPABILITY_IBSS))) {
  4407. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
  4408. "capability mismatch.\n",
  4409. escape_essid(network->ssid, network->ssid_len),
  4410. MAC_ARG(network->bssid));
  4411. return 0;
  4412. }
  4413. /* If we do not have an ESSID for this AP, we can not associate with
  4414. * it */
  4415. if (network->flags & NETWORK_EMPTY_ESSID) {
  4416. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
  4417. "because of hidden ESSID.\n",
  4418. escape_essid(network->ssid, network->ssid_len),
  4419. MAC_ARG(network->bssid));
  4420. return 0;
  4421. }
  4422. if (unlikely(roaming)) {
  4423. /* If we are roaming, then ensure check if this is a valid
  4424. * network to try and roam to */
  4425. if ((network->ssid_len != match->network->ssid_len) ||
  4426. memcmp(network->ssid, match->network->ssid,
  4427. network->ssid_len)) {
  4428. IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
  4429. "because of non-network ESSID.\n",
  4430. escape_essid(network->ssid,
  4431. network->ssid_len),
  4432. MAC_ARG(network->bssid));
  4433. return 0;
  4434. }
  4435. } else {
  4436. /* If an ESSID has been configured then compare the broadcast
  4437. * ESSID to ours */
  4438. if ((priv->config & CFG_STATIC_ESSID) &&
  4439. ((network->ssid_len != priv->essid_len) ||
  4440. memcmp(network->ssid, priv->essid,
  4441. min(network->ssid_len, priv->essid_len)))) {
  4442. char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
  4443. strncpy(escaped,
  4444. escape_essid(network->ssid, network->ssid_len),
  4445. sizeof(escaped));
  4446. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
  4447. "because of ESSID mismatch: '%s'.\n",
  4448. escaped, MAC_ARG(network->bssid),
  4449. escape_essid(priv->essid,
  4450. priv->essid_len));
  4451. return 0;
  4452. }
  4453. }
  4454. /* If the old network rate is better than this one, don't bother
  4455. * testing everything else. */
  4456. if (match->network && match->network->stats.rssi > network->stats.rssi) {
  4457. char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
  4458. strncpy(escaped,
  4459. escape_essid(network->ssid, network->ssid_len),
  4460. sizeof(escaped));
  4461. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
  4462. "'%s (" MAC_FMT ")' has a stronger signal.\n",
  4463. escaped, MAC_ARG(network->bssid),
  4464. escape_essid(match->network->ssid,
  4465. match->network->ssid_len),
  4466. MAC_ARG(match->network->bssid));
  4467. return 0;
  4468. }
  4469. /* If this network has already had an association attempt within the
  4470. * last 3 seconds, do not try and associate again... */
  4471. if (network->last_associate &&
  4472. time_after(network->last_associate + (HZ * 3UL), jiffies)) {
  4473. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
  4474. "because of storming (%lus since last "
  4475. "assoc attempt).\n",
  4476. escape_essid(network->ssid, network->ssid_len),
  4477. MAC_ARG(network->bssid),
  4478. (jiffies - network->last_associate) / HZ);
  4479. return 0;
  4480. }
  4481. /* Now go through and see if the requested network is valid... */
  4482. if (priv->ieee->scan_age != 0 &&
  4483. time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
  4484. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
  4485. "because of age: %lums.\n",
  4486. escape_essid(network->ssid, network->ssid_len),
  4487. MAC_ARG(network->bssid),
  4488. 1000 * (jiffies - network->last_scanned) / HZ);
  4489. return 0;
  4490. }
  4491. if ((priv->config & CFG_STATIC_CHANNEL) &&
  4492. (network->channel != priv->channel)) {
  4493. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
  4494. "because of channel mismatch: %d != %d.\n",
  4495. escape_essid(network->ssid, network->ssid_len),
  4496. MAC_ARG(network->bssid),
  4497. network->channel, priv->channel);
  4498. return 0;
  4499. }
  4500. /* Verify privacy compatability */
  4501. if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
  4502. ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
  4503. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
  4504. "because of privacy mismatch: %s != %s.\n",
  4505. escape_essid(network->ssid, network->ssid_len),
  4506. MAC_ARG(network->bssid),
  4507. priv->capability & CAP_PRIVACY_ON ? "on" :
  4508. "off",
  4509. network->capability &
  4510. WLAN_CAPABILITY_PRIVACY ? "on" : "off");
  4511. return 0;
  4512. }
  4513. if ((priv->config & CFG_STATIC_BSSID) &&
  4514. memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
  4515. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
  4516. "because of BSSID mismatch: " MAC_FMT ".\n",
  4517. escape_essid(network->ssid, network->ssid_len),
  4518. MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
  4519. return 0;
  4520. }
  4521. /* Filter out any incompatible freq / mode combinations */
  4522. if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
  4523. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
  4524. "because of invalid frequency/mode "
  4525. "combination.\n",
  4526. escape_essid(network->ssid, network->ssid_len),
  4527. MAC_ARG(network->bssid));
  4528. return 0;
  4529. }
  4530. /* Ensure that the rates supported by the driver are compatible with
  4531. * this AP, including verification of basic rates (mandatory) */
  4532. if (!ipw_compatible_rates(priv, network, &rates)) {
  4533. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
  4534. "because configured rate mask excludes "
  4535. "AP mandatory rate.\n",
  4536. escape_essid(network->ssid, network->ssid_len),
  4537. MAC_ARG(network->bssid));
  4538. return 0;
  4539. }
  4540. if (rates.num_rates == 0) {
  4541. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
  4542. "because of no compatible rates.\n",
  4543. escape_essid(network->ssid, network->ssid_len),
  4544. MAC_ARG(network->bssid));
  4545. return 0;
  4546. }
  4547. /* TODO: Perform any further minimal comparititive tests. We do not
  4548. * want to put too much policy logic here; intelligent scan selection
  4549. * should occur within a generic IEEE 802.11 user space tool. */
  4550. /* Set up 'new' AP to this network */
  4551. ipw_copy_rates(&match->rates, &rates);
  4552. match->network = network;
  4553. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
  4554. escape_essid(network->ssid, network->ssid_len),
  4555. MAC_ARG(network->bssid));
  4556. return 1;
  4557. }
  4558. static void ipw_adhoc_create(struct ipw_priv *priv,
  4559. struct ieee80211_network *network)
  4560. {
  4561. const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
  4562. int i;
  4563. /*
  4564. * For the purposes of scanning, we can set our wireless mode
  4565. * to trigger scans across combinations of bands, but when it
  4566. * comes to creating a new ad-hoc network, we have tell the FW
  4567. * exactly which band to use.
  4568. *
  4569. * We also have the possibility of an invalid channel for the
  4570. * chossen band. Attempting to create a new ad-hoc network
  4571. * with an invalid channel for wireless mode will trigger a
  4572. * FW fatal error.
  4573. *
  4574. */
  4575. switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
  4576. case IEEE80211_52GHZ_BAND:
  4577. network->mode = IEEE_A;
  4578. i = ieee80211_channel_to_index(priv->ieee, priv->channel);
  4579. if (i == -1)
  4580. BUG();
  4581. if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
  4582. IPW_WARNING("Overriding invalid channel\n");
  4583. priv->channel = geo->a[0].channel;
  4584. }
  4585. break;
  4586. case IEEE80211_24GHZ_BAND:
  4587. if (priv->ieee->mode & IEEE_G)
  4588. network->mode = IEEE_G;
  4589. else
  4590. network->mode = IEEE_B;
  4591. break;
  4592. default:
  4593. IPW_WARNING("Overriding invalid channel\n");
  4594. if (priv->ieee->mode & IEEE_A) {
  4595. network->mode = IEEE_A;
  4596. priv->channel = geo->a[0].channel;
  4597. } else if (priv->ieee->mode & IEEE_G) {
  4598. network->mode = IEEE_G;
  4599. priv->channel = geo->bg[0].channel;
  4600. } else {
  4601. network->mode = IEEE_B;
  4602. priv->channel = geo->bg[0].channel;
  4603. }
  4604. break;
  4605. }
  4606. network->channel = priv->channel;
  4607. priv->config |= CFG_ADHOC_PERSIST;
  4608. ipw_create_bssid(priv, network->bssid);
  4609. network->ssid_len = priv->essid_len;
  4610. memcpy(network->ssid, priv->essid, priv->essid_len);
  4611. memset(&network->stats, 0, sizeof(network->stats));
  4612. network->capability = WLAN_CAPABILITY_IBSS;
  4613. if (!(priv->config & CFG_PREAMBLE_LONG))
  4614. network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  4615. if (priv->capability & CAP_PRIVACY_ON)
  4616. network->capability |= WLAN_CAPABILITY_PRIVACY;
  4617. network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
  4618. memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
  4619. network->rates_ex_len = priv->rates.num_rates - network->rates_len;
  4620. memcpy(network->rates_ex,
  4621. &priv->rates.supported_rates[network->rates_len],
  4622. network->rates_ex_len);
  4623. network->last_scanned = 0;
  4624. network->flags = 0;
  4625. network->last_associate = 0;
  4626. network->time_stamp[0] = 0;
  4627. network->time_stamp[1] = 0;
  4628. network->beacon_interval = 100; /* Default */
  4629. network->listen_interval = 10; /* Default */
  4630. network->atim_window = 0; /* Default */
  4631. network->wpa_ie_len = 0;
  4632. network->rsn_ie_len = 0;
  4633. }
  4634. static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
  4635. {
  4636. struct ipw_tgi_tx_key *key;
  4637. struct host_cmd cmd = {
  4638. .cmd = IPW_CMD_TGI_TX_KEY,
  4639. .len = sizeof(*key)
  4640. };
  4641. if (!(priv->ieee->sec.flags & (1 << index)))
  4642. return;
  4643. key = (struct ipw_tgi_tx_key *)&cmd.param;
  4644. key->key_id = index;
  4645. memcpy(key->key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
  4646. key->security_type = type;
  4647. key->station_index = 0; /* always 0 for BSS */
  4648. key->flags = 0;
  4649. /* 0 for new key; previous value of counter (after fatal error) */
  4650. key->tx_counter[0] = 0;
  4651. key->tx_counter[1] = 0;
  4652. if (ipw_send_cmd(priv, &cmd)) {
  4653. IPW_ERROR("failed to send TGI_TX_KEY command\n");
  4654. return;
  4655. }
  4656. }
  4657. static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
  4658. {
  4659. struct ipw_wep_key *key;
  4660. int i;
  4661. struct host_cmd cmd = {
  4662. .cmd = IPW_CMD_WEP_KEY,
  4663. .len = sizeof(*key)
  4664. };
  4665. key = (struct ipw_wep_key *)&cmd.param;
  4666. key->cmd_id = DINO_CMD_WEP_KEY;
  4667. key->seq_num = 0;
  4668. /* Note: AES keys cannot be set for multiple times.
  4669. * Only set it at the first time. */
  4670. for (i = 0; i < 4; i++) {
  4671. key->key_index = i | type;
  4672. if (!(priv->ieee->sec.flags & (1 << i))) {
  4673. key->key_size = 0;
  4674. continue;
  4675. }
  4676. key->key_size = priv->ieee->sec.key_sizes[i];
  4677. memcpy(key->key, priv->ieee->sec.keys[i], key->key_size);
  4678. if (ipw_send_cmd(priv, &cmd)) {
  4679. IPW_ERROR("failed to send WEP_KEY command\n");
  4680. return;
  4681. }
  4682. }
  4683. }
  4684. static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
  4685. {
  4686. if (priv->ieee->host_encrypt)
  4687. return;
  4688. switch (level) {
  4689. case SEC_LEVEL_3:
  4690. priv->sys_config.disable_unicast_decryption = 0;
  4691. priv->ieee->host_decrypt = 0;
  4692. break;
  4693. case SEC_LEVEL_2:
  4694. priv->sys_config.disable_unicast_decryption = 1;
  4695. priv->ieee->host_decrypt = 1;
  4696. break;
  4697. case SEC_LEVEL_1:
  4698. priv->sys_config.disable_unicast_decryption = 0;
  4699. priv->ieee->host_decrypt = 0;
  4700. break;
  4701. case SEC_LEVEL_0:
  4702. priv->sys_config.disable_unicast_decryption = 1;
  4703. break;
  4704. default:
  4705. break;
  4706. }
  4707. }
  4708. static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
  4709. {
  4710. if (priv->ieee->host_encrypt)
  4711. return;
  4712. switch (level) {
  4713. case SEC_LEVEL_3:
  4714. priv->sys_config.disable_multicast_decryption = 0;
  4715. break;
  4716. case SEC_LEVEL_2:
  4717. priv->sys_config.disable_multicast_decryption = 1;
  4718. break;
  4719. case SEC_LEVEL_1:
  4720. priv->sys_config.disable_multicast_decryption = 0;
  4721. break;
  4722. case SEC_LEVEL_0:
  4723. priv->sys_config.disable_multicast_decryption = 1;
  4724. break;
  4725. default:
  4726. break;
  4727. }
  4728. }
  4729. static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
  4730. {
  4731. switch (priv->ieee->sec.level) {
  4732. case SEC_LEVEL_3:
  4733. if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
  4734. ipw_send_tgi_tx_key(priv,
  4735. DCT_FLAG_EXT_SECURITY_CCM,
  4736. priv->ieee->sec.active_key);
  4737. ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
  4738. break;
  4739. case SEC_LEVEL_2:
  4740. if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
  4741. ipw_send_tgi_tx_key(priv,
  4742. DCT_FLAG_EXT_SECURITY_TKIP,
  4743. priv->ieee->sec.active_key);
  4744. break;
  4745. case SEC_LEVEL_1:
  4746. ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
  4747. break;
  4748. case SEC_LEVEL_0:
  4749. default:
  4750. break;
  4751. }
  4752. ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
  4753. ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
  4754. }
  4755. static void ipw_adhoc_check(void *data)
  4756. {
  4757. struct ipw_priv *priv = data;
  4758. if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
  4759. !(priv->config & CFG_ADHOC_PERSIST)) {
  4760. IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
  4761. IPW_DL_STATE | IPW_DL_ASSOC,
  4762. "Missed beacon: %d - disassociate\n",
  4763. priv->missed_adhoc_beacons);
  4764. ipw_remove_current_network(priv);
  4765. ipw_disassociate(priv);
  4766. return;
  4767. }
  4768. queue_delayed_work(priv->workqueue, &priv->adhoc_check,
  4769. priv->assoc_request.beacon_interval);
  4770. }
  4771. static void ipw_bg_adhoc_check(void *data)
  4772. {
  4773. struct ipw_priv *priv = data;
  4774. down(&priv->sem);
  4775. ipw_adhoc_check(data);
  4776. up(&priv->sem);
  4777. }
  4778. #ifdef CONFIG_IPW_DEBUG
  4779. static void ipw_debug_config(struct ipw_priv *priv)
  4780. {
  4781. IPW_DEBUG_INFO("Scan completed, no valid APs matched "
  4782. "[CFG 0x%08X]\n", priv->config);
  4783. if (priv->config & CFG_STATIC_CHANNEL)
  4784. IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
  4785. else
  4786. IPW_DEBUG_INFO("Channel unlocked.\n");
  4787. if (priv->config & CFG_STATIC_ESSID)
  4788. IPW_DEBUG_INFO("ESSID locked to '%s'\n",
  4789. escape_essid(priv->essid, priv->essid_len));
  4790. else
  4791. IPW_DEBUG_INFO("ESSID unlocked.\n");
  4792. if (priv->config & CFG_STATIC_BSSID)
  4793. IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
  4794. MAC_ARG(priv->bssid));
  4795. else
  4796. IPW_DEBUG_INFO("BSSID unlocked.\n");
  4797. if (priv->capability & CAP_PRIVACY_ON)
  4798. IPW_DEBUG_INFO("PRIVACY on\n");
  4799. else
  4800. IPW_DEBUG_INFO("PRIVACY off\n");
  4801. IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
  4802. }
  4803. #else
  4804. #define ipw_debug_config(x) do {} while (0)
  4805. #endif
  4806. static inline void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
  4807. {
  4808. /* TODO: Verify that this works... */
  4809. struct ipw_fixed_rate fr = {
  4810. .tx_rates = priv->rates_mask
  4811. };
  4812. u32 reg;
  4813. u16 mask = 0;
  4814. /* Identify 'current FW band' and match it with the fixed
  4815. * Tx rates */
  4816. switch (priv->ieee->freq_band) {
  4817. case IEEE80211_52GHZ_BAND: /* A only */
  4818. /* IEEE_A */
  4819. if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
  4820. /* Invalid fixed rate mask */
  4821. IPW_DEBUG_WX
  4822. ("invalid fixed rate mask in ipw_set_fixed_rate\n");
  4823. fr.tx_rates = 0;
  4824. break;
  4825. }
  4826. fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
  4827. break;
  4828. default: /* 2.4Ghz or Mixed */
  4829. /* IEEE_B */
  4830. if (mode == IEEE_B) {
  4831. if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
  4832. /* Invalid fixed rate mask */
  4833. IPW_DEBUG_WX
  4834. ("invalid fixed rate mask in ipw_set_fixed_rate\n");
  4835. fr.tx_rates = 0;
  4836. }
  4837. break;
  4838. }
  4839. /* IEEE_G */
  4840. if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
  4841. IEEE80211_OFDM_RATES_MASK)) {
  4842. /* Invalid fixed rate mask */
  4843. IPW_DEBUG_WX
  4844. ("invalid fixed rate mask in ipw_set_fixed_rate\n");
  4845. fr.tx_rates = 0;
  4846. break;
  4847. }
  4848. if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
  4849. mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
  4850. fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
  4851. }
  4852. if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
  4853. mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
  4854. fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
  4855. }
  4856. if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
  4857. mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
  4858. fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
  4859. }
  4860. fr.tx_rates |= mask;
  4861. break;
  4862. }
  4863. reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
  4864. ipw_write_reg32(priv, reg, *(u32 *) & fr);
  4865. }
  4866. static void ipw_abort_scan(struct ipw_priv *priv)
  4867. {
  4868. int err;
  4869. if (priv->status & STATUS_SCAN_ABORTING) {
  4870. IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
  4871. return;
  4872. }
  4873. priv->status |= STATUS_SCAN_ABORTING;
  4874. err = ipw_send_scan_abort(priv);
  4875. if (err)
  4876. IPW_DEBUG_HC("Request to abort scan failed.\n");
  4877. }
  4878. static void ipw_add_scan_channels(struct ipw_priv *priv,
  4879. struct ipw_scan_request_ext *scan,
  4880. int scan_type)
  4881. {
  4882. int channel_index = 0;
  4883. const struct ieee80211_geo *geo;
  4884. int i;
  4885. geo = ieee80211_get_geo(priv->ieee);
  4886. if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
  4887. int start = channel_index;
  4888. for (i = 0; i < geo->a_channels; i++) {
  4889. if ((priv->status & STATUS_ASSOCIATED) &&
  4890. geo->a[i].channel == priv->channel)
  4891. continue;
  4892. channel_index++;
  4893. scan->channels_list[channel_index] = geo->a[i].channel;
  4894. ipw_set_scan_type(scan, channel_index, scan_type);
  4895. }
  4896. if (start != channel_index) {
  4897. scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
  4898. (channel_index - start);
  4899. channel_index++;
  4900. }
  4901. }
  4902. if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
  4903. int start = channel_index;
  4904. if (priv->config & CFG_SPEED_SCAN) {
  4905. u8 channels[IEEE80211_24GHZ_CHANNELS] = {
  4906. /* nop out the list */
  4907. [0] = 0
  4908. };
  4909. u8 channel;
  4910. while (channel_index < IPW_SCAN_CHANNELS) {
  4911. channel =
  4912. priv->speed_scan[priv->speed_scan_pos];
  4913. if (channel == 0) {
  4914. priv->speed_scan_pos = 0;
  4915. channel = priv->speed_scan[0];
  4916. }
  4917. if ((priv->status & STATUS_ASSOCIATED) &&
  4918. channel == priv->channel) {
  4919. priv->speed_scan_pos++;
  4920. continue;
  4921. }
  4922. /* If this channel has already been
  4923. * added in scan, break from loop
  4924. * and this will be the first channel
  4925. * in the next scan.
  4926. */
  4927. if (channels[channel - 1] != 0)
  4928. break;
  4929. channels[channel - 1] = 1;
  4930. priv->speed_scan_pos++;
  4931. channel_index++;
  4932. scan->channels_list[channel_index] = channel;
  4933. ipw_set_scan_type(scan, channel_index,
  4934. scan_type);
  4935. }
  4936. } else {
  4937. for (i = 0; i < geo->bg_channels; i++) {
  4938. if ((priv->status & STATUS_ASSOCIATED) &&
  4939. geo->bg[i].channel == priv->channel)
  4940. continue;
  4941. channel_index++;
  4942. scan->channels_list[channel_index] =
  4943. geo->bg[i].channel;
  4944. ipw_set_scan_type(scan, channel_index,
  4945. scan_type);
  4946. }
  4947. }
  4948. if (start != channel_index) {
  4949. scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
  4950. (channel_index - start);
  4951. }
  4952. }
  4953. }
  4954. static int ipw_request_scan(struct ipw_priv *priv)
  4955. {
  4956. struct ipw_scan_request_ext scan;
  4957. int err = 0, scan_type;
  4958. if (!(priv->status & STATUS_INIT) ||
  4959. (priv->status & STATUS_EXIT_PENDING))
  4960. return 0;
  4961. down(&priv->sem);
  4962. if (priv->status & STATUS_SCANNING) {
  4963. IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
  4964. priv->status |= STATUS_SCAN_PENDING;
  4965. goto done;
  4966. }
  4967. if (!(priv->status & STATUS_SCAN_FORCED) &&
  4968. priv->status & STATUS_SCAN_ABORTING) {
  4969. IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
  4970. priv->status |= STATUS_SCAN_PENDING;
  4971. goto done;
  4972. }
  4973. if (priv->status & STATUS_RF_KILL_MASK) {
  4974. IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
  4975. priv->status |= STATUS_SCAN_PENDING;
  4976. goto done;
  4977. }
  4978. memset(&scan, 0, sizeof(scan));
  4979. if (priv->config & CFG_SPEED_SCAN)
  4980. scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
  4981. cpu_to_le16(30);
  4982. else
  4983. scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
  4984. cpu_to_le16(20);
  4985. scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
  4986. cpu_to_le16(20);
  4987. scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(20);
  4988. scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
  4989. #ifdef CONFIG_IPW2200_MONITOR
  4990. if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
  4991. u8 channel;
  4992. u8 band = 0;
  4993. switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
  4994. case IEEE80211_52GHZ_BAND:
  4995. band = (u8) (IPW_A_MODE << 6) | 1;
  4996. channel = priv->channel;
  4997. break;
  4998. case IEEE80211_24GHZ_BAND:
  4999. band = (u8) (IPW_B_MODE << 6) | 1;
  5000. channel = priv->channel;
  5001. break;
  5002. default:
  5003. band = (u8) (IPW_B_MODE << 6) | 1;
  5004. channel = 9;
  5005. break;
  5006. }
  5007. scan.channels_list[0] = band;
  5008. scan.channels_list[1] = channel;
  5009. ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
  5010. /* NOTE: The card will sit on this channel for this time
  5011. * period. Scan aborts are timing sensitive and frequently
  5012. * result in firmware restarts. As such, it is best to
  5013. * set a small dwell_time here and just keep re-issuing
  5014. * scans. Otherwise fast channel hopping will not actually
  5015. * hop channels.
  5016. *
  5017. * TODO: Move SPEED SCAN support to all modes and bands */
  5018. scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
  5019. cpu_to_le16(2000);
  5020. } else {
  5021. #endif /* CONFIG_IPW2200_MONITOR */
  5022. /* If we are roaming, then make this a directed scan for the
  5023. * current network. Otherwise, ensure that every other scan
  5024. * is a fast channel hop scan */
  5025. if ((priv->status & STATUS_ROAMING)
  5026. || (!(priv->status & STATUS_ASSOCIATED)
  5027. && (priv->config & CFG_STATIC_ESSID)
  5028. && (le32_to_cpu(scan.full_scan_index) % 2))) {
  5029. err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
  5030. if (err) {
  5031. IPW_DEBUG_HC("Attempt to send SSID command "
  5032. "failed.\n");
  5033. goto done;
  5034. }
  5035. scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
  5036. } else
  5037. scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
  5038. ipw_add_scan_channels(priv, &scan, scan_type);
  5039. #ifdef CONFIG_IPW2200_MONITOR
  5040. }
  5041. #endif
  5042. err = ipw_send_scan_request_ext(priv, &scan);
  5043. if (err) {
  5044. IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
  5045. goto done;
  5046. }
  5047. priv->status |= STATUS_SCANNING;
  5048. priv->status &= ~STATUS_SCAN_PENDING;
  5049. queue_delayed_work(priv->workqueue, &priv->scan_check,
  5050. IPW_SCAN_CHECK_WATCHDOG);
  5051. done:
  5052. up(&priv->sem);
  5053. return err;
  5054. }
  5055. static void ipw_bg_abort_scan(void *data)
  5056. {
  5057. struct ipw_priv *priv = data;
  5058. down(&priv->sem);
  5059. ipw_abort_scan(data);
  5060. up(&priv->sem);
  5061. }
  5062. #if WIRELESS_EXT < 18
  5063. /* Support for wpa_supplicant before WE-18, deprecated. */
  5064. /* following definitions must match definitions in driver_ipw.c */
  5065. #define IPW_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30
  5066. #define IPW_CMD_SET_WPA_PARAM 1
  5067. #define IPW_CMD_SET_WPA_IE 2
  5068. #define IPW_CMD_SET_ENCRYPTION 3
  5069. #define IPW_CMD_MLME 4
  5070. #define IPW_PARAM_WPA_ENABLED 1
  5071. #define IPW_PARAM_TKIP_COUNTERMEASURES 2
  5072. #define IPW_PARAM_DROP_UNENCRYPTED 3
  5073. #define IPW_PARAM_PRIVACY_INVOKED 4
  5074. #define IPW_PARAM_AUTH_ALGS 5
  5075. #define IPW_PARAM_IEEE_802_1X 6
  5076. #define IPW_MLME_STA_DEAUTH 1
  5077. #define IPW_MLME_STA_DISASSOC 2
  5078. #define IPW_CRYPT_ERR_UNKNOWN_ALG 2
  5079. #define IPW_CRYPT_ERR_UNKNOWN_ADDR 3
  5080. #define IPW_CRYPT_ERR_CRYPT_INIT_FAILED 4
  5081. #define IPW_CRYPT_ERR_KEY_SET_FAILED 5
  5082. #define IPW_CRYPT_ERR_TX_KEY_SET_FAILED 6
  5083. #define IPW_CRYPT_ERR_CARD_CONF_FAILED 7
  5084. #define IPW_CRYPT_ALG_NAME_LEN 16
  5085. struct ipw_param {
  5086. u32 cmd;
  5087. u8 sta_addr[ETH_ALEN];
  5088. union {
  5089. struct {
  5090. u8 name;
  5091. u32 value;
  5092. } wpa_param;
  5093. struct {
  5094. u32 len;
  5095. u8 reserved[32];
  5096. u8 data[0];
  5097. } wpa_ie;
  5098. struct {
  5099. u32 command;
  5100. u32 reason_code;
  5101. } mlme;
  5102. struct {
  5103. u8 alg[IPW_CRYPT_ALG_NAME_LEN];
  5104. u8 set_tx;
  5105. u32 err;
  5106. u8 idx;
  5107. u8 seq[8]; /* sequence counter (set: RX, get: TX) */
  5108. u16 key_len;
  5109. u8 key[0];
  5110. } crypt;
  5111. } u;
  5112. };
  5113. /* end of driver_ipw.c code */
  5114. #endif
  5115. static int ipw_wpa_enable(struct ipw_priv *priv, int value)
  5116. {
  5117. /* This is called when wpa_supplicant loads and closes the driver
  5118. * interface. */
  5119. return 0;
  5120. }
  5121. #if WIRELESS_EXT < 18
  5122. #define IW_AUTH_ALG_OPEN_SYSTEM 0x1
  5123. #define IW_AUTH_ALG_SHARED_KEY 0x2
  5124. #endif
  5125. static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
  5126. {
  5127. struct ieee80211_device *ieee = priv->ieee;
  5128. struct ieee80211_security sec = {
  5129. .flags = SEC_AUTH_MODE,
  5130. };
  5131. int ret = 0;
  5132. if (value & IW_AUTH_ALG_SHARED_KEY) {
  5133. sec.auth_mode = WLAN_AUTH_SHARED_KEY;
  5134. ieee->open_wep = 0;
  5135. } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
  5136. sec.auth_mode = WLAN_AUTH_OPEN;
  5137. ieee->open_wep = 1;
  5138. } else
  5139. return -EINVAL;
  5140. if (ieee->set_security)
  5141. ieee->set_security(ieee->dev, &sec);
  5142. else
  5143. ret = -EOPNOTSUPP;
  5144. return ret;
  5145. }
  5146. void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, int wpa_ie_len)
  5147. {
  5148. /* make sure WPA is enabled */
  5149. ipw_wpa_enable(priv, 1);
  5150. ipw_disassociate(priv);
  5151. }
  5152. static int ipw_set_rsn_capa(struct ipw_priv *priv,
  5153. char *capabilities, int length)
  5154. {
  5155. struct host_cmd cmd = {
  5156. .cmd = IPW_CMD_RSN_CAPABILITIES,
  5157. .len = length,
  5158. };
  5159. IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
  5160. memcpy(cmd.param, capabilities, length);
  5161. if (ipw_send_cmd(priv, &cmd)) {
  5162. IPW_ERROR("failed to send HOST_CMD_RSN_CAPABILITIES command\n");
  5163. return -1;
  5164. }
  5165. return 0;
  5166. }
  5167. #if WIRELESS_EXT < 18
  5168. static int ipw_wpa_set_param(struct net_device *dev, u8 name, u32 value)
  5169. {
  5170. struct ipw_priv *priv = ieee80211_priv(dev);
  5171. struct ieee80211_crypt_data *crypt;
  5172. unsigned long flags;
  5173. int ret = 0;
  5174. switch (name) {
  5175. case IPW_PARAM_WPA_ENABLED:
  5176. ret = ipw_wpa_enable(priv, value);
  5177. break;
  5178. case IPW_PARAM_TKIP_COUNTERMEASURES:
  5179. crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
  5180. if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) {
  5181. IPW_WARNING("Can't set TKIP countermeasures: "
  5182. "crypt not set!\n");
  5183. break;
  5184. }
  5185. flags = crypt->ops->get_flags(crypt->priv);
  5186. if (value)
  5187. flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
  5188. else
  5189. flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
  5190. crypt->ops->set_flags(flags, crypt->priv);
  5191. break;
  5192. case IPW_PARAM_DROP_UNENCRYPTED:{
  5193. /* HACK:
  5194. *
  5195. * wpa_supplicant calls set_wpa_enabled when the driver
  5196. * is loaded and unloaded, regardless of if WPA is being
  5197. * used. No other calls are made which can be used to
  5198. * determine if encryption will be used or not prior to
  5199. * association being expected. If encryption is not being
  5200. * used, drop_unencrypted is set to false, else true -- we
  5201. * can use this to determine if the CAP_PRIVACY_ON bit should
  5202. * be set.
  5203. */
  5204. struct ieee80211_security sec = {
  5205. .flags = SEC_ENABLED,
  5206. .enabled = value,
  5207. };
  5208. priv->ieee->drop_unencrypted = value;
  5209. /* We only change SEC_LEVEL for open mode. Others
  5210. * are set by ipw_wpa_set_encryption.
  5211. */
  5212. if (!value) {
  5213. sec.flags |= SEC_LEVEL;
  5214. sec.level = SEC_LEVEL_0;
  5215. } else {
  5216. sec.flags |= SEC_LEVEL;
  5217. sec.level = SEC_LEVEL_1;
  5218. }
  5219. if (priv->ieee->set_security)
  5220. priv->ieee->set_security(priv->ieee->dev, &sec);
  5221. break;
  5222. }
  5223. case IPW_PARAM_PRIVACY_INVOKED:
  5224. priv->ieee->privacy_invoked = value;
  5225. break;
  5226. case IPW_PARAM_AUTH_ALGS:
  5227. ret = ipw_wpa_set_auth_algs(priv, value);
  5228. break;
  5229. case IPW_PARAM_IEEE_802_1X:
  5230. priv->ieee->ieee802_1x = value;
  5231. break;
  5232. default:
  5233. IPW_ERROR("%s: Unknown WPA param: %d\n", dev->name, name);
  5234. ret = -EOPNOTSUPP;
  5235. }
  5236. return ret;
  5237. }
  5238. static int ipw_wpa_mlme(struct net_device *dev, int command, int reason)
  5239. {
  5240. struct ipw_priv *priv = ieee80211_priv(dev);
  5241. int ret = 0;
  5242. switch (command) {
  5243. case IPW_MLME_STA_DEAUTH:
  5244. // silently ignore
  5245. break;
  5246. case IPW_MLME_STA_DISASSOC:
  5247. ipw_disassociate(priv);
  5248. break;
  5249. default:
  5250. IPW_ERROR("%s: Unknown MLME request: %d\n", dev->name, command);
  5251. ret = -EOPNOTSUPP;
  5252. }
  5253. return ret;
  5254. }
  5255. static int ipw_wpa_ie_cipher2level(u8 cipher)
  5256. {
  5257. switch (cipher) {
  5258. case 4: /* CCMP */
  5259. return SEC_LEVEL_3;
  5260. case 2: /* TKIP */
  5261. return SEC_LEVEL_2;
  5262. case 5: /* WEP104 */
  5263. case 1: /* WEP40 */
  5264. return SEC_LEVEL_1;
  5265. case 0: /* NONE */
  5266. return SEC_LEVEL_0;
  5267. default:
  5268. return -1;
  5269. }
  5270. }
  5271. static int ipw_wpa_set_wpa_ie(struct net_device *dev,
  5272. struct ipw_param *param, int plen)
  5273. {
  5274. struct ipw_priv *priv = ieee80211_priv(dev);
  5275. struct ieee80211_device *ieee = priv->ieee;
  5276. u8 *buf;
  5277. u8 *ptk, *gtk;
  5278. int level;
  5279. if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
  5280. (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL))
  5281. return -EINVAL;
  5282. if (param->u.wpa_ie.len) {
  5283. buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
  5284. if (buf == NULL)
  5285. return -ENOMEM;
  5286. memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
  5287. kfree(ieee->wpa_ie);
  5288. ieee->wpa_ie = buf;
  5289. ieee->wpa_ie_len = param->u.wpa_ie.len;
  5290. } else {
  5291. kfree(ieee->wpa_ie);
  5292. ieee->wpa_ie = NULL;
  5293. ieee->wpa_ie_len = 0;
  5294. goto done;
  5295. }
  5296. if (priv->ieee->host_encrypt)
  5297. goto done;
  5298. /* HACK: Parse wpa_ie here to get pairwise suite, otherwise
  5299. * we need to change driver_ipw.c from wpa_supplicant. This
  5300. * is OK since -Dipw is deprecated. The -Dwext driver has a
  5301. * clean way to handle this. */
  5302. gtk = ptk = (u8 *) ieee->wpa_ie;
  5303. if (ieee->wpa_ie[0] == 0x30) { /* RSN IE */
  5304. gtk += 4 + 3;
  5305. ptk += 4 + 4 + 2 + 3;
  5306. } else { /* WPA IE */
  5307. gtk += 8 + 3;
  5308. ptk += 8 + 4 + 2 + 3;
  5309. }
  5310. if (ptk - (u8 *) ieee->wpa_ie > ieee->wpa_ie_len)
  5311. return -EINVAL;
  5312. level = ipw_wpa_ie_cipher2level(*gtk);
  5313. ipw_set_hw_decrypt_multicast(priv, level);
  5314. level = ipw_wpa_ie_cipher2level(*ptk);
  5315. ipw_set_hw_decrypt_unicast(priv, level);
  5316. done:
  5317. ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
  5318. return 0;
  5319. }
  5320. /* implementation borrowed from hostap driver */
  5321. static int ipw_wpa_set_encryption(struct net_device *dev,
  5322. struct ipw_param *param, int param_len)
  5323. {
  5324. int ret = 0;
  5325. struct ipw_priv *priv = ieee80211_priv(dev);
  5326. struct ieee80211_device *ieee = priv->ieee;
  5327. struct ieee80211_crypto_ops *ops;
  5328. struct ieee80211_crypt_data **crypt;
  5329. struct ieee80211_security sec = {
  5330. .flags = 0,
  5331. };
  5332. param->u.crypt.err = 0;
  5333. param->u.crypt.alg[IPW_CRYPT_ALG_NAME_LEN - 1] = '\0';
  5334. if (param_len !=
  5335. (int)((char *)param->u.crypt.key - (char *)param) +
  5336. param->u.crypt.key_len) {
  5337. IPW_DEBUG_INFO("Len mismatch %d, %d\n", param_len,
  5338. param->u.crypt.key_len);
  5339. return -EINVAL;
  5340. }
  5341. if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
  5342. param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
  5343. param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
  5344. if (param->u.crypt.idx >= WEP_KEYS)
  5345. return -EINVAL;
  5346. crypt = &ieee->crypt[param->u.crypt.idx];
  5347. } else {
  5348. return -EINVAL;
  5349. }
  5350. sec.flags |= SEC_ENABLED | SEC_ENCRYPT;
  5351. if (strcmp(param->u.crypt.alg, "none") == 0) {
  5352. if (crypt) {
  5353. sec.enabled = 0;
  5354. sec.encrypt = 0;
  5355. sec.level = SEC_LEVEL_0;
  5356. sec.flags |= SEC_LEVEL;
  5357. ieee80211_crypt_delayed_deinit(ieee, crypt);
  5358. }
  5359. goto done;
  5360. }
  5361. sec.enabled = 1;
  5362. sec.encrypt = 1;
  5363. /* IPW HW cannot build TKIP MIC, host decryption still needed. */
  5364. if (strcmp(param->u.crypt.alg, "TKIP") == 0)
  5365. ieee->host_encrypt_msdu = 1;
  5366. if (!(ieee->host_encrypt || ieee->host_encrypt_msdu ||
  5367. ieee->host_decrypt))
  5368. goto skip_host_crypt;
  5369. ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
  5370. if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
  5371. request_module("ieee80211_crypt_wep");
  5372. ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
  5373. } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
  5374. request_module("ieee80211_crypt_tkip");
  5375. ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
  5376. } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
  5377. request_module("ieee80211_crypt_ccmp");
  5378. ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
  5379. }
  5380. if (ops == NULL) {
  5381. IPW_DEBUG_INFO("%s: unknown crypto alg '%s'\n",
  5382. dev->name, param->u.crypt.alg);
  5383. param->u.crypt.err = IPW_CRYPT_ERR_UNKNOWN_ALG;
  5384. ret = -EINVAL;
  5385. goto done;
  5386. }
  5387. if (*crypt == NULL || (*crypt)->ops != ops) {
  5388. struct ieee80211_crypt_data *new_crypt;
  5389. ieee80211_crypt_delayed_deinit(ieee, crypt);
  5390. new_crypt = (struct ieee80211_crypt_data *)
  5391. kmalloc(sizeof(*new_crypt), GFP_KERNEL);
  5392. if (new_crypt == NULL) {
  5393. ret = -ENOMEM;
  5394. goto done;
  5395. }
  5396. memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
  5397. new_crypt->ops = ops;
  5398. if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
  5399. new_crypt->priv =
  5400. new_crypt->ops->init(param->u.crypt.idx);
  5401. if (new_crypt->priv == NULL) {
  5402. kfree(new_crypt);
  5403. param->u.crypt.err = IPW_CRYPT_ERR_CRYPT_INIT_FAILED;
  5404. ret = -EINVAL;
  5405. goto done;
  5406. }
  5407. *crypt = new_crypt;
  5408. }
  5409. if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
  5410. (*crypt)->ops->set_key(param->u.crypt.key,
  5411. param->u.crypt.key_len, param->u.crypt.seq,
  5412. (*crypt)->priv) < 0) {
  5413. IPW_DEBUG_INFO("%s: key setting failed\n", dev->name);
  5414. param->u.crypt.err = IPW_CRYPT_ERR_KEY_SET_FAILED;
  5415. ret = -EINVAL;
  5416. goto done;
  5417. }
  5418. skip_host_crypt:
  5419. if (param->u.crypt.set_tx) {
  5420. ieee->tx_keyidx = param->u.crypt.idx;
  5421. sec.active_key = param->u.crypt.idx;
  5422. sec.flags |= SEC_ACTIVE_KEY;
  5423. } else
  5424. sec.flags &= ~SEC_ACTIVE_KEY;
  5425. if (param->u.crypt.alg != NULL) {
  5426. memcpy(sec.keys[param->u.crypt.idx],
  5427. param->u.crypt.key, param->u.crypt.key_len);
  5428. sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
  5429. sec.flags |= (1 << param->u.crypt.idx);
  5430. if (strcmp(param->u.crypt.alg, "WEP") == 0) {
  5431. sec.flags |= SEC_LEVEL;
  5432. sec.level = SEC_LEVEL_1;
  5433. } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
  5434. sec.flags |= SEC_LEVEL;
  5435. sec.level = SEC_LEVEL_2;
  5436. } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
  5437. sec.flags |= SEC_LEVEL;
  5438. sec.level = SEC_LEVEL_3;
  5439. }
  5440. }
  5441. done:
  5442. if (ieee->set_security)
  5443. ieee->set_security(ieee->dev, &sec);
  5444. /* Do not reset port if card is in Managed mode since resetting will
  5445. * generate new IEEE 802.11 authentication which may end up in looping
  5446. * with IEEE 802.1X. If your hardware requires a reset after WEP
  5447. * configuration (for example... Prism2), implement the reset_port in
  5448. * the callbacks structures used to initialize the 802.11 stack. */
  5449. if (ieee->reset_on_keychange &&
  5450. ieee->iw_mode != IW_MODE_INFRA &&
  5451. ieee->reset_port && ieee->reset_port(dev)) {
  5452. IPW_DEBUG_INFO("%s: reset_port failed\n", dev->name);
  5453. param->u.crypt.err = IPW_CRYPT_ERR_CARD_CONF_FAILED;
  5454. return -EINVAL;
  5455. }
  5456. return ret;
  5457. }
  5458. static int ipw_wpa_supplicant(struct net_device *dev, struct iw_point *p)
  5459. {
  5460. struct ipw_param *param;
  5461. struct ipw_priv *priv = ieee80211_priv(dev);
  5462. int ret = 0;
  5463. IPW_DEBUG_INFO("wpa_supplicant: len=%d\n", p->length);
  5464. if (p->length < sizeof(struct ipw_param) || !p->pointer)
  5465. return -EINVAL;
  5466. param = (struct ipw_param *)kmalloc(p->length, GFP_KERNEL);
  5467. if (param == NULL)
  5468. return -ENOMEM;
  5469. if (copy_from_user(param, p->pointer, p->length)) {
  5470. kfree(param);
  5471. return -EFAULT;
  5472. }
  5473. down(&priv->sem);
  5474. switch (param->cmd) {
  5475. case IPW_CMD_SET_WPA_PARAM:
  5476. ret = ipw_wpa_set_param(dev, param->u.wpa_param.name,
  5477. param->u.wpa_param.value);
  5478. break;
  5479. case IPW_CMD_SET_WPA_IE:
  5480. ret = ipw_wpa_set_wpa_ie(dev, param, p->length);
  5481. break;
  5482. case IPW_CMD_SET_ENCRYPTION:
  5483. ret = ipw_wpa_set_encryption(dev, param, p->length);
  5484. break;
  5485. case IPW_CMD_MLME:
  5486. ret = ipw_wpa_mlme(dev, param->u.mlme.command,
  5487. param->u.mlme.reason_code);
  5488. break;
  5489. default:
  5490. IPW_ERROR("%s: Unknown WPA supplicant request: %d\n",
  5491. dev->name, param->cmd);
  5492. ret = -EOPNOTSUPP;
  5493. }
  5494. up(&priv->sem);
  5495. if (ret == 0 && copy_to_user(p->pointer, param, p->length))
  5496. ret = -EFAULT;
  5497. kfree(param);
  5498. return ret;
  5499. }
  5500. #else
  5501. /*
  5502. * WE-18 support
  5503. */
  5504. /* SIOCSIWGENIE */
  5505. static int ipw_wx_set_genie(struct net_device *dev,
  5506. struct iw_request_info *info,
  5507. union iwreq_data *wrqu, char *extra)
  5508. {
  5509. struct ipw_priv *priv = ieee80211_priv(dev);
  5510. struct ieee80211_device *ieee = priv->ieee;
  5511. u8 *buf;
  5512. int err = 0;
  5513. if (wrqu->data.length > MAX_WPA_IE_LEN ||
  5514. (wrqu->data.length && extra == NULL))
  5515. return -EINVAL;
  5516. //down(&priv->sem);
  5517. //if (!ieee->wpa_enabled) {
  5518. // err = -EOPNOTSUPP;
  5519. // goto out;
  5520. //}
  5521. if (wrqu->data.length) {
  5522. buf = kmalloc(wrqu->data.length, GFP_KERNEL);
  5523. if (buf == NULL) {
  5524. err = -ENOMEM;
  5525. goto out;
  5526. }
  5527. memcpy(buf, extra, wrqu->data.length);
  5528. kfree(ieee->wpa_ie);
  5529. ieee->wpa_ie = buf;
  5530. ieee->wpa_ie_len = wrqu->data.length;
  5531. } else {
  5532. kfree(ieee->wpa_ie);
  5533. ieee->wpa_ie = NULL;
  5534. ieee->wpa_ie_len = 0;
  5535. }
  5536. ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
  5537. out:
  5538. //up(&priv->sem);
  5539. return err;
  5540. }
  5541. /* SIOCGIWGENIE */
  5542. static int ipw_wx_get_genie(struct net_device *dev,
  5543. struct iw_request_info *info,
  5544. union iwreq_data *wrqu, char *extra)
  5545. {
  5546. struct ipw_priv *priv = ieee80211_priv(dev);
  5547. struct ieee80211_device *ieee = priv->ieee;
  5548. int err = 0;
  5549. //down(&priv->sem);
  5550. //if (!ieee->wpa_enabled) {
  5551. // err = -EOPNOTSUPP;
  5552. // goto out;
  5553. //}
  5554. if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
  5555. wrqu->data.length = 0;
  5556. goto out;
  5557. }
  5558. if (wrqu->data.length < ieee->wpa_ie_len) {
  5559. err = -E2BIG;
  5560. goto out;
  5561. }
  5562. wrqu->data.length = ieee->wpa_ie_len;
  5563. memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
  5564. out:
  5565. //up(&priv->sem);
  5566. return err;
  5567. }
  5568. static int wext_cipher2level(int cipher)
  5569. {
  5570. switch (cipher) {
  5571. case IW_AUTH_CIPHER_NONE:
  5572. return SEC_LEVEL_0;
  5573. case IW_AUTH_CIPHER_WEP40:
  5574. case IW_AUTH_CIPHER_WEP104:
  5575. return SEC_LEVEL_1;
  5576. case IW_AUTH_CIPHER_TKIP:
  5577. return SEC_LEVEL_2;
  5578. case IW_AUTH_CIPHER_CCMP:
  5579. return SEC_LEVEL_3;
  5580. default:
  5581. return -1;
  5582. }
  5583. }
  5584. /* SIOCSIWAUTH */
  5585. static int ipw_wx_set_auth(struct net_device *dev,
  5586. struct iw_request_info *info,
  5587. union iwreq_data *wrqu, char *extra)
  5588. {
  5589. struct ipw_priv *priv = ieee80211_priv(dev);
  5590. struct ieee80211_device *ieee = priv->ieee;
  5591. struct iw_param *param = &wrqu->param;
  5592. struct ieee80211_crypt_data *crypt;
  5593. unsigned long flags;
  5594. int ret = 0;
  5595. switch (param->flags & IW_AUTH_INDEX) {
  5596. case IW_AUTH_WPA_VERSION:
  5597. break;
  5598. case IW_AUTH_CIPHER_PAIRWISE:
  5599. ipw_set_hw_decrypt_unicast(priv,
  5600. wext_cipher2level(param->value));
  5601. break;
  5602. case IW_AUTH_CIPHER_GROUP:
  5603. ipw_set_hw_decrypt_multicast(priv,
  5604. wext_cipher2level(param->value));
  5605. break;
  5606. case IW_AUTH_KEY_MGMT:
  5607. /*
  5608. * ipw2200 does not use these parameters
  5609. */
  5610. break;
  5611. case IW_AUTH_TKIP_COUNTERMEASURES:
  5612. crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
  5613. if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) {
  5614. IPW_WARNING("Can't set TKIP countermeasures: "
  5615. "crypt not set!\n");
  5616. break;
  5617. }
  5618. flags = crypt->ops->get_flags(crypt->priv);
  5619. if (param->value)
  5620. flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
  5621. else
  5622. flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
  5623. crypt->ops->set_flags(flags, crypt->priv);
  5624. break;
  5625. case IW_AUTH_DROP_UNENCRYPTED:{
  5626. /* HACK:
  5627. *
  5628. * wpa_supplicant calls set_wpa_enabled when the driver
  5629. * is loaded and unloaded, regardless of if WPA is being
  5630. * used. No other calls are made which can be used to
  5631. * determine if encryption will be used or not prior to
  5632. * association being expected. If encryption is not being
  5633. * used, drop_unencrypted is set to false, else true -- we
  5634. * can use this to determine if the CAP_PRIVACY_ON bit should
  5635. * be set.
  5636. */
  5637. struct ieee80211_security sec = {
  5638. .flags = SEC_ENABLED,
  5639. .enabled = param->value,
  5640. };
  5641. priv->ieee->drop_unencrypted = param->value;
  5642. /* We only change SEC_LEVEL for open mode. Others
  5643. * are set by ipw_wpa_set_encryption.
  5644. */
  5645. if (!param->value) {
  5646. sec.flags |= SEC_LEVEL;
  5647. sec.level = SEC_LEVEL_0;
  5648. } else {
  5649. sec.flags |= SEC_LEVEL;
  5650. sec.level = SEC_LEVEL_1;
  5651. }
  5652. if (priv->ieee->set_security)
  5653. priv->ieee->set_security(priv->ieee->dev, &sec);
  5654. break;
  5655. }
  5656. case IW_AUTH_80211_AUTH_ALG:
  5657. ret = ipw_wpa_set_auth_algs(priv, param->value);
  5658. break;
  5659. case IW_AUTH_WPA_ENABLED:
  5660. ret = ipw_wpa_enable(priv, param->value);
  5661. break;
  5662. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  5663. ieee->ieee802_1x = param->value;
  5664. break;
  5665. //case IW_AUTH_ROAMING_CONTROL:
  5666. case IW_AUTH_PRIVACY_INVOKED:
  5667. ieee->privacy_invoked = param->value;
  5668. break;
  5669. default:
  5670. return -EOPNOTSUPP;
  5671. }
  5672. return ret;
  5673. }
  5674. /* SIOCGIWAUTH */
  5675. static int ipw_wx_get_auth(struct net_device *dev,
  5676. struct iw_request_info *info,
  5677. union iwreq_data *wrqu, char *extra)
  5678. {
  5679. struct ipw_priv *priv = ieee80211_priv(dev);
  5680. struct ieee80211_device *ieee = priv->ieee;
  5681. struct ieee80211_crypt_data *crypt;
  5682. struct iw_param *param = &wrqu->param;
  5683. int ret = 0;
  5684. switch (param->flags & IW_AUTH_INDEX) {
  5685. case IW_AUTH_WPA_VERSION:
  5686. case IW_AUTH_CIPHER_PAIRWISE:
  5687. case IW_AUTH_CIPHER_GROUP:
  5688. case IW_AUTH_KEY_MGMT:
  5689. /*
  5690. * wpa_supplicant will control these internally
  5691. */
  5692. ret = -EOPNOTSUPP;
  5693. break;
  5694. case IW_AUTH_TKIP_COUNTERMEASURES:
  5695. crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
  5696. if (!crypt || !crypt->ops->get_flags) {
  5697. IPW_WARNING("Can't get TKIP countermeasures: "
  5698. "crypt not set!\n");
  5699. break;
  5700. }
  5701. param->value = (crypt->ops->get_flags(crypt->priv) &
  5702. IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
  5703. break;
  5704. case IW_AUTH_DROP_UNENCRYPTED:
  5705. param->value = ieee->drop_unencrypted;
  5706. break;
  5707. case IW_AUTH_80211_AUTH_ALG:
  5708. param->value = ieee->sec.auth_mode;
  5709. break;
  5710. case IW_AUTH_WPA_ENABLED:
  5711. param->value = ieee->wpa_enabled;
  5712. break;
  5713. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  5714. param->value = ieee->ieee802_1x;
  5715. break;
  5716. case IW_AUTH_ROAMING_CONTROL:
  5717. case IW_AUTH_PRIVACY_INVOKED:
  5718. param->value = ieee->privacy_invoked;
  5719. break;
  5720. default:
  5721. return -EOPNOTSUPP;
  5722. }
  5723. return 0;
  5724. }
  5725. /* SIOCSIWENCODEEXT */
  5726. static int ipw_wx_set_encodeext(struct net_device *dev,
  5727. struct iw_request_info *info,
  5728. union iwreq_data *wrqu, char *extra)
  5729. {
  5730. struct ipw_priv *priv = ieee80211_priv(dev);
  5731. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  5732. if (hwcrypto) {
  5733. /* IPW HW can't build TKIP MIC, host decryption still needed */
  5734. if (ext->alg == IW_ENCODE_ALG_TKIP) {
  5735. priv->ieee->host_encrypt = 0;
  5736. priv->ieee->host_encrypt_msdu = 1;
  5737. priv->ieee->host_decrypt = 1;
  5738. } else {
  5739. priv->ieee->host_encrypt = 0;
  5740. priv->ieee->host_encrypt_msdu = 0;
  5741. priv->ieee->host_decrypt = 0;
  5742. }
  5743. }
  5744. return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
  5745. }
  5746. /* SIOCGIWENCODEEXT */
  5747. static int ipw_wx_get_encodeext(struct net_device *dev,
  5748. struct iw_request_info *info,
  5749. union iwreq_data *wrqu, char *extra)
  5750. {
  5751. struct ipw_priv *priv = ieee80211_priv(dev);
  5752. return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
  5753. }
  5754. /* SIOCSIWMLME */
  5755. static int ipw_wx_set_mlme(struct net_device *dev,
  5756. struct iw_request_info *info,
  5757. union iwreq_data *wrqu, char *extra)
  5758. {
  5759. struct ipw_priv *priv = ieee80211_priv(dev);
  5760. struct iw_mlme *mlme = (struct iw_mlme *)extra;
  5761. u16 reason;
  5762. reason = cpu_to_le16(mlme->reason_code);
  5763. switch (mlme->cmd) {
  5764. case IW_MLME_DEAUTH:
  5765. // silently ignore
  5766. break;
  5767. case IW_MLME_DISASSOC:
  5768. ipw_disassociate(priv);
  5769. break;
  5770. default:
  5771. return -EOPNOTSUPP;
  5772. }
  5773. return 0;
  5774. }
  5775. #endif
  5776. #ifdef CONFIG_IPW_QOS
  5777. /* QoS */
  5778. /*
  5779. * get the modulation type of the current network or
  5780. * the card current mode
  5781. */
  5782. u8 ipw_qos_current_mode(struct ipw_priv * priv)
  5783. {
  5784. u8 mode = 0;
  5785. if (priv->status & STATUS_ASSOCIATED) {
  5786. unsigned long flags;
  5787. spin_lock_irqsave(&priv->ieee->lock, flags);
  5788. mode = priv->assoc_network->mode;
  5789. spin_unlock_irqrestore(&priv->ieee->lock, flags);
  5790. } else {
  5791. mode = priv->ieee->mode;
  5792. }
  5793. IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
  5794. return mode;
  5795. }
  5796. /*
  5797. * Handle management frame beacon and probe response
  5798. */
  5799. static int ipw_qos_handle_probe_reponse(struct ipw_priv *priv,
  5800. int active_network,
  5801. struct ieee80211_network *network)
  5802. {
  5803. u32 size = sizeof(struct ieee80211_qos_parameters);
  5804. if (network->capability & WLAN_CAPABILITY_IBSS)
  5805. network->qos_data.active = network->qos_data.supported;
  5806. if (network->flags & NETWORK_HAS_QOS_MASK) {
  5807. if (active_network &&
  5808. (network->flags & NETWORK_HAS_QOS_PARAMETERS))
  5809. network->qos_data.active = network->qos_data.supported;
  5810. if ((network->qos_data.active == 1) && (active_network == 1) &&
  5811. (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
  5812. (network->qos_data.old_param_count !=
  5813. network->qos_data.param_count)) {
  5814. network->qos_data.old_param_count =
  5815. network->qos_data.param_count;
  5816. schedule_work(&priv->qos_activate);
  5817. IPW_DEBUG_QOS("QoS parameters change call "
  5818. "qos_activate\n");
  5819. }
  5820. } else {
  5821. if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
  5822. memcpy(&network->qos_data.parameters,
  5823. &def_parameters_CCK, size);
  5824. else
  5825. memcpy(&network->qos_data.parameters,
  5826. &def_parameters_OFDM, size);
  5827. if ((network->qos_data.active == 1) && (active_network == 1)) {
  5828. IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
  5829. schedule_work(&priv->qos_activate);
  5830. }
  5831. network->qos_data.active = 0;
  5832. network->qos_data.supported = 0;
  5833. }
  5834. if ((priv->status & STATUS_ASSOCIATED) &&
  5835. (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
  5836. if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
  5837. if ((network->capability & WLAN_CAPABILITY_IBSS) &&
  5838. !(network->flags & NETWORK_EMPTY_ESSID))
  5839. if ((network->ssid_len ==
  5840. priv->assoc_network->ssid_len) &&
  5841. !memcmp(network->ssid,
  5842. priv->assoc_network->ssid,
  5843. network->ssid_len)) {
  5844. queue_work(priv->workqueue,
  5845. &priv->merge_networks);
  5846. }
  5847. }
  5848. return 0;
  5849. }
  5850. /*
  5851. * This function set up the firmware to support QoS. It sends
  5852. * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
  5853. */
  5854. static int ipw_qos_activate(struct ipw_priv *priv,
  5855. struct ieee80211_qos_data *qos_network_data)
  5856. {
  5857. int err;
  5858. struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
  5859. struct ieee80211_qos_parameters *active_one = NULL;
  5860. u32 size = sizeof(struct ieee80211_qos_parameters);
  5861. u32 burst_duration;
  5862. int i;
  5863. u8 type;
  5864. type = ipw_qos_current_mode(priv);
  5865. active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
  5866. memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
  5867. active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
  5868. memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
  5869. if (qos_network_data == NULL) {
  5870. if (type == IEEE_B) {
  5871. IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
  5872. active_one = &def_parameters_CCK;
  5873. } else
  5874. active_one = &def_parameters_OFDM;
  5875. memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
  5876. burst_duration = ipw_qos_get_burst_duration(priv);
  5877. for (i = 0; i < QOS_QUEUE_NUM; i++)
  5878. qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
  5879. (u16) burst_duration;
  5880. } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
  5881. if (type == IEEE_B) {
  5882. IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
  5883. type);
  5884. if (priv->qos_data.qos_enable == 0)
  5885. active_one = &def_parameters_CCK;
  5886. else
  5887. active_one = priv->qos_data.def_qos_parm_CCK;
  5888. } else {
  5889. if (priv->qos_data.qos_enable == 0)
  5890. active_one = &def_parameters_OFDM;
  5891. else
  5892. active_one = priv->qos_data.def_qos_parm_OFDM;
  5893. }
  5894. memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
  5895. } else {
  5896. unsigned long flags;
  5897. int active;
  5898. spin_lock_irqsave(&priv->ieee->lock, flags);
  5899. active_one = &(qos_network_data->parameters);
  5900. qos_network_data->old_param_count =
  5901. qos_network_data->param_count;
  5902. memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
  5903. active = qos_network_data->supported;
  5904. spin_unlock_irqrestore(&priv->ieee->lock, flags);
  5905. if (active == 0) {
  5906. burst_duration = ipw_qos_get_burst_duration(priv);
  5907. for (i = 0; i < QOS_QUEUE_NUM; i++)
  5908. qos_parameters[QOS_PARAM_SET_ACTIVE].
  5909. tx_op_limit[i] = (u16) burst_duration;
  5910. }
  5911. }
  5912. IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
  5913. err = ipw_send_qos_params_command(priv,
  5914. (struct ieee80211_qos_parameters *)
  5915. &(qos_parameters[0]));
  5916. if (err)
  5917. IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
  5918. return err;
  5919. }
  5920. /*
  5921. * send IPW_CMD_WME_INFO to the firmware
  5922. */
  5923. static int ipw_qos_set_info_element(struct ipw_priv *priv)
  5924. {
  5925. int ret = 0;
  5926. struct ieee80211_qos_information_element qos_info;
  5927. if (priv == NULL)
  5928. return -1;
  5929. qos_info.elementID = QOS_ELEMENT_ID;
  5930. qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
  5931. qos_info.version = QOS_VERSION_1;
  5932. qos_info.ac_info = 0;
  5933. memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
  5934. qos_info.qui_type = QOS_OUI_TYPE;
  5935. qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
  5936. ret = ipw_send_qos_info_command(priv, &qos_info);
  5937. if (ret != 0) {
  5938. IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
  5939. }
  5940. return ret;
  5941. }
  5942. /*
  5943. * Set the QoS parameter with the association request structure
  5944. */
  5945. static int ipw_qos_association(struct ipw_priv *priv,
  5946. struct ieee80211_network *network)
  5947. {
  5948. int err = 0;
  5949. struct ieee80211_qos_data *qos_data = NULL;
  5950. struct ieee80211_qos_data ibss_data = {
  5951. .supported = 1,
  5952. .active = 1,
  5953. };
  5954. switch (priv->ieee->iw_mode) {
  5955. case IW_MODE_ADHOC:
  5956. if (!(network->capability & WLAN_CAPABILITY_IBSS))
  5957. BUG();
  5958. qos_data = &ibss_data;
  5959. break;
  5960. case IW_MODE_INFRA:
  5961. qos_data = &network->qos_data;
  5962. break;
  5963. default:
  5964. BUG();
  5965. break;
  5966. }
  5967. err = ipw_qos_activate(priv, qos_data);
  5968. if (err) {
  5969. priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
  5970. return err;
  5971. }
  5972. if (priv->qos_data.qos_enable && qos_data->supported) {
  5973. IPW_DEBUG_QOS("QoS will be enabled for this association\n");
  5974. priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
  5975. return ipw_qos_set_info_element(priv);
  5976. }
  5977. return 0;
  5978. }
  5979. /*
  5980. * handling the beaconing responces. if we get different QoS setting
  5981. * of the network from the the associated setting adjust the QoS
  5982. * setting
  5983. */
  5984. static int ipw_qos_association_resp(struct ipw_priv *priv,
  5985. struct ieee80211_network *network)
  5986. {
  5987. int ret = 0;
  5988. unsigned long flags;
  5989. u32 size = sizeof(struct ieee80211_qos_parameters);
  5990. int set_qos_param = 0;
  5991. if ((priv == NULL) || (network == NULL) ||
  5992. (priv->assoc_network == NULL))
  5993. return ret;
  5994. if (!(priv->status & STATUS_ASSOCIATED))
  5995. return ret;
  5996. if ((priv->ieee->iw_mode != IW_MODE_INFRA))
  5997. return ret;
  5998. spin_lock_irqsave(&priv->ieee->lock, flags);
  5999. if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
  6000. memcpy(&priv->assoc_network->qos_data, &network->qos_data,
  6001. sizeof(struct ieee80211_qos_data));
  6002. priv->assoc_network->qos_data.active = 1;
  6003. if ((network->qos_data.old_param_count !=
  6004. network->qos_data.param_count)) {
  6005. set_qos_param = 1;
  6006. network->qos_data.old_param_count =
  6007. network->qos_data.param_count;
  6008. }
  6009. } else {
  6010. if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
  6011. memcpy(&priv->assoc_network->qos_data.parameters,
  6012. &def_parameters_CCK, size);
  6013. else
  6014. memcpy(&priv->assoc_network->qos_data.parameters,
  6015. &def_parameters_OFDM, size);
  6016. priv->assoc_network->qos_data.active = 0;
  6017. priv->assoc_network->qos_data.supported = 0;
  6018. set_qos_param = 1;
  6019. }
  6020. spin_unlock_irqrestore(&priv->ieee->lock, flags);
  6021. if (set_qos_param == 1)
  6022. schedule_work(&priv->qos_activate);
  6023. return ret;
  6024. }
  6025. static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
  6026. {
  6027. u32 ret = 0;
  6028. if ((priv == NULL))
  6029. return 0;
  6030. if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION))
  6031. ret = priv->qos_data.burst_duration_CCK;
  6032. else
  6033. ret = priv->qos_data.burst_duration_OFDM;
  6034. return ret;
  6035. }
  6036. /*
  6037. * Initialize the setting of QoS global
  6038. */
  6039. static void ipw_qos_init(struct ipw_priv *priv, int enable,
  6040. int burst_enable, u32 burst_duration_CCK,
  6041. u32 burst_duration_OFDM)
  6042. {
  6043. priv->qos_data.qos_enable = enable;
  6044. if (priv->qos_data.qos_enable) {
  6045. priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
  6046. priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
  6047. IPW_DEBUG_QOS("QoS is enabled\n");
  6048. } else {
  6049. priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
  6050. priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
  6051. IPW_DEBUG_QOS("QoS is not enabled\n");
  6052. }
  6053. priv->qos_data.burst_enable = burst_enable;
  6054. if (burst_enable) {
  6055. priv->qos_data.burst_duration_CCK = burst_duration_CCK;
  6056. priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
  6057. } else {
  6058. priv->qos_data.burst_duration_CCK = 0;
  6059. priv->qos_data.burst_duration_OFDM = 0;
  6060. }
  6061. }
  6062. /*
  6063. * map the packet priority to the right TX Queue
  6064. */
  6065. static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
  6066. {
  6067. if (priority > 7 || !priv->qos_data.qos_enable)
  6068. priority = 0;
  6069. return from_priority_to_tx_queue[priority] - 1;
  6070. }
  6071. /*
  6072. * add QoS parameter to the TX command
  6073. */
  6074. static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
  6075. u16 priority,
  6076. struct tfd_data *tfd, u8 unicast)
  6077. {
  6078. int ret = 0;
  6079. int tx_queue_id = 0;
  6080. struct ieee80211_qos_data *qos_data = NULL;
  6081. int active, supported;
  6082. unsigned long flags;
  6083. if (!(priv->status & STATUS_ASSOCIATED))
  6084. return 0;
  6085. qos_data = &priv->assoc_network->qos_data;
  6086. spin_lock_irqsave(&priv->ieee->lock, flags);
  6087. if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
  6088. if (unicast == 0)
  6089. qos_data->active = 0;
  6090. else
  6091. qos_data->active = qos_data->supported;
  6092. }
  6093. active = qos_data->active;
  6094. supported = qos_data->supported;
  6095. spin_unlock_irqrestore(&priv->ieee->lock, flags);
  6096. IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
  6097. "unicast %d\n",
  6098. priv->qos_data.qos_enable, active, supported, unicast);
  6099. if (active && priv->qos_data.qos_enable) {
  6100. ret = from_priority_to_tx_queue[priority];
  6101. tx_queue_id = ret - 1;
  6102. IPW_DEBUG_QOS("QoS packet priority is %d \n", priority);
  6103. if (priority <= 7) {
  6104. tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
  6105. tfd->tfd.tfd_26.mchdr.qos_ctrl = priority;
  6106. tfd->tfd.tfd_26.mchdr.frame_ctl |=
  6107. IEEE80211_STYPE_QOS_DATA;
  6108. if (priv->qos_data.qos_no_ack_mask &
  6109. (1UL << tx_queue_id)) {
  6110. tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
  6111. tfd->tfd.tfd_26.mchdr.qos_ctrl |=
  6112. CTRL_QOS_NO_ACK;
  6113. }
  6114. }
  6115. }
  6116. return ret;
  6117. }
  6118. /*
  6119. * background support to run QoS activate functionality
  6120. */
  6121. static void ipw_bg_qos_activate(void *data)
  6122. {
  6123. struct ipw_priv *priv = data;
  6124. if (priv == NULL)
  6125. return;
  6126. down(&priv->sem);
  6127. if (priv->status & STATUS_ASSOCIATED)
  6128. ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
  6129. up(&priv->sem);
  6130. }
  6131. /*
  6132. * Handler for probe responce and beacon frame
  6133. */
  6134. static int ipw_handle_management(struct net_device *dev,
  6135. struct ieee80211_network *network, u16 type)
  6136. {
  6137. struct ipw_priv *priv = ieee80211_priv(dev);
  6138. int active_network;
  6139. if (priv->status & STATUS_ASSOCIATED && network == priv->assoc_network)
  6140. active_network = 1;
  6141. else
  6142. active_network = 0;
  6143. switch (type) {
  6144. case IEEE80211_STYPE_PROBE_RESP:
  6145. case IEEE80211_STYPE_BEACON:
  6146. ipw_qos_handle_probe_reponse(priv, active_network, network);
  6147. break;
  6148. case IEEE80211_STYPE_ASSOC_RESP:
  6149. ipw_qos_association_resp(priv, network);
  6150. break;
  6151. default:
  6152. break;
  6153. }
  6154. return 0;
  6155. }
  6156. static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
  6157. *qos_param)
  6158. {
  6159. struct host_cmd cmd = {
  6160. .cmd = IPW_CMD_QOS_PARAMETERS,
  6161. .len = (sizeof(struct ieee80211_qos_parameters) * 3)
  6162. };
  6163. if (!priv || !qos_param) {
  6164. IPW_ERROR("Invalid args\n");
  6165. return -1;
  6166. }
  6167. memcpy(cmd.param, qos_param, sizeof(*qos_param) * 3);
  6168. if (ipw_send_cmd(priv, &cmd)) {
  6169. IPW_ERROR("failed to send IPW_CMD_QOS_PARAMETERS command\n");
  6170. return -1;
  6171. }
  6172. return 0;
  6173. }
  6174. static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
  6175. *qos_param)
  6176. {
  6177. struct host_cmd cmd = {
  6178. .cmd = IPW_CMD_WME_INFO,
  6179. .len = sizeof(*qos_param)
  6180. };
  6181. if (!priv || !qos_param) {
  6182. IPW_ERROR("Invalid args\n");
  6183. return -1;
  6184. }
  6185. memcpy(cmd.param, qos_param, sizeof(*qos_param));
  6186. if (ipw_send_cmd(priv, &cmd)) {
  6187. IPW_ERROR("failed to send CMD_QOS_INFO command\n");
  6188. return -1;
  6189. }
  6190. return 0;
  6191. }
  6192. #endif /* CONFIG_IPW_QOS */
  6193. static int ipw_associate_network(struct ipw_priv *priv,
  6194. struct ieee80211_network *network,
  6195. struct ipw_supported_rates *rates, int roaming)
  6196. {
  6197. int err;
  6198. if (priv->config & CFG_FIXED_RATE)
  6199. ipw_set_fixed_rate(priv, network->mode);
  6200. if (!(priv->config & CFG_STATIC_ESSID)) {
  6201. priv->essid_len = min(network->ssid_len,
  6202. (u8) IW_ESSID_MAX_SIZE);
  6203. memcpy(priv->essid, network->ssid, priv->essid_len);
  6204. }
  6205. network->last_associate = jiffies;
  6206. memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
  6207. priv->assoc_request.channel = network->channel;
  6208. if ((priv->capability & CAP_PRIVACY_ON) &&
  6209. (priv->capability & CAP_SHARED_KEY)) {
  6210. priv->assoc_request.auth_type = AUTH_SHARED_KEY;
  6211. priv->assoc_request.auth_key = priv->ieee->sec.active_key;
  6212. if ((priv->capability & CAP_PRIVACY_ON) &&
  6213. (priv->ieee->sec.level == SEC_LEVEL_1) &&
  6214. !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
  6215. ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
  6216. } else {
  6217. priv->assoc_request.auth_type = AUTH_OPEN;
  6218. priv->assoc_request.auth_key = 0;
  6219. }
  6220. if (priv->ieee->wpa_ie_len) {
  6221. priv->assoc_request.policy_support = 0x02; /* RSN active */
  6222. ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
  6223. priv->ieee->wpa_ie_len);
  6224. }
  6225. /*
  6226. * It is valid for our ieee device to support multiple modes, but
  6227. * when it comes to associating to a given network we have to choose
  6228. * just one mode.
  6229. */
  6230. if (network->mode & priv->ieee->mode & IEEE_A)
  6231. priv->assoc_request.ieee_mode = IPW_A_MODE;
  6232. else if (network->mode & priv->ieee->mode & IEEE_G)
  6233. priv->assoc_request.ieee_mode = IPW_G_MODE;
  6234. else if (network->mode & priv->ieee->mode & IEEE_B)
  6235. priv->assoc_request.ieee_mode = IPW_B_MODE;
  6236. priv->assoc_request.capability = network->capability;
  6237. if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  6238. && !(priv->config & CFG_PREAMBLE_LONG)) {
  6239. priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
  6240. } else {
  6241. priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
  6242. /* Clear the short preamble if we won't be supporting it */
  6243. priv->assoc_request.capability &=
  6244. ~WLAN_CAPABILITY_SHORT_PREAMBLE;
  6245. }
  6246. /* Clear capability bits that aren't used in Ad Hoc */
  6247. if (priv->ieee->iw_mode == IW_MODE_ADHOC)
  6248. priv->assoc_request.capability &=
  6249. ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
  6250. IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
  6251. "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
  6252. roaming ? "Rea" : "A",
  6253. escape_essid(priv->essid, priv->essid_len),
  6254. network->channel,
  6255. ipw_modes[priv->assoc_request.ieee_mode],
  6256. rates->num_rates,
  6257. (priv->assoc_request.preamble_length ==
  6258. DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
  6259. network->capability &
  6260. WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
  6261. priv->capability & CAP_PRIVACY_ON ? "on " : "off",
  6262. priv->capability & CAP_PRIVACY_ON ?
  6263. (priv->capability & CAP_SHARED_KEY ? "(shared)" :
  6264. "(open)") : "",
  6265. priv->capability & CAP_PRIVACY_ON ? " key=" : "",
  6266. priv->capability & CAP_PRIVACY_ON ?
  6267. '1' + priv->ieee->sec.active_key : '.',
  6268. priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
  6269. priv->assoc_request.beacon_interval = network->beacon_interval;
  6270. if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
  6271. (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
  6272. priv->assoc_request.assoc_type = HC_IBSS_START;
  6273. priv->assoc_request.assoc_tsf_msw = 0;
  6274. priv->assoc_request.assoc_tsf_lsw = 0;
  6275. } else {
  6276. if (unlikely(roaming))
  6277. priv->assoc_request.assoc_type = HC_REASSOCIATE;
  6278. else
  6279. priv->assoc_request.assoc_type = HC_ASSOCIATE;
  6280. priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
  6281. priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
  6282. }
  6283. memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
  6284. if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
  6285. memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
  6286. priv->assoc_request.atim_window = network->atim_window;
  6287. } else {
  6288. memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
  6289. priv->assoc_request.atim_window = 0;
  6290. }
  6291. priv->assoc_request.listen_interval = network->listen_interval;
  6292. err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
  6293. if (err) {
  6294. IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
  6295. return err;
  6296. }
  6297. rates->ieee_mode = priv->assoc_request.ieee_mode;
  6298. rates->purpose = IPW_RATE_CONNECT;
  6299. ipw_send_supported_rates(priv, rates);
  6300. if (priv->assoc_request.ieee_mode == IPW_G_MODE)
  6301. priv->sys_config.dot11g_auto_detection = 1;
  6302. else
  6303. priv->sys_config.dot11g_auto_detection = 0;
  6304. if (priv->ieee->iw_mode == IW_MODE_ADHOC)
  6305. priv->sys_config.answer_broadcast_ssid_probe = 1;
  6306. else
  6307. priv->sys_config.answer_broadcast_ssid_probe = 0;
  6308. err = ipw_send_system_config(priv, &priv->sys_config);
  6309. if (err) {
  6310. IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
  6311. return err;
  6312. }
  6313. IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
  6314. err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
  6315. if (err) {
  6316. IPW_DEBUG_HC("Attempt to send associate command failed.\n");
  6317. return err;
  6318. }
  6319. /*
  6320. * If preemption is enabled, it is possible for the association
  6321. * to complete before we return from ipw_send_associate. Therefore
  6322. * we have to be sure and update our priviate data first.
  6323. */
  6324. priv->channel = network->channel;
  6325. memcpy(priv->bssid, network->bssid, ETH_ALEN);
  6326. priv->status |= STATUS_ASSOCIATING;
  6327. priv->status &= ~STATUS_SECURITY_UPDATED;
  6328. priv->assoc_network = network;
  6329. #ifdef CONFIG_IPW_QOS
  6330. ipw_qos_association(priv, network);
  6331. #endif
  6332. err = ipw_send_associate(priv, &priv->assoc_request);
  6333. if (err) {
  6334. IPW_DEBUG_HC("Attempt to send associate command failed.\n");
  6335. return err;
  6336. }
  6337. IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
  6338. escape_essid(priv->essid, priv->essid_len),
  6339. MAC_ARG(priv->bssid));
  6340. return 0;
  6341. }
  6342. static void ipw_roam(void *data)
  6343. {
  6344. struct ipw_priv *priv = data;
  6345. struct ieee80211_network *network = NULL;
  6346. struct ipw_network_match match = {
  6347. .network = priv->assoc_network
  6348. };
  6349. /* The roaming process is as follows:
  6350. *
  6351. * 1. Missed beacon threshold triggers the roaming process by
  6352. * setting the status ROAM bit and requesting a scan.
  6353. * 2. When the scan completes, it schedules the ROAM work
  6354. * 3. The ROAM work looks at all of the known networks for one that
  6355. * is a better network than the currently associated. If none
  6356. * found, the ROAM process is over (ROAM bit cleared)
  6357. * 4. If a better network is found, a disassociation request is
  6358. * sent.
  6359. * 5. When the disassociation completes, the roam work is again
  6360. * scheduled. The second time through, the driver is no longer
  6361. * associated, and the newly selected network is sent an
  6362. * association request.
  6363. * 6. At this point ,the roaming process is complete and the ROAM
  6364. * status bit is cleared.
  6365. */
  6366. /* If we are no longer associated, and the roaming bit is no longer
  6367. * set, then we are not actively roaming, so just return */
  6368. if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
  6369. return;
  6370. if (priv->status & STATUS_ASSOCIATED) {
  6371. /* First pass through ROAM process -- look for a better
  6372. * network */
  6373. unsigned long flags;
  6374. u8 rssi = priv->assoc_network->stats.rssi;
  6375. priv->assoc_network->stats.rssi = -128;
  6376. spin_lock_irqsave(&priv->ieee->lock, flags);
  6377. list_for_each_entry(network, &priv->ieee->network_list, list) {
  6378. if (network != priv->assoc_network)
  6379. ipw_best_network(priv, &match, network, 1);
  6380. }
  6381. spin_unlock_irqrestore(&priv->ieee->lock, flags);
  6382. priv->assoc_network->stats.rssi = rssi;
  6383. if (match.network == priv->assoc_network) {
  6384. IPW_DEBUG_ASSOC("No better APs in this network to "
  6385. "roam to.\n");
  6386. priv->status &= ~STATUS_ROAMING;
  6387. ipw_debug_config(priv);
  6388. return;
  6389. }
  6390. ipw_send_disassociate(priv, 1);
  6391. priv->assoc_network = match.network;
  6392. return;
  6393. }
  6394. /* Second pass through ROAM process -- request association */
  6395. ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
  6396. ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
  6397. priv->status &= ~STATUS_ROAMING;
  6398. }
  6399. static void ipw_bg_roam(void *data)
  6400. {
  6401. struct ipw_priv *priv = data;
  6402. down(&priv->sem);
  6403. ipw_roam(data);
  6404. up(&priv->sem);
  6405. }
  6406. static int ipw_associate(void *data)
  6407. {
  6408. struct ipw_priv *priv = data;
  6409. struct ieee80211_network *network = NULL;
  6410. struct ipw_network_match match = {
  6411. .network = NULL
  6412. };
  6413. struct ipw_supported_rates *rates;
  6414. struct list_head *element;
  6415. unsigned long flags;
  6416. if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
  6417. IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
  6418. return 0;
  6419. }
  6420. if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
  6421. IPW_DEBUG_ASSOC("Not attempting association (already in "
  6422. "progress)\n");
  6423. return 0;
  6424. }
  6425. if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
  6426. IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
  6427. "initialized)\n");
  6428. return 0;
  6429. }
  6430. if (!(priv->config & CFG_ASSOCIATE) &&
  6431. !(priv->config & (CFG_STATIC_ESSID |
  6432. CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
  6433. IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
  6434. return 0;
  6435. }
  6436. /* Protect our use of the network_list */
  6437. spin_lock_irqsave(&priv->ieee->lock, flags);
  6438. list_for_each_entry(network, &priv->ieee->network_list, list)
  6439. ipw_best_network(priv, &match, network, 0);
  6440. network = match.network;
  6441. rates = &match.rates;
  6442. if (network == NULL &&
  6443. priv->ieee->iw_mode == IW_MODE_ADHOC &&
  6444. priv->config & CFG_ADHOC_CREATE &&
  6445. priv->config & CFG_STATIC_ESSID &&
  6446. priv->config & CFG_STATIC_CHANNEL &&
  6447. !list_empty(&priv->ieee->network_free_list)) {
  6448. element = priv->ieee->network_free_list.next;
  6449. network = list_entry(element, struct ieee80211_network, list);
  6450. ipw_adhoc_create(priv, network);
  6451. rates = &priv->rates;
  6452. list_del(element);
  6453. list_add_tail(&network->list, &priv->ieee->network_list);
  6454. }
  6455. spin_unlock_irqrestore(&priv->ieee->lock, flags);
  6456. /* If we reached the end of the list, then we don't have any valid
  6457. * matching APs */
  6458. if (!network) {
  6459. ipw_debug_config(priv);
  6460. if (!(priv->status & STATUS_SCANNING)) {
  6461. if (!(priv->config & CFG_SPEED_SCAN))
  6462. queue_delayed_work(priv->workqueue,
  6463. &priv->request_scan,
  6464. SCAN_INTERVAL);
  6465. else
  6466. queue_work(priv->workqueue,
  6467. &priv->request_scan);
  6468. }
  6469. return 0;
  6470. }
  6471. ipw_associate_network(priv, network, rates, 0);
  6472. return 1;
  6473. }
  6474. static void ipw_bg_associate(void *data)
  6475. {
  6476. struct ipw_priv *priv = data;
  6477. down(&priv->sem);
  6478. ipw_associate(data);
  6479. up(&priv->sem);
  6480. }
  6481. static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
  6482. struct sk_buff *skb)
  6483. {
  6484. struct ieee80211_hdr *hdr;
  6485. u16 fc;
  6486. hdr = (struct ieee80211_hdr *)skb->data;
  6487. fc = le16_to_cpu(hdr->frame_ctl);
  6488. if (!(fc & IEEE80211_FCTL_PROTECTED))
  6489. return;
  6490. fc &= ~IEEE80211_FCTL_PROTECTED;
  6491. hdr->frame_ctl = cpu_to_le16(fc);
  6492. switch (priv->ieee->sec.level) {
  6493. case SEC_LEVEL_3:
  6494. /* Remove CCMP HDR */
  6495. memmove(skb->data + IEEE80211_3ADDR_LEN,
  6496. skb->data + IEEE80211_3ADDR_LEN + 8,
  6497. skb->len - IEEE80211_3ADDR_LEN - 8);
  6498. if (fc & IEEE80211_FCTL_MOREFRAGS)
  6499. skb_trim(skb, skb->len - 16); /* 2*MIC */
  6500. else
  6501. skb_trim(skb, skb->len - 8); /* MIC */
  6502. break;
  6503. case SEC_LEVEL_2:
  6504. break;
  6505. case SEC_LEVEL_1:
  6506. /* Remove IV */
  6507. memmove(skb->data + IEEE80211_3ADDR_LEN,
  6508. skb->data + IEEE80211_3ADDR_LEN + 4,
  6509. skb->len - IEEE80211_3ADDR_LEN - 4);
  6510. if (fc & IEEE80211_FCTL_MOREFRAGS)
  6511. skb_trim(skb, skb->len - 8); /* 2*ICV */
  6512. else
  6513. skb_trim(skb, skb->len - 4); /* ICV */
  6514. break;
  6515. case SEC_LEVEL_0:
  6516. break;
  6517. default:
  6518. printk(KERN_ERR "Unknow security level %d\n",
  6519. priv->ieee->sec.level);
  6520. break;
  6521. }
  6522. }
  6523. static void ipw_handle_data_packet(struct ipw_priv *priv,
  6524. struct ipw_rx_mem_buffer *rxb,
  6525. struct ieee80211_rx_stats *stats)
  6526. {
  6527. struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
  6528. /* We received data from the HW, so stop the watchdog */
  6529. priv->net_dev->trans_start = jiffies;
  6530. /* We only process data packets if the
  6531. * interface is open */
  6532. if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
  6533. skb_tailroom(rxb->skb))) {
  6534. priv->ieee->stats.rx_errors++;
  6535. priv->wstats.discard.misc++;
  6536. IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
  6537. return;
  6538. } else if (unlikely(!netif_running(priv->net_dev))) {
  6539. priv->ieee->stats.rx_dropped++;
  6540. priv->wstats.discard.misc++;
  6541. IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
  6542. return;
  6543. }
  6544. /* Advance skb->data to the start of the actual payload */
  6545. skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
  6546. /* Set the size of the skb to the size of the frame */
  6547. skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
  6548. IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
  6549. /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
  6550. if (!priv->ieee->host_decrypt)
  6551. ipw_rebuild_decrypted_skb(priv, rxb->skb);
  6552. if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
  6553. priv->ieee->stats.rx_errors++;
  6554. else { /* ieee80211_rx succeeded, so it now owns the SKB */
  6555. rxb->skb = NULL;
  6556. __ipw_led_activity_on(priv);
  6557. }
  6558. }
  6559. static inline int is_network_packet(struct ipw_priv *priv,
  6560. struct ieee80211_hdr_4addr *header)
  6561. {
  6562. /* Filter incoming packets to determine if they are targetted toward
  6563. * this network, discarding packets coming from ourselves */
  6564. switch (priv->ieee->iw_mode) {
  6565. case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
  6566. /* packets from our adapter are dropped (echo) */
  6567. if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
  6568. return 0;
  6569. /* multicast packets to our IBSS go through */
  6570. if (is_multicast_ether_addr(header->addr1))
  6571. return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
  6572. /* packets to our adapter go through */
  6573. return !memcmp(header->addr1, priv->net_dev->dev_addr,
  6574. ETH_ALEN);
  6575. case IW_MODE_INFRA: /* Header: Dest. | AP{BSSID} | Source */
  6576. /* packets from our adapter are dropped (echo) */
  6577. if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
  6578. return 0;
  6579. /* {broad,multi}cast packets to our IBSS go through */
  6580. if (is_multicast_ether_addr(header->addr1))
  6581. return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
  6582. /* packets to our adapter go through */
  6583. return !memcmp(header->addr1, priv->net_dev->dev_addr,
  6584. ETH_ALEN);
  6585. }
  6586. return 1;
  6587. }
  6588. #define IPW_PACKET_RETRY_TIME HZ
  6589. static inline int is_duplicate_packet(struct ipw_priv *priv,
  6590. struct ieee80211_hdr_4addr *header)
  6591. {
  6592. u16 sc = le16_to_cpu(header->seq_ctl);
  6593. u16 seq = WLAN_GET_SEQ_SEQ(sc);
  6594. u16 frag = WLAN_GET_SEQ_FRAG(sc);
  6595. u16 *last_seq, *last_frag;
  6596. unsigned long *last_time;
  6597. switch (priv->ieee->iw_mode) {
  6598. case IW_MODE_ADHOC:
  6599. {
  6600. struct list_head *p;
  6601. struct ipw_ibss_seq *entry = NULL;
  6602. u8 *mac = header->addr2;
  6603. int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
  6604. __list_for_each(p, &priv->ibss_mac_hash[index]) {
  6605. entry =
  6606. list_entry(p, struct ipw_ibss_seq, list);
  6607. if (!memcmp(entry->mac, mac, ETH_ALEN))
  6608. break;
  6609. }
  6610. if (p == &priv->ibss_mac_hash[index]) {
  6611. entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
  6612. if (!entry) {
  6613. IPW_ERROR
  6614. ("Cannot malloc new mac entry\n");
  6615. return 0;
  6616. }
  6617. memcpy(entry->mac, mac, ETH_ALEN);
  6618. entry->seq_num = seq;
  6619. entry->frag_num = frag;
  6620. entry->packet_time = jiffies;
  6621. list_add(&entry->list,
  6622. &priv->ibss_mac_hash[index]);
  6623. return 0;
  6624. }
  6625. last_seq = &entry->seq_num;
  6626. last_frag = &entry->frag_num;
  6627. last_time = &entry->packet_time;
  6628. break;
  6629. }
  6630. case IW_MODE_INFRA:
  6631. last_seq = &priv->last_seq_num;
  6632. last_frag = &priv->last_frag_num;
  6633. last_time = &priv->last_packet_time;
  6634. break;
  6635. default:
  6636. return 0;
  6637. }
  6638. if ((*last_seq == seq) &&
  6639. time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
  6640. if (*last_frag == frag)
  6641. goto drop;
  6642. if (*last_frag + 1 != frag)
  6643. /* out-of-order fragment */
  6644. goto drop;
  6645. } else
  6646. *last_seq = seq;
  6647. *last_frag = frag;
  6648. *last_time = jiffies;
  6649. return 0;
  6650. drop:
  6651. /* Comment this line now since we observed the card receives
  6652. * duplicate packets but the FCTL_RETRY bit is not set in the
  6653. * IBSS mode with fragmentation enabled.
  6654. BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */
  6655. return 1;
  6656. }
  6657. static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
  6658. struct ipw_rx_mem_buffer *rxb,
  6659. struct ieee80211_rx_stats *stats)
  6660. {
  6661. struct sk_buff *skb = rxb->skb;
  6662. struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
  6663. struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
  6664. (skb->data + IPW_RX_FRAME_SIZE);
  6665. ieee80211_rx_mgt(priv->ieee, header, stats);
  6666. if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
  6667. ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
  6668. IEEE80211_STYPE_PROBE_RESP) ||
  6669. (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
  6670. IEEE80211_STYPE_BEACON))) {
  6671. if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
  6672. ipw_add_station(priv, header->addr2);
  6673. }
  6674. if (priv->config & CFG_NET_STATS) {
  6675. IPW_DEBUG_HC("sending stat packet\n");
  6676. /* Set the size of the skb to the size of the full
  6677. * ipw header and 802.11 frame */
  6678. skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
  6679. IPW_RX_FRAME_SIZE);
  6680. /* Advance past the ipw packet header to the 802.11 frame */
  6681. skb_pull(skb, IPW_RX_FRAME_SIZE);
  6682. /* Push the ieee80211_rx_stats before the 802.11 frame */
  6683. memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
  6684. skb->dev = priv->ieee->dev;
  6685. /* Point raw at the ieee80211_stats */
  6686. skb->mac.raw = skb->data;
  6687. skb->pkt_type = PACKET_OTHERHOST;
  6688. skb->protocol = __constant_htons(ETH_P_80211_STATS);
  6689. memset(skb->cb, 0, sizeof(rxb->skb->cb));
  6690. netif_rx(skb);
  6691. rxb->skb = NULL;
  6692. }
  6693. }
  6694. /*
  6695. * Main entry function for recieving a packet with 80211 headers. This
  6696. * should be called when ever the FW has notified us that there is a new
  6697. * skb in the recieve queue.
  6698. */
  6699. static void ipw_rx(struct ipw_priv *priv)
  6700. {
  6701. struct ipw_rx_mem_buffer *rxb;
  6702. struct ipw_rx_packet *pkt;
  6703. struct ieee80211_hdr_4addr *header;
  6704. u32 r, w, i;
  6705. u8 network_packet;
  6706. r = ipw_read32(priv, IPW_RX_READ_INDEX);
  6707. w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
  6708. i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
  6709. while (i != r) {
  6710. rxb = priv->rxq->queue[i];
  6711. #ifdef CONFIG_IPW_DEBUG
  6712. if (unlikely(rxb == NULL)) {
  6713. printk(KERN_CRIT "Queue not allocated!\n");
  6714. break;
  6715. }
  6716. #endif
  6717. priv->rxq->queue[i] = NULL;
  6718. pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
  6719. IPW_RX_BUF_SIZE,
  6720. PCI_DMA_FROMDEVICE);
  6721. pkt = (struct ipw_rx_packet *)rxb->skb->data;
  6722. IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
  6723. pkt->header.message_type,
  6724. pkt->header.rx_seq_num, pkt->header.control_bits);
  6725. switch (pkt->header.message_type) {
  6726. case RX_FRAME_TYPE: /* 802.11 frame */ {
  6727. struct ieee80211_rx_stats stats = {
  6728. .rssi =
  6729. le16_to_cpu(pkt->u.frame.rssi_dbm) -
  6730. IPW_RSSI_TO_DBM,
  6731. .signal =
  6732. le16_to_cpu(pkt->u.frame.signal),
  6733. .noise =
  6734. le16_to_cpu(pkt->u.frame.noise),
  6735. .rate = pkt->u.frame.rate,
  6736. .mac_time = jiffies,
  6737. .received_channel =
  6738. pkt->u.frame.received_channel,
  6739. .freq =
  6740. (pkt->u.frame.
  6741. control & (1 << 0)) ?
  6742. IEEE80211_24GHZ_BAND :
  6743. IEEE80211_52GHZ_BAND,
  6744. .len = le16_to_cpu(pkt->u.frame.length),
  6745. };
  6746. if (stats.rssi != 0)
  6747. stats.mask |= IEEE80211_STATMASK_RSSI;
  6748. if (stats.signal != 0)
  6749. stats.mask |= IEEE80211_STATMASK_SIGNAL;
  6750. if (stats.noise != 0)
  6751. stats.mask |= IEEE80211_STATMASK_NOISE;
  6752. if (stats.rate != 0)
  6753. stats.mask |= IEEE80211_STATMASK_RATE;
  6754. priv->rx_packets++;
  6755. #ifdef CONFIG_IPW2200_MONITOR
  6756. if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
  6757. ipw_handle_data_packet(priv, rxb,
  6758. &stats);
  6759. break;
  6760. }
  6761. #endif
  6762. header =
  6763. (struct ieee80211_hdr_4addr *)(rxb->skb->
  6764. data +
  6765. IPW_RX_FRAME_SIZE);
  6766. /* TODO: Check Ad-Hoc dest/source and make sure
  6767. * that we are actually parsing these packets
  6768. * correctly -- we should probably use the
  6769. * frame control of the packet and disregard
  6770. * the current iw_mode */
  6771. network_packet =
  6772. is_network_packet(priv, header);
  6773. if (network_packet && priv->assoc_network) {
  6774. priv->assoc_network->stats.rssi =
  6775. stats.rssi;
  6776. average_add(&priv->average_rssi,
  6777. stats.rssi);
  6778. priv->last_rx_rssi = stats.rssi;
  6779. }
  6780. IPW_DEBUG_RX("Frame: len=%u\n",
  6781. le16_to_cpu(pkt->u.frame.length));
  6782. if (le16_to_cpu(pkt->u.frame.length) <
  6783. frame_hdr_len(header)) {
  6784. IPW_DEBUG_DROP
  6785. ("Received packet is too small. "
  6786. "Dropping.\n");
  6787. priv->ieee->stats.rx_errors++;
  6788. priv->wstats.discard.misc++;
  6789. break;
  6790. }
  6791. switch (WLAN_FC_GET_TYPE
  6792. (le16_to_cpu(header->frame_ctl))) {
  6793. case IEEE80211_FTYPE_MGMT:
  6794. ipw_handle_mgmt_packet(priv, rxb,
  6795. &stats);
  6796. break;
  6797. case IEEE80211_FTYPE_CTL:
  6798. break;
  6799. case IEEE80211_FTYPE_DATA:
  6800. if (unlikely(!network_packet ||
  6801. is_duplicate_packet(priv,
  6802. header)))
  6803. {
  6804. IPW_DEBUG_DROP("Dropping: "
  6805. MAC_FMT ", "
  6806. MAC_FMT ", "
  6807. MAC_FMT "\n",
  6808. MAC_ARG(header->
  6809. addr1),
  6810. MAC_ARG(header->
  6811. addr2),
  6812. MAC_ARG(header->
  6813. addr3));
  6814. break;
  6815. }
  6816. ipw_handle_data_packet(priv, rxb,
  6817. &stats);
  6818. break;
  6819. }
  6820. break;
  6821. }
  6822. case RX_HOST_NOTIFICATION_TYPE:{
  6823. IPW_DEBUG_RX
  6824. ("Notification: subtype=%02X flags=%02X size=%d\n",
  6825. pkt->u.notification.subtype,
  6826. pkt->u.notification.flags,
  6827. pkt->u.notification.size);
  6828. ipw_rx_notification(priv, &pkt->u.notification);
  6829. break;
  6830. }
  6831. default:
  6832. IPW_DEBUG_RX("Bad Rx packet of type %d\n",
  6833. pkt->header.message_type);
  6834. break;
  6835. }
  6836. /* For now we just don't re-use anything. We can tweak this
  6837. * later to try and re-use notification packets and SKBs that
  6838. * fail to Rx correctly */
  6839. if (rxb->skb != NULL) {
  6840. dev_kfree_skb_any(rxb->skb);
  6841. rxb->skb = NULL;
  6842. }
  6843. pci_unmap_single(priv->pci_dev, rxb->dma_addr,
  6844. IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
  6845. list_add_tail(&rxb->list, &priv->rxq->rx_used);
  6846. i = (i + 1) % RX_QUEUE_SIZE;
  6847. }
  6848. /* Backtrack one entry */
  6849. priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
  6850. ipw_rx_queue_restock(priv);
  6851. }
  6852. #define DEFAULT_RTS_THRESHOLD 2304U
  6853. #define MIN_RTS_THRESHOLD 1U
  6854. #define MAX_RTS_THRESHOLD 2304U
  6855. #define DEFAULT_BEACON_INTERVAL 100U
  6856. #define DEFAULT_SHORT_RETRY_LIMIT 7U
  6857. #define DEFAULT_LONG_RETRY_LIMIT 4U
  6858. static int ipw_sw_reset(struct ipw_priv *priv, int init)
  6859. {
  6860. int band, modulation;
  6861. int old_mode = priv->ieee->iw_mode;
  6862. /* Initialize module parameter values here */
  6863. priv->config = 0;
  6864. /* We default to disabling the LED code as right now it causes
  6865. * too many systems to lock up... */
  6866. if (!led)
  6867. priv->config |= CFG_NO_LED;
  6868. if (associate)
  6869. priv->config |= CFG_ASSOCIATE;
  6870. else
  6871. IPW_DEBUG_INFO("Auto associate disabled.\n");
  6872. if (auto_create)
  6873. priv->config |= CFG_ADHOC_CREATE;
  6874. else
  6875. IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
  6876. if (disable) {
  6877. priv->status |= STATUS_RF_KILL_SW;
  6878. IPW_DEBUG_INFO("Radio disabled.\n");
  6879. }
  6880. if (channel != 0) {
  6881. priv->config |= CFG_STATIC_CHANNEL;
  6882. priv->channel = channel;
  6883. IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
  6884. /* TODO: Validate that provided channel is in range */
  6885. }
  6886. #ifdef CONFIG_IPW_QOS
  6887. ipw_qos_init(priv, qos_enable, qos_burst_enable,
  6888. burst_duration_CCK, burst_duration_OFDM);
  6889. #endif /* CONFIG_IPW_QOS */
  6890. switch (mode) {
  6891. case 1:
  6892. priv->ieee->iw_mode = IW_MODE_ADHOC;
  6893. priv->net_dev->type = ARPHRD_ETHER;
  6894. break;
  6895. #ifdef CONFIG_IPW2200_MONITOR
  6896. case 2:
  6897. priv->ieee->iw_mode = IW_MODE_MONITOR;
  6898. priv->net_dev->type = ARPHRD_IEEE80211;
  6899. break;
  6900. #endif
  6901. default:
  6902. case 0:
  6903. priv->net_dev->type = ARPHRD_ETHER;
  6904. priv->ieee->iw_mode = IW_MODE_INFRA;
  6905. break;
  6906. }
  6907. if (hwcrypto) {
  6908. priv->ieee->host_encrypt = 0;
  6909. priv->ieee->host_encrypt_msdu = 0;
  6910. priv->ieee->host_decrypt = 0;
  6911. }
  6912. IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
  6913. /* IPW2200/2915 is abled to do hardware fragmentation. */
  6914. priv->ieee->host_open_frag = 0;
  6915. if ((priv->pci_dev->device == 0x4223) ||
  6916. (priv->pci_dev->device == 0x4224)) {
  6917. if (init)
  6918. printk(KERN_INFO DRV_NAME
  6919. ": Detected Intel PRO/Wireless 2915ABG Network "
  6920. "Connection\n");
  6921. priv->ieee->abg_true = 1;
  6922. band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
  6923. modulation = IEEE80211_OFDM_MODULATION |
  6924. IEEE80211_CCK_MODULATION;
  6925. priv->adapter = IPW_2915ABG;
  6926. priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
  6927. } else {
  6928. if (init)
  6929. printk(KERN_INFO DRV_NAME
  6930. ": Detected Intel PRO/Wireless 2200BG Network "
  6931. "Connection\n");
  6932. priv->ieee->abg_true = 0;
  6933. band = IEEE80211_24GHZ_BAND;
  6934. modulation = IEEE80211_OFDM_MODULATION |
  6935. IEEE80211_CCK_MODULATION;
  6936. priv->adapter = IPW_2200BG;
  6937. priv->ieee->mode = IEEE_G | IEEE_B;
  6938. }
  6939. priv->ieee->freq_band = band;
  6940. priv->ieee->modulation = modulation;
  6941. priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
  6942. priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
  6943. priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
  6944. priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
  6945. priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
  6946. priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
  6947. /* If power management is turned on, default to AC mode */
  6948. priv->power_mode = IPW_POWER_AC;
  6949. priv->tx_power = IPW_TX_POWER_DEFAULT;
  6950. return old_mode == priv->ieee->iw_mode;
  6951. }
  6952. /*
  6953. * This file defines the Wireless Extension handlers. It does not
  6954. * define any methods of hardware manipulation and relies on the
  6955. * functions defined in ipw_main to provide the HW interaction.
  6956. *
  6957. * The exception to this is the use of the ipw_get_ordinal()
  6958. * function used to poll the hardware vs. making unecessary calls.
  6959. *
  6960. */
  6961. static int ipw_wx_get_name(struct net_device *dev,
  6962. struct iw_request_info *info,
  6963. union iwreq_data *wrqu, char *extra)
  6964. {
  6965. struct ipw_priv *priv = ieee80211_priv(dev);
  6966. down(&priv->sem);
  6967. if (priv->status & STATUS_RF_KILL_MASK)
  6968. strcpy(wrqu->name, "radio off");
  6969. else if (!(priv->status & STATUS_ASSOCIATED))
  6970. strcpy(wrqu->name, "unassociated");
  6971. else
  6972. snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
  6973. ipw_modes[priv->assoc_request.ieee_mode]);
  6974. IPW_DEBUG_WX("Name: %s\n", wrqu->name);
  6975. up(&priv->sem);
  6976. return 0;
  6977. }
  6978. static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
  6979. {
  6980. if (channel == 0) {
  6981. IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
  6982. priv->config &= ~CFG_STATIC_CHANNEL;
  6983. IPW_DEBUG_ASSOC("Attempting to associate with new "
  6984. "parameters.\n");
  6985. ipw_associate(priv);
  6986. return 0;
  6987. }
  6988. priv->config |= CFG_STATIC_CHANNEL;
  6989. if (priv->channel == channel) {
  6990. IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
  6991. channel);
  6992. return 0;
  6993. }
  6994. IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
  6995. priv->channel = channel;
  6996. #ifdef CONFIG_IPW2200_MONITOR
  6997. if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
  6998. int i;
  6999. if (priv->status & STATUS_SCANNING) {
  7000. IPW_DEBUG_SCAN("Scan abort triggered due to "
  7001. "channel change.\n");
  7002. ipw_abort_scan(priv);
  7003. }
  7004. for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
  7005. udelay(10);
  7006. if (priv->status & STATUS_SCANNING)
  7007. IPW_DEBUG_SCAN("Still scanning...\n");
  7008. else
  7009. IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
  7010. 1000 - i);
  7011. return 0;
  7012. }
  7013. #endif /* CONFIG_IPW2200_MONITOR */
  7014. /* Network configuration changed -- force [re]association */
  7015. IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
  7016. if (!ipw_disassociate(priv))
  7017. ipw_associate(priv);
  7018. return 0;
  7019. }
  7020. static int ipw_wx_set_freq(struct net_device *dev,
  7021. struct iw_request_info *info,
  7022. union iwreq_data *wrqu, char *extra)
  7023. {
  7024. struct ipw_priv *priv = ieee80211_priv(dev);
  7025. const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
  7026. struct iw_freq *fwrq = &wrqu->freq;
  7027. int ret = 0, i;
  7028. u8 channel;
  7029. if (fwrq->m == 0) {
  7030. IPW_DEBUG_WX("SET Freq/Channel -> any\n");
  7031. down(&priv->sem);
  7032. ret = ipw_set_channel(priv, 0);
  7033. up(&priv->sem);
  7034. return ret;
  7035. }
  7036. /* if setting by freq convert to channel */
  7037. if (fwrq->e == 1) {
  7038. channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m);
  7039. if (channel == 0)
  7040. return -EINVAL;
  7041. } else
  7042. channel = fwrq->m;
  7043. if (!ieee80211_is_valid_channel(priv->ieee, channel))
  7044. return -EINVAL;
  7045. if (priv->ieee->iw_mode == IW_MODE_ADHOC && priv->ieee->mode & IEEE_A) {
  7046. i = ieee80211_channel_to_index(priv->ieee, channel);
  7047. if (i == -1)
  7048. return -EINVAL;
  7049. if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
  7050. IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
  7051. return -EINVAL;
  7052. }
  7053. }
  7054. IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
  7055. down(&priv->sem);
  7056. ret = ipw_set_channel(priv, channel);
  7057. up(&priv->sem);
  7058. return ret;
  7059. }
  7060. static int ipw_wx_get_freq(struct net_device *dev,
  7061. struct iw_request_info *info,
  7062. union iwreq_data *wrqu, char *extra)
  7063. {
  7064. struct ipw_priv *priv = ieee80211_priv(dev);
  7065. wrqu->freq.e = 0;
  7066. /* If we are associated, trying to associate, or have a statically
  7067. * configured CHANNEL then return that; otherwise return ANY */
  7068. down(&priv->sem);
  7069. if (priv->config & CFG_STATIC_CHANNEL ||
  7070. priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
  7071. wrqu->freq.m = priv->channel;
  7072. else
  7073. wrqu->freq.m = 0;
  7074. up(&priv->sem);
  7075. IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
  7076. return 0;
  7077. }
  7078. static int ipw_wx_set_mode(struct net_device *dev,
  7079. struct iw_request_info *info,
  7080. union iwreq_data *wrqu, char *extra)
  7081. {
  7082. struct ipw_priv *priv = ieee80211_priv(dev);
  7083. int err = 0;
  7084. IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
  7085. switch (wrqu->mode) {
  7086. #ifdef CONFIG_IPW2200_MONITOR
  7087. case IW_MODE_MONITOR:
  7088. #endif
  7089. case IW_MODE_ADHOC:
  7090. case IW_MODE_INFRA:
  7091. break;
  7092. case IW_MODE_AUTO:
  7093. wrqu->mode = IW_MODE_INFRA;
  7094. break;
  7095. default:
  7096. return -EINVAL;
  7097. }
  7098. if (wrqu->mode == priv->ieee->iw_mode)
  7099. return 0;
  7100. down(&priv->sem);
  7101. ipw_sw_reset(priv, 0);
  7102. #ifdef CONFIG_IPW2200_MONITOR
  7103. if (priv->ieee->iw_mode == IW_MODE_MONITOR)
  7104. priv->net_dev->type = ARPHRD_ETHER;
  7105. if (wrqu->mode == IW_MODE_MONITOR)
  7106. priv->net_dev->type = ARPHRD_IEEE80211;
  7107. #endif /* CONFIG_IPW2200_MONITOR */
  7108. /* Free the existing firmware and reset the fw_loaded
  7109. * flag so ipw_load() will bring in the new firmawre */
  7110. free_firmware();
  7111. priv->ieee->iw_mode = wrqu->mode;
  7112. queue_work(priv->workqueue, &priv->adapter_restart);
  7113. up(&priv->sem);
  7114. return err;
  7115. }
  7116. static int ipw_wx_get_mode(struct net_device *dev,
  7117. struct iw_request_info *info,
  7118. union iwreq_data *wrqu, char *extra)
  7119. {
  7120. struct ipw_priv *priv = ieee80211_priv(dev);
  7121. down(&priv->sem);
  7122. wrqu->mode = priv->ieee->iw_mode;
  7123. IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
  7124. up(&priv->sem);
  7125. return 0;
  7126. }
  7127. /* Values are in microsecond */
  7128. static const s32 timeout_duration[] = {
  7129. 350000,
  7130. 250000,
  7131. 75000,
  7132. 37000,
  7133. 25000,
  7134. };
  7135. static const s32 period_duration[] = {
  7136. 400000,
  7137. 700000,
  7138. 1000000,
  7139. 1000000,
  7140. 1000000
  7141. };
  7142. static int ipw_wx_get_range(struct net_device *dev,
  7143. struct iw_request_info *info,
  7144. union iwreq_data *wrqu, char *extra)
  7145. {
  7146. struct ipw_priv *priv = ieee80211_priv(dev);
  7147. struct iw_range *range = (struct iw_range *)extra;
  7148. const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
  7149. int i = 0, j;
  7150. wrqu->data.length = sizeof(*range);
  7151. memset(range, 0, sizeof(*range));
  7152. /* 54Mbs == ~27 Mb/s real (802.11g) */
  7153. range->throughput = 27 * 1000 * 1000;
  7154. range->max_qual.qual = 100;
  7155. /* TODO: Find real max RSSI and stick here */
  7156. range->max_qual.level = 0;
  7157. range->max_qual.noise = priv->ieee->worst_rssi + 0x100;
  7158. range->max_qual.updated = 7; /* Updated all three */
  7159. range->avg_qual.qual = 70;
  7160. /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
  7161. range->avg_qual.level = 0; /* FIXME to real average level */
  7162. range->avg_qual.noise = 0;
  7163. range->avg_qual.updated = 7; /* Updated all three */
  7164. down(&priv->sem);
  7165. range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
  7166. for (i = 0; i < range->num_bitrates; i++)
  7167. range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
  7168. 500000;
  7169. range->max_rts = DEFAULT_RTS_THRESHOLD;
  7170. range->min_frag = MIN_FRAG_THRESHOLD;
  7171. range->max_frag = MAX_FRAG_THRESHOLD;
  7172. range->encoding_size[0] = 5;
  7173. range->encoding_size[1] = 13;
  7174. range->num_encoding_sizes = 2;
  7175. range->max_encoding_tokens = WEP_KEYS;
  7176. /* Set the Wireless Extension versions */
  7177. range->we_version_compiled = WIRELESS_EXT;
  7178. range->we_version_source = 16;
  7179. i = 0;
  7180. if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
  7181. for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES;
  7182. i++, j++) {
  7183. range->freq[i].i = geo->bg[j].channel;
  7184. range->freq[i].m = geo->bg[j].freq * 100000;
  7185. range->freq[i].e = 1;
  7186. }
  7187. }
  7188. if (priv->ieee->mode & IEEE_A) {
  7189. for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES;
  7190. i++, j++) {
  7191. range->freq[i].i = geo->a[j].channel;
  7192. range->freq[i].m = geo->a[j].freq * 100000;
  7193. range->freq[i].e = 1;
  7194. }
  7195. }
  7196. range->num_channels = i;
  7197. range->num_frequency = i;
  7198. up(&priv->sem);
  7199. IPW_DEBUG_WX("GET Range\n");
  7200. return 0;
  7201. }
  7202. static int ipw_wx_set_wap(struct net_device *dev,
  7203. struct iw_request_info *info,
  7204. union iwreq_data *wrqu, char *extra)
  7205. {
  7206. struct ipw_priv *priv = ieee80211_priv(dev);
  7207. static const unsigned char any[] = {
  7208. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
  7209. };
  7210. static const unsigned char off[] = {
  7211. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  7212. };
  7213. if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
  7214. return -EINVAL;
  7215. down(&priv->sem);
  7216. if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
  7217. !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
  7218. /* we disable mandatory BSSID association */
  7219. IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
  7220. priv->config &= ~CFG_STATIC_BSSID;
  7221. IPW_DEBUG_ASSOC("Attempting to associate with new "
  7222. "parameters.\n");
  7223. ipw_associate(priv);
  7224. up(&priv->sem);
  7225. return 0;
  7226. }
  7227. priv->config |= CFG_STATIC_BSSID;
  7228. if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
  7229. IPW_DEBUG_WX("BSSID set to current BSSID.\n");
  7230. up(&priv->sem);
  7231. return 0;
  7232. }
  7233. IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
  7234. MAC_ARG(wrqu->ap_addr.sa_data));
  7235. memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
  7236. /* Network configuration changed -- force [re]association */
  7237. IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
  7238. if (!ipw_disassociate(priv))
  7239. ipw_associate(priv);
  7240. up(&priv->sem);
  7241. return 0;
  7242. }
  7243. static int ipw_wx_get_wap(struct net_device *dev,
  7244. struct iw_request_info *info,
  7245. union iwreq_data *wrqu, char *extra)
  7246. {
  7247. struct ipw_priv *priv = ieee80211_priv(dev);
  7248. /* If we are associated, trying to associate, or have a statically
  7249. * configured BSSID then return that; otherwise return ANY */
  7250. down(&priv->sem);
  7251. if (priv->config & CFG_STATIC_BSSID ||
  7252. priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
  7253. wrqu->ap_addr.sa_family = ARPHRD_ETHER;
  7254. memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
  7255. } else
  7256. memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
  7257. IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
  7258. MAC_ARG(wrqu->ap_addr.sa_data));
  7259. up(&priv->sem);
  7260. return 0;
  7261. }
  7262. static int ipw_wx_set_essid(struct net_device *dev,
  7263. struct iw_request_info *info,
  7264. union iwreq_data *wrqu, char *extra)
  7265. {
  7266. struct ipw_priv *priv = ieee80211_priv(dev);
  7267. char *essid = ""; /* ANY */
  7268. int length = 0;
  7269. down(&priv->sem);
  7270. if (wrqu->essid.flags && wrqu->essid.length) {
  7271. length = wrqu->essid.length - 1;
  7272. essid = extra;
  7273. }
  7274. if (length == 0) {
  7275. IPW_DEBUG_WX("Setting ESSID to ANY\n");
  7276. if ((priv->config & CFG_STATIC_ESSID) &&
  7277. !(priv->status & (STATUS_ASSOCIATED |
  7278. STATUS_ASSOCIATING))) {
  7279. IPW_DEBUG_ASSOC("Attempting to associate with new "
  7280. "parameters.\n");
  7281. priv->config &= ~CFG_STATIC_ESSID;
  7282. ipw_associate(priv);
  7283. }
  7284. up(&priv->sem);
  7285. return 0;
  7286. }
  7287. length = min(length, IW_ESSID_MAX_SIZE);
  7288. priv->config |= CFG_STATIC_ESSID;
  7289. if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
  7290. IPW_DEBUG_WX("ESSID set to current ESSID.\n");
  7291. up(&priv->sem);
  7292. return 0;
  7293. }
  7294. IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
  7295. length);
  7296. priv->essid_len = length;
  7297. memcpy(priv->essid, essid, priv->essid_len);
  7298. /* Network configuration changed -- force [re]association */
  7299. IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
  7300. if (!ipw_disassociate(priv))
  7301. ipw_associate(priv);
  7302. up(&priv->sem);
  7303. return 0;
  7304. }
  7305. static int ipw_wx_get_essid(struct net_device *dev,
  7306. struct iw_request_info *info,
  7307. union iwreq_data *wrqu, char *extra)
  7308. {
  7309. struct ipw_priv *priv = ieee80211_priv(dev);
  7310. /* If we are associated, trying to associate, or have a statically
  7311. * configured ESSID then return that; otherwise return ANY */
  7312. down(&priv->sem);
  7313. if (priv->config & CFG_STATIC_ESSID ||
  7314. priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
  7315. IPW_DEBUG_WX("Getting essid: '%s'\n",
  7316. escape_essid(priv->essid, priv->essid_len));
  7317. memcpy(extra, priv->essid, priv->essid_len);
  7318. wrqu->essid.length = priv->essid_len;
  7319. wrqu->essid.flags = 1; /* active */
  7320. } else {
  7321. IPW_DEBUG_WX("Getting essid: ANY\n");
  7322. wrqu->essid.length = 0;
  7323. wrqu->essid.flags = 0; /* active */
  7324. }
  7325. up(&priv->sem);
  7326. return 0;
  7327. }
  7328. static int ipw_wx_set_nick(struct net_device *dev,
  7329. struct iw_request_info *info,
  7330. union iwreq_data *wrqu, char *extra)
  7331. {
  7332. struct ipw_priv *priv = ieee80211_priv(dev);
  7333. IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
  7334. if (wrqu->data.length > IW_ESSID_MAX_SIZE)
  7335. return -E2BIG;
  7336. down(&priv->sem);
  7337. wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
  7338. memset(priv->nick, 0, sizeof(priv->nick));
  7339. memcpy(priv->nick, extra, wrqu->data.length);
  7340. IPW_DEBUG_TRACE("<<\n");
  7341. up(&priv->sem);
  7342. return 0;
  7343. }
  7344. static int ipw_wx_get_nick(struct net_device *dev,
  7345. struct iw_request_info *info,
  7346. union iwreq_data *wrqu, char *extra)
  7347. {
  7348. struct ipw_priv *priv = ieee80211_priv(dev);
  7349. IPW_DEBUG_WX("Getting nick\n");
  7350. down(&priv->sem);
  7351. wrqu->data.length = strlen(priv->nick) + 1;
  7352. memcpy(extra, priv->nick, wrqu->data.length);
  7353. wrqu->data.flags = 1; /* active */
  7354. up(&priv->sem);
  7355. return 0;
  7356. }
  7357. static int ipw_wx_set_rate(struct net_device *dev,
  7358. struct iw_request_info *info,
  7359. union iwreq_data *wrqu, char *extra)
  7360. {
  7361. /* TODO: We should use semaphores or locks for access to priv */
  7362. struct ipw_priv *priv = ieee80211_priv(dev);
  7363. u32 target_rate = wrqu->bitrate.value;
  7364. u32 fixed, mask;
  7365. /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
  7366. /* value = X, fixed = 1 means only rate X */
  7367. /* value = X, fixed = 0 means all rates lower equal X */
  7368. if (target_rate == -1) {
  7369. fixed = 0;
  7370. mask = IEEE80211_DEFAULT_RATES_MASK;
  7371. /* Now we should reassociate */
  7372. goto apply;
  7373. }
  7374. mask = 0;
  7375. fixed = wrqu->bitrate.fixed;
  7376. if (target_rate == 1000000 || !fixed)
  7377. mask |= IEEE80211_CCK_RATE_1MB_MASK;
  7378. if (target_rate == 1000000)
  7379. goto apply;
  7380. if (target_rate == 2000000 || !fixed)
  7381. mask |= IEEE80211_CCK_RATE_2MB_MASK;
  7382. if (target_rate == 2000000)
  7383. goto apply;
  7384. if (target_rate == 5500000 || !fixed)
  7385. mask |= IEEE80211_CCK_RATE_5MB_MASK;
  7386. if (target_rate == 5500000)
  7387. goto apply;
  7388. if (target_rate == 6000000 || !fixed)
  7389. mask |= IEEE80211_OFDM_RATE_6MB_MASK;
  7390. if (target_rate == 6000000)
  7391. goto apply;
  7392. if (target_rate == 9000000 || !fixed)
  7393. mask |= IEEE80211_OFDM_RATE_9MB_MASK;
  7394. if (target_rate == 9000000)
  7395. goto apply;
  7396. if (target_rate == 11000000 || !fixed)
  7397. mask |= IEEE80211_CCK_RATE_11MB_MASK;
  7398. if (target_rate == 11000000)
  7399. goto apply;
  7400. if (target_rate == 12000000 || !fixed)
  7401. mask |= IEEE80211_OFDM_RATE_12MB_MASK;
  7402. if (target_rate == 12000000)
  7403. goto apply;
  7404. if (target_rate == 18000000 || !fixed)
  7405. mask |= IEEE80211_OFDM_RATE_18MB_MASK;
  7406. if (target_rate == 18000000)
  7407. goto apply;
  7408. if (target_rate == 24000000 || !fixed)
  7409. mask |= IEEE80211_OFDM_RATE_24MB_MASK;
  7410. if (target_rate == 24000000)
  7411. goto apply;
  7412. if (target_rate == 36000000 || !fixed)
  7413. mask |= IEEE80211_OFDM_RATE_36MB_MASK;
  7414. if (target_rate == 36000000)
  7415. goto apply;
  7416. if (target_rate == 48000000 || !fixed)
  7417. mask |= IEEE80211_OFDM_RATE_48MB_MASK;
  7418. if (target_rate == 48000000)
  7419. goto apply;
  7420. if (target_rate == 54000000 || !fixed)
  7421. mask |= IEEE80211_OFDM_RATE_54MB_MASK;
  7422. if (target_rate == 54000000)
  7423. goto apply;
  7424. IPW_DEBUG_WX("invalid rate specified, returning error\n");
  7425. return -EINVAL;
  7426. apply:
  7427. IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
  7428. mask, fixed ? "fixed" : "sub-rates");
  7429. down(&priv->sem);
  7430. if (mask == IEEE80211_DEFAULT_RATES_MASK) {
  7431. priv->config &= ~CFG_FIXED_RATE;
  7432. ipw_set_fixed_rate(priv, priv->ieee->mode);
  7433. } else
  7434. priv->config |= CFG_FIXED_RATE;
  7435. if (priv->rates_mask == mask) {
  7436. IPW_DEBUG_WX("Mask set to current mask.\n");
  7437. up(&priv->sem);
  7438. return 0;
  7439. }
  7440. priv->rates_mask = mask;
  7441. /* Network configuration changed -- force [re]association */
  7442. IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
  7443. if (!ipw_disassociate(priv))
  7444. ipw_associate(priv);
  7445. up(&priv->sem);
  7446. return 0;
  7447. }
  7448. static int ipw_wx_get_rate(struct net_device *dev,
  7449. struct iw_request_info *info,
  7450. union iwreq_data *wrqu, char *extra)
  7451. {
  7452. struct ipw_priv *priv = ieee80211_priv(dev);
  7453. down(&priv->sem);
  7454. wrqu->bitrate.value = priv->last_rate;
  7455. up(&priv->sem);
  7456. IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
  7457. return 0;
  7458. }
  7459. static int ipw_wx_set_rts(struct net_device *dev,
  7460. struct iw_request_info *info,
  7461. union iwreq_data *wrqu, char *extra)
  7462. {
  7463. struct ipw_priv *priv = ieee80211_priv(dev);
  7464. down(&priv->sem);
  7465. if (wrqu->rts.disabled)
  7466. priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
  7467. else {
  7468. if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
  7469. wrqu->rts.value > MAX_RTS_THRESHOLD) {
  7470. up(&priv->sem);
  7471. return -EINVAL;
  7472. }
  7473. priv->rts_threshold = wrqu->rts.value;
  7474. }
  7475. ipw_send_rts_threshold(priv, priv->rts_threshold);
  7476. up(&priv->sem);
  7477. IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
  7478. return 0;
  7479. }
  7480. static int ipw_wx_get_rts(struct net_device *dev,
  7481. struct iw_request_info *info,
  7482. union iwreq_data *wrqu, char *extra)
  7483. {
  7484. struct ipw_priv *priv = ieee80211_priv(dev);
  7485. down(&priv->sem);
  7486. wrqu->rts.value = priv->rts_threshold;
  7487. wrqu->rts.fixed = 0; /* no auto select */
  7488. wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
  7489. up(&priv->sem);
  7490. IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
  7491. return 0;
  7492. }
  7493. static int ipw_wx_set_txpow(struct net_device *dev,
  7494. struct iw_request_info *info,
  7495. union iwreq_data *wrqu, char *extra)
  7496. {
  7497. struct ipw_priv *priv = ieee80211_priv(dev);
  7498. const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
  7499. struct ipw_tx_power tx_power;
  7500. int i;
  7501. down(&priv->sem);
  7502. if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
  7503. up(&priv->sem);
  7504. return -EINPROGRESS;
  7505. }
  7506. if (!wrqu->power.fixed)
  7507. wrqu->power.value = IPW_TX_POWER_DEFAULT;
  7508. if (wrqu->power.flags != IW_TXPOW_DBM) {
  7509. up(&priv->sem);
  7510. return -EINVAL;
  7511. }
  7512. if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
  7513. (wrqu->power.value < IPW_TX_POWER_MIN)) {
  7514. up(&priv->sem);
  7515. return -EINVAL;
  7516. }
  7517. priv->tx_power = wrqu->power.value;
  7518. memset(&tx_power, 0, sizeof(tx_power));
  7519. /* configure device for 'G' band */
  7520. tx_power.ieee_mode = IPW_G_MODE;
  7521. tx_power.num_channels = geo->bg_channels;
  7522. for (i = 0; i < geo->bg_channels; i++) {
  7523. int max_power = geo->bg[i].max_power;
  7524. tx_power.channels_tx_power[i].channel_number = i + 1;
  7525. if (max_power != 0 && priv->tx_power > max_power)
  7526. tx_power.channels_tx_power[i].tx_power = max_power;
  7527. else
  7528. tx_power.channels_tx_power[i].tx_power = priv->tx_power;
  7529. }
  7530. if (ipw_send_tx_power(priv, &tx_power))
  7531. goto error;
  7532. /* configure device to also handle 'B' band */
  7533. tx_power.ieee_mode = IPW_B_MODE;
  7534. if (ipw_send_tx_power(priv, &tx_power))
  7535. goto error;
  7536. /* configure device to also handle 'A' band */
  7537. if (priv->ieee->abg_true) {
  7538. tx_power.ieee_mode = IPW_A_MODE;
  7539. tx_power.num_channels = geo->a_channels;
  7540. for (i = 0; i < geo->a_channels; i++) {
  7541. int max_power = geo->a[i].max_power;
  7542. tx_power.channels_tx_power[i].channel_number = i + 1;
  7543. if (max_power != 0 && priv->tx_power > max_power)
  7544. tx_power.channels_tx_power[i].tx_power =
  7545. max_power;
  7546. else
  7547. tx_power.channels_tx_power[i].tx_power =
  7548. priv->tx_power;
  7549. }
  7550. if (ipw_send_tx_power(priv, &tx_power))
  7551. goto error;
  7552. }
  7553. up(&priv->sem);
  7554. return 0;
  7555. error:
  7556. up(&priv->sem);
  7557. return -EIO;
  7558. }
  7559. static int ipw_wx_get_txpow(struct net_device *dev,
  7560. struct iw_request_info *info,
  7561. union iwreq_data *wrqu, char *extra)
  7562. {
  7563. struct ipw_priv *priv = ieee80211_priv(dev);
  7564. down(&priv->sem);
  7565. wrqu->power.value = priv->tx_power;
  7566. wrqu->power.fixed = 1;
  7567. wrqu->power.flags = IW_TXPOW_DBM;
  7568. wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
  7569. up(&priv->sem);
  7570. IPW_DEBUG_WX("GET TX Power -> %s %d \n",
  7571. wrqu->power.disabled ? "ON" : "OFF", wrqu->power.value);
  7572. return 0;
  7573. }
  7574. static int ipw_wx_set_frag(struct net_device *dev,
  7575. struct iw_request_info *info,
  7576. union iwreq_data *wrqu, char *extra)
  7577. {
  7578. struct ipw_priv *priv = ieee80211_priv(dev);
  7579. down(&priv->sem);
  7580. if (wrqu->frag.disabled)
  7581. priv->ieee->fts = DEFAULT_FTS;
  7582. else {
  7583. if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
  7584. wrqu->frag.value > MAX_FRAG_THRESHOLD) {
  7585. up(&priv->sem);
  7586. return -EINVAL;
  7587. }
  7588. priv->ieee->fts = wrqu->frag.value & ~0x1;
  7589. }
  7590. ipw_send_frag_threshold(priv, wrqu->frag.value);
  7591. up(&priv->sem);
  7592. IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
  7593. return 0;
  7594. }
  7595. static int ipw_wx_get_frag(struct net_device *dev,
  7596. struct iw_request_info *info,
  7597. union iwreq_data *wrqu, char *extra)
  7598. {
  7599. struct ipw_priv *priv = ieee80211_priv(dev);
  7600. down(&priv->sem);
  7601. wrqu->frag.value = priv->ieee->fts;
  7602. wrqu->frag.fixed = 0; /* no auto select */
  7603. wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
  7604. up(&priv->sem);
  7605. IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
  7606. return 0;
  7607. }
  7608. static int ipw_wx_set_retry(struct net_device *dev,
  7609. struct iw_request_info *info,
  7610. union iwreq_data *wrqu, char *extra)
  7611. {
  7612. struct ipw_priv *priv = ieee80211_priv(dev);
  7613. if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
  7614. return -EINVAL;
  7615. if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
  7616. return 0;
  7617. if (wrqu->retry.value < 0 || wrqu->retry.value > 255)
  7618. return -EINVAL;
  7619. down(&priv->sem);
  7620. if (wrqu->retry.flags & IW_RETRY_MIN)
  7621. priv->short_retry_limit = (u8) wrqu->retry.value;
  7622. else if (wrqu->retry.flags & IW_RETRY_MAX)
  7623. priv->long_retry_limit = (u8) wrqu->retry.value;
  7624. else {
  7625. priv->short_retry_limit = (u8) wrqu->retry.value;
  7626. priv->long_retry_limit = (u8) wrqu->retry.value;
  7627. }
  7628. ipw_send_retry_limit(priv, priv->short_retry_limit,
  7629. priv->long_retry_limit);
  7630. up(&priv->sem);
  7631. IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
  7632. priv->short_retry_limit, priv->long_retry_limit);
  7633. return 0;
  7634. }
  7635. static int ipw_wx_get_retry(struct net_device *dev,
  7636. struct iw_request_info *info,
  7637. union iwreq_data *wrqu, char *extra)
  7638. {
  7639. struct ipw_priv *priv = ieee80211_priv(dev);
  7640. down(&priv->sem);
  7641. wrqu->retry.disabled = 0;
  7642. if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
  7643. up(&priv->sem);
  7644. return -EINVAL;
  7645. }
  7646. if (wrqu->retry.flags & IW_RETRY_MAX) {
  7647. wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
  7648. wrqu->retry.value = priv->long_retry_limit;
  7649. } else if (wrqu->retry.flags & IW_RETRY_MIN) {
  7650. wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
  7651. wrqu->retry.value = priv->short_retry_limit;
  7652. } else {
  7653. wrqu->retry.flags = IW_RETRY_LIMIT;
  7654. wrqu->retry.value = priv->short_retry_limit;
  7655. }
  7656. up(&priv->sem);
  7657. IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
  7658. return 0;
  7659. }
  7660. #if WIRELESS_EXT > 17
  7661. static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid,
  7662. int essid_len)
  7663. {
  7664. struct ipw_scan_request_ext scan;
  7665. int err = 0, scan_type;
  7666. down(&priv->sem);
  7667. if (priv->status & STATUS_RF_KILL_MASK) {
  7668. IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
  7669. priv->status |= STATUS_SCAN_PENDING;
  7670. goto done;
  7671. }
  7672. IPW_DEBUG_HC("starting request direct scan!\n");
  7673. if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
  7674. err = wait_event_interruptible(priv->wait_state,
  7675. !(priv->
  7676. status & (STATUS_SCANNING |
  7677. STATUS_SCAN_ABORTING)));
  7678. if (err) {
  7679. IPW_DEBUG_HC("aborting direct scan");
  7680. goto done;
  7681. }
  7682. }
  7683. memset(&scan, 0, sizeof(scan));
  7684. if (priv->config & CFG_SPEED_SCAN)
  7685. scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
  7686. cpu_to_le16(30);
  7687. else
  7688. scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
  7689. cpu_to_le16(20);
  7690. scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
  7691. cpu_to_le16(20);
  7692. scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(20);
  7693. scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
  7694. scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
  7695. err = ipw_send_ssid(priv, essid, essid_len);
  7696. if (err) {
  7697. IPW_DEBUG_HC("Attempt to send SSID command failed\n");
  7698. goto done;
  7699. }
  7700. scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
  7701. ipw_add_scan_channels(priv, &scan, scan_type);
  7702. err = ipw_send_scan_request_ext(priv, &scan);
  7703. if (err) {
  7704. IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
  7705. goto done;
  7706. }
  7707. priv->status |= STATUS_SCANNING;
  7708. done:
  7709. up(&priv->sem);
  7710. return err;
  7711. }
  7712. #endif /* WIRELESS_EXT > 17 */
  7713. static int ipw_wx_set_scan(struct net_device *dev,
  7714. struct iw_request_info *info,
  7715. union iwreq_data *wrqu, char *extra)
  7716. {
  7717. struct ipw_priv *priv = ieee80211_priv(dev);
  7718. #if WIRELESS_EXT > 17
  7719. struct iw_scan_req *req = NULL;
  7720. if (wrqu->data.length
  7721. && wrqu->data.length == sizeof(struct iw_scan_req)) {
  7722. req = (struct iw_scan_req *)extra;
  7723. if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
  7724. ipw_request_direct_scan(priv, req->essid,
  7725. req->essid_len);
  7726. return 0;
  7727. }
  7728. }
  7729. #endif
  7730. IPW_DEBUG_WX("Start scan\n");
  7731. queue_work(priv->workqueue, &priv->request_scan);
  7732. return 0;
  7733. }
  7734. static int ipw_wx_get_scan(struct net_device *dev,
  7735. struct iw_request_info *info,
  7736. union iwreq_data *wrqu, char *extra)
  7737. {
  7738. struct ipw_priv *priv = ieee80211_priv(dev);
  7739. return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
  7740. }
  7741. static int ipw_wx_set_encode(struct net_device *dev,
  7742. struct iw_request_info *info,
  7743. union iwreq_data *wrqu, char *key)
  7744. {
  7745. struct ipw_priv *priv = ieee80211_priv(dev);
  7746. int ret;
  7747. u32 cap = priv->capability;
  7748. down(&priv->sem);
  7749. ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
  7750. /* In IBSS mode, we need to notify the firmware to update
  7751. * the beacon info after we changed the capability. */
  7752. if (cap != priv->capability &&
  7753. priv->ieee->iw_mode == IW_MODE_ADHOC &&
  7754. priv->status & STATUS_ASSOCIATED)
  7755. ipw_disassociate(priv);
  7756. up(&priv->sem);
  7757. return ret;
  7758. }
  7759. static int ipw_wx_get_encode(struct net_device *dev,
  7760. struct iw_request_info *info,
  7761. union iwreq_data *wrqu, char *key)
  7762. {
  7763. struct ipw_priv *priv = ieee80211_priv(dev);
  7764. return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
  7765. }
  7766. static int ipw_wx_set_power(struct net_device *dev,
  7767. struct iw_request_info *info,
  7768. union iwreq_data *wrqu, char *extra)
  7769. {
  7770. struct ipw_priv *priv = ieee80211_priv(dev);
  7771. int err;
  7772. down(&priv->sem);
  7773. if (wrqu->power.disabled) {
  7774. priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
  7775. err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
  7776. if (err) {
  7777. IPW_DEBUG_WX("failed setting power mode.\n");
  7778. up(&priv->sem);
  7779. return err;
  7780. }
  7781. IPW_DEBUG_WX("SET Power Management Mode -> off\n");
  7782. up(&priv->sem);
  7783. return 0;
  7784. }
  7785. switch (wrqu->power.flags & IW_POWER_MODE) {
  7786. case IW_POWER_ON: /* If not specified */
  7787. case IW_POWER_MODE: /* If set all mask */
  7788. case IW_POWER_ALL_R: /* If explicitely state all */
  7789. break;
  7790. default: /* Otherwise we don't support it */
  7791. IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
  7792. wrqu->power.flags);
  7793. up(&priv->sem);
  7794. return -EOPNOTSUPP;
  7795. }
  7796. /* If the user hasn't specified a power management mode yet, default
  7797. * to BATTERY */
  7798. if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
  7799. priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
  7800. else
  7801. priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
  7802. err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
  7803. if (err) {
  7804. IPW_DEBUG_WX("failed setting power mode.\n");
  7805. up(&priv->sem);
  7806. return err;
  7807. }
  7808. IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
  7809. up(&priv->sem);
  7810. return 0;
  7811. }
  7812. static int ipw_wx_get_power(struct net_device *dev,
  7813. struct iw_request_info *info,
  7814. union iwreq_data *wrqu, char *extra)
  7815. {
  7816. struct ipw_priv *priv = ieee80211_priv(dev);
  7817. down(&priv->sem);
  7818. if (!(priv->power_mode & IPW_POWER_ENABLED))
  7819. wrqu->power.disabled = 1;
  7820. else
  7821. wrqu->power.disabled = 0;
  7822. up(&priv->sem);
  7823. IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
  7824. return 0;
  7825. }
  7826. static int ipw_wx_set_powermode(struct net_device *dev,
  7827. struct iw_request_info *info,
  7828. union iwreq_data *wrqu, char *extra)
  7829. {
  7830. struct ipw_priv *priv = ieee80211_priv(dev);
  7831. int mode = *(int *)extra;
  7832. int err;
  7833. down(&priv->sem);
  7834. if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
  7835. mode = IPW_POWER_AC;
  7836. priv->power_mode = mode;
  7837. } else {
  7838. priv->power_mode = IPW_POWER_ENABLED | mode;
  7839. }
  7840. if (priv->power_mode != mode) {
  7841. err = ipw_send_power_mode(priv, mode);
  7842. if (err) {
  7843. IPW_DEBUG_WX("failed setting power mode.\n");
  7844. up(&priv->sem);
  7845. return err;
  7846. }
  7847. }
  7848. up(&priv->sem);
  7849. return 0;
  7850. }
  7851. #define MAX_WX_STRING 80
  7852. static int ipw_wx_get_powermode(struct net_device *dev,
  7853. struct iw_request_info *info,
  7854. union iwreq_data *wrqu, char *extra)
  7855. {
  7856. struct ipw_priv *priv = ieee80211_priv(dev);
  7857. int level = IPW_POWER_LEVEL(priv->power_mode);
  7858. char *p = extra;
  7859. p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
  7860. switch (level) {
  7861. case IPW_POWER_AC:
  7862. p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
  7863. break;
  7864. case IPW_POWER_BATTERY:
  7865. p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
  7866. break;
  7867. default:
  7868. p += snprintf(p, MAX_WX_STRING - (p - extra),
  7869. "(Timeout %dms, Period %dms)",
  7870. timeout_duration[level - 1] / 1000,
  7871. period_duration[level - 1] / 1000);
  7872. }
  7873. if (!(priv->power_mode & IPW_POWER_ENABLED))
  7874. p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
  7875. wrqu->data.length = p - extra + 1;
  7876. return 0;
  7877. }
  7878. static int ipw_wx_set_wireless_mode(struct net_device *dev,
  7879. struct iw_request_info *info,
  7880. union iwreq_data *wrqu, char *extra)
  7881. {
  7882. struct ipw_priv *priv = ieee80211_priv(dev);
  7883. int mode = *(int *)extra;
  7884. u8 band = 0, modulation = 0;
  7885. if (mode == 0 || mode & ~IEEE_MODE_MASK) {
  7886. IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
  7887. return -EINVAL;
  7888. }
  7889. down(&priv->sem);
  7890. if (priv->adapter == IPW_2915ABG) {
  7891. priv->ieee->abg_true = 1;
  7892. if (mode & IEEE_A) {
  7893. band |= IEEE80211_52GHZ_BAND;
  7894. modulation |= IEEE80211_OFDM_MODULATION;
  7895. } else
  7896. priv->ieee->abg_true = 0;
  7897. } else {
  7898. if (mode & IEEE_A) {
  7899. IPW_WARNING("Attempt to set 2200BG into "
  7900. "802.11a mode\n");
  7901. up(&priv->sem);
  7902. return -EINVAL;
  7903. }
  7904. priv->ieee->abg_true = 0;
  7905. }
  7906. if (mode & IEEE_B) {
  7907. band |= IEEE80211_24GHZ_BAND;
  7908. modulation |= IEEE80211_CCK_MODULATION;
  7909. } else
  7910. priv->ieee->abg_true = 0;
  7911. if (mode & IEEE_G) {
  7912. band |= IEEE80211_24GHZ_BAND;
  7913. modulation |= IEEE80211_OFDM_MODULATION;
  7914. } else
  7915. priv->ieee->abg_true = 0;
  7916. priv->ieee->mode = mode;
  7917. priv->ieee->freq_band = band;
  7918. priv->ieee->modulation = modulation;
  7919. init_supported_rates(priv, &priv->rates);
  7920. /* Network configuration changed -- force [re]association */
  7921. IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
  7922. if (!ipw_disassociate(priv)) {
  7923. ipw_send_supported_rates(priv, &priv->rates);
  7924. ipw_associate(priv);
  7925. }
  7926. /* Update the band LEDs */
  7927. ipw_led_band_on(priv);
  7928. IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
  7929. mode & IEEE_A ? 'a' : '.',
  7930. mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
  7931. up(&priv->sem);
  7932. return 0;
  7933. }
  7934. static int ipw_wx_get_wireless_mode(struct net_device *dev,
  7935. struct iw_request_info *info,
  7936. union iwreq_data *wrqu, char *extra)
  7937. {
  7938. struct ipw_priv *priv = ieee80211_priv(dev);
  7939. down(&priv->sem);
  7940. switch (priv->ieee->mode) {
  7941. case IEEE_A:
  7942. strncpy(extra, "802.11a (1)", MAX_WX_STRING);
  7943. break;
  7944. case IEEE_B:
  7945. strncpy(extra, "802.11b (2)", MAX_WX_STRING);
  7946. break;
  7947. case IEEE_A | IEEE_B:
  7948. strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
  7949. break;
  7950. case IEEE_G:
  7951. strncpy(extra, "802.11g (4)", MAX_WX_STRING);
  7952. break;
  7953. case IEEE_A | IEEE_G:
  7954. strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
  7955. break;
  7956. case IEEE_B | IEEE_G:
  7957. strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
  7958. break;
  7959. case IEEE_A | IEEE_B | IEEE_G:
  7960. strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
  7961. break;
  7962. default:
  7963. strncpy(extra, "unknown", MAX_WX_STRING);
  7964. break;
  7965. }
  7966. IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
  7967. wrqu->data.length = strlen(extra) + 1;
  7968. up(&priv->sem);
  7969. return 0;
  7970. }
  7971. static int ipw_wx_set_preamble(struct net_device *dev,
  7972. struct iw_request_info *info,
  7973. union iwreq_data *wrqu, char *extra)
  7974. {
  7975. struct ipw_priv *priv = ieee80211_priv(dev);
  7976. int mode = *(int *)extra;
  7977. down(&priv->sem);
  7978. /* Switching from SHORT -> LONG requires a disassociation */
  7979. if (mode == 1) {
  7980. if (!(priv->config & CFG_PREAMBLE_LONG)) {
  7981. priv->config |= CFG_PREAMBLE_LONG;
  7982. /* Network configuration changed -- force [re]association */
  7983. IPW_DEBUG_ASSOC
  7984. ("[re]association triggered due to preamble change.\n");
  7985. if (!ipw_disassociate(priv))
  7986. ipw_associate(priv);
  7987. }
  7988. goto done;
  7989. }
  7990. if (mode == 0) {
  7991. priv->config &= ~CFG_PREAMBLE_LONG;
  7992. goto done;
  7993. }
  7994. up(&priv->sem);
  7995. return -EINVAL;
  7996. done:
  7997. up(&priv->sem);
  7998. return 0;
  7999. }
  8000. static int ipw_wx_get_preamble(struct net_device *dev,
  8001. struct iw_request_info *info,
  8002. union iwreq_data *wrqu, char *extra)
  8003. {
  8004. struct ipw_priv *priv = ieee80211_priv(dev);
  8005. down(&priv->sem);
  8006. if (priv->config & CFG_PREAMBLE_LONG)
  8007. snprintf(wrqu->name, IFNAMSIZ, "long (1)");
  8008. else
  8009. snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
  8010. up(&priv->sem);
  8011. return 0;
  8012. }
  8013. #ifdef CONFIG_IPW2200_MONITOR
  8014. static int ipw_wx_set_monitor(struct net_device *dev,
  8015. struct iw_request_info *info,
  8016. union iwreq_data *wrqu, char *extra)
  8017. {
  8018. struct ipw_priv *priv = ieee80211_priv(dev);
  8019. int *parms = (int *)extra;
  8020. int enable = (parms[0] > 0);
  8021. down(&priv->sem);
  8022. IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
  8023. if (enable) {
  8024. if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
  8025. priv->net_dev->type = ARPHRD_IEEE80211;
  8026. queue_work(priv->workqueue, &priv->adapter_restart);
  8027. }
  8028. ipw_set_channel(priv, parms[1]);
  8029. } else {
  8030. if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
  8031. up(&priv->sem);
  8032. return 0;
  8033. }
  8034. priv->net_dev->type = ARPHRD_ETHER;
  8035. queue_work(priv->workqueue, &priv->adapter_restart);
  8036. }
  8037. up(&priv->sem);
  8038. return 0;
  8039. }
  8040. #endif // CONFIG_IPW2200_MONITOR
  8041. static int ipw_wx_reset(struct net_device *dev,
  8042. struct iw_request_info *info,
  8043. union iwreq_data *wrqu, char *extra)
  8044. {
  8045. struct ipw_priv *priv = ieee80211_priv(dev);
  8046. IPW_DEBUG_WX("RESET\n");
  8047. queue_work(priv->workqueue, &priv->adapter_restart);
  8048. return 0;
  8049. }
  8050. static int ipw_wx_sw_reset(struct net_device *dev,
  8051. struct iw_request_info *info,
  8052. union iwreq_data *wrqu, char *extra)
  8053. {
  8054. struct ipw_priv *priv = ieee80211_priv(dev);
  8055. union iwreq_data wrqu_sec = {
  8056. .encoding = {
  8057. .flags = IW_ENCODE_DISABLED,
  8058. },
  8059. };
  8060. int ret;
  8061. IPW_DEBUG_WX("SW_RESET\n");
  8062. down(&priv->sem);
  8063. ret = ipw_sw_reset(priv, 0);
  8064. if (!ret) {
  8065. free_firmware();
  8066. ipw_adapter_restart(priv);
  8067. }
  8068. /* The SW reset bit might have been toggled on by the 'disable'
  8069. * module parameter, so take appropriate action */
  8070. ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
  8071. up(&priv->sem);
  8072. ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
  8073. down(&priv->sem);
  8074. if (!(priv->status & STATUS_RF_KILL_MASK)) {
  8075. /* Configuration likely changed -- force [re]association */
  8076. IPW_DEBUG_ASSOC("[re]association triggered due to sw "
  8077. "reset.\n");
  8078. if (!ipw_disassociate(priv))
  8079. ipw_associate(priv);
  8080. }
  8081. up(&priv->sem);
  8082. return 0;
  8083. }
  8084. /* Rebase the WE IOCTLs to zero for the handler array */
  8085. #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
  8086. static iw_handler ipw_wx_handlers[] = {
  8087. IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
  8088. IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
  8089. IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
  8090. IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
  8091. IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
  8092. IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
  8093. IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
  8094. IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
  8095. IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
  8096. IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
  8097. IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
  8098. IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
  8099. IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
  8100. IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
  8101. IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
  8102. IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
  8103. IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
  8104. IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
  8105. IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
  8106. IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
  8107. IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
  8108. IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
  8109. IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
  8110. IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
  8111. IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
  8112. IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
  8113. IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
  8114. IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
  8115. IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
  8116. IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
  8117. IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
  8118. IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
  8119. #if WIRELESS_EXT > 17
  8120. IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
  8121. IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
  8122. IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
  8123. IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
  8124. IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
  8125. IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
  8126. IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
  8127. #endif
  8128. };
  8129. enum {
  8130. IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
  8131. IPW_PRIV_GET_POWER,
  8132. IPW_PRIV_SET_MODE,
  8133. IPW_PRIV_GET_MODE,
  8134. IPW_PRIV_SET_PREAMBLE,
  8135. IPW_PRIV_GET_PREAMBLE,
  8136. IPW_PRIV_RESET,
  8137. IPW_PRIV_SW_RESET,
  8138. #ifdef CONFIG_IPW2200_MONITOR
  8139. IPW_PRIV_SET_MONITOR,
  8140. #endif
  8141. };
  8142. static struct iw_priv_args ipw_priv_args[] = {
  8143. {
  8144. .cmd = IPW_PRIV_SET_POWER,
  8145. .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  8146. .name = "set_power"},
  8147. {
  8148. .cmd = IPW_PRIV_GET_POWER,
  8149. .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
  8150. .name = "get_power"},
  8151. {
  8152. .cmd = IPW_PRIV_SET_MODE,
  8153. .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  8154. .name = "set_mode"},
  8155. {
  8156. .cmd = IPW_PRIV_GET_MODE,
  8157. .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
  8158. .name = "get_mode"},
  8159. {
  8160. .cmd = IPW_PRIV_SET_PREAMBLE,
  8161. .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  8162. .name = "set_preamble"},
  8163. {
  8164. .cmd = IPW_PRIV_GET_PREAMBLE,
  8165. .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
  8166. .name = "get_preamble"},
  8167. {
  8168. IPW_PRIV_RESET,
  8169. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
  8170. {
  8171. IPW_PRIV_SW_RESET,
  8172. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
  8173. #ifdef CONFIG_IPW2200_MONITOR
  8174. {
  8175. IPW_PRIV_SET_MONITOR,
  8176. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
  8177. #endif /* CONFIG_IPW2200_MONITOR */
  8178. };
  8179. static iw_handler ipw_priv_handler[] = {
  8180. ipw_wx_set_powermode,
  8181. ipw_wx_get_powermode,
  8182. ipw_wx_set_wireless_mode,
  8183. ipw_wx_get_wireless_mode,
  8184. ipw_wx_set_preamble,
  8185. ipw_wx_get_preamble,
  8186. ipw_wx_reset,
  8187. ipw_wx_sw_reset,
  8188. #ifdef CONFIG_IPW2200_MONITOR
  8189. ipw_wx_set_monitor,
  8190. #endif
  8191. };
  8192. static struct iw_handler_def ipw_wx_handler_def = {
  8193. .standard = ipw_wx_handlers,
  8194. .num_standard = ARRAY_SIZE(ipw_wx_handlers),
  8195. .num_private = ARRAY_SIZE(ipw_priv_handler),
  8196. .num_private_args = ARRAY_SIZE(ipw_priv_args),
  8197. .private = ipw_priv_handler,
  8198. .private_args = ipw_priv_args,
  8199. };
  8200. static struct iw_public_data ipw_wx_data;
  8201. /*
  8202. * Get wireless statistics.
  8203. * Called by /proc/net/wireless
  8204. * Also called by SIOCGIWSTATS
  8205. */
  8206. static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
  8207. {
  8208. struct ipw_priv *priv = ieee80211_priv(dev);
  8209. struct iw_statistics *wstats;
  8210. wstats = &priv->wstats;
  8211. /* if hw is disabled, then ipw_get_ordinal() can't be called.
  8212. * netdev->get_wireless_stats seems to be called before fw is
  8213. * initialized. STATUS_ASSOCIATED will only be set if the hw is up
  8214. * and associated; if not associcated, the values are all meaningless
  8215. * anyway, so set them all to NULL and INVALID */
  8216. if (!(priv->status & STATUS_ASSOCIATED)) {
  8217. wstats->miss.beacon = 0;
  8218. wstats->discard.retries = 0;
  8219. wstats->qual.qual = 0;
  8220. wstats->qual.level = 0;
  8221. wstats->qual.noise = 0;
  8222. wstats->qual.updated = 7;
  8223. wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
  8224. IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
  8225. return wstats;
  8226. }
  8227. wstats->qual.qual = priv->quality;
  8228. wstats->qual.level = average_value(&priv->average_rssi);
  8229. wstats->qual.noise = average_value(&priv->average_noise);
  8230. wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
  8231. IW_QUAL_NOISE_UPDATED;
  8232. wstats->miss.beacon = average_value(&priv->average_missed_beacons);
  8233. wstats->discard.retries = priv->last_tx_failures;
  8234. wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
  8235. /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
  8236. goto fail_get_ordinal;
  8237. wstats->discard.retries += tx_retry; */
  8238. return wstats;
  8239. }
  8240. /* net device stuff */
  8241. static inline void init_sys_config(struct ipw_sys_config *sys_config)
  8242. {
  8243. memset(sys_config, 0, sizeof(struct ipw_sys_config));
  8244. sys_config->bt_coexistence = 1; /* We may need to look into prvStaBtConfig */
  8245. sys_config->answer_broadcast_ssid_probe = 0;
  8246. sys_config->accept_all_data_frames = 0;
  8247. sys_config->accept_non_directed_frames = 1;
  8248. sys_config->exclude_unicast_unencrypted = 0;
  8249. sys_config->disable_unicast_decryption = 1;
  8250. sys_config->exclude_multicast_unencrypted = 0;
  8251. sys_config->disable_multicast_decryption = 1;
  8252. sys_config->antenna_diversity = CFG_SYS_ANTENNA_BOTH;
  8253. sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
  8254. sys_config->dot11g_auto_detection = 0;
  8255. sys_config->enable_cts_to_self = 0;
  8256. sys_config->bt_coexist_collision_thr = 0;
  8257. sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256
  8258. }
  8259. static int ipw_net_open(struct net_device *dev)
  8260. {
  8261. struct ipw_priv *priv = ieee80211_priv(dev);
  8262. IPW_DEBUG_INFO("dev->open\n");
  8263. /* we should be verifying the device is ready to be opened */
  8264. down(&priv->sem);
  8265. if (!(priv->status & STATUS_RF_KILL_MASK) &&
  8266. (priv->status & STATUS_ASSOCIATED))
  8267. netif_start_queue(dev);
  8268. up(&priv->sem);
  8269. return 0;
  8270. }
  8271. static int ipw_net_stop(struct net_device *dev)
  8272. {
  8273. IPW_DEBUG_INFO("dev->close\n");
  8274. netif_stop_queue(dev);
  8275. return 0;
  8276. }
  8277. /*
  8278. todo:
  8279. modify to send one tfd per fragment instead of using chunking. otherwise
  8280. we need to heavily modify the ieee80211_skb_to_txb.
  8281. */
  8282. static inline int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
  8283. int pri)
  8284. {
  8285. struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *)
  8286. txb->fragments[0]->data;
  8287. int i = 0;
  8288. struct tfd_frame *tfd;
  8289. #ifdef CONFIG_IPW_QOS
  8290. int tx_id = ipw_get_tx_queue_number(priv, pri);
  8291. struct clx2_tx_queue *txq = &priv->txq[tx_id];
  8292. #else
  8293. struct clx2_tx_queue *txq = &priv->txq[0];
  8294. #endif
  8295. struct clx2_queue *q = &txq->q;
  8296. u8 id, hdr_len, unicast;
  8297. u16 remaining_bytes;
  8298. int fc;
  8299. /* If there isn't room in the queue, we return busy and let the
  8300. * network stack requeue the packet for us */
  8301. if (ipw_queue_space(q) < q->high_mark)
  8302. return NETDEV_TX_BUSY;
  8303. switch (priv->ieee->iw_mode) {
  8304. case IW_MODE_ADHOC:
  8305. hdr_len = IEEE80211_3ADDR_LEN;
  8306. unicast = !is_multicast_ether_addr(hdr->addr1);
  8307. id = ipw_find_station(priv, hdr->addr1);
  8308. if (id == IPW_INVALID_STATION) {
  8309. id = ipw_add_station(priv, hdr->addr1);
  8310. if (id == IPW_INVALID_STATION) {
  8311. IPW_WARNING("Attempt to send data to "
  8312. "invalid cell: " MAC_FMT "\n",
  8313. MAC_ARG(hdr->addr1));
  8314. goto drop;
  8315. }
  8316. }
  8317. break;
  8318. case IW_MODE_INFRA:
  8319. default:
  8320. unicast = !is_multicast_ether_addr(hdr->addr3);
  8321. hdr_len = IEEE80211_3ADDR_LEN;
  8322. id = 0;
  8323. break;
  8324. }
  8325. tfd = &txq->bd[q->first_empty];
  8326. txq->txb[q->first_empty] = txb;
  8327. memset(tfd, 0, sizeof(*tfd));
  8328. tfd->u.data.station_number = id;
  8329. tfd->control_flags.message_type = TX_FRAME_TYPE;
  8330. tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
  8331. tfd->u.data.cmd_id = DINO_CMD_TX;
  8332. tfd->u.data.len = cpu_to_le16(txb->payload_size);
  8333. remaining_bytes = txb->payload_size;
  8334. if (priv->assoc_request.ieee_mode == IPW_B_MODE)
  8335. tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
  8336. else
  8337. tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
  8338. if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
  8339. tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
  8340. fc = le16_to_cpu(hdr->frame_ctl);
  8341. hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
  8342. memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
  8343. if (likely(unicast))
  8344. tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
  8345. if (txb->encrypted && !priv->ieee->host_encrypt) {
  8346. switch (priv->ieee->sec.level) {
  8347. case SEC_LEVEL_3:
  8348. tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
  8349. IEEE80211_FCTL_PROTECTED;
  8350. /* XXX: ACK flag must be set for CCMP even if it
  8351. * is a multicast/broadcast packet, because CCMP
  8352. * group communication encrypted by GTK is
  8353. * actually done by the AP. */
  8354. if (!unicast)
  8355. tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
  8356. tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
  8357. tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
  8358. tfd->u.data.key_index = 0;
  8359. tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
  8360. break;
  8361. case SEC_LEVEL_2:
  8362. tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
  8363. IEEE80211_FCTL_PROTECTED;
  8364. tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
  8365. tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
  8366. tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
  8367. break;
  8368. case SEC_LEVEL_1:
  8369. tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
  8370. IEEE80211_FCTL_PROTECTED;
  8371. tfd->u.data.key_index = priv->ieee->tx_keyidx;
  8372. if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
  8373. 40)
  8374. tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
  8375. else
  8376. tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
  8377. break;
  8378. case SEC_LEVEL_0:
  8379. break;
  8380. default:
  8381. printk(KERN_ERR "Unknow security level %d\n",
  8382. priv->ieee->sec.level);
  8383. break;
  8384. }
  8385. } else
  8386. /* No hardware encryption */
  8387. tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
  8388. #ifdef CONFIG_IPW_QOS
  8389. ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data), unicast);
  8390. #endif /* CONFIG_IPW_QOS */
  8391. /* payload */
  8392. tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
  8393. txb->nr_frags));
  8394. IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
  8395. txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
  8396. for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
  8397. IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
  8398. i, le32_to_cpu(tfd->u.data.num_chunks),
  8399. txb->fragments[i]->len - hdr_len);
  8400. IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
  8401. i, tfd->u.data.num_chunks,
  8402. txb->fragments[i]->len - hdr_len);
  8403. printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
  8404. txb->fragments[i]->len - hdr_len);
  8405. tfd->u.data.chunk_ptr[i] =
  8406. cpu_to_le32(pci_map_single
  8407. (priv->pci_dev,
  8408. txb->fragments[i]->data + hdr_len,
  8409. txb->fragments[i]->len - hdr_len,
  8410. PCI_DMA_TODEVICE));
  8411. tfd->u.data.chunk_len[i] =
  8412. cpu_to_le16(txb->fragments[i]->len - hdr_len);
  8413. }
  8414. if (i != txb->nr_frags) {
  8415. struct sk_buff *skb;
  8416. u16 remaining_bytes = 0;
  8417. int j;
  8418. for (j = i; j < txb->nr_frags; j++)
  8419. remaining_bytes += txb->fragments[j]->len - hdr_len;
  8420. printk(KERN_INFO "Trying to reallocate for %d bytes\n",
  8421. remaining_bytes);
  8422. skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
  8423. if (skb != NULL) {
  8424. tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
  8425. for (j = i; j < txb->nr_frags; j++) {
  8426. int size = txb->fragments[j]->len - hdr_len;
  8427. printk(KERN_INFO "Adding frag %d %d...\n",
  8428. j, size);
  8429. memcpy(skb_put(skb, size),
  8430. txb->fragments[j]->data + hdr_len, size);
  8431. }
  8432. dev_kfree_skb_any(txb->fragments[i]);
  8433. txb->fragments[i] = skb;
  8434. tfd->u.data.chunk_ptr[i] =
  8435. cpu_to_le32(pci_map_single
  8436. (priv->pci_dev, skb->data,
  8437. tfd->u.data.chunk_len[i],
  8438. PCI_DMA_TODEVICE));
  8439. tfd->u.data.num_chunks =
  8440. cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
  8441. 1);
  8442. }
  8443. }
  8444. /* kick DMA */
  8445. q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
  8446. ipw_write32(priv, q->reg_w, q->first_empty);
  8447. return NETDEV_TX_OK;
  8448. drop:
  8449. IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
  8450. ieee80211_txb_free(txb);
  8451. return NETDEV_TX_OK;
  8452. }
  8453. static int ipw_net_is_queue_full(struct net_device *dev, int pri)
  8454. {
  8455. struct ipw_priv *priv = ieee80211_priv(dev);
  8456. #ifdef CONFIG_IPW_QOS
  8457. int tx_id = ipw_get_tx_queue_number(priv, pri);
  8458. struct clx2_tx_queue *txq = &priv->txq[tx_id];
  8459. #else
  8460. struct clx2_tx_queue *txq = &priv->txq[0];
  8461. #endif /* CONFIG_IPW_QOS */
  8462. if (ipw_queue_space(&txq->q) < txq->q.high_mark)
  8463. return 1;
  8464. return 0;
  8465. }
  8466. static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
  8467. struct net_device *dev, int pri)
  8468. {
  8469. struct ipw_priv *priv = ieee80211_priv(dev);
  8470. unsigned long flags;
  8471. int ret;
  8472. IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
  8473. spin_lock_irqsave(&priv->lock, flags);
  8474. if (!(priv->status & STATUS_ASSOCIATED)) {
  8475. IPW_DEBUG_INFO("Tx attempt while not associated.\n");
  8476. priv->ieee->stats.tx_carrier_errors++;
  8477. netif_stop_queue(dev);
  8478. goto fail_unlock;
  8479. }
  8480. ret = ipw_tx_skb(priv, txb, pri);
  8481. if (ret == NETDEV_TX_OK)
  8482. __ipw_led_activity_on(priv);
  8483. spin_unlock_irqrestore(&priv->lock, flags);
  8484. return ret;
  8485. fail_unlock:
  8486. spin_unlock_irqrestore(&priv->lock, flags);
  8487. return 1;
  8488. }
  8489. static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
  8490. {
  8491. struct ipw_priv *priv = ieee80211_priv(dev);
  8492. priv->ieee->stats.tx_packets = priv->tx_packets;
  8493. priv->ieee->stats.rx_packets = priv->rx_packets;
  8494. return &priv->ieee->stats;
  8495. }
  8496. static void ipw_net_set_multicast_list(struct net_device *dev)
  8497. {
  8498. }
  8499. static int ipw_net_set_mac_address(struct net_device *dev, void *p)
  8500. {
  8501. struct ipw_priv *priv = ieee80211_priv(dev);
  8502. struct sockaddr *addr = p;
  8503. if (!is_valid_ether_addr(addr->sa_data))
  8504. return -EADDRNOTAVAIL;
  8505. down(&priv->sem);
  8506. priv->config |= CFG_CUSTOM_MAC;
  8507. memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
  8508. printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
  8509. priv->net_dev->name, MAC_ARG(priv->mac_addr));
  8510. queue_work(priv->workqueue, &priv->adapter_restart);
  8511. up(&priv->sem);
  8512. return 0;
  8513. }
  8514. static void ipw_ethtool_get_drvinfo(struct net_device *dev,
  8515. struct ethtool_drvinfo *info)
  8516. {
  8517. struct ipw_priv *p = ieee80211_priv(dev);
  8518. char vers[64];
  8519. char date[32];
  8520. u32 len;
  8521. strcpy(info->driver, DRV_NAME);
  8522. strcpy(info->version, DRV_VERSION);
  8523. len = sizeof(vers);
  8524. ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
  8525. len = sizeof(date);
  8526. ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
  8527. snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
  8528. vers, date);
  8529. strcpy(info->bus_info, pci_name(p->pci_dev));
  8530. info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
  8531. }
  8532. static u32 ipw_ethtool_get_link(struct net_device *dev)
  8533. {
  8534. struct ipw_priv *priv = ieee80211_priv(dev);
  8535. return (priv->status & STATUS_ASSOCIATED) != 0;
  8536. }
  8537. static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
  8538. {
  8539. return IPW_EEPROM_IMAGE_SIZE;
  8540. }
  8541. static int ipw_ethtool_get_eeprom(struct net_device *dev,
  8542. struct ethtool_eeprom *eeprom, u8 * bytes)
  8543. {
  8544. struct ipw_priv *p = ieee80211_priv(dev);
  8545. if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
  8546. return -EINVAL;
  8547. down(&p->sem);
  8548. memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
  8549. up(&p->sem);
  8550. return 0;
  8551. }
  8552. static int ipw_ethtool_set_eeprom(struct net_device *dev,
  8553. struct ethtool_eeprom *eeprom, u8 * bytes)
  8554. {
  8555. struct ipw_priv *p = ieee80211_priv(dev);
  8556. int i;
  8557. if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
  8558. return -EINVAL;
  8559. down(&p->sem);
  8560. memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
  8561. for (i = IPW_EEPROM_DATA;
  8562. i < IPW_EEPROM_DATA + IPW_EEPROM_IMAGE_SIZE; i++)
  8563. ipw_write8(p, i, p->eeprom[i]);
  8564. up(&p->sem);
  8565. return 0;
  8566. }
  8567. static struct ethtool_ops ipw_ethtool_ops = {
  8568. .get_link = ipw_ethtool_get_link,
  8569. .get_drvinfo = ipw_ethtool_get_drvinfo,
  8570. .get_eeprom_len = ipw_ethtool_get_eeprom_len,
  8571. .get_eeprom = ipw_ethtool_get_eeprom,
  8572. .set_eeprom = ipw_ethtool_set_eeprom,
  8573. };
  8574. static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
  8575. {
  8576. struct ipw_priv *priv = data;
  8577. u32 inta, inta_mask;
  8578. if (!priv)
  8579. return IRQ_NONE;
  8580. spin_lock(&priv->lock);
  8581. if (!(priv->status & STATUS_INT_ENABLED)) {
  8582. /* Shared IRQ */
  8583. goto none;
  8584. }
  8585. inta = ipw_read32(priv, IPW_INTA_RW);
  8586. inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
  8587. if (inta == 0xFFFFFFFF) {
  8588. /* Hardware disappeared */
  8589. IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
  8590. goto none;
  8591. }
  8592. if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
  8593. /* Shared interrupt */
  8594. goto none;
  8595. }
  8596. /* tell the device to stop sending interrupts */
  8597. ipw_disable_interrupts(priv);
  8598. /* ack current interrupts */
  8599. inta &= (IPW_INTA_MASK_ALL & inta_mask);
  8600. ipw_write32(priv, IPW_INTA_RW, inta);
  8601. /* Cache INTA value for our tasklet */
  8602. priv->isr_inta = inta;
  8603. tasklet_schedule(&priv->irq_tasklet);
  8604. spin_unlock(&priv->lock);
  8605. return IRQ_HANDLED;
  8606. none:
  8607. spin_unlock(&priv->lock);
  8608. return IRQ_NONE;
  8609. }
  8610. static void ipw_rf_kill(void *adapter)
  8611. {
  8612. struct ipw_priv *priv = adapter;
  8613. unsigned long flags;
  8614. spin_lock_irqsave(&priv->lock, flags);
  8615. if (rf_kill_active(priv)) {
  8616. IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
  8617. if (priv->workqueue)
  8618. queue_delayed_work(priv->workqueue,
  8619. &priv->rf_kill, 2 * HZ);
  8620. goto exit_unlock;
  8621. }
  8622. /* RF Kill is now disabled, so bring the device back up */
  8623. if (!(priv->status & STATUS_RF_KILL_MASK)) {
  8624. IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
  8625. "device\n");
  8626. /* we can not do an adapter restart while inside an irq lock */
  8627. queue_work(priv->workqueue, &priv->adapter_restart);
  8628. } else
  8629. IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
  8630. "enabled\n");
  8631. exit_unlock:
  8632. spin_unlock_irqrestore(&priv->lock, flags);
  8633. }
  8634. static void ipw_bg_rf_kill(void *data)
  8635. {
  8636. struct ipw_priv *priv = data;
  8637. down(&priv->sem);
  8638. ipw_rf_kill(data);
  8639. up(&priv->sem);
  8640. }
  8641. void ipw_link_up(struct ipw_priv *priv)
  8642. {
  8643. priv->last_seq_num = -1;
  8644. priv->last_frag_num = -1;
  8645. priv->last_packet_time = 0;
  8646. netif_carrier_on(priv->net_dev);
  8647. if (netif_queue_stopped(priv->net_dev)) {
  8648. IPW_DEBUG_NOTIF("waking queue\n");
  8649. netif_wake_queue(priv->net_dev);
  8650. } else {
  8651. IPW_DEBUG_NOTIF("starting queue\n");
  8652. netif_start_queue(priv->net_dev);
  8653. }
  8654. cancel_delayed_work(&priv->request_scan);
  8655. ipw_reset_stats(priv);
  8656. /* Ensure the rate is updated immediately */
  8657. priv->last_rate = ipw_get_current_rate(priv);
  8658. ipw_gather_stats(priv);
  8659. ipw_led_link_up(priv);
  8660. notify_wx_assoc_event(priv);
  8661. if (priv->config & CFG_BACKGROUND_SCAN)
  8662. queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
  8663. }
  8664. static void ipw_bg_link_up(void *data)
  8665. {
  8666. struct ipw_priv *priv = data;
  8667. down(&priv->sem);
  8668. ipw_link_up(data);
  8669. up(&priv->sem);
  8670. }
  8671. void ipw_link_down(struct ipw_priv *priv)
  8672. {
  8673. ipw_led_link_down(priv);
  8674. netif_carrier_off(priv->net_dev);
  8675. netif_stop_queue(priv->net_dev);
  8676. notify_wx_assoc_event(priv);
  8677. /* Cancel any queued work ... */
  8678. cancel_delayed_work(&priv->request_scan);
  8679. cancel_delayed_work(&priv->adhoc_check);
  8680. cancel_delayed_work(&priv->gather_stats);
  8681. ipw_reset_stats(priv);
  8682. if (!(priv->status & STATUS_EXIT_PENDING)) {
  8683. /* Queue up another scan... */
  8684. queue_work(priv->workqueue, &priv->request_scan);
  8685. }
  8686. }
  8687. static void ipw_bg_link_down(void *data)
  8688. {
  8689. struct ipw_priv *priv = data;
  8690. down(&priv->sem);
  8691. ipw_link_down(data);
  8692. up(&priv->sem);
  8693. }
  8694. static int ipw_setup_deferred_work(struct ipw_priv *priv)
  8695. {
  8696. int ret = 0;
  8697. priv->workqueue = create_workqueue(DRV_NAME);
  8698. init_waitqueue_head(&priv->wait_command_queue);
  8699. init_waitqueue_head(&priv->wait_state);
  8700. INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
  8701. INIT_WORK(&priv->associate, ipw_bg_associate, priv);
  8702. INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
  8703. INIT_WORK(&priv->system_config, ipw_system_config, priv);
  8704. INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
  8705. INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
  8706. INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
  8707. INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
  8708. INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
  8709. INIT_WORK(&priv->request_scan,
  8710. (void (*)(void *))ipw_request_scan, priv);
  8711. INIT_WORK(&priv->gather_stats,
  8712. (void (*)(void *))ipw_bg_gather_stats, priv);
  8713. INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
  8714. INIT_WORK(&priv->roam, ipw_bg_roam, priv);
  8715. INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
  8716. INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
  8717. INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
  8718. INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
  8719. priv);
  8720. INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
  8721. priv);
  8722. INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
  8723. priv);
  8724. INIT_WORK(&priv->merge_networks,
  8725. (void (*)(void *))ipw_merge_adhoc_network, priv);
  8726. #ifdef CONFIG_IPW_QOS
  8727. INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
  8728. priv);
  8729. #endif /* CONFIG_IPW_QOS */
  8730. tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
  8731. ipw_irq_tasklet, (unsigned long)priv);
  8732. return ret;
  8733. }
  8734. static void shim__set_security(struct net_device *dev,
  8735. struct ieee80211_security *sec)
  8736. {
  8737. struct ipw_priv *priv = ieee80211_priv(dev);
  8738. int i;
  8739. for (i = 0; i < 4; i++) {
  8740. if (sec->flags & (1 << i)) {
  8741. priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
  8742. priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
  8743. if (sec->key_sizes[i] == 0)
  8744. priv->ieee->sec.flags &= ~(1 << i);
  8745. else {
  8746. memcpy(priv->ieee->sec.keys[i], sec->keys[i],
  8747. sec->key_sizes[i]);
  8748. priv->ieee->sec.flags |= (1 << i);
  8749. }
  8750. priv->status |= STATUS_SECURITY_UPDATED;
  8751. } else if (sec->level != SEC_LEVEL_1)
  8752. priv->ieee->sec.flags &= ~(1 << i);
  8753. }
  8754. if (sec->flags & SEC_ACTIVE_KEY) {
  8755. if (sec->active_key <= 3) {
  8756. priv->ieee->sec.active_key = sec->active_key;
  8757. priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
  8758. } else
  8759. priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
  8760. priv->status |= STATUS_SECURITY_UPDATED;
  8761. } else
  8762. priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
  8763. if ((sec->flags & SEC_AUTH_MODE) &&
  8764. (priv->ieee->sec.auth_mode != sec->auth_mode)) {
  8765. priv->ieee->sec.auth_mode = sec->auth_mode;
  8766. priv->ieee->sec.flags |= SEC_AUTH_MODE;
  8767. if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
  8768. priv->capability |= CAP_SHARED_KEY;
  8769. else
  8770. priv->capability &= ~CAP_SHARED_KEY;
  8771. priv->status |= STATUS_SECURITY_UPDATED;
  8772. }
  8773. if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
  8774. priv->ieee->sec.flags |= SEC_ENABLED;
  8775. priv->ieee->sec.enabled = sec->enabled;
  8776. priv->status |= STATUS_SECURITY_UPDATED;
  8777. if (sec->enabled)
  8778. priv->capability |= CAP_PRIVACY_ON;
  8779. else
  8780. priv->capability &= ~CAP_PRIVACY_ON;
  8781. }
  8782. if (sec->flags & SEC_ENCRYPT)
  8783. priv->ieee->sec.encrypt = sec->encrypt;
  8784. if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
  8785. priv->ieee->sec.level = sec->level;
  8786. priv->ieee->sec.flags |= SEC_LEVEL;
  8787. priv->status |= STATUS_SECURITY_UPDATED;
  8788. }
  8789. if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
  8790. ipw_set_hwcrypto_keys(priv);
  8791. /* To match current functionality of ipw2100 (which works well w/
  8792. * various supplicants, we don't force a disassociate if the
  8793. * privacy capability changes ... */
  8794. #if 0
  8795. if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
  8796. (((priv->assoc_request.capability &
  8797. WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
  8798. (!(priv->assoc_request.capability &
  8799. WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
  8800. IPW_DEBUG_ASSOC("Disassociating due to capability "
  8801. "change.\n");
  8802. ipw_disassociate(priv);
  8803. }
  8804. #endif
  8805. }
  8806. static int init_supported_rates(struct ipw_priv *priv,
  8807. struct ipw_supported_rates *rates)
  8808. {
  8809. /* TODO: Mask out rates based on priv->rates_mask */
  8810. memset(rates, 0, sizeof(*rates));
  8811. /* configure supported rates */
  8812. switch (priv->ieee->freq_band) {
  8813. case IEEE80211_52GHZ_BAND:
  8814. rates->ieee_mode = IPW_A_MODE;
  8815. rates->purpose = IPW_RATE_CAPABILITIES;
  8816. ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
  8817. IEEE80211_OFDM_DEFAULT_RATES_MASK);
  8818. break;
  8819. default: /* Mixed or 2.4Ghz */
  8820. rates->ieee_mode = IPW_G_MODE;
  8821. rates->purpose = IPW_RATE_CAPABILITIES;
  8822. ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
  8823. IEEE80211_CCK_DEFAULT_RATES_MASK);
  8824. if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
  8825. ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
  8826. IEEE80211_OFDM_DEFAULT_RATES_MASK);
  8827. }
  8828. break;
  8829. }
  8830. return 0;
  8831. }
  8832. static int ipw_config(struct ipw_priv *priv)
  8833. {
  8834. int i;
  8835. struct ipw_tx_power tx_power;
  8836. memset(&priv->sys_config, 0, sizeof(priv->sys_config));
  8837. memset(&tx_power, 0, sizeof(tx_power));
  8838. /* This is only called from ipw_up, which resets/reloads the firmware
  8839. so, we don't need to first disable the card before we configure
  8840. it */
  8841. /* configure device for 'G' band */
  8842. tx_power.ieee_mode = IPW_G_MODE;
  8843. tx_power.num_channels = 11;
  8844. for (i = 0; i < 11; i++) {
  8845. tx_power.channels_tx_power[i].channel_number = i + 1;
  8846. tx_power.channels_tx_power[i].tx_power = priv->tx_power;
  8847. }
  8848. if (ipw_send_tx_power(priv, &tx_power))
  8849. goto error;
  8850. /* configure device to also handle 'B' band */
  8851. tx_power.ieee_mode = IPW_B_MODE;
  8852. if (ipw_send_tx_power(priv, &tx_power))
  8853. goto error;
  8854. /* initialize adapter address */
  8855. if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
  8856. goto error;
  8857. /* set basic system config settings */
  8858. init_sys_config(&priv->sys_config);
  8859. if (priv->ieee->iw_mode == IW_MODE_ADHOC)
  8860. priv->sys_config.answer_broadcast_ssid_probe = 1;
  8861. else
  8862. priv->sys_config.answer_broadcast_ssid_probe = 0;
  8863. if (ipw_send_system_config(priv, &priv->sys_config))
  8864. goto error;
  8865. init_supported_rates(priv, &priv->rates);
  8866. if (ipw_send_supported_rates(priv, &priv->rates))
  8867. goto error;
  8868. /* Set request-to-send threshold */
  8869. if (priv->rts_threshold) {
  8870. if (ipw_send_rts_threshold(priv, priv->rts_threshold))
  8871. goto error;
  8872. }
  8873. #ifdef CONFIG_IPW_QOS
  8874. IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
  8875. ipw_qos_activate(priv, NULL);
  8876. #endif /* CONFIG_IPW_QOS */
  8877. if (ipw_set_random_seed(priv))
  8878. goto error;
  8879. /* final state transition to the RUN state */
  8880. if (ipw_send_host_complete(priv))
  8881. goto error;
  8882. /* If configured to try and auto-associate, kick off a scan */
  8883. if (priv->config & CFG_ASSOCIATE)
  8884. queue_work(priv->workqueue, &priv->request_scan);
  8885. return 0;
  8886. error:
  8887. return -EIO;
  8888. }
  8889. /*
  8890. * NOTE:
  8891. *
  8892. * These tables have been tested in conjunction with the
  8893. * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
  8894. *
  8895. * Altering this values, using it on other hardware, or in geographies
  8896. * not intended for resale of the above mentioned Intel adapters has
  8897. * not been tested.
  8898. *
  8899. */
  8900. static const struct ieee80211_geo ipw_geos[] = {
  8901. { /* Restricted */
  8902. "---",
  8903. .bg_channels = 11,
  8904. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  8905. {2427, 4}, {2432, 5}, {2437, 6},
  8906. {2442, 7}, {2447, 8}, {2452, 9},
  8907. {2457, 10}, {2462, 11}},
  8908. },
  8909. { /* Custom US/Canada */
  8910. "ZZF",
  8911. .bg_channels = 11,
  8912. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  8913. {2427, 4}, {2432, 5}, {2437, 6},
  8914. {2442, 7}, {2447, 8}, {2452, 9},
  8915. {2457, 10}, {2462, 11}},
  8916. .a_channels = 8,
  8917. .a = {{5180, 36},
  8918. {5200, 40},
  8919. {5220, 44},
  8920. {5240, 48},
  8921. {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
  8922. {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
  8923. {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
  8924. {5320, 64, IEEE80211_CH_PASSIVE_ONLY}},
  8925. },
  8926. { /* Rest of World */
  8927. "ZZD",
  8928. .bg_channels = 13,
  8929. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  8930. {2427, 4}, {2432, 5}, {2437, 6},
  8931. {2442, 7}, {2447, 8}, {2452, 9},
  8932. {2457, 10}, {2462, 11}, {2467, 12},
  8933. {2472, 13}},
  8934. },
  8935. { /* Custom USA & Europe & High */
  8936. "ZZA",
  8937. .bg_channels = 11,
  8938. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  8939. {2427, 4}, {2432, 5}, {2437, 6},
  8940. {2442, 7}, {2447, 8}, {2452, 9},
  8941. {2457, 10}, {2462, 11}},
  8942. .a_channels = 13,
  8943. .a = {{5180, 36},
  8944. {5200, 40},
  8945. {5220, 44},
  8946. {5240, 48},
  8947. {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
  8948. {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
  8949. {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
  8950. {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
  8951. {5745, 149},
  8952. {5765, 153},
  8953. {5785, 157},
  8954. {5805, 161},
  8955. {5825, 165}},
  8956. },
  8957. { /* Custom NA & Europe */
  8958. "ZZB",
  8959. .bg_channels = 11,
  8960. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  8961. {2427, 4}, {2432, 5}, {2437, 6},
  8962. {2442, 7}, {2447, 8}, {2452, 9},
  8963. {2457, 10}, {2462, 11}},
  8964. .a_channels = 13,
  8965. .a = {{5180, 36},
  8966. {5200, 40},
  8967. {5220, 44},
  8968. {5240, 48},
  8969. {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
  8970. {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
  8971. {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
  8972. {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
  8973. {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
  8974. {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
  8975. {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
  8976. {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
  8977. {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
  8978. },
  8979. { /* Custom Japan */
  8980. "ZZC",
  8981. .bg_channels = 11,
  8982. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  8983. {2427, 4}, {2432, 5}, {2437, 6},
  8984. {2442, 7}, {2447, 8}, {2452, 9},
  8985. {2457, 10}, {2462, 11}},
  8986. .a_channels = 4,
  8987. .a = {{5170, 34}, {5190, 38},
  8988. {5210, 42}, {5230, 46}},
  8989. },
  8990. { /* Custom */
  8991. "ZZM",
  8992. .bg_channels = 11,
  8993. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  8994. {2427, 4}, {2432, 5}, {2437, 6},
  8995. {2442, 7}, {2447, 8}, {2452, 9},
  8996. {2457, 10}, {2462, 11}},
  8997. },
  8998. { /* Europe */
  8999. "ZZE",
  9000. .bg_channels = 13,
  9001. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  9002. {2427, 4}, {2432, 5}, {2437, 6},
  9003. {2442, 7}, {2447, 8}, {2452, 9},
  9004. {2457, 10}, {2462, 11}, {2467, 12},
  9005. {2472, 13}},
  9006. .a_channels = 19,
  9007. .a = {{5180, 36},
  9008. {5200, 40},
  9009. {5220, 44},
  9010. {5240, 48},
  9011. {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
  9012. {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
  9013. {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
  9014. {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
  9015. {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
  9016. {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
  9017. {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
  9018. {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
  9019. {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
  9020. {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
  9021. {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
  9022. {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
  9023. {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
  9024. {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
  9025. {5700, 140, IEEE80211_CH_PASSIVE_ONLY}},
  9026. },
  9027. { /* Custom Japan */
  9028. "ZZJ",
  9029. .bg_channels = 14,
  9030. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  9031. {2427, 4}, {2432, 5}, {2437, 6},
  9032. {2442, 7}, {2447, 8}, {2452, 9},
  9033. {2457, 10}, {2462, 11}, {2467, 12},
  9034. {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}},
  9035. .a_channels = 4,
  9036. .a = {{5170, 34}, {5190, 38},
  9037. {5210, 42}, {5230, 46}},
  9038. },
  9039. { /* High Band */
  9040. "ZZH",
  9041. .bg_channels = 13,
  9042. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  9043. {2427, 4}, {2432, 5}, {2437, 6},
  9044. {2442, 7}, {2447, 8}, {2452, 9},
  9045. {2457, 10}, {2462, 11},
  9046. {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
  9047. {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
  9048. .a_channels = 4,
  9049. .a = {{5745, 149}, {5765, 153},
  9050. {5785, 157}, {5805, 161}},
  9051. },
  9052. { /* Custom Europe */
  9053. "ZZG",
  9054. .bg_channels = 13,
  9055. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  9056. {2427, 4}, {2432, 5}, {2437, 6},
  9057. {2442, 7}, {2447, 8}, {2452, 9},
  9058. {2457, 10}, {2462, 11},
  9059. {2467, 12}, {2472, 13}},
  9060. .a_channels = 4,
  9061. .a = {{5180, 36}, {5200, 40},
  9062. {5220, 44}, {5240, 48}},
  9063. },
  9064. { /* Europe */
  9065. "ZZK",
  9066. .bg_channels = 13,
  9067. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  9068. {2427, 4}, {2432, 5}, {2437, 6},
  9069. {2442, 7}, {2447, 8}, {2452, 9},
  9070. {2457, 10}, {2462, 11},
  9071. {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
  9072. {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
  9073. .a_channels = 24,
  9074. .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
  9075. {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
  9076. {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
  9077. {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
  9078. {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
  9079. {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
  9080. {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
  9081. {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
  9082. {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
  9083. {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
  9084. {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
  9085. {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
  9086. {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
  9087. {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
  9088. {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
  9089. {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
  9090. {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
  9091. {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
  9092. {5700, 140, IEEE80211_CH_PASSIVE_ONLY},
  9093. {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
  9094. {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
  9095. {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
  9096. {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
  9097. {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
  9098. },
  9099. { /* Europe */
  9100. "ZZL",
  9101. .bg_channels = 11,
  9102. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  9103. {2427, 4}, {2432, 5}, {2437, 6},
  9104. {2442, 7}, {2447, 8}, {2452, 9},
  9105. {2457, 10}, {2462, 11}},
  9106. .a_channels = 13,
  9107. .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
  9108. {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
  9109. {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
  9110. {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
  9111. {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
  9112. {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
  9113. {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
  9114. {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
  9115. {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
  9116. {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
  9117. {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
  9118. {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
  9119. {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
  9120. }
  9121. };
  9122. #define MAX_HW_RESTARTS 5
  9123. static int ipw_up(struct ipw_priv *priv)
  9124. {
  9125. int rc, i, j;
  9126. if (priv->status & STATUS_EXIT_PENDING)
  9127. return -EIO;
  9128. for (i = 0; i < MAX_HW_RESTARTS; i++) {
  9129. /* Load the microcode, firmware, and eeprom.
  9130. * Also start the clocks. */
  9131. rc = ipw_load(priv);
  9132. if (rc) {
  9133. IPW_ERROR("Unable to load firmware: 0x%08X\n", rc);
  9134. return rc;
  9135. }
  9136. ipw_init_ordinals(priv);
  9137. if (!(priv->config & CFG_CUSTOM_MAC))
  9138. eeprom_parse_mac(priv, priv->mac_addr);
  9139. memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
  9140. for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
  9141. if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
  9142. ipw_geos[j].name, 3))
  9143. break;
  9144. }
  9145. if (j == ARRAY_SIZE(ipw_geos))
  9146. j = 0;
  9147. if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) {
  9148. IPW_WARNING("Could not set geography.");
  9149. return 0;
  9150. }
  9151. IPW_DEBUG_INFO("Geography %03d [%s] detected.\n",
  9152. j, priv->ieee->geo.name);
  9153. if (priv->status & STATUS_RF_KILL_SW) {
  9154. IPW_WARNING("Radio disabled by module parameter.\n");
  9155. return 0;
  9156. } else if (rf_kill_active(priv)) {
  9157. IPW_WARNING("Radio Frequency Kill Switch is On:\n"
  9158. "Kill switch must be turned off for "
  9159. "wireless networking to work.\n");
  9160. queue_delayed_work(priv->workqueue, &priv->rf_kill,
  9161. 2 * HZ);
  9162. return 0;
  9163. }
  9164. rc = ipw_config(priv);
  9165. if (!rc) {
  9166. IPW_DEBUG_INFO("Configured device on count %i\n", i);
  9167. ipw_led_init(priv);
  9168. ipw_led_radio_on(priv);
  9169. priv->notif_missed_beacons = 0;
  9170. priv->status |= STATUS_INIT;
  9171. /* Set hardware WEP key if it is configured. */
  9172. if ((priv->capability & CAP_PRIVACY_ON) &&
  9173. (priv->ieee->sec.level == SEC_LEVEL_1) &&
  9174. !(priv->ieee->host_encrypt ||
  9175. priv->ieee->host_decrypt))
  9176. ipw_set_hwcrypto_keys(priv);
  9177. return 0;
  9178. }
  9179. IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
  9180. IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
  9181. i, MAX_HW_RESTARTS);
  9182. /* We had an error bringing up the hardware, so take it
  9183. * all the way back down so we can try again */
  9184. ipw_down(priv);
  9185. }
  9186. /* tried to restart and config the device for as long as our
  9187. * patience could withstand */
  9188. IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
  9189. return -EIO;
  9190. }
  9191. static void ipw_bg_up(void *data)
  9192. {
  9193. struct ipw_priv *priv = data;
  9194. down(&priv->sem);
  9195. ipw_up(data);
  9196. up(&priv->sem);
  9197. }
  9198. static void ipw_deinit(struct ipw_priv *priv)
  9199. {
  9200. int i;
  9201. if (priv->status & STATUS_SCANNING) {
  9202. IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
  9203. ipw_abort_scan(priv);
  9204. }
  9205. if (priv->status & STATUS_ASSOCIATED) {
  9206. IPW_DEBUG_INFO("Disassociating during shutdown.\n");
  9207. ipw_disassociate(priv);
  9208. }
  9209. ipw_led_shutdown(priv);
  9210. /* Wait up to 1s for status to change to not scanning and not
  9211. * associated (disassociation can take a while for a ful 802.11
  9212. * exchange */
  9213. for (i = 1000; i && (priv->status &
  9214. (STATUS_DISASSOCIATING |
  9215. STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
  9216. udelay(10);
  9217. if (priv->status & (STATUS_DISASSOCIATING |
  9218. STATUS_ASSOCIATED | STATUS_SCANNING))
  9219. IPW_DEBUG_INFO("Still associated or scanning...\n");
  9220. else
  9221. IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
  9222. /* Attempt to disable the card */
  9223. ipw_send_card_disable(priv, 0);
  9224. priv->status &= ~STATUS_INIT;
  9225. }
  9226. static void ipw_down(struct ipw_priv *priv)
  9227. {
  9228. int exit_pending = priv->status & STATUS_EXIT_PENDING;
  9229. priv->status |= STATUS_EXIT_PENDING;
  9230. if (ipw_is_init(priv))
  9231. ipw_deinit(priv);
  9232. /* Wipe out the EXIT_PENDING status bit if we are not actually
  9233. * exiting the module */
  9234. if (!exit_pending)
  9235. priv->status &= ~STATUS_EXIT_PENDING;
  9236. /* tell the device to stop sending interrupts */
  9237. ipw_disable_interrupts(priv);
  9238. /* Clear all bits but the RF Kill */
  9239. priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
  9240. netif_carrier_off(priv->net_dev);
  9241. netif_stop_queue(priv->net_dev);
  9242. ipw_stop_nic(priv);
  9243. ipw_led_radio_off(priv);
  9244. }
  9245. static void ipw_bg_down(void *data)
  9246. {
  9247. struct ipw_priv *priv = data;
  9248. down(&priv->sem);
  9249. ipw_down(data);
  9250. up(&priv->sem);
  9251. }
  9252. #if WIRELESS_EXT < 18
  9253. static int ipw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  9254. {
  9255. struct iwreq *wrq = (struct iwreq *)rq;
  9256. int ret = -1;
  9257. switch (cmd) {
  9258. case IPW_IOCTL_WPA_SUPPLICANT:
  9259. ret = ipw_wpa_supplicant(dev, &wrq->u.data);
  9260. return ret;
  9261. default:
  9262. return -EOPNOTSUPP;
  9263. }
  9264. return -EOPNOTSUPP;
  9265. }
  9266. #endif
  9267. /* Called by register_netdev() */
  9268. static int ipw_net_init(struct net_device *dev)
  9269. {
  9270. struct ipw_priv *priv = ieee80211_priv(dev);
  9271. down(&priv->sem);
  9272. if (ipw_up(priv)) {
  9273. up(&priv->sem);
  9274. return -EIO;
  9275. }
  9276. up(&priv->sem);
  9277. return 0;
  9278. }
  9279. /* PCI driver stuff */
  9280. static struct pci_device_id card_ids[] = {
  9281. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
  9282. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
  9283. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
  9284. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
  9285. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
  9286. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
  9287. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
  9288. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
  9289. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
  9290. {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
  9291. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
  9292. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
  9293. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
  9294. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
  9295. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
  9296. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
  9297. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
  9298. {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  9299. {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
  9300. {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
  9301. {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
  9302. {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
  9303. /* required last entry */
  9304. {0,}
  9305. };
  9306. MODULE_DEVICE_TABLE(pci, card_ids);
  9307. static struct attribute *ipw_sysfs_entries[] = {
  9308. &dev_attr_rf_kill.attr,
  9309. &dev_attr_direct_dword.attr,
  9310. &dev_attr_indirect_byte.attr,
  9311. &dev_attr_indirect_dword.attr,
  9312. &dev_attr_mem_gpio_reg.attr,
  9313. &dev_attr_command_event_reg.attr,
  9314. &dev_attr_nic_type.attr,
  9315. &dev_attr_status.attr,
  9316. &dev_attr_cfg.attr,
  9317. &dev_attr_dump_errors.attr,
  9318. &dev_attr_dump_events.attr,
  9319. &dev_attr_eeprom_delay.attr,
  9320. &dev_attr_ucode_version.attr,
  9321. &dev_attr_rtc.attr,
  9322. &dev_attr_scan_age.attr,
  9323. &dev_attr_led.attr,
  9324. &dev_attr_speed_scan.attr,
  9325. &dev_attr_net_stats.attr,
  9326. NULL
  9327. };
  9328. static struct attribute_group ipw_attribute_group = {
  9329. .name = NULL, /* put in device directory */
  9330. .attrs = ipw_sysfs_entries,
  9331. };
  9332. static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  9333. {
  9334. int err = 0;
  9335. struct net_device *net_dev;
  9336. void __iomem *base;
  9337. u32 length, val;
  9338. struct ipw_priv *priv;
  9339. int i;
  9340. net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
  9341. if (net_dev == NULL) {
  9342. err = -ENOMEM;
  9343. goto out;
  9344. }
  9345. priv = ieee80211_priv(net_dev);
  9346. priv->ieee = netdev_priv(net_dev);
  9347. priv->net_dev = net_dev;
  9348. priv->pci_dev = pdev;
  9349. #ifdef CONFIG_IPW_DEBUG
  9350. ipw_debug_level = debug;
  9351. #endif
  9352. spin_lock_init(&priv->lock);
  9353. for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
  9354. INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
  9355. init_MUTEX(&priv->sem);
  9356. if (pci_enable_device(pdev)) {
  9357. err = -ENODEV;
  9358. goto out_free_ieee80211;
  9359. }
  9360. pci_set_master(pdev);
  9361. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  9362. if (!err)
  9363. err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  9364. if (err) {
  9365. printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
  9366. goto out_pci_disable_device;
  9367. }
  9368. pci_set_drvdata(pdev, priv);
  9369. err = pci_request_regions(pdev, DRV_NAME);
  9370. if (err)
  9371. goto out_pci_disable_device;
  9372. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  9373. * PCI Tx retries from interfering with C3 CPU state */
  9374. pci_read_config_dword(pdev, 0x40, &val);
  9375. if ((val & 0x0000ff00) != 0)
  9376. pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
  9377. length = pci_resource_len(pdev, 0);
  9378. priv->hw_len = length;
  9379. base = ioremap_nocache(pci_resource_start(pdev, 0), length);
  9380. if (!base) {
  9381. err = -ENODEV;
  9382. goto out_pci_release_regions;
  9383. }
  9384. priv->hw_base = base;
  9385. IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
  9386. IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
  9387. err = ipw_setup_deferred_work(priv);
  9388. if (err) {
  9389. IPW_ERROR("Unable to setup deferred work\n");
  9390. goto out_iounmap;
  9391. }
  9392. ipw_sw_reset(priv, 1);
  9393. err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
  9394. if (err) {
  9395. IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
  9396. goto out_destroy_workqueue;
  9397. }
  9398. SET_MODULE_OWNER(net_dev);
  9399. SET_NETDEV_DEV(net_dev, &pdev->dev);
  9400. ipw_wx_data.spy_data = &priv->ieee->spy_data;
  9401. ipw_wx_data.ieee80211 = priv->ieee;
  9402. down(&priv->sem);
  9403. priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
  9404. priv->ieee->set_security = shim__set_security;
  9405. priv->ieee->is_queue_full = ipw_net_is_queue_full;
  9406. #ifdef CONFIG_IPW_QOS
  9407. priv->ieee->handle_management = ipw_handle_management;
  9408. #endif /* CONFIG_IPW_QOS */
  9409. priv->ieee->perfect_rssi = -20;
  9410. priv->ieee->worst_rssi = -85;
  9411. net_dev->open = ipw_net_open;
  9412. net_dev->stop = ipw_net_stop;
  9413. net_dev->init = ipw_net_init;
  9414. #if WIRELESS_EXT < 18
  9415. net_dev->do_ioctl = ipw_ioctl;
  9416. #endif
  9417. net_dev->get_stats = ipw_net_get_stats;
  9418. net_dev->set_multicast_list = ipw_net_set_multicast_list;
  9419. net_dev->set_mac_address = ipw_net_set_mac_address;
  9420. net_dev->get_wireless_stats = ipw_get_wireless_stats;
  9421. net_dev->wireless_data = &ipw_wx_data;
  9422. net_dev->wireless_handlers = &ipw_wx_handler_def;
  9423. net_dev->ethtool_ops = &ipw_ethtool_ops;
  9424. net_dev->irq = pdev->irq;
  9425. net_dev->base_addr = (unsigned long)priv->hw_base;
  9426. net_dev->mem_start = pci_resource_start(pdev, 0);
  9427. net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
  9428. err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
  9429. if (err) {
  9430. IPW_ERROR("failed to create sysfs device attributes\n");
  9431. up(&priv->sem);
  9432. goto out_release_irq;
  9433. }
  9434. up(&priv->sem);
  9435. err = register_netdev(net_dev);
  9436. if (err) {
  9437. IPW_ERROR("failed to register network device\n");
  9438. goto out_remove_sysfs;
  9439. }
  9440. return 0;
  9441. out_remove_sysfs:
  9442. sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
  9443. out_release_irq:
  9444. free_irq(pdev->irq, priv);
  9445. out_destroy_workqueue:
  9446. destroy_workqueue(priv->workqueue);
  9447. priv->workqueue = NULL;
  9448. out_iounmap:
  9449. iounmap(priv->hw_base);
  9450. out_pci_release_regions:
  9451. pci_release_regions(pdev);
  9452. out_pci_disable_device:
  9453. pci_disable_device(pdev);
  9454. pci_set_drvdata(pdev, NULL);
  9455. out_free_ieee80211:
  9456. free_ieee80211(priv->net_dev);
  9457. out:
  9458. return err;
  9459. }
  9460. static void ipw_pci_remove(struct pci_dev *pdev)
  9461. {
  9462. struct ipw_priv *priv = pci_get_drvdata(pdev);
  9463. struct list_head *p, *q;
  9464. int i;
  9465. if (!priv)
  9466. return;
  9467. down(&priv->sem);
  9468. priv->status |= STATUS_EXIT_PENDING;
  9469. ipw_down(priv);
  9470. sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
  9471. up(&priv->sem);
  9472. unregister_netdev(priv->net_dev);
  9473. if (priv->rxq) {
  9474. ipw_rx_queue_free(priv, priv->rxq);
  9475. priv->rxq = NULL;
  9476. }
  9477. ipw_tx_queue_free(priv);
  9478. /* ipw_down will ensure that there is no more pending work
  9479. * in the workqueue's, so we can safely remove them now. */
  9480. cancel_delayed_work(&priv->adhoc_check);
  9481. cancel_delayed_work(&priv->gather_stats);
  9482. cancel_delayed_work(&priv->request_scan);
  9483. cancel_delayed_work(&priv->rf_kill);
  9484. cancel_delayed_work(&priv->scan_check);
  9485. destroy_workqueue(priv->workqueue);
  9486. priv->workqueue = NULL;
  9487. /* Free MAC hash list for ADHOC */
  9488. for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
  9489. list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
  9490. kfree(list_entry(p, struct ipw_ibss_seq, list));
  9491. list_del(p);
  9492. }
  9493. }
  9494. free_irq(pdev->irq, priv);
  9495. iounmap(priv->hw_base);
  9496. pci_release_regions(pdev);
  9497. pci_disable_device(pdev);
  9498. pci_set_drvdata(pdev, NULL);
  9499. free_ieee80211(priv->net_dev);
  9500. free_firmware();
  9501. }
  9502. #ifdef CONFIG_PM
  9503. static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  9504. {
  9505. struct ipw_priv *priv = pci_get_drvdata(pdev);
  9506. struct net_device *dev = priv->net_dev;
  9507. printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
  9508. /* Take down the device; powers it off, etc. */
  9509. ipw_down(priv);
  9510. /* Remove the PRESENT state of the device */
  9511. netif_device_detach(dev);
  9512. pci_save_state(pdev);
  9513. pci_disable_device(pdev);
  9514. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  9515. return 0;
  9516. }
  9517. static int ipw_pci_resume(struct pci_dev *pdev)
  9518. {
  9519. struct ipw_priv *priv = pci_get_drvdata(pdev);
  9520. struct net_device *dev = priv->net_dev;
  9521. u32 val;
  9522. printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
  9523. pci_set_power_state(pdev, PCI_D0);
  9524. pci_enable_device(pdev);
  9525. pci_restore_state(pdev);
  9526. /*
  9527. * Suspend/Resume resets the PCI configuration space, so we have to
  9528. * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
  9529. * from interfering with C3 CPU state. pci_restore_state won't help
  9530. * here since it only restores the first 64 bytes pci config header.
  9531. */
  9532. pci_read_config_dword(pdev, 0x40, &val);
  9533. if ((val & 0x0000ff00) != 0)
  9534. pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
  9535. /* Set the device back into the PRESENT state; this will also wake
  9536. * the queue of needed */
  9537. netif_device_attach(dev);
  9538. /* Bring the device back up */
  9539. queue_work(priv->workqueue, &priv->up);
  9540. return 0;
  9541. }
  9542. #endif
  9543. /* driver initialization stuff */
  9544. static struct pci_driver ipw_driver = {
  9545. .name = DRV_NAME,
  9546. .id_table = card_ids,
  9547. .probe = ipw_pci_probe,
  9548. .remove = __devexit_p(ipw_pci_remove),
  9549. #ifdef CONFIG_PM
  9550. .suspend = ipw_pci_suspend,
  9551. .resume = ipw_pci_resume,
  9552. #endif
  9553. };
  9554. static int __init ipw_init(void)
  9555. {
  9556. int ret;
  9557. printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
  9558. printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
  9559. ret = pci_module_init(&ipw_driver);
  9560. if (ret) {
  9561. IPW_ERROR("Unable to initialize PCI module\n");
  9562. return ret;
  9563. }
  9564. ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
  9565. if (ret) {
  9566. IPW_ERROR("Unable to create driver sysfs file\n");
  9567. pci_unregister_driver(&ipw_driver);
  9568. return ret;
  9569. }
  9570. return ret;
  9571. }
  9572. static void __exit ipw_exit(void)
  9573. {
  9574. driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
  9575. pci_unregister_driver(&ipw_driver);
  9576. }
  9577. module_param(disable, int, 0444);
  9578. MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
  9579. module_param(associate, int, 0444);
  9580. MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
  9581. module_param(auto_create, int, 0444);
  9582. MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
  9583. module_param(led, int, 0444);
  9584. MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
  9585. module_param(debug, int, 0444);
  9586. MODULE_PARM_DESC(debug, "debug output mask");
  9587. module_param(channel, int, 0444);
  9588. MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
  9589. #ifdef CONFIG_IPW_QOS
  9590. module_param(qos_enable, int, 0444);
  9591. MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
  9592. module_param(qos_burst_enable, int, 0444);
  9593. MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
  9594. module_param(qos_no_ack_mask, int, 0444);
  9595. MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
  9596. module_param(burst_duration_CCK, int, 0444);
  9597. MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
  9598. module_param(burst_duration_OFDM, int, 0444);
  9599. MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
  9600. #endif /* CONFIG_IPW_QOS */
  9601. #ifdef CONFIG_IPW2200_MONITOR
  9602. module_param(mode, int, 0444);
  9603. MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
  9604. #else
  9605. module_param(mode, int, 0444);
  9606. MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
  9607. #endif
  9608. module_param(hwcrypto, int, 0444);
  9609. MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default on)");
  9610. module_exit(ipw_exit);
  9611. module_init(ipw_init);