ipw2200.c 303 KB

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