ipw2100.c 227 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718
  1. /******************************************************************************
  2. Copyright(c) 2003 - 2006 Intel Corporation. All rights reserved.
  3. This program is free software; you can redistribute it and/or modify it
  4. under the terms of version 2 of the GNU General Public License as
  5. published by the Free Software Foundation.
  6. This program is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  8. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  9. more details.
  10. You should have received a copy of the GNU General Public License along with
  11. this program; if not, write to the Free Software Foundation, Inc., 59
  12. Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  13. The full GNU General Public License is included in this distribution in the
  14. file called LICENSE.
  15. Contact Information:
  16. Intel Linux Wireless <ilw@linux.intel.com>
  17. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  18. Portions of this file are based on the sample_* files provided by Wireless
  19. Extensions 0.26 package and copyright (c) 1997-2003 Jean Tourrilhes
  20. <jt@hpl.hp.com>
  21. Portions of this file are based on the Host AP project,
  22. Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
  23. <j@w1.fi>
  24. Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
  25. Portions of ipw2100_mod_firmware_load, ipw2100_do_mod_firmware_load, and
  26. ipw2100_fw_load are loosely based on drivers/sound/sound_firmware.c
  27. available in the 2.4.25 kernel sources, and are copyright (c) Alan Cox
  28. ******************************************************************************/
  29. /*
  30. Initial driver on which this is based was developed by Janusz Gorycki,
  31. Maciej Urbaniak, and Maciej Sosnowski.
  32. Promiscuous mode support added by Jacek Wysoczynski and Maciej Urbaniak.
  33. Theory of Operation
  34. Tx - Commands and Data
  35. Firmware and host share a circular queue of Transmit Buffer Descriptors (TBDs)
  36. Each TBD contains a pointer to the physical (dma_addr_t) address of data being
  37. sent to the firmware as well as the length of the data.
  38. The host writes to the TBD queue at the WRITE index. The WRITE index points
  39. to the _next_ packet to be written and is advanced when after the TBD has been
  40. filled.
  41. The firmware pulls from the TBD queue at the READ index. The READ index points
  42. to the currently being read entry, and is advanced once the firmware is
  43. done with a packet.
  44. When data is sent to the firmware, the first TBD is used to indicate to the
  45. firmware if a Command or Data is being sent. If it is Command, all of the
  46. command information is contained within the physical address referred to by the
  47. TBD. If it is Data, the first TBD indicates the type of data packet, number
  48. of fragments, etc. The next TBD then refers to the actual packet location.
  49. The Tx flow cycle is as follows:
  50. 1) ipw2100_tx() is called by kernel with SKB to transmit
  51. 2) Packet is move from the tx_free_list and appended to the transmit pending
  52. list (tx_pend_list)
  53. 3) work is scheduled to move pending packets into the shared circular queue.
  54. 4) when placing packet in the circular queue, the incoming SKB is DMA mapped
  55. to a physical address. That address is entered into a TBD. Two TBDs are
  56. filled out. The first indicating a data packet, the second referring to the
  57. actual payload data.
  58. 5) the packet is removed from tx_pend_list and placed on the end of the
  59. firmware pending list (fw_pend_list)
  60. 6) firmware is notified that the WRITE index has
  61. 7) Once the firmware has processed the TBD, INTA is triggered.
  62. 8) For each Tx interrupt received from the firmware, the READ index is checked
  63. to see which TBDs are done being processed.
  64. 9) For each TBD that has been processed, the ISR pulls the oldest packet
  65. from the fw_pend_list.
  66. 10)The packet structure contained in the fw_pend_list is then used
  67. to unmap the DMA address and to free the SKB originally passed to the driver
  68. from the kernel.
  69. 11)The packet structure is placed onto the tx_free_list
  70. The above steps are the same for commands, only the msg_free_list/msg_pend_list
  71. are used instead of tx_free_list/tx_pend_list
  72. ...
  73. Critical Sections / Locking :
  74. There are two locks utilized. The first is the low level lock (priv->low_lock)
  75. that protects the following:
  76. - Access to the Tx/Rx queue lists via priv->low_lock. The lists are as follows:
  77. tx_free_list : Holds pre-allocated Tx buffers.
  78. TAIL modified in __ipw2100_tx_process()
  79. HEAD modified in ipw2100_tx()
  80. tx_pend_list : Holds used Tx buffers waiting to go into the TBD ring
  81. TAIL modified ipw2100_tx()
  82. HEAD modified by ipw2100_tx_send_data()
  83. msg_free_list : Holds pre-allocated Msg (Command) buffers
  84. TAIL modified in __ipw2100_tx_process()
  85. HEAD modified in ipw2100_hw_send_command()
  86. msg_pend_list : Holds used Msg buffers waiting to go into the TBD ring
  87. TAIL modified in ipw2100_hw_send_command()
  88. HEAD modified in ipw2100_tx_send_commands()
  89. The flow of data on the TX side is as follows:
  90. MSG_FREE_LIST + COMMAND => MSG_PEND_LIST => TBD => MSG_FREE_LIST
  91. TX_FREE_LIST + DATA => TX_PEND_LIST => TBD => TX_FREE_LIST
  92. The methods that work on the TBD ring are protected via priv->low_lock.
  93. - The internal data state of the device itself
  94. - Access to the firmware read/write indexes for the BD queues
  95. and associated logic
  96. All external entry functions are locked with the priv->action_lock to ensure
  97. that only one external action is invoked at a time.
  98. */
  99. #include <linux/compiler.h>
  100. #include <linux/errno.h>
  101. #include <linux/if_arp.h>
  102. #include <linux/in6.h>
  103. #include <linux/in.h>
  104. #include <linux/ip.h>
  105. #include <linux/kernel.h>
  106. #include <linux/kmod.h>
  107. #include <linux/module.h>
  108. #include <linux/netdevice.h>
  109. #include <linux/ethtool.h>
  110. #include <linux/pci.h>
  111. #include <linux/dma-mapping.h>
  112. #include <linux/proc_fs.h>
  113. #include <linux/skbuff.h>
  114. #include <asm/uaccess.h>
  115. #include <asm/io.h>
  116. #include <linux/fs.h>
  117. #include <linux/mm.h>
  118. #include <linux/slab.h>
  119. #include <linux/unistd.h>
  120. #include <linux/stringify.h>
  121. #include <linux/tcp.h>
  122. #include <linux/types.h>
  123. #include <linux/time.h>
  124. #include <linux/firmware.h>
  125. #include <linux/acpi.h>
  126. #include <linux/ctype.h>
  127. #include <linux/pm_qos.h>
  128. #include <net/lib80211.h>
  129. #include "ipw2100.h"
  130. #include "ipw.h"
  131. #define IPW2100_VERSION "git-1.2.2"
  132. #define DRV_NAME "ipw2100"
  133. #define DRV_VERSION IPW2100_VERSION
  134. #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2100 Network Driver"
  135. #define DRV_COPYRIGHT "Copyright(c) 2003-2006 Intel Corporation"
  136. static struct pm_qos_request ipw2100_pm_qos_req;
  137. /* Debugging stuff */
  138. #ifdef CONFIG_IPW2100_DEBUG
  139. #define IPW2100_RX_DEBUG /* Reception debugging */
  140. #endif
  141. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  142. MODULE_VERSION(DRV_VERSION);
  143. MODULE_AUTHOR(DRV_COPYRIGHT);
  144. MODULE_LICENSE("GPL");
  145. static int debug = 0;
  146. static int network_mode = 0;
  147. static int channel = 0;
  148. static int associate = 0;
  149. static int disable = 0;
  150. #ifdef CONFIG_PM
  151. static struct ipw2100_fw ipw2100_firmware;
  152. #endif
  153. #include <linux/moduleparam.h>
  154. module_param(debug, int, 0444);
  155. module_param_named(mode, network_mode, int, 0444);
  156. module_param(channel, int, 0444);
  157. module_param(associate, int, 0444);
  158. module_param(disable, int, 0444);
  159. MODULE_PARM_DESC(debug, "debug level");
  160. MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
  161. MODULE_PARM_DESC(channel, "channel");
  162. MODULE_PARM_DESC(associate, "auto associate when scanning (default off)");
  163. MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
  164. static u32 ipw2100_debug_level = IPW_DL_NONE;
  165. #ifdef CONFIG_IPW2100_DEBUG
  166. #define IPW_DEBUG(level, message...) \
  167. do { \
  168. if (ipw2100_debug_level & (level)) { \
  169. printk(KERN_DEBUG "ipw2100: %c %s ", \
  170. in_interrupt() ? 'I' : 'U', __func__); \
  171. printk(message); \
  172. } \
  173. } while (0)
  174. #else
  175. #define IPW_DEBUG(level, message...) do {} while (0)
  176. #endif /* CONFIG_IPW2100_DEBUG */
  177. #ifdef CONFIG_IPW2100_DEBUG
  178. static const char *command_types[] = {
  179. "undefined",
  180. "unused", /* HOST_ATTENTION */
  181. "HOST_COMPLETE",
  182. "unused", /* SLEEP */
  183. "unused", /* HOST_POWER_DOWN */
  184. "unused",
  185. "SYSTEM_CONFIG",
  186. "unused", /* SET_IMR */
  187. "SSID",
  188. "MANDATORY_BSSID",
  189. "AUTHENTICATION_TYPE",
  190. "ADAPTER_ADDRESS",
  191. "PORT_TYPE",
  192. "INTERNATIONAL_MODE",
  193. "CHANNEL",
  194. "RTS_THRESHOLD",
  195. "FRAG_THRESHOLD",
  196. "POWER_MODE",
  197. "TX_RATES",
  198. "BASIC_TX_RATES",
  199. "WEP_KEY_INFO",
  200. "unused",
  201. "unused",
  202. "unused",
  203. "unused",
  204. "WEP_KEY_INDEX",
  205. "WEP_FLAGS",
  206. "ADD_MULTICAST",
  207. "CLEAR_ALL_MULTICAST",
  208. "BEACON_INTERVAL",
  209. "ATIM_WINDOW",
  210. "CLEAR_STATISTICS",
  211. "undefined",
  212. "undefined",
  213. "undefined",
  214. "undefined",
  215. "TX_POWER_INDEX",
  216. "undefined",
  217. "undefined",
  218. "undefined",
  219. "undefined",
  220. "undefined",
  221. "undefined",
  222. "BROADCAST_SCAN",
  223. "CARD_DISABLE",
  224. "PREFERRED_BSSID",
  225. "SET_SCAN_OPTIONS",
  226. "SCAN_DWELL_TIME",
  227. "SWEEP_TABLE",
  228. "AP_OR_STATION_TABLE",
  229. "GROUP_ORDINALS",
  230. "SHORT_RETRY_LIMIT",
  231. "LONG_RETRY_LIMIT",
  232. "unused", /* SAVE_CALIBRATION */
  233. "unused", /* RESTORE_CALIBRATION */
  234. "undefined",
  235. "undefined",
  236. "undefined",
  237. "HOST_PRE_POWER_DOWN",
  238. "unused", /* HOST_INTERRUPT_COALESCING */
  239. "undefined",
  240. "CARD_DISABLE_PHY_OFF",
  241. "MSDU_TX_RATES",
  242. "undefined",
  243. "SET_STATION_STAT_BITS",
  244. "CLEAR_STATIONS_STAT_BITS",
  245. "LEAP_ROGUE_MODE",
  246. "SET_SECURITY_INFORMATION",
  247. "DISASSOCIATION_BSSID",
  248. "SET_WPA_ASS_IE"
  249. };
  250. #endif
  251. static const long ipw2100_frequencies[] = {
  252. 2412, 2417, 2422, 2427,
  253. 2432, 2437, 2442, 2447,
  254. 2452, 2457, 2462, 2467,
  255. 2472, 2484
  256. };
  257. #define FREQ_COUNT ARRAY_SIZE(ipw2100_frequencies)
  258. static struct ieee80211_rate ipw2100_bg_rates[] = {
  259. { .bitrate = 10 },
  260. { .bitrate = 20, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  261. { .bitrate = 55, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  262. { .bitrate = 110, .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  263. };
  264. #define RATE_COUNT ARRAY_SIZE(ipw2100_bg_rates)
  265. /* Pre-decl until we get the code solid and then we can clean it up */
  266. static void ipw2100_tx_send_commands(struct ipw2100_priv *priv);
  267. static void ipw2100_tx_send_data(struct ipw2100_priv *priv);
  268. static int ipw2100_adapter_setup(struct ipw2100_priv *priv);
  269. static void ipw2100_queues_initialize(struct ipw2100_priv *priv);
  270. static void ipw2100_queues_free(struct ipw2100_priv *priv);
  271. static int ipw2100_queues_allocate(struct ipw2100_priv *priv);
  272. static int ipw2100_fw_download(struct ipw2100_priv *priv,
  273. struct ipw2100_fw *fw);
  274. static int ipw2100_get_firmware(struct ipw2100_priv *priv,
  275. struct ipw2100_fw *fw);
  276. static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf,
  277. size_t max);
  278. static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf,
  279. size_t max);
  280. static void ipw2100_release_firmware(struct ipw2100_priv *priv,
  281. struct ipw2100_fw *fw);
  282. static int ipw2100_ucode_download(struct ipw2100_priv *priv,
  283. struct ipw2100_fw *fw);
  284. static void ipw2100_wx_event_work(struct work_struct *work);
  285. static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device *dev);
  286. static struct iw_handler_def ipw2100_wx_handler_def;
  287. static inline void read_register(struct net_device *dev, u32 reg, u32 * val)
  288. {
  289. *val = readl((void __iomem *)(dev->base_addr + reg));
  290. IPW_DEBUG_IO("r: 0x%08X => 0x%08X\n", reg, *val);
  291. }
  292. static inline void write_register(struct net_device *dev, u32 reg, u32 val)
  293. {
  294. writel(val, (void __iomem *)(dev->base_addr + reg));
  295. IPW_DEBUG_IO("w: 0x%08X <= 0x%08X\n", reg, val);
  296. }
  297. static inline void read_register_word(struct net_device *dev, u32 reg,
  298. u16 * val)
  299. {
  300. *val = readw((void __iomem *)(dev->base_addr + reg));
  301. IPW_DEBUG_IO("r: 0x%08X => %04X\n", reg, *val);
  302. }
  303. static inline void read_register_byte(struct net_device *dev, u32 reg, u8 * val)
  304. {
  305. *val = readb((void __iomem *)(dev->base_addr + reg));
  306. IPW_DEBUG_IO("r: 0x%08X => %02X\n", reg, *val);
  307. }
  308. static inline void write_register_word(struct net_device *dev, u32 reg, u16 val)
  309. {
  310. writew(val, (void __iomem *)(dev->base_addr + reg));
  311. IPW_DEBUG_IO("w: 0x%08X <= %04X\n", reg, val);
  312. }
  313. static inline void write_register_byte(struct net_device *dev, u32 reg, u8 val)
  314. {
  315. writeb(val, (void __iomem *)(dev->base_addr + reg));
  316. IPW_DEBUG_IO("w: 0x%08X =< %02X\n", reg, val);
  317. }
  318. static inline void read_nic_dword(struct net_device *dev, u32 addr, u32 * val)
  319. {
  320. write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
  321. addr & IPW_REG_INDIRECT_ADDR_MASK);
  322. read_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
  323. }
  324. static inline void write_nic_dword(struct net_device *dev, u32 addr, u32 val)
  325. {
  326. write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
  327. addr & IPW_REG_INDIRECT_ADDR_MASK);
  328. write_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
  329. }
  330. static inline void read_nic_word(struct net_device *dev, u32 addr, u16 * val)
  331. {
  332. write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
  333. addr & IPW_REG_INDIRECT_ADDR_MASK);
  334. read_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
  335. }
  336. static inline void write_nic_word(struct net_device *dev, u32 addr, u16 val)
  337. {
  338. write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
  339. addr & IPW_REG_INDIRECT_ADDR_MASK);
  340. write_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
  341. }
  342. static inline void read_nic_byte(struct net_device *dev, u32 addr, u8 * val)
  343. {
  344. write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
  345. addr & IPW_REG_INDIRECT_ADDR_MASK);
  346. read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
  347. }
  348. static inline void write_nic_byte(struct net_device *dev, u32 addr, u8 val)
  349. {
  350. write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
  351. addr & IPW_REG_INDIRECT_ADDR_MASK);
  352. write_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
  353. }
  354. static inline void write_nic_auto_inc_address(struct net_device *dev, u32 addr)
  355. {
  356. write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS,
  357. addr & IPW_REG_INDIRECT_ADDR_MASK);
  358. }
  359. static inline void write_nic_dword_auto_inc(struct net_device *dev, u32 val)
  360. {
  361. write_register(dev, IPW_REG_AUTOINCREMENT_DATA, val);
  362. }
  363. static void write_nic_memory(struct net_device *dev, u32 addr, u32 len,
  364. const u8 * buf)
  365. {
  366. u32 aligned_addr;
  367. u32 aligned_len;
  368. u32 dif_len;
  369. u32 i;
  370. /* read first nibble byte by byte */
  371. aligned_addr = addr & (~0x3);
  372. dif_len = addr - aligned_addr;
  373. if (dif_len) {
  374. /* Start reading at aligned_addr + dif_len */
  375. write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
  376. aligned_addr);
  377. for (i = dif_len; i < 4; i++, buf++)
  378. write_register_byte(dev,
  379. IPW_REG_INDIRECT_ACCESS_DATA + i,
  380. *buf);
  381. len -= dif_len;
  382. aligned_addr += 4;
  383. }
  384. /* read DWs through autoincrement registers */
  385. write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS, aligned_addr);
  386. aligned_len = len & (~0x3);
  387. for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
  388. write_register(dev, IPW_REG_AUTOINCREMENT_DATA, *(u32 *) buf);
  389. /* copy the last nibble */
  390. dif_len = len - aligned_len;
  391. write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, aligned_addr);
  392. for (i = 0; i < dif_len; i++, buf++)
  393. write_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA + i,
  394. *buf);
  395. }
  396. static void read_nic_memory(struct net_device *dev, u32 addr, u32 len,
  397. u8 * buf)
  398. {
  399. u32 aligned_addr;
  400. u32 aligned_len;
  401. u32 dif_len;
  402. u32 i;
  403. /* read first nibble byte by byte */
  404. aligned_addr = addr & (~0x3);
  405. dif_len = addr - aligned_addr;
  406. if (dif_len) {
  407. /* Start reading at aligned_addr + dif_len */
  408. write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
  409. aligned_addr);
  410. for (i = dif_len; i < 4; i++, buf++)
  411. read_register_byte(dev,
  412. IPW_REG_INDIRECT_ACCESS_DATA + i,
  413. buf);
  414. len -= dif_len;
  415. aligned_addr += 4;
  416. }
  417. /* read DWs through autoincrement registers */
  418. write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS, aligned_addr);
  419. aligned_len = len & (~0x3);
  420. for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
  421. read_register(dev, IPW_REG_AUTOINCREMENT_DATA, (u32 *) buf);
  422. /* copy the last nibble */
  423. dif_len = len - aligned_len;
  424. write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, aligned_addr);
  425. for (i = 0; i < dif_len; i++, buf++)
  426. read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA + i, buf);
  427. }
  428. static inline int ipw2100_hw_is_adapter_in_system(struct net_device *dev)
  429. {
  430. return (dev->base_addr &&
  431. (readl
  432. ((void __iomem *)(dev->base_addr +
  433. IPW_REG_DOA_DEBUG_AREA_START))
  434. == IPW_DATA_DOA_DEBUG_VALUE));
  435. }
  436. static int ipw2100_get_ordinal(struct ipw2100_priv *priv, u32 ord,
  437. void *val, u32 * len)
  438. {
  439. struct ipw2100_ordinals *ordinals = &priv->ordinals;
  440. u32 addr;
  441. u32 field_info;
  442. u16 field_len;
  443. u16 field_count;
  444. u32 total_length;
  445. if (ordinals->table1_addr == 0) {
  446. printk(KERN_WARNING DRV_NAME ": attempt to use fw ordinals "
  447. "before they have been loaded.\n");
  448. return -EINVAL;
  449. }
  450. if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) {
  451. if (*len < IPW_ORD_TAB_1_ENTRY_SIZE) {
  452. *len = IPW_ORD_TAB_1_ENTRY_SIZE;
  453. printk(KERN_WARNING DRV_NAME
  454. ": ordinal buffer length too small, need %zd\n",
  455. IPW_ORD_TAB_1_ENTRY_SIZE);
  456. return -EINVAL;
  457. }
  458. read_nic_dword(priv->net_dev,
  459. ordinals->table1_addr + (ord << 2), &addr);
  460. read_nic_dword(priv->net_dev, addr, val);
  461. *len = IPW_ORD_TAB_1_ENTRY_SIZE;
  462. return 0;
  463. }
  464. if (IS_ORDINAL_TABLE_TWO(ordinals, ord)) {
  465. ord -= IPW_START_ORD_TAB_2;
  466. /* get the address of statistic */
  467. read_nic_dword(priv->net_dev,
  468. ordinals->table2_addr + (ord << 3), &addr);
  469. /* get the second DW of statistics ;
  470. * two 16-bit words - first is length, second is count */
  471. read_nic_dword(priv->net_dev,
  472. ordinals->table2_addr + (ord << 3) + sizeof(u32),
  473. &field_info);
  474. /* get each entry length */
  475. field_len = *((u16 *) & field_info);
  476. /* get number of entries */
  477. field_count = *(((u16 *) & field_info) + 1);
  478. /* abort if no enough memory */
  479. total_length = field_len * field_count;
  480. if (total_length > *len) {
  481. *len = total_length;
  482. return -EINVAL;
  483. }
  484. *len = total_length;
  485. if (!total_length)
  486. return 0;
  487. /* read the ordinal data from the SRAM */
  488. read_nic_memory(priv->net_dev, addr, total_length, val);
  489. return 0;
  490. }
  491. printk(KERN_WARNING DRV_NAME ": ordinal %d neither in table 1 nor "
  492. "in table 2\n", ord);
  493. return -EINVAL;
  494. }
  495. static int ipw2100_set_ordinal(struct ipw2100_priv *priv, u32 ord, u32 * val,
  496. u32 * len)
  497. {
  498. struct ipw2100_ordinals *ordinals = &priv->ordinals;
  499. u32 addr;
  500. if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) {
  501. if (*len != IPW_ORD_TAB_1_ENTRY_SIZE) {
  502. *len = IPW_ORD_TAB_1_ENTRY_SIZE;
  503. IPW_DEBUG_INFO("wrong size\n");
  504. return -EINVAL;
  505. }
  506. read_nic_dword(priv->net_dev,
  507. ordinals->table1_addr + (ord << 2), &addr);
  508. write_nic_dword(priv->net_dev, addr, *val);
  509. *len = IPW_ORD_TAB_1_ENTRY_SIZE;
  510. return 0;
  511. }
  512. IPW_DEBUG_INFO("wrong table\n");
  513. if (IS_ORDINAL_TABLE_TWO(ordinals, ord))
  514. return -EINVAL;
  515. return -EINVAL;
  516. }
  517. static char *snprint_line(char *buf, size_t count,
  518. const u8 * data, u32 len, u32 ofs)
  519. {
  520. int out, i, j, l;
  521. char c;
  522. out = snprintf(buf, count, "%08X", ofs);
  523. for (l = 0, i = 0; i < 2; i++) {
  524. out += snprintf(buf + out, count - out, " ");
  525. for (j = 0; j < 8 && l < len; j++, l++)
  526. out += snprintf(buf + out, count - out, "%02X ",
  527. data[(i * 8 + j)]);
  528. for (; j < 8; j++)
  529. out += snprintf(buf + out, count - out, " ");
  530. }
  531. out += snprintf(buf + out, count - out, " ");
  532. for (l = 0, i = 0; i < 2; i++) {
  533. out += snprintf(buf + out, count - out, " ");
  534. for (j = 0; j < 8 && l < len; j++, l++) {
  535. c = data[(i * 8 + j)];
  536. if (!isascii(c) || !isprint(c))
  537. c = '.';
  538. out += snprintf(buf + out, count - out, "%c", c);
  539. }
  540. for (; j < 8; j++)
  541. out += snprintf(buf + out, count - out, " ");
  542. }
  543. return buf;
  544. }
  545. static void printk_buf(int level, const u8 * data, u32 len)
  546. {
  547. char line[81];
  548. u32 ofs = 0;
  549. if (!(ipw2100_debug_level & level))
  550. return;
  551. while (len) {
  552. printk(KERN_DEBUG "%s\n",
  553. snprint_line(line, sizeof(line), &data[ofs],
  554. min(len, 16U), ofs));
  555. ofs += 16;
  556. len -= min(len, 16U);
  557. }
  558. }
  559. #define MAX_RESET_BACKOFF 10
  560. static void schedule_reset(struct ipw2100_priv *priv)
  561. {
  562. unsigned long now = get_seconds();
  563. /* If we haven't received a reset request within the backoff period,
  564. * then we can reset the backoff interval so this reset occurs
  565. * immediately */
  566. if (priv->reset_backoff &&
  567. (now - priv->last_reset > priv->reset_backoff))
  568. priv->reset_backoff = 0;
  569. priv->last_reset = get_seconds();
  570. if (!(priv->status & STATUS_RESET_PENDING)) {
  571. IPW_DEBUG_INFO("%s: Scheduling firmware restart (%ds).\n",
  572. priv->net_dev->name, priv->reset_backoff);
  573. netif_carrier_off(priv->net_dev);
  574. netif_stop_queue(priv->net_dev);
  575. priv->status |= STATUS_RESET_PENDING;
  576. if (priv->reset_backoff)
  577. schedule_delayed_work(&priv->reset_work,
  578. priv->reset_backoff * HZ);
  579. else
  580. schedule_delayed_work(&priv->reset_work, 0);
  581. if (priv->reset_backoff < MAX_RESET_BACKOFF)
  582. priv->reset_backoff++;
  583. wake_up_interruptible(&priv->wait_command_queue);
  584. } else
  585. IPW_DEBUG_INFO("%s: Firmware restart already in progress.\n",
  586. priv->net_dev->name);
  587. }
  588. #define HOST_COMPLETE_TIMEOUT (2 * HZ)
  589. static int ipw2100_hw_send_command(struct ipw2100_priv *priv,
  590. struct host_command *cmd)
  591. {
  592. struct list_head *element;
  593. struct ipw2100_tx_packet *packet;
  594. unsigned long flags;
  595. int err = 0;
  596. IPW_DEBUG_HC("Sending %s command (#%d), %d bytes\n",
  597. command_types[cmd->host_command], cmd->host_command,
  598. cmd->host_command_length);
  599. printk_buf(IPW_DL_HC, (u8 *) cmd->host_command_parameters,
  600. cmd->host_command_length);
  601. spin_lock_irqsave(&priv->low_lock, flags);
  602. if (priv->fatal_error) {
  603. IPW_DEBUG_INFO
  604. ("Attempt to send command while hardware in fatal error condition.\n");
  605. err = -EIO;
  606. goto fail_unlock;
  607. }
  608. if (!(priv->status & STATUS_RUNNING)) {
  609. IPW_DEBUG_INFO
  610. ("Attempt to send command while hardware is not running.\n");
  611. err = -EIO;
  612. goto fail_unlock;
  613. }
  614. if (priv->status & STATUS_CMD_ACTIVE) {
  615. IPW_DEBUG_INFO
  616. ("Attempt to send command while another command is pending.\n");
  617. err = -EBUSY;
  618. goto fail_unlock;
  619. }
  620. if (list_empty(&priv->msg_free_list)) {
  621. IPW_DEBUG_INFO("no available msg buffers\n");
  622. goto fail_unlock;
  623. }
  624. priv->status |= STATUS_CMD_ACTIVE;
  625. priv->messages_sent++;
  626. element = priv->msg_free_list.next;
  627. packet = list_entry(element, struct ipw2100_tx_packet, list);
  628. packet->jiffy_start = jiffies;
  629. /* initialize the firmware command packet */
  630. packet->info.c_struct.cmd->host_command_reg = cmd->host_command;
  631. packet->info.c_struct.cmd->host_command_reg1 = cmd->host_command1;
  632. packet->info.c_struct.cmd->host_command_len_reg =
  633. cmd->host_command_length;
  634. packet->info.c_struct.cmd->sequence = cmd->host_command_sequence;
  635. memcpy(packet->info.c_struct.cmd->host_command_params_reg,
  636. cmd->host_command_parameters,
  637. sizeof(packet->info.c_struct.cmd->host_command_params_reg));
  638. list_del(element);
  639. DEC_STAT(&priv->msg_free_stat);
  640. list_add_tail(element, &priv->msg_pend_list);
  641. INC_STAT(&priv->msg_pend_stat);
  642. ipw2100_tx_send_commands(priv);
  643. ipw2100_tx_send_data(priv);
  644. spin_unlock_irqrestore(&priv->low_lock, flags);
  645. /*
  646. * We must wait for this command to complete before another
  647. * command can be sent... but if we wait more than 3 seconds
  648. * then there is a problem.
  649. */
  650. err =
  651. wait_event_interruptible_timeout(priv->wait_command_queue,
  652. !(priv->
  653. status & STATUS_CMD_ACTIVE),
  654. HOST_COMPLETE_TIMEOUT);
  655. if (err == 0) {
  656. IPW_DEBUG_INFO("Command completion failed out after %dms.\n",
  657. 1000 * (HOST_COMPLETE_TIMEOUT / HZ));
  658. priv->fatal_error = IPW2100_ERR_MSG_TIMEOUT;
  659. priv->status &= ~STATUS_CMD_ACTIVE;
  660. schedule_reset(priv);
  661. return -EIO;
  662. }
  663. if (priv->fatal_error) {
  664. printk(KERN_WARNING DRV_NAME ": %s: firmware fatal error\n",
  665. priv->net_dev->name);
  666. return -EIO;
  667. }
  668. /* !!!!! HACK TEST !!!!!
  669. * When lots of debug trace statements are enabled, the driver
  670. * doesn't seem to have as many firmware restart cycles...
  671. *
  672. * As a test, we're sticking in a 1/100s delay here */
  673. schedule_timeout_uninterruptible(msecs_to_jiffies(10));
  674. return 0;
  675. fail_unlock:
  676. spin_unlock_irqrestore(&priv->low_lock, flags);
  677. return err;
  678. }
  679. /*
  680. * Verify the values and data access of the hardware
  681. * No locks needed or used. No functions called.
  682. */
  683. static int ipw2100_verify(struct ipw2100_priv *priv)
  684. {
  685. u32 data1, data2;
  686. u32 address;
  687. u32 val1 = 0x76543210;
  688. u32 val2 = 0xFEDCBA98;
  689. /* Domain 0 check - all values should be DOA_DEBUG */
  690. for (address = IPW_REG_DOA_DEBUG_AREA_START;
  691. address < IPW_REG_DOA_DEBUG_AREA_END; address += sizeof(u32)) {
  692. read_register(priv->net_dev, address, &data1);
  693. if (data1 != IPW_DATA_DOA_DEBUG_VALUE)
  694. return -EIO;
  695. }
  696. /* Domain 1 check - use arbitrary read/write compare */
  697. for (address = 0; address < 5; address++) {
  698. /* The memory area is not used now */
  699. write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32,
  700. val1);
  701. write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36,
  702. val2);
  703. read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32,
  704. &data1);
  705. read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36,
  706. &data2);
  707. if (val1 == data1 && val2 == data2)
  708. return 0;
  709. }
  710. return -EIO;
  711. }
  712. /*
  713. *
  714. * Loop until the CARD_DISABLED bit is the same value as the
  715. * supplied parameter
  716. *
  717. * TODO: See if it would be more efficient to do a wait/wake
  718. * cycle and have the completion event trigger the wakeup
  719. *
  720. */
  721. #define IPW_CARD_DISABLE_COMPLETE_WAIT 100 // 100 milli
  722. static int ipw2100_wait_for_card_state(struct ipw2100_priv *priv, int state)
  723. {
  724. int i;
  725. u32 card_state;
  726. u32 len = sizeof(card_state);
  727. int err;
  728. for (i = 0; i <= IPW_CARD_DISABLE_COMPLETE_WAIT * 1000; i += 50) {
  729. err = ipw2100_get_ordinal(priv, IPW_ORD_CARD_DISABLED,
  730. &card_state, &len);
  731. if (err) {
  732. IPW_DEBUG_INFO("Query of CARD_DISABLED ordinal "
  733. "failed.\n");
  734. return 0;
  735. }
  736. /* We'll break out if either the HW state says it is
  737. * in the state we want, or if HOST_COMPLETE command
  738. * finishes */
  739. if ((card_state == state) ||
  740. ((priv->status & STATUS_ENABLED) ?
  741. IPW_HW_STATE_ENABLED : IPW_HW_STATE_DISABLED) == state) {
  742. if (state == IPW_HW_STATE_ENABLED)
  743. priv->status |= STATUS_ENABLED;
  744. else
  745. priv->status &= ~STATUS_ENABLED;
  746. return 0;
  747. }
  748. udelay(50);
  749. }
  750. IPW_DEBUG_INFO("ipw2100_wait_for_card_state to %s state timed out\n",
  751. state ? "DISABLED" : "ENABLED");
  752. return -EIO;
  753. }
  754. /*********************************************************************
  755. Procedure : sw_reset_and_clock
  756. Purpose : Asserts s/w reset, asserts clock initialization
  757. and waits for clock stabilization
  758. ********************************************************************/
  759. static int sw_reset_and_clock(struct ipw2100_priv *priv)
  760. {
  761. int i;
  762. u32 r;
  763. // assert s/w reset
  764. write_register(priv->net_dev, IPW_REG_RESET_REG,
  765. IPW_AUX_HOST_RESET_REG_SW_RESET);
  766. // wait for clock stabilization
  767. for (i = 0; i < 1000; i++) {
  768. udelay(IPW_WAIT_RESET_ARC_COMPLETE_DELAY);
  769. // check clock ready bit
  770. read_register(priv->net_dev, IPW_REG_RESET_REG, &r);
  771. if (r & IPW_AUX_HOST_RESET_REG_PRINCETON_RESET)
  772. break;
  773. }
  774. if (i == 1000)
  775. return -EIO; // TODO: better error value
  776. /* set "initialization complete" bit to move adapter to
  777. * D0 state */
  778. write_register(priv->net_dev, IPW_REG_GP_CNTRL,
  779. IPW_AUX_HOST_GP_CNTRL_BIT_INIT_DONE);
  780. /* wait for clock stabilization */
  781. for (i = 0; i < 10000; i++) {
  782. udelay(IPW_WAIT_CLOCK_STABILIZATION_DELAY * 4);
  783. /* check clock ready bit */
  784. read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
  785. if (r & IPW_AUX_HOST_GP_CNTRL_BIT_CLOCK_READY)
  786. break;
  787. }
  788. if (i == 10000)
  789. return -EIO; /* TODO: better error value */
  790. /* set D0 standby bit */
  791. read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
  792. write_register(priv->net_dev, IPW_REG_GP_CNTRL,
  793. r | IPW_AUX_HOST_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
  794. return 0;
  795. }
  796. /*********************************************************************
  797. Procedure : ipw2100_download_firmware
  798. Purpose : Initiaze adapter after power on.
  799. The sequence is:
  800. 1. assert s/w reset first!
  801. 2. awake clocks & wait for clock stabilization
  802. 3. hold ARC (don't ask me why...)
  803. 4. load Dino ucode and reset/clock init again
  804. 5. zero-out shared mem
  805. 6. download f/w
  806. *******************************************************************/
  807. static int ipw2100_download_firmware(struct ipw2100_priv *priv)
  808. {
  809. u32 address;
  810. int err;
  811. #ifndef CONFIG_PM
  812. /* Fetch the firmware and microcode */
  813. struct ipw2100_fw ipw2100_firmware;
  814. #endif
  815. if (priv->fatal_error) {
  816. IPW_DEBUG_ERROR("%s: ipw2100_download_firmware called after "
  817. "fatal error %d. Interface must be brought down.\n",
  818. priv->net_dev->name, priv->fatal_error);
  819. return -EINVAL;
  820. }
  821. #ifdef CONFIG_PM
  822. if (!ipw2100_firmware.version) {
  823. err = ipw2100_get_firmware(priv, &ipw2100_firmware);
  824. if (err) {
  825. IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
  826. priv->net_dev->name, err);
  827. priv->fatal_error = IPW2100_ERR_FW_LOAD;
  828. goto fail;
  829. }
  830. }
  831. #else
  832. err = ipw2100_get_firmware(priv, &ipw2100_firmware);
  833. if (err) {
  834. IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
  835. priv->net_dev->name, err);
  836. priv->fatal_error = IPW2100_ERR_FW_LOAD;
  837. goto fail;
  838. }
  839. #endif
  840. priv->firmware_version = ipw2100_firmware.version;
  841. /* s/w reset and clock stabilization */
  842. err = sw_reset_and_clock(priv);
  843. if (err) {
  844. IPW_DEBUG_ERROR("%s: sw_reset_and_clock failed: %d\n",
  845. priv->net_dev->name, err);
  846. goto fail;
  847. }
  848. err = ipw2100_verify(priv);
  849. if (err) {
  850. IPW_DEBUG_ERROR("%s: ipw2100_verify failed: %d\n",
  851. priv->net_dev->name, err);
  852. goto fail;
  853. }
  854. /* Hold ARC */
  855. write_nic_dword(priv->net_dev,
  856. IPW_INTERNAL_REGISTER_HALT_AND_RESET, 0x80000000);
  857. /* allow ARC to run */
  858. write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
  859. /* load microcode */
  860. err = ipw2100_ucode_download(priv, &ipw2100_firmware);
  861. if (err) {
  862. printk(KERN_ERR DRV_NAME ": %s: Error loading microcode: %d\n",
  863. priv->net_dev->name, err);
  864. goto fail;
  865. }
  866. /* release ARC */
  867. write_nic_dword(priv->net_dev,
  868. IPW_INTERNAL_REGISTER_HALT_AND_RESET, 0x00000000);
  869. /* s/w reset and clock stabilization (again!!!) */
  870. err = sw_reset_and_clock(priv);
  871. if (err) {
  872. printk(KERN_ERR DRV_NAME
  873. ": %s: sw_reset_and_clock failed: %d\n",
  874. priv->net_dev->name, err);
  875. goto fail;
  876. }
  877. /* load f/w */
  878. err = ipw2100_fw_download(priv, &ipw2100_firmware);
  879. if (err) {
  880. IPW_DEBUG_ERROR("%s: Error loading firmware: %d\n",
  881. priv->net_dev->name, err);
  882. goto fail;
  883. }
  884. #ifndef CONFIG_PM
  885. /*
  886. * When the .resume method of the driver is called, the other
  887. * part of the system, i.e. the ide driver could still stay in
  888. * the suspend stage. This prevents us from loading the firmware
  889. * from the disk. --YZ
  890. */
  891. /* free any storage allocated for firmware image */
  892. ipw2100_release_firmware(priv, &ipw2100_firmware);
  893. #endif
  894. /* zero out Domain 1 area indirectly (Si requirement) */
  895. for (address = IPW_HOST_FW_SHARED_AREA0;
  896. address < IPW_HOST_FW_SHARED_AREA0_END; address += 4)
  897. write_nic_dword(priv->net_dev, address, 0);
  898. for (address = IPW_HOST_FW_SHARED_AREA1;
  899. address < IPW_HOST_FW_SHARED_AREA1_END; address += 4)
  900. write_nic_dword(priv->net_dev, address, 0);
  901. for (address = IPW_HOST_FW_SHARED_AREA2;
  902. address < IPW_HOST_FW_SHARED_AREA2_END; address += 4)
  903. write_nic_dword(priv->net_dev, address, 0);
  904. for (address = IPW_HOST_FW_SHARED_AREA3;
  905. address < IPW_HOST_FW_SHARED_AREA3_END; address += 4)
  906. write_nic_dword(priv->net_dev, address, 0);
  907. for (address = IPW_HOST_FW_INTERRUPT_AREA;
  908. address < IPW_HOST_FW_INTERRUPT_AREA_END; address += 4)
  909. write_nic_dword(priv->net_dev, address, 0);
  910. return 0;
  911. fail:
  912. ipw2100_release_firmware(priv, &ipw2100_firmware);
  913. return err;
  914. }
  915. static inline void ipw2100_enable_interrupts(struct ipw2100_priv *priv)
  916. {
  917. if (priv->status & STATUS_INT_ENABLED)
  918. return;
  919. priv->status |= STATUS_INT_ENABLED;
  920. write_register(priv->net_dev, IPW_REG_INTA_MASK, IPW_INTERRUPT_MASK);
  921. }
  922. static inline void ipw2100_disable_interrupts(struct ipw2100_priv *priv)
  923. {
  924. if (!(priv->status & STATUS_INT_ENABLED))
  925. return;
  926. priv->status &= ~STATUS_INT_ENABLED;
  927. write_register(priv->net_dev, IPW_REG_INTA_MASK, 0x0);
  928. }
  929. static void ipw2100_initialize_ordinals(struct ipw2100_priv *priv)
  930. {
  931. struct ipw2100_ordinals *ord = &priv->ordinals;
  932. IPW_DEBUG_INFO("enter\n");
  933. read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_1,
  934. &ord->table1_addr);
  935. read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_2,
  936. &ord->table2_addr);
  937. read_nic_dword(priv->net_dev, ord->table1_addr, &ord->table1_size);
  938. read_nic_dword(priv->net_dev, ord->table2_addr, &ord->table2_size);
  939. ord->table2_size &= 0x0000FFFF;
  940. IPW_DEBUG_INFO("table 1 size: %d\n", ord->table1_size);
  941. IPW_DEBUG_INFO("table 2 size: %d\n", ord->table2_size);
  942. IPW_DEBUG_INFO("exit\n");
  943. }
  944. static inline void ipw2100_hw_set_gpio(struct ipw2100_priv *priv)
  945. {
  946. u32 reg = 0;
  947. /*
  948. * Set GPIO 3 writable by FW; GPIO 1 writable
  949. * by driver and enable clock
  950. */
  951. reg = (IPW_BIT_GPIO_GPIO3_MASK | IPW_BIT_GPIO_GPIO1_ENABLE |
  952. IPW_BIT_GPIO_LED_OFF);
  953. write_register(priv->net_dev, IPW_REG_GPIO, reg);
  954. }
  955. static int rf_kill_active(struct ipw2100_priv *priv)
  956. {
  957. #define MAX_RF_KILL_CHECKS 5
  958. #define RF_KILL_CHECK_DELAY 40
  959. unsigned short value = 0;
  960. u32 reg = 0;
  961. int i;
  962. if (!(priv->hw_features & HW_FEATURE_RFKILL)) {
  963. wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, false);
  964. priv->status &= ~STATUS_RF_KILL_HW;
  965. return 0;
  966. }
  967. for (i = 0; i < MAX_RF_KILL_CHECKS; i++) {
  968. udelay(RF_KILL_CHECK_DELAY);
  969. read_register(priv->net_dev, IPW_REG_GPIO, &reg);
  970. value = (value << 1) | ((reg & IPW_BIT_GPIO_RF_KILL) ? 0 : 1);
  971. }
  972. if (value == 0) {
  973. wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
  974. priv->status |= STATUS_RF_KILL_HW;
  975. } else {
  976. wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, false);
  977. priv->status &= ~STATUS_RF_KILL_HW;
  978. }
  979. return (value == 0);
  980. }
  981. static int ipw2100_get_hw_features(struct ipw2100_priv *priv)
  982. {
  983. u32 addr, len;
  984. u32 val;
  985. /*
  986. * EEPROM_SRAM_DB_START_ADDRESS using ordinal in ordinal table 1
  987. */
  988. len = sizeof(addr);
  989. if (ipw2100_get_ordinal
  990. (priv, IPW_ORD_EEPROM_SRAM_DB_BLOCK_START_ADDRESS, &addr, &len)) {
  991. IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
  992. __LINE__);
  993. return -EIO;
  994. }
  995. IPW_DEBUG_INFO("EEPROM address: %08X\n", addr);
  996. /*
  997. * EEPROM version is the byte at offset 0xfd in firmware
  998. * We read 4 bytes, then shift out the byte we actually want */
  999. read_nic_dword(priv->net_dev, addr + 0xFC, &val);
  1000. priv->eeprom_version = (val >> 24) & 0xFF;
  1001. IPW_DEBUG_INFO("EEPROM version: %d\n", priv->eeprom_version);
  1002. /*
  1003. * HW RF Kill enable is bit 0 in byte at offset 0x21 in firmware
  1004. *
  1005. * notice that the EEPROM bit is reverse polarity, i.e.
  1006. * bit = 0 signifies HW RF kill switch is supported
  1007. * bit = 1 signifies HW RF kill switch is NOT supported
  1008. */
  1009. read_nic_dword(priv->net_dev, addr + 0x20, &val);
  1010. if (!((val >> 24) & 0x01))
  1011. priv->hw_features |= HW_FEATURE_RFKILL;
  1012. IPW_DEBUG_INFO("HW RF Kill: %ssupported.\n",
  1013. (priv->hw_features & HW_FEATURE_RFKILL) ? "" : "not ");
  1014. return 0;
  1015. }
  1016. /*
  1017. * Start firmware execution after power on and intialization
  1018. * The sequence is:
  1019. * 1. Release ARC
  1020. * 2. Wait for f/w initialization completes;
  1021. */
  1022. static int ipw2100_start_adapter(struct ipw2100_priv *priv)
  1023. {
  1024. int i;
  1025. u32 inta, inta_mask, gpio;
  1026. IPW_DEBUG_INFO("enter\n");
  1027. if (priv->status & STATUS_RUNNING)
  1028. return 0;
  1029. /*
  1030. * Initialize the hw - drive adapter to DO state by setting
  1031. * init_done bit. Wait for clk_ready bit and Download
  1032. * fw & dino ucode
  1033. */
  1034. if (ipw2100_download_firmware(priv)) {
  1035. printk(KERN_ERR DRV_NAME
  1036. ": %s: Failed to power on the adapter.\n",
  1037. priv->net_dev->name);
  1038. return -EIO;
  1039. }
  1040. /* Clear the Tx, Rx and Msg queues and the r/w indexes
  1041. * in the firmware RBD and TBD ring queue */
  1042. ipw2100_queues_initialize(priv);
  1043. ipw2100_hw_set_gpio(priv);
  1044. /* TODO -- Look at disabling interrupts here to make sure none
  1045. * get fired during FW initialization */
  1046. /* Release ARC - clear reset bit */
  1047. write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
  1048. /* wait for f/w intialization complete */
  1049. IPW_DEBUG_FW("Waiting for f/w initialization to complete...\n");
  1050. i = 5000;
  1051. do {
  1052. schedule_timeout_uninterruptible(msecs_to_jiffies(40));
  1053. /* Todo... wait for sync command ... */
  1054. read_register(priv->net_dev, IPW_REG_INTA, &inta);
  1055. /* check "init done" bit */
  1056. if (inta & IPW2100_INTA_FW_INIT_DONE) {
  1057. /* reset "init done" bit */
  1058. write_register(priv->net_dev, IPW_REG_INTA,
  1059. IPW2100_INTA_FW_INIT_DONE);
  1060. break;
  1061. }
  1062. /* check error conditions : we check these after the firmware
  1063. * check so that if there is an error, the interrupt handler
  1064. * will see it and the adapter will be reset */
  1065. if (inta &
  1066. (IPW2100_INTA_FATAL_ERROR | IPW2100_INTA_PARITY_ERROR)) {
  1067. /* clear error conditions */
  1068. write_register(priv->net_dev, IPW_REG_INTA,
  1069. IPW2100_INTA_FATAL_ERROR |
  1070. IPW2100_INTA_PARITY_ERROR);
  1071. }
  1072. } while (--i);
  1073. /* Clear out any pending INTAs since we aren't supposed to have
  1074. * interrupts enabled at this point... */
  1075. read_register(priv->net_dev, IPW_REG_INTA, &inta);
  1076. read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
  1077. inta &= IPW_INTERRUPT_MASK;
  1078. /* Clear out any pending interrupts */
  1079. if (inta & inta_mask)
  1080. write_register(priv->net_dev, IPW_REG_INTA, inta);
  1081. IPW_DEBUG_FW("f/w initialization complete: %s\n",
  1082. i ? "SUCCESS" : "FAILED");
  1083. if (!i) {
  1084. printk(KERN_WARNING DRV_NAME
  1085. ": %s: Firmware did not initialize.\n",
  1086. priv->net_dev->name);
  1087. return -EIO;
  1088. }
  1089. /* allow firmware to write to GPIO1 & GPIO3 */
  1090. read_register(priv->net_dev, IPW_REG_GPIO, &gpio);
  1091. gpio |= (IPW_BIT_GPIO_GPIO1_MASK | IPW_BIT_GPIO_GPIO3_MASK);
  1092. write_register(priv->net_dev, IPW_REG_GPIO, gpio);
  1093. /* Ready to receive commands */
  1094. priv->status |= STATUS_RUNNING;
  1095. /* The adapter has been reset; we are not associated */
  1096. priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
  1097. IPW_DEBUG_INFO("exit\n");
  1098. return 0;
  1099. }
  1100. static inline void ipw2100_reset_fatalerror(struct ipw2100_priv *priv)
  1101. {
  1102. if (!priv->fatal_error)
  1103. return;
  1104. priv->fatal_errors[priv->fatal_index++] = priv->fatal_error;
  1105. priv->fatal_index %= IPW2100_ERROR_QUEUE;
  1106. priv->fatal_error = 0;
  1107. }
  1108. /* NOTE: Our interrupt is disabled when this method is called */
  1109. static int ipw2100_power_cycle_adapter(struct ipw2100_priv *priv)
  1110. {
  1111. u32 reg;
  1112. int i;
  1113. IPW_DEBUG_INFO("Power cycling the hardware.\n");
  1114. ipw2100_hw_set_gpio(priv);
  1115. /* Step 1. Stop Master Assert */
  1116. write_register(priv->net_dev, IPW_REG_RESET_REG,
  1117. IPW_AUX_HOST_RESET_REG_STOP_MASTER);
  1118. /* Step 2. Wait for stop Master Assert
  1119. * (not more than 50us, otherwise ret error */
  1120. i = 5;
  1121. do {
  1122. udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
  1123. read_register(priv->net_dev, IPW_REG_RESET_REG, &reg);
  1124. if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
  1125. break;
  1126. } while (--i);
  1127. priv->status &= ~STATUS_RESET_PENDING;
  1128. if (!i) {
  1129. IPW_DEBUG_INFO
  1130. ("exit - waited too long for master assert stop\n");
  1131. return -EIO;
  1132. }
  1133. write_register(priv->net_dev, IPW_REG_RESET_REG,
  1134. IPW_AUX_HOST_RESET_REG_SW_RESET);
  1135. /* Reset any fatal_error conditions */
  1136. ipw2100_reset_fatalerror(priv);
  1137. /* At this point, the adapter is now stopped and disabled */
  1138. priv->status &= ~(STATUS_RUNNING | STATUS_ASSOCIATING |
  1139. STATUS_ASSOCIATED | STATUS_ENABLED);
  1140. return 0;
  1141. }
  1142. /*
  1143. * Send the CARD_DISABLE_PHY_OFF command to the card to disable it
  1144. *
  1145. * After disabling, if the card was associated, a STATUS_ASSN_LOST will be sent.
  1146. *
  1147. * STATUS_CARD_DISABLE_NOTIFICATION will be sent regardless of
  1148. * if STATUS_ASSN_LOST is sent.
  1149. */
  1150. static int ipw2100_hw_phy_off(struct ipw2100_priv *priv)
  1151. {
  1152. #define HW_PHY_OFF_LOOP_DELAY (HZ / 5000)
  1153. struct host_command cmd = {
  1154. .host_command = CARD_DISABLE_PHY_OFF,
  1155. .host_command_sequence = 0,
  1156. .host_command_length = 0,
  1157. };
  1158. int err, i;
  1159. u32 val1, val2;
  1160. IPW_DEBUG_HC("CARD_DISABLE_PHY_OFF\n");
  1161. /* Turn off the radio */
  1162. err = ipw2100_hw_send_command(priv, &cmd);
  1163. if (err)
  1164. return err;
  1165. for (i = 0; i < 2500; i++) {
  1166. read_nic_dword(priv->net_dev, IPW2100_CONTROL_REG, &val1);
  1167. read_nic_dword(priv->net_dev, IPW2100_COMMAND, &val2);
  1168. if ((val1 & IPW2100_CONTROL_PHY_OFF) &&
  1169. (val2 & IPW2100_COMMAND_PHY_OFF))
  1170. return 0;
  1171. schedule_timeout_uninterruptible(HW_PHY_OFF_LOOP_DELAY);
  1172. }
  1173. return -EIO;
  1174. }
  1175. static int ipw2100_enable_adapter(struct ipw2100_priv *priv)
  1176. {
  1177. struct host_command cmd = {
  1178. .host_command = HOST_COMPLETE,
  1179. .host_command_sequence = 0,
  1180. .host_command_length = 0
  1181. };
  1182. int err = 0;
  1183. IPW_DEBUG_HC("HOST_COMPLETE\n");
  1184. if (priv->status & STATUS_ENABLED)
  1185. return 0;
  1186. mutex_lock(&priv->adapter_mutex);
  1187. if (rf_kill_active(priv)) {
  1188. IPW_DEBUG_HC("Command aborted due to RF kill active.\n");
  1189. goto fail_up;
  1190. }
  1191. err = ipw2100_hw_send_command(priv, &cmd);
  1192. if (err) {
  1193. IPW_DEBUG_INFO("Failed to send HOST_COMPLETE command\n");
  1194. goto fail_up;
  1195. }
  1196. err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_ENABLED);
  1197. if (err) {
  1198. IPW_DEBUG_INFO("%s: card not responding to init command.\n",
  1199. priv->net_dev->name);
  1200. goto fail_up;
  1201. }
  1202. if (priv->stop_hang_check) {
  1203. priv->stop_hang_check = 0;
  1204. schedule_delayed_work(&priv->hang_check, HZ / 2);
  1205. }
  1206. fail_up:
  1207. mutex_unlock(&priv->adapter_mutex);
  1208. return err;
  1209. }
  1210. static int ipw2100_hw_stop_adapter(struct ipw2100_priv *priv)
  1211. {
  1212. #define HW_POWER_DOWN_DELAY (msecs_to_jiffies(100))
  1213. struct host_command cmd = {
  1214. .host_command = HOST_PRE_POWER_DOWN,
  1215. .host_command_sequence = 0,
  1216. .host_command_length = 0,
  1217. };
  1218. int err, i;
  1219. u32 reg;
  1220. if (!(priv->status & STATUS_RUNNING))
  1221. return 0;
  1222. priv->status |= STATUS_STOPPING;
  1223. /* We can only shut down the card if the firmware is operational. So,
  1224. * if we haven't reset since a fatal_error, then we can not send the
  1225. * shutdown commands. */
  1226. if (!priv->fatal_error) {
  1227. /* First, make sure the adapter is enabled so that the PHY_OFF
  1228. * command can shut it down */
  1229. ipw2100_enable_adapter(priv);
  1230. err = ipw2100_hw_phy_off(priv);
  1231. if (err)
  1232. printk(KERN_WARNING DRV_NAME
  1233. ": Error disabling radio %d\n", err);
  1234. /*
  1235. * If in D0-standby mode going directly to D3 may cause a
  1236. * PCI bus violation. Therefore we must change out of the D0
  1237. * state.
  1238. *
  1239. * Sending the PREPARE_FOR_POWER_DOWN will restrict the
  1240. * hardware from going into standby mode and will transition
  1241. * out of D0-standby if it is already in that state.
  1242. *
  1243. * STATUS_PREPARE_POWER_DOWN_COMPLETE will be sent by the
  1244. * driver upon completion. Once received, the driver can
  1245. * proceed to the D3 state.
  1246. *
  1247. * Prepare for power down command to fw. This command would
  1248. * take HW out of D0-standby and prepare it for D3 state.
  1249. *
  1250. * Currently FW does not support event notification for this
  1251. * event. Therefore, skip waiting for it. Just wait a fixed
  1252. * 100ms
  1253. */
  1254. IPW_DEBUG_HC("HOST_PRE_POWER_DOWN\n");
  1255. err = ipw2100_hw_send_command(priv, &cmd);
  1256. if (err)
  1257. printk(KERN_WARNING DRV_NAME ": "
  1258. "%s: Power down command failed: Error %d\n",
  1259. priv->net_dev->name, err);
  1260. else
  1261. schedule_timeout_uninterruptible(HW_POWER_DOWN_DELAY);
  1262. }
  1263. priv->status &= ~STATUS_ENABLED;
  1264. /*
  1265. * Set GPIO 3 writable by FW; GPIO 1 writable
  1266. * by driver and enable clock
  1267. */
  1268. ipw2100_hw_set_gpio(priv);
  1269. /*
  1270. * Power down adapter. Sequence:
  1271. * 1. Stop master assert (RESET_REG[9]=1)
  1272. * 2. Wait for stop master (RESET_REG[8]==1)
  1273. * 3. S/w reset assert (RESET_REG[7] = 1)
  1274. */
  1275. /* Stop master assert */
  1276. write_register(priv->net_dev, IPW_REG_RESET_REG,
  1277. IPW_AUX_HOST_RESET_REG_STOP_MASTER);
  1278. /* wait stop master not more than 50 usec.
  1279. * Otherwise return error. */
  1280. for (i = 5; i > 0; i--) {
  1281. udelay(10);
  1282. /* Check master stop bit */
  1283. read_register(priv->net_dev, IPW_REG_RESET_REG, &reg);
  1284. if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
  1285. break;
  1286. }
  1287. if (i == 0)
  1288. printk(KERN_WARNING DRV_NAME
  1289. ": %s: Could now power down adapter.\n",
  1290. priv->net_dev->name);
  1291. /* assert s/w reset */
  1292. write_register(priv->net_dev, IPW_REG_RESET_REG,
  1293. IPW_AUX_HOST_RESET_REG_SW_RESET);
  1294. priv->status &= ~(STATUS_RUNNING | STATUS_STOPPING);
  1295. return 0;
  1296. }
  1297. static int ipw2100_disable_adapter(struct ipw2100_priv *priv)
  1298. {
  1299. struct host_command cmd = {
  1300. .host_command = CARD_DISABLE,
  1301. .host_command_sequence = 0,
  1302. .host_command_length = 0
  1303. };
  1304. int err = 0;
  1305. IPW_DEBUG_HC("CARD_DISABLE\n");
  1306. if (!(priv->status & STATUS_ENABLED))
  1307. return 0;
  1308. /* Make sure we clear the associated state */
  1309. priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
  1310. if (!priv->stop_hang_check) {
  1311. priv->stop_hang_check = 1;
  1312. cancel_delayed_work(&priv->hang_check);
  1313. }
  1314. mutex_lock(&priv->adapter_mutex);
  1315. err = ipw2100_hw_send_command(priv, &cmd);
  1316. if (err) {
  1317. printk(KERN_WARNING DRV_NAME
  1318. ": exit - failed to send CARD_DISABLE command\n");
  1319. goto fail_up;
  1320. }
  1321. err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_DISABLED);
  1322. if (err) {
  1323. printk(KERN_WARNING DRV_NAME
  1324. ": exit - card failed to change to DISABLED\n");
  1325. goto fail_up;
  1326. }
  1327. IPW_DEBUG_INFO("TODO: implement scan state machine\n");
  1328. fail_up:
  1329. mutex_unlock(&priv->adapter_mutex);
  1330. return err;
  1331. }
  1332. static int ipw2100_set_scan_options(struct ipw2100_priv *priv)
  1333. {
  1334. struct host_command cmd = {
  1335. .host_command = SET_SCAN_OPTIONS,
  1336. .host_command_sequence = 0,
  1337. .host_command_length = 8
  1338. };
  1339. int err;
  1340. IPW_DEBUG_INFO("enter\n");
  1341. IPW_DEBUG_SCAN("setting scan options\n");
  1342. cmd.host_command_parameters[0] = 0;
  1343. if (!(priv->config & CFG_ASSOCIATE))
  1344. cmd.host_command_parameters[0] |= IPW_SCAN_NOASSOCIATE;
  1345. if ((priv->ieee->sec.flags & SEC_ENABLED) && priv->ieee->sec.enabled)
  1346. cmd.host_command_parameters[0] |= IPW_SCAN_MIXED_CELL;
  1347. if (priv->config & CFG_PASSIVE_SCAN)
  1348. cmd.host_command_parameters[0] |= IPW_SCAN_PASSIVE;
  1349. cmd.host_command_parameters[1] = priv->channel_mask;
  1350. err = ipw2100_hw_send_command(priv, &cmd);
  1351. IPW_DEBUG_HC("SET_SCAN_OPTIONS 0x%04X\n",
  1352. cmd.host_command_parameters[0]);
  1353. return err;
  1354. }
  1355. static int ipw2100_start_scan(struct ipw2100_priv *priv)
  1356. {
  1357. struct host_command cmd = {
  1358. .host_command = BROADCAST_SCAN,
  1359. .host_command_sequence = 0,
  1360. .host_command_length = 4
  1361. };
  1362. int err;
  1363. IPW_DEBUG_HC("START_SCAN\n");
  1364. cmd.host_command_parameters[0] = 0;
  1365. /* No scanning if in monitor mode */
  1366. if (priv->ieee->iw_mode == IW_MODE_MONITOR)
  1367. return 1;
  1368. if (priv->status & STATUS_SCANNING) {
  1369. IPW_DEBUG_SCAN("Scan requested while already in scan...\n");
  1370. return 0;
  1371. }
  1372. IPW_DEBUG_INFO("enter\n");
  1373. /* Not clearing here; doing so makes iwlist always return nothing...
  1374. *
  1375. * We should modify the table logic to use aging tables vs. clearing
  1376. * the table on each scan start.
  1377. */
  1378. IPW_DEBUG_SCAN("starting scan\n");
  1379. priv->status |= STATUS_SCANNING;
  1380. err = ipw2100_hw_send_command(priv, &cmd);
  1381. if (err)
  1382. priv->status &= ~STATUS_SCANNING;
  1383. IPW_DEBUG_INFO("exit\n");
  1384. return err;
  1385. }
  1386. static const struct libipw_geo ipw_geos[] = {
  1387. { /* Restricted */
  1388. "---",
  1389. .bg_channels = 14,
  1390. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  1391. {2427, 4}, {2432, 5}, {2437, 6},
  1392. {2442, 7}, {2447, 8}, {2452, 9},
  1393. {2457, 10}, {2462, 11}, {2467, 12},
  1394. {2472, 13}, {2484, 14}},
  1395. },
  1396. };
  1397. static int ipw2100_up(struct ipw2100_priv *priv, int deferred)
  1398. {
  1399. unsigned long flags;
  1400. int rc = 0;
  1401. u32 lock;
  1402. u32 ord_len = sizeof(lock);
  1403. /* Age scan list entries found before suspend */
  1404. if (priv->suspend_time) {
  1405. libipw_networks_age(priv->ieee, priv->suspend_time);
  1406. priv->suspend_time = 0;
  1407. }
  1408. /* Quiet if manually disabled. */
  1409. if (priv->status & STATUS_RF_KILL_SW) {
  1410. IPW_DEBUG_INFO("%s: Radio is disabled by Manual Disable "
  1411. "switch\n", priv->net_dev->name);
  1412. return 0;
  1413. }
  1414. /* the ipw2100 hardware really doesn't want power management delays
  1415. * longer than 175usec
  1416. */
  1417. pm_qos_update_request(&ipw2100_pm_qos_req, 175);
  1418. /* If the interrupt is enabled, turn it off... */
  1419. spin_lock_irqsave(&priv->low_lock, flags);
  1420. ipw2100_disable_interrupts(priv);
  1421. /* Reset any fatal_error conditions */
  1422. ipw2100_reset_fatalerror(priv);
  1423. spin_unlock_irqrestore(&priv->low_lock, flags);
  1424. if (priv->status & STATUS_POWERED ||
  1425. (priv->status & STATUS_RESET_PENDING)) {
  1426. /* Power cycle the card ... */
  1427. if (ipw2100_power_cycle_adapter(priv)) {
  1428. printk(KERN_WARNING DRV_NAME
  1429. ": %s: Could not cycle adapter.\n",
  1430. priv->net_dev->name);
  1431. rc = 1;
  1432. goto exit;
  1433. }
  1434. } else
  1435. priv->status |= STATUS_POWERED;
  1436. /* Load the firmware, start the clocks, etc. */
  1437. if (ipw2100_start_adapter(priv)) {
  1438. printk(KERN_ERR DRV_NAME
  1439. ": %s: Failed to start the firmware.\n",
  1440. priv->net_dev->name);
  1441. rc = 1;
  1442. goto exit;
  1443. }
  1444. ipw2100_initialize_ordinals(priv);
  1445. /* Determine capabilities of this particular HW configuration */
  1446. if (ipw2100_get_hw_features(priv)) {
  1447. printk(KERN_ERR DRV_NAME
  1448. ": %s: Failed to determine HW features.\n",
  1449. priv->net_dev->name);
  1450. rc = 1;
  1451. goto exit;
  1452. }
  1453. /* Initialize the geo */
  1454. if (libipw_set_geo(priv->ieee, &ipw_geos[0])) {
  1455. printk(KERN_WARNING DRV_NAME "Could not set geo\n");
  1456. return 0;
  1457. }
  1458. priv->ieee->freq_band = LIBIPW_24GHZ_BAND;
  1459. lock = LOCK_NONE;
  1460. if (ipw2100_set_ordinal(priv, IPW_ORD_PERS_DB_LOCK, &lock, &ord_len)) {
  1461. printk(KERN_ERR DRV_NAME
  1462. ": %s: Failed to clear ordinal lock.\n",
  1463. priv->net_dev->name);
  1464. rc = 1;
  1465. goto exit;
  1466. }
  1467. priv->status &= ~STATUS_SCANNING;
  1468. if (rf_kill_active(priv)) {
  1469. printk(KERN_INFO "%s: Radio is disabled by RF switch.\n",
  1470. priv->net_dev->name);
  1471. if (priv->stop_rf_kill) {
  1472. priv->stop_rf_kill = 0;
  1473. schedule_delayed_work(&priv->rf_kill,
  1474. round_jiffies_relative(HZ));
  1475. }
  1476. deferred = 1;
  1477. }
  1478. /* Turn on the interrupt so that commands can be processed */
  1479. ipw2100_enable_interrupts(priv);
  1480. /* Send all of the commands that must be sent prior to
  1481. * HOST_COMPLETE */
  1482. if (ipw2100_adapter_setup(priv)) {
  1483. printk(KERN_ERR DRV_NAME ": %s: Failed to start the card.\n",
  1484. priv->net_dev->name);
  1485. rc = 1;
  1486. goto exit;
  1487. }
  1488. if (!deferred) {
  1489. /* Enable the adapter - sends HOST_COMPLETE */
  1490. if (ipw2100_enable_adapter(priv)) {
  1491. printk(KERN_ERR DRV_NAME ": "
  1492. "%s: failed in call to enable adapter.\n",
  1493. priv->net_dev->name);
  1494. ipw2100_hw_stop_adapter(priv);
  1495. rc = 1;
  1496. goto exit;
  1497. }
  1498. /* Start a scan . . . */
  1499. ipw2100_set_scan_options(priv);
  1500. ipw2100_start_scan(priv);
  1501. }
  1502. exit:
  1503. return rc;
  1504. }
  1505. static void ipw2100_down(struct ipw2100_priv *priv)
  1506. {
  1507. unsigned long flags;
  1508. union iwreq_data wrqu = {
  1509. .ap_addr = {
  1510. .sa_family = ARPHRD_ETHER}
  1511. };
  1512. int associated = priv->status & STATUS_ASSOCIATED;
  1513. /* Kill the RF switch timer */
  1514. if (!priv->stop_rf_kill) {
  1515. priv->stop_rf_kill = 1;
  1516. cancel_delayed_work(&priv->rf_kill);
  1517. }
  1518. /* Kill the firmware hang check timer */
  1519. if (!priv->stop_hang_check) {
  1520. priv->stop_hang_check = 1;
  1521. cancel_delayed_work(&priv->hang_check);
  1522. }
  1523. /* Kill any pending resets */
  1524. if (priv->status & STATUS_RESET_PENDING)
  1525. cancel_delayed_work(&priv->reset_work);
  1526. /* Make sure the interrupt is on so that FW commands will be
  1527. * processed correctly */
  1528. spin_lock_irqsave(&priv->low_lock, flags);
  1529. ipw2100_enable_interrupts(priv);
  1530. spin_unlock_irqrestore(&priv->low_lock, flags);
  1531. if (ipw2100_hw_stop_adapter(priv))
  1532. printk(KERN_ERR DRV_NAME ": %s: Error stopping adapter.\n",
  1533. priv->net_dev->name);
  1534. /* Do not disable the interrupt until _after_ we disable
  1535. * the adaptor. Otherwise the CARD_DISABLE command will never
  1536. * be ack'd by the firmware */
  1537. spin_lock_irqsave(&priv->low_lock, flags);
  1538. ipw2100_disable_interrupts(priv);
  1539. spin_unlock_irqrestore(&priv->low_lock, flags);
  1540. pm_qos_update_request(&ipw2100_pm_qos_req, PM_QOS_DEFAULT_VALUE);
  1541. /* We have to signal any supplicant if we are disassociating */
  1542. if (associated)
  1543. wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
  1544. priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
  1545. netif_carrier_off(priv->net_dev);
  1546. netif_stop_queue(priv->net_dev);
  1547. }
  1548. /* Called by register_netdev() */
  1549. static int ipw2100_net_init(struct net_device *dev)
  1550. {
  1551. struct ipw2100_priv *priv = libipw_priv(dev);
  1552. return ipw2100_up(priv, 1);
  1553. }
  1554. static int ipw2100_wdev_init(struct net_device *dev)
  1555. {
  1556. struct ipw2100_priv *priv = libipw_priv(dev);
  1557. const struct libipw_geo *geo = libipw_get_geo(priv->ieee);
  1558. struct wireless_dev *wdev = &priv->ieee->wdev;
  1559. int i;
  1560. memcpy(wdev->wiphy->perm_addr, priv->mac_addr, ETH_ALEN);
  1561. /* fill-out priv->ieee->bg_band */
  1562. if (geo->bg_channels) {
  1563. struct ieee80211_supported_band *bg_band = &priv->ieee->bg_band;
  1564. bg_band->band = IEEE80211_BAND_2GHZ;
  1565. bg_band->n_channels = geo->bg_channels;
  1566. bg_band->channels = kcalloc(geo->bg_channels,
  1567. sizeof(struct ieee80211_channel),
  1568. GFP_KERNEL);
  1569. if (!bg_band->channels) {
  1570. ipw2100_down(priv);
  1571. return -ENOMEM;
  1572. }
  1573. /* translate geo->bg to bg_band.channels */
  1574. for (i = 0; i < geo->bg_channels; i++) {
  1575. bg_band->channels[i].band = IEEE80211_BAND_2GHZ;
  1576. bg_band->channels[i].center_freq = geo->bg[i].freq;
  1577. bg_band->channels[i].hw_value = geo->bg[i].channel;
  1578. bg_band->channels[i].max_power = geo->bg[i].max_power;
  1579. if (geo->bg[i].flags & LIBIPW_CH_PASSIVE_ONLY)
  1580. bg_band->channels[i].flags |=
  1581. IEEE80211_CHAN_PASSIVE_SCAN;
  1582. if (geo->bg[i].flags & LIBIPW_CH_NO_IBSS)
  1583. bg_band->channels[i].flags |=
  1584. IEEE80211_CHAN_NO_IBSS;
  1585. if (geo->bg[i].flags & LIBIPW_CH_RADAR_DETECT)
  1586. bg_band->channels[i].flags |=
  1587. IEEE80211_CHAN_RADAR;
  1588. /* No equivalent for LIBIPW_CH_80211H_RULES,
  1589. LIBIPW_CH_UNIFORM_SPREADING, or
  1590. LIBIPW_CH_B_ONLY... */
  1591. }
  1592. /* point at bitrate info */
  1593. bg_band->bitrates = ipw2100_bg_rates;
  1594. bg_band->n_bitrates = RATE_COUNT;
  1595. wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = bg_band;
  1596. }
  1597. wdev->wiphy->cipher_suites = ipw_cipher_suites;
  1598. wdev->wiphy->n_cipher_suites = ARRAY_SIZE(ipw_cipher_suites);
  1599. set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev);
  1600. if (wiphy_register(wdev->wiphy)) {
  1601. ipw2100_down(priv);
  1602. return -EIO;
  1603. }
  1604. return 0;
  1605. }
  1606. static void ipw2100_reset_adapter(struct work_struct *work)
  1607. {
  1608. struct ipw2100_priv *priv =
  1609. container_of(work, struct ipw2100_priv, reset_work.work);
  1610. unsigned long flags;
  1611. union iwreq_data wrqu = {
  1612. .ap_addr = {
  1613. .sa_family = ARPHRD_ETHER}
  1614. };
  1615. int associated = priv->status & STATUS_ASSOCIATED;
  1616. spin_lock_irqsave(&priv->low_lock, flags);
  1617. IPW_DEBUG_INFO(": %s: Restarting adapter.\n", priv->net_dev->name);
  1618. priv->resets++;
  1619. priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
  1620. priv->status |= STATUS_SECURITY_UPDATED;
  1621. /* Force a power cycle even if interface hasn't been opened
  1622. * yet */
  1623. cancel_delayed_work(&priv->reset_work);
  1624. priv->status |= STATUS_RESET_PENDING;
  1625. spin_unlock_irqrestore(&priv->low_lock, flags);
  1626. mutex_lock(&priv->action_mutex);
  1627. /* stop timed checks so that they don't interfere with reset */
  1628. priv->stop_hang_check = 1;
  1629. cancel_delayed_work(&priv->hang_check);
  1630. /* We have to signal any supplicant if we are disassociating */
  1631. if (associated)
  1632. wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
  1633. ipw2100_up(priv, 0);
  1634. mutex_unlock(&priv->action_mutex);
  1635. }
  1636. static void isr_indicate_associated(struct ipw2100_priv *priv, u32 status)
  1637. {
  1638. #define MAC_ASSOCIATION_READ_DELAY (HZ)
  1639. int ret;
  1640. unsigned int len, essid_len;
  1641. char essid[IW_ESSID_MAX_SIZE];
  1642. u32 txrate;
  1643. u32 chan;
  1644. char *txratename;
  1645. u8 bssid[ETH_ALEN];
  1646. DECLARE_SSID_BUF(ssid);
  1647. /*
  1648. * TBD: BSSID is usually 00:00:00:00:00:00 here and not
  1649. * an actual MAC of the AP. Seems like FW sets this
  1650. * address too late. Read it later and expose through
  1651. * /proc or schedule a later task to query and update
  1652. */
  1653. essid_len = IW_ESSID_MAX_SIZE;
  1654. ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID,
  1655. essid, &essid_len);
  1656. if (ret) {
  1657. IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
  1658. __LINE__);
  1659. return;
  1660. }
  1661. len = sizeof(u32);
  1662. ret = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &txrate, &len);
  1663. if (ret) {
  1664. IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
  1665. __LINE__);
  1666. return;
  1667. }
  1668. len = sizeof(u32);
  1669. ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &len);
  1670. if (ret) {
  1671. IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
  1672. __LINE__);
  1673. return;
  1674. }
  1675. len = ETH_ALEN;
  1676. ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID, &bssid, &len);
  1677. if (ret) {
  1678. IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
  1679. __LINE__);
  1680. return;
  1681. }
  1682. memcpy(priv->ieee->bssid, bssid, ETH_ALEN);
  1683. switch (txrate) {
  1684. case TX_RATE_1_MBIT:
  1685. txratename = "1Mbps";
  1686. break;
  1687. case TX_RATE_2_MBIT:
  1688. txratename = "2Mbsp";
  1689. break;
  1690. case TX_RATE_5_5_MBIT:
  1691. txratename = "5.5Mbps";
  1692. break;
  1693. case TX_RATE_11_MBIT:
  1694. txratename = "11Mbps";
  1695. break;
  1696. default:
  1697. IPW_DEBUG_INFO("Unknown rate: %d\n", txrate);
  1698. txratename = "unknown rate";
  1699. break;
  1700. }
  1701. IPW_DEBUG_INFO("%s: Associated with '%s' at %s, channel %d (BSSID=%pM)\n",
  1702. priv->net_dev->name, print_ssid(ssid, essid, essid_len),
  1703. txratename, chan, bssid);
  1704. /* now we copy read ssid into dev */
  1705. if (!(priv->config & CFG_STATIC_ESSID)) {
  1706. priv->essid_len = min((u8) essid_len, (u8) IW_ESSID_MAX_SIZE);
  1707. memcpy(priv->essid, essid, priv->essid_len);
  1708. }
  1709. priv->channel = chan;
  1710. memcpy(priv->bssid, bssid, ETH_ALEN);
  1711. priv->status |= STATUS_ASSOCIATING;
  1712. priv->connect_start = get_seconds();
  1713. schedule_delayed_work(&priv->wx_event_work, HZ / 10);
  1714. }
  1715. static int ipw2100_set_essid(struct ipw2100_priv *priv, char *essid,
  1716. int length, int batch_mode)
  1717. {
  1718. int ssid_len = min(length, IW_ESSID_MAX_SIZE);
  1719. struct host_command cmd = {
  1720. .host_command = SSID,
  1721. .host_command_sequence = 0,
  1722. .host_command_length = ssid_len
  1723. };
  1724. int err;
  1725. DECLARE_SSID_BUF(ssid);
  1726. IPW_DEBUG_HC("SSID: '%s'\n", print_ssid(ssid, essid, ssid_len));
  1727. if (ssid_len)
  1728. memcpy(cmd.host_command_parameters, essid, ssid_len);
  1729. if (!batch_mode) {
  1730. err = ipw2100_disable_adapter(priv);
  1731. if (err)
  1732. return err;
  1733. }
  1734. /* Bug in FW currently doesn't honor bit 0 in SET_SCAN_OPTIONS to
  1735. * disable auto association -- so we cheat by setting a bogus SSID */
  1736. if (!ssid_len && !(priv->config & CFG_ASSOCIATE)) {
  1737. int i;
  1738. u8 *bogus = (u8 *) cmd.host_command_parameters;
  1739. for (i = 0; i < IW_ESSID_MAX_SIZE; i++)
  1740. bogus[i] = 0x18 + i;
  1741. cmd.host_command_length = IW_ESSID_MAX_SIZE;
  1742. }
  1743. /* NOTE: We always send the SSID command even if the provided ESSID is
  1744. * the same as what we currently think is set. */
  1745. err = ipw2100_hw_send_command(priv, &cmd);
  1746. if (!err) {
  1747. memset(priv->essid + ssid_len, 0, IW_ESSID_MAX_SIZE - ssid_len);
  1748. memcpy(priv->essid, essid, ssid_len);
  1749. priv->essid_len = ssid_len;
  1750. }
  1751. if (!batch_mode) {
  1752. if (ipw2100_enable_adapter(priv))
  1753. err = -EIO;
  1754. }
  1755. return err;
  1756. }
  1757. static void isr_indicate_association_lost(struct ipw2100_priv *priv, u32 status)
  1758. {
  1759. DECLARE_SSID_BUF(ssid);
  1760. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
  1761. "disassociated: '%s' %pM\n",
  1762. print_ssid(ssid, priv->essid, priv->essid_len),
  1763. priv->bssid);
  1764. priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
  1765. if (priv->status & STATUS_STOPPING) {
  1766. IPW_DEBUG_INFO("Card is stopping itself, discard ASSN_LOST.\n");
  1767. return;
  1768. }
  1769. memset(priv->bssid, 0, ETH_ALEN);
  1770. memset(priv->ieee->bssid, 0, ETH_ALEN);
  1771. netif_carrier_off(priv->net_dev);
  1772. netif_stop_queue(priv->net_dev);
  1773. if (!(priv->status & STATUS_RUNNING))
  1774. return;
  1775. if (priv->status & STATUS_SECURITY_UPDATED)
  1776. schedule_delayed_work(&priv->security_work, 0);
  1777. schedule_delayed_work(&priv->wx_event_work, 0);
  1778. }
  1779. static void isr_indicate_rf_kill(struct ipw2100_priv *priv, u32 status)
  1780. {
  1781. IPW_DEBUG_INFO("%s: RF Kill state changed to radio OFF.\n",
  1782. priv->net_dev->name);
  1783. /* RF_KILL is now enabled (else we wouldn't be here) */
  1784. wiphy_rfkill_set_hw_state(priv->ieee->wdev.wiphy, true);
  1785. priv->status |= STATUS_RF_KILL_HW;
  1786. /* Make sure the RF Kill check timer is running */
  1787. priv->stop_rf_kill = 0;
  1788. cancel_delayed_work(&priv->rf_kill);
  1789. schedule_delayed_work(&priv->rf_kill, round_jiffies_relative(HZ));
  1790. }
  1791. static void send_scan_event(void *data)
  1792. {
  1793. struct ipw2100_priv *priv = data;
  1794. union iwreq_data wrqu;
  1795. wrqu.data.length = 0;
  1796. wrqu.data.flags = 0;
  1797. wireless_send_event(priv->net_dev, SIOCGIWSCAN, &wrqu, NULL);
  1798. }
  1799. static void ipw2100_scan_event_later(struct work_struct *work)
  1800. {
  1801. send_scan_event(container_of(work, struct ipw2100_priv,
  1802. scan_event_later.work));
  1803. }
  1804. static void ipw2100_scan_event_now(struct work_struct *work)
  1805. {
  1806. send_scan_event(container_of(work, struct ipw2100_priv,
  1807. scan_event_now));
  1808. }
  1809. static void isr_scan_complete(struct ipw2100_priv *priv, u32 status)
  1810. {
  1811. IPW_DEBUG_SCAN("scan complete\n");
  1812. /* Age the scan results... */
  1813. priv->ieee->scans++;
  1814. priv->status &= ~STATUS_SCANNING;
  1815. /* Only userspace-requested scan completion events go out immediately */
  1816. if (!priv->user_requested_scan) {
  1817. if (!delayed_work_pending(&priv->scan_event_later))
  1818. schedule_delayed_work(&priv->scan_event_later,
  1819. round_jiffies_relative(msecs_to_jiffies(4000)));
  1820. } else {
  1821. priv->user_requested_scan = 0;
  1822. cancel_delayed_work(&priv->scan_event_later);
  1823. schedule_work(&priv->scan_event_now);
  1824. }
  1825. }
  1826. #ifdef CONFIG_IPW2100_DEBUG
  1827. #define IPW2100_HANDLER(v, f) { v, f, # v }
  1828. struct ipw2100_status_indicator {
  1829. int status;
  1830. void (*cb) (struct ipw2100_priv * priv, u32 status);
  1831. char *name;
  1832. };
  1833. #else
  1834. #define IPW2100_HANDLER(v, f) { v, f }
  1835. struct ipw2100_status_indicator {
  1836. int status;
  1837. void (*cb) (struct ipw2100_priv * priv, u32 status);
  1838. };
  1839. #endif /* CONFIG_IPW2100_DEBUG */
  1840. static void isr_indicate_scanning(struct ipw2100_priv *priv, u32 status)
  1841. {
  1842. IPW_DEBUG_SCAN("Scanning...\n");
  1843. priv->status |= STATUS_SCANNING;
  1844. }
  1845. static const struct ipw2100_status_indicator status_handlers[] = {
  1846. IPW2100_HANDLER(IPW_STATE_INITIALIZED, NULL),
  1847. IPW2100_HANDLER(IPW_STATE_COUNTRY_FOUND, NULL),
  1848. IPW2100_HANDLER(IPW_STATE_ASSOCIATED, isr_indicate_associated),
  1849. IPW2100_HANDLER(IPW_STATE_ASSN_LOST, isr_indicate_association_lost),
  1850. IPW2100_HANDLER(IPW_STATE_ASSN_CHANGED, NULL),
  1851. IPW2100_HANDLER(IPW_STATE_SCAN_COMPLETE, isr_scan_complete),
  1852. IPW2100_HANDLER(IPW_STATE_ENTERED_PSP, NULL),
  1853. IPW2100_HANDLER(IPW_STATE_LEFT_PSP, NULL),
  1854. IPW2100_HANDLER(IPW_STATE_RF_KILL, isr_indicate_rf_kill),
  1855. IPW2100_HANDLER(IPW_STATE_DISABLED, NULL),
  1856. IPW2100_HANDLER(IPW_STATE_POWER_DOWN, NULL),
  1857. IPW2100_HANDLER(IPW_STATE_SCANNING, isr_indicate_scanning),
  1858. IPW2100_HANDLER(-1, NULL)
  1859. };
  1860. static void isr_status_change(struct ipw2100_priv *priv, int status)
  1861. {
  1862. int i;
  1863. if (status == IPW_STATE_SCANNING &&
  1864. priv->status & STATUS_ASSOCIATED &&
  1865. !(priv->status & STATUS_SCANNING)) {
  1866. IPW_DEBUG_INFO("Scan detected while associated, with "
  1867. "no scan request. Restarting firmware.\n");
  1868. /* Wake up any sleeping jobs */
  1869. schedule_reset(priv);
  1870. }
  1871. for (i = 0; status_handlers[i].status != -1; i++) {
  1872. if (status == status_handlers[i].status) {
  1873. IPW_DEBUG_NOTIF("Status change: %s\n",
  1874. status_handlers[i].name);
  1875. if (status_handlers[i].cb)
  1876. status_handlers[i].cb(priv, status);
  1877. priv->wstats.status = status;
  1878. return;
  1879. }
  1880. }
  1881. IPW_DEBUG_NOTIF("unknown status received: %04x\n", status);
  1882. }
  1883. static void isr_rx_complete_command(struct ipw2100_priv *priv,
  1884. struct ipw2100_cmd_header *cmd)
  1885. {
  1886. #ifdef CONFIG_IPW2100_DEBUG
  1887. if (cmd->host_command_reg < ARRAY_SIZE(command_types)) {
  1888. IPW_DEBUG_HC("Command completed '%s (%d)'\n",
  1889. command_types[cmd->host_command_reg],
  1890. cmd->host_command_reg);
  1891. }
  1892. #endif
  1893. if (cmd->host_command_reg == HOST_COMPLETE)
  1894. priv->status |= STATUS_ENABLED;
  1895. if (cmd->host_command_reg == CARD_DISABLE)
  1896. priv->status &= ~STATUS_ENABLED;
  1897. priv->status &= ~STATUS_CMD_ACTIVE;
  1898. wake_up_interruptible(&priv->wait_command_queue);
  1899. }
  1900. #ifdef CONFIG_IPW2100_DEBUG
  1901. static const char *frame_types[] = {
  1902. "COMMAND_STATUS_VAL",
  1903. "STATUS_CHANGE_VAL",
  1904. "P80211_DATA_VAL",
  1905. "P8023_DATA_VAL",
  1906. "HOST_NOTIFICATION_VAL"
  1907. };
  1908. #endif
  1909. static int ipw2100_alloc_skb(struct ipw2100_priv *priv,
  1910. struct ipw2100_rx_packet *packet)
  1911. {
  1912. packet->skb = dev_alloc_skb(sizeof(struct ipw2100_rx));
  1913. if (!packet->skb)
  1914. return -ENOMEM;
  1915. packet->rxp = (struct ipw2100_rx *)packet->skb->data;
  1916. packet->dma_addr = pci_map_single(priv->pci_dev, packet->skb->data,
  1917. sizeof(struct ipw2100_rx),
  1918. PCI_DMA_FROMDEVICE);
  1919. /* NOTE: pci_map_single does not return an error code, and 0 is a valid
  1920. * dma_addr */
  1921. return 0;
  1922. }
  1923. #define SEARCH_ERROR 0xffffffff
  1924. #define SEARCH_FAIL 0xfffffffe
  1925. #define SEARCH_SUCCESS 0xfffffff0
  1926. #define SEARCH_DISCARD 0
  1927. #define SEARCH_SNAPSHOT 1
  1928. #define SNAPSHOT_ADDR(ofs) (priv->snapshot[((ofs) >> 12) & 0xff] + ((ofs) & 0xfff))
  1929. static void ipw2100_snapshot_free(struct ipw2100_priv *priv)
  1930. {
  1931. int i;
  1932. if (!priv->snapshot[0])
  1933. return;
  1934. for (i = 0; i < 0x30; i++)
  1935. kfree(priv->snapshot[i]);
  1936. priv->snapshot[0] = NULL;
  1937. }
  1938. #ifdef IPW2100_DEBUG_C3
  1939. static int ipw2100_snapshot_alloc(struct ipw2100_priv *priv)
  1940. {
  1941. int i;
  1942. if (priv->snapshot[0])
  1943. return 1;
  1944. for (i = 0; i < 0x30; i++) {
  1945. priv->snapshot[i] = kmalloc(0x1000, GFP_ATOMIC);
  1946. if (!priv->snapshot[i]) {
  1947. IPW_DEBUG_INFO("%s: Error allocating snapshot "
  1948. "buffer %d\n", priv->net_dev->name, i);
  1949. while (i > 0)
  1950. kfree(priv->snapshot[--i]);
  1951. priv->snapshot[0] = NULL;
  1952. return 0;
  1953. }
  1954. }
  1955. return 1;
  1956. }
  1957. static u32 ipw2100_match_buf(struct ipw2100_priv *priv, u8 * in_buf,
  1958. size_t len, int mode)
  1959. {
  1960. u32 i, j;
  1961. u32 tmp;
  1962. u8 *s, *d;
  1963. u32 ret;
  1964. s = in_buf;
  1965. if (mode == SEARCH_SNAPSHOT) {
  1966. if (!ipw2100_snapshot_alloc(priv))
  1967. mode = SEARCH_DISCARD;
  1968. }
  1969. for (ret = SEARCH_FAIL, i = 0; i < 0x30000; i += 4) {
  1970. read_nic_dword(priv->net_dev, i, &tmp);
  1971. if (mode == SEARCH_SNAPSHOT)
  1972. *(u32 *) SNAPSHOT_ADDR(i) = tmp;
  1973. if (ret == SEARCH_FAIL) {
  1974. d = (u8 *) & tmp;
  1975. for (j = 0; j < 4; j++) {
  1976. if (*s != *d) {
  1977. s = in_buf;
  1978. continue;
  1979. }
  1980. s++;
  1981. d++;
  1982. if ((s - in_buf) == len)
  1983. ret = (i + j) - len + 1;
  1984. }
  1985. } else if (mode == SEARCH_DISCARD)
  1986. return ret;
  1987. }
  1988. return ret;
  1989. }
  1990. #endif
  1991. /*
  1992. *
  1993. * 0) Disconnect the SKB from the firmware (just unmap)
  1994. * 1) Pack the ETH header into the SKB
  1995. * 2) Pass the SKB to the network stack
  1996. *
  1997. * When packet is provided by the firmware, it contains the following:
  1998. *
  1999. * . libipw_hdr
  2000. * . libipw_snap_hdr
  2001. *
  2002. * The size of the constructed ethernet
  2003. *
  2004. */
  2005. #ifdef IPW2100_RX_DEBUG
  2006. static u8 packet_data[IPW_RX_NIC_BUFFER_LENGTH];
  2007. #endif
  2008. static void ipw2100_corruption_detected(struct ipw2100_priv *priv, int i)
  2009. {
  2010. #ifdef IPW2100_DEBUG_C3
  2011. struct ipw2100_status *status = &priv->status_queue.drv[i];
  2012. u32 match, reg;
  2013. int j;
  2014. #endif
  2015. IPW_DEBUG_INFO(": PCI latency error detected at 0x%04zX.\n",
  2016. i * sizeof(struct ipw2100_status));
  2017. #ifdef IPW2100_DEBUG_C3
  2018. /* Halt the firmware so we can get a good image */
  2019. write_register(priv->net_dev, IPW_REG_RESET_REG,
  2020. IPW_AUX_HOST_RESET_REG_STOP_MASTER);
  2021. j = 5;
  2022. do {
  2023. udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
  2024. read_register(priv->net_dev, IPW_REG_RESET_REG, &reg);
  2025. if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
  2026. break;
  2027. } while (j--);
  2028. match = ipw2100_match_buf(priv, (u8 *) status,
  2029. sizeof(struct ipw2100_status),
  2030. SEARCH_SNAPSHOT);
  2031. if (match < SEARCH_SUCCESS)
  2032. IPW_DEBUG_INFO("%s: DMA status match in Firmware at "
  2033. "offset 0x%06X, length %d:\n",
  2034. priv->net_dev->name, match,
  2035. sizeof(struct ipw2100_status));
  2036. else
  2037. IPW_DEBUG_INFO("%s: No DMA status match in "
  2038. "Firmware.\n", priv->net_dev->name);
  2039. printk_buf((u8 *) priv->status_queue.drv,
  2040. sizeof(struct ipw2100_status) * RX_QUEUE_LENGTH);
  2041. #endif
  2042. priv->fatal_error = IPW2100_ERR_C3_CORRUPTION;
  2043. priv->net_dev->stats.rx_errors++;
  2044. schedule_reset(priv);
  2045. }
  2046. static void isr_rx(struct ipw2100_priv *priv, int i,
  2047. struct libipw_rx_stats *stats)
  2048. {
  2049. struct net_device *dev = priv->net_dev;
  2050. struct ipw2100_status *status = &priv->status_queue.drv[i];
  2051. struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
  2052. IPW_DEBUG_RX("Handler...\n");
  2053. if (unlikely(status->frame_size > skb_tailroom(packet->skb))) {
  2054. IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!"
  2055. " Dropping.\n",
  2056. dev->name,
  2057. status->frame_size, skb_tailroom(packet->skb));
  2058. dev->stats.rx_errors++;
  2059. return;
  2060. }
  2061. if (unlikely(!netif_running(dev))) {
  2062. dev->stats.rx_errors++;
  2063. priv->wstats.discard.misc++;
  2064. IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
  2065. return;
  2066. }
  2067. if (unlikely(priv->ieee->iw_mode != IW_MODE_MONITOR &&
  2068. !(priv->status & STATUS_ASSOCIATED))) {
  2069. IPW_DEBUG_DROP("Dropping packet while not associated.\n");
  2070. priv->wstats.discard.misc++;
  2071. return;
  2072. }
  2073. pci_unmap_single(priv->pci_dev,
  2074. packet->dma_addr,
  2075. sizeof(struct ipw2100_rx), PCI_DMA_FROMDEVICE);
  2076. skb_put(packet->skb, status->frame_size);
  2077. #ifdef IPW2100_RX_DEBUG
  2078. /* Make a copy of the frame so we can dump it to the logs if
  2079. * libipw_rx fails */
  2080. skb_copy_from_linear_data(packet->skb, packet_data,
  2081. min_t(u32, status->frame_size,
  2082. IPW_RX_NIC_BUFFER_LENGTH));
  2083. #endif
  2084. if (!libipw_rx(priv->ieee, packet->skb, stats)) {
  2085. #ifdef IPW2100_RX_DEBUG
  2086. IPW_DEBUG_DROP("%s: Non consumed packet:\n",
  2087. dev->name);
  2088. printk_buf(IPW_DL_DROP, packet_data, status->frame_size);
  2089. #endif
  2090. dev->stats.rx_errors++;
  2091. /* libipw_rx failed, so it didn't free the SKB */
  2092. dev_kfree_skb_any(packet->skb);
  2093. packet->skb = NULL;
  2094. }
  2095. /* We need to allocate a new SKB and attach it to the RDB. */
  2096. if (unlikely(ipw2100_alloc_skb(priv, packet))) {
  2097. printk(KERN_WARNING DRV_NAME ": "
  2098. "%s: Unable to allocate SKB onto RBD ring - disabling "
  2099. "adapter.\n", dev->name);
  2100. /* TODO: schedule adapter shutdown */
  2101. IPW_DEBUG_INFO("TODO: Shutdown adapter...\n");
  2102. }
  2103. /* Update the RDB entry */
  2104. priv->rx_queue.drv[i].host_addr = packet->dma_addr;
  2105. }
  2106. #ifdef CONFIG_IPW2100_MONITOR
  2107. static void isr_rx_monitor(struct ipw2100_priv *priv, int i,
  2108. struct libipw_rx_stats *stats)
  2109. {
  2110. struct net_device *dev = priv->net_dev;
  2111. struct ipw2100_status *status = &priv->status_queue.drv[i];
  2112. struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
  2113. /* Magic struct that slots into the radiotap header -- no reason
  2114. * to build this manually element by element, we can write it much
  2115. * more efficiently than we can parse it. ORDER MATTERS HERE */
  2116. struct ipw_rt_hdr {
  2117. struct ieee80211_radiotap_header rt_hdr;
  2118. s8 rt_dbmsignal; /* signal in dbM, kluged to signed */
  2119. } *ipw_rt;
  2120. IPW_DEBUG_RX("Handler...\n");
  2121. if (unlikely(status->frame_size > skb_tailroom(packet->skb) -
  2122. sizeof(struct ipw_rt_hdr))) {
  2123. IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!"
  2124. " Dropping.\n",
  2125. dev->name,
  2126. status->frame_size,
  2127. skb_tailroom(packet->skb));
  2128. dev->stats.rx_errors++;
  2129. return;
  2130. }
  2131. if (unlikely(!netif_running(dev))) {
  2132. dev->stats.rx_errors++;
  2133. priv->wstats.discard.misc++;
  2134. IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
  2135. return;
  2136. }
  2137. if (unlikely(priv->config & CFG_CRC_CHECK &&
  2138. status->flags & IPW_STATUS_FLAG_CRC_ERROR)) {
  2139. IPW_DEBUG_RX("CRC error in packet. Dropping.\n");
  2140. dev->stats.rx_errors++;
  2141. return;
  2142. }
  2143. pci_unmap_single(priv->pci_dev, packet->dma_addr,
  2144. sizeof(struct ipw2100_rx), PCI_DMA_FROMDEVICE);
  2145. memmove(packet->skb->data + sizeof(struct ipw_rt_hdr),
  2146. packet->skb->data, status->frame_size);
  2147. ipw_rt = (struct ipw_rt_hdr *) packet->skb->data;
  2148. ipw_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
  2149. ipw_rt->rt_hdr.it_pad = 0; /* always good to zero */
  2150. ipw_rt->rt_hdr.it_len = cpu_to_le16(sizeof(struct ipw_rt_hdr)); /* total hdr+data */
  2151. ipw_rt->rt_hdr.it_present = cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
  2152. ipw_rt->rt_dbmsignal = status->rssi + IPW2100_RSSI_TO_DBM;
  2153. skb_put(packet->skb, status->frame_size + sizeof(struct ipw_rt_hdr));
  2154. if (!libipw_rx(priv->ieee, packet->skb, stats)) {
  2155. dev->stats.rx_errors++;
  2156. /* libipw_rx failed, so it didn't free the SKB */
  2157. dev_kfree_skb_any(packet->skb);
  2158. packet->skb = NULL;
  2159. }
  2160. /* We need to allocate a new SKB and attach it to the RDB. */
  2161. if (unlikely(ipw2100_alloc_skb(priv, packet))) {
  2162. IPW_DEBUG_WARNING(
  2163. "%s: Unable to allocate SKB onto RBD ring - disabling "
  2164. "adapter.\n", dev->name);
  2165. /* TODO: schedule adapter shutdown */
  2166. IPW_DEBUG_INFO("TODO: Shutdown adapter...\n");
  2167. }
  2168. /* Update the RDB entry */
  2169. priv->rx_queue.drv[i].host_addr = packet->dma_addr;
  2170. }
  2171. #endif
  2172. static int ipw2100_corruption_check(struct ipw2100_priv *priv, int i)
  2173. {
  2174. struct ipw2100_status *status = &priv->status_queue.drv[i];
  2175. struct ipw2100_rx *u = priv->rx_buffers[i].rxp;
  2176. u16 frame_type = status->status_fields & STATUS_TYPE_MASK;
  2177. switch (frame_type) {
  2178. case COMMAND_STATUS_VAL:
  2179. return (status->frame_size != sizeof(u->rx_data.command));
  2180. case STATUS_CHANGE_VAL:
  2181. return (status->frame_size != sizeof(u->rx_data.status));
  2182. case HOST_NOTIFICATION_VAL:
  2183. return (status->frame_size < sizeof(u->rx_data.notification));
  2184. case P80211_DATA_VAL:
  2185. case P8023_DATA_VAL:
  2186. #ifdef CONFIG_IPW2100_MONITOR
  2187. return 0;
  2188. #else
  2189. switch (WLAN_FC_GET_TYPE(le16_to_cpu(u->rx_data.header.frame_ctl))) {
  2190. case IEEE80211_FTYPE_MGMT:
  2191. case IEEE80211_FTYPE_CTL:
  2192. return 0;
  2193. case IEEE80211_FTYPE_DATA:
  2194. return (status->frame_size >
  2195. IPW_MAX_802_11_PAYLOAD_LENGTH);
  2196. }
  2197. #endif
  2198. }
  2199. return 1;
  2200. }
  2201. /*
  2202. * ipw2100 interrupts are disabled at this point, and the ISR
  2203. * is the only code that calls this method. So, we do not need
  2204. * to play with any locks.
  2205. *
  2206. * RX Queue works as follows:
  2207. *
  2208. * Read index - firmware places packet in entry identified by the
  2209. * Read index and advances Read index. In this manner,
  2210. * Read index will always point to the next packet to
  2211. * be filled--but not yet valid.
  2212. *
  2213. * Write index - driver fills this entry with an unused RBD entry.
  2214. * This entry has not filled by the firmware yet.
  2215. *
  2216. * In between the W and R indexes are the RBDs that have been received
  2217. * but not yet processed.
  2218. *
  2219. * The process of handling packets will start at WRITE + 1 and advance
  2220. * until it reaches the READ index.
  2221. *
  2222. * The WRITE index is cached in the variable 'priv->rx_queue.next'.
  2223. *
  2224. */
  2225. static void __ipw2100_rx_process(struct ipw2100_priv *priv)
  2226. {
  2227. struct ipw2100_bd_queue *rxq = &priv->rx_queue;
  2228. struct ipw2100_status_queue *sq = &priv->status_queue;
  2229. struct ipw2100_rx_packet *packet;
  2230. u16 frame_type;
  2231. u32 r, w, i, s;
  2232. struct ipw2100_rx *u;
  2233. struct libipw_rx_stats stats = {
  2234. .mac_time = jiffies,
  2235. };
  2236. read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_READ_INDEX, &r);
  2237. read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, &w);
  2238. if (r >= rxq->entries) {
  2239. IPW_DEBUG_RX("exit - bad read index\n");
  2240. return;
  2241. }
  2242. i = (rxq->next + 1) % rxq->entries;
  2243. s = i;
  2244. while (i != r) {
  2245. /* IPW_DEBUG_RX("r = %d : w = %d : processing = %d\n",
  2246. r, rxq->next, i); */
  2247. packet = &priv->rx_buffers[i];
  2248. /* Sync the DMA for the RX buffer so CPU is sure to get
  2249. * the correct values */
  2250. pci_dma_sync_single_for_cpu(priv->pci_dev, packet->dma_addr,
  2251. sizeof(struct ipw2100_rx),
  2252. PCI_DMA_FROMDEVICE);
  2253. if (unlikely(ipw2100_corruption_check(priv, i))) {
  2254. ipw2100_corruption_detected(priv, i);
  2255. goto increment;
  2256. }
  2257. u = packet->rxp;
  2258. frame_type = sq->drv[i].status_fields & STATUS_TYPE_MASK;
  2259. stats.rssi = sq->drv[i].rssi + IPW2100_RSSI_TO_DBM;
  2260. stats.len = sq->drv[i].frame_size;
  2261. stats.mask = 0;
  2262. if (stats.rssi != 0)
  2263. stats.mask |= LIBIPW_STATMASK_RSSI;
  2264. stats.freq = LIBIPW_24GHZ_BAND;
  2265. IPW_DEBUG_RX("%s: '%s' frame type received (%d).\n",
  2266. priv->net_dev->name, frame_types[frame_type],
  2267. stats.len);
  2268. switch (frame_type) {
  2269. case COMMAND_STATUS_VAL:
  2270. /* Reset Rx watchdog */
  2271. isr_rx_complete_command(priv, &u->rx_data.command);
  2272. break;
  2273. case STATUS_CHANGE_VAL:
  2274. isr_status_change(priv, u->rx_data.status);
  2275. break;
  2276. case P80211_DATA_VAL:
  2277. case P8023_DATA_VAL:
  2278. #ifdef CONFIG_IPW2100_MONITOR
  2279. if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
  2280. isr_rx_monitor(priv, i, &stats);
  2281. break;
  2282. }
  2283. #endif
  2284. if (stats.len < sizeof(struct libipw_hdr_3addr))
  2285. break;
  2286. switch (WLAN_FC_GET_TYPE(le16_to_cpu(u->rx_data.header.frame_ctl))) {
  2287. case IEEE80211_FTYPE_MGMT:
  2288. libipw_rx_mgt(priv->ieee,
  2289. &u->rx_data.header, &stats);
  2290. break;
  2291. case IEEE80211_FTYPE_CTL:
  2292. break;
  2293. case IEEE80211_FTYPE_DATA:
  2294. isr_rx(priv, i, &stats);
  2295. break;
  2296. }
  2297. break;
  2298. }
  2299. increment:
  2300. /* clear status field associated with this RBD */
  2301. rxq->drv[i].status.info.field = 0;
  2302. i = (i + 1) % rxq->entries;
  2303. }
  2304. if (i != s) {
  2305. /* backtrack one entry, wrapping to end if at 0 */
  2306. rxq->next = (i ? i : rxq->entries) - 1;
  2307. write_register(priv->net_dev,
  2308. IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, rxq->next);
  2309. }
  2310. }
  2311. /*
  2312. * __ipw2100_tx_process
  2313. *
  2314. * This routine will determine whether the next packet on
  2315. * the fw_pend_list has been processed by the firmware yet.
  2316. *
  2317. * If not, then it does nothing and returns.
  2318. *
  2319. * If so, then it removes the item from the fw_pend_list, frees
  2320. * any associated storage, and places the item back on the
  2321. * free list of its source (either msg_free_list or tx_free_list)
  2322. *
  2323. * TX Queue works as follows:
  2324. *
  2325. * Read index - points to the next TBD that the firmware will
  2326. * process. The firmware will read the data, and once
  2327. * done processing, it will advance the Read index.
  2328. *
  2329. * Write index - driver fills this entry with an constructed TBD
  2330. * entry. The Write index is not advanced until the
  2331. * packet has been configured.
  2332. *
  2333. * In between the W and R indexes are the TBDs that have NOT been
  2334. * processed. Lagging behind the R index are packets that have
  2335. * been processed but have not been freed by the driver.
  2336. *
  2337. * In order to free old storage, an internal index will be maintained
  2338. * that points to the next packet to be freed. When all used
  2339. * packets have been freed, the oldest index will be the same as the
  2340. * firmware's read index.
  2341. *
  2342. * The OLDEST index is cached in the variable 'priv->tx_queue.oldest'
  2343. *
  2344. * Because the TBD structure can not contain arbitrary data, the
  2345. * driver must keep an internal queue of cached allocations such that
  2346. * it can put that data back into the tx_free_list and msg_free_list
  2347. * for use by future command and data packets.
  2348. *
  2349. */
  2350. static int __ipw2100_tx_process(struct ipw2100_priv *priv)
  2351. {
  2352. struct ipw2100_bd_queue *txq = &priv->tx_queue;
  2353. struct ipw2100_bd *tbd;
  2354. struct list_head *element;
  2355. struct ipw2100_tx_packet *packet;
  2356. int descriptors_used;
  2357. int e, i;
  2358. u32 r, w, frag_num = 0;
  2359. if (list_empty(&priv->fw_pend_list))
  2360. return 0;
  2361. element = priv->fw_pend_list.next;
  2362. packet = list_entry(element, struct ipw2100_tx_packet, list);
  2363. tbd = &txq->drv[packet->index];
  2364. /* Determine how many TBD entries must be finished... */
  2365. switch (packet->type) {
  2366. case COMMAND:
  2367. /* COMMAND uses only one slot; don't advance */
  2368. descriptors_used = 1;
  2369. e = txq->oldest;
  2370. break;
  2371. case DATA:
  2372. /* DATA uses two slots; advance and loop position. */
  2373. descriptors_used = tbd->num_fragments;
  2374. frag_num = tbd->num_fragments - 1;
  2375. e = txq->oldest + frag_num;
  2376. e %= txq->entries;
  2377. break;
  2378. default:
  2379. printk(KERN_WARNING DRV_NAME ": %s: Bad fw_pend_list entry!\n",
  2380. priv->net_dev->name);
  2381. return 0;
  2382. }
  2383. /* if the last TBD is not done by NIC yet, then packet is
  2384. * not ready to be released.
  2385. *
  2386. */
  2387. read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
  2388. &r);
  2389. read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
  2390. &w);
  2391. if (w != txq->next)
  2392. printk(KERN_WARNING DRV_NAME ": %s: write index mismatch\n",
  2393. priv->net_dev->name);
  2394. /*
  2395. * txq->next is the index of the last packet written txq->oldest is
  2396. * the index of the r is the index of the next packet to be read by
  2397. * firmware
  2398. */
  2399. /*
  2400. * Quick graphic to help you visualize the following
  2401. * if / else statement
  2402. *
  2403. * ===>| s---->|===============
  2404. * e>|
  2405. * | a | b | c | d | e | f | g | h | i | j | k | l
  2406. * r---->|
  2407. * w
  2408. *
  2409. * w - updated by driver
  2410. * r - updated by firmware
  2411. * s - start of oldest BD entry (txq->oldest)
  2412. * e - end of oldest BD entry
  2413. *
  2414. */
  2415. if (!((r <= w && (e < r || e >= w)) || (e < r && e >= w))) {
  2416. IPW_DEBUG_TX("exit - no processed packets ready to release.\n");
  2417. return 0;
  2418. }
  2419. list_del(element);
  2420. DEC_STAT(&priv->fw_pend_stat);
  2421. #ifdef CONFIG_IPW2100_DEBUG
  2422. {
  2423. i = txq->oldest;
  2424. IPW_DEBUG_TX("TX%d V=%p P=%04X T=%04X L=%d\n", i,
  2425. &txq->drv[i],
  2426. (u32) (txq->nic + i * sizeof(struct ipw2100_bd)),
  2427. txq->drv[i].host_addr, txq->drv[i].buf_length);
  2428. if (packet->type == DATA) {
  2429. i = (i + 1) % txq->entries;
  2430. IPW_DEBUG_TX("TX%d V=%p P=%04X T=%04X L=%d\n", i,
  2431. &txq->drv[i],
  2432. (u32) (txq->nic + i *
  2433. sizeof(struct ipw2100_bd)),
  2434. (u32) txq->drv[i].host_addr,
  2435. txq->drv[i].buf_length);
  2436. }
  2437. }
  2438. #endif
  2439. switch (packet->type) {
  2440. case DATA:
  2441. if (txq->drv[txq->oldest].status.info.fields.txType != 0)
  2442. printk(KERN_WARNING DRV_NAME ": %s: Queue mismatch. "
  2443. "Expecting DATA TBD but pulled "
  2444. "something else: ids %d=%d.\n",
  2445. priv->net_dev->name, txq->oldest, packet->index);
  2446. /* DATA packet; we have to unmap and free the SKB */
  2447. for (i = 0; i < frag_num; i++) {
  2448. tbd = &txq->drv[(packet->index + 1 + i) % txq->entries];
  2449. IPW_DEBUG_TX("TX%d P=%08x L=%d\n",
  2450. (packet->index + 1 + i) % txq->entries,
  2451. tbd->host_addr, tbd->buf_length);
  2452. pci_unmap_single(priv->pci_dev,
  2453. tbd->host_addr,
  2454. tbd->buf_length, PCI_DMA_TODEVICE);
  2455. }
  2456. libipw_txb_free(packet->info.d_struct.txb);
  2457. packet->info.d_struct.txb = NULL;
  2458. list_add_tail(element, &priv->tx_free_list);
  2459. INC_STAT(&priv->tx_free_stat);
  2460. /* We have a free slot in the Tx queue, so wake up the
  2461. * transmit layer if it is stopped. */
  2462. if (priv->status & STATUS_ASSOCIATED)
  2463. netif_wake_queue(priv->net_dev);
  2464. /* A packet was processed by the hardware, so update the
  2465. * watchdog */
  2466. priv->net_dev->trans_start = jiffies;
  2467. break;
  2468. case COMMAND:
  2469. if (txq->drv[txq->oldest].status.info.fields.txType != 1)
  2470. printk(KERN_WARNING DRV_NAME ": %s: Queue mismatch. "
  2471. "Expecting COMMAND TBD but pulled "
  2472. "something else: ids %d=%d.\n",
  2473. priv->net_dev->name, txq->oldest, packet->index);
  2474. #ifdef CONFIG_IPW2100_DEBUG
  2475. if (packet->info.c_struct.cmd->host_command_reg <
  2476. ARRAY_SIZE(command_types))
  2477. IPW_DEBUG_TX("Command '%s (%d)' processed: %d.\n",
  2478. command_types[packet->info.c_struct.cmd->
  2479. host_command_reg],
  2480. packet->info.c_struct.cmd->
  2481. host_command_reg,
  2482. packet->info.c_struct.cmd->cmd_status_reg);
  2483. #endif
  2484. list_add_tail(element, &priv->msg_free_list);
  2485. INC_STAT(&priv->msg_free_stat);
  2486. break;
  2487. }
  2488. /* advance oldest used TBD pointer to start of next entry */
  2489. txq->oldest = (e + 1) % txq->entries;
  2490. /* increase available TBDs number */
  2491. txq->available += descriptors_used;
  2492. SET_STAT(&priv->txq_stat, txq->available);
  2493. IPW_DEBUG_TX("packet latency (send to process) %ld jiffies\n",
  2494. jiffies - packet->jiffy_start);
  2495. return (!list_empty(&priv->fw_pend_list));
  2496. }
  2497. static inline void __ipw2100_tx_complete(struct ipw2100_priv *priv)
  2498. {
  2499. int i = 0;
  2500. while (__ipw2100_tx_process(priv) && i < 200)
  2501. i++;
  2502. if (i == 200) {
  2503. printk(KERN_WARNING DRV_NAME ": "
  2504. "%s: Driver is running slow (%d iters).\n",
  2505. priv->net_dev->name, i);
  2506. }
  2507. }
  2508. static void ipw2100_tx_send_commands(struct ipw2100_priv *priv)
  2509. {
  2510. struct list_head *element;
  2511. struct ipw2100_tx_packet *packet;
  2512. struct ipw2100_bd_queue *txq = &priv->tx_queue;
  2513. struct ipw2100_bd *tbd;
  2514. int next = txq->next;
  2515. while (!list_empty(&priv->msg_pend_list)) {
  2516. /* if there isn't enough space in TBD queue, then
  2517. * don't stuff a new one in.
  2518. * NOTE: 3 are needed as a command will take one,
  2519. * and there is a minimum of 2 that must be
  2520. * maintained between the r and w indexes
  2521. */
  2522. if (txq->available <= 3) {
  2523. IPW_DEBUG_TX("no room in tx_queue\n");
  2524. break;
  2525. }
  2526. element = priv->msg_pend_list.next;
  2527. list_del(element);
  2528. DEC_STAT(&priv->msg_pend_stat);
  2529. packet = list_entry(element, struct ipw2100_tx_packet, list);
  2530. IPW_DEBUG_TX("using TBD at virt=%p, phys=%04X\n",
  2531. &txq->drv[txq->next],
  2532. (u32) (txq->nic + txq->next *
  2533. sizeof(struct ipw2100_bd)));
  2534. packet->index = txq->next;
  2535. tbd = &txq->drv[txq->next];
  2536. /* initialize TBD */
  2537. tbd->host_addr = packet->info.c_struct.cmd_phys;
  2538. tbd->buf_length = sizeof(struct ipw2100_cmd_header);
  2539. /* not marking number of fragments causes problems
  2540. * with f/w debug version */
  2541. tbd->num_fragments = 1;
  2542. tbd->status.info.field =
  2543. IPW_BD_STATUS_TX_FRAME_COMMAND |
  2544. IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
  2545. /* update TBD queue counters */
  2546. txq->next++;
  2547. txq->next %= txq->entries;
  2548. txq->available--;
  2549. DEC_STAT(&priv->txq_stat);
  2550. list_add_tail(element, &priv->fw_pend_list);
  2551. INC_STAT(&priv->fw_pend_stat);
  2552. }
  2553. if (txq->next != next) {
  2554. /* kick off the DMA by notifying firmware the
  2555. * write index has moved; make sure TBD stores are sync'd */
  2556. wmb();
  2557. write_register(priv->net_dev,
  2558. IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
  2559. txq->next);
  2560. }
  2561. }
  2562. /*
  2563. * ipw2100_tx_send_data
  2564. *
  2565. */
  2566. static void ipw2100_tx_send_data(struct ipw2100_priv *priv)
  2567. {
  2568. struct list_head *element;
  2569. struct ipw2100_tx_packet *packet;
  2570. struct ipw2100_bd_queue *txq = &priv->tx_queue;
  2571. struct ipw2100_bd *tbd;
  2572. int next = txq->next;
  2573. int i = 0;
  2574. struct ipw2100_data_header *ipw_hdr;
  2575. struct libipw_hdr_3addr *hdr;
  2576. while (!list_empty(&priv->tx_pend_list)) {
  2577. /* if there isn't enough space in TBD queue, then
  2578. * don't stuff a new one in.
  2579. * NOTE: 4 are needed as a data will take two,
  2580. * and there is a minimum of 2 that must be
  2581. * maintained between the r and w indexes
  2582. */
  2583. element = priv->tx_pend_list.next;
  2584. packet = list_entry(element, struct ipw2100_tx_packet, list);
  2585. if (unlikely(1 + packet->info.d_struct.txb->nr_frags >
  2586. IPW_MAX_BDS)) {
  2587. /* TODO: Support merging buffers if more than
  2588. * IPW_MAX_BDS are used */
  2589. IPW_DEBUG_INFO("%s: Maximum BD threshold exceeded. "
  2590. "Increase fragmentation level.\n",
  2591. priv->net_dev->name);
  2592. }
  2593. if (txq->available <= 3 + packet->info.d_struct.txb->nr_frags) {
  2594. IPW_DEBUG_TX("no room in tx_queue\n");
  2595. break;
  2596. }
  2597. list_del(element);
  2598. DEC_STAT(&priv->tx_pend_stat);
  2599. tbd = &txq->drv[txq->next];
  2600. packet->index = txq->next;
  2601. ipw_hdr = packet->info.d_struct.data;
  2602. hdr = (struct libipw_hdr_3addr *)packet->info.d_struct.txb->
  2603. fragments[0]->data;
  2604. if (priv->ieee->iw_mode == IW_MODE_INFRA) {
  2605. /* To DS: Addr1 = BSSID, Addr2 = SA,
  2606. Addr3 = DA */
  2607. memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
  2608. memcpy(ipw_hdr->dst_addr, hdr->addr3, ETH_ALEN);
  2609. } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
  2610. /* not From/To DS: Addr1 = DA, Addr2 = SA,
  2611. Addr3 = BSSID */
  2612. memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
  2613. memcpy(ipw_hdr->dst_addr, hdr->addr1, ETH_ALEN);
  2614. }
  2615. ipw_hdr->host_command_reg = SEND;
  2616. ipw_hdr->host_command_reg1 = 0;
  2617. /* For now we only support host based encryption */
  2618. ipw_hdr->needs_encryption = 0;
  2619. ipw_hdr->encrypted = packet->info.d_struct.txb->encrypted;
  2620. if (packet->info.d_struct.txb->nr_frags > 1)
  2621. ipw_hdr->fragment_size =
  2622. packet->info.d_struct.txb->frag_size -
  2623. LIBIPW_3ADDR_LEN;
  2624. else
  2625. ipw_hdr->fragment_size = 0;
  2626. tbd->host_addr = packet->info.d_struct.data_phys;
  2627. tbd->buf_length = sizeof(struct ipw2100_data_header);
  2628. tbd->num_fragments = 1 + packet->info.d_struct.txb->nr_frags;
  2629. tbd->status.info.field =
  2630. IPW_BD_STATUS_TX_FRAME_802_3 |
  2631. IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
  2632. txq->next++;
  2633. txq->next %= txq->entries;
  2634. IPW_DEBUG_TX("data header tbd TX%d P=%08x L=%d\n",
  2635. packet->index, tbd->host_addr, tbd->buf_length);
  2636. #ifdef CONFIG_IPW2100_DEBUG
  2637. if (packet->info.d_struct.txb->nr_frags > 1)
  2638. IPW_DEBUG_FRAG("fragment Tx: %d frames\n",
  2639. packet->info.d_struct.txb->nr_frags);
  2640. #endif
  2641. for (i = 0; i < packet->info.d_struct.txb->nr_frags; i++) {
  2642. tbd = &txq->drv[txq->next];
  2643. if (i == packet->info.d_struct.txb->nr_frags - 1)
  2644. tbd->status.info.field =
  2645. IPW_BD_STATUS_TX_FRAME_802_3 |
  2646. IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
  2647. else
  2648. tbd->status.info.field =
  2649. IPW_BD_STATUS_TX_FRAME_802_3 |
  2650. IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
  2651. tbd->buf_length = packet->info.d_struct.txb->
  2652. fragments[i]->len - LIBIPW_3ADDR_LEN;
  2653. tbd->host_addr = pci_map_single(priv->pci_dev,
  2654. packet->info.d_struct.
  2655. txb->fragments[i]->
  2656. data +
  2657. LIBIPW_3ADDR_LEN,
  2658. tbd->buf_length,
  2659. PCI_DMA_TODEVICE);
  2660. IPW_DEBUG_TX("data frag tbd TX%d P=%08x L=%d\n",
  2661. txq->next, tbd->host_addr,
  2662. tbd->buf_length);
  2663. pci_dma_sync_single_for_device(priv->pci_dev,
  2664. tbd->host_addr,
  2665. tbd->buf_length,
  2666. PCI_DMA_TODEVICE);
  2667. txq->next++;
  2668. txq->next %= txq->entries;
  2669. }
  2670. txq->available -= 1 + packet->info.d_struct.txb->nr_frags;
  2671. SET_STAT(&priv->txq_stat, txq->available);
  2672. list_add_tail(element, &priv->fw_pend_list);
  2673. INC_STAT(&priv->fw_pend_stat);
  2674. }
  2675. if (txq->next != next) {
  2676. /* kick off the DMA by notifying firmware the
  2677. * write index has moved; make sure TBD stores are sync'd */
  2678. write_register(priv->net_dev,
  2679. IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
  2680. txq->next);
  2681. }
  2682. }
  2683. static void ipw2100_irq_tasklet(struct ipw2100_priv *priv)
  2684. {
  2685. struct net_device *dev = priv->net_dev;
  2686. unsigned long flags;
  2687. u32 inta, tmp;
  2688. spin_lock_irqsave(&priv->low_lock, flags);
  2689. ipw2100_disable_interrupts(priv);
  2690. read_register(dev, IPW_REG_INTA, &inta);
  2691. IPW_DEBUG_ISR("enter - INTA: 0x%08lX\n",
  2692. (unsigned long)inta & IPW_INTERRUPT_MASK);
  2693. priv->in_isr++;
  2694. priv->interrupts++;
  2695. /* We do not loop and keep polling for more interrupts as this
  2696. * is frowned upon and doesn't play nicely with other potentially
  2697. * chained IRQs */
  2698. IPW_DEBUG_ISR("INTA: 0x%08lX\n",
  2699. (unsigned long)inta & IPW_INTERRUPT_MASK);
  2700. if (inta & IPW2100_INTA_FATAL_ERROR) {
  2701. printk(KERN_WARNING DRV_NAME
  2702. ": Fatal interrupt. Scheduling firmware restart.\n");
  2703. priv->inta_other++;
  2704. write_register(dev, IPW_REG_INTA, IPW2100_INTA_FATAL_ERROR);
  2705. read_nic_dword(dev, IPW_NIC_FATAL_ERROR, &priv->fatal_error);
  2706. IPW_DEBUG_INFO("%s: Fatal error value: 0x%08X\n",
  2707. priv->net_dev->name, priv->fatal_error);
  2708. read_nic_dword(dev, IPW_ERROR_ADDR(priv->fatal_error), &tmp);
  2709. IPW_DEBUG_INFO("%s: Fatal error address value: 0x%08X\n",
  2710. priv->net_dev->name, tmp);
  2711. /* Wake up any sleeping jobs */
  2712. schedule_reset(priv);
  2713. }
  2714. if (inta & IPW2100_INTA_PARITY_ERROR) {
  2715. printk(KERN_ERR DRV_NAME
  2716. ": ***** PARITY ERROR INTERRUPT !!!!\n");
  2717. priv->inta_other++;
  2718. write_register(dev, IPW_REG_INTA, IPW2100_INTA_PARITY_ERROR);
  2719. }
  2720. if (inta & IPW2100_INTA_RX_TRANSFER) {
  2721. IPW_DEBUG_ISR("RX interrupt\n");
  2722. priv->rx_interrupts++;
  2723. write_register(dev, IPW_REG_INTA, IPW2100_INTA_RX_TRANSFER);
  2724. __ipw2100_rx_process(priv);
  2725. __ipw2100_tx_complete(priv);
  2726. }
  2727. if (inta & IPW2100_INTA_TX_TRANSFER) {
  2728. IPW_DEBUG_ISR("TX interrupt\n");
  2729. priv->tx_interrupts++;
  2730. write_register(dev, IPW_REG_INTA, IPW2100_INTA_TX_TRANSFER);
  2731. __ipw2100_tx_complete(priv);
  2732. ipw2100_tx_send_commands(priv);
  2733. ipw2100_tx_send_data(priv);
  2734. }
  2735. if (inta & IPW2100_INTA_TX_COMPLETE) {
  2736. IPW_DEBUG_ISR("TX complete\n");
  2737. priv->inta_other++;
  2738. write_register(dev, IPW_REG_INTA, IPW2100_INTA_TX_COMPLETE);
  2739. __ipw2100_tx_complete(priv);
  2740. }
  2741. if (inta & IPW2100_INTA_EVENT_INTERRUPT) {
  2742. /* ipw2100_handle_event(dev); */
  2743. priv->inta_other++;
  2744. write_register(dev, IPW_REG_INTA, IPW2100_INTA_EVENT_INTERRUPT);
  2745. }
  2746. if (inta & IPW2100_INTA_FW_INIT_DONE) {
  2747. IPW_DEBUG_ISR("FW init done interrupt\n");
  2748. priv->inta_other++;
  2749. read_register(dev, IPW_REG_INTA, &tmp);
  2750. if (tmp & (IPW2100_INTA_FATAL_ERROR |
  2751. IPW2100_INTA_PARITY_ERROR)) {
  2752. write_register(dev, IPW_REG_INTA,
  2753. IPW2100_INTA_FATAL_ERROR |
  2754. IPW2100_INTA_PARITY_ERROR);
  2755. }
  2756. write_register(dev, IPW_REG_INTA, IPW2100_INTA_FW_INIT_DONE);
  2757. }
  2758. if (inta & IPW2100_INTA_STATUS_CHANGE) {
  2759. IPW_DEBUG_ISR("Status change interrupt\n");
  2760. priv->inta_other++;
  2761. write_register(dev, IPW_REG_INTA, IPW2100_INTA_STATUS_CHANGE);
  2762. }
  2763. if (inta & IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE) {
  2764. IPW_DEBUG_ISR("slave host mode interrupt\n");
  2765. priv->inta_other++;
  2766. write_register(dev, IPW_REG_INTA,
  2767. IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE);
  2768. }
  2769. priv->in_isr--;
  2770. ipw2100_enable_interrupts(priv);
  2771. spin_unlock_irqrestore(&priv->low_lock, flags);
  2772. IPW_DEBUG_ISR("exit\n");
  2773. }
  2774. static irqreturn_t ipw2100_interrupt(int irq, void *data)
  2775. {
  2776. struct ipw2100_priv *priv = data;
  2777. u32 inta, inta_mask;
  2778. if (!data)
  2779. return IRQ_NONE;
  2780. spin_lock(&priv->low_lock);
  2781. /* We check to see if we should be ignoring interrupts before
  2782. * we touch the hardware. During ucode load if we try and handle
  2783. * an interrupt we can cause keyboard problems as well as cause
  2784. * the ucode to fail to initialize */
  2785. if (!(priv->status & STATUS_INT_ENABLED)) {
  2786. /* Shared IRQ */
  2787. goto none;
  2788. }
  2789. read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
  2790. read_register(priv->net_dev, IPW_REG_INTA, &inta);
  2791. if (inta == 0xFFFFFFFF) {
  2792. /* Hardware disappeared */
  2793. printk(KERN_WARNING DRV_NAME ": IRQ INTA == 0xFFFFFFFF\n");
  2794. goto none;
  2795. }
  2796. inta &= IPW_INTERRUPT_MASK;
  2797. if (!(inta & inta_mask)) {
  2798. /* Shared interrupt */
  2799. goto none;
  2800. }
  2801. /* We disable the hardware interrupt here just to prevent unneeded
  2802. * calls to be made. We disable this again within the actual
  2803. * work tasklet, so if another part of the code re-enables the
  2804. * interrupt, that is fine */
  2805. ipw2100_disable_interrupts(priv);
  2806. tasklet_schedule(&priv->irq_tasklet);
  2807. spin_unlock(&priv->low_lock);
  2808. return IRQ_HANDLED;
  2809. none:
  2810. spin_unlock(&priv->low_lock);
  2811. return IRQ_NONE;
  2812. }
  2813. static netdev_tx_t ipw2100_tx(struct libipw_txb *txb,
  2814. struct net_device *dev, int pri)
  2815. {
  2816. struct ipw2100_priv *priv = libipw_priv(dev);
  2817. struct list_head *element;
  2818. struct ipw2100_tx_packet *packet;
  2819. unsigned long flags;
  2820. spin_lock_irqsave(&priv->low_lock, flags);
  2821. if (!(priv->status & STATUS_ASSOCIATED)) {
  2822. IPW_DEBUG_INFO("Can not transmit when not connected.\n");
  2823. priv->net_dev->stats.tx_carrier_errors++;
  2824. netif_stop_queue(dev);
  2825. goto fail_unlock;
  2826. }
  2827. if (list_empty(&priv->tx_free_list))
  2828. goto fail_unlock;
  2829. element = priv->tx_free_list.next;
  2830. packet = list_entry(element, struct ipw2100_tx_packet, list);
  2831. packet->info.d_struct.txb = txb;
  2832. IPW_DEBUG_TX("Sending fragment (%d bytes):\n", txb->fragments[0]->len);
  2833. printk_buf(IPW_DL_TX, txb->fragments[0]->data, txb->fragments[0]->len);
  2834. packet->jiffy_start = jiffies;
  2835. list_del(element);
  2836. DEC_STAT(&priv->tx_free_stat);
  2837. list_add_tail(element, &priv->tx_pend_list);
  2838. INC_STAT(&priv->tx_pend_stat);
  2839. ipw2100_tx_send_data(priv);
  2840. spin_unlock_irqrestore(&priv->low_lock, flags);
  2841. return NETDEV_TX_OK;
  2842. fail_unlock:
  2843. netif_stop_queue(dev);
  2844. spin_unlock_irqrestore(&priv->low_lock, flags);
  2845. return NETDEV_TX_BUSY;
  2846. }
  2847. static int ipw2100_msg_allocate(struct ipw2100_priv *priv)
  2848. {
  2849. int i, j, err = -EINVAL;
  2850. void *v;
  2851. dma_addr_t p;
  2852. priv->msg_buffers =
  2853. kmalloc(IPW_COMMAND_POOL_SIZE * sizeof(struct ipw2100_tx_packet),
  2854. GFP_KERNEL);
  2855. if (!priv->msg_buffers)
  2856. return -ENOMEM;
  2857. for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
  2858. v = pci_alloc_consistent(priv->pci_dev,
  2859. sizeof(struct ipw2100_cmd_header), &p);
  2860. if (!v) {
  2861. printk(KERN_ERR DRV_NAME ": "
  2862. "%s: PCI alloc failed for msg "
  2863. "buffers.\n", priv->net_dev->name);
  2864. err = -ENOMEM;
  2865. break;
  2866. }
  2867. memset(v, 0, sizeof(struct ipw2100_cmd_header));
  2868. priv->msg_buffers[i].type = COMMAND;
  2869. priv->msg_buffers[i].info.c_struct.cmd =
  2870. (struct ipw2100_cmd_header *)v;
  2871. priv->msg_buffers[i].info.c_struct.cmd_phys = p;
  2872. }
  2873. if (i == IPW_COMMAND_POOL_SIZE)
  2874. return 0;
  2875. for (j = 0; j < i; j++) {
  2876. pci_free_consistent(priv->pci_dev,
  2877. sizeof(struct ipw2100_cmd_header),
  2878. priv->msg_buffers[j].info.c_struct.cmd,
  2879. priv->msg_buffers[j].info.c_struct.
  2880. cmd_phys);
  2881. }
  2882. kfree(priv->msg_buffers);
  2883. priv->msg_buffers = NULL;
  2884. return err;
  2885. }
  2886. static int ipw2100_msg_initialize(struct ipw2100_priv *priv)
  2887. {
  2888. int i;
  2889. INIT_LIST_HEAD(&priv->msg_free_list);
  2890. INIT_LIST_HEAD(&priv->msg_pend_list);
  2891. for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++)
  2892. list_add_tail(&priv->msg_buffers[i].list, &priv->msg_free_list);
  2893. SET_STAT(&priv->msg_free_stat, i);
  2894. return 0;
  2895. }
  2896. static void ipw2100_msg_free(struct ipw2100_priv *priv)
  2897. {
  2898. int i;
  2899. if (!priv->msg_buffers)
  2900. return;
  2901. for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
  2902. pci_free_consistent(priv->pci_dev,
  2903. sizeof(struct ipw2100_cmd_header),
  2904. priv->msg_buffers[i].info.c_struct.cmd,
  2905. priv->msg_buffers[i].info.c_struct.
  2906. cmd_phys);
  2907. }
  2908. kfree(priv->msg_buffers);
  2909. priv->msg_buffers = NULL;
  2910. }
  2911. static ssize_t show_pci(struct device *d, struct device_attribute *attr,
  2912. char *buf)
  2913. {
  2914. struct pci_dev *pci_dev = container_of(d, struct pci_dev, dev);
  2915. char *out = buf;
  2916. int i, j;
  2917. u32 val;
  2918. for (i = 0; i < 16; i++) {
  2919. out += sprintf(out, "[%08X] ", i * 16);
  2920. for (j = 0; j < 16; j += 4) {
  2921. pci_read_config_dword(pci_dev, i * 16 + j, &val);
  2922. out += sprintf(out, "%08X ", val);
  2923. }
  2924. out += sprintf(out, "\n");
  2925. }
  2926. return out - buf;
  2927. }
  2928. static DEVICE_ATTR(pci, S_IRUGO, show_pci, NULL);
  2929. static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
  2930. char *buf)
  2931. {
  2932. struct ipw2100_priv *p = dev_get_drvdata(d);
  2933. return sprintf(buf, "0x%08x\n", (int)p->config);
  2934. }
  2935. static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
  2936. static ssize_t show_status(struct device *d, struct device_attribute *attr,
  2937. char *buf)
  2938. {
  2939. struct ipw2100_priv *p = dev_get_drvdata(d);
  2940. return sprintf(buf, "0x%08x\n", (int)p->status);
  2941. }
  2942. static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
  2943. static ssize_t show_capability(struct device *d, struct device_attribute *attr,
  2944. char *buf)
  2945. {
  2946. struct ipw2100_priv *p = dev_get_drvdata(d);
  2947. return sprintf(buf, "0x%08x\n", (int)p->capability);
  2948. }
  2949. static DEVICE_ATTR(capability, S_IRUGO, show_capability, NULL);
  2950. #define IPW2100_REG(x) { IPW_ ##x, #x }
  2951. static const struct {
  2952. u32 addr;
  2953. const char *name;
  2954. } hw_data[] = {
  2955. IPW2100_REG(REG_GP_CNTRL),
  2956. IPW2100_REG(REG_GPIO),
  2957. IPW2100_REG(REG_INTA),
  2958. IPW2100_REG(REG_INTA_MASK), IPW2100_REG(REG_RESET_REG),};
  2959. #define IPW2100_NIC(x, s) { x, #x, s }
  2960. static const struct {
  2961. u32 addr;
  2962. const char *name;
  2963. size_t size;
  2964. } nic_data[] = {
  2965. IPW2100_NIC(IPW2100_CONTROL_REG, 2),
  2966. IPW2100_NIC(0x210014, 1), IPW2100_NIC(0x210000, 1),};
  2967. #define IPW2100_ORD(x, d) { IPW_ORD_ ##x, #x, d }
  2968. static const struct {
  2969. u8 index;
  2970. const char *name;
  2971. const char *desc;
  2972. } ord_data[] = {
  2973. IPW2100_ORD(STAT_TX_HOST_REQUESTS, "requested Host Tx's (MSDU)"),
  2974. IPW2100_ORD(STAT_TX_HOST_COMPLETE,
  2975. "successful Host Tx's (MSDU)"),
  2976. IPW2100_ORD(STAT_TX_DIR_DATA,
  2977. "successful Directed Tx's (MSDU)"),
  2978. IPW2100_ORD(STAT_TX_DIR_DATA1,
  2979. "successful Directed Tx's (MSDU) @ 1MB"),
  2980. IPW2100_ORD(STAT_TX_DIR_DATA2,
  2981. "successful Directed Tx's (MSDU) @ 2MB"),
  2982. IPW2100_ORD(STAT_TX_DIR_DATA5_5,
  2983. "successful Directed Tx's (MSDU) @ 5_5MB"),
  2984. IPW2100_ORD(STAT_TX_DIR_DATA11,
  2985. "successful Directed Tx's (MSDU) @ 11MB"),
  2986. IPW2100_ORD(STAT_TX_NODIR_DATA1,
  2987. "successful Non_Directed Tx's (MSDU) @ 1MB"),
  2988. IPW2100_ORD(STAT_TX_NODIR_DATA2,
  2989. "successful Non_Directed Tx's (MSDU) @ 2MB"),
  2990. IPW2100_ORD(STAT_TX_NODIR_DATA5_5,
  2991. "successful Non_Directed Tx's (MSDU) @ 5.5MB"),
  2992. IPW2100_ORD(STAT_TX_NODIR_DATA11,
  2993. "successful Non_Directed Tx's (MSDU) @ 11MB"),
  2994. IPW2100_ORD(STAT_NULL_DATA, "successful NULL data Tx's"),
  2995. IPW2100_ORD(STAT_TX_RTS, "successful Tx RTS"),
  2996. IPW2100_ORD(STAT_TX_CTS, "successful Tx CTS"),
  2997. IPW2100_ORD(STAT_TX_ACK, "successful Tx ACK"),
  2998. IPW2100_ORD(STAT_TX_ASSN, "successful Association Tx's"),
  2999. IPW2100_ORD(STAT_TX_ASSN_RESP,
  3000. "successful Association response Tx's"),
  3001. IPW2100_ORD(STAT_TX_REASSN,
  3002. "successful Reassociation Tx's"),
  3003. IPW2100_ORD(STAT_TX_REASSN_RESP,
  3004. "successful Reassociation response Tx's"),
  3005. IPW2100_ORD(STAT_TX_PROBE,
  3006. "probes successfully transmitted"),
  3007. IPW2100_ORD(STAT_TX_PROBE_RESP,
  3008. "probe responses successfully transmitted"),
  3009. IPW2100_ORD(STAT_TX_BEACON, "tx beacon"),
  3010. IPW2100_ORD(STAT_TX_ATIM, "Tx ATIM"),
  3011. IPW2100_ORD(STAT_TX_DISASSN,
  3012. "successful Disassociation TX"),
  3013. IPW2100_ORD(STAT_TX_AUTH, "successful Authentication Tx"),
  3014. IPW2100_ORD(STAT_TX_DEAUTH,
  3015. "successful Deauthentication TX"),
  3016. IPW2100_ORD(STAT_TX_TOTAL_BYTES,
  3017. "Total successful Tx data bytes"),
  3018. IPW2100_ORD(STAT_TX_RETRIES, "Tx retries"),
  3019. IPW2100_ORD(STAT_TX_RETRY1, "Tx retries at 1MBPS"),
  3020. IPW2100_ORD(STAT_TX_RETRY2, "Tx retries at 2MBPS"),
  3021. IPW2100_ORD(STAT_TX_RETRY5_5, "Tx retries at 5.5MBPS"),
  3022. IPW2100_ORD(STAT_TX_RETRY11, "Tx retries at 11MBPS"),
  3023. IPW2100_ORD(STAT_TX_FAILURES, "Tx Failures"),
  3024. IPW2100_ORD(STAT_TX_MAX_TRIES_IN_HOP,
  3025. "times max tries in a hop failed"),
  3026. IPW2100_ORD(STAT_TX_DISASSN_FAIL,
  3027. "times disassociation failed"),
  3028. IPW2100_ORD(STAT_TX_ERR_CTS, "missed/bad CTS frames"),
  3029. IPW2100_ORD(STAT_TX_ERR_ACK, "tx err due to acks"),
  3030. IPW2100_ORD(STAT_RX_HOST, "packets passed to host"),
  3031. IPW2100_ORD(STAT_RX_DIR_DATA, "directed packets"),
  3032. IPW2100_ORD(STAT_RX_DIR_DATA1, "directed packets at 1MB"),
  3033. IPW2100_ORD(STAT_RX_DIR_DATA2, "directed packets at 2MB"),
  3034. IPW2100_ORD(STAT_RX_DIR_DATA5_5,
  3035. "directed packets at 5.5MB"),
  3036. IPW2100_ORD(STAT_RX_DIR_DATA11, "directed packets at 11MB"),
  3037. IPW2100_ORD(STAT_RX_NODIR_DATA, "nondirected packets"),
  3038. IPW2100_ORD(STAT_RX_NODIR_DATA1,
  3039. "nondirected packets at 1MB"),
  3040. IPW2100_ORD(STAT_RX_NODIR_DATA2,
  3041. "nondirected packets at 2MB"),
  3042. IPW2100_ORD(STAT_RX_NODIR_DATA5_5,
  3043. "nondirected packets at 5.5MB"),
  3044. IPW2100_ORD(STAT_RX_NODIR_DATA11,
  3045. "nondirected packets at 11MB"),
  3046. IPW2100_ORD(STAT_RX_NULL_DATA, "null data rx's"),
  3047. IPW2100_ORD(STAT_RX_RTS, "Rx RTS"), IPW2100_ORD(STAT_RX_CTS,
  3048. "Rx CTS"),
  3049. IPW2100_ORD(STAT_RX_ACK, "Rx ACK"),
  3050. IPW2100_ORD(STAT_RX_CFEND, "Rx CF End"),
  3051. IPW2100_ORD(STAT_RX_CFEND_ACK, "Rx CF End + CF Ack"),
  3052. IPW2100_ORD(STAT_RX_ASSN, "Association Rx's"),
  3053. IPW2100_ORD(STAT_RX_ASSN_RESP, "Association response Rx's"),
  3054. IPW2100_ORD(STAT_RX_REASSN, "Reassociation Rx's"),
  3055. IPW2100_ORD(STAT_RX_REASSN_RESP,
  3056. "Reassociation response Rx's"),
  3057. IPW2100_ORD(STAT_RX_PROBE, "probe Rx's"),
  3058. IPW2100_ORD(STAT_RX_PROBE_RESP, "probe response Rx's"),
  3059. IPW2100_ORD(STAT_RX_BEACON, "Rx beacon"),
  3060. IPW2100_ORD(STAT_RX_ATIM, "Rx ATIM"),
  3061. IPW2100_ORD(STAT_RX_DISASSN, "disassociation Rx"),
  3062. IPW2100_ORD(STAT_RX_AUTH, "authentication Rx"),
  3063. IPW2100_ORD(STAT_RX_DEAUTH, "deauthentication Rx"),
  3064. IPW2100_ORD(STAT_RX_TOTAL_BYTES,
  3065. "Total rx data bytes received"),
  3066. IPW2100_ORD(STAT_RX_ERR_CRC, "packets with Rx CRC error"),
  3067. IPW2100_ORD(STAT_RX_ERR_CRC1, "Rx CRC errors at 1MB"),
  3068. IPW2100_ORD(STAT_RX_ERR_CRC2, "Rx CRC errors at 2MB"),
  3069. IPW2100_ORD(STAT_RX_ERR_CRC5_5, "Rx CRC errors at 5.5MB"),
  3070. IPW2100_ORD(STAT_RX_ERR_CRC11, "Rx CRC errors at 11MB"),
  3071. IPW2100_ORD(STAT_RX_DUPLICATE1,
  3072. "duplicate rx packets at 1MB"),
  3073. IPW2100_ORD(STAT_RX_DUPLICATE2,
  3074. "duplicate rx packets at 2MB"),
  3075. IPW2100_ORD(STAT_RX_DUPLICATE5_5,
  3076. "duplicate rx packets at 5.5MB"),
  3077. IPW2100_ORD(STAT_RX_DUPLICATE11,
  3078. "duplicate rx packets at 11MB"),
  3079. IPW2100_ORD(STAT_RX_DUPLICATE, "duplicate rx packets"),
  3080. IPW2100_ORD(PERS_DB_LOCK, "locking fw permanent db"),
  3081. IPW2100_ORD(PERS_DB_SIZE, "size of fw permanent db"),
  3082. IPW2100_ORD(PERS_DB_ADDR, "address of fw permanent db"),
  3083. IPW2100_ORD(STAT_RX_INVALID_PROTOCOL,
  3084. "rx frames with invalid protocol"),
  3085. IPW2100_ORD(SYS_BOOT_TIME, "Boot time"),
  3086. IPW2100_ORD(STAT_RX_NO_BUFFER,
  3087. "rx frames rejected due to no buffer"),
  3088. IPW2100_ORD(STAT_RX_MISSING_FRAG,
  3089. "rx frames dropped due to missing fragment"),
  3090. IPW2100_ORD(STAT_RX_ORPHAN_FRAG,
  3091. "rx frames dropped due to non-sequential fragment"),
  3092. IPW2100_ORD(STAT_RX_ORPHAN_FRAME,
  3093. "rx frames dropped due to unmatched 1st frame"),
  3094. IPW2100_ORD(STAT_RX_FRAG_AGEOUT,
  3095. "rx frames dropped due to uncompleted frame"),
  3096. IPW2100_ORD(STAT_RX_ICV_ERRORS,
  3097. "ICV errors during decryption"),
  3098. IPW2100_ORD(STAT_PSP_SUSPENSION, "times adapter suspended"),
  3099. IPW2100_ORD(STAT_PSP_BCN_TIMEOUT, "beacon timeout"),
  3100. IPW2100_ORD(STAT_PSP_POLL_TIMEOUT,
  3101. "poll response timeouts"),
  3102. IPW2100_ORD(STAT_PSP_NONDIR_TIMEOUT,
  3103. "timeouts waiting for last {broad,multi}cast pkt"),
  3104. IPW2100_ORD(STAT_PSP_RX_DTIMS, "PSP DTIMs received"),
  3105. IPW2100_ORD(STAT_PSP_RX_TIMS, "PSP TIMs received"),
  3106. IPW2100_ORD(STAT_PSP_STATION_ID, "PSP Station ID"),
  3107. IPW2100_ORD(LAST_ASSN_TIME, "RTC time of last association"),
  3108. IPW2100_ORD(STAT_PERCENT_MISSED_BCNS,
  3109. "current calculation of % missed beacons"),
  3110. IPW2100_ORD(STAT_PERCENT_RETRIES,
  3111. "current calculation of % missed tx retries"),
  3112. IPW2100_ORD(ASSOCIATED_AP_PTR,
  3113. "0 if not associated, else pointer to AP table entry"),
  3114. IPW2100_ORD(AVAILABLE_AP_CNT,
  3115. "AP's decsribed in the AP table"),
  3116. IPW2100_ORD(AP_LIST_PTR, "Ptr to list of available APs"),
  3117. IPW2100_ORD(STAT_AP_ASSNS, "associations"),
  3118. IPW2100_ORD(STAT_ASSN_FAIL, "association failures"),
  3119. IPW2100_ORD(STAT_ASSN_RESP_FAIL,
  3120. "failures due to response fail"),
  3121. IPW2100_ORD(STAT_FULL_SCANS, "full scans"),
  3122. IPW2100_ORD(CARD_DISABLED, "Card Disabled"),
  3123. IPW2100_ORD(STAT_ROAM_INHIBIT,
  3124. "times roaming was inhibited due to activity"),
  3125. IPW2100_ORD(RSSI_AT_ASSN,
  3126. "RSSI of associated AP at time of association"),
  3127. IPW2100_ORD(STAT_ASSN_CAUSE1,
  3128. "reassociation: no probe response or TX on hop"),
  3129. IPW2100_ORD(STAT_ASSN_CAUSE2,
  3130. "reassociation: poor tx/rx quality"),
  3131. IPW2100_ORD(STAT_ASSN_CAUSE3,
  3132. "reassociation: tx/rx quality (excessive AP load"),
  3133. IPW2100_ORD(STAT_ASSN_CAUSE4,
  3134. "reassociation: AP RSSI level"),
  3135. IPW2100_ORD(STAT_ASSN_CAUSE5,
  3136. "reassociations due to load leveling"),
  3137. IPW2100_ORD(STAT_AUTH_FAIL, "times authentication failed"),
  3138. IPW2100_ORD(STAT_AUTH_RESP_FAIL,
  3139. "times authentication response failed"),
  3140. IPW2100_ORD(STATION_TABLE_CNT,
  3141. "entries in association table"),
  3142. IPW2100_ORD(RSSI_AVG_CURR, "Current avg RSSI"),
  3143. IPW2100_ORD(POWER_MGMT_MODE, "Power mode - 0=CAM, 1=PSP"),
  3144. IPW2100_ORD(COUNTRY_CODE,
  3145. "IEEE country code as recv'd from beacon"),
  3146. IPW2100_ORD(COUNTRY_CHANNELS,
  3147. "channels suported by country"),
  3148. IPW2100_ORD(RESET_CNT, "adapter resets (warm)"),
  3149. IPW2100_ORD(BEACON_INTERVAL, "Beacon interval"),
  3150. IPW2100_ORD(ANTENNA_DIVERSITY,
  3151. "TRUE if antenna diversity is disabled"),
  3152. IPW2100_ORD(DTIM_PERIOD, "beacon intervals between DTIMs"),
  3153. IPW2100_ORD(OUR_FREQ,
  3154. "current radio freq lower digits - channel ID"),
  3155. IPW2100_ORD(RTC_TIME, "current RTC time"),
  3156. IPW2100_ORD(PORT_TYPE, "operating mode"),
  3157. IPW2100_ORD(CURRENT_TX_RATE, "current tx rate"),
  3158. IPW2100_ORD(SUPPORTED_RATES, "supported tx rates"),
  3159. IPW2100_ORD(ATIM_WINDOW, "current ATIM Window"),
  3160. IPW2100_ORD(BASIC_RATES, "basic tx rates"),
  3161. IPW2100_ORD(NIC_HIGHEST_RATE, "NIC highest tx rate"),
  3162. IPW2100_ORD(AP_HIGHEST_RATE, "AP highest tx rate"),
  3163. IPW2100_ORD(CAPABILITIES,
  3164. "Management frame capability field"),
  3165. IPW2100_ORD(AUTH_TYPE, "Type of authentication"),
  3166. IPW2100_ORD(RADIO_TYPE, "Adapter card platform type"),
  3167. IPW2100_ORD(RTS_THRESHOLD,
  3168. "Min packet length for RTS handshaking"),
  3169. IPW2100_ORD(INT_MODE, "International mode"),
  3170. IPW2100_ORD(FRAGMENTATION_THRESHOLD,
  3171. "protocol frag threshold"),
  3172. IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_START_ADDRESS,
  3173. "EEPROM offset in SRAM"),
  3174. IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_SIZE,
  3175. "EEPROM size in SRAM"),
  3176. IPW2100_ORD(EEPROM_SKU_CAPABILITY, "EEPROM SKU Capability"),
  3177. IPW2100_ORD(EEPROM_IBSS_11B_CHANNELS,
  3178. "EEPROM IBSS 11b channel set"),
  3179. IPW2100_ORD(MAC_VERSION, "MAC Version"),
  3180. IPW2100_ORD(MAC_REVISION, "MAC Revision"),
  3181. IPW2100_ORD(RADIO_VERSION, "Radio Version"),
  3182. IPW2100_ORD(NIC_MANF_DATE_TIME, "MANF Date/Time STAMP"),
  3183. IPW2100_ORD(UCODE_VERSION, "Ucode Version"),};
  3184. static ssize_t show_registers(struct device *d, struct device_attribute *attr,
  3185. char *buf)
  3186. {
  3187. int i;
  3188. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3189. struct net_device *dev = priv->net_dev;
  3190. char *out = buf;
  3191. u32 val = 0;
  3192. out += sprintf(out, "%30s [Address ] : Hex\n", "Register");
  3193. for (i = 0; i < ARRAY_SIZE(hw_data); i++) {
  3194. read_register(dev, hw_data[i].addr, &val);
  3195. out += sprintf(out, "%30s [%08X] : %08X\n",
  3196. hw_data[i].name, hw_data[i].addr, val);
  3197. }
  3198. return out - buf;
  3199. }
  3200. static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL);
  3201. static ssize_t show_hardware(struct device *d, struct device_attribute *attr,
  3202. char *buf)
  3203. {
  3204. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3205. struct net_device *dev = priv->net_dev;
  3206. char *out = buf;
  3207. int i;
  3208. out += sprintf(out, "%30s [Address ] : Hex\n", "NIC entry");
  3209. for (i = 0; i < ARRAY_SIZE(nic_data); i++) {
  3210. u8 tmp8;
  3211. u16 tmp16;
  3212. u32 tmp32;
  3213. switch (nic_data[i].size) {
  3214. case 1:
  3215. read_nic_byte(dev, nic_data[i].addr, &tmp8);
  3216. out += sprintf(out, "%30s [%08X] : %02X\n",
  3217. nic_data[i].name, nic_data[i].addr,
  3218. tmp8);
  3219. break;
  3220. case 2:
  3221. read_nic_word(dev, nic_data[i].addr, &tmp16);
  3222. out += sprintf(out, "%30s [%08X] : %04X\n",
  3223. nic_data[i].name, nic_data[i].addr,
  3224. tmp16);
  3225. break;
  3226. case 4:
  3227. read_nic_dword(dev, nic_data[i].addr, &tmp32);
  3228. out += sprintf(out, "%30s [%08X] : %08X\n",
  3229. nic_data[i].name, nic_data[i].addr,
  3230. tmp32);
  3231. break;
  3232. }
  3233. }
  3234. return out - buf;
  3235. }
  3236. static DEVICE_ATTR(hardware, S_IRUGO, show_hardware, NULL);
  3237. static ssize_t show_memory(struct device *d, struct device_attribute *attr,
  3238. char *buf)
  3239. {
  3240. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3241. struct net_device *dev = priv->net_dev;
  3242. static unsigned long loop = 0;
  3243. int len = 0;
  3244. u32 buffer[4];
  3245. int i;
  3246. char line[81];
  3247. if (loop >= 0x30000)
  3248. loop = 0;
  3249. /* sysfs provides us PAGE_SIZE buffer */
  3250. while (len < PAGE_SIZE - 128 && loop < 0x30000) {
  3251. if (priv->snapshot[0])
  3252. for (i = 0; i < 4; i++)
  3253. buffer[i] =
  3254. *(u32 *) SNAPSHOT_ADDR(loop + i * 4);
  3255. else
  3256. for (i = 0; i < 4; i++)
  3257. read_nic_dword(dev, loop + i * 4, &buffer[i]);
  3258. if (priv->dump_raw)
  3259. len += sprintf(buf + len,
  3260. "%c%c%c%c"
  3261. "%c%c%c%c"
  3262. "%c%c%c%c"
  3263. "%c%c%c%c",
  3264. ((u8 *) buffer)[0x0],
  3265. ((u8 *) buffer)[0x1],
  3266. ((u8 *) buffer)[0x2],
  3267. ((u8 *) buffer)[0x3],
  3268. ((u8 *) buffer)[0x4],
  3269. ((u8 *) buffer)[0x5],
  3270. ((u8 *) buffer)[0x6],
  3271. ((u8 *) buffer)[0x7],
  3272. ((u8 *) buffer)[0x8],
  3273. ((u8 *) buffer)[0x9],
  3274. ((u8 *) buffer)[0xa],
  3275. ((u8 *) buffer)[0xb],
  3276. ((u8 *) buffer)[0xc],
  3277. ((u8 *) buffer)[0xd],
  3278. ((u8 *) buffer)[0xe],
  3279. ((u8 *) buffer)[0xf]);
  3280. else
  3281. len += sprintf(buf + len, "%s\n",
  3282. snprint_line(line, sizeof(line),
  3283. (u8 *) buffer, 16, loop));
  3284. loop += 16;
  3285. }
  3286. return len;
  3287. }
  3288. static ssize_t store_memory(struct device *d, struct device_attribute *attr,
  3289. const char *buf, size_t count)
  3290. {
  3291. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3292. struct net_device *dev = priv->net_dev;
  3293. const char *p = buf;
  3294. (void)dev; /* kill unused-var warning for debug-only code */
  3295. if (count < 1)
  3296. return count;
  3297. if (p[0] == '1' ||
  3298. (count >= 2 && tolower(p[0]) == 'o' && tolower(p[1]) == 'n')) {
  3299. IPW_DEBUG_INFO("%s: Setting memory dump to RAW mode.\n",
  3300. dev->name);
  3301. priv->dump_raw = 1;
  3302. } else if (p[0] == '0' || (count >= 2 && tolower(p[0]) == 'o' &&
  3303. tolower(p[1]) == 'f')) {
  3304. IPW_DEBUG_INFO("%s: Setting memory dump to HEX mode.\n",
  3305. dev->name);
  3306. priv->dump_raw = 0;
  3307. } else if (tolower(p[0]) == 'r') {
  3308. IPW_DEBUG_INFO("%s: Resetting firmware snapshot.\n", dev->name);
  3309. ipw2100_snapshot_free(priv);
  3310. } else
  3311. IPW_DEBUG_INFO("%s: Usage: 0|on = HEX, 1|off = RAW, "
  3312. "reset = clear memory snapshot\n", dev->name);
  3313. return count;
  3314. }
  3315. static DEVICE_ATTR(memory, S_IWUSR | S_IRUGO, show_memory, store_memory);
  3316. static ssize_t show_ordinals(struct device *d, struct device_attribute *attr,
  3317. char *buf)
  3318. {
  3319. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3320. u32 val = 0;
  3321. int len = 0;
  3322. u32 val_len;
  3323. static int loop = 0;
  3324. if (priv->status & STATUS_RF_KILL_MASK)
  3325. return 0;
  3326. if (loop >= ARRAY_SIZE(ord_data))
  3327. loop = 0;
  3328. /* sysfs provides us PAGE_SIZE buffer */
  3329. while (len < PAGE_SIZE - 128 && loop < ARRAY_SIZE(ord_data)) {
  3330. val_len = sizeof(u32);
  3331. if (ipw2100_get_ordinal(priv, ord_data[loop].index, &val,
  3332. &val_len))
  3333. len += sprintf(buf + len, "[0x%02X] = ERROR %s\n",
  3334. ord_data[loop].index,
  3335. ord_data[loop].desc);
  3336. else
  3337. len += sprintf(buf + len, "[0x%02X] = 0x%08X %s\n",
  3338. ord_data[loop].index, val,
  3339. ord_data[loop].desc);
  3340. loop++;
  3341. }
  3342. return len;
  3343. }
  3344. static DEVICE_ATTR(ordinals, S_IRUGO, show_ordinals, NULL);
  3345. static ssize_t show_stats(struct device *d, struct device_attribute *attr,
  3346. char *buf)
  3347. {
  3348. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3349. char *out = buf;
  3350. out += sprintf(out, "interrupts: %d {tx: %d, rx: %d, other: %d}\n",
  3351. priv->interrupts, priv->tx_interrupts,
  3352. priv->rx_interrupts, priv->inta_other);
  3353. out += sprintf(out, "firmware resets: %d\n", priv->resets);
  3354. out += sprintf(out, "firmware hangs: %d\n", priv->hangs);
  3355. #ifdef CONFIG_IPW2100_DEBUG
  3356. out += sprintf(out, "packet mismatch image: %s\n",
  3357. priv->snapshot[0] ? "YES" : "NO");
  3358. #endif
  3359. return out - buf;
  3360. }
  3361. static DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL);
  3362. static int ipw2100_switch_mode(struct ipw2100_priv *priv, u32 mode)
  3363. {
  3364. int err;
  3365. if (mode == priv->ieee->iw_mode)
  3366. return 0;
  3367. err = ipw2100_disable_adapter(priv);
  3368. if (err) {
  3369. printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n",
  3370. priv->net_dev->name, err);
  3371. return err;
  3372. }
  3373. switch (mode) {
  3374. case IW_MODE_INFRA:
  3375. priv->net_dev->type = ARPHRD_ETHER;
  3376. break;
  3377. case IW_MODE_ADHOC:
  3378. priv->net_dev->type = ARPHRD_ETHER;
  3379. break;
  3380. #ifdef CONFIG_IPW2100_MONITOR
  3381. case IW_MODE_MONITOR:
  3382. priv->last_mode = priv->ieee->iw_mode;
  3383. priv->net_dev->type = ARPHRD_IEEE80211_RADIOTAP;
  3384. break;
  3385. #endif /* CONFIG_IPW2100_MONITOR */
  3386. }
  3387. priv->ieee->iw_mode = mode;
  3388. #ifdef CONFIG_PM
  3389. /* Indicate ipw2100_download_firmware download firmware
  3390. * from disk instead of memory. */
  3391. ipw2100_firmware.version = 0;
  3392. #endif
  3393. printk(KERN_INFO "%s: Reseting on mode change.\n", priv->net_dev->name);
  3394. priv->reset_backoff = 0;
  3395. schedule_reset(priv);
  3396. return 0;
  3397. }
  3398. static ssize_t show_internals(struct device *d, struct device_attribute *attr,
  3399. char *buf)
  3400. {
  3401. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3402. int len = 0;
  3403. #define DUMP_VAR(x,y) len += sprintf(buf + len, # x ": %" y "\n", priv-> x)
  3404. if (priv->status & STATUS_ASSOCIATED)
  3405. len += sprintf(buf + len, "connected: %lu\n",
  3406. get_seconds() - priv->connect_start);
  3407. else
  3408. len += sprintf(buf + len, "not connected\n");
  3409. DUMP_VAR(ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx], "p");
  3410. DUMP_VAR(status, "08lx");
  3411. DUMP_VAR(config, "08lx");
  3412. DUMP_VAR(capability, "08lx");
  3413. len +=
  3414. sprintf(buf + len, "last_rtc: %lu\n",
  3415. (unsigned long)priv->last_rtc);
  3416. DUMP_VAR(fatal_error, "d");
  3417. DUMP_VAR(stop_hang_check, "d");
  3418. DUMP_VAR(stop_rf_kill, "d");
  3419. DUMP_VAR(messages_sent, "d");
  3420. DUMP_VAR(tx_pend_stat.value, "d");
  3421. DUMP_VAR(tx_pend_stat.hi, "d");
  3422. DUMP_VAR(tx_free_stat.value, "d");
  3423. DUMP_VAR(tx_free_stat.lo, "d");
  3424. DUMP_VAR(msg_free_stat.value, "d");
  3425. DUMP_VAR(msg_free_stat.lo, "d");
  3426. DUMP_VAR(msg_pend_stat.value, "d");
  3427. DUMP_VAR(msg_pend_stat.hi, "d");
  3428. DUMP_VAR(fw_pend_stat.value, "d");
  3429. DUMP_VAR(fw_pend_stat.hi, "d");
  3430. DUMP_VAR(txq_stat.value, "d");
  3431. DUMP_VAR(txq_stat.lo, "d");
  3432. DUMP_VAR(ieee->scans, "d");
  3433. DUMP_VAR(reset_backoff, "d");
  3434. return len;
  3435. }
  3436. static DEVICE_ATTR(internals, S_IRUGO, show_internals, NULL);
  3437. static ssize_t show_bssinfo(struct device *d, struct device_attribute *attr,
  3438. char *buf)
  3439. {
  3440. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3441. char essid[IW_ESSID_MAX_SIZE + 1];
  3442. u8 bssid[ETH_ALEN];
  3443. u32 chan = 0;
  3444. char *out = buf;
  3445. unsigned int length;
  3446. int ret;
  3447. if (priv->status & STATUS_RF_KILL_MASK)
  3448. return 0;
  3449. memset(essid, 0, sizeof(essid));
  3450. memset(bssid, 0, sizeof(bssid));
  3451. length = IW_ESSID_MAX_SIZE;
  3452. ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID, essid, &length);
  3453. if (ret)
  3454. IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
  3455. __LINE__);
  3456. length = sizeof(bssid);
  3457. ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
  3458. bssid, &length);
  3459. if (ret)
  3460. IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
  3461. __LINE__);
  3462. length = sizeof(u32);
  3463. ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &length);
  3464. if (ret)
  3465. IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
  3466. __LINE__);
  3467. out += sprintf(out, "ESSID: %s\n", essid);
  3468. out += sprintf(out, "BSSID: %pM\n", bssid);
  3469. out += sprintf(out, "Channel: %d\n", chan);
  3470. return out - buf;
  3471. }
  3472. static DEVICE_ATTR(bssinfo, S_IRUGO, show_bssinfo, NULL);
  3473. #ifdef CONFIG_IPW2100_DEBUG
  3474. static ssize_t show_debug_level(struct device_driver *d, char *buf)
  3475. {
  3476. return sprintf(buf, "0x%08X\n", ipw2100_debug_level);
  3477. }
  3478. static ssize_t store_debug_level(struct device_driver *d,
  3479. const char *buf, size_t count)
  3480. {
  3481. char *p = (char *)buf;
  3482. u32 val;
  3483. if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
  3484. p++;
  3485. if (p[0] == 'x' || p[0] == 'X')
  3486. p++;
  3487. val = simple_strtoul(p, &p, 16);
  3488. } else
  3489. val = simple_strtoul(p, &p, 10);
  3490. if (p == buf)
  3491. IPW_DEBUG_INFO(": %s is not in hex or decimal form.\n", buf);
  3492. else
  3493. ipw2100_debug_level = val;
  3494. return strnlen(buf, count);
  3495. }
  3496. static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, show_debug_level,
  3497. store_debug_level);
  3498. #endif /* CONFIG_IPW2100_DEBUG */
  3499. static ssize_t show_fatal_error(struct device *d,
  3500. struct device_attribute *attr, char *buf)
  3501. {
  3502. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3503. char *out = buf;
  3504. int i;
  3505. if (priv->fatal_error)
  3506. out += sprintf(out, "0x%08X\n", priv->fatal_error);
  3507. else
  3508. out += sprintf(out, "0\n");
  3509. for (i = 1; i <= IPW2100_ERROR_QUEUE; i++) {
  3510. if (!priv->fatal_errors[(priv->fatal_index - i) %
  3511. IPW2100_ERROR_QUEUE])
  3512. continue;
  3513. out += sprintf(out, "%d. 0x%08X\n", i,
  3514. priv->fatal_errors[(priv->fatal_index - i) %
  3515. IPW2100_ERROR_QUEUE]);
  3516. }
  3517. return out - buf;
  3518. }
  3519. static ssize_t store_fatal_error(struct device *d,
  3520. struct device_attribute *attr, const char *buf,
  3521. size_t count)
  3522. {
  3523. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3524. schedule_reset(priv);
  3525. return count;
  3526. }
  3527. static DEVICE_ATTR(fatal_error, S_IWUSR | S_IRUGO, show_fatal_error,
  3528. store_fatal_error);
  3529. static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
  3530. char *buf)
  3531. {
  3532. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3533. return sprintf(buf, "%d\n", priv->ieee->scan_age);
  3534. }
  3535. static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
  3536. const char *buf, size_t count)
  3537. {
  3538. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3539. struct net_device *dev = priv->net_dev;
  3540. char buffer[] = "00000000";
  3541. unsigned long len =
  3542. (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
  3543. unsigned long val;
  3544. char *p = buffer;
  3545. (void)dev; /* kill unused-var warning for debug-only code */
  3546. IPW_DEBUG_INFO("enter\n");
  3547. strncpy(buffer, buf, len);
  3548. buffer[len] = 0;
  3549. if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
  3550. p++;
  3551. if (p[0] == 'x' || p[0] == 'X')
  3552. p++;
  3553. val = simple_strtoul(p, &p, 16);
  3554. } else
  3555. val = simple_strtoul(p, &p, 10);
  3556. if (p == buffer) {
  3557. IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
  3558. } else {
  3559. priv->ieee->scan_age = val;
  3560. IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
  3561. }
  3562. IPW_DEBUG_INFO("exit\n");
  3563. return len;
  3564. }
  3565. static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
  3566. static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
  3567. char *buf)
  3568. {
  3569. /* 0 - RF kill not enabled
  3570. 1 - SW based RF kill active (sysfs)
  3571. 2 - HW based RF kill active
  3572. 3 - Both HW and SW baed RF kill active */
  3573. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3574. int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
  3575. (rf_kill_active(priv) ? 0x2 : 0x0);
  3576. return sprintf(buf, "%i\n", val);
  3577. }
  3578. static int ipw_radio_kill_sw(struct ipw2100_priv *priv, int disable_radio)
  3579. {
  3580. if ((disable_radio ? 1 : 0) ==
  3581. (priv->status & STATUS_RF_KILL_SW ? 1 : 0))
  3582. return 0;
  3583. IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
  3584. disable_radio ? "OFF" : "ON");
  3585. mutex_lock(&priv->action_mutex);
  3586. if (disable_radio) {
  3587. priv->status |= STATUS_RF_KILL_SW;
  3588. ipw2100_down(priv);
  3589. } else {
  3590. priv->status &= ~STATUS_RF_KILL_SW;
  3591. if (rf_kill_active(priv)) {
  3592. IPW_DEBUG_RF_KILL("Can not turn radio back on - "
  3593. "disabled by HW switch\n");
  3594. /* Make sure the RF_KILL check timer is running */
  3595. priv->stop_rf_kill = 0;
  3596. cancel_delayed_work(&priv->rf_kill);
  3597. schedule_delayed_work(&priv->rf_kill,
  3598. round_jiffies_relative(HZ));
  3599. } else
  3600. schedule_reset(priv);
  3601. }
  3602. mutex_unlock(&priv->action_mutex);
  3603. return 1;
  3604. }
  3605. static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
  3606. const char *buf, size_t count)
  3607. {
  3608. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3609. ipw_radio_kill_sw(priv, buf[0] == '1');
  3610. return count;
  3611. }
  3612. static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
  3613. static struct attribute *ipw2100_sysfs_entries[] = {
  3614. &dev_attr_hardware.attr,
  3615. &dev_attr_registers.attr,
  3616. &dev_attr_ordinals.attr,
  3617. &dev_attr_pci.attr,
  3618. &dev_attr_stats.attr,
  3619. &dev_attr_internals.attr,
  3620. &dev_attr_bssinfo.attr,
  3621. &dev_attr_memory.attr,
  3622. &dev_attr_scan_age.attr,
  3623. &dev_attr_fatal_error.attr,
  3624. &dev_attr_rf_kill.attr,
  3625. &dev_attr_cfg.attr,
  3626. &dev_attr_status.attr,
  3627. &dev_attr_capability.attr,
  3628. NULL,
  3629. };
  3630. static struct attribute_group ipw2100_attribute_group = {
  3631. .attrs = ipw2100_sysfs_entries,
  3632. };
  3633. static int status_queue_allocate(struct ipw2100_priv *priv, int entries)
  3634. {
  3635. struct ipw2100_status_queue *q = &priv->status_queue;
  3636. IPW_DEBUG_INFO("enter\n");
  3637. q->size = entries * sizeof(struct ipw2100_status);
  3638. q->drv =
  3639. (struct ipw2100_status *)pci_alloc_consistent(priv->pci_dev,
  3640. q->size, &q->nic);
  3641. if (!q->drv) {
  3642. IPW_DEBUG_WARNING("Can not allocate status queue.\n");
  3643. return -ENOMEM;
  3644. }
  3645. memset(q->drv, 0, q->size);
  3646. IPW_DEBUG_INFO("exit\n");
  3647. return 0;
  3648. }
  3649. static void status_queue_free(struct ipw2100_priv *priv)
  3650. {
  3651. IPW_DEBUG_INFO("enter\n");
  3652. if (priv->status_queue.drv) {
  3653. pci_free_consistent(priv->pci_dev, priv->status_queue.size,
  3654. priv->status_queue.drv,
  3655. priv->status_queue.nic);
  3656. priv->status_queue.drv = NULL;
  3657. }
  3658. IPW_DEBUG_INFO("exit\n");
  3659. }
  3660. static int bd_queue_allocate(struct ipw2100_priv *priv,
  3661. struct ipw2100_bd_queue *q, int entries)
  3662. {
  3663. IPW_DEBUG_INFO("enter\n");
  3664. memset(q, 0, sizeof(struct ipw2100_bd_queue));
  3665. q->entries = entries;
  3666. q->size = entries * sizeof(struct ipw2100_bd);
  3667. q->drv = pci_alloc_consistent(priv->pci_dev, q->size, &q->nic);
  3668. if (!q->drv) {
  3669. IPW_DEBUG_INFO
  3670. ("can't allocate shared memory for buffer descriptors\n");
  3671. return -ENOMEM;
  3672. }
  3673. memset(q->drv, 0, q->size);
  3674. IPW_DEBUG_INFO("exit\n");
  3675. return 0;
  3676. }
  3677. static void bd_queue_free(struct ipw2100_priv *priv, struct ipw2100_bd_queue *q)
  3678. {
  3679. IPW_DEBUG_INFO("enter\n");
  3680. if (!q)
  3681. return;
  3682. if (q->drv) {
  3683. pci_free_consistent(priv->pci_dev, q->size, q->drv, q->nic);
  3684. q->drv = NULL;
  3685. }
  3686. IPW_DEBUG_INFO("exit\n");
  3687. }
  3688. static void bd_queue_initialize(struct ipw2100_priv *priv,
  3689. struct ipw2100_bd_queue *q, u32 base, u32 size,
  3690. u32 r, u32 w)
  3691. {
  3692. IPW_DEBUG_INFO("enter\n");
  3693. IPW_DEBUG_INFO("initializing bd queue at virt=%p, phys=%08x\n", q->drv,
  3694. (u32) q->nic);
  3695. write_register(priv->net_dev, base, q->nic);
  3696. write_register(priv->net_dev, size, q->entries);
  3697. write_register(priv->net_dev, r, q->oldest);
  3698. write_register(priv->net_dev, w, q->next);
  3699. IPW_DEBUG_INFO("exit\n");
  3700. }
  3701. static void ipw2100_kill_works(struct ipw2100_priv *priv)
  3702. {
  3703. priv->stop_rf_kill = 1;
  3704. priv->stop_hang_check = 1;
  3705. cancel_delayed_work_sync(&priv->reset_work);
  3706. cancel_delayed_work_sync(&priv->security_work);
  3707. cancel_delayed_work_sync(&priv->wx_event_work);
  3708. cancel_delayed_work_sync(&priv->hang_check);
  3709. cancel_delayed_work_sync(&priv->rf_kill);
  3710. cancel_work_sync(&priv->scan_event_now);
  3711. cancel_delayed_work_sync(&priv->scan_event_later);
  3712. }
  3713. static int ipw2100_tx_allocate(struct ipw2100_priv *priv)
  3714. {
  3715. int i, j, err = -EINVAL;
  3716. void *v;
  3717. dma_addr_t p;
  3718. IPW_DEBUG_INFO("enter\n");
  3719. err = bd_queue_allocate(priv, &priv->tx_queue, TX_QUEUE_LENGTH);
  3720. if (err) {
  3721. IPW_DEBUG_ERROR("%s: failed bd_queue_allocate\n",
  3722. priv->net_dev->name);
  3723. return err;
  3724. }
  3725. priv->tx_buffers =
  3726. kmalloc(TX_PENDED_QUEUE_LENGTH * sizeof(struct ipw2100_tx_packet),
  3727. GFP_ATOMIC);
  3728. if (!priv->tx_buffers) {
  3729. printk(KERN_ERR DRV_NAME
  3730. ": %s: alloc failed form tx buffers.\n",
  3731. priv->net_dev->name);
  3732. bd_queue_free(priv, &priv->tx_queue);
  3733. return -ENOMEM;
  3734. }
  3735. for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
  3736. v = pci_alloc_consistent(priv->pci_dev,
  3737. sizeof(struct ipw2100_data_header),
  3738. &p);
  3739. if (!v) {
  3740. printk(KERN_ERR DRV_NAME
  3741. ": %s: PCI alloc failed for tx " "buffers.\n",
  3742. priv->net_dev->name);
  3743. err = -ENOMEM;
  3744. break;
  3745. }
  3746. priv->tx_buffers[i].type = DATA;
  3747. priv->tx_buffers[i].info.d_struct.data =
  3748. (struct ipw2100_data_header *)v;
  3749. priv->tx_buffers[i].info.d_struct.data_phys = p;
  3750. priv->tx_buffers[i].info.d_struct.txb = NULL;
  3751. }
  3752. if (i == TX_PENDED_QUEUE_LENGTH)
  3753. return 0;
  3754. for (j = 0; j < i; j++) {
  3755. pci_free_consistent(priv->pci_dev,
  3756. sizeof(struct ipw2100_data_header),
  3757. priv->tx_buffers[j].info.d_struct.data,
  3758. priv->tx_buffers[j].info.d_struct.
  3759. data_phys);
  3760. }
  3761. kfree(priv->tx_buffers);
  3762. priv->tx_buffers = NULL;
  3763. return err;
  3764. }
  3765. static void ipw2100_tx_initialize(struct ipw2100_priv *priv)
  3766. {
  3767. int i;
  3768. IPW_DEBUG_INFO("enter\n");
  3769. /*
  3770. * reinitialize packet info lists
  3771. */
  3772. INIT_LIST_HEAD(&priv->fw_pend_list);
  3773. INIT_STAT(&priv->fw_pend_stat);
  3774. /*
  3775. * reinitialize lists
  3776. */
  3777. INIT_LIST_HEAD(&priv->tx_pend_list);
  3778. INIT_LIST_HEAD(&priv->tx_free_list);
  3779. INIT_STAT(&priv->tx_pend_stat);
  3780. INIT_STAT(&priv->tx_free_stat);
  3781. for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
  3782. /* We simply drop any SKBs that have been queued for
  3783. * transmit */
  3784. if (priv->tx_buffers[i].info.d_struct.txb) {
  3785. libipw_txb_free(priv->tx_buffers[i].info.d_struct.
  3786. txb);
  3787. priv->tx_buffers[i].info.d_struct.txb = NULL;
  3788. }
  3789. list_add_tail(&priv->tx_buffers[i].list, &priv->tx_free_list);
  3790. }
  3791. SET_STAT(&priv->tx_free_stat, i);
  3792. priv->tx_queue.oldest = 0;
  3793. priv->tx_queue.available = priv->tx_queue.entries;
  3794. priv->tx_queue.next = 0;
  3795. INIT_STAT(&priv->txq_stat);
  3796. SET_STAT(&priv->txq_stat, priv->tx_queue.available);
  3797. bd_queue_initialize(priv, &priv->tx_queue,
  3798. IPW_MEM_HOST_SHARED_TX_QUEUE_BD_BASE,
  3799. IPW_MEM_HOST_SHARED_TX_QUEUE_BD_SIZE,
  3800. IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
  3801. IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX);
  3802. IPW_DEBUG_INFO("exit\n");
  3803. }
  3804. static void ipw2100_tx_free(struct ipw2100_priv *priv)
  3805. {
  3806. int i;
  3807. IPW_DEBUG_INFO("enter\n");
  3808. bd_queue_free(priv, &priv->tx_queue);
  3809. if (!priv->tx_buffers)
  3810. return;
  3811. for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
  3812. if (priv->tx_buffers[i].info.d_struct.txb) {
  3813. libipw_txb_free(priv->tx_buffers[i].info.d_struct.
  3814. txb);
  3815. priv->tx_buffers[i].info.d_struct.txb = NULL;
  3816. }
  3817. if (priv->tx_buffers[i].info.d_struct.data)
  3818. pci_free_consistent(priv->pci_dev,
  3819. sizeof(struct ipw2100_data_header),
  3820. priv->tx_buffers[i].info.d_struct.
  3821. data,
  3822. priv->tx_buffers[i].info.d_struct.
  3823. data_phys);
  3824. }
  3825. kfree(priv->tx_buffers);
  3826. priv->tx_buffers = NULL;
  3827. IPW_DEBUG_INFO("exit\n");
  3828. }
  3829. static int ipw2100_rx_allocate(struct ipw2100_priv *priv)
  3830. {
  3831. int i, j, err = -EINVAL;
  3832. IPW_DEBUG_INFO("enter\n");
  3833. err = bd_queue_allocate(priv, &priv->rx_queue, RX_QUEUE_LENGTH);
  3834. if (err) {
  3835. IPW_DEBUG_INFO("failed bd_queue_allocate\n");
  3836. return err;
  3837. }
  3838. err = status_queue_allocate(priv, RX_QUEUE_LENGTH);
  3839. if (err) {
  3840. IPW_DEBUG_INFO("failed status_queue_allocate\n");
  3841. bd_queue_free(priv, &priv->rx_queue);
  3842. return err;
  3843. }
  3844. /*
  3845. * allocate packets
  3846. */
  3847. priv->rx_buffers = kmalloc(RX_QUEUE_LENGTH *
  3848. sizeof(struct ipw2100_rx_packet),
  3849. GFP_KERNEL);
  3850. if (!priv->rx_buffers) {
  3851. IPW_DEBUG_INFO("can't allocate rx packet buffer table\n");
  3852. bd_queue_free(priv, &priv->rx_queue);
  3853. status_queue_free(priv);
  3854. return -ENOMEM;
  3855. }
  3856. for (i = 0; i < RX_QUEUE_LENGTH; i++) {
  3857. struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
  3858. err = ipw2100_alloc_skb(priv, packet);
  3859. if (unlikely(err)) {
  3860. err = -ENOMEM;
  3861. break;
  3862. }
  3863. /* The BD holds the cache aligned address */
  3864. priv->rx_queue.drv[i].host_addr = packet->dma_addr;
  3865. priv->rx_queue.drv[i].buf_length = IPW_RX_NIC_BUFFER_LENGTH;
  3866. priv->status_queue.drv[i].status_fields = 0;
  3867. }
  3868. if (i == RX_QUEUE_LENGTH)
  3869. return 0;
  3870. for (j = 0; j < i; j++) {
  3871. pci_unmap_single(priv->pci_dev, priv->rx_buffers[j].dma_addr,
  3872. sizeof(struct ipw2100_rx_packet),
  3873. PCI_DMA_FROMDEVICE);
  3874. dev_kfree_skb(priv->rx_buffers[j].skb);
  3875. }
  3876. kfree(priv->rx_buffers);
  3877. priv->rx_buffers = NULL;
  3878. bd_queue_free(priv, &priv->rx_queue);
  3879. status_queue_free(priv);
  3880. return err;
  3881. }
  3882. static void ipw2100_rx_initialize(struct ipw2100_priv *priv)
  3883. {
  3884. IPW_DEBUG_INFO("enter\n");
  3885. priv->rx_queue.oldest = 0;
  3886. priv->rx_queue.available = priv->rx_queue.entries - 1;
  3887. priv->rx_queue.next = priv->rx_queue.entries - 1;
  3888. INIT_STAT(&priv->rxq_stat);
  3889. SET_STAT(&priv->rxq_stat, priv->rx_queue.available);
  3890. bd_queue_initialize(priv, &priv->rx_queue,
  3891. IPW_MEM_HOST_SHARED_RX_BD_BASE,
  3892. IPW_MEM_HOST_SHARED_RX_BD_SIZE,
  3893. IPW_MEM_HOST_SHARED_RX_READ_INDEX,
  3894. IPW_MEM_HOST_SHARED_RX_WRITE_INDEX);
  3895. /* set up the status queue */
  3896. write_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_STATUS_BASE,
  3897. priv->status_queue.nic);
  3898. IPW_DEBUG_INFO("exit\n");
  3899. }
  3900. static void ipw2100_rx_free(struct ipw2100_priv *priv)
  3901. {
  3902. int i;
  3903. IPW_DEBUG_INFO("enter\n");
  3904. bd_queue_free(priv, &priv->rx_queue);
  3905. status_queue_free(priv);
  3906. if (!priv->rx_buffers)
  3907. return;
  3908. for (i = 0; i < RX_QUEUE_LENGTH; i++) {
  3909. if (priv->rx_buffers[i].rxp) {
  3910. pci_unmap_single(priv->pci_dev,
  3911. priv->rx_buffers[i].dma_addr,
  3912. sizeof(struct ipw2100_rx),
  3913. PCI_DMA_FROMDEVICE);
  3914. dev_kfree_skb(priv->rx_buffers[i].skb);
  3915. }
  3916. }
  3917. kfree(priv->rx_buffers);
  3918. priv->rx_buffers = NULL;
  3919. IPW_DEBUG_INFO("exit\n");
  3920. }
  3921. static int ipw2100_read_mac_address(struct ipw2100_priv *priv)
  3922. {
  3923. u32 length = ETH_ALEN;
  3924. u8 addr[ETH_ALEN];
  3925. int err;
  3926. err = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ADAPTER_MAC, addr, &length);
  3927. if (err) {
  3928. IPW_DEBUG_INFO("MAC address read failed\n");
  3929. return -EIO;
  3930. }
  3931. memcpy(priv->net_dev->dev_addr, addr, ETH_ALEN);
  3932. IPW_DEBUG_INFO("card MAC is %pM\n", priv->net_dev->dev_addr);
  3933. return 0;
  3934. }
  3935. /********************************************************************
  3936. *
  3937. * Firmware Commands
  3938. *
  3939. ********************************************************************/
  3940. static int ipw2100_set_mac_address(struct ipw2100_priv *priv, int batch_mode)
  3941. {
  3942. struct host_command cmd = {
  3943. .host_command = ADAPTER_ADDRESS,
  3944. .host_command_sequence = 0,
  3945. .host_command_length = ETH_ALEN
  3946. };
  3947. int err;
  3948. IPW_DEBUG_HC("SET_MAC_ADDRESS\n");
  3949. IPW_DEBUG_INFO("enter\n");
  3950. if (priv->config & CFG_CUSTOM_MAC) {
  3951. memcpy(cmd.host_command_parameters, priv->mac_addr, ETH_ALEN);
  3952. memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
  3953. } else
  3954. memcpy(cmd.host_command_parameters, priv->net_dev->dev_addr,
  3955. ETH_ALEN);
  3956. err = ipw2100_hw_send_command(priv, &cmd);
  3957. IPW_DEBUG_INFO("exit\n");
  3958. return err;
  3959. }
  3960. static int ipw2100_set_port_type(struct ipw2100_priv *priv, u32 port_type,
  3961. int batch_mode)
  3962. {
  3963. struct host_command cmd = {
  3964. .host_command = PORT_TYPE,
  3965. .host_command_sequence = 0,
  3966. .host_command_length = sizeof(u32)
  3967. };
  3968. int err;
  3969. switch (port_type) {
  3970. case IW_MODE_INFRA:
  3971. cmd.host_command_parameters[0] = IPW_BSS;
  3972. break;
  3973. case IW_MODE_ADHOC:
  3974. cmd.host_command_parameters[0] = IPW_IBSS;
  3975. break;
  3976. }
  3977. IPW_DEBUG_HC("PORT_TYPE: %s\n",
  3978. port_type == IPW_IBSS ? "Ad-Hoc" : "Managed");
  3979. if (!batch_mode) {
  3980. err = ipw2100_disable_adapter(priv);
  3981. if (err) {
  3982. printk(KERN_ERR DRV_NAME
  3983. ": %s: Could not disable adapter %d\n",
  3984. priv->net_dev->name, err);
  3985. return err;
  3986. }
  3987. }
  3988. /* send cmd to firmware */
  3989. err = ipw2100_hw_send_command(priv, &cmd);
  3990. if (!batch_mode)
  3991. ipw2100_enable_adapter(priv);
  3992. return err;
  3993. }
  3994. static int ipw2100_set_channel(struct ipw2100_priv *priv, u32 channel,
  3995. int batch_mode)
  3996. {
  3997. struct host_command cmd = {
  3998. .host_command = CHANNEL,
  3999. .host_command_sequence = 0,
  4000. .host_command_length = sizeof(u32)
  4001. };
  4002. int err;
  4003. cmd.host_command_parameters[0] = channel;
  4004. IPW_DEBUG_HC("CHANNEL: %d\n", channel);
  4005. /* If BSS then we don't support channel selection */
  4006. if (priv->ieee->iw_mode == IW_MODE_INFRA)
  4007. return 0;
  4008. if ((channel != 0) &&
  4009. ((channel < REG_MIN_CHANNEL) || (channel > REG_MAX_CHANNEL)))
  4010. return -EINVAL;
  4011. if (!batch_mode) {
  4012. err = ipw2100_disable_adapter(priv);
  4013. if (err)
  4014. return err;
  4015. }
  4016. err = ipw2100_hw_send_command(priv, &cmd);
  4017. if (err) {
  4018. IPW_DEBUG_INFO("Failed to set channel to %d", channel);
  4019. return err;
  4020. }
  4021. if (channel)
  4022. priv->config |= CFG_STATIC_CHANNEL;
  4023. else
  4024. priv->config &= ~CFG_STATIC_CHANNEL;
  4025. priv->channel = channel;
  4026. if (!batch_mode) {
  4027. err = ipw2100_enable_adapter(priv);
  4028. if (err)
  4029. return err;
  4030. }
  4031. return 0;
  4032. }
  4033. static int ipw2100_system_config(struct ipw2100_priv *priv, int batch_mode)
  4034. {
  4035. struct host_command cmd = {
  4036. .host_command = SYSTEM_CONFIG,
  4037. .host_command_sequence = 0,
  4038. .host_command_length = 12,
  4039. };
  4040. u32 ibss_mask, len = sizeof(u32);
  4041. int err;
  4042. /* Set system configuration */
  4043. if (!batch_mode) {
  4044. err = ipw2100_disable_adapter(priv);
  4045. if (err)
  4046. return err;
  4047. }
  4048. if (priv->ieee->iw_mode == IW_MODE_ADHOC)
  4049. cmd.host_command_parameters[0] |= IPW_CFG_IBSS_AUTO_START;
  4050. cmd.host_command_parameters[0] |= IPW_CFG_IBSS_MASK |
  4051. IPW_CFG_BSS_MASK | IPW_CFG_802_1x_ENABLE;
  4052. if (!(priv->config & CFG_LONG_PREAMBLE))
  4053. cmd.host_command_parameters[0] |= IPW_CFG_PREAMBLE_AUTO;
  4054. err = ipw2100_get_ordinal(priv,
  4055. IPW_ORD_EEPROM_IBSS_11B_CHANNELS,
  4056. &ibss_mask, &len);
  4057. if (err)
  4058. ibss_mask = IPW_IBSS_11B_DEFAULT_MASK;
  4059. cmd.host_command_parameters[1] = REG_CHANNEL_MASK;
  4060. cmd.host_command_parameters[2] = REG_CHANNEL_MASK & ibss_mask;
  4061. /* 11b only */
  4062. /*cmd.host_command_parameters[0] |= DIVERSITY_ANTENNA_A; */
  4063. err = ipw2100_hw_send_command(priv, &cmd);
  4064. if (err)
  4065. return err;
  4066. /* If IPv6 is configured in the kernel then we don't want to filter out all
  4067. * of the multicast packets as IPv6 needs some. */
  4068. #if !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
  4069. cmd.host_command = ADD_MULTICAST;
  4070. cmd.host_command_sequence = 0;
  4071. cmd.host_command_length = 0;
  4072. ipw2100_hw_send_command(priv, &cmd);
  4073. #endif
  4074. if (!batch_mode) {
  4075. err = ipw2100_enable_adapter(priv);
  4076. if (err)
  4077. return err;
  4078. }
  4079. return 0;
  4080. }
  4081. static int ipw2100_set_tx_rates(struct ipw2100_priv *priv, u32 rate,
  4082. int batch_mode)
  4083. {
  4084. struct host_command cmd = {
  4085. .host_command = BASIC_TX_RATES,
  4086. .host_command_sequence = 0,
  4087. .host_command_length = 4
  4088. };
  4089. int err;
  4090. cmd.host_command_parameters[0] = rate & TX_RATE_MASK;
  4091. if (!batch_mode) {
  4092. err = ipw2100_disable_adapter(priv);
  4093. if (err)
  4094. return err;
  4095. }
  4096. /* Set BASIC TX Rate first */
  4097. ipw2100_hw_send_command(priv, &cmd);
  4098. /* Set TX Rate */
  4099. cmd.host_command = TX_RATES;
  4100. ipw2100_hw_send_command(priv, &cmd);
  4101. /* Set MSDU TX Rate */
  4102. cmd.host_command = MSDU_TX_RATES;
  4103. ipw2100_hw_send_command(priv, &cmd);
  4104. if (!batch_mode) {
  4105. err = ipw2100_enable_adapter(priv);
  4106. if (err)
  4107. return err;
  4108. }
  4109. priv->tx_rates = rate;
  4110. return 0;
  4111. }
  4112. static int ipw2100_set_power_mode(struct ipw2100_priv *priv, int power_level)
  4113. {
  4114. struct host_command cmd = {
  4115. .host_command = POWER_MODE,
  4116. .host_command_sequence = 0,
  4117. .host_command_length = 4
  4118. };
  4119. int err;
  4120. cmd.host_command_parameters[0] = power_level;
  4121. err = ipw2100_hw_send_command(priv, &cmd);
  4122. if (err)
  4123. return err;
  4124. if (power_level == IPW_POWER_MODE_CAM)
  4125. priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
  4126. else
  4127. priv->power_mode = IPW_POWER_ENABLED | power_level;
  4128. #ifdef IPW2100_TX_POWER
  4129. if (priv->port_type == IBSS && priv->adhoc_power != DFTL_IBSS_TX_POWER) {
  4130. /* Set beacon interval */
  4131. cmd.host_command = TX_POWER_INDEX;
  4132. cmd.host_command_parameters[0] = (u32) priv->adhoc_power;
  4133. err = ipw2100_hw_send_command(priv, &cmd);
  4134. if (err)
  4135. return err;
  4136. }
  4137. #endif
  4138. return 0;
  4139. }
  4140. static int ipw2100_set_rts_threshold(struct ipw2100_priv *priv, u32 threshold)
  4141. {
  4142. struct host_command cmd = {
  4143. .host_command = RTS_THRESHOLD,
  4144. .host_command_sequence = 0,
  4145. .host_command_length = 4
  4146. };
  4147. int err;
  4148. if (threshold & RTS_DISABLED)
  4149. cmd.host_command_parameters[0] = MAX_RTS_THRESHOLD;
  4150. else
  4151. cmd.host_command_parameters[0] = threshold & ~RTS_DISABLED;
  4152. err = ipw2100_hw_send_command(priv, &cmd);
  4153. if (err)
  4154. return err;
  4155. priv->rts_threshold = threshold;
  4156. return 0;
  4157. }
  4158. #if 0
  4159. int ipw2100_set_fragmentation_threshold(struct ipw2100_priv *priv,
  4160. u32 threshold, int batch_mode)
  4161. {
  4162. struct host_command cmd = {
  4163. .host_command = FRAG_THRESHOLD,
  4164. .host_command_sequence = 0,
  4165. .host_command_length = 4,
  4166. .host_command_parameters[0] = 0,
  4167. };
  4168. int err;
  4169. if (!batch_mode) {
  4170. err = ipw2100_disable_adapter(priv);
  4171. if (err)
  4172. return err;
  4173. }
  4174. if (threshold == 0)
  4175. threshold = DEFAULT_FRAG_THRESHOLD;
  4176. else {
  4177. threshold = max(threshold, MIN_FRAG_THRESHOLD);
  4178. threshold = min(threshold, MAX_FRAG_THRESHOLD);
  4179. }
  4180. cmd.host_command_parameters[0] = threshold;
  4181. IPW_DEBUG_HC("FRAG_THRESHOLD: %u\n", threshold);
  4182. err = ipw2100_hw_send_command(priv, &cmd);
  4183. if (!batch_mode)
  4184. ipw2100_enable_adapter(priv);
  4185. if (!err)
  4186. priv->frag_threshold = threshold;
  4187. return err;
  4188. }
  4189. #endif
  4190. static int ipw2100_set_short_retry(struct ipw2100_priv *priv, u32 retry)
  4191. {
  4192. struct host_command cmd = {
  4193. .host_command = SHORT_RETRY_LIMIT,
  4194. .host_command_sequence = 0,
  4195. .host_command_length = 4
  4196. };
  4197. int err;
  4198. cmd.host_command_parameters[0] = retry;
  4199. err = ipw2100_hw_send_command(priv, &cmd);
  4200. if (err)
  4201. return err;
  4202. priv->short_retry_limit = retry;
  4203. return 0;
  4204. }
  4205. static int ipw2100_set_long_retry(struct ipw2100_priv *priv, u32 retry)
  4206. {
  4207. struct host_command cmd = {
  4208. .host_command = LONG_RETRY_LIMIT,
  4209. .host_command_sequence = 0,
  4210. .host_command_length = 4
  4211. };
  4212. int err;
  4213. cmd.host_command_parameters[0] = retry;
  4214. err = ipw2100_hw_send_command(priv, &cmd);
  4215. if (err)
  4216. return err;
  4217. priv->long_retry_limit = retry;
  4218. return 0;
  4219. }
  4220. static int ipw2100_set_mandatory_bssid(struct ipw2100_priv *priv, u8 * bssid,
  4221. int batch_mode)
  4222. {
  4223. struct host_command cmd = {
  4224. .host_command = MANDATORY_BSSID,
  4225. .host_command_sequence = 0,
  4226. .host_command_length = (bssid == NULL) ? 0 : ETH_ALEN
  4227. };
  4228. int err;
  4229. #ifdef CONFIG_IPW2100_DEBUG
  4230. if (bssid != NULL)
  4231. IPW_DEBUG_HC("MANDATORY_BSSID: %pM\n", bssid);
  4232. else
  4233. IPW_DEBUG_HC("MANDATORY_BSSID: <clear>\n");
  4234. #endif
  4235. /* if BSSID is empty then we disable mandatory bssid mode */
  4236. if (bssid != NULL)
  4237. memcpy(cmd.host_command_parameters, bssid, ETH_ALEN);
  4238. if (!batch_mode) {
  4239. err = ipw2100_disable_adapter(priv);
  4240. if (err)
  4241. return err;
  4242. }
  4243. err = ipw2100_hw_send_command(priv, &cmd);
  4244. if (!batch_mode)
  4245. ipw2100_enable_adapter(priv);
  4246. return err;
  4247. }
  4248. static int ipw2100_disassociate_bssid(struct ipw2100_priv *priv)
  4249. {
  4250. struct host_command cmd = {
  4251. .host_command = DISASSOCIATION_BSSID,
  4252. .host_command_sequence = 0,
  4253. .host_command_length = ETH_ALEN
  4254. };
  4255. int err;
  4256. int len;
  4257. IPW_DEBUG_HC("DISASSOCIATION_BSSID\n");
  4258. len = ETH_ALEN;
  4259. /* The Firmware currently ignores the BSSID and just disassociates from
  4260. * the currently associated AP -- but in the off chance that a future
  4261. * firmware does use the BSSID provided here, we go ahead and try and
  4262. * set it to the currently associated AP's BSSID */
  4263. memcpy(cmd.host_command_parameters, priv->bssid, ETH_ALEN);
  4264. err = ipw2100_hw_send_command(priv, &cmd);
  4265. return err;
  4266. }
  4267. static int ipw2100_set_wpa_ie(struct ipw2100_priv *,
  4268. struct ipw2100_wpa_assoc_frame *, int)
  4269. __attribute__ ((unused));
  4270. static int ipw2100_set_wpa_ie(struct ipw2100_priv *priv,
  4271. struct ipw2100_wpa_assoc_frame *wpa_frame,
  4272. int batch_mode)
  4273. {
  4274. struct host_command cmd = {
  4275. .host_command = SET_WPA_IE,
  4276. .host_command_sequence = 0,
  4277. .host_command_length = sizeof(struct ipw2100_wpa_assoc_frame),
  4278. };
  4279. int err;
  4280. IPW_DEBUG_HC("SET_WPA_IE\n");
  4281. if (!batch_mode) {
  4282. err = ipw2100_disable_adapter(priv);
  4283. if (err)
  4284. return err;
  4285. }
  4286. memcpy(cmd.host_command_parameters, wpa_frame,
  4287. sizeof(struct ipw2100_wpa_assoc_frame));
  4288. err = ipw2100_hw_send_command(priv, &cmd);
  4289. if (!batch_mode) {
  4290. if (ipw2100_enable_adapter(priv))
  4291. err = -EIO;
  4292. }
  4293. return err;
  4294. }
  4295. struct security_info_params {
  4296. u32 allowed_ciphers;
  4297. u16 version;
  4298. u8 auth_mode;
  4299. u8 replay_counters_number;
  4300. u8 unicast_using_group;
  4301. } __packed;
  4302. static int ipw2100_set_security_information(struct ipw2100_priv *priv,
  4303. int auth_mode,
  4304. int security_level,
  4305. int unicast_using_group,
  4306. int batch_mode)
  4307. {
  4308. struct host_command cmd = {
  4309. .host_command = SET_SECURITY_INFORMATION,
  4310. .host_command_sequence = 0,
  4311. .host_command_length = sizeof(struct security_info_params)
  4312. };
  4313. struct security_info_params *security =
  4314. (struct security_info_params *)&cmd.host_command_parameters;
  4315. int err;
  4316. memset(security, 0, sizeof(*security));
  4317. /* If shared key AP authentication is turned on, then we need to
  4318. * configure the firmware to try and use it.
  4319. *
  4320. * Actual data encryption/decryption is handled by the host. */
  4321. security->auth_mode = auth_mode;
  4322. security->unicast_using_group = unicast_using_group;
  4323. switch (security_level) {
  4324. default:
  4325. case SEC_LEVEL_0:
  4326. security->allowed_ciphers = IPW_NONE_CIPHER;
  4327. break;
  4328. case SEC_LEVEL_1:
  4329. security->allowed_ciphers = IPW_WEP40_CIPHER |
  4330. IPW_WEP104_CIPHER;
  4331. break;
  4332. case SEC_LEVEL_2:
  4333. security->allowed_ciphers = IPW_WEP40_CIPHER |
  4334. IPW_WEP104_CIPHER | IPW_TKIP_CIPHER;
  4335. break;
  4336. case SEC_LEVEL_2_CKIP:
  4337. security->allowed_ciphers = IPW_WEP40_CIPHER |
  4338. IPW_WEP104_CIPHER | IPW_CKIP_CIPHER;
  4339. break;
  4340. case SEC_LEVEL_3:
  4341. security->allowed_ciphers = IPW_WEP40_CIPHER |
  4342. IPW_WEP104_CIPHER | IPW_TKIP_CIPHER | IPW_CCMP_CIPHER;
  4343. break;
  4344. }
  4345. IPW_DEBUG_HC
  4346. ("SET_SECURITY_INFORMATION: auth:%d cipher:0x%02X (level %d)\n",
  4347. security->auth_mode, security->allowed_ciphers, security_level);
  4348. security->replay_counters_number = 0;
  4349. if (!batch_mode) {
  4350. err = ipw2100_disable_adapter(priv);
  4351. if (err)
  4352. return err;
  4353. }
  4354. err = ipw2100_hw_send_command(priv, &cmd);
  4355. if (!batch_mode)
  4356. ipw2100_enable_adapter(priv);
  4357. return err;
  4358. }
  4359. static int ipw2100_set_tx_power(struct ipw2100_priv *priv, u32 tx_power)
  4360. {
  4361. struct host_command cmd = {
  4362. .host_command = TX_POWER_INDEX,
  4363. .host_command_sequence = 0,
  4364. .host_command_length = 4
  4365. };
  4366. int err = 0;
  4367. u32 tmp = tx_power;
  4368. if (tx_power != IPW_TX_POWER_DEFAULT)
  4369. tmp = (tx_power - IPW_TX_POWER_MIN_DBM) * 16 /
  4370. (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM);
  4371. cmd.host_command_parameters[0] = tmp;
  4372. if (priv->ieee->iw_mode == IW_MODE_ADHOC)
  4373. err = ipw2100_hw_send_command(priv, &cmd);
  4374. if (!err)
  4375. priv->tx_power = tx_power;
  4376. return 0;
  4377. }
  4378. static int ipw2100_set_ibss_beacon_interval(struct ipw2100_priv *priv,
  4379. u32 interval, int batch_mode)
  4380. {
  4381. struct host_command cmd = {
  4382. .host_command = BEACON_INTERVAL,
  4383. .host_command_sequence = 0,
  4384. .host_command_length = 4
  4385. };
  4386. int err;
  4387. cmd.host_command_parameters[0] = interval;
  4388. IPW_DEBUG_INFO("enter\n");
  4389. if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
  4390. if (!batch_mode) {
  4391. err = ipw2100_disable_adapter(priv);
  4392. if (err)
  4393. return err;
  4394. }
  4395. ipw2100_hw_send_command(priv, &cmd);
  4396. if (!batch_mode) {
  4397. err = ipw2100_enable_adapter(priv);
  4398. if (err)
  4399. return err;
  4400. }
  4401. }
  4402. IPW_DEBUG_INFO("exit\n");
  4403. return 0;
  4404. }
  4405. static void ipw2100_queues_initialize(struct ipw2100_priv *priv)
  4406. {
  4407. ipw2100_tx_initialize(priv);
  4408. ipw2100_rx_initialize(priv);
  4409. ipw2100_msg_initialize(priv);
  4410. }
  4411. static void ipw2100_queues_free(struct ipw2100_priv *priv)
  4412. {
  4413. ipw2100_tx_free(priv);
  4414. ipw2100_rx_free(priv);
  4415. ipw2100_msg_free(priv);
  4416. }
  4417. static int ipw2100_queues_allocate(struct ipw2100_priv *priv)
  4418. {
  4419. if (ipw2100_tx_allocate(priv) ||
  4420. ipw2100_rx_allocate(priv) || ipw2100_msg_allocate(priv))
  4421. goto fail;
  4422. return 0;
  4423. fail:
  4424. ipw2100_tx_free(priv);
  4425. ipw2100_rx_free(priv);
  4426. ipw2100_msg_free(priv);
  4427. return -ENOMEM;
  4428. }
  4429. #define IPW_PRIVACY_CAPABLE 0x0008
  4430. static int ipw2100_set_wep_flags(struct ipw2100_priv *priv, u32 flags,
  4431. int batch_mode)
  4432. {
  4433. struct host_command cmd = {
  4434. .host_command = WEP_FLAGS,
  4435. .host_command_sequence = 0,
  4436. .host_command_length = 4
  4437. };
  4438. int err;
  4439. cmd.host_command_parameters[0] = flags;
  4440. IPW_DEBUG_HC("WEP_FLAGS: flags = 0x%08X\n", flags);
  4441. if (!batch_mode) {
  4442. err = ipw2100_disable_adapter(priv);
  4443. if (err) {
  4444. printk(KERN_ERR DRV_NAME
  4445. ": %s: Could not disable adapter %d\n",
  4446. priv->net_dev->name, err);
  4447. return err;
  4448. }
  4449. }
  4450. /* send cmd to firmware */
  4451. err = ipw2100_hw_send_command(priv, &cmd);
  4452. if (!batch_mode)
  4453. ipw2100_enable_adapter(priv);
  4454. return err;
  4455. }
  4456. struct ipw2100_wep_key {
  4457. u8 idx;
  4458. u8 len;
  4459. u8 key[13];
  4460. };
  4461. /* Macros to ease up priting WEP keys */
  4462. #define WEP_FMT_64 "%02X%02X%02X%02X-%02X"
  4463. #define WEP_FMT_128 "%02X%02X%02X%02X-%02X%02X%02X%02X-%02X%02X%02X"
  4464. #define WEP_STR_64(x) x[0],x[1],x[2],x[3],x[4]
  4465. #define WEP_STR_128(x) x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],x[8],x[9],x[10]
  4466. /**
  4467. * Set a the wep key
  4468. *
  4469. * @priv: struct to work on
  4470. * @idx: index of the key we want to set
  4471. * @key: ptr to the key data to set
  4472. * @len: length of the buffer at @key
  4473. * @batch_mode: FIXME perform the operation in batch mode, not
  4474. * disabling the device.
  4475. *
  4476. * @returns 0 if OK, < 0 errno code on error.
  4477. *
  4478. * Fill out a command structure with the new wep key, length an
  4479. * index and send it down the wire.
  4480. */
  4481. static int ipw2100_set_key(struct ipw2100_priv *priv,
  4482. int idx, char *key, int len, int batch_mode)
  4483. {
  4484. int keylen = len ? (len <= 5 ? 5 : 13) : 0;
  4485. struct host_command cmd = {
  4486. .host_command = WEP_KEY_INFO,
  4487. .host_command_sequence = 0,
  4488. .host_command_length = sizeof(struct ipw2100_wep_key),
  4489. };
  4490. struct ipw2100_wep_key *wep_key = (void *)cmd.host_command_parameters;
  4491. int err;
  4492. IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
  4493. idx, keylen, len);
  4494. /* NOTE: We don't check cached values in case the firmware was reset
  4495. * or some other problem is occurring. If the user is setting the key,
  4496. * then we push the change */
  4497. wep_key->idx = idx;
  4498. wep_key->len = keylen;
  4499. if (keylen) {
  4500. memcpy(wep_key->key, key, len);
  4501. memset(wep_key->key + len, 0, keylen - len);
  4502. }
  4503. /* Will be optimized out on debug not being configured in */
  4504. if (keylen == 0)
  4505. IPW_DEBUG_WEP("%s: Clearing key %d\n",
  4506. priv->net_dev->name, wep_key->idx);
  4507. else if (keylen == 5)
  4508. IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_64 "\n",
  4509. priv->net_dev->name, wep_key->idx, wep_key->len,
  4510. WEP_STR_64(wep_key->key));
  4511. else
  4512. IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_128
  4513. "\n",
  4514. priv->net_dev->name, wep_key->idx, wep_key->len,
  4515. WEP_STR_128(wep_key->key));
  4516. if (!batch_mode) {
  4517. err = ipw2100_disable_adapter(priv);
  4518. /* FIXME: IPG: shouldn't this prink be in _disable_adapter()? */
  4519. if (err) {
  4520. printk(KERN_ERR DRV_NAME
  4521. ": %s: Could not disable adapter %d\n",
  4522. priv->net_dev->name, err);
  4523. return err;
  4524. }
  4525. }
  4526. /* send cmd to firmware */
  4527. err = ipw2100_hw_send_command(priv, &cmd);
  4528. if (!batch_mode) {
  4529. int err2 = ipw2100_enable_adapter(priv);
  4530. if (err == 0)
  4531. err = err2;
  4532. }
  4533. return err;
  4534. }
  4535. static int ipw2100_set_key_index(struct ipw2100_priv *priv,
  4536. int idx, int batch_mode)
  4537. {
  4538. struct host_command cmd = {
  4539. .host_command = WEP_KEY_INDEX,
  4540. .host_command_sequence = 0,
  4541. .host_command_length = 4,
  4542. .host_command_parameters = {idx},
  4543. };
  4544. int err;
  4545. IPW_DEBUG_HC("WEP_KEY_INDEX: index = %d\n", idx);
  4546. if (idx < 0 || idx > 3)
  4547. return -EINVAL;
  4548. if (!batch_mode) {
  4549. err = ipw2100_disable_adapter(priv);
  4550. if (err) {
  4551. printk(KERN_ERR DRV_NAME
  4552. ": %s: Could not disable adapter %d\n",
  4553. priv->net_dev->name, err);
  4554. return err;
  4555. }
  4556. }
  4557. /* send cmd to firmware */
  4558. err = ipw2100_hw_send_command(priv, &cmd);
  4559. if (!batch_mode)
  4560. ipw2100_enable_adapter(priv);
  4561. return err;
  4562. }
  4563. static int ipw2100_configure_security(struct ipw2100_priv *priv, int batch_mode)
  4564. {
  4565. int i, err, auth_mode, sec_level, use_group;
  4566. if (!(priv->status & STATUS_RUNNING))
  4567. return 0;
  4568. if (!batch_mode) {
  4569. err = ipw2100_disable_adapter(priv);
  4570. if (err)
  4571. return err;
  4572. }
  4573. if (!priv->ieee->sec.enabled) {
  4574. err =
  4575. ipw2100_set_security_information(priv, IPW_AUTH_OPEN,
  4576. SEC_LEVEL_0, 0, 1);
  4577. } else {
  4578. auth_mode = IPW_AUTH_OPEN;
  4579. if (priv->ieee->sec.flags & SEC_AUTH_MODE) {
  4580. if (priv->ieee->sec.auth_mode == WLAN_AUTH_SHARED_KEY)
  4581. auth_mode = IPW_AUTH_SHARED;
  4582. else if (priv->ieee->sec.auth_mode == WLAN_AUTH_LEAP)
  4583. auth_mode = IPW_AUTH_LEAP_CISCO_ID;
  4584. }
  4585. sec_level = SEC_LEVEL_0;
  4586. if (priv->ieee->sec.flags & SEC_LEVEL)
  4587. sec_level = priv->ieee->sec.level;
  4588. use_group = 0;
  4589. if (priv->ieee->sec.flags & SEC_UNICAST_GROUP)
  4590. use_group = priv->ieee->sec.unicast_uses_group;
  4591. err =
  4592. ipw2100_set_security_information(priv, auth_mode, sec_level,
  4593. use_group, 1);
  4594. }
  4595. if (err)
  4596. goto exit;
  4597. if (priv->ieee->sec.enabled) {
  4598. for (i = 0; i < 4; i++) {
  4599. if (!(priv->ieee->sec.flags & (1 << i))) {
  4600. memset(priv->ieee->sec.keys[i], 0, WEP_KEY_LEN);
  4601. priv->ieee->sec.key_sizes[i] = 0;
  4602. } else {
  4603. err = ipw2100_set_key(priv, i,
  4604. priv->ieee->sec.keys[i],
  4605. priv->ieee->sec.
  4606. key_sizes[i], 1);
  4607. if (err)
  4608. goto exit;
  4609. }
  4610. }
  4611. ipw2100_set_key_index(priv, priv->ieee->crypt_info.tx_keyidx, 1);
  4612. }
  4613. /* Always enable privacy so the Host can filter WEP packets if
  4614. * encrypted data is sent up */
  4615. err =
  4616. ipw2100_set_wep_flags(priv,
  4617. priv->ieee->sec.
  4618. enabled ? IPW_PRIVACY_CAPABLE : 0, 1);
  4619. if (err)
  4620. goto exit;
  4621. priv->status &= ~STATUS_SECURITY_UPDATED;
  4622. exit:
  4623. if (!batch_mode)
  4624. ipw2100_enable_adapter(priv);
  4625. return err;
  4626. }
  4627. static void ipw2100_security_work(struct work_struct *work)
  4628. {
  4629. struct ipw2100_priv *priv =
  4630. container_of(work, struct ipw2100_priv, security_work.work);
  4631. /* If we happen to have reconnected before we get a chance to
  4632. * process this, then update the security settings--which causes
  4633. * a disassociation to occur */
  4634. if (!(priv->status & STATUS_ASSOCIATED) &&
  4635. priv->status & STATUS_SECURITY_UPDATED)
  4636. ipw2100_configure_security(priv, 0);
  4637. }
  4638. static void shim__set_security(struct net_device *dev,
  4639. struct libipw_security *sec)
  4640. {
  4641. struct ipw2100_priv *priv = libipw_priv(dev);
  4642. int i, force_update = 0;
  4643. mutex_lock(&priv->action_mutex);
  4644. if (!(priv->status & STATUS_INITIALIZED))
  4645. goto done;
  4646. for (i = 0; i < 4; i++) {
  4647. if (sec->flags & (1 << i)) {
  4648. priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
  4649. if (sec->key_sizes[i] == 0)
  4650. priv->ieee->sec.flags &= ~(1 << i);
  4651. else
  4652. memcpy(priv->ieee->sec.keys[i], sec->keys[i],
  4653. sec->key_sizes[i]);
  4654. if (sec->level == SEC_LEVEL_1) {
  4655. priv->ieee->sec.flags |= (1 << i);
  4656. priv->status |= STATUS_SECURITY_UPDATED;
  4657. } else
  4658. priv->ieee->sec.flags &= ~(1 << i);
  4659. }
  4660. }
  4661. if ((sec->flags & SEC_ACTIVE_KEY) &&
  4662. priv->ieee->sec.active_key != sec->active_key) {
  4663. if (sec->active_key <= 3) {
  4664. priv->ieee->sec.active_key = sec->active_key;
  4665. priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
  4666. } else
  4667. priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
  4668. priv->status |= STATUS_SECURITY_UPDATED;
  4669. }
  4670. if ((sec->flags & SEC_AUTH_MODE) &&
  4671. (priv->ieee->sec.auth_mode != sec->auth_mode)) {
  4672. priv->ieee->sec.auth_mode = sec->auth_mode;
  4673. priv->ieee->sec.flags |= SEC_AUTH_MODE;
  4674. priv->status |= STATUS_SECURITY_UPDATED;
  4675. }
  4676. if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
  4677. priv->ieee->sec.flags |= SEC_ENABLED;
  4678. priv->ieee->sec.enabled = sec->enabled;
  4679. priv->status |= STATUS_SECURITY_UPDATED;
  4680. force_update = 1;
  4681. }
  4682. if (sec->flags & SEC_ENCRYPT)
  4683. priv->ieee->sec.encrypt = sec->encrypt;
  4684. if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
  4685. priv->ieee->sec.level = sec->level;
  4686. priv->ieee->sec.flags |= SEC_LEVEL;
  4687. priv->status |= STATUS_SECURITY_UPDATED;
  4688. }
  4689. IPW_DEBUG_WEP("Security flags: %c %c%c%c%c %c%c%c%c\n",
  4690. priv->ieee->sec.flags & (1 << 8) ? '1' : '0',
  4691. priv->ieee->sec.flags & (1 << 7) ? '1' : '0',
  4692. priv->ieee->sec.flags & (1 << 6) ? '1' : '0',
  4693. priv->ieee->sec.flags & (1 << 5) ? '1' : '0',
  4694. priv->ieee->sec.flags & (1 << 4) ? '1' : '0',
  4695. priv->ieee->sec.flags & (1 << 3) ? '1' : '0',
  4696. priv->ieee->sec.flags & (1 << 2) ? '1' : '0',
  4697. priv->ieee->sec.flags & (1 << 1) ? '1' : '0',
  4698. priv->ieee->sec.flags & (1 << 0) ? '1' : '0');
  4699. /* As a temporary work around to enable WPA until we figure out why
  4700. * wpa_supplicant toggles the security capability of the driver, which
  4701. * forces a disassocation with force_update...
  4702. *
  4703. * if (force_update || !(priv->status & STATUS_ASSOCIATED))*/
  4704. if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
  4705. ipw2100_configure_security(priv, 0);
  4706. done:
  4707. mutex_unlock(&priv->action_mutex);
  4708. }
  4709. static int ipw2100_adapter_setup(struct ipw2100_priv *priv)
  4710. {
  4711. int err;
  4712. int batch_mode = 1;
  4713. u8 *bssid;
  4714. IPW_DEBUG_INFO("enter\n");
  4715. err = ipw2100_disable_adapter(priv);
  4716. if (err)
  4717. return err;
  4718. #ifdef CONFIG_IPW2100_MONITOR
  4719. if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
  4720. err = ipw2100_set_channel(priv, priv->channel, batch_mode);
  4721. if (err)
  4722. return err;
  4723. IPW_DEBUG_INFO("exit\n");
  4724. return 0;
  4725. }
  4726. #endif /* CONFIG_IPW2100_MONITOR */
  4727. err = ipw2100_read_mac_address(priv);
  4728. if (err)
  4729. return -EIO;
  4730. err = ipw2100_set_mac_address(priv, batch_mode);
  4731. if (err)
  4732. return err;
  4733. err = ipw2100_set_port_type(priv, priv->ieee->iw_mode, batch_mode);
  4734. if (err)
  4735. return err;
  4736. if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
  4737. err = ipw2100_set_channel(priv, priv->channel, batch_mode);
  4738. if (err)
  4739. return err;
  4740. }
  4741. err = ipw2100_system_config(priv, batch_mode);
  4742. if (err)
  4743. return err;
  4744. err = ipw2100_set_tx_rates(priv, priv->tx_rates, batch_mode);
  4745. if (err)
  4746. return err;
  4747. /* Default to power mode OFF */
  4748. err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
  4749. if (err)
  4750. return err;
  4751. err = ipw2100_set_rts_threshold(priv, priv->rts_threshold);
  4752. if (err)
  4753. return err;
  4754. if (priv->config & CFG_STATIC_BSSID)
  4755. bssid = priv->bssid;
  4756. else
  4757. bssid = NULL;
  4758. err = ipw2100_set_mandatory_bssid(priv, bssid, batch_mode);
  4759. if (err)
  4760. return err;
  4761. if (priv->config & CFG_STATIC_ESSID)
  4762. err = ipw2100_set_essid(priv, priv->essid, priv->essid_len,
  4763. batch_mode);
  4764. else
  4765. err = ipw2100_set_essid(priv, NULL, 0, batch_mode);
  4766. if (err)
  4767. return err;
  4768. err = ipw2100_configure_security(priv, batch_mode);
  4769. if (err)
  4770. return err;
  4771. if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
  4772. err =
  4773. ipw2100_set_ibss_beacon_interval(priv,
  4774. priv->beacon_interval,
  4775. batch_mode);
  4776. if (err)
  4777. return err;
  4778. err = ipw2100_set_tx_power(priv, priv->tx_power);
  4779. if (err)
  4780. return err;
  4781. }
  4782. /*
  4783. err = ipw2100_set_fragmentation_threshold(
  4784. priv, priv->frag_threshold, batch_mode);
  4785. if (err)
  4786. return err;
  4787. */
  4788. IPW_DEBUG_INFO("exit\n");
  4789. return 0;
  4790. }
  4791. /*************************************************************************
  4792. *
  4793. * EXTERNALLY CALLED METHODS
  4794. *
  4795. *************************************************************************/
  4796. /* This method is called by the network layer -- not to be confused with
  4797. * ipw2100_set_mac_address() declared above called by this driver (and this
  4798. * method as well) to talk to the firmware */
  4799. static int ipw2100_set_address(struct net_device *dev, void *p)
  4800. {
  4801. struct ipw2100_priv *priv = libipw_priv(dev);
  4802. struct sockaddr *addr = p;
  4803. int err = 0;
  4804. if (!is_valid_ether_addr(addr->sa_data))
  4805. return -EADDRNOTAVAIL;
  4806. mutex_lock(&priv->action_mutex);
  4807. priv->config |= CFG_CUSTOM_MAC;
  4808. memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
  4809. err = ipw2100_set_mac_address(priv, 0);
  4810. if (err)
  4811. goto done;
  4812. priv->reset_backoff = 0;
  4813. mutex_unlock(&priv->action_mutex);
  4814. ipw2100_reset_adapter(&priv->reset_work.work);
  4815. return 0;
  4816. done:
  4817. mutex_unlock(&priv->action_mutex);
  4818. return err;
  4819. }
  4820. static int ipw2100_open(struct net_device *dev)
  4821. {
  4822. struct ipw2100_priv *priv = libipw_priv(dev);
  4823. unsigned long flags;
  4824. IPW_DEBUG_INFO("dev->open\n");
  4825. spin_lock_irqsave(&priv->low_lock, flags);
  4826. if (priv->status & STATUS_ASSOCIATED) {
  4827. netif_carrier_on(dev);
  4828. netif_start_queue(dev);
  4829. }
  4830. spin_unlock_irqrestore(&priv->low_lock, flags);
  4831. return 0;
  4832. }
  4833. static int ipw2100_close(struct net_device *dev)
  4834. {
  4835. struct ipw2100_priv *priv = libipw_priv(dev);
  4836. unsigned long flags;
  4837. struct list_head *element;
  4838. struct ipw2100_tx_packet *packet;
  4839. IPW_DEBUG_INFO("enter\n");
  4840. spin_lock_irqsave(&priv->low_lock, flags);
  4841. if (priv->status & STATUS_ASSOCIATED)
  4842. netif_carrier_off(dev);
  4843. netif_stop_queue(dev);
  4844. /* Flush the TX queue ... */
  4845. while (!list_empty(&priv->tx_pend_list)) {
  4846. element = priv->tx_pend_list.next;
  4847. packet = list_entry(element, struct ipw2100_tx_packet, list);
  4848. list_del(element);
  4849. DEC_STAT(&priv->tx_pend_stat);
  4850. libipw_txb_free(packet->info.d_struct.txb);
  4851. packet->info.d_struct.txb = NULL;
  4852. list_add_tail(element, &priv->tx_free_list);
  4853. INC_STAT(&priv->tx_free_stat);
  4854. }
  4855. spin_unlock_irqrestore(&priv->low_lock, flags);
  4856. IPW_DEBUG_INFO("exit\n");
  4857. return 0;
  4858. }
  4859. /*
  4860. * TODO: Fix this function... its just wrong
  4861. */
  4862. static void ipw2100_tx_timeout(struct net_device *dev)
  4863. {
  4864. struct ipw2100_priv *priv = libipw_priv(dev);
  4865. dev->stats.tx_errors++;
  4866. #ifdef CONFIG_IPW2100_MONITOR
  4867. if (priv->ieee->iw_mode == IW_MODE_MONITOR)
  4868. return;
  4869. #endif
  4870. IPW_DEBUG_INFO("%s: TX timed out. Scheduling firmware restart.\n",
  4871. dev->name);
  4872. schedule_reset(priv);
  4873. }
  4874. static int ipw2100_wpa_enable(struct ipw2100_priv *priv, int value)
  4875. {
  4876. /* This is called when wpa_supplicant loads and closes the driver
  4877. * interface. */
  4878. priv->ieee->wpa_enabled = value;
  4879. return 0;
  4880. }
  4881. static int ipw2100_wpa_set_auth_algs(struct ipw2100_priv *priv, int value)
  4882. {
  4883. struct libipw_device *ieee = priv->ieee;
  4884. struct libipw_security sec = {
  4885. .flags = SEC_AUTH_MODE,
  4886. };
  4887. int ret = 0;
  4888. if (value & IW_AUTH_ALG_SHARED_KEY) {
  4889. sec.auth_mode = WLAN_AUTH_SHARED_KEY;
  4890. ieee->open_wep = 0;
  4891. } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
  4892. sec.auth_mode = WLAN_AUTH_OPEN;
  4893. ieee->open_wep = 1;
  4894. } else if (value & IW_AUTH_ALG_LEAP) {
  4895. sec.auth_mode = WLAN_AUTH_LEAP;
  4896. ieee->open_wep = 1;
  4897. } else
  4898. return -EINVAL;
  4899. if (ieee->set_security)
  4900. ieee->set_security(ieee->dev, &sec);
  4901. else
  4902. ret = -EOPNOTSUPP;
  4903. return ret;
  4904. }
  4905. static void ipw2100_wpa_assoc_frame(struct ipw2100_priv *priv,
  4906. char *wpa_ie, int wpa_ie_len)
  4907. {
  4908. struct ipw2100_wpa_assoc_frame frame;
  4909. frame.fixed_ie_mask = 0;
  4910. /* copy WPA IE */
  4911. memcpy(frame.var_ie, wpa_ie, wpa_ie_len);
  4912. frame.var_ie_len = wpa_ie_len;
  4913. /* make sure WPA is enabled */
  4914. ipw2100_wpa_enable(priv, 1);
  4915. ipw2100_set_wpa_ie(priv, &frame, 0);
  4916. }
  4917. static void ipw_ethtool_get_drvinfo(struct net_device *dev,
  4918. struct ethtool_drvinfo *info)
  4919. {
  4920. struct ipw2100_priv *priv = libipw_priv(dev);
  4921. char fw_ver[64], ucode_ver[64];
  4922. strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
  4923. strlcpy(info->version, DRV_VERSION, sizeof(info->version));
  4924. ipw2100_get_fwversion(priv, fw_ver, sizeof(fw_ver));
  4925. ipw2100_get_ucodeversion(priv, ucode_ver, sizeof(ucode_ver));
  4926. snprintf(info->fw_version, sizeof(info->fw_version), "%s:%d:%s",
  4927. fw_ver, priv->eeprom_version, ucode_ver);
  4928. strlcpy(info->bus_info, pci_name(priv->pci_dev),
  4929. sizeof(info->bus_info));
  4930. }
  4931. static u32 ipw2100_ethtool_get_link(struct net_device *dev)
  4932. {
  4933. struct ipw2100_priv *priv = libipw_priv(dev);
  4934. return (priv->status & STATUS_ASSOCIATED) ? 1 : 0;
  4935. }
  4936. static const struct ethtool_ops ipw2100_ethtool_ops = {
  4937. .get_link = ipw2100_ethtool_get_link,
  4938. .get_drvinfo = ipw_ethtool_get_drvinfo,
  4939. };
  4940. static void ipw2100_hang_check(struct work_struct *work)
  4941. {
  4942. struct ipw2100_priv *priv =
  4943. container_of(work, struct ipw2100_priv, hang_check.work);
  4944. unsigned long flags;
  4945. u32 rtc = 0xa5a5a5a5;
  4946. u32 len = sizeof(rtc);
  4947. int restart = 0;
  4948. spin_lock_irqsave(&priv->low_lock, flags);
  4949. if (priv->fatal_error != 0) {
  4950. /* If fatal_error is set then we need to restart */
  4951. IPW_DEBUG_INFO("%s: Hardware fatal error detected.\n",
  4952. priv->net_dev->name);
  4953. restart = 1;
  4954. } else if (ipw2100_get_ordinal(priv, IPW_ORD_RTC_TIME, &rtc, &len) ||
  4955. (rtc == priv->last_rtc)) {
  4956. /* Check if firmware is hung */
  4957. IPW_DEBUG_INFO("%s: Firmware RTC stalled.\n",
  4958. priv->net_dev->name);
  4959. restart = 1;
  4960. }
  4961. if (restart) {
  4962. /* Kill timer */
  4963. priv->stop_hang_check = 1;
  4964. priv->hangs++;
  4965. /* Restart the NIC */
  4966. schedule_reset(priv);
  4967. }
  4968. priv->last_rtc = rtc;
  4969. if (!priv->stop_hang_check)
  4970. schedule_delayed_work(&priv->hang_check, HZ / 2);
  4971. spin_unlock_irqrestore(&priv->low_lock, flags);
  4972. }
  4973. static void ipw2100_rf_kill(struct work_struct *work)
  4974. {
  4975. struct ipw2100_priv *priv =
  4976. container_of(work, struct ipw2100_priv, rf_kill.work);
  4977. unsigned long flags;
  4978. spin_lock_irqsave(&priv->low_lock, flags);
  4979. if (rf_kill_active(priv)) {
  4980. IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
  4981. if (!priv->stop_rf_kill)
  4982. schedule_delayed_work(&priv->rf_kill,
  4983. round_jiffies_relative(HZ));
  4984. goto exit_unlock;
  4985. }
  4986. /* RF Kill is now disabled, so bring the device back up */
  4987. if (!(priv->status & STATUS_RF_KILL_MASK)) {
  4988. IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
  4989. "device\n");
  4990. schedule_reset(priv);
  4991. } else
  4992. IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
  4993. "enabled\n");
  4994. exit_unlock:
  4995. spin_unlock_irqrestore(&priv->low_lock, flags);
  4996. }
  4997. static void ipw2100_irq_tasklet(struct ipw2100_priv *priv);
  4998. static const struct net_device_ops ipw2100_netdev_ops = {
  4999. .ndo_open = ipw2100_open,
  5000. .ndo_stop = ipw2100_close,
  5001. .ndo_start_xmit = libipw_xmit,
  5002. .ndo_change_mtu = libipw_change_mtu,
  5003. .ndo_init = ipw2100_net_init,
  5004. .ndo_tx_timeout = ipw2100_tx_timeout,
  5005. .ndo_set_mac_address = ipw2100_set_address,
  5006. .ndo_validate_addr = eth_validate_addr,
  5007. };
  5008. /* Look into using netdev destructor to shutdown libipw? */
  5009. static struct net_device *ipw2100_alloc_device(struct pci_dev *pci_dev,
  5010. void __iomem * base_addr,
  5011. unsigned long mem_start,
  5012. unsigned long mem_len)
  5013. {
  5014. struct ipw2100_priv *priv;
  5015. struct net_device *dev;
  5016. dev = alloc_libipw(sizeof(struct ipw2100_priv), 0);
  5017. if (!dev)
  5018. return NULL;
  5019. priv = libipw_priv(dev);
  5020. priv->ieee = netdev_priv(dev);
  5021. priv->pci_dev = pci_dev;
  5022. priv->net_dev = dev;
  5023. priv->ieee->hard_start_xmit = ipw2100_tx;
  5024. priv->ieee->set_security = shim__set_security;
  5025. priv->ieee->perfect_rssi = -20;
  5026. priv->ieee->worst_rssi = -85;
  5027. dev->netdev_ops = &ipw2100_netdev_ops;
  5028. dev->ethtool_ops = &ipw2100_ethtool_ops;
  5029. dev->wireless_handlers = &ipw2100_wx_handler_def;
  5030. priv->wireless_data.libipw = priv->ieee;
  5031. dev->wireless_data = &priv->wireless_data;
  5032. dev->watchdog_timeo = 3 * HZ;
  5033. dev->irq = 0;
  5034. dev->base_addr = (unsigned long)base_addr;
  5035. dev->mem_start = mem_start;
  5036. dev->mem_end = dev->mem_start + mem_len - 1;
  5037. /* NOTE: We don't use the wireless_handlers hook
  5038. * in dev as the system will start throwing WX requests
  5039. * to us before we're actually initialized and it just
  5040. * ends up causing problems. So, we just handle
  5041. * the WX extensions through the ipw2100_ioctl interface */
  5042. /* memset() puts everything to 0, so we only have explicitly set
  5043. * those values that need to be something else */
  5044. /* If power management is turned on, default to AUTO mode */
  5045. priv->power_mode = IPW_POWER_AUTO;
  5046. #ifdef CONFIG_IPW2100_MONITOR
  5047. priv->config |= CFG_CRC_CHECK;
  5048. #endif
  5049. priv->ieee->wpa_enabled = 0;
  5050. priv->ieee->drop_unencrypted = 0;
  5051. priv->ieee->privacy_invoked = 0;
  5052. priv->ieee->ieee802_1x = 1;
  5053. /* Set module parameters */
  5054. switch (network_mode) {
  5055. case 1:
  5056. priv->ieee->iw_mode = IW_MODE_ADHOC;
  5057. break;
  5058. #ifdef CONFIG_IPW2100_MONITOR
  5059. case 2:
  5060. priv->ieee->iw_mode = IW_MODE_MONITOR;
  5061. break;
  5062. #endif
  5063. default:
  5064. case 0:
  5065. priv->ieee->iw_mode = IW_MODE_INFRA;
  5066. break;
  5067. }
  5068. if (disable == 1)
  5069. priv->status |= STATUS_RF_KILL_SW;
  5070. if (channel != 0 &&
  5071. ((channel >= REG_MIN_CHANNEL) && (channel <= REG_MAX_CHANNEL))) {
  5072. priv->config |= CFG_STATIC_CHANNEL;
  5073. priv->channel = channel;
  5074. }
  5075. if (associate)
  5076. priv->config |= CFG_ASSOCIATE;
  5077. priv->beacon_interval = DEFAULT_BEACON_INTERVAL;
  5078. priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
  5079. priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
  5080. priv->rts_threshold = DEFAULT_RTS_THRESHOLD | RTS_DISABLED;
  5081. priv->frag_threshold = DEFAULT_FTS | FRAG_DISABLED;
  5082. priv->tx_power = IPW_TX_POWER_DEFAULT;
  5083. priv->tx_rates = DEFAULT_TX_RATES;
  5084. strcpy(priv->nick, "ipw2100");
  5085. spin_lock_init(&priv->low_lock);
  5086. mutex_init(&priv->action_mutex);
  5087. mutex_init(&priv->adapter_mutex);
  5088. init_waitqueue_head(&priv->wait_command_queue);
  5089. netif_carrier_off(dev);
  5090. INIT_LIST_HEAD(&priv->msg_free_list);
  5091. INIT_LIST_HEAD(&priv->msg_pend_list);
  5092. INIT_STAT(&priv->msg_free_stat);
  5093. INIT_STAT(&priv->msg_pend_stat);
  5094. INIT_LIST_HEAD(&priv->tx_free_list);
  5095. INIT_LIST_HEAD(&priv->tx_pend_list);
  5096. INIT_STAT(&priv->tx_free_stat);
  5097. INIT_STAT(&priv->tx_pend_stat);
  5098. INIT_LIST_HEAD(&priv->fw_pend_list);
  5099. INIT_STAT(&priv->fw_pend_stat);
  5100. INIT_DELAYED_WORK(&priv->reset_work, ipw2100_reset_adapter);
  5101. INIT_DELAYED_WORK(&priv->security_work, ipw2100_security_work);
  5102. INIT_DELAYED_WORK(&priv->wx_event_work, ipw2100_wx_event_work);
  5103. INIT_DELAYED_WORK(&priv->hang_check, ipw2100_hang_check);
  5104. INIT_DELAYED_WORK(&priv->rf_kill, ipw2100_rf_kill);
  5105. INIT_WORK(&priv->scan_event_now, ipw2100_scan_event_now);
  5106. INIT_DELAYED_WORK(&priv->scan_event_later, ipw2100_scan_event_later);
  5107. tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
  5108. ipw2100_irq_tasklet, (unsigned long)priv);
  5109. /* NOTE: We do not start the deferred work for status checks yet */
  5110. priv->stop_rf_kill = 1;
  5111. priv->stop_hang_check = 1;
  5112. return dev;
  5113. }
  5114. static int ipw2100_pci_init_one(struct pci_dev *pci_dev,
  5115. const struct pci_device_id *ent)
  5116. {
  5117. unsigned long mem_start, mem_len, mem_flags;
  5118. void __iomem *base_addr = NULL;
  5119. struct net_device *dev = NULL;
  5120. struct ipw2100_priv *priv = NULL;
  5121. int err = 0;
  5122. int registered = 0;
  5123. u32 val;
  5124. IPW_DEBUG_INFO("enter\n");
  5125. mem_start = pci_resource_start(pci_dev, 0);
  5126. mem_len = pci_resource_len(pci_dev, 0);
  5127. mem_flags = pci_resource_flags(pci_dev, 0);
  5128. if ((mem_flags & IORESOURCE_MEM) != IORESOURCE_MEM) {
  5129. IPW_DEBUG_INFO("weird - resource type is not memory\n");
  5130. err = -ENODEV;
  5131. goto fail;
  5132. }
  5133. base_addr = ioremap_nocache(mem_start, mem_len);
  5134. if (!base_addr) {
  5135. printk(KERN_WARNING DRV_NAME
  5136. "Error calling ioremap_nocache.\n");
  5137. err = -EIO;
  5138. goto fail;
  5139. }
  5140. /* allocate and initialize our net_device */
  5141. dev = ipw2100_alloc_device(pci_dev, base_addr, mem_start, mem_len);
  5142. if (!dev) {
  5143. printk(KERN_WARNING DRV_NAME
  5144. "Error calling ipw2100_alloc_device.\n");
  5145. err = -ENOMEM;
  5146. goto fail;
  5147. }
  5148. /* set up PCI mappings for device */
  5149. err = pci_enable_device(pci_dev);
  5150. if (err) {
  5151. printk(KERN_WARNING DRV_NAME
  5152. "Error calling pci_enable_device.\n");
  5153. return err;
  5154. }
  5155. priv = libipw_priv(dev);
  5156. pci_set_master(pci_dev);
  5157. pci_set_drvdata(pci_dev, priv);
  5158. err = pci_set_dma_mask(pci_dev, DMA_BIT_MASK(32));
  5159. if (err) {
  5160. printk(KERN_WARNING DRV_NAME
  5161. "Error calling pci_set_dma_mask.\n");
  5162. pci_disable_device(pci_dev);
  5163. return err;
  5164. }
  5165. err = pci_request_regions(pci_dev, DRV_NAME);
  5166. if (err) {
  5167. printk(KERN_WARNING DRV_NAME
  5168. "Error calling pci_request_regions.\n");
  5169. pci_disable_device(pci_dev);
  5170. return err;
  5171. }
  5172. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  5173. * PCI Tx retries from interfering with C3 CPU state */
  5174. pci_read_config_dword(pci_dev, 0x40, &val);
  5175. if ((val & 0x0000ff00) != 0)
  5176. pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
  5177. pci_set_power_state(pci_dev, PCI_D0);
  5178. if (!ipw2100_hw_is_adapter_in_system(dev)) {
  5179. printk(KERN_WARNING DRV_NAME
  5180. "Device not found via register read.\n");
  5181. err = -ENODEV;
  5182. goto fail;
  5183. }
  5184. SET_NETDEV_DEV(dev, &pci_dev->dev);
  5185. /* Force interrupts to be shut off on the device */
  5186. priv->status |= STATUS_INT_ENABLED;
  5187. ipw2100_disable_interrupts(priv);
  5188. /* Allocate and initialize the Tx/Rx queues and lists */
  5189. if (ipw2100_queues_allocate(priv)) {
  5190. printk(KERN_WARNING DRV_NAME
  5191. "Error calling ipw2100_queues_allocate.\n");
  5192. err = -ENOMEM;
  5193. goto fail;
  5194. }
  5195. ipw2100_queues_initialize(priv);
  5196. err = request_irq(pci_dev->irq,
  5197. ipw2100_interrupt, IRQF_SHARED, dev->name, priv);
  5198. if (err) {
  5199. printk(KERN_WARNING DRV_NAME
  5200. "Error calling request_irq: %d.\n", pci_dev->irq);
  5201. goto fail;
  5202. }
  5203. dev->irq = pci_dev->irq;
  5204. IPW_DEBUG_INFO("Attempting to register device...\n");
  5205. printk(KERN_INFO DRV_NAME
  5206. ": Detected Intel PRO/Wireless 2100 Network Connection\n");
  5207. /* Bring up the interface. Pre 0.46, after we registered the
  5208. * network device we would call ipw2100_up. This introduced a race
  5209. * condition with newer hotplug configurations (network was coming
  5210. * up and making calls before the device was initialized).
  5211. *
  5212. * If we called ipw2100_up before we registered the device, then the
  5213. * device name wasn't registered. So, we instead use the net_dev->init
  5214. * member to call a function that then just turns and calls ipw2100_up.
  5215. * net_dev->init is called after name allocation but before the
  5216. * notifier chain is called */
  5217. err = register_netdev(dev);
  5218. if (err) {
  5219. printk(KERN_WARNING DRV_NAME
  5220. "Error calling register_netdev.\n");
  5221. goto fail;
  5222. }
  5223. registered = 1;
  5224. err = ipw2100_wdev_init(dev);
  5225. if (err)
  5226. goto fail;
  5227. mutex_lock(&priv->action_mutex);
  5228. IPW_DEBUG_INFO("%s: Bound to %s\n", dev->name, pci_name(pci_dev));
  5229. /* perform this after register_netdev so that dev->name is set */
  5230. err = sysfs_create_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
  5231. if (err)
  5232. goto fail_unlock;
  5233. /* If the RF Kill switch is disabled, go ahead and complete the
  5234. * startup sequence */
  5235. if (!(priv->status & STATUS_RF_KILL_MASK)) {
  5236. /* Enable the adapter - sends HOST_COMPLETE */
  5237. if (ipw2100_enable_adapter(priv)) {
  5238. printk(KERN_WARNING DRV_NAME
  5239. ": %s: failed in call to enable adapter.\n",
  5240. priv->net_dev->name);
  5241. ipw2100_hw_stop_adapter(priv);
  5242. err = -EIO;
  5243. goto fail_unlock;
  5244. }
  5245. /* Start a scan . . . */
  5246. ipw2100_set_scan_options(priv);
  5247. ipw2100_start_scan(priv);
  5248. }
  5249. IPW_DEBUG_INFO("exit\n");
  5250. priv->status |= STATUS_INITIALIZED;
  5251. mutex_unlock(&priv->action_mutex);
  5252. return 0;
  5253. fail_unlock:
  5254. mutex_unlock(&priv->action_mutex);
  5255. wiphy_unregister(priv->ieee->wdev.wiphy);
  5256. kfree(priv->ieee->bg_band.channels);
  5257. fail:
  5258. if (dev) {
  5259. if (registered)
  5260. unregister_netdev(dev);
  5261. ipw2100_hw_stop_adapter(priv);
  5262. ipw2100_disable_interrupts(priv);
  5263. if (dev->irq)
  5264. free_irq(dev->irq, priv);
  5265. ipw2100_kill_works(priv);
  5266. /* These are safe to call even if they weren't allocated */
  5267. ipw2100_queues_free(priv);
  5268. sysfs_remove_group(&pci_dev->dev.kobj,
  5269. &ipw2100_attribute_group);
  5270. free_libipw(dev, 0);
  5271. pci_set_drvdata(pci_dev, NULL);
  5272. }
  5273. if (base_addr)
  5274. iounmap(base_addr);
  5275. pci_release_regions(pci_dev);
  5276. pci_disable_device(pci_dev);
  5277. return err;
  5278. }
  5279. static void __devexit ipw2100_pci_remove_one(struct pci_dev *pci_dev)
  5280. {
  5281. struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
  5282. struct net_device *dev;
  5283. if (priv) {
  5284. mutex_lock(&priv->action_mutex);
  5285. priv->status &= ~STATUS_INITIALIZED;
  5286. dev = priv->net_dev;
  5287. sysfs_remove_group(&pci_dev->dev.kobj,
  5288. &ipw2100_attribute_group);
  5289. #ifdef CONFIG_PM
  5290. if (ipw2100_firmware.version)
  5291. ipw2100_release_firmware(priv, &ipw2100_firmware);
  5292. #endif
  5293. /* Take down the hardware */
  5294. ipw2100_down(priv);
  5295. /* Release the mutex so that the network subsystem can
  5296. * complete any needed calls into the driver... */
  5297. mutex_unlock(&priv->action_mutex);
  5298. /* Unregister the device first - this results in close()
  5299. * being called if the device is open. If we free storage
  5300. * first, then close() will crash. */
  5301. unregister_netdev(dev);
  5302. ipw2100_kill_works(priv);
  5303. ipw2100_queues_free(priv);
  5304. /* Free potential debugging firmware snapshot */
  5305. ipw2100_snapshot_free(priv);
  5306. if (dev->irq)
  5307. free_irq(dev->irq, priv);
  5308. if (dev->base_addr)
  5309. iounmap((void __iomem *)dev->base_addr);
  5310. /* wiphy_unregister needs to be here, before free_libipw */
  5311. wiphy_unregister(priv->ieee->wdev.wiphy);
  5312. kfree(priv->ieee->bg_band.channels);
  5313. free_libipw(dev, 0);
  5314. }
  5315. pci_release_regions(pci_dev);
  5316. pci_disable_device(pci_dev);
  5317. IPW_DEBUG_INFO("exit\n");
  5318. }
  5319. #ifdef CONFIG_PM
  5320. static int ipw2100_suspend(struct pci_dev *pci_dev, pm_message_t state)
  5321. {
  5322. struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
  5323. struct net_device *dev = priv->net_dev;
  5324. IPW_DEBUG_INFO("%s: Going into suspend...\n", dev->name);
  5325. mutex_lock(&priv->action_mutex);
  5326. if (priv->status & STATUS_INITIALIZED) {
  5327. /* Take down the device; powers it off, etc. */
  5328. ipw2100_down(priv);
  5329. }
  5330. /* Remove the PRESENT state of the device */
  5331. netif_device_detach(dev);
  5332. pci_save_state(pci_dev);
  5333. pci_disable_device(pci_dev);
  5334. pci_set_power_state(pci_dev, PCI_D3hot);
  5335. priv->suspend_at = get_seconds();
  5336. mutex_unlock(&priv->action_mutex);
  5337. return 0;
  5338. }
  5339. static int ipw2100_resume(struct pci_dev *pci_dev)
  5340. {
  5341. struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
  5342. struct net_device *dev = priv->net_dev;
  5343. int err;
  5344. u32 val;
  5345. if (IPW2100_PM_DISABLED)
  5346. return 0;
  5347. mutex_lock(&priv->action_mutex);
  5348. IPW_DEBUG_INFO("%s: Coming out of suspend...\n", dev->name);
  5349. pci_set_power_state(pci_dev, PCI_D0);
  5350. err = pci_enable_device(pci_dev);
  5351. if (err) {
  5352. printk(KERN_ERR "%s: pci_enable_device failed on resume\n",
  5353. dev->name);
  5354. mutex_unlock(&priv->action_mutex);
  5355. return err;
  5356. }
  5357. pci_restore_state(pci_dev);
  5358. /*
  5359. * Suspend/Resume resets the PCI configuration space, so we have to
  5360. * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
  5361. * from interfering with C3 CPU state. pci_restore_state won't help
  5362. * here since it only restores the first 64 bytes pci config header.
  5363. */
  5364. pci_read_config_dword(pci_dev, 0x40, &val);
  5365. if ((val & 0x0000ff00) != 0)
  5366. pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
  5367. /* Set the device back into the PRESENT state; this will also wake
  5368. * the queue of needed */
  5369. netif_device_attach(dev);
  5370. priv->suspend_time = get_seconds() - priv->suspend_at;
  5371. /* Bring the device back up */
  5372. if (!(priv->status & STATUS_RF_KILL_SW))
  5373. ipw2100_up(priv, 0);
  5374. mutex_unlock(&priv->action_mutex);
  5375. return 0;
  5376. }
  5377. #endif
  5378. static void ipw2100_shutdown(struct pci_dev *pci_dev)
  5379. {
  5380. struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
  5381. /* Take down the device; powers it off, etc. */
  5382. ipw2100_down(priv);
  5383. pci_disable_device(pci_dev);
  5384. }
  5385. #define IPW2100_DEV_ID(x) { PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, x }
  5386. static DEFINE_PCI_DEVICE_TABLE(ipw2100_pci_id_table) = {
  5387. IPW2100_DEV_ID(0x2520), /* IN 2100A mPCI 3A */
  5388. IPW2100_DEV_ID(0x2521), /* IN 2100A mPCI 3B */
  5389. IPW2100_DEV_ID(0x2524), /* IN 2100A mPCI 3B */
  5390. IPW2100_DEV_ID(0x2525), /* IN 2100A mPCI 3B */
  5391. IPW2100_DEV_ID(0x2526), /* IN 2100A mPCI Gen A3 */
  5392. IPW2100_DEV_ID(0x2522), /* IN 2100 mPCI 3B */
  5393. IPW2100_DEV_ID(0x2523), /* IN 2100 mPCI 3A */
  5394. IPW2100_DEV_ID(0x2527), /* IN 2100 mPCI 3B */
  5395. IPW2100_DEV_ID(0x2528), /* IN 2100 mPCI 3B */
  5396. IPW2100_DEV_ID(0x2529), /* IN 2100 mPCI 3B */
  5397. IPW2100_DEV_ID(0x252B), /* IN 2100 mPCI 3A */
  5398. IPW2100_DEV_ID(0x252C), /* IN 2100 mPCI 3A */
  5399. IPW2100_DEV_ID(0x252D), /* IN 2100 mPCI 3A */
  5400. IPW2100_DEV_ID(0x2550), /* IB 2100A mPCI 3B */
  5401. IPW2100_DEV_ID(0x2551), /* IB 2100 mPCI 3B */
  5402. IPW2100_DEV_ID(0x2553), /* IB 2100 mPCI 3B */
  5403. IPW2100_DEV_ID(0x2554), /* IB 2100 mPCI 3B */
  5404. IPW2100_DEV_ID(0x2555), /* IB 2100 mPCI 3B */
  5405. IPW2100_DEV_ID(0x2560), /* DE 2100A mPCI 3A */
  5406. IPW2100_DEV_ID(0x2562), /* DE 2100A mPCI 3A */
  5407. IPW2100_DEV_ID(0x2563), /* DE 2100A mPCI 3A */
  5408. IPW2100_DEV_ID(0x2561), /* DE 2100 mPCI 3A */
  5409. IPW2100_DEV_ID(0x2565), /* DE 2100 mPCI 3A */
  5410. IPW2100_DEV_ID(0x2566), /* DE 2100 mPCI 3A */
  5411. IPW2100_DEV_ID(0x2567), /* DE 2100 mPCI 3A */
  5412. IPW2100_DEV_ID(0x2570), /* GA 2100 mPCI 3B */
  5413. IPW2100_DEV_ID(0x2580), /* TO 2100A mPCI 3B */
  5414. IPW2100_DEV_ID(0x2582), /* TO 2100A mPCI 3B */
  5415. IPW2100_DEV_ID(0x2583), /* TO 2100A mPCI 3B */
  5416. IPW2100_DEV_ID(0x2581), /* TO 2100 mPCI 3B */
  5417. IPW2100_DEV_ID(0x2585), /* TO 2100 mPCI 3B */
  5418. IPW2100_DEV_ID(0x2586), /* TO 2100 mPCI 3B */
  5419. IPW2100_DEV_ID(0x2587), /* TO 2100 mPCI 3B */
  5420. IPW2100_DEV_ID(0x2590), /* SO 2100A mPCI 3B */
  5421. IPW2100_DEV_ID(0x2592), /* SO 2100A mPCI 3B */
  5422. IPW2100_DEV_ID(0x2591), /* SO 2100 mPCI 3B */
  5423. IPW2100_DEV_ID(0x2593), /* SO 2100 mPCI 3B */
  5424. IPW2100_DEV_ID(0x2596), /* SO 2100 mPCI 3B */
  5425. IPW2100_DEV_ID(0x2598), /* SO 2100 mPCI 3B */
  5426. IPW2100_DEV_ID(0x25A0), /* HP 2100 mPCI 3B */
  5427. {0,},
  5428. };
  5429. MODULE_DEVICE_TABLE(pci, ipw2100_pci_id_table);
  5430. static struct pci_driver ipw2100_pci_driver = {
  5431. .name = DRV_NAME,
  5432. .id_table = ipw2100_pci_id_table,
  5433. .probe = ipw2100_pci_init_one,
  5434. .remove = __devexit_p(ipw2100_pci_remove_one),
  5435. #ifdef CONFIG_PM
  5436. .suspend = ipw2100_suspend,
  5437. .resume = ipw2100_resume,
  5438. #endif
  5439. .shutdown = ipw2100_shutdown,
  5440. };
  5441. /**
  5442. * Initialize the ipw2100 driver/module
  5443. *
  5444. * @returns 0 if ok, < 0 errno node con error.
  5445. *
  5446. * Note: we cannot init the /proc stuff until the PCI driver is there,
  5447. * or we risk an unlikely race condition on someone accessing
  5448. * uninitialized data in the PCI dev struct through /proc.
  5449. */
  5450. static int __init ipw2100_init(void)
  5451. {
  5452. int ret;
  5453. printk(KERN_INFO DRV_NAME ": %s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
  5454. printk(KERN_INFO DRV_NAME ": %s\n", DRV_COPYRIGHT);
  5455. pm_qos_add_request(&ipw2100_pm_qos_req, PM_QOS_CPU_DMA_LATENCY,
  5456. PM_QOS_DEFAULT_VALUE);
  5457. ret = pci_register_driver(&ipw2100_pci_driver);
  5458. if (ret)
  5459. goto out;
  5460. #ifdef CONFIG_IPW2100_DEBUG
  5461. ipw2100_debug_level = debug;
  5462. ret = driver_create_file(&ipw2100_pci_driver.driver,
  5463. &driver_attr_debug_level);
  5464. #endif
  5465. out:
  5466. return ret;
  5467. }
  5468. /**
  5469. * Cleanup ipw2100 driver registration
  5470. */
  5471. static void __exit ipw2100_exit(void)
  5472. {
  5473. /* FIXME: IPG: check that we have no instances of the devices open */
  5474. #ifdef CONFIG_IPW2100_DEBUG
  5475. driver_remove_file(&ipw2100_pci_driver.driver,
  5476. &driver_attr_debug_level);
  5477. #endif
  5478. pci_unregister_driver(&ipw2100_pci_driver);
  5479. pm_qos_remove_request(&ipw2100_pm_qos_req);
  5480. }
  5481. module_init(ipw2100_init);
  5482. module_exit(ipw2100_exit);
  5483. static int ipw2100_wx_get_name(struct net_device *dev,
  5484. struct iw_request_info *info,
  5485. union iwreq_data *wrqu, char *extra)
  5486. {
  5487. /*
  5488. * This can be called at any time. No action lock required
  5489. */
  5490. struct ipw2100_priv *priv = libipw_priv(dev);
  5491. if (!(priv->status & STATUS_ASSOCIATED))
  5492. strcpy(wrqu->name, "unassociated");
  5493. else
  5494. snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b");
  5495. IPW_DEBUG_WX("Name: %s\n", wrqu->name);
  5496. return 0;
  5497. }
  5498. static int ipw2100_wx_set_freq(struct net_device *dev,
  5499. struct iw_request_info *info,
  5500. union iwreq_data *wrqu, char *extra)
  5501. {
  5502. struct ipw2100_priv *priv = libipw_priv(dev);
  5503. struct iw_freq *fwrq = &wrqu->freq;
  5504. int err = 0;
  5505. if (priv->ieee->iw_mode == IW_MODE_INFRA)
  5506. return -EOPNOTSUPP;
  5507. mutex_lock(&priv->action_mutex);
  5508. if (!(priv->status & STATUS_INITIALIZED)) {
  5509. err = -EIO;
  5510. goto done;
  5511. }
  5512. /* if setting by freq convert to channel */
  5513. if (fwrq->e == 1) {
  5514. if ((fwrq->m >= (int)2.412e8 && fwrq->m <= (int)2.487e8)) {
  5515. int f = fwrq->m / 100000;
  5516. int c = 0;
  5517. while ((c < REG_MAX_CHANNEL) &&
  5518. (f != ipw2100_frequencies[c]))
  5519. c++;
  5520. /* hack to fall through */
  5521. fwrq->e = 0;
  5522. fwrq->m = c + 1;
  5523. }
  5524. }
  5525. if (fwrq->e > 0 || fwrq->m > 1000) {
  5526. err = -EOPNOTSUPP;
  5527. goto done;
  5528. } else { /* Set the channel */
  5529. IPW_DEBUG_WX("SET Freq/Channel -> %d\n", fwrq->m);
  5530. err = ipw2100_set_channel(priv, fwrq->m, 0);
  5531. }
  5532. done:
  5533. mutex_unlock(&priv->action_mutex);
  5534. return err;
  5535. }
  5536. static int ipw2100_wx_get_freq(struct net_device *dev,
  5537. struct iw_request_info *info,
  5538. union iwreq_data *wrqu, char *extra)
  5539. {
  5540. /*
  5541. * This can be called at any time. No action lock required
  5542. */
  5543. struct ipw2100_priv *priv = libipw_priv(dev);
  5544. wrqu->freq.e = 0;
  5545. /* If we are associated, trying to associate, or have a statically
  5546. * configured CHANNEL then return that; otherwise return ANY */
  5547. if (priv->config & CFG_STATIC_CHANNEL ||
  5548. priv->status & STATUS_ASSOCIATED)
  5549. wrqu->freq.m = priv->channel;
  5550. else
  5551. wrqu->freq.m = 0;
  5552. IPW_DEBUG_WX("GET Freq/Channel -> %d\n", priv->channel);
  5553. return 0;
  5554. }
  5555. static int ipw2100_wx_set_mode(struct net_device *dev,
  5556. struct iw_request_info *info,
  5557. union iwreq_data *wrqu, char *extra)
  5558. {
  5559. struct ipw2100_priv *priv = libipw_priv(dev);
  5560. int err = 0;
  5561. IPW_DEBUG_WX("SET Mode -> %d\n", wrqu->mode);
  5562. if (wrqu->mode == priv->ieee->iw_mode)
  5563. return 0;
  5564. mutex_lock(&priv->action_mutex);
  5565. if (!(priv->status & STATUS_INITIALIZED)) {
  5566. err = -EIO;
  5567. goto done;
  5568. }
  5569. switch (wrqu->mode) {
  5570. #ifdef CONFIG_IPW2100_MONITOR
  5571. case IW_MODE_MONITOR:
  5572. err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
  5573. break;
  5574. #endif /* CONFIG_IPW2100_MONITOR */
  5575. case IW_MODE_ADHOC:
  5576. err = ipw2100_switch_mode(priv, IW_MODE_ADHOC);
  5577. break;
  5578. case IW_MODE_INFRA:
  5579. case IW_MODE_AUTO:
  5580. default:
  5581. err = ipw2100_switch_mode(priv, IW_MODE_INFRA);
  5582. break;
  5583. }
  5584. done:
  5585. mutex_unlock(&priv->action_mutex);
  5586. return err;
  5587. }
  5588. static int ipw2100_wx_get_mode(struct net_device *dev,
  5589. struct iw_request_info *info,
  5590. union iwreq_data *wrqu, char *extra)
  5591. {
  5592. /*
  5593. * This can be called at any time. No action lock required
  5594. */
  5595. struct ipw2100_priv *priv = libipw_priv(dev);
  5596. wrqu->mode = priv->ieee->iw_mode;
  5597. IPW_DEBUG_WX("GET Mode -> %d\n", wrqu->mode);
  5598. return 0;
  5599. }
  5600. #define POWER_MODES 5
  5601. /* Values are in microsecond */
  5602. static const s32 timeout_duration[POWER_MODES] = {
  5603. 350000,
  5604. 250000,
  5605. 75000,
  5606. 37000,
  5607. 25000,
  5608. };
  5609. static const s32 period_duration[POWER_MODES] = {
  5610. 400000,
  5611. 700000,
  5612. 1000000,
  5613. 1000000,
  5614. 1000000
  5615. };
  5616. static int ipw2100_wx_get_range(struct net_device *dev,
  5617. struct iw_request_info *info,
  5618. union iwreq_data *wrqu, char *extra)
  5619. {
  5620. /*
  5621. * This can be called at any time. No action lock required
  5622. */
  5623. struct ipw2100_priv *priv = libipw_priv(dev);
  5624. struct iw_range *range = (struct iw_range *)extra;
  5625. u16 val;
  5626. int i, level;
  5627. wrqu->data.length = sizeof(*range);
  5628. memset(range, 0, sizeof(*range));
  5629. /* Let's try to keep this struct in the same order as in
  5630. * linux/include/wireless.h
  5631. */
  5632. /* TODO: See what values we can set, and remove the ones we can't
  5633. * set, or fill them with some default data.
  5634. */
  5635. /* ~5 Mb/s real (802.11b) */
  5636. range->throughput = 5 * 1000 * 1000;
  5637. // range->sensitivity; /* signal level threshold range */
  5638. range->max_qual.qual = 100;
  5639. /* TODO: Find real max RSSI and stick here */
  5640. range->max_qual.level = 0;
  5641. range->max_qual.noise = 0;
  5642. range->max_qual.updated = 7; /* Updated all three */
  5643. range->avg_qual.qual = 70; /* > 8% missed beacons is 'bad' */
  5644. /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
  5645. range->avg_qual.level = 20 + IPW2100_RSSI_TO_DBM;
  5646. range->avg_qual.noise = 0;
  5647. range->avg_qual.updated = 7; /* Updated all three */
  5648. range->num_bitrates = RATE_COUNT;
  5649. for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++) {
  5650. range->bitrate[i] = ipw2100_bg_rates[i].bitrate * 100 * 1000;
  5651. }
  5652. range->min_rts = MIN_RTS_THRESHOLD;
  5653. range->max_rts = MAX_RTS_THRESHOLD;
  5654. range->min_frag = MIN_FRAG_THRESHOLD;
  5655. range->max_frag = MAX_FRAG_THRESHOLD;
  5656. range->min_pmp = period_duration[0]; /* Minimal PM period */
  5657. range->max_pmp = period_duration[POWER_MODES - 1]; /* Maximal PM period */
  5658. range->min_pmt = timeout_duration[POWER_MODES - 1]; /* Minimal PM timeout */
  5659. range->max_pmt = timeout_duration[0]; /* Maximal PM timeout */
  5660. /* How to decode max/min PM period */
  5661. range->pmp_flags = IW_POWER_PERIOD;
  5662. /* How to decode max/min PM period */
  5663. range->pmt_flags = IW_POWER_TIMEOUT;
  5664. /* What PM options are supported */
  5665. range->pm_capa = IW_POWER_TIMEOUT | IW_POWER_PERIOD;
  5666. range->encoding_size[0] = 5;
  5667. range->encoding_size[1] = 13; /* Different token sizes */
  5668. range->num_encoding_sizes = 2; /* Number of entry in the list */
  5669. range->max_encoding_tokens = WEP_KEYS; /* Max number of tokens */
  5670. // range->encoding_login_index; /* token index for login token */
  5671. if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
  5672. range->txpower_capa = IW_TXPOW_DBM;
  5673. range->num_txpower = IW_MAX_TXPOWER;
  5674. for (i = 0, level = (IPW_TX_POWER_MAX_DBM * 16);
  5675. i < IW_MAX_TXPOWER;
  5676. i++, level -=
  5677. ((IPW_TX_POWER_MAX_DBM -
  5678. IPW_TX_POWER_MIN_DBM) * 16) / (IW_MAX_TXPOWER - 1))
  5679. range->txpower[i] = level / 16;
  5680. } else {
  5681. range->txpower_capa = 0;
  5682. range->num_txpower = 0;
  5683. }
  5684. /* Set the Wireless Extension versions */
  5685. range->we_version_compiled = WIRELESS_EXT;
  5686. range->we_version_source = 18;
  5687. // range->retry_capa; /* What retry options are supported */
  5688. // range->retry_flags; /* How to decode max/min retry limit */
  5689. // range->r_time_flags; /* How to decode max/min retry life */
  5690. // range->min_retry; /* Minimal number of retries */
  5691. // range->max_retry; /* Maximal number of retries */
  5692. // range->min_r_time; /* Minimal retry lifetime */
  5693. // range->max_r_time; /* Maximal retry lifetime */
  5694. range->num_channels = FREQ_COUNT;
  5695. val = 0;
  5696. for (i = 0; i < FREQ_COUNT; i++) {
  5697. // TODO: Include only legal frequencies for some countries
  5698. // if (local->channel_mask & (1 << i)) {
  5699. range->freq[val].i = i + 1;
  5700. range->freq[val].m = ipw2100_frequencies[i] * 100000;
  5701. range->freq[val].e = 1;
  5702. val++;
  5703. // }
  5704. if (val == IW_MAX_FREQUENCIES)
  5705. break;
  5706. }
  5707. range->num_frequency = val;
  5708. /* Event capability (kernel + driver) */
  5709. range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
  5710. IW_EVENT_CAPA_MASK(SIOCGIWAP));
  5711. range->event_capa[1] = IW_EVENT_CAPA_K_1;
  5712. range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
  5713. IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
  5714. IPW_DEBUG_WX("GET Range\n");
  5715. return 0;
  5716. }
  5717. static int ipw2100_wx_set_wap(struct net_device *dev,
  5718. struct iw_request_info *info,
  5719. union iwreq_data *wrqu, char *extra)
  5720. {
  5721. struct ipw2100_priv *priv = libipw_priv(dev);
  5722. int err = 0;
  5723. static const unsigned char any[] = {
  5724. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
  5725. };
  5726. static const unsigned char off[] = {
  5727. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  5728. };
  5729. // sanity checks
  5730. if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
  5731. return -EINVAL;
  5732. mutex_lock(&priv->action_mutex);
  5733. if (!(priv->status & STATUS_INITIALIZED)) {
  5734. err = -EIO;
  5735. goto done;
  5736. }
  5737. if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
  5738. !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
  5739. /* we disable mandatory BSSID association */
  5740. IPW_DEBUG_WX("exit - disable mandatory BSSID\n");
  5741. priv->config &= ~CFG_STATIC_BSSID;
  5742. err = ipw2100_set_mandatory_bssid(priv, NULL, 0);
  5743. goto done;
  5744. }
  5745. priv->config |= CFG_STATIC_BSSID;
  5746. memcpy(priv->mandatory_bssid_mac, wrqu->ap_addr.sa_data, ETH_ALEN);
  5747. err = ipw2100_set_mandatory_bssid(priv, wrqu->ap_addr.sa_data, 0);
  5748. IPW_DEBUG_WX("SET BSSID -> %pM\n", wrqu->ap_addr.sa_data);
  5749. done:
  5750. mutex_unlock(&priv->action_mutex);
  5751. return err;
  5752. }
  5753. static int ipw2100_wx_get_wap(struct net_device *dev,
  5754. struct iw_request_info *info,
  5755. union iwreq_data *wrqu, char *extra)
  5756. {
  5757. /*
  5758. * This can be called at any time. No action lock required
  5759. */
  5760. struct ipw2100_priv *priv = libipw_priv(dev);
  5761. /* If we are associated, trying to associate, or have a statically
  5762. * configured BSSID then return that; otherwise return ANY */
  5763. if (priv->config & CFG_STATIC_BSSID || priv->status & STATUS_ASSOCIATED) {
  5764. wrqu->ap_addr.sa_family = ARPHRD_ETHER;
  5765. memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
  5766. } else
  5767. memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
  5768. IPW_DEBUG_WX("Getting WAP BSSID: %pM\n", wrqu->ap_addr.sa_data);
  5769. return 0;
  5770. }
  5771. static int ipw2100_wx_set_essid(struct net_device *dev,
  5772. struct iw_request_info *info,
  5773. union iwreq_data *wrqu, char *extra)
  5774. {
  5775. struct ipw2100_priv *priv = libipw_priv(dev);
  5776. char *essid = ""; /* ANY */
  5777. int length = 0;
  5778. int err = 0;
  5779. DECLARE_SSID_BUF(ssid);
  5780. mutex_lock(&priv->action_mutex);
  5781. if (!(priv->status & STATUS_INITIALIZED)) {
  5782. err = -EIO;
  5783. goto done;
  5784. }
  5785. if (wrqu->essid.flags && wrqu->essid.length) {
  5786. length = wrqu->essid.length;
  5787. essid = extra;
  5788. }
  5789. if (length == 0) {
  5790. IPW_DEBUG_WX("Setting ESSID to ANY\n");
  5791. priv->config &= ~CFG_STATIC_ESSID;
  5792. err = ipw2100_set_essid(priv, NULL, 0, 0);
  5793. goto done;
  5794. }
  5795. length = min(length, IW_ESSID_MAX_SIZE);
  5796. priv->config |= CFG_STATIC_ESSID;
  5797. if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
  5798. IPW_DEBUG_WX("ESSID set to current ESSID.\n");
  5799. err = 0;
  5800. goto done;
  5801. }
  5802. IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n",
  5803. print_ssid(ssid, essid, length), length);
  5804. priv->essid_len = length;
  5805. memcpy(priv->essid, essid, priv->essid_len);
  5806. err = ipw2100_set_essid(priv, essid, length, 0);
  5807. done:
  5808. mutex_unlock(&priv->action_mutex);
  5809. return err;
  5810. }
  5811. static int ipw2100_wx_get_essid(struct net_device *dev,
  5812. struct iw_request_info *info,
  5813. union iwreq_data *wrqu, char *extra)
  5814. {
  5815. /*
  5816. * This can be called at any time. No action lock required
  5817. */
  5818. struct ipw2100_priv *priv = libipw_priv(dev);
  5819. DECLARE_SSID_BUF(ssid);
  5820. /* If we are associated, trying to associate, or have a statically
  5821. * configured ESSID then return that; otherwise return ANY */
  5822. if (priv->config & CFG_STATIC_ESSID || priv->status & STATUS_ASSOCIATED) {
  5823. IPW_DEBUG_WX("Getting essid: '%s'\n",
  5824. print_ssid(ssid, priv->essid, priv->essid_len));
  5825. memcpy(extra, priv->essid, priv->essid_len);
  5826. wrqu->essid.length = priv->essid_len;
  5827. wrqu->essid.flags = 1; /* active */
  5828. } else {
  5829. IPW_DEBUG_WX("Getting essid: ANY\n");
  5830. wrqu->essid.length = 0;
  5831. wrqu->essid.flags = 0; /* active */
  5832. }
  5833. return 0;
  5834. }
  5835. static int ipw2100_wx_set_nick(struct net_device *dev,
  5836. struct iw_request_info *info,
  5837. union iwreq_data *wrqu, char *extra)
  5838. {
  5839. /*
  5840. * This can be called at any time. No action lock required
  5841. */
  5842. struct ipw2100_priv *priv = libipw_priv(dev);
  5843. if (wrqu->data.length > IW_ESSID_MAX_SIZE)
  5844. return -E2BIG;
  5845. wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
  5846. memset(priv->nick, 0, sizeof(priv->nick));
  5847. memcpy(priv->nick, extra, wrqu->data.length);
  5848. IPW_DEBUG_WX("SET Nickname -> %s\n", priv->nick);
  5849. return 0;
  5850. }
  5851. static int ipw2100_wx_get_nick(struct net_device *dev,
  5852. struct iw_request_info *info,
  5853. union iwreq_data *wrqu, char *extra)
  5854. {
  5855. /*
  5856. * This can be called at any time. No action lock required
  5857. */
  5858. struct ipw2100_priv *priv = libipw_priv(dev);
  5859. wrqu->data.length = strlen(priv->nick);
  5860. memcpy(extra, priv->nick, wrqu->data.length);
  5861. wrqu->data.flags = 1; /* active */
  5862. IPW_DEBUG_WX("GET Nickname -> %s\n", extra);
  5863. return 0;
  5864. }
  5865. static int ipw2100_wx_set_rate(struct net_device *dev,
  5866. struct iw_request_info *info,
  5867. union iwreq_data *wrqu, char *extra)
  5868. {
  5869. struct ipw2100_priv *priv = libipw_priv(dev);
  5870. u32 target_rate = wrqu->bitrate.value;
  5871. u32 rate;
  5872. int err = 0;
  5873. mutex_lock(&priv->action_mutex);
  5874. if (!(priv->status & STATUS_INITIALIZED)) {
  5875. err = -EIO;
  5876. goto done;
  5877. }
  5878. rate = 0;
  5879. if (target_rate == 1000000 ||
  5880. (!wrqu->bitrate.fixed && target_rate > 1000000))
  5881. rate |= TX_RATE_1_MBIT;
  5882. if (target_rate == 2000000 ||
  5883. (!wrqu->bitrate.fixed && target_rate > 2000000))
  5884. rate |= TX_RATE_2_MBIT;
  5885. if (target_rate == 5500000 ||
  5886. (!wrqu->bitrate.fixed && target_rate > 5500000))
  5887. rate |= TX_RATE_5_5_MBIT;
  5888. if (target_rate == 11000000 ||
  5889. (!wrqu->bitrate.fixed && target_rate > 11000000))
  5890. rate |= TX_RATE_11_MBIT;
  5891. if (rate == 0)
  5892. rate = DEFAULT_TX_RATES;
  5893. err = ipw2100_set_tx_rates(priv, rate, 0);
  5894. IPW_DEBUG_WX("SET Rate -> %04X\n", rate);
  5895. done:
  5896. mutex_unlock(&priv->action_mutex);
  5897. return err;
  5898. }
  5899. static int ipw2100_wx_get_rate(struct net_device *dev,
  5900. struct iw_request_info *info,
  5901. union iwreq_data *wrqu, char *extra)
  5902. {
  5903. struct ipw2100_priv *priv = libipw_priv(dev);
  5904. int val;
  5905. unsigned int len = sizeof(val);
  5906. int err = 0;
  5907. if (!(priv->status & STATUS_ENABLED) ||
  5908. priv->status & STATUS_RF_KILL_MASK ||
  5909. !(priv->status & STATUS_ASSOCIATED)) {
  5910. wrqu->bitrate.value = 0;
  5911. return 0;
  5912. }
  5913. mutex_lock(&priv->action_mutex);
  5914. if (!(priv->status & STATUS_INITIALIZED)) {
  5915. err = -EIO;
  5916. goto done;
  5917. }
  5918. err = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &val, &len);
  5919. if (err) {
  5920. IPW_DEBUG_WX("failed querying ordinals.\n");
  5921. goto done;
  5922. }
  5923. switch (val & TX_RATE_MASK) {
  5924. case TX_RATE_1_MBIT:
  5925. wrqu->bitrate.value = 1000000;
  5926. break;
  5927. case TX_RATE_2_MBIT:
  5928. wrqu->bitrate.value = 2000000;
  5929. break;
  5930. case TX_RATE_5_5_MBIT:
  5931. wrqu->bitrate.value = 5500000;
  5932. break;
  5933. case TX_RATE_11_MBIT:
  5934. wrqu->bitrate.value = 11000000;
  5935. break;
  5936. default:
  5937. wrqu->bitrate.value = 0;
  5938. }
  5939. IPW_DEBUG_WX("GET Rate -> %d\n", wrqu->bitrate.value);
  5940. done:
  5941. mutex_unlock(&priv->action_mutex);
  5942. return err;
  5943. }
  5944. static int ipw2100_wx_set_rts(struct net_device *dev,
  5945. struct iw_request_info *info,
  5946. union iwreq_data *wrqu, char *extra)
  5947. {
  5948. struct ipw2100_priv *priv = libipw_priv(dev);
  5949. int value, err;
  5950. /* Auto RTS not yet supported */
  5951. if (wrqu->rts.fixed == 0)
  5952. return -EINVAL;
  5953. mutex_lock(&priv->action_mutex);
  5954. if (!(priv->status & STATUS_INITIALIZED)) {
  5955. err = -EIO;
  5956. goto done;
  5957. }
  5958. if (wrqu->rts.disabled)
  5959. value = priv->rts_threshold | RTS_DISABLED;
  5960. else {
  5961. if (wrqu->rts.value < 1 || wrqu->rts.value > 2304) {
  5962. err = -EINVAL;
  5963. goto done;
  5964. }
  5965. value = wrqu->rts.value;
  5966. }
  5967. err = ipw2100_set_rts_threshold(priv, value);
  5968. IPW_DEBUG_WX("SET RTS Threshold -> 0x%08X\n", value);
  5969. done:
  5970. mutex_unlock(&priv->action_mutex);
  5971. return err;
  5972. }
  5973. static int ipw2100_wx_get_rts(struct net_device *dev,
  5974. struct iw_request_info *info,
  5975. union iwreq_data *wrqu, char *extra)
  5976. {
  5977. /*
  5978. * This can be called at any time. No action lock required
  5979. */
  5980. struct ipw2100_priv *priv = libipw_priv(dev);
  5981. wrqu->rts.value = priv->rts_threshold & ~RTS_DISABLED;
  5982. wrqu->rts.fixed = 1; /* no auto select */
  5983. /* If RTS is set to the default value, then it is disabled */
  5984. wrqu->rts.disabled = (priv->rts_threshold & RTS_DISABLED) ? 1 : 0;
  5985. IPW_DEBUG_WX("GET RTS Threshold -> 0x%08X\n", wrqu->rts.value);
  5986. return 0;
  5987. }
  5988. static int ipw2100_wx_set_txpow(struct net_device *dev,
  5989. struct iw_request_info *info,
  5990. union iwreq_data *wrqu, char *extra)
  5991. {
  5992. struct ipw2100_priv *priv = libipw_priv(dev);
  5993. int err = 0, value;
  5994. if (ipw_radio_kill_sw(priv, wrqu->txpower.disabled))
  5995. return -EINPROGRESS;
  5996. if (priv->ieee->iw_mode != IW_MODE_ADHOC)
  5997. return 0;
  5998. if ((wrqu->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
  5999. return -EINVAL;
  6000. if (wrqu->txpower.fixed == 0)
  6001. value = IPW_TX_POWER_DEFAULT;
  6002. else {
  6003. if (wrqu->txpower.value < IPW_TX_POWER_MIN_DBM ||
  6004. wrqu->txpower.value > IPW_TX_POWER_MAX_DBM)
  6005. return -EINVAL;
  6006. value = wrqu->txpower.value;
  6007. }
  6008. mutex_lock(&priv->action_mutex);
  6009. if (!(priv->status & STATUS_INITIALIZED)) {
  6010. err = -EIO;
  6011. goto done;
  6012. }
  6013. err = ipw2100_set_tx_power(priv, value);
  6014. IPW_DEBUG_WX("SET TX Power -> %d\n", value);
  6015. done:
  6016. mutex_unlock(&priv->action_mutex);
  6017. return err;
  6018. }
  6019. static int ipw2100_wx_get_txpow(struct net_device *dev,
  6020. struct iw_request_info *info,
  6021. union iwreq_data *wrqu, char *extra)
  6022. {
  6023. /*
  6024. * This can be called at any time. No action lock required
  6025. */
  6026. struct ipw2100_priv *priv = libipw_priv(dev);
  6027. wrqu->txpower.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
  6028. if (priv->tx_power == IPW_TX_POWER_DEFAULT) {
  6029. wrqu->txpower.fixed = 0;
  6030. wrqu->txpower.value = IPW_TX_POWER_MAX_DBM;
  6031. } else {
  6032. wrqu->txpower.fixed = 1;
  6033. wrqu->txpower.value = priv->tx_power;
  6034. }
  6035. wrqu->txpower.flags = IW_TXPOW_DBM;
  6036. IPW_DEBUG_WX("GET TX Power -> %d\n", wrqu->txpower.value);
  6037. return 0;
  6038. }
  6039. static int ipw2100_wx_set_frag(struct net_device *dev,
  6040. struct iw_request_info *info,
  6041. union iwreq_data *wrqu, char *extra)
  6042. {
  6043. /*
  6044. * This can be called at any time. No action lock required
  6045. */
  6046. struct ipw2100_priv *priv = libipw_priv(dev);
  6047. if (!wrqu->frag.fixed)
  6048. return -EINVAL;
  6049. if (wrqu->frag.disabled) {
  6050. priv->frag_threshold |= FRAG_DISABLED;
  6051. priv->ieee->fts = DEFAULT_FTS;
  6052. } else {
  6053. if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
  6054. wrqu->frag.value > MAX_FRAG_THRESHOLD)
  6055. return -EINVAL;
  6056. priv->ieee->fts = wrqu->frag.value & ~0x1;
  6057. priv->frag_threshold = priv->ieee->fts;
  6058. }
  6059. IPW_DEBUG_WX("SET Frag Threshold -> %d\n", priv->ieee->fts);
  6060. return 0;
  6061. }
  6062. static int ipw2100_wx_get_frag(struct net_device *dev,
  6063. struct iw_request_info *info,
  6064. union iwreq_data *wrqu, char *extra)
  6065. {
  6066. /*
  6067. * This can be called at any time. No action lock required
  6068. */
  6069. struct ipw2100_priv *priv = libipw_priv(dev);
  6070. wrqu->frag.value = priv->frag_threshold & ~FRAG_DISABLED;
  6071. wrqu->frag.fixed = 0; /* no auto select */
  6072. wrqu->frag.disabled = (priv->frag_threshold & FRAG_DISABLED) ? 1 : 0;
  6073. IPW_DEBUG_WX("GET Frag Threshold -> %d\n", wrqu->frag.value);
  6074. return 0;
  6075. }
  6076. static int ipw2100_wx_set_retry(struct net_device *dev,
  6077. struct iw_request_info *info,
  6078. union iwreq_data *wrqu, char *extra)
  6079. {
  6080. struct ipw2100_priv *priv = libipw_priv(dev);
  6081. int err = 0;
  6082. if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
  6083. return -EINVAL;
  6084. if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
  6085. return 0;
  6086. mutex_lock(&priv->action_mutex);
  6087. if (!(priv->status & STATUS_INITIALIZED)) {
  6088. err = -EIO;
  6089. goto done;
  6090. }
  6091. if (wrqu->retry.flags & IW_RETRY_SHORT) {
  6092. err = ipw2100_set_short_retry(priv, wrqu->retry.value);
  6093. IPW_DEBUG_WX("SET Short Retry Limit -> %d\n",
  6094. wrqu->retry.value);
  6095. goto done;
  6096. }
  6097. if (wrqu->retry.flags & IW_RETRY_LONG) {
  6098. err = ipw2100_set_long_retry(priv, wrqu->retry.value);
  6099. IPW_DEBUG_WX("SET Long Retry Limit -> %d\n",
  6100. wrqu->retry.value);
  6101. goto done;
  6102. }
  6103. err = ipw2100_set_short_retry(priv, wrqu->retry.value);
  6104. if (!err)
  6105. err = ipw2100_set_long_retry(priv, wrqu->retry.value);
  6106. IPW_DEBUG_WX("SET Both Retry Limits -> %d\n", wrqu->retry.value);
  6107. done:
  6108. mutex_unlock(&priv->action_mutex);
  6109. return err;
  6110. }
  6111. static int ipw2100_wx_get_retry(struct net_device *dev,
  6112. struct iw_request_info *info,
  6113. union iwreq_data *wrqu, char *extra)
  6114. {
  6115. /*
  6116. * This can be called at any time. No action lock required
  6117. */
  6118. struct ipw2100_priv *priv = libipw_priv(dev);
  6119. wrqu->retry.disabled = 0; /* can't be disabled */
  6120. if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME)
  6121. return -EINVAL;
  6122. if (wrqu->retry.flags & IW_RETRY_LONG) {
  6123. wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
  6124. wrqu->retry.value = priv->long_retry_limit;
  6125. } else {
  6126. wrqu->retry.flags =
  6127. (priv->short_retry_limit !=
  6128. priv->long_retry_limit) ?
  6129. IW_RETRY_LIMIT | IW_RETRY_SHORT : IW_RETRY_LIMIT;
  6130. wrqu->retry.value = priv->short_retry_limit;
  6131. }
  6132. IPW_DEBUG_WX("GET Retry -> %d\n", wrqu->retry.value);
  6133. return 0;
  6134. }
  6135. static int ipw2100_wx_set_scan(struct net_device *dev,
  6136. struct iw_request_info *info,
  6137. union iwreq_data *wrqu, char *extra)
  6138. {
  6139. struct ipw2100_priv *priv = libipw_priv(dev);
  6140. int err = 0;
  6141. mutex_lock(&priv->action_mutex);
  6142. if (!(priv->status & STATUS_INITIALIZED)) {
  6143. err = -EIO;
  6144. goto done;
  6145. }
  6146. IPW_DEBUG_WX("Initiating scan...\n");
  6147. priv->user_requested_scan = 1;
  6148. if (ipw2100_set_scan_options(priv) || ipw2100_start_scan(priv)) {
  6149. IPW_DEBUG_WX("Start scan failed.\n");
  6150. /* TODO: Mark a scan as pending so when hardware initialized
  6151. * a scan starts */
  6152. }
  6153. done:
  6154. mutex_unlock(&priv->action_mutex);
  6155. return err;
  6156. }
  6157. static int ipw2100_wx_get_scan(struct net_device *dev,
  6158. struct iw_request_info *info,
  6159. union iwreq_data *wrqu, char *extra)
  6160. {
  6161. /*
  6162. * This can be called at any time. No action lock required
  6163. */
  6164. struct ipw2100_priv *priv = libipw_priv(dev);
  6165. return libipw_wx_get_scan(priv->ieee, info, wrqu, extra);
  6166. }
  6167. /*
  6168. * Implementation based on code in hostap-driver v0.1.3 hostap_ioctl.c
  6169. */
  6170. static int ipw2100_wx_set_encode(struct net_device *dev,
  6171. struct iw_request_info *info,
  6172. union iwreq_data *wrqu, char *key)
  6173. {
  6174. /*
  6175. * No check of STATUS_INITIALIZED required
  6176. */
  6177. struct ipw2100_priv *priv = libipw_priv(dev);
  6178. return libipw_wx_set_encode(priv->ieee, info, wrqu, key);
  6179. }
  6180. static int ipw2100_wx_get_encode(struct net_device *dev,
  6181. struct iw_request_info *info,
  6182. union iwreq_data *wrqu, char *key)
  6183. {
  6184. /*
  6185. * This can be called at any time. No action lock required
  6186. */
  6187. struct ipw2100_priv *priv = libipw_priv(dev);
  6188. return libipw_wx_get_encode(priv->ieee, info, wrqu, key);
  6189. }
  6190. static int ipw2100_wx_set_power(struct net_device *dev,
  6191. struct iw_request_info *info,
  6192. union iwreq_data *wrqu, char *extra)
  6193. {
  6194. struct ipw2100_priv *priv = libipw_priv(dev);
  6195. int err = 0;
  6196. mutex_lock(&priv->action_mutex);
  6197. if (!(priv->status & STATUS_INITIALIZED)) {
  6198. err = -EIO;
  6199. goto done;
  6200. }
  6201. if (wrqu->power.disabled) {
  6202. priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
  6203. err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
  6204. IPW_DEBUG_WX("SET Power Management Mode -> off\n");
  6205. goto done;
  6206. }
  6207. switch (wrqu->power.flags & IW_POWER_MODE) {
  6208. case IW_POWER_ON: /* If not specified */
  6209. case IW_POWER_MODE: /* If set all mask */
  6210. case IW_POWER_ALL_R: /* If explicitly state all */
  6211. break;
  6212. default: /* Otherwise we don't support it */
  6213. IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
  6214. wrqu->power.flags);
  6215. err = -EOPNOTSUPP;
  6216. goto done;
  6217. }
  6218. /* If the user hasn't specified a power management mode yet, default
  6219. * to BATTERY */
  6220. priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
  6221. err = ipw2100_set_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
  6222. IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
  6223. done:
  6224. mutex_unlock(&priv->action_mutex);
  6225. return err;
  6226. }
  6227. static int ipw2100_wx_get_power(struct net_device *dev,
  6228. struct iw_request_info *info,
  6229. union iwreq_data *wrqu, char *extra)
  6230. {
  6231. /*
  6232. * This can be called at any time. No action lock required
  6233. */
  6234. struct ipw2100_priv *priv = libipw_priv(dev);
  6235. if (!(priv->power_mode & IPW_POWER_ENABLED))
  6236. wrqu->power.disabled = 1;
  6237. else {
  6238. wrqu->power.disabled = 0;
  6239. wrqu->power.flags = 0;
  6240. }
  6241. IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
  6242. return 0;
  6243. }
  6244. /*
  6245. * WE-18 WPA support
  6246. */
  6247. /* SIOCSIWGENIE */
  6248. static int ipw2100_wx_set_genie(struct net_device *dev,
  6249. struct iw_request_info *info,
  6250. union iwreq_data *wrqu, char *extra)
  6251. {
  6252. struct ipw2100_priv *priv = libipw_priv(dev);
  6253. struct libipw_device *ieee = priv->ieee;
  6254. u8 *buf;
  6255. if (!ieee->wpa_enabled)
  6256. return -EOPNOTSUPP;
  6257. if (wrqu->data.length > MAX_WPA_IE_LEN ||
  6258. (wrqu->data.length && extra == NULL))
  6259. return -EINVAL;
  6260. if (wrqu->data.length) {
  6261. buf = kmemdup(extra, wrqu->data.length, GFP_KERNEL);
  6262. if (buf == NULL)
  6263. return -ENOMEM;
  6264. kfree(ieee->wpa_ie);
  6265. ieee->wpa_ie = buf;
  6266. ieee->wpa_ie_len = wrqu->data.length;
  6267. } else {
  6268. kfree(ieee->wpa_ie);
  6269. ieee->wpa_ie = NULL;
  6270. ieee->wpa_ie_len = 0;
  6271. }
  6272. ipw2100_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
  6273. return 0;
  6274. }
  6275. /* SIOCGIWGENIE */
  6276. static int ipw2100_wx_get_genie(struct net_device *dev,
  6277. struct iw_request_info *info,
  6278. union iwreq_data *wrqu, char *extra)
  6279. {
  6280. struct ipw2100_priv *priv = libipw_priv(dev);
  6281. struct libipw_device *ieee = priv->ieee;
  6282. if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
  6283. wrqu->data.length = 0;
  6284. return 0;
  6285. }
  6286. if (wrqu->data.length < ieee->wpa_ie_len)
  6287. return -E2BIG;
  6288. wrqu->data.length = ieee->wpa_ie_len;
  6289. memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
  6290. return 0;
  6291. }
  6292. /* SIOCSIWAUTH */
  6293. static int ipw2100_wx_set_auth(struct net_device *dev,
  6294. struct iw_request_info *info,
  6295. union iwreq_data *wrqu, char *extra)
  6296. {
  6297. struct ipw2100_priv *priv = libipw_priv(dev);
  6298. struct libipw_device *ieee = priv->ieee;
  6299. struct iw_param *param = &wrqu->param;
  6300. struct lib80211_crypt_data *crypt;
  6301. unsigned long flags;
  6302. int ret = 0;
  6303. switch (param->flags & IW_AUTH_INDEX) {
  6304. case IW_AUTH_WPA_VERSION:
  6305. case IW_AUTH_CIPHER_PAIRWISE:
  6306. case IW_AUTH_CIPHER_GROUP:
  6307. case IW_AUTH_KEY_MGMT:
  6308. /*
  6309. * ipw2200 does not use these parameters
  6310. */
  6311. break;
  6312. case IW_AUTH_TKIP_COUNTERMEASURES:
  6313. crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
  6314. if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags)
  6315. break;
  6316. flags = crypt->ops->get_flags(crypt->priv);
  6317. if (param->value)
  6318. flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
  6319. else
  6320. flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
  6321. crypt->ops->set_flags(flags, crypt->priv);
  6322. break;
  6323. case IW_AUTH_DROP_UNENCRYPTED:{
  6324. /* HACK:
  6325. *
  6326. * wpa_supplicant calls set_wpa_enabled when the driver
  6327. * is loaded and unloaded, regardless of if WPA is being
  6328. * used. No other calls are made which can be used to
  6329. * determine if encryption will be used or not prior to
  6330. * association being expected. If encryption is not being
  6331. * used, drop_unencrypted is set to false, else true -- we
  6332. * can use this to determine if the CAP_PRIVACY_ON bit should
  6333. * be set.
  6334. */
  6335. struct libipw_security sec = {
  6336. .flags = SEC_ENABLED,
  6337. .enabled = param->value,
  6338. };
  6339. priv->ieee->drop_unencrypted = param->value;
  6340. /* We only change SEC_LEVEL for open mode. Others
  6341. * are set by ipw_wpa_set_encryption.
  6342. */
  6343. if (!param->value) {
  6344. sec.flags |= SEC_LEVEL;
  6345. sec.level = SEC_LEVEL_0;
  6346. } else {
  6347. sec.flags |= SEC_LEVEL;
  6348. sec.level = SEC_LEVEL_1;
  6349. }
  6350. if (priv->ieee->set_security)
  6351. priv->ieee->set_security(priv->ieee->dev, &sec);
  6352. break;
  6353. }
  6354. case IW_AUTH_80211_AUTH_ALG:
  6355. ret = ipw2100_wpa_set_auth_algs(priv, param->value);
  6356. break;
  6357. case IW_AUTH_WPA_ENABLED:
  6358. ret = ipw2100_wpa_enable(priv, param->value);
  6359. break;
  6360. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  6361. ieee->ieee802_1x = param->value;
  6362. break;
  6363. //case IW_AUTH_ROAMING_CONTROL:
  6364. case IW_AUTH_PRIVACY_INVOKED:
  6365. ieee->privacy_invoked = param->value;
  6366. break;
  6367. default:
  6368. return -EOPNOTSUPP;
  6369. }
  6370. return ret;
  6371. }
  6372. /* SIOCGIWAUTH */
  6373. static int ipw2100_wx_get_auth(struct net_device *dev,
  6374. struct iw_request_info *info,
  6375. union iwreq_data *wrqu, char *extra)
  6376. {
  6377. struct ipw2100_priv *priv = libipw_priv(dev);
  6378. struct libipw_device *ieee = priv->ieee;
  6379. struct lib80211_crypt_data *crypt;
  6380. struct iw_param *param = &wrqu->param;
  6381. int ret = 0;
  6382. switch (param->flags & IW_AUTH_INDEX) {
  6383. case IW_AUTH_WPA_VERSION:
  6384. case IW_AUTH_CIPHER_PAIRWISE:
  6385. case IW_AUTH_CIPHER_GROUP:
  6386. case IW_AUTH_KEY_MGMT:
  6387. /*
  6388. * wpa_supplicant will control these internally
  6389. */
  6390. ret = -EOPNOTSUPP;
  6391. break;
  6392. case IW_AUTH_TKIP_COUNTERMEASURES:
  6393. crypt = priv->ieee->crypt_info.crypt[priv->ieee->crypt_info.tx_keyidx];
  6394. if (!crypt || !crypt->ops->get_flags) {
  6395. IPW_DEBUG_WARNING("Can't get TKIP countermeasures: "
  6396. "crypt not set!\n");
  6397. break;
  6398. }
  6399. param->value = (crypt->ops->get_flags(crypt->priv) &
  6400. IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
  6401. break;
  6402. case IW_AUTH_DROP_UNENCRYPTED:
  6403. param->value = ieee->drop_unencrypted;
  6404. break;
  6405. case IW_AUTH_80211_AUTH_ALG:
  6406. param->value = priv->ieee->sec.auth_mode;
  6407. break;
  6408. case IW_AUTH_WPA_ENABLED:
  6409. param->value = ieee->wpa_enabled;
  6410. break;
  6411. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  6412. param->value = ieee->ieee802_1x;
  6413. break;
  6414. case IW_AUTH_ROAMING_CONTROL:
  6415. case IW_AUTH_PRIVACY_INVOKED:
  6416. param->value = ieee->privacy_invoked;
  6417. break;
  6418. default:
  6419. return -EOPNOTSUPP;
  6420. }
  6421. return 0;
  6422. }
  6423. /* SIOCSIWENCODEEXT */
  6424. static int ipw2100_wx_set_encodeext(struct net_device *dev,
  6425. struct iw_request_info *info,
  6426. union iwreq_data *wrqu, char *extra)
  6427. {
  6428. struct ipw2100_priv *priv = libipw_priv(dev);
  6429. return libipw_wx_set_encodeext(priv->ieee, info, wrqu, extra);
  6430. }
  6431. /* SIOCGIWENCODEEXT */
  6432. static int ipw2100_wx_get_encodeext(struct net_device *dev,
  6433. struct iw_request_info *info,
  6434. union iwreq_data *wrqu, char *extra)
  6435. {
  6436. struct ipw2100_priv *priv = libipw_priv(dev);
  6437. return libipw_wx_get_encodeext(priv->ieee, info, wrqu, extra);
  6438. }
  6439. /* SIOCSIWMLME */
  6440. static int ipw2100_wx_set_mlme(struct net_device *dev,
  6441. struct iw_request_info *info,
  6442. union iwreq_data *wrqu, char *extra)
  6443. {
  6444. struct ipw2100_priv *priv = libipw_priv(dev);
  6445. struct iw_mlme *mlme = (struct iw_mlme *)extra;
  6446. __le16 reason;
  6447. reason = cpu_to_le16(mlme->reason_code);
  6448. switch (mlme->cmd) {
  6449. case IW_MLME_DEAUTH:
  6450. // silently ignore
  6451. break;
  6452. case IW_MLME_DISASSOC:
  6453. ipw2100_disassociate_bssid(priv);
  6454. break;
  6455. default:
  6456. return -EOPNOTSUPP;
  6457. }
  6458. return 0;
  6459. }
  6460. /*
  6461. *
  6462. * IWPRIV handlers
  6463. *
  6464. */
  6465. #ifdef CONFIG_IPW2100_MONITOR
  6466. static int ipw2100_wx_set_promisc(struct net_device *dev,
  6467. struct iw_request_info *info,
  6468. union iwreq_data *wrqu, char *extra)
  6469. {
  6470. struct ipw2100_priv *priv = libipw_priv(dev);
  6471. int *parms = (int *)extra;
  6472. int enable = (parms[0] > 0);
  6473. int err = 0;
  6474. mutex_lock(&priv->action_mutex);
  6475. if (!(priv->status & STATUS_INITIALIZED)) {
  6476. err = -EIO;
  6477. goto done;
  6478. }
  6479. if (enable) {
  6480. if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
  6481. err = ipw2100_set_channel(priv, parms[1], 0);
  6482. goto done;
  6483. }
  6484. priv->channel = parms[1];
  6485. err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
  6486. } else {
  6487. if (priv->ieee->iw_mode == IW_MODE_MONITOR)
  6488. err = ipw2100_switch_mode(priv, priv->last_mode);
  6489. }
  6490. done:
  6491. mutex_unlock(&priv->action_mutex);
  6492. return err;
  6493. }
  6494. static int ipw2100_wx_reset(struct net_device *dev,
  6495. struct iw_request_info *info,
  6496. union iwreq_data *wrqu, char *extra)
  6497. {
  6498. struct ipw2100_priv *priv = libipw_priv(dev);
  6499. if (priv->status & STATUS_INITIALIZED)
  6500. schedule_reset(priv);
  6501. return 0;
  6502. }
  6503. #endif
  6504. static int ipw2100_wx_set_powermode(struct net_device *dev,
  6505. struct iw_request_info *info,
  6506. union iwreq_data *wrqu, char *extra)
  6507. {
  6508. struct ipw2100_priv *priv = libipw_priv(dev);
  6509. int err = 0, mode = *(int *)extra;
  6510. mutex_lock(&priv->action_mutex);
  6511. if (!(priv->status & STATUS_INITIALIZED)) {
  6512. err = -EIO;
  6513. goto done;
  6514. }
  6515. if ((mode < 0) || (mode > POWER_MODES))
  6516. mode = IPW_POWER_AUTO;
  6517. if (IPW_POWER_LEVEL(priv->power_mode) != mode)
  6518. err = ipw2100_set_power_mode(priv, mode);
  6519. done:
  6520. mutex_unlock(&priv->action_mutex);
  6521. return err;
  6522. }
  6523. #define MAX_POWER_STRING 80
  6524. static int ipw2100_wx_get_powermode(struct net_device *dev,
  6525. struct iw_request_info *info,
  6526. union iwreq_data *wrqu, char *extra)
  6527. {
  6528. /*
  6529. * This can be called at any time. No action lock required
  6530. */
  6531. struct ipw2100_priv *priv = libipw_priv(dev);
  6532. int level = IPW_POWER_LEVEL(priv->power_mode);
  6533. s32 timeout, period;
  6534. if (!(priv->power_mode & IPW_POWER_ENABLED)) {
  6535. snprintf(extra, MAX_POWER_STRING,
  6536. "Power save level: %d (Off)", level);
  6537. } else {
  6538. switch (level) {
  6539. case IPW_POWER_MODE_CAM:
  6540. snprintf(extra, MAX_POWER_STRING,
  6541. "Power save level: %d (None)", level);
  6542. break;
  6543. case IPW_POWER_AUTO:
  6544. snprintf(extra, MAX_POWER_STRING,
  6545. "Power save level: %d (Auto)", level);
  6546. break;
  6547. default:
  6548. timeout = timeout_duration[level - 1] / 1000;
  6549. period = period_duration[level - 1] / 1000;
  6550. snprintf(extra, MAX_POWER_STRING,
  6551. "Power save level: %d "
  6552. "(Timeout %dms, Period %dms)",
  6553. level, timeout, period);
  6554. }
  6555. }
  6556. wrqu->data.length = strlen(extra) + 1;
  6557. return 0;
  6558. }
  6559. static int ipw2100_wx_set_preamble(struct net_device *dev,
  6560. struct iw_request_info *info,
  6561. union iwreq_data *wrqu, char *extra)
  6562. {
  6563. struct ipw2100_priv *priv = libipw_priv(dev);
  6564. int err, mode = *(int *)extra;
  6565. mutex_lock(&priv->action_mutex);
  6566. if (!(priv->status & STATUS_INITIALIZED)) {
  6567. err = -EIO;
  6568. goto done;
  6569. }
  6570. if (mode == 1)
  6571. priv->config |= CFG_LONG_PREAMBLE;
  6572. else if (mode == 0)
  6573. priv->config &= ~CFG_LONG_PREAMBLE;
  6574. else {
  6575. err = -EINVAL;
  6576. goto done;
  6577. }
  6578. err = ipw2100_system_config(priv, 0);
  6579. done:
  6580. mutex_unlock(&priv->action_mutex);
  6581. return err;
  6582. }
  6583. static int ipw2100_wx_get_preamble(struct net_device *dev,
  6584. struct iw_request_info *info,
  6585. union iwreq_data *wrqu, char *extra)
  6586. {
  6587. /*
  6588. * This can be called at any time. No action lock required
  6589. */
  6590. struct ipw2100_priv *priv = libipw_priv(dev);
  6591. if (priv->config & CFG_LONG_PREAMBLE)
  6592. snprintf(wrqu->name, IFNAMSIZ, "long (1)");
  6593. else
  6594. snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
  6595. return 0;
  6596. }
  6597. #ifdef CONFIG_IPW2100_MONITOR
  6598. static int ipw2100_wx_set_crc_check(struct net_device *dev,
  6599. struct iw_request_info *info,
  6600. union iwreq_data *wrqu, char *extra)
  6601. {
  6602. struct ipw2100_priv *priv = libipw_priv(dev);
  6603. int err, mode = *(int *)extra;
  6604. mutex_lock(&priv->action_mutex);
  6605. if (!(priv->status & STATUS_INITIALIZED)) {
  6606. err = -EIO;
  6607. goto done;
  6608. }
  6609. if (mode == 1)
  6610. priv->config |= CFG_CRC_CHECK;
  6611. else if (mode == 0)
  6612. priv->config &= ~CFG_CRC_CHECK;
  6613. else {
  6614. err = -EINVAL;
  6615. goto done;
  6616. }
  6617. err = 0;
  6618. done:
  6619. mutex_unlock(&priv->action_mutex);
  6620. return err;
  6621. }
  6622. static int ipw2100_wx_get_crc_check(struct net_device *dev,
  6623. struct iw_request_info *info,
  6624. union iwreq_data *wrqu, char *extra)
  6625. {
  6626. /*
  6627. * This can be called at any time. No action lock required
  6628. */
  6629. struct ipw2100_priv *priv = libipw_priv(dev);
  6630. if (priv->config & CFG_CRC_CHECK)
  6631. snprintf(wrqu->name, IFNAMSIZ, "CRC checked (1)");
  6632. else
  6633. snprintf(wrqu->name, IFNAMSIZ, "CRC ignored (0)");
  6634. return 0;
  6635. }
  6636. #endif /* CONFIG_IPW2100_MONITOR */
  6637. static iw_handler ipw2100_wx_handlers[] = {
  6638. IW_HANDLER(SIOCGIWNAME, ipw2100_wx_get_name),
  6639. IW_HANDLER(SIOCSIWFREQ, ipw2100_wx_set_freq),
  6640. IW_HANDLER(SIOCGIWFREQ, ipw2100_wx_get_freq),
  6641. IW_HANDLER(SIOCSIWMODE, ipw2100_wx_set_mode),
  6642. IW_HANDLER(SIOCGIWMODE, ipw2100_wx_get_mode),
  6643. IW_HANDLER(SIOCGIWRANGE, ipw2100_wx_get_range),
  6644. IW_HANDLER(SIOCSIWAP, ipw2100_wx_set_wap),
  6645. IW_HANDLER(SIOCGIWAP, ipw2100_wx_get_wap),
  6646. IW_HANDLER(SIOCSIWMLME, ipw2100_wx_set_mlme),
  6647. IW_HANDLER(SIOCSIWSCAN, ipw2100_wx_set_scan),
  6648. IW_HANDLER(SIOCGIWSCAN, ipw2100_wx_get_scan),
  6649. IW_HANDLER(SIOCSIWESSID, ipw2100_wx_set_essid),
  6650. IW_HANDLER(SIOCGIWESSID, ipw2100_wx_get_essid),
  6651. IW_HANDLER(SIOCSIWNICKN, ipw2100_wx_set_nick),
  6652. IW_HANDLER(SIOCGIWNICKN, ipw2100_wx_get_nick),
  6653. IW_HANDLER(SIOCSIWRATE, ipw2100_wx_set_rate),
  6654. IW_HANDLER(SIOCGIWRATE, ipw2100_wx_get_rate),
  6655. IW_HANDLER(SIOCSIWRTS, ipw2100_wx_set_rts),
  6656. IW_HANDLER(SIOCGIWRTS, ipw2100_wx_get_rts),
  6657. IW_HANDLER(SIOCSIWFRAG, ipw2100_wx_set_frag),
  6658. IW_HANDLER(SIOCGIWFRAG, ipw2100_wx_get_frag),
  6659. IW_HANDLER(SIOCSIWTXPOW, ipw2100_wx_set_txpow),
  6660. IW_HANDLER(SIOCGIWTXPOW, ipw2100_wx_get_txpow),
  6661. IW_HANDLER(SIOCSIWRETRY, ipw2100_wx_set_retry),
  6662. IW_HANDLER(SIOCGIWRETRY, ipw2100_wx_get_retry),
  6663. IW_HANDLER(SIOCSIWENCODE, ipw2100_wx_set_encode),
  6664. IW_HANDLER(SIOCGIWENCODE, ipw2100_wx_get_encode),
  6665. IW_HANDLER(SIOCSIWPOWER, ipw2100_wx_set_power),
  6666. IW_HANDLER(SIOCGIWPOWER, ipw2100_wx_get_power),
  6667. IW_HANDLER(SIOCSIWGENIE, ipw2100_wx_set_genie),
  6668. IW_HANDLER(SIOCGIWGENIE, ipw2100_wx_get_genie),
  6669. IW_HANDLER(SIOCSIWAUTH, ipw2100_wx_set_auth),
  6670. IW_HANDLER(SIOCGIWAUTH, ipw2100_wx_get_auth),
  6671. IW_HANDLER(SIOCSIWENCODEEXT, ipw2100_wx_set_encodeext),
  6672. IW_HANDLER(SIOCGIWENCODEEXT, ipw2100_wx_get_encodeext),
  6673. };
  6674. #define IPW2100_PRIV_SET_MONITOR SIOCIWFIRSTPRIV
  6675. #define IPW2100_PRIV_RESET SIOCIWFIRSTPRIV+1
  6676. #define IPW2100_PRIV_SET_POWER SIOCIWFIRSTPRIV+2
  6677. #define IPW2100_PRIV_GET_POWER SIOCIWFIRSTPRIV+3
  6678. #define IPW2100_PRIV_SET_LONGPREAMBLE SIOCIWFIRSTPRIV+4
  6679. #define IPW2100_PRIV_GET_LONGPREAMBLE SIOCIWFIRSTPRIV+5
  6680. #define IPW2100_PRIV_SET_CRC_CHECK SIOCIWFIRSTPRIV+6
  6681. #define IPW2100_PRIV_GET_CRC_CHECK SIOCIWFIRSTPRIV+7
  6682. static const struct iw_priv_args ipw2100_private_args[] = {
  6683. #ifdef CONFIG_IPW2100_MONITOR
  6684. {
  6685. IPW2100_PRIV_SET_MONITOR,
  6686. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
  6687. {
  6688. IPW2100_PRIV_RESET,
  6689. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
  6690. #endif /* CONFIG_IPW2100_MONITOR */
  6691. {
  6692. IPW2100_PRIV_SET_POWER,
  6693. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_power"},
  6694. {
  6695. IPW2100_PRIV_GET_POWER,
  6696. 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_POWER_STRING,
  6697. "get_power"},
  6698. {
  6699. IPW2100_PRIV_SET_LONGPREAMBLE,
  6700. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_preamble"},
  6701. {
  6702. IPW2100_PRIV_GET_LONGPREAMBLE,
  6703. 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_preamble"},
  6704. #ifdef CONFIG_IPW2100_MONITOR
  6705. {
  6706. IPW2100_PRIV_SET_CRC_CHECK,
  6707. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_crc_check"},
  6708. {
  6709. IPW2100_PRIV_GET_CRC_CHECK,
  6710. 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_crc_check"},
  6711. #endif /* CONFIG_IPW2100_MONITOR */
  6712. };
  6713. static iw_handler ipw2100_private_handler[] = {
  6714. #ifdef CONFIG_IPW2100_MONITOR
  6715. ipw2100_wx_set_promisc,
  6716. ipw2100_wx_reset,
  6717. #else /* CONFIG_IPW2100_MONITOR */
  6718. NULL,
  6719. NULL,
  6720. #endif /* CONFIG_IPW2100_MONITOR */
  6721. ipw2100_wx_set_powermode,
  6722. ipw2100_wx_get_powermode,
  6723. ipw2100_wx_set_preamble,
  6724. ipw2100_wx_get_preamble,
  6725. #ifdef CONFIG_IPW2100_MONITOR
  6726. ipw2100_wx_set_crc_check,
  6727. ipw2100_wx_get_crc_check,
  6728. #else /* CONFIG_IPW2100_MONITOR */
  6729. NULL,
  6730. NULL,
  6731. #endif /* CONFIG_IPW2100_MONITOR */
  6732. };
  6733. /*
  6734. * Get wireless statistics.
  6735. * Called by /proc/net/wireless
  6736. * Also called by SIOCGIWSTATS
  6737. */
  6738. static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device *dev)
  6739. {
  6740. enum {
  6741. POOR = 30,
  6742. FAIR = 60,
  6743. GOOD = 80,
  6744. VERY_GOOD = 90,
  6745. EXCELLENT = 95,
  6746. PERFECT = 100
  6747. };
  6748. int rssi_qual;
  6749. int tx_qual;
  6750. int beacon_qual;
  6751. int quality;
  6752. struct ipw2100_priv *priv = libipw_priv(dev);
  6753. struct iw_statistics *wstats;
  6754. u32 rssi, tx_retries, missed_beacons, tx_failures;
  6755. u32 ord_len = sizeof(u32);
  6756. if (!priv)
  6757. return (struct iw_statistics *)NULL;
  6758. wstats = &priv->wstats;
  6759. /* if hw is disabled, then ipw2100_get_ordinal() can't be called.
  6760. * ipw2100_wx_wireless_stats seems to be called before fw is
  6761. * initialized. STATUS_ASSOCIATED will only be set if the hw is up
  6762. * and associated; if not associcated, the values are all meaningless
  6763. * anyway, so set them all to NULL and INVALID */
  6764. if (!(priv->status & STATUS_ASSOCIATED)) {
  6765. wstats->miss.beacon = 0;
  6766. wstats->discard.retries = 0;
  6767. wstats->qual.qual = 0;
  6768. wstats->qual.level = 0;
  6769. wstats->qual.noise = 0;
  6770. wstats->qual.updated = 7;
  6771. wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
  6772. IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
  6773. return wstats;
  6774. }
  6775. if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_MISSED_BCNS,
  6776. &missed_beacons, &ord_len))
  6777. goto fail_get_ordinal;
  6778. /* If we don't have a connection the quality and level is 0 */
  6779. if (!(priv->status & STATUS_ASSOCIATED)) {
  6780. wstats->qual.qual = 0;
  6781. wstats->qual.level = 0;
  6782. } else {
  6783. if (ipw2100_get_ordinal(priv, IPW_ORD_RSSI_AVG_CURR,
  6784. &rssi, &ord_len))
  6785. goto fail_get_ordinal;
  6786. wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
  6787. if (rssi < 10)
  6788. rssi_qual = rssi * POOR / 10;
  6789. else if (rssi < 15)
  6790. rssi_qual = (rssi - 10) * (FAIR - POOR) / 5 + POOR;
  6791. else if (rssi < 20)
  6792. rssi_qual = (rssi - 15) * (GOOD - FAIR) / 5 + FAIR;
  6793. else if (rssi < 30)
  6794. rssi_qual = (rssi - 20) * (VERY_GOOD - GOOD) /
  6795. 10 + GOOD;
  6796. else
  6797. rssi_qual = (rssi - 30) * (PERFECT - VERY_GOOD) /
  6798. 10 + VERY_GOOD;
  6799. if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_RETRIES,
  6800. &tx_retries, &ord_len))
  6801. goto fail_get_ordinal;
  6802. if (tx_retries > 75)
  6803. tx_qual = (90 - tx_retries) * POOR / 15;
  6804. else if (tx_retries > 70)
  6805. tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
  6806. else if (tx_retries > 65)
  6807. tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
  6808. else if (tx_retries > 50)
  6809. tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
  6810. 15 + GOOD;
  6811. else
  6812. tx_qual = (50 - tx_retries) *
  6813. (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
  6814. if (missed_beacons > 50)
  6815. beacon_qual = (60 - missed_beacons) * POOR / 10;
  6816. else if (missed_beacons > 40)
  6817. beacon_qual = (50 - missed_beacons) * (FAIR - POOR) /
  6818. 10 + POOR;
  6819. else if (missed_beacons > 32)
  6820. beacon_qual = (40 - missed_beacons) * (GOOD - FAIR) /
  6821. 18 + FAIR;
  6822. else if (missed_beacons > 20)
  6823. beacon_qual = (32 - missed_beacons) *
  6824. (VERY_GOOD - GOOD) / 20 + GOOD;
  6825. else
  6826. beacon_qual = (20 - missed_beacons) *
  6827. (PERFECT - VERY_GOOD) / 20 + VERY_GOOD;
  6828. quality = min(tx_qual, rssi_qual);
  6829. quality = min(beacon_qual, quality);
  6830. #ifdef CONFIG_IPW2100_DEBUG
  6831. if (beacon_qual == quality)
  6832. IPW_DEBUG_WX("Quality clamped by Missed Beacons\n");
  6833. else if (tx_qual == quality)
  6834. IPW_DEBUG_WX("Quality clamped by Tx Retries\n");
  6835. else if (quality != 100)
  6836. IPW_DEBUG_WX("Quality clamped by Signal Strength\n");
  6837. else
  6838. IPW_DEBUG_WX("Quality not clamped.\n");
  6839. #endif
  6840. wstats->qual.qual = quality;
  6841. wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
  6842. }
  6843. wstats->qual.noise = 0;
  6844. wstats->qual.updated = 7;
  6845. wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
  6846. /* FIXME: this is percent and not a # */
  6847. wstats->miss.beacon = missed_beacons;
  6848. if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURES,
  6849. &tx_failures, &ord_len))
  6850. goto fail_get_ordinal;
  6851. wstats->discard.retries = tx_failures;
  6852. return wstats;
  6853. fail_get_ordinal:
  6854. IPW_DEBUG_WX("failed querying ordinals.\n");
  6855. return (struct iw_statistics *)NULL;
  6856. }
  6857. static struct iw_handler_def ipw2100_wx_handler_def = {
  6858. .standard = ipw2100_wx_handlers,
  6859. .num_standard = ARRAY_SIZE(ipw2100_wx_handlers),
  6860. .num_private = ARRAY_SIZE(ipw2100_private_handler),
  6861. .num_private_args = ARRAY_SIZE(ipw2100_private_args),
  6862. .private = (iw_handler *) ipw2100_private_handler,
  6863. .private_args = (struct iw_priv_args *)ipw2100_private_args,
  6864. .get_wireless_stats = ipw2100_wx_wireless_stats,
  6865. };
  6866. static void ipw2100_wx_event_work(struct work_struct *work)
  6867. {
  6868. struct ipw2100_priv *priv =
  6869. container_of(work, struct ipw2100_priv, wx_event_work.work);
  6870. union iwreq_data wrqu;
  6871. unsigned int len = ETH_ALEN;
  6872. if (priv->status & STATUS_STOPPING)
  6873. return;
  6874. mutex_lock(&priv->action_mutex);
  6875. IPW_DEBUG_WX("enter\n");
  6876. mutex_unlock(&priv->action_mutex);
  6877. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  6878. /* Fetch BSSID from the hardware */
  6879. if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) ||
  6880. priv->status & STATUS_RF_KILL_MASK ||
  6881. ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
  6882. &priv->bssid, &len)) {
  6883. memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
  6884. } else {
  6885. /* We now have the BSSID, so can finish setting to the full
  6886. * associated state */
  6887. memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
  6888. memcpy(priv->ieee->bssid, priv->bssid, ETH_ALEN);
  6889. priv->status &= ~STATUS_ASSOCIATING;
  6890. priv->status |= STATUS_ASSOCIATED;
  6891. netif_carrier_on(priv->net_dev);
  6892. netif_wake_queue(priv->net_dev);
  6893. }
  6894. if (!(priv->status & STATUS_ASSOCIATED)) {
  6895. IPW_DEBUG_WX("Configuring ESSID\n");
  6896. mutex_lock(&priv->action_mutex);
  6897. /* This is a disassociation event, so kick the firmware to
  6898. * look for another AP */
  6899. if (priv->config & CFG_STATIC_ESSID)
  6900. ipw2100_set_essid(priv, priv->essid, priv->essid_len,
  6901. 0);
  6902. else
  6903. ipw2100_set_essid(priv, NULL, 0, 0);
  6904. mutex_unlock(&priv->action_mutex);
  6905. }
  6906. wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
  6907. }
  6908. #define IPW2100_FW_MAJOR_VERSION 1
  6909. #define IPW2100_FW_MINOR_VERSION 3
  6910. #define IPW2100_FW_MINOR(x) ((x & 0xff) >> 8)
  6911. #define IPW2100_FW_MAJOR(x) (x & 0xff)
  6912. #define IPW2100_FW_VERSION ((IPW2100_FW_MINOR_VERSION << 8) | \
  6913. IPW2100_FW_MAJOR_VERSION)
  6914. #define IPW2100_FW_PREFIX "ipw2100-" __stringify(IPW2100_FW_MAJOR_VERSION) \
  6915. "." __stringify(IPW2100_FW_MINOR_VERSION)
  6916. #define IPW2100_FW_NAME(x) IPW2100_FW_PREFIX "" x ".fw"
  6917. /*
  6918. BINARY FIRMWARE HEADER FORMAT
  6919. offset length desc
  6920. 0 2 version
  6921. 2 2 mode == 0:BSS,1:IBSS,2:MONITOR
  6922. 4 4 fw_len
  6923. 8 4 uc_len
  6924. C fw_len firmware data
  6925. 12 + fw_len uc_len microcode data
  6926. */
  6927. struct ipw2100_fw_header {
  6928. short version;
  6929. short mode;
  6930. unsigned int fw_size;
  6931. unsigned int uc_size;
  6932. } __packed;
  6933. static int ipw2100_mod_firmware_load(struct ipw2100_fw *fw)
  6934. {
  6935. struct ipw2100_fw_header *h =
  6936. (struct ipw2100_fw_header *)fw->fw_entry->data;
  6937. if (IPW2100_FW_MAJOR(h->version) != IPW2100_FW_MAJOR_VERSION) {
  6938. printk(KERN_WARNING DRV_NAME ": Firmware image not compatible "
  6939. "(detected version id of %u). "
  6940. "See Documentation/networking/README.ipw2100\n",
  6941. h->version);
  6942. return 1;
  6943. }
  6944. fw->version = h->version;
  6945. fw->fw.data = fw->fw_entry->data + sizeof(struct ipw2100_fw_header);
  6946. fw->fw.size = h->fw_size;
  6947. fw->uc.data = fw->fw.data + h->fw_size;
  6948. fw->uc.size = h->uc_size;
  6949. return 0;
  6950. }
  6951. static int ipw2100_get_firmware(struct ipw2100_priv *priv,
  6952. struct ipw2100_fw *fw)
  6953. {
  6954. char *fw_name;
  6955. int rc;
  6956. IPW_DEBUG_INFO("%s: Using hotplug firmware load.\n",
  6957. priv->net_dev->name);
  6958. switch (priv->ieee->iw_mode) {
  6959. case IW_MODE_ADHOC:
  6960. fw_name = IPW2100_FW_NAME("-i");
  6961. break;
  6962. #ifdef CONFIG_IPW2100_MONITOR
  6963. case IW_MODE_MONITOR:
  6964. fw_name = IPW2100_FW_NAME("-p");
  6965. break;
  6966. #endif
  6967. case IW_MODE_INFRA:
  6968. default:
  6969. fw_name = IPW2100_FW_NAME("");
  6970. break;
  6971. }
  6972. rc = request_firmware(&fw->fw_entry, fw_name, &priv->pci_dev->dev);
  6973. if (rc < 0) {
  6974. printk(KERN_ERR DRV_NAME ": "
  6975. "%s: Firmware '%s' not available or load failed.\n",
  6976. priv->net_dev->name, fw_name);
  6977. return rc;
  6978. }
  6979. IPW_DEBUG_INFO("firmware data %p size %zd\n", fw->fw_entry->data,
  6980. fw->fw_entry->size);
  6981. ipw2100_mod_firmware_load(fw);
  6982. return 0;
  6983. }
  6984. MODULE_FIRMWARE(IPW2100_FW_NAME("-i"));
  6985. #ifdef CONFIG_IPW2100_MONITOR
  6986. MODULE_FIRMWARE(IPW2100_FW_NAME("-p"));
  6987. #endif
  6988. MODULE_FIRMWARE(IPW2100_FW_NAME(""));
  6989. static void ipw2100_release_firmware(struct ipw2100_priv *priv,
  6990. struct ipw2100_fw *fw)
  6991. {
  6992. fw->version = 0;
  6993. if (fw->fw_entry)
  6994. release_firmware(fw->fw_entry);
  6995. fw->fw_entry = NULL;
  6996. }
  6997. static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf,
  6998. size_t max)
  6999. {
  7000. char ver[MAX_FW_VERSION_LEN];
  7001. u32 len = MAX_FW_VERSION_LEN;
  7002. u32 tmp;
  7003. int i;
  7004. /* firmware version is an ascii string (max len of 14) */
  7005. if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_FW_VER_NUM, ver, &len))
  7006. return -EIO;
  7007. tmp = max;
  7008. if (len >= max)
  7009. len = max - 1;
  7010. for (i = 0; i < len; i++)
  7011. buf[i] = ver[i];
  7012. buf[i] = '\0';
  7013. return tmp;
  7014. }
  7015. static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf,
  7016. size_t max)
  7017. {
  7018. u32 ver;
  7019. u32 len = sizeof(ver);
  7020. /* microcode version is a 32 bit integer */
  7021. if (ipw2100_get_ordinal(priv, IPW_ORD_UCODE_VERSION, &ver, &len))
  7022. return -EIO;
  7023. return snprintf(buf, max, "%08X", ver);
  7024. }
  7025. /*
  7026. * On exit, the firmware will have been freed from the fw list
  7027. */
  7028. static int ipw2100_fw_download(struct ipw2100_priv *priv, struct ipw2100_fw *fw)
  7029. {
  7030. /* firmware is constructed of N contiguous entries, each entry is
  7031. * structured as:
  7032. *
  7033. * offset sie desc
  7034. * 0 4 address to write to
  7035. * 4 2 length of data run
  7036. * 6 length data
  7037. */
  7038. unsigned int addr;
  7039. unsigned short len;
  7040. const unsigned char *firmware_data = fw->fw.data;
  7041. unsigned int firmware_data_left = fw->fw.size;
  7042. while (firmware_data_left > 0) {
  7043. addr = *(u32 *) (firmware_data);
  7044. firmware_data += 4;
  7045. firmware_data_left -= 4;
  7046. len = *(u16 *) (firmware_data);
  7047. firmware_data += 2;
  7048. firmware_data_left -= 2;
  7049. if (len > 32) {
  7050. printk(KERN_ERR DRV_NAME ": "
  7051. "Invalid firmware run-length of %d bytes\n",
  7052. len);
  7053. return -EINVAL;
  7054. }
  7055. write_nic_memory(priv->net_dev, addr, len, firmware_data);
  7056. firmware_data += len;
  7057. firmware_data_left -= len;
  7058. }
  7059. return 0;
  7060. }
  7061. struct symbol_alive_response {
  7062. u8 cmd_id;
  7063. u8 seq_num;
  7064. u8 ucode_rev;
  7065. u8 eeprom_valid;
  7066. u16 valid_flags;
  7067. u8 IEEE_addr[6];
  7068. u16 flags;
  7069. u16 pcb_rev;
  7070. u16 clock_settle_time; // 1us LSB
  7071. u16 powerup_settle_time; // 1us LSB
  7072. u16 hop_settle_time; // 1us LSB
  7073. u8 date[3]; // month, day, year
  7074. u8 time[2]; // hours, minutes
  7075. u8 ucode_valid;
  7076. };
  7077. static int ipw2100_ucode_download(struct ipw2100_priv *priv,
  7078. struct ipw2100_fw *fw)
  7079. {
  7080. struct net_device *dev = priv->net_dev;
  7081. const unsigned char *microcode_data = fw->uc.data;
  7082. unsigned int microcode_data_left = fw->uc.size;
  7083. void __iomem *reg = (void __iomem *)dev->base_addr;
  7084. struct symbol_alive_response response;
  7085. int i, j;
  7086. u8 data;
  7087. /* Symbol control */
  7088. write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
  7089. readl(reg);
  7090. write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
  7091. readl(reg);
  7092. /* HW config */
  7093. write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
  7094. readl(reg);
  7095. write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
  7096. readl(reg);
  7097. /* EN_CS_ACCESS bit to reset control store pointer */
  7098. write_nic_byte(dev, 0x210000, 0x40);
  7099. readl(reg);
  7100. write_nic_byte(dev, 0x210000, 0x0);
  7101. readl(reg);
  7102. write_nic_byte(dev, 0x210000, 0x40);
  7103. readl(reg);
  7104. /* copy microcode from buffer into Symbol */
  7105. while (microcode_data_left > 0) {
  7106. write_nic_byte(dev, 0x210010, *microcode_data++);
  7107. write_nic_byte(dev, 0x210010, *microcode_data++);
  7108. microcode_data_left -= 2;
  7109. }
  7110. /* EN_CS_ACCESS bit to reset the control store pointer */
  7111. write_nic_byte(dev, 0x210000, 0x0);
  7112. readl(reg);
  7113. /* Enable System (Reg 0)
  7114. * first enable causes garbage in RX FIFO */
  7115. write_nic_byte(dev, 0x210000, 0x0);
  7116. readl(reg);
  7117. write_nic_byte(dev, 0x210000, 0x80);
  7118. readl(reg);
  7119. /* Reset External Baseband Reg */
  7120. write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
  7121. readl(reg);
  7122. write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
  7123. readl(reg);
  7124. /* HW Config (Reg 5) */
  7125. write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
  7126. readl(reg);
  7127. write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
  7128. readl(reg);
  7129. /* Enable System (Reg 0)
  7130. * second enable should be OK */
  7131. write_nic_byte(dev, 0x210000, 0x00); // clear enable system
  7132. readl(reg);
  7133. write_nic_byte(dev, 0x210000, 0x80); // set enable system
  7134. /* check Symbol is enabled - upped this from 5 as it wasn't always
  7135. * catching the update */
  7136. for (i = 0; i < 10; i++) {
  7137. udelay(10);
  7138. /* check Dino is enabled bit */
  7139. read_nic_byte(dev, 0x210000, &data);
  7140. if (data & 0x1)
  7141. break;
  7142. }
  7143. if (i == 10) {
  7144. printk(KERN_ERR DRV_NAME ": %s: Error initializing Symbol\n",
  7145. dev->name);
  7146. return -EIO;
  7147. }
  7148. /* Get Symbol alive response */
  7149. for (i = 0; i < 30; i++) {
  7150. /* Read alive response structure */
  7151. for (j = 0;
  7152. j < (sizeof(struct symbol_alive_response) >> 1); j++)
  7153. read_nic_word(dev, 0x210004, ((u16 *) & response) + j);
  7154. if ((response.cmd_id == 1) && (response.ucode_valid == 0x1))
  7155. break;
  7156. udelay(10);
  7157. }
  7158. if (i == 30) {
  7159. printk(KERN_ERR DRV_NAME
  7160. ": %s: No response from Symbol - hw not alive\n",
  7161. dev->name);
  7162. printk_buf(IPW_DL_ERROR, (u8 *) & response, sizeof(response));
  7163. return -EIO;
  7164. }
  7165. return 0;
  7166. }