ipw2100.c 223 KB

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