ipw2100.c 225 KB

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