iwl3945-base.c 249 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2007 Intel Corporation. All rights reserved.
  4. *
  5. * Portions of this file are derived from the ipw3945 project, as well
  6. * as portions of the ieee80211 subsystem header files.
  7. *
  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. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  20. *
  21. * The full GNU General Public License is included in this distribution in the
  22. * file called LICENSE.
  23. *
  24. * Contact Information:
  25. * James P. Ketrenos <ipw2100-admin@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/version.h>
  32. #include <linux/init.h>
  33. #include <linux/pci.h>
  34. #include <linux/dma-mapping.h>
  35. #include <linux/delay.h>
  36. #include <linux/skbuff.h>
  37. #include <linux/netdevice.h>
  38. #include <linux/wireless.h>
  39. #include <linux/firmware.h>
  40. #include <linux/etherdevice.h>
  41. #include <linux/if_arp.h>
  42. #include <net/ieee80211_radiotap.h>
  43. #include <net/mac80211.h>
  44. #include <asm/div64.h>
  45. #include "iwl-3945.h"
  46. #include "iwl-helpers.h"
  47. #ifdef CONFIG_IWL3945_DEBUG
  48. u32 iwl3945_debug_level;
  49. #endif
  50. static int iwl3945_tx_queue_update_write_ptr(struct iwl3945_priv *priv,
  51. struct iwl3945_tx_queue *txq);
  52. /******************************************************************************
  53. *
  54. * module boiler plate
  55. *
  56. ******************************************************************************/
  57. /* module parameters */
  58. static int iwl3945_param_disable_hw_scan; /* def: 0 = use 3945's h/w scan */
  59. static int iwl3945_param_debug; /* def: 0 = minimal debug log messages */
  60. static int iwl3945_param_disable; /* def: 0 = enable radio */
  61. static int iwl3945_param_antenna; /* def: 0 = both antennas (use diversity) */
  62. int iwl3945_param_hwcrypto; /* def: 0 = use software encryption */
  63. static int iwl3945_param_qos_enable = 1; /* def: 1 = use quality of service */
  64. int iwl3945_param_queues_num = IWL_MAX_NUM_QUEUES; /* def: 8 Tx queues */
  65. /*
  66. * module name, copyright, version, etc.
  67. * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
  68. */
  69. #define DRV_DESCRIPTION \
  70. "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
  71. #ifdef CONFIG_IWL3945_DEBUG
  72. #define VD "d"
  73. #else
  74. #define VD
  75. #endif
  76. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  77. #define VS "s"
  78. #else
  79. #define VS
  80. #endif
  81. #define IWLWIFI_VERSION "1.1.19k" VD VS
  82. #define DRV_COPYRIGHT "Copyright(c) 2003-2007 Intel Corporation"
  83. #define DRV_VERSION IWLWIFI_VERSION
  84. /* Change firmware file name, using "-" and incrementing number,
  85. * *only* when uCode interface or architecture changes so that it
  86. * is not compatible with earlier drivers.
  87. * This number will also appear in << 8 position of 1st dword of uCode file */
  88. #define IWL3945_UCODE_API "-1"
  89. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  90. MODULE_VERSION(DRV_VERSION);
  91. MODULE_AUTHOR(DRV_COPYRIGHT);
  92. MODULE_LICENSE("GPL");
  93. static __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr)
  94. {
  95. u16 fc = le16_to_cpu(hdr->frame_control);
  96. int hdr_len = ieee80211_get_hdrlen(fc);
  97. if ((fc & 0x00cc) == (IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA))
  98. return (__le16 *) ((u8 *) hdr + hdr_len - QOS_CONTROL_LEN);
  99. return NULL;
  100. }
  101. static const struct ieee80211_hw_mode *iwl3945_get_hw_mode(
  102. struct iwl3945_priv *priv, int mode)
  103. {
  104. int i;
  105. for (i = 0; i < 3; i++)
  106. if (priv->modes[i].mode == mode)
  107. return &priv->modes[i];
  108. return NULL;
  109. }
  110. static int iwl3945_is_empty_essid(const char *essid, int essid_len)
  111. {
  112. /* Single white space is for Linksys APs */
  113. if (essid_len == 1 && essid[0] == ' ')
  114. return 1;
  115. /* Otherwise, if the entire essid is 0, we assume it is hidden */
  116. while (essid_len) {
  117. essid_len--;
  118. if (essid[essid_len] != '\0')
  119. return 0;
  120. }
  121. return 1;
  122. }
  123. static const char *iwl3945_escape_essid(const char *essid, u8 essid_len)
  124. {
  125. static char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
  126. const char *s = essid;
  127. char *d = escaped;
  128. if (iwl3945_is_empty_essid(essid, essid_len)) {
  129. memcpy(escaped, "<hidden>", sizeof("<hidden>"));
  130. return escaped;
  131. }
  132. essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE);
  133. while (essid_len--) {
  134. if (*s == '\0') {
  135. *d++ = '\\';
  136. *d++ = '0';
  137. s++;
  138. } else
  139. *d++ = *s++;
  140. }
  141. *d = '\0';
  142. return escaped;
  143. }
  144. static void iwl3945_print_hex_dump(int level, void *p, u32 len)
  145. {
  146. #ifdef CONFIG_IWL3945_DEBUG
  147. if (!(iwl3945_debug_level & level))
  148. return;
  149. print_hex_dump(KERN_DEBUG, "iwl data: ", DUMP_PREFIX_OFFSET, 16, 1,
  150. p, len, 1);
  151. #endif
  152. }
  153. /*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
  154. * DMA services
  155. *
  156. * Theory of operation
  157. *
  158. * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
  159. * of buffer descriptors, each of which points to one or more data buffers for
  160. * the device to read from or fill. Driver and device exchange status of each
  161. * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
  162. * entries in each circular buffer, to protect against confusing empty and full
  163. * queue states.
  164. *
  165. * The device reads or writes the data in the queues via the device's several
  166. * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
  167. *
  168. * For Tx queue, there are low mark and high mark limits. If, after queuing
  169. * the packet for Tx, free space become < low mark, Tx queue stopped. When
  170. * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
  171. * Tx queue resumed.
  172. *
  173. * The 3945 operates with six queues: One receive queue, one transmit queue
  174. * (#4) for sending commands to the device firmware, and four transmit queues
  175. * (#0-3) for data tx via EDCA. An additional 2 HCCA queues are unused.
  176. ***************************************************/
  177. static int iwl3945_queue_space(const struct iwl3945_queue *q)
  178. {
  179. int s = q->read_ptr - q->write_ptr;
  180. if (q->read_ptr > q->write_ptr)
  181. s -= q->n_bd;
  182. if (s <= 0)
  183. s += q->n_window;
  184. /* keep some reserve to not confuse empty and full situations */
  185. s -= 2;
  186. if (s < 0)
  187. s = 0;
  188. return s;
  189. }
  190. /**
  191. * iwl3945_queue_inc_wrap - increment queue index, wrap back to beginning
  192. * @index -- current index
  193. * @n_bd -- total number of entries in queue (must be power of 2)
  194. */
  195. static inline int iwl3945_queue_inc_wrap(int index, int n_bd)
  196. {
  197. return ++index & (n_bd - 1);
  198. }
  199. /**
  200. * iwl3945_queue_dec_wrap - increment queue index, wrap back to end
  201. * @index -- current index
  202. * @n_bd -- total number of entries in queue (must be power of 2)
  203. */
  204. static inline int iwl3945_queue_dec_wrap(int index, int n_bd)
  205. {
  206. return --index & (n_bd - 1);
  207. }
  208. static inline int x2_queue_used(const struct iwl3945_queue *q, int i)
  209. {
  210. return q->write_ptr > q->read_ptr ?
  211. (i >= q->read_ptr && i < q->write_ptr) :
  212. !(i < q->read_ptr && i >= q->write_ptr);
  213. }
  214. static inline u8 get_cmd_index(struct iwl3945_queue *q, u32 index, int is_huge)
  215. {
  216. /* This is for scan command, the big buffer at end of command array */
  217. if (is_huge)
  218. return q->n_window; /* must be power of 2 */
  219. /* Otherwise, use normal size buffers */
  220. return index & (q->n_window - 1);
  221. }
  222. /**
  223. * iwl3945_queue_init - Initialize queue's high/low-water and read/write indexes
  224. */
  225. static int iwl3945_queue_init(struct iwl3945_priv *priv, struct iwl3945_queue *q,
  226. int count, int slots_num, u32 id)
  227. {
  228. q->n_bd = count;
  229. q->n_window = slots_num;
  230. q->id = id;
  231. /* count must be power-of-two size, otherwise iwl3945_queue_inc_wrap
  232. * and iwl3945_queue_dec_wrap are broken. */
  233. BUG_ON(!is_power_of_2(count));
  234. /* slots_num must be power-of-two size, otherwise
  235. * get_cmd_index is broken. */
  236. BUG_ON(!is_power_of_2(slots_num));
  237. q->low_mark = q->n_window / 4;
  238. if (q->low_mark < 4)
  239. q->low_mark = 4;
  240. q->high_mark = q->n_window / 8;
  241. if (q->high_mark < 2)
  242. q->high_mark = 2;
  243. q->write_ptr = q->read_ptr = 0;
  244. return 0;
  245. }
  246. /**
  247. * iwl3945_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
  248. */
  249. static int iwl3945_tx_queue_alloc(struct iwl3945_priv *priv,
  250. struct iwl3945_tx_queue *txq, u32 id)
  251. {
  252. struct pci_dev *dev = priv->pci_dev;
  253. /* Driver private data, only for Tx (not command) queues,
  254. * not shared with device. */
  255. if (id != IWL_CMD_QUEUE_NUM) {
  256. txq->txb = kmalloc(sizeof(txq->txb[0]) *
  257. TFD_QUEUE_SIZE_MAX, GFP_KERNEL);
  258. if (!txq->txb) {
  259. IWL_ERROR("kmalloc for auxiliary BD "
  260. "structures failed\n");
  261. goto error;
  262. }
  263. } else
  264. txq->txb = NULL;
  265. /* Circular buffer of transmit frame descriptors (TFDs),
  266. * shared with device */
  267. txq->bd = pci_alloc_consistent(dev,
  268. sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX,
  269. &txq->q.dma_addr);
  270. if (!txq->bd) {
  271. IWL_ERROR("pci_alloc_consistent(%zd) failed\n",
  272. sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX);
  273. goto error;
  274. }
  275. txq->q.id = id;
  276. return 0;
  277. error:
  278. if (txq->txb) {
  279. kfree(txq->txb);
  280. txq->txb = NULL;
  281. }
  282. return -ENOMEM;
  283. }
  284. /**
  285. * iwl3945_tx_queue_init - Allocate and initialize one tx/cmd queue
  286. */
  287. int iwl3945_tx_queue_init(struct iwl3945_priv *priv,
  288. struct iwl3945_tx_queue *txq, int slots_num, u32 txq_id)
  289. {
  290. struct pci_dev *dev = priv->pci_dev;
  291. int len;
  292. int rc = 0;
  293. /*
  294. * Alloc buffer array for commands (Tx or other types of commands).
  295. * For the command queue (#4), allocate command space + one big
  296. * command for scan, since scan command is very huge; the system will
  297. * not have two scans at the same time, so only one is needed.
  298. * For data Tx queues (all other queues), no super-size command
  299. * space is needed.
  300. */
  301. len = sizeof(struct iwl3945_cmd) * slots_num;
  302. if (txq_id == IWL_CMD_QUEUE_NUM)
  303. len += IWL_MAX_SCAN_SIZE;
  304. txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd);
  305. if (!txq->cmd)
  306. return -ENOMEM;
  307. /* Alloc driver data array and TFD circular buffer */
  308. rc = iwl3945_tx_queue_alloc(priv, txq, txq_id);
  309. if (rc) {
  310. pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
  311. return -ENOMEM;
  312. }
  313. txq->need_update = 0;
  314. /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
  315. * iwl3945_queue_inc_wrap and iwl3945_queue_dec_wrap are broken. */
  316. BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1));
  317. /* Initialize queue high/low-water, head/tail indexes */
  318. iwl3945_queue_init(priv, &txq->q, TFD_QUEUE_SIZE_MAX, slots_num, txq_id);
  319. /* Tell device where to find queue, enable DMA channel. */
  320. iwl3945_hw_tx_queue_init(priv, txq);
  321. return 0;
  322. }
  323. /**
  324. * iwl3945_tx_queue_free - Deallocate DMA queue.
  325. * @txq: Transmit queue to deallocate.
  326. *
  327. * Empty queue by removing and destroying all BD's.
  328. * Free all buffers.
  329. * 0-fill, but do not free "txq" descriptor structure.
  330. */
  331. void iwl3945_tx_queue_free(struct iwl3945_priv *priv, struct iwl3945_tx_queue *txq)
  332. {
  333. struct iwl3945_queue *q = &txq->q;
  334. struct pci_dev *dev = priv->pci_dev;
  335. int len;
  336. if (q->n_bd == 0)
  337. return;
  338. /* first, empty all BD's */
  339. for (; q->write_ptr != q->read_ptr;
  340. q->read_ptr = iwl3945_queue_inc_wrap(q->read_ptr, q->n_bd))
  341. iwl3945_hw_txq_free_tfd(priv, txq);
  342. len = sizeof(struct iwl3945_cmd) * q->n_window;
  343. if (q->id == IWL_CMD_QUEUE_NUM)
  344. len += IWL_MAX_SCAN_SIZE;
  345. /* De-alloc array of command/tx buffers */
  346. pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd);
  347. /* De-alloc circular buffer of TFDs */
  348. if (txq->q.n_bd)
  349. pci_free_consistent(dev, sizeof(struct iwl3945_tfd_frame) *
  350. txq->q.n_bd, txq->bd, txq->q.dma_addr);
  351. /* De-alloc array of per-TFD driver data */
  352. if (txq->txb) {
  353. kfree(txq->txb);
  354. txq->txb = NULL;
  355. }
  356. /* 0-fill queue descriptor structure */
  357. memset(txq, 0, sizeof(*txq));
  358. }
  359. const u8 iwl3945_broadcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  360. /*************** STATION TABLE MANAGEMENT ****
  361. * mac80211 should be examined to determine if sta_info is duplicating
  362. * the functionality provided here
  363. */
  364. /**************************************************************/
  365. #if 0 /* temporary disable till we add real remove station */
  366. /**
  367. * iwl3945_remove_station - Remove driver's knowledge of station.
  368. *
  369. * NOTE: This does not remove station from device's station table.
  370. */
  371. static u8 iwl3945_remove_station(struct iwl3945_priv *priv, const u8 *addr, int is_ap)
  372. {
  373. int index = IWL_INVALID_STATION;
  374. int i;
  375. unsigned long flags;
  376. spin_lock_irqsave(&priv->sta_lock, flags);
  377. if (is_ap)
  378. index = IWL_AP_ID;
  379. else if (is_broadcast_ether_addr(addr))
  380. index = priv->hw_setting.bcast_sta_id;
  381. else
  382. for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++)
  383. if (priv->stations[i].used &&
  384. !compare_ether_addr(priv->stations[i].sta.sta.addr,
  385. addr)) {
  386. index = i;
  387. break;
  388. }
  389. if (unlikely(index == IWL_INVALID_STATION))
  390. goto out;
  391. if (priv->stations[index].used) {
  392. priv->stations[index].used = 0;
  393. priv->num_stations--;
  394. }
  395. BUG_ON(priv->num_stations < 0);
  396. out:
  397. spin_unlock_irqrestore(&priv->sta_lock, flags);
  398. return 0;
  399. }
  400. #endif
  401. /**
  402. * iwl3945_clear_stations_table - Clear the driver's station table
  403. *
  404. * NOTE: This does not clear or otherwise alter the device's station table.
  405. */
  406. static void iwl3945_clear_stations_table(struct iwl3945_priv *priv)
  407. {
  408. unsigned long flags;
  409. spin_lock_irqsave(&priv->sta_lock, flags);
  410. priv->num_stations = 0;
  411. memset(priv->stations, 0, sizeof(priv->stations));
  412. spin_unlock_irqrestore(&priv->sta_lock, flags);
  413. }
  414. /**
  415. * iwl3945_add_station - Add station to station tables in driver and device
  416. */
  417. u8 iwl3945_add_station(struct iwl3945_priv *priv, const u8 *addr, int is_ap, u8 flags)
  418. {
  419. int i;
  420. int index = IWL_INVALID_STATION;
  421. struct iwl3945_station_entry *station;
  422. unsigned long flags_spin;
  423. DECLARE_MAC_BUF(mac);
  424. u8 rate;
  425. spin_lock_irqsave(&priv->sta_lock, flags_spin);
  426. if (is_ap)
  427. index = IWL_AP_ID;
  428. else if (is_broadcast_ether_addr(addr))
  429. index = priv->hw_setting.bcast_sta_id;
  430. else
  431. for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) {
  432. if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
  433. addr)) {
  434. index = i;
  435. break;
  436. }
  437. if (!priv->stations[i].used &&
  438. index == IWL_INVALID_STATION)
  439. index = i;
  440. }
  441. /* These two conditions has the same outcome but keep them separate
  442. since they have different meaning */
  443. if (unlikely(index == IWL_INVALID_STATION)) {
  444. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  445. return index;
  446. }
  447. if (priv->stations[index].used &&
  448. !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) {
  449. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  450. return index;
  451. }
  452. IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index, print_mac(mac, addr));
  453. station = &priv->stations[index];
  454. station->used = 1;
  455. priv->num_stations++;
  456. /* Set up the REPLY_ADD_STA command to send to device */
  457. memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd));
  458. memcpy(station->sta.sta.addr, addr, ETH_ALEN);
  459. station->sta.mode = 0;
  460. station->sta.sta.sta_id = index;
  461. station->sta.station_flags = 0;
  462. if (priv->phymode == MODE_IEEE80211A)
  463. rate = IWL_RATE_6M_PLCP;
  464. else
  465. rate = IWL_RATE_1M_PLCP;
  466. /* Turn on both antennas for the station... */
  467. station->sta.rate_n_flags =
  468. iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK);
  469. station->current_rate.rate_n_flags =
  470. le16_to_cpu(station->sta.rate_n_flags);
  471. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  472. /* Add station to device's station table */
  473. iwl3945_send_add_station(priv, &station->sta, flags);
  474. return index;
  475. }
  476. /*************** DRIVER STATUS FUNCTIONS *****/
  477. static inline int iwl3945_is_ready(struct iwl3945_priv *priv)
  478. {
  479. /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are
  480. * set but EXIT_PENDING is not */
  481. return test_bit(STATUS_READY, &priv->status) &&
  482. test_bit(STATUS_GEO_CONFIGURED, &priv->status) &&
  483. !test_bit(STATUS_EXIT_PENDING, &priv->status);
  484. }
  485. static inline int iwl3945_is_alive(struct iwl3945_priv *priv)
  486. {
  487. return test_bit(STATUS_ALIVE, &priv->status);
  488. }
  489. static inline int iwl3945_is_init(struct iwl3945_priv *priv)
  490. {
  491. return test_bit(STATUS_INIT, &priv->status);
  492. }
  493. static inline int iwl3945_is_rfkill(struct iwl3945_priv *priv)
  494. {
  495. return test_bit(STATUS_RF_KILL_HW, &priv->status) ||
  496. test_bit(STATUS_RF_KILL_SW, &priv->status);
  497. }
  498. static inline int iwl3945_is_ready_rf(struct iwl3945_priv *priv)
  499. {
  500. if (iwl3945_is_rfkill(priv))
  501. return 0;
  502. return iwl3945_is_ready(priv);
  503. }
  504. /*************** HOST COMMAND QUEUE FUNCTIONS *****/
  505. #define IWL_CMD(x) case x : return #x
  506. static const char *get_cmd_string(u8 cmd)
  507. {
  508. switch (cmd) {
  509. IWL_CMD(REPLY_ALIVE);
  510. IWL_CMD(REPLY_ERROR);
  511. IWL_CMD(REPLY_RXON);
  512. IWL_CMD(REPLY_RXON_ASSOC);
  513. IWL_CMD(REPLY_QOS_PARAM);
  514. IWL_CMD(REPLY_RXON_TIMING);
  515. IWL_CMD(REPLY_ADD_STA);
  516. IWL_CMD(REPLY_REMOVE_STA);
  517. IWL_CMD(REPLY_REMOVE_ALL_STA);
  518. IWL_CMD(REPLY_3945_RX);
  519. IWL_CMD(REPLY_TX);
  520. IWL_CMD(REPLY_RATE_SCALE);
  521. IWL_CMD(REPLY_LEDS_CMD);
  522. IWL_CMD(REPLY_TX_LINK_QUALITY_CMD);
  523. IWL_CMD(RADAR_NOTIFICATION);
  524. IWL_CMD(REPLY_QUIET_CMD);
  525. IWL_CMD(REPLY_CHANNEL_SWITCH);
  526. IWL_CMD(CHANNEL_SWITCH_NOTIFICATION);
  527. IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD);
  528. IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION);
  529. IWL_CMD(POWER_TABLE_CMD);
  530. IWL_CMD(PM_SLEEP_NOTIFICATION);
  531. IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC);
  532. IWL_CMD(REPLY_SCAN_CMD);
  533. IWL_CMD(REPLY_SCAN_ABORT_CMD);
  534. IWL_CMD(SCAN_START_NOTIFICATION);
  535. IWL_CMD(SCAN_RESULTS_NOTIFICATION);
  536. IWL_CMD(SCAN_COMPLETE_NOTIFICATION);
  537. IWL_CMD(BEACON_NOTIFICATION);
  538. IWL_CMD(REPLY_TX_BEACON);
  539. IWL_CMD(WHO_IS_AWAKE_NOTIFICATION);
  540. IWL_CMD(QUIET_NOTIFICATION);
  541. IWL_CMD(REPLY_TX_PWR_TABLE_CMD);
  542. IWL_CMD(MEASURE_ABORT_NOTIFICATION);
  543. IWL_CMD(REPLY_BT_CONFIG);
  544. IWL_CMD(REPLY_STATISTICS_CMD);
  545. IWL_CMD(STATISTICS_NOTIFICATION);
  546. IWL_CMD(REPLY_CARD_STATE_CMD);
  547. IWL_CMD(CARD_STATE_NOTIFICATION);
  548. IWL_CMD(MISSED_BEACONS_NOTIFICATION);
  549. default:
  550. return "UNKNOWN";
  551. }
  552. }
  553. #define HOST_COMPLETE_TIMEOUT (HZ / 2)
  554. /**
  555. * iwl3945_enqueue_hcmd - enqueue a uCode command
  556. * @priv: device private data point
  557. * @cmd: a point to the ucode command structure
  558. *
  559. * The function returns < 0 values to indicate the operation is
  560. * failed. On success, it turns the index (> 0) of command in the
  561. * command queue.
  562. */
  563. static int iwl3945_enqueue_hcmd(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd)
  564. {
  565. struct iwl3945_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM];
  566. struct iwl3945_queue *q = &txq->q;
  567. struct iwl3945_tfd_frame *tfd;
  568. u32 *control_flags;
  569. struct iwl3945_cmd *out_cmd;
  570. u32 idx;
  571. u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
  572. dma_addr_t phys_addr;
  573. int pad;
  574. u16 count;
  575. int ret;
  576. unsigned long flags;
  577. /* If any of the command structures end up being larger than
  578. * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
  579. * we will need to increase the size of the TFD entries */
  580. BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) &&
  581. !(cmd->meta.flags & CMD_SIZE_HUGE));
  582. if (iwl3945_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) {
  583. IWL_ERROR("No space for Tx\n");
  584. return -ENOSPC;
  585. }
  586. spin_lock_irqsave(&priv->hcmd_lock, flags);
  587. tfd = &txq->bd[q->write_ptr];
  588. memset(tfd, 0, sizeof(*tfd));
  589. control_flags = (u32 *) tfd;
  590. idx = get_cmd_index(q, q->write_ptr, cmd->meta.flags & CMD_SIZE_HUGE);
  591. out_cmd = &txq->cmd[idx];
  592. out_cmd->hdr.cmd = cmd->id;
  593. memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta));
  594. memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len);
  595. /* At this point, the out_cmd now has all of the incoming cmd
  596. * information */
  597. out_cmd->hdr.flags = 0;
  598. out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) |
  599. INDEX_TO_SEQ(q->write_ptr));
  600. if (out_cmd->meta.flags & CMD_SIZE_HUGE)
  601. out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME);
  602. phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx +
  603. offsetof(struct iwl3945_cmd, hdr);
  604. iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size);
  605. pad = U32_PAD(cmd->len);
  606. count = TFD_CTL_COUNT_GET(*control_flags);
  607. *control_flags = TFD_CTL_COUNT_SET(count) | TFD_CTL_PAD_SET(pad);
  608. IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
  609. "%d bytes at %d[%d]:%d\n",
  610. get_cmd_string(out_cmd->hdr.cmd),
  611. out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence),
  612. fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM);
  613. txq->need_update = 1;
  614. /* Increment and update queue's write index */
  615. q->write_ptr = iwl3945_queue_inc_wrap(q->write_ptr, q->n_bd);
  616. ret = iwl3945_tx_queue_update_write_ptr(priv, txq);
  617. spin_unlock_irqrestore(&priv->hcmd_lock, flags);
  618. return ret ? ret : idx;
  619. }
  620. static int iwl3945_send_cmd_async(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd)
  621. {
  622. int ret;
  623. BUG_ON(!(cmd->meta.flags & CMD_ASYNC));
  624. /* An asynchronous command can not expect an SKB to be set. */
  625. BUG_ON(cmd->meta.flags & CMD_WANT_SKB);
  626. /* An asynchronous command MUST have a callback. */
  627. BUG_ON(!cmd->meta.u.callback);
  628. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  629. return -EBUSY;
  630. ret = iwl3945_enqueue_hcmd(priv, cmd);
  631. if (ret < 0) {
  632. IWL_ERROR("Error sending %s: iwl3945_enqueue_hcmd failed: %d\n",
  633. get_cmd_string(cmd->id), ret);
  634. return ret;
  635. }
  636. return 0;
  637. }
  638. static int iwl3945_send_cmd_sync(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd)
  639. {
  640. int cmd_idx;
  641. int ret;
  642. static atomic_t entry = ATOMIC_INIT(0); /* reentrance protection */
  643. BUG_ON(cmd->meta.flags & CMD_ASYNC);
  644. /* A synchronous command can not have a callback set. */
  645. BUG_ON(cmd->meta.u.callback != NULL);
  646. if (atomic_xchg(&entry, 1)) {
  647. IWL_ERROR("Error sending %s: Already sending a host command\n",
  648. get_cmd_string(cmd->id));
  649. return -EBUSY;
  650. }
  651. set_bit(STATUS_HCMD_ACTIVE, &priv->status);
  652. if (cmd->meta.flags & CMD_WANT_SKB)
  653. cmd->meta.source = &cmd->meta;
  654. cmd_idx = iwl3945_enqueue_hcmd(priv, cmd);
  655. if (cmd_idx < 0) {
  656. ret = cmd_idx;
  657. IWL_ERROR("Error sending %s: iwl3945_enqueue_hcmd failed: %d\n",
  658. get_cmd_string(cmd->id), ret);
  659. goto out;
  660. }
  661. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  662. !test_bit(STATUS_HCMD_ACTIVE, &priv->status),
  663. HOST_COMPLETE_TIMEOUT);
  664. if (!ret) {
  665. if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) {
  666. IWL_ERROR("Error sending %s: time out after %dms.\n",
  667. get_cmd_string(cmd->id),
  668. jiffies_to_msecs(HOST_COMPLETE_TIMEOUT));
  669. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  670. ret = -ETIMEDOUT;
  671. goto cancel;
  672. }
  673. }
  674. if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
  675. IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n",
  676. get_cmd_string(cmd->id));
  677. ret = -ECANCELED;
  678. goto fail;
  679. }
  680. if (test_bit(STATUS_FW_ERROR, &priv->status)) {
  681. IWL_DEBUG_INFO("Command %s failed: FW Error\n",
  682. get_cmd_string(cmd->id));
  683. ret = -EIO;
  684. goto fail;
  685. }
  686. if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) {
  687. IWL_ERROR("Error: Response NULL in '%s'\n",
  688. get_cmd_string(cmd->id));
  689. ret = -EIO;
  690. goto out;
  691. }
  692. ret = 0;
  693. goto out;
  694. cancel:
  695. if (cmd->meta.flags & CMD_WANT_SKB) {
  696. struct iwl3945_cmd *qcmd;
  697. /* Cancel the CMD_WANT_SKB flag for the cmd in the
  698. * TX cmd queue. Otherwise in case the cmd comes
  699. * in later, it will possibly set an invalid
  700. * address (cmd->meta.source). */
  701. qcmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_idx];
  702. qcmd->meta.flags &= ~CMD_WANT_SKB;
  703. }
  704. fail:
  705. if (cmd->meta.u.skb) {
  706. dev_kfree_skb_any(cmd->meta.u.skb);
  707. cmd->meta.u.skb = NULL;
  708. }
  709. out:
  710. atomic_set(&entry, 0);
  711. return ret;
  712. }
  713. int iwl3945_send_cmd(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd)
  714. {
  715. if (cmd->meta.flags & CMD_ASYNC)
  716. return iwl3945_send_cmd_async(priv, cmd);
  717. return iwl3945_send_cmd_sync(priv, cmd);
  718. }
  719. int iwl3945_send_cmd_pdu(struct iwl3945_priv *priv, u8 id, u16 len, const void *data)
  720. {
  721. struct iwl3945_host_cmd cmd = {
  722. .id = id,
  723. .len = len,
  724. .data = data,
  725. };
  726. return iwl3945_send_cmd_sync(priv, &cmd);
  727. }
  728. static int __must_check iwl3945_send_cmd_u32(struct iwl3945_priv *priv, u8 id, u32 val)
  729. {
  730. struct iwl3945_host_cmd cmd = {
  731. .id = id,
  732. .len = sizeof(val),
  733. .data = &val,
  734. };
  735. return iwl3945_send_cmd_sync(priv, &cmd);
  736. }
  737. int iwl3945_send_statistics_request(struct iwl3945_priv *priv)
  738. {
  739. return iwl3945_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0);
  740. }
  741. /**
  742. * iwl3945_set_rxon_channel - Set the phymode and channel values in staging RXON
  743. * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz
  744. * @channel: Any channel valid for the requested phymode
  745. * In addition to setting the staging RXON, priv->phymode is also set.
  746. *
  747. * NOTE: Does not commit to the hardware; it sets appropriate bit fields
  748. * in the staging RXON flag structure based on the phymode
  749. */
  750. static int iwl3945_set_rxon_channel(struct iwl3945_priv *priv, u8 phymode, u16 channel)
  751. {
  752. if (!iwl3945_get_channel_info(priv, phymode, channel)) {
  753. IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
  754. channel, phymode);
  755. return -EINVAL;
  756. }
  757. if ((le16_to_cpu(priv->staging_rxon.channel) == channel) &&
  758. (priv->phymode == phymode))
  759. return 0;
  760. priv->staging_rxon.channel = cpu_to_le16(channel);
  761. if (phymode == MODE_IEEE80211A)
  762. priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
  763. else
  764. priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
  765. priv->phymode = phymode;
  766. IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, phymode);
  767. return 0;
  768. }
  769. /**
  770. * iwl3945_check_rxon_cmd - validate RXON structure is valid
  771. *
  772. * NOTE: This is really only useful during development and can eventually
  773. * be #ifdef'd out once the driver is stable and folks aren't actively
  774. * making changes
  775. */
  776. static int iwl3945_check_rxon_cmd(struct iwl3945_rxon_cmd *rxon)
  777. {
  778. int error = 0;
  779. int counter = 1;
  780. if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
  781. error |= le32_to_cpu(rxon->flags &
  782. (RXON_FLG_TGJ_NARROW_BAND_MSK |
  783. RXON_FLG_RADAR_DETECT_MSK));
  784. if (error)
  785. IWL_WARNING("check 24G fields %d | %d\n",
  786. counter++, error);
  787. } else {
  788. error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
  789. 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
  790. if (error)
  791. IWL_WARNING("check 52 fields %d | %d\n",
  792. counter++, error);
  793. error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
  794. if (error)
  795. IWL_WARNING("check 52 CCK %d | %d\n",
  796. counter++, error);
  797. }
  798. error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
  799. if (error)
  800. IWL_WARNING("check mac addr %d | %d\n", counter++, error);
  801. /* make sure basic rates 6Mbps and 1Mbps are supported */
  802. error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
  803. ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
  804. if (error)
  805. IWL_WARNING("check basic rate %d | %d\n", counter++, error);
  806. error |= (le16_to_cpu(rxon->assoc_id) > 2007);
  807. if (error)
  808. IWL_WARNING("check assoc id %d | %d\n", counter++, error);
  809. error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
  810. == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
  811. if (error)
  812. IWL_WARNING("check CCK and short slot %d | %d\n",
  813. counter++, error);
  814. error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
  815. == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
  816. if (error)
  817. IWL_WARNING("check CCK & auto detect %d | %d\n",
  818. counter++, error);
  819. error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
  820. RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
  821. if (error)
  822. IWL_WARNING("check TGG and auto detect %d | %d\n",
  823. counter++, error);
  824. if ((rxon->flags & RXON_FLG_DIS_DIV_MSK))
  825. error |= ((rxon->flags & (RXON_FLG_ANT_B_MSK |
  826. RXON_FLG_ANT_A_MSK)) == 0);
  827. if (error)
  828. IWL_WARNING("check antenna %d %d\n", counter++, error);
  829. if (error)
  830. IWL_WARNING("Tuning to channel %d\n",
  831. le16_to_cpu(rxon->channel));
  832. if (error) {
  833. IWL_ERROR("Not a valid iwl3945_rxon_assoc_cmd field values\n");
  834. return -1;
  835. }
  836. return 0;
  837. }
  838. /**
  839. * iwl3945_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
  840. * @priv: staging_rxon is compared to active_rxon
  841. *
  842. * If the RXON structure is changing enough to require a new tune,
  843. * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
  844. * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
  845. */
  846. static int iwl3945_full_rxon_required(struct iwl3945_priv *priv)
  847. {
  848. /* These items are only settable from the full RXON command */
  849. if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ||
  850. compare_ether_addr(priv->staging_rxon.bssid_addr,
  851. priv->active_rxon.bssid_addr) ||
  852. compare_ether_addr(priv->staging_rxon.node_addr,
  853. priv->active_rxon.node_addr) ||
  854. compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
  855. priv->active_rxon.wlap_bssid_addr) ||
  856. (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
  857. (priv->staging_rxon.channel != priv->active_rxon.channel) ||
  858. (priv->staging_rxon.air_propagation !=
  859. priv->active_rxon.air_propagation) ||
  860. (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
  861. return 1;
  862. /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
  863. * be updated with the RXON_ASSOC command -- however only some
  864. * flag transitions are allowed using RXON_ASSOC */
  865. /* Check if we are not switching bands */
  866. if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
  867. (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
  868. return 1;
  869. /* Check if we are switching association toggle */
  870. if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
  871. (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
  872. return 1;
  873. return 0;
  874. }
  875. static int iwl3945_send_rxon_assoc(struct iwl3945_priv *priv)
  876. {
  877. int rc = 0;
  878. struct iwl3945_rx_packet *res = NULL;
  879. struct iwl3945_rxon_assoc_cmd rxon_assoc;
  880. struct iwl3945_host_cmd cmd = {
  881. .id = REPLY_RXON_ASSOC,
  882. .len = sizeof(rxon_assoc),
  883. .meta.flags = CMD_WANT_SKB,
  884. .data = &rxon_assoc,
  885. };
  886. const struct iwl3945_rxon_cmd *rxon1 = &priv->staging_rxon;
  887. const struct iwl3945_rxon_cmd *rxon2 = &priv->active_rxon;
  888. if ((rxon1->flags == rxon2->flags) &&
  889. (rxon1->filter_flags == rxon2->filter_flags) &&
  890. (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
  891. (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
  892. IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
  893. return 0;
  894. }
  895. rxon_assoc.flags = priv->staging_rxon.flags;
  896. rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
  897. rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
  898. rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
  899. rxon_assoc.reserved = 0;
  900. rc = iwl3945_send_cmd_sync(priv, &cmd);
  901. if (rc)
  902. return rc;
  903. res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data;
  904. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  905. IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n");
  906. rc = -EIO;
  907. }
  908. priv->alloc_rxb_skb--;
  909. dev_kfree_skb_any(cmd.meta.u.skb);
  910. return rc;
  911. }
  912. /**
  913. * iwl3945_commit_rxon - commit staging_rxon to hardware
  914. *
  915. * The RXON command in staging_rxon is committed to the hardware and
  916. * the active_rxon structure is updated with the new data. This
  917. * function correctly transitions out of the RXON_ASSOC_MSK state if
  918. * a HW tune is required based on the RXON structure changes.
  919. */
  920. static int iwl3945_commit_rxon(struct iwl3945_priv *priv)
  921. {
  922. /* cast away the const for active_rxon in this function */
  923. struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
  924. int rc = 0;
  925. DECLARE_MAC_BUF(mac);
  926. if (!iwl3945_is_alive(priv))
  927. return -1;
  928. /* always get timestamp with Rx frame */
  929. priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
  930. /* select antenna */
  931. priv->staging_rxon.flags &=
  932. ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
  933. priv->staging_rxon.flags |= iwl3945_get_antenna_flags(priv);
  934. rc = iwl3945_check_rxon_cmd(&priv->staging_rxon);
  935. if (rc) {
  936. IWL_ERROR("Invalid RXON configuration. Not committing.\n");
  937. return -EINVAL;
  938. }
  939. /* If we don't need to send a full RXON, we can use
  940. * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
  941. * and other flags for the current radio configuration. */
  942. if (!iwl3945_full_rxon_required(priv)) {
  943. rc = iwl3945_send_rxon_assoc(priv);
  944. if (rc) {
  945. IWL_ERROR("Error setting RXON_ASSOC "
  946. "configuration (%d).\n", rc);
  947. return rc;
  948. }
  949. memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
  950. return 0;
  951. }
  952. /* If we are currently associated and the new config requires
  953. * an RXON_ASSOC and the new config wants the associated mask enabled,
  954. * we must clear the associated from the active configuration
  955. * before we apply the new config */
  956. if (iwl3945_is_associated(priv) &&
  957. (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) {
  958. IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
  959. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  960. rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON,
  961. sizeof(struct iwl3945_rxon_cmd),
  962. &priv->active_rxon);
  963. /* If the mask clearing failed then we set
  964. * active_rxon back to what it was previously */
  965. if (rc) {
  966. active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
  967. IWL_ERROR("Error clearing ASSOC_MSK on current "
  968. "configuration (%d).\n", rc);
  969. return rc;
  970. }
  971. }
  972. IWL_DEBUG_INFO("Sending RXON\n"
  973. "* with%s RXON_FILTER_ASSOC_MSK\n"
  974. "* channel = %d\n"
  975. "* bssid = %s\n",
  976. ((priv->staging_rxon.filter_flags &
  977. RXON_FILTER_ASSOC_MSK) ? "" : "out"),
  978. le16_to_cpu(priv->staging_rxon.channel),
  979. print_mac(mac, priv->staging_rxon.bssid_addr));
  980. /* Apply the new configuration */
  981. rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON,
  982. sizeof(struct iwl3945_rxon_cmd), &priv->staging_rxon);
  983. if (rc) {
  984. IWL_ERROR("Error setting new configuration (%d).\n", rc);
  985. return rc;
  986. }
  987. memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
  988. iwl3945_clear_stations_table(priv);
  989. /* If we issue a new RXON command which required a tune then we must
  990. * send a new TXPOWER command or we won't be able to Tx any frames */
  991. rc = iwl3945_hw_reg_send_txpower(priv);
  992. if (rc) {
  993. IWL_ERROR("Error setting Tx power (%d).\n", rc);
  994. return rc;
  995. }
  996. /* Add the broadcast address so we can send broadcast frames */
  997. if (iwl3945_add_station(priv, iwl3945_broadcast_addr, 0, 0) ==
  998. IWL_INVALID_STATION) {
  999. IWL_ERROR("Error adding BROADCAST address for transmit.\n");
  1000. return -EIO;
  1001. }
  1002. /* If we have set the ASSOC_MSK and we are in BSS mode then
  1003. * add the IWL_AP_ID to the station rate table */
  1004. if (iwl3945_is_associated(priv) &&
  1005. (priv->iw_mode == IEEE80211_IF_TYPE_STA))
  1006. if (iwl3945_add_station(priv, priv->active_rxon.bssid_addr, 1, 0)
  1007. == IWL_INVALID_STATION) {
  1008. IWL_ERROR("Error adding AP address for transmit.\n");
  1009. return -EIO;
  1010. }
  1011. /* Init the hardware's rate fallback order based on the
  1012. * phymode */
  1013. rc = iwl3945_init_hw_rate_table(priv);
  1014. if (rc) {
  1015. IWL_ERROR("Error setting HW rate table: %02X\n", rc);
  1016. return -EIO;
  1017. }
  1018. return 0;
  1019. }
  1020. static int iwl3945_send_bt_config(struct iwl3945_priv *priv)
  1021. {
  1022. struct iwl3945_bt_cmd bt_cmd = {
  1023. .flags = 3,
  1024. .lead_time = 0xAA,
  1025. .max_kill = 1,
  1026. .kill_ack_mask = 0,
  1027. .kill_cts_mask = 0,
  1028. };
  1029. return iwl3945_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  1030. sizeof(struct iwl3945_bt_cmd), &bt_cmd);
  1031. }
  1032. static int iwl3945_send_scan_abort(struct iwl3945_priv *priv)
  1033. {
  1034. int rc = 0;
  1035. struct iwl3945_rx_packet *res;
  1036. struct iwl3945_host_cmd cmd = {
  1037. .id = REPLY_SCAN_ABORT_CMD,
  1038. .meta.flags = CMD_WANT_SKB,
  1039. };
  1040. /* If there isn't a scan actively going on in the hardware
  1041. * then we are in between scan bands and not actually
  1042. * actively scanning, so don't send the abort command */
  1043. if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
  1044. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  1045. return 0;
  1046. }
  1047. rc = iwl3945_send_cmd_sync(priv, &cmd);
  1048. if (rc) {
  1049. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  1050. return rc;
  1051. }
  1052. res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data;
  1053. if (res->u.status != CAN_ABORT_STATUS) {
  1054. /* The scan abort will return 1 for success or
  1055. * 2 for "failure". A failure condition can be
  1056. * due to simply not being in an active scan which
  1057. * can occur if we send the scan abort before we
  1058. * the microcode has notified us that a scan is
  1059. * completed. */
  1060. IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status);
  1061. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  1062. clear_bit(STATUS_SCAN_HW, &priv->status);
  1063. }
  1064. dev_kfree_skb_any(cmd.meta.u.skb);
  1065. return rc;
  1066. }
  1067. static int iwl3945_card_state_sync_callback(struct iwl3945_priv *priv,
  1068. struct iwl3945_cmd *cmd,
  1069. struct sk_buff *skb)
  1070. {
  1071. return 1;
  1072. }
  1073. /*
  1074. * CARD_STATE_CMD
  1075. *
  1076. * Use: Sets the device's internal card state to enable, disable, or halt
  1077. *
  1078. * When in the 'enable' state the card operates as normal.
  1079. * When in the 'disable' state, the card enters into a low power mode.
  1080. * When in the 'halt' state, the card is shut down and must be fully
  1081. * restarted to come back on.
  1082. */
  1083. static int iwl3945_send_card_state(struct iwl3945_priv *priv, u32 flags, u8 meta_flag)
  1084. {
  1085. struct iwl3945_host_cmd cmd = {
  1086. .id = REPLY_CARD_STATE_CMD,
  1087. .len = sizeof(u32),
  1088. .data = &flags,
  1089. .meta.flags = meta_flag,
  1090. };
  1091. if (meta_flag & CMD_ASYNC)
  1092. cmd.meta.u.callback = iwl3945_card_state_sync_callback;
  1093. return iwl3945_send_cmd(priv, &cmd);
  1094. }
  1095. static int iwl3945_add_sta_sync_callback(struct iwl3945_priv *priv,
  1096. struct iwl3945_cmd *cmd, struct sk_buff *skb)
  1097. {
  1098. struct iwl3945_rx_packet *res = NULL;
  1099. if (!skb) {
  1100. IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
  1101. return 1;
  1102. }
  1103. res = (struct iwl3945_rx_packet *)skb->data;
  1104. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  1105. IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
  1106. res->hdr.flags);
  1107. return 1;
  1108. }
  1109. switch (res->u.add_sta.status) {
  1110. case ADD_STA_SUCCESS_MSK:
  1111. break;
  1112. default:
  1113. break;
  1114. }
  1115. /* We didn't cache the SKB; let the caller free it */
  1116. return 1;
  1117. }
  1118. int iwl3945_send_add_station(struct iwl3945_priv *priv,
  1119. struct iwl3945_addsta_cmd *sta, u8 flags)
  1120. {
  1121. struct iwl3945_rx_packet *res = NULL;
  1122. int rc = 0;
  1123. struct iwl3945_host_cmd cmd = {
  1124. .id = REPLY_ADD_STA,
  1125. .len = sizeof(struct iwl3945_addsta_cmd),
  1126. .meta.flags = flags,
  1127. .data = sta,
  1128. };
  1129. if (flags & CMD_ASYNC)
  1130. cmd.meta.u.callback = iwl3945_add_sta_sync_callback;
  1131. else
  1132. cmd.meta.flags |= CMD_WANT_SKB;
  1133. rc = iwl3945_send_cmd(priv, &cmd);
  1134. if (rc || (flags & CMD_ASYNC))
  1135. return rc;
  1136. res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data;
  1137. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  1138. IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
  1139. res->hdr.flags);
  1140. rc = -EIO;
  1141. }
  1142. if (rc == 0) {
  1143. switch (res->u.add_sta.status) {
  1144. case ADD_STA_SUCCESS_MSK:
  1145. IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
  1146. break;
  1147. default:
  1148. rc = -EIO;
  1149. IWL_WARNING("REPLY_ADD_STA failed\n");
  1150. break;
  1151. }
  1152. }
  1153. priv->alloc_rxb_skb--;
  1154. dev_kfree_skb_any(cmd.meta.u.skb);
  1155. return rc;
  1156. }
  1157. static int iwl3945_update_sta_key_info(struct iwl3945_priv *priv,
  1158. struct ieee80211_key_conf *keyconf,
  1159. u8 sta_id)
  1160. {
  1161. unsigned long flags;
  1162. __le16 key_flags = 0;
  1163. switch (keyconf->alg) {
  1164. case ALG_CCMP:
  1165. key_flags |= STA_KEY_FLG_CCMP;
  1166. key_flags |= cpu_to_le16(
  1167. keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  1168. key_flags &= ~STA_KEY_FLG_INVALID;
  1169. break;
  1170. case ALG_TKIP:
  1171. case ALG_WEP:
  1172. default:
  1173. return -EINVAL;
  1174. }
  1175. spin_lock_irqsave(&priv->sta_lock, flags);
  1176. priv->stations[sta_id].keyinfo.alg = keyconf->alg;
  1177. priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
  1178. memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
  1179. keyconf->keylen);
  1180. memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
  1181. keyconf->keylen);
  1182. priv->stations[sta_id].sta.key.key_flags = key_flags;
  1183. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  1184. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  1185. spin_unlock_irqrestore(&priv->sta_lock, flags);
  1186. IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
  1187. iwl3945_send_add_station(priv, &priv->stations[sta_id].sta, 0);
  1188. return 0;
  1189. }
  1190. static int iwl3945_clear_sta_key_info(struct iwl3945_priv *priv, u8 sta_id)
  1191. {
  1192. unsigned long flags;
  1193. spin_lock_irqsave(&priv->sta_lock, flags);
  1194. memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key));
  1195. memset(&priv->stations[sta_id].sta.key, 0, sizeof(struct iwl3945_keyinfo));
  1196. priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
  1197. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  1198. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  1199. spin_unlock_irqrestore(&priv->sta_lock, flags);
  1200. IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
  1201. iwl3945_send_add_station(priv, &priv->stations[sta_id].sta, 0);
  1202. return 0;
  1203. }
  1204. static void iwl3945_clear_free_frames(struct iwl3945_priv *priv)
  1205. {
  1206. struct list_head *element;
  1207. IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
  1208. priv->frames_count);
  1209. while (!list_empty(&priv->free_frames)) {
  1210. element = priv->free_frames.next;
  1211. list_del(element);
  1212. kfree(list_entry(element, struct iwl3945_frame, list));
  1213. priv->frames_count--;
  1214. }
  1215. if (priv->frames_count) {
  1216. IWL_WARNING("%d frames still in use. Did we lose one?\n",
  1217. priv->frames_count);
  1218. priv->frames_count = 0;
  1219. }
  1220. }
  1221. static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl3945_priv *priv)
  1222. {
  1223. struct iwl3945_frame *frame;
  1224. struct list_head *element;
  1225. if (list_empty(&priv->free_frames)) {
  1226. frame = kzalloc(sizeof(*frame), GFP_KERNEL);
  1227. if (!frame) {
  1228. IWL_ERROR("Could not allocate frame!\n");
  1229. return NULL;
  1230. }
  1231. priv->frames_count++;
  1232. return frame;
  1233. }
  1234. element = priv->free_frames.next;
  1235. list_del(element);
  1236. return list_entry(element, struct iwl3945_frame, list);
  1237. }
  1238. static void iwl3945_free_frame(struct iwl3945_priv *priv, struct iwl3945_frame *frame)
  1239. {
  1240. memset(frame, 0, sizeof(*frame));
  1241. list_add(&frame->list, &priv->free_frames);
  1242. }
  1243. unsigned int iwl3945_fill_beacon_frame(struct iwl3945_priv *priv,
  1244. struct ieee80211_hdr *hdr,
  1245. const u8 *dest, int left)
  1246. {
  1247. if (!iwl3945_is_associated(priv) || !priv->ibss_beacon ||
  1248. ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) &&
  1249. (priv->iw_mode != IEEE80211_IF_TYPE_AP)))
  1250. return 0;
  1251. if (priv->ibss_beacon->len > left)
  1252. return 0;
  1253. memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
  1254. return priv->ibss_beacon->len;
  1255. }
  1256. static int iwl3945_rate_index_from_plcp(int plcp)
  1257. {
  1258. int i = 0;
  1259. for (i = 0; i < IWL_RATE_COUNT; i++)
  1260. if (iwl3945_rates[i].plcp == plcp)
  1261. return i;
  1262. return -1;
  1263. }
  1264. static u8 iwl3945_rate_get_lowest_plcp(int rate_mask)
  1265. {
  1266. u8 i;
  1267. for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
  1268. i = iwl3945_rates[i].next_ieee) {
  1269. if (rate_mask & (1 << i))
  1270. return iwl3945_rates[i].plcp;
  1271. }
  1272. return IWL_RATE_INVALID;
  1273. }
  1274. static int iwl3945_send_beacon_cmd(struct iwl3945_priv *priv)
  1275. {
  1276. struct iwl3945_frame *frame;
  1277. unsigned int frame_size;
  1278. int rc;
  1279. u8 rate;
  1280. frame = iwl3945_get_free_frame(priv);
  1281. if (!frame) {
  1282. IWL_ERROR("Could not obtain free frame buffer for beacon "
  1283. "command.\n");
  1284. return -ENOMEM;
  1285. }
  1286. if (!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)) {
  1287. rate = iwl3945_rate_get_lowest_plcp(priv->active_rate_basic &
  1288. 0xFF0);
  1289. if (rate == IWL_INVALID_RATE)
  1290. rate = IWL_RATE_6M_PLCP;
  1291. } else {
  1292. rate = iwl3945_rate_get_lowest_plcp(priv->active_rate_basic & 0xF);
  1293. if (rate == IWL_INVALID_RATE)
  1294. rate = IWL_RATE_1M_PLCP;
  1295. }
  1296. frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
  1297. rc = iwl3945_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
  1298. &frame->u.cmd[0]);
  1299. iwl3945_free_frame(priv, frame);
  1300. return rc;
  1301. }
  1302. /******************************************************************************
  1303. *
  1304. * EEPROM related functions
  1305. *
  1306. ******************************************************************************/
  1307. static void get_eeprom_mac(struct iwl3945_priv *priv, u8 *mac)
  1308. {
  1309. memcpy(mac, priv->eeprom.mac_address, 6);
  1310. }
  1311. /**
  1312. * iwl3945_eeprom_init - read EEPROM contents
  1313. *
  1314. * Load the EEPROM contents from adapter into priv->eeprom
  1315. *
  1316. * NOTE: This routine uses the non-debug IO access functions.
  1317. */
  1318. int iwl3945_eeprom_init(struct iwl3945_priv *priv)
  1319. {
  1320. u16 *e = (u16 *)&priv->eeprom;
  1321. u32 gp = iwl3945_read32(priv, CSR_EEPROM_GP);
  1322. u32 r;
  1323. int sz = sizeof(priv->eeprom);
  1324. int rc;
  1325. int i;
  1326. u16 addr;
  1327. /* The EEPROM structure has several padding buffers within it
  1328. * and when adding new EEPROM maps is subject to programmer errors
  1329. * which may be very difficult to identify without explicitly
  1330. * checking the resulting size of the eeprom map. */
  1331. BUILD_BUG_ON(sizeof(priv->eeprom) != IWL_EEPROM_IMAGE_SIZE);
  1332. if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) {
  1333. IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp);
  1334. return -ENOENT;
  1335. }
  1336. /* Make sure driver (instead of uCode) is allowed to read EEPROM */
  1337. rc = iwl3945_eeprom_acquire_semaphore(priv);
  1338. if (rc < 0) {
  1339. IWL_ERROR("Failed to acquire EEPROM semaphore.\n");
  1340. return -ENOENT;
  1341. }
  1342. /* eeprom is an array of 16bit values */
  1343. for (addr = 0; addr < sz; addr += sizeof(u16)) {
  1344. _iwl3945_write32(priv, CSR_EEPROM_REG, addr << 1);
  1345. _iwl3945_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD);
  1346. for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT;
  1347. i += IWL_EEPROM_ACCESS_DELAY) {
  1348. r = _iwl3945_read_direct32(priv, CSR_EEPROM_REG);
  1349. if (r & CSR_EEPROM_REG_READ_VALID_MSK)
  1350. break;
  1351. udelay(IWL_EEPROM_ACCESS_DELAY);
  1352. }
  1353. if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) {
  1354. IWL_ERROR("Time out reading EEPROM[%d]", addr);
  1355. return -ETIMEDOUT;
  1356. }
  1357. e[addr / 2] = le16_to_cpu(r >> 16);
  1358. }
  1359. return 0;
  1360. }
  1361. /******************************************************************************
  1362. *
  1363. * Misc. internal state and helper functions
  1364. *
  1365. ******************************************************************************/
  1366. #ifdef CONFIG_IWL3945_DEBUG
  1367. /**
  1368. * iwl3945_report_frame - dump frame to syslog during debug sessions
  1369. *
  1370. * You may hack this function to show different aspects of received frames,
  1371. * including selective frame dumps.
  1372. * group100 parameter selects whether to show 1 out of 100 good frames.
  1373. */
  1374. void iwl3945_report_frame(struct iwl3945_priv *priv,
  1375. struct iwl3945_rx_packet *pkt,
  1376. struct ieee80211_hdr *header, int group100)
  1377. {
  1378. u32 to_us;
  1379. u32 print_summary = 0;
  1380. u32 print_dump = 0; /* set to 1 to dump all frames' contents */
  1381. u32 hundred = 0;
  1382. u32 dataframe = 0;
  1383. u16 fc;
  1384. u16 seq_ctl;
  1385. u16 channel;
  1386. u16 phy_flags;
  1387. int rate_sym;
  1388. u16 length;
  1389. u16 status;
  1390. u16 bcn_tmr;
  1391. u32 tsf_low;
  1392. u64 tsf;
  1393. u8 rssi;
  1394. u8 agc;
  1395. u16 sig_avg;
  1396. u16 noise_diff;
  1397. struct iwl3945_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt);
  1398. struct iwl3945_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
  1399. struct iwl3945_rx_frame_end *rx_end = IWL_RX_END(pkt);
  1400. u8 *data = IWL_RX_DATA(pkt);
  1401. /* MAC header */
  1402. fc = le16_to_cpu(header->frame_control);
  1403. seq_ctl = le16_to_cpu(header->seq_ctrl);
  1404. /* metadata */
  1405. channel = le16_to_cpu(rx_hdr->channel);
  1406. phy_flags = le16_to_cpu(rx_hdr->phy_flags);
  1407. rate_sym = rx_hdr->rate;
  1408. length = le16_to_cpu(rx_hdr->len);
  1409. /* end-of-frame status and timestamp */
  1410. status = le32_to_cpu(rx_end->status);
  1411. bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp);
  1412. tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff;
  1413. tsf = le64_to_cpu(rx_end->timestamp);
  1414. /* signal statistics */
  1415. rssi = rx_stats->rssi;
  1416. agc = rx_stats->agc;
  1417. sig_avg = le16_to_cpu(rx_stats->sig_avg);
  1418. noise_diff = le16_to_cpu(rx_stats->noise_diff);
  1419. to_us = !compare_ether_addr(header->addr1, priv->mac_addr);
  1420. /* if data frame is to us and all is good,
  1421. * (optionally) print summary for only 1 out of every 100 */
  1422. if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) ==
  1423. (IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) {
  1424. dataframe = 1;
  1425. if (!group100)
  1426. print_summary = 1; /* print each frame */
  1427. else if (priv->framecnt_to_us < 100) {
  1428. priv->framecnt_to_us++;
  1429. print_summary = 0;
  1430. } else {
  1431. priv->framecnt_to_us = 0;
  1432. print_summary = 1;
  1433. hundred = 1;
  1434. }
  1435. } else {
  1436. /* print summary for all other frames */
  1437. print_summary = 1;
  1438. }
  1439. if (print_summary) {
  1440. char *title;
  1441. u32 rate;
  1442. if (hundred)
  1443. title = "100Frames";
  1444. else if (fc & IEEE80211_FCTL_RETRY)
  1445. title = "Retry";
  1446. else if (ieee80211_is_assoc_response(fc))
  1447. title = "AscRsp";
  1448. else if (ieee80211_is_reassoc_response(fc))
  1449. title = "RasRsp";
  1450. else if (ieee80211_is_probe_response(fc)) {
  1451. title = "PrbRsp";
  1452. print_dump = 1; /* dump frame contents */
  1453. } else if (ieee80211_is_beacon(fc)) {
  1454. title = "Beacon";
  1455. print_dump = 1; /* dump frame contents */
  1456. } else if (ieee80211_is_atim(fc))
  1457. title = "ATIM";
  1458. else if (ieee80211_is_auth(fc))
  1459. title = "Auth";
  1460. else if (ieee80211_is_deauth(fc))
  1461. title = "DeAuth";
  1462. else if (ieee80211_is_disassoc(fc))
  1463. title = "DisAssoc";
  1464. else
  1465. title = "Frame";
  1466. rate = iwl3945_rate_index_from_plcp(rate_sym);
  1467. if (rate == -1)
  1468. rate = 0;
  1469. else
  1470. rate = iwl3945_rates[rate].ieee / 2;
  1471. /* print frame summary.
  1472. * MAC addresses show just the last byte (for brevity),
  1473. * but you can hack it to show more, if you'd like to. */
  1474. if (dataframe)
  1475. IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, "
  1476. "len=%u, rssi=%d, chnl=%d, rate=%u, \n",
  1477. title, fc, header->addr1[5],
  1478. length, rssi, channel, rate);
  1479. else {
  1480. /* src/dst addresses assume managed mode */
  1481. IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, "
  1482. "src=0x%02x, rssi=%u, tim=%lu usec, "
  1483. "phy=0x%02x, chnl=%d\n",
  1484. title, fc, header->addr1[5],
  1485. header->addr3[5], rssi,
  1486. tsf_low - priv->scan_start_tsf,
  1487. phy_flags, channel);
  1488. }
  1489. }
  1490. if (print_dump)
  1491. iwl3945_print_hex_dump(IWL_DL_RX, data, length);
  1492. }
  1493. #endif
  1494. static void iwl3945_unset_hw_setting(struct iwl3945_priv *priv)
  1495. {
  1496. if (priv->hw_setting.shared_virt)
  1497. pci_free_consistent(priv->pci_dev,
  1498. sizeof(struct iwl3945_shared),
  1499. priv->hw_setting.shared_virt,
  1500. priv->hw_setting.shared_phys);
  1501. }
  1502. /**
  1503. * iwl3945_supported_rate_to_ie - fill in the supported rate in IE field
  1504. *
  1505. * return : set the bit for each supported rate insert in ie
  1506. */
  1507. static u16 iwl3945_supported_rate_to_ie(u8 *ie, u16 supported_rate,
  1508. u16 basic_rate, int *left)
  1509. {
  1510. u16 ret_rates = 0, bit;
  1511. int i;
  1512. u8 *cnt = ie;
  1513. u8 *rates = ie + 1;
  1514. for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) {
  1515. if (bit & supported_rate) {
  1516. ret_rates |= bit;
  1517. rates[*cnt] = iwl3945_rates[i].ieee |
  1518. ((bit & basic_rate) ? 0x80 : 0x00);
  1519. (*cnt)++;
  1520. (*left)--;
  1521. if ((*left <= 0) ||
  1522. (*cnt >= IWL_SUPPORTED_RATES_IE_LEN))
  1523. break;
  1524. }
  1525. }
  1526. return ret_rates;
  1527. }
  1528. /**
  1529. * iwl3945_fill_probe_req - fill in all required fields and IE for probe request
  1530. */
  1531. static u16 iwl3945_fill_probe_req(struct iwl3945_priv *priv,
  1532. struct ieee80211_mgmt *frame,
  1533. int left, int is_direct)
  1534. {
  1535. int len = 0;
  1536. u8 *pos = NULL;
  1537. u16 active_rates, ret_rates, cck_rates;
  1538. /* Make sure there is enough space for the probe request,
  1539. * two mandatory IEs and the data */
  1540. left -= 24;
  1541. if (left < 0)
  1542. return 0;
  1543. len += 24;
  1544. frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
  1545. memcpy(frame->da, iwl3945_broadcast_addr, ETH_ALEN);
  1546. memcpy(frame->sa, priv->mac_addr, ETH_ALEN);
  1547. memcpy(frame->bssid, iwl3945_broadcast_addr, ETH_ALEN);
  1548. frame->seq_ctrl = 0;
  1549. /* fill in our indirect SSID IE */
  1550. /* ...next IE... */
  1551. left -= 2;
  1552. if (left < 0)
  1553. return 0;
  1554. len += 2;
  1555. pos = &(frame->u.probe_req.variable[0]);
  1556. *pos++ = WLAN_EID_SSID;
  1557. *pos++ = 0;
  1558. /* fill in our direct SSID IE... */
  1559. if (is_direct) {
  1560. /* ...next IE... */
  1561. left -= 2 + priv->essid_len;
  1562. if (left < 0)
  1563. return 0;
  1564. /* ... fill it in... */
  1565. *pos++ = WLAN_EID_SSID;
  1566. *pos++ = priv->essid_len;
  1567. memcpy(pos, priv->essid, priv->essid_len);
  1568. pos += priv->essid_len;
  1569. len += 2 + priv->essid_len;
  1570. }
  1571. /* fill in supported rate */
  1572. /* ...next IE... */
  1573. left -= 2;
  1574. if (left < 0)
  1575. return 0;
  1576. /* ... fill it in... */
  1577. *pos++ = WLAN_EID_SUPP_RATES;
  1578. *pos = 0;
  1579. priv->active_rate = priv->rates_mask;
  1580. active_rates = priv->active_rate;
  1581. priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
  1582. cck_rates = IWL_CCK_RATES_MASK & active_rates;
  1583. ret_rates = iwl3945_supported_rate_to_ie(pos, cck_rates,
  1584. priv->active_rate_basic, &left);
  1585. active_rates &= ~ret_rates;
  1586. ret_rates = iwl3945_supported_rate_to_ie(pos, active_rates,
  1587. priv->active_rate_basic, &left);
  1588. active_rates &= ~ret_rates;
  1589. len += 2 + *pos;
  1590. pos += (*pos) + 1;
  1591. if (active_rates == 0)
  1592. goto fill_end;
  1593. /* fill in supported extended rate */
  1594. /* ...next IE... */
  1595. left -= 2;
  1596. if (left < 0)
  1597. return 0;
  1598. /* ... fill it in... */
  1599. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  1600. *pos = 0;
  1601. iwl3945_supported_rate_to_ie(pos, active_rates,
  1602. priv->active_rate_basic, &left);
  1603. if (*pos > 0)
  1604. len += 2 + *pos;
  1605. fill_end:
  1606. return (u16)len;
  1607. }
  1608. /*
  1609. * QoS support
  1610. */
  1611. #ifdef CONFIG_IWL3945_QOS
  1612. static int iwl3945_send_qos_params_command(struct iwl3945_priv *priv,
  1613. struct iwl3945_qosparam_cmd *qos)
  1614. {
  1615. return iwl3945_send_cmd_pdu(priv, REPLY_QOS_PARAM,
  1616. sizeof(struct iwl3945_qosparam_cmd), qos);
  1617. }
  1618. static void iwl3945_reset_qos(struct iwl3945_priv *priv)
  1619. {
  1620. u16 cw_min = 15;
  1621. u16 cw_max = 1023;
  1622. u8 aifs = 2;
  1623. u8 is_legacy = 0;
  1624. unsigned long flags;
  1625. int i;
  1626. spin_lock_irqsave(&priv->lock, flags);
  1627. priv->qos_data.qos_active = 0;
  1628. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) {
  1629. if (priv->qos_data.qos_enable)
  1630. priv->qos_data.qos_active = 1;
  1631. if (!(priv->active_rate & 0xfff0)) {
  1632. cw_min = 31;
  1633. is_legacy = 1;
  1634. }
  1635. } else if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  1636. if (priv->qos_data.qos_enable)
  1637. priv->qos_data.qos_active = 1;
  1638. } else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) {
  1639. cw_min = 31;
  1640. is_legacy = 1;
  1641. }
  1642. if (priv->qos_data.qos_active)
  1643. aifs = 3;
  1644. priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min);
  1645. priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max);
  1646. priv->qos_data.def_qos_parm.ac[0].aifsn = aifs;
  1647. priv->qos_data.def_qos_parm.ac[0].edca_txop = 0;
  1648. priv->qos_data.def_qos_parm.ac[0].reserved1 = 0;
  1649. if (priv->qos_data.qos_active) {
  1650. i = 1;
  1651. priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min);
  1652. priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max);
  1653. priv->qos_data.def_qos_parm.ac[i].aifsn = 7;
  1654. priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
  1655. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  1656. i = 2;
  1657. priv->qos_data.def_qos_parm.ac[i].cw_min =
  1658. cpu_to_le16((cw_min + 1) / 2 - 1);
  1659. priv->qos_data.def_qos_parm.ac[i].cw_max =
  1660. cpu_to_le16(cw_max);
  1661. priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
  1662. if (is_legacy)
  1663. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  1664. cpu_to_le16(6016);
  1665. else
  1666. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  1667. cpu_to_le16(3008);
  1668. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  1669. i = 3;
  1670. priv->qos_data.def_qos_parm.ac[i].cw_min =
  1671. cpu_to_le16((cw_min + 1) / 4 - 1);
  1672. priv->qos_data.def_qos_parm.ac[i].cw_max =
  1673. cpu_to_le16((cw_max + 1) / 2 - 1);
  1674. priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
  1675. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  1676. if (is_legacy)
  1677. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  1678. cpu_to_le16(3264);
  1679. else
  1680. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  1681. cpu_to_le16(1504);
  1682. } else {
  1683. for (i = 1; i < 4; i++) {
  1684. priv->qos_data.def_qos_parm.ac[i].cw_min =
  1685. cpu_to_le16(cw_min);
  1686. priv->qos_data.def_qos_parm.ac[i].cw_max =
  1687. cpu_to_le16(cw_max);
  1688. priv->qos_data.def_qos_parm.ac[i].aifsn = aifs;
  1689. priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
  1690. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  1691. }
  1692. }
  1693. IWL_DEBUG_QOS("set QoS to default \n");
  1694. spin_unlock_irqrestore(&priv->lock, flags);
  1695. }
  1696. static void iwl3945_activate_qos(struct iwl3945_priv *priv, u8 force)
  1697. {
  1698. unsigned long flags;
  1699. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1700. return;
  1701. if (!priv->qos_data.qos_enable)
  1702. return;
  1703. spin_lock_irqsave(&priv->lock, flags);
  1704. priv->qos_data.def_qos_parm.qos_flags = 0;
  1705. if (priv->qos_data.qos_cap.q_AP.queue_request &&
  1706. !priv->qos_data.qos_cap.q_AP.txop_request)
  1707. priv->qos_data.def_qos_parm.qos_flags |=
  1708. QOS_PARAM_FLG_TXOP_TYPE_MSK;
  1709. if (priv->qos_data.qos_active)
  1710. priv->qos_data.def_qos_parm.qos_flags |=
  1711. QOS_PARAM_FLG_UPDATE_EDCA_MSK;
  1712. spin_unlock_irqrestore(&priv->lock, flags);
  1713. if (force || iwl3945_is_associated(priv)) {
  1714. IWL_DEBUG_QOS("send QoS cmd with Qos active %d \n",
  1715. priv->qos_data.qos_active);
  1716. iwl3945_send_qos_params_command(priv,
  1717. &(priv->qos_data.def_qos_parm));
  1718. }
  1719. }
  1720. #endif /* CONFIG_IWL3945_QOS */
  1721. /*
  1722. * Power management (not Tx power!) functions
  1723. */
  1724. #define MSEC_TO_USEC 1024
  1725. #define NOSLP __constant_cpu_to_le32(0)
  1726. #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK
  1727. #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
  1728. #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
  1729. __constant_cpu_to_le32(X1), \
  1730. __constant_cpu_to_le32(X2), \
  1731. __constant_cpu_to_le32(X3), \
  1732. __constant_cpu_to_le32(X4)}
  1733. /* default power management (not Tx power) table values */
  1734. /* for tim 0-10 */
  1735. static struct iwl3945_power_vec_entry range_0[IWL_POWER_AC] = {
  1736. {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
  1737. {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
  1738. {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
  1739. {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
  1740. {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
  1741. {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
  1742. };
  1743. /* for tim > 10 */
  1744. static struct iwl3945_power_vec_entry range_1[IWL_POWER_AC] = {
  1745. {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
  1746. {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500),
  1747. SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
  1748. {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300),
  1749. SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
  1750. {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100),
  1751. SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
  1752. {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
  1753. {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25),
  1754. SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
  1755. };
  1756. int iwl3945_power_init_handle(struct iwl3945_priv *priv)
  1757. {
  1758. int rc = 0, i;
  1759. struct iwl3945_power_mgr *pow_data;
  1760. int size = sizeof(struct iwl3945_power_vec_entry) * IWL_POWER_AC;
  1761. u16 pci_pm;
  1762. IWL_DEBUG_POWER("Initialize power \n");
  1763. pow_data = &(priv->power_data);
  1764. memset(pow_data, 0, sizeof(*pow_data));
  1765. pow_data->active_index = IWL_POWER_RANGE_0;
  1766. pow_data->dtim_val = 0xffff;
  1767. memcpy(&pow_data->pwr_range_0[0], &range_0[0], size);
  1768. memcpy(&pow_data->pwr_range_1[0], &range_1[0], size);
  1769. rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm);
  1770. if (rc != 0)
  1771. return 0;
  1772. else {
  1773. struct iwl3945_powertable_cmd *cmd;
  1774. IWL_DEBUG_POWER("adjust power command flags\n");
  1775. for (i = 0; i < IWL_POWER_AC; i++) {
  1776. cmd = &pow_data->pwr_range_0[i].cmd;
  1777. if (pci_pm & 0x1)
  1778. cmd->flags &= ~IWL_POWER_PCI_PM_MSK;
  1779. else
  1780. cmd->flags |= IWL_POWER_PCI_PM_MSK;
  1781. }
  1782. }
  1783. return rc;
  1784. }
  1785. static int iwl3945_update_power_cmd(struct iwl3945_priv *priv,
  1786. struct iwl3945_powertable_cmd *cmd, u32 mode)
  1787. {
  1788. int rc = 0, i;
  1789. u8 skip;
  1790. u32 max_sleep = 0;
  1791. struct iwl3945_power_vec_entry *range;
  1792. u8 period = 0;
  1793. struct iwl3945_power_mgr *pow_data;
  1794. if (mode > IWL_POWER_INDEX_5) {
  1795. IWL_DEBUG_POWER("Error invalid power mode \n");
  1796. return -1;
  1797. }
  1798. pow_data = &(priv->power_data);
  1799. if (pow_data->active_index == IWL_POWER_RANGE_0)
  1800. range = &pow_data->pwr_range_0[0];
  1801. else
  1802. range = &pow_data->pwr_range_1[1];
  1803. memcpy(cmd, &range[mode].cmd, sizeof(struct iwl3945_powertable_cmd));
  1804. #ifdef IWL_MAC80211_DISABLE
  1805. if (priv->assoc_network != NULL) {
  1806. unsigned long flags;
  1807. period = priv->assoc_network->tim.tim_period;
  1808. }
  1809. #endif /*IWL_MAC80211_DISABLE */
  1810. skip = range[mode].no_dtim;
  1811. if (period == 0) {
  1812. period = 1;
  1813. skip = 0;
  1814. }
  1815. if (skip == 0) {
  1816. max_sleep = period;
  1817. cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK;
  1818. } else {
  1819. __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1];
  1820. max_sleep = (le32_to_cpu(slp_itrvl) / period) * period;
  1821. cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK;
  1822. }
  1823. for (i = 0; i < IWL_POWER_VEC_SIZE; i++) {
  1824. if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep)
  1825. cmd->sleep_interval[i] = cpu_to_le32(max_sleep);
  1826. }
  1827. IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags);
  1828. IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout));
  1829. IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout));
  1830. IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
  1831. le32_to_cpu(cmd->sleep_interval[0]),
  1832. le32_to_cpu(cmd->sleep_interval[1]),
  1833. le32_to_cpu(cmd->sleep_interval[2]),
  1834. le32_to_cpu(cmd->sleep_interval[3]),
  1835. le32_to_cpu(cmd->sleep_interval[4]));
  1836. return rc;
  1837. }
  1838. static int iwl3945_send_power_mode(struct iwl3945_priv *priv, u32 mode)
  1839. {
  1840. u32 uninitialized_var(final_mode);
  1841. int rc;
  1842. struct iwl3945_powertable_cmd cmd;
  1843. /* If on battery, set to 3,
  1844. * if plugged into AC power, set to CAM ("continuously aware mode"),
  1845. * else user level */
  1846. switch (mode) {
  1847. case IWL_POWER_BATTERY:
  1848. final_mode = IWL_POWER_INDEX_3;
  1849. break;
  1850. case IWL_POWER_AC:
  1851. final_mode = IWL_POWER_MODE_CAM;
  1852. break;
  1853. default:
  1854. final_mode = mode;
  1855. break;
  1856. }
  1857. iwl3945_update_power_cmd(priv, &cmd, final_mode);
  1858. rc = iwl3945_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd);
  1859. if (final_mode == IWL_POWER_MODE_CAM)
  1860. clear_bit(STATUS_POWER_PMI, &priv->status);
  1861. else
  1862. set_bit(STATUS_POWER_PMI, &priv->status);
  1863. return rc;
  1864. }
  1865. int iwl3945_is_network_packet(struct iwl3945_priv *priv, struct ieee80211_hdr *header)
  1866. {
  1867. /* Filter incoming packets to determine if they are targeted toward
  1868. * this network, discarding packets coming from ourselves */
  1869. switch (priv->iw_mode) {
  1870. case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */
  1871. /* packets from our adapter are dropped (echo) */
  1872. if (!compare_ether_addr(header->addr2, priv->mac_addr))
  1873. return 0;
  1874. /* {broad,multi}cast packets to our IBSS go through */
  1875. if (is_multicast_ether_addr(header->addr1))
  1876. return !compare_ether_addr(header->addr3, priv->bssid);
  1877. /* packets to our adapter go through */
  1878. return !compare_ether_addr(header->addr1, priv->mac_addr);
  1879. case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */
  1880. /* packets from our adapter are dropped (echo) */
  1881. if (!compare_ether_addr(header->addr3, priv->mac_addr))
  1882. return 0;
  1883. /* {broad,multi}cast packets to our BSS go through */
  1884. if (is_multicast_ether_addr(header->addr1))
  1885. return !compare_ether_addr(header->addr2, priv->bssid);
  1886. /* packets to our adapter go through */
  1887. return !compare_ether_addr(header->addr1, priv->mac_addr);
  1888. }
  1889. return 1;
  1890. }
  1891. #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
  1892. static const char *iwl3945_get_tx_fail_reason(u32 status)
  1893. {
  1894. switch (status & TX_STATUS_MSK) {
  1895. case TX_STATUS_SUCCESS:
  1896. return "SUCCESS";
  1897. TX_STATUS_ENTRY(SHORT_LIMIT);
  1898. TX_STATUS_ENTRY(LONG_LIMIT);
  1899. TX_STATUS_ENTRY(FIFO_UNDERRUN);
  1900. TX_STATUS_ENTRY(MGMNT_ABORT);
  1901. TX_STATUS_ENTRY(NEXT_FRAG);
  1902. TX_STATUS_ENTRY(LIFE_EXPIRE);
  1903. TX_STATUS_ENTRY(DEST_PS);
  1904. TX_STATUS_ENTRY(ABORTED);
  1905. TX_STATUS_ENTRY(BT_RETRY);
  1906. TX_STATUS_ENTRY(STA_INVALID);
  1907. TX_STATUS_ENTRY(FRAG_DROPPED);
  1908. TX_STATUS_ENTRY(TID_DISABLE);
  1909. TX_STATUS_ENTRY(FRAME_FLUSHED);
  1910. TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL);
  1911. TX_STATUS_ENTRY(TX_LOCKED);
  1912. TX_STATUS_ENTRY(NO_BEACON_ON_RADAR);
  1913. }
  1914. return "UNKNOWN";
  1915. }
  1916. /**
  1917. * iwl3945_scan_cancel - Cancel any currently executing HW scan
  1918. *
  1919. * NOTE: priv->mutex is not required before calling this function
  1920. */
  1921. static int iwl3945_scan_cancel(struct iwl3945_priv *priv)
  1922. {
  1923. if (!test_bit(STATUS_SCAN_HW, &priv->status)) {
  1924. clear_bit(STATUS_SCANNING, &priv->status);
  1925. return 0;
  1926. }
  1927. if (test_bit(STATUS_SCANNING, &priv->status)) {
  1928. if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  1929. IWL_DEBUG_SCAN("Queuing scan abort.\n");
  1930. set_bit(STATUS_SCAN_ABORTING, &priv->status);
  1931. queue_work(priv->workqueue, &priv->abort_scan);
  1932. } else
  1933. IWL_DEBUG_SCAN("Scan abort already in progress.\n");
  1934. return test_bit(STATUS_SCANNING, &priv->status);
  1935. }
  1936. return 0;
  1937. }
  1938. /**
  1939. * iwl3945_scan_cancel_timeout - Cancel any currently executing HW scan
  1940. * @ms: amount of time to wait (in milliseconds) for scan to abort
  1941. *
  1942. * NOTE: priv->mutex must be held before calling this function
  1943. */
  1944. static int iwl3945_scan_cancel_timeout(struct iwl3945_priv *priv, unsigned long ms)
  1945. {
  1946. unsigned long now = jiffies;
  1947. int ret;
  1948. ret = iwl3945_scan_cancel(priv);
  1949. if (ret && ms) {
  1950. mutex_unlock(&priv->mutex);
  1951. while (!time_after(jiffies, now + msecs_to_jiffies(ms)) &&
  1952. test_bit(STATUS_SCANNING, &priv->status))
  1953. msleep(1);
  1954. mutex_lock(&priv->mutex);
  1955. return test_bit(STATUS_SCANNING, &priv->status);
  1956. }
  1957. return ret;
  1958. }
  1959. static void iwl3945_sequence_reset(struct iwl3945_priv *priv)
  1960. {
  1961. /* Reset ieee stats */
  1962. /* We don't reset the net_device_stats (ieee->stats) on
  1963. * re-association */
  1964. priv->last_seq_num = -1;
  1965. priv->last_frag_num = -1;
  1966. priv->last_packet_time = 0;
  1967. iwl3945_scan_cancel(priv);
  1968. }
  1969. #define MAX_UCODE_BEACON_INTERVAL 1024
  1970. #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
  1971. static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val)
  1972. {
  1973. u16 new_val = 0;
  1974. u16 beacon_factor = 0;
  1975. beacon_factor =
  1976. (beacon_val + MAX_UCODE_BEACON_INTERVAL)
  1977. / MAX_UCODE_BEACON_INTERVAL;
  1978. new_val = beacon_val / beacon_factor;
  1979. return cpu_to_le16(new_val);
  1980. }
  1981. static void iwl3945_setup_rxon_timing(struct iwl3945_priv *priv)
  1982. {
  1983. u64 interval_tm_unit;
  1984. u64 tsf, result;
  1985. unsigned long flags;
  1986. struct ieee80211_conf *conf = NULL;
  1987. u16 beacon_int = 0;
  1988. conf = ieee80211_get_hw_conf(priv->hw);
  1989. spin_lock_irqsave(&priv->lock, flags);
  1990. priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp1);
  1991. priv->rxon_timing.timestamp.dw[0] = cpu_to_le32(priv->timestamp0);
  1992. priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
  1993. tsf = priv->timestamp1;
  1994. tsf = ((tsf << 32) | priv->timestamp0);
  1995. beacon_int = priv->beacon_int;
  1996. spin_unlock_irqrestore(&priv->lock, flags);
  1997. if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
  1998. if (beacon_int == 0) {
  1999. priv->rxon_timing.beacon_interval = cpu_to_le16(100);
  2000. priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
  2001. } else {
  2002. priv->rxon_timing.beacon_interval =
  2003. cpu_to_le16(beacon_int);
  2004. priv->rxon_timing.beacon_interval =
  2005. iwl3945_adjust_beacon_interval(
  2006. le16_to_cpu(priv->rxon_timing.beacon_interval));
  2007. }
  2008. priv->rxon_timing.atim_window = 0;
  2009. } else {
  2010. priv->rxon_timing.beacon_interval =
  2011. iwl3945_adjust_beacon_interval(conf->beacon_int);
  2012. /* TODO: we need to get atim_window from upper stack
  2013. * for now we set to 0 */
  2014. priv->rxon_timing.atim_window = 0;
  2015. }
  2016. interval_tm_unit =
  2017. (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
  2018. result = do_div(tsf, interval_tm_unit);
  2019. priv->rxon_timing.beacon_init_val =
  2020. cpu_to_le32((u32) ((u64) interval_tm_unit - result));
  2021. IWL_DEBUG_ASSOC
  2022. ("beacon interval %d beacon timer %d beacon tim %d\n",
  2023. le16_to_cpu(priv->rxon_timing.beacon_interval),
  2024. le32_to_cpu(priv->rxon_timing.beacon_init_val),
  2025. le16_to_cpu(priv->rxon_timing.atim_window));
  2026. }
  2027. static int iwl3945_scan_initiate(struct iwl3945_priv *priv)
  2028. {
  2029. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  2030. IWL_ERROR("APs don't scan.\n");
  2031. return 0;
  2032. }
  2033. if (!iwl3945_is_ready_rf(priv)) {
  2034. IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
  2035. return -EIO;
  2036. }
  2037. if (test_bit(STATUS_SCANNING, &priv->status)) {
  2038. IWL_DEBUG_SCAN("Scan already in progress.\n");
  2039. return -EAGAIN;
  2040. }
  2041. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  2042. IWL_DEBUG_SCAN("Scan request while abort pending. "
  2043. "Queuing.\n");
  2044. return -EAGAIN;
  2045. }
  2046. IWL_DEBUG_INFO("Starting scan...\n");
  2047. priv->scan_bands = 2;
  2048. set_bit(STATUS_SCANNING, &priv->status);
  2049. priv->scan_start = jiffies;
  2050. priv->scan_pass_start = priv->scan_start;
  2051. queue_work(priv->workqueue, &priv->request_scan);
  2052. return 0;
  2053. }
  2054. static int iwl3945_set_rxon_hwcrypto(struct iwl3945_priv *priv, int hw_decrypt)
  2055. {
  2056. struct iwl3945_rxon_cmd *rxon = &priv->staging_rxon;
  2057. if (hw_decrypt)
  2058. rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
  2059. else
  2060. rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
  2061. return 0;
  2062. }
  2063. static void iwl3945_set_flags_for_phymode(struct iwl3945_priv *priv, u8 phymode)
  2064. {
  2065. if (phymode == MODE_IEEE80211A) {
  2066. priv->staging_rxon.flags &=
  2067. ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
  2068. | RXON_FLG_CCK_MSK);
  2069. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  2070. } else {
  2071. /* Copied from iwl3945_bg_post_associate() */
  2072. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
  2073. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  2074. else
  2075. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  2076. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  2077. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  2078. priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
  2079. priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
  2080. priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
  2081. }
  2082. }
  2083. /*
  2084. * initialize rxon structure with default values from eeprom
  2085. */
  2086. static void iwl3945_connection_init_rx_config(struct iwl3945_priv *priv)
  2087. {
  2088. const struct iwl3945_channel_info *ch_info;
  2089. memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
  2090. switch (priv->iw_mode) {
  2091. case IEEE80211_IF_TYPE_AP:
  2092. priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
  2093. break;
  2094. case IEEE80211_IF_TYPE_STA:
  2095. priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
  2096. priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
  2097. break;
  2098. case IEEE80211_IF_TYPE_IBSS:
  2099. priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
  2100. priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
  2101. priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
  2102. RXON_FILTER_ACCEPT_GRP_MSK;
  2103. break;
  2104. case IEEE80211_IF_TYPE_MNTR:
  2105. priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
  2106. priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
  2107. RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
  2108. break;
  2109. }
  2110. #if 0
  2111. /* TODO: Figure out when short_preamble would be set and cache from
  2112. * that */
  2113. if (!hw_to_local(priv->hw)->short_preamble)
  2114. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  2115. else
  2116. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  2117. #endif
  2118. ch_info = iwl3945_get_channel_info(priv, priv->phymode,
  2119. le16_to_cpu(priv->staging_rxon.channel));
  2120. if (!ch_info)
  2121. ch_info = &priv->channel_info[0];
  2122. /*
  2123. * in some case A channels are all non IBSS
  2124. * in this case force B/G channel
  2125. */
  2126. if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
  2127. !(is_channel_ibss(ch_info)))
  2128. ch_info = &priv->channel_info[0];
  2129. priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
  2130. if (is_channel_a_band(ch_info))
  2131. priv->phymode = MODE_IEEE80211A;
  2132. else
  2133. priv->phymode = MODE_IEEE80211G;
  2134. iwl3945_set_flags_for_phymode(priv, priv->phymode);
  2135. priv->staging_rxon.ofdm_basic_rates =
  2136. (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  2137. priv->staging_rxon.cck_basic_rates =
  2138. (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  2139. }
  2140. static int iwl3945_set_mode(struct iwl3945_priv *priv, int mode)
  2141. {
  2142. if (!iwl3945_is_ready_rf(priv))
  2143. return -EAGAIN;
  2144. if (mode == IEEE80211_IF_TYPE_IBSS) {
  2145. const struct iwl3945_channel_info *ch_info;
  2146. ch_info = iwl3945_get_channel_info(priv,
  2147. priv->phymode,
  2148. le16_to_cpu(priv->staging_rxon.channel));
  2149. if (!ch_info || !is_channel_ibss(ch_info)) {
  2150. IWL_ERROR("channel %d not IBSS channel\n",
  2151. le16_to_cpu(priv->staging_rxon.channel));
  2152. return -EINVAL;
  2153. }
  2154. }
  2155. cancel_delayed_work(&priv->scan_check);
  2156. if (iwl3945_scan_cancel_timeout(priv, 100)) {
  2157. IWL_WARNING("Aborted scan still in progress after 100ms\n");
  2158. IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
  2159. return -EAGAIN;
  2160. }
  2161. priv->iw_mode = mode;
  2162. iwl3945_connection_init_rx_config(priv);
  2163. memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  2164. iwl3945_clear_stations_table(priv);
  2165. iwl3945_commit_rxon(priv);
  2166. return 0;
  2167. }
  2168. static void iwl3945_build_tx_cmd_hwcrypto(struct iwl3945_priv *priv,
  2169. struct ieee80211_tx_control *ctl,
  2170. struct iwl3945_cmd *cmd,
  2171. struct sk_buff *skb_frag,
  2172. int last_frag)
  2173. {
  2174. struct iwl3945_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo;
  2175. switch (keyinfo->alg) {
  2176. case ALG_CCMP:
  2177. cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM;
  2178. memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen);
  2179. IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
  2180. break;
  2181. case ALG_TKIP:
  2182. #if 0
  2183. cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP;
  2184. if (last_frag)
  2185. memcpy(cmd->cmd.tx.tkip_mic.byte, skb_frag->tail - 8,
  2186. 8);
  2187. else
  2188. memset(cmd->cmd.tx.tkip_mic.byte, 0, 8);
  2189. #endif
  2190. break;
  2191. case ALG_WEP:
  2192. cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP |
  2193. (ctl->key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
  2194. if (keyinfo->keylen == 13)
  2195. cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128;
  2196. memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen);
  2197. IWL_DEBUG_TX("Configuring packet for WEP encryption "
  2198. "with key %d\n", ctl->key_idx);
  2199. break;
  2200. default:
  2201. printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg);
  2202. break;
  2203. }
  2204. }
  2205. /*
  2206. * handle build REPLY_TX command notification.
  2207. */
  2208. static void iwl3945_build_tx_cmd_basic(struct iwl3945_priv *priv,
  2209. struct iwl3945_cmd *cmd,
  2210. struct ieee80211_tx_control *ctrl,
  2211. struct ieee80211_hdr *hdr,
  2212. int is_unicast, u8 std_id)
  2213. {
  2214. __le16 *qc;
  2215. u16 fc = le16_to_cpu(hdr->frame_control);
  2216. __le32 tx_flags = cmd->cmd.tx.tx_flags;
  2217. cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  2218. if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) {
  2219. tx_flags |= TX_CMD_FLG_ACK_MSK;
  2220. if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)
  2221. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  2222. if (ieee80211_is_probe_response(fc) &&
  2223. !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
  2224. tx_flags |= TX_CMD_FLG_TSF_MSK;
  2225. } else {
  2226. tx_flags &= (~TX_CMD_FLG_ACK_MSK);
  2227. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  2228. }
  2229. cmd->cmd.tx.sta_id = std_id;
  2230. if (ieee80211_get_morefrag(hdr))
  2231. tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
  2232. qc = ieee80211_get_qos_ctrl(hdr);
  2233. if (qc) {
  2234. cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf);
  2235. tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
  2236. } else
  2237. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  2238. if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) {
  2239. tx_flags |= TX_CMD_FLG_RTS_MSK;
  2240. tx_flags &= ~TX_CMD_FLG_CTS_MSK;
  2241. } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) {
  2242. tx_flags &= ~TX_CMD_FLG_RTS_MSK;
  2243. tx_flags |= TX_CMD_FLG_CTS_MSK;
  2244. }
  2245. if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
  2246. tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
  2247. tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
  2248. if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
  2249. if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ ||
  2250. (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ)
  2251. cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3);
  2252. else
  2253. cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2);
  2254. } else
  2255. cmd->cmd.tx.timeout.pm_frame_timeout = 0;
  2256. cmd->cmd.tx.driver_txop = 0;
  2257. cmd->cmd.tx.tx_flags = tx_flags;
  2258. cmd->cmd.tx.next_frame_len = 0;
  2259. }
  2260. /**
  2261. * iwl3945_get_sta_id - Find station's index within station table
  2262. */
  2263. static int iwl3945_get_sta_id(struct iwl3945_priv *priv, struct ieee80211_hdr *hdr)
  2264. {
  2265. int sta_id;
  2266. u16 fc = le16_to_cpu(hdr->frame_control);
  2267. /* If this frame is broadcast or management, use broadcast station id */
  2268. if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
  2269. is_multicast_ether_addr(hdr->addr1))
  2270. return priv->hw_setting.bcast_sta_id;
  2271. switch (priv->iw_mode) {
  2272. /* If we are a client station in a BSS network, use the special
  2273. * AP station entry (that's the only station we communicate with) */
  2274. case IEEE80211_IF_TYPE_STA:
  2275. return IWL_AP_ID;
  2276. /* If we are an AP, then find the station, or use BCAST */
  2277. case IEEE80211_IF_TYPE_AP:
  2278. sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
  2279. if (sta_id != IWL_INVALID_STATION)
  2280. return sta_id;
  2281. return priv->hw_setting.bcast_sta_id;
  2282. /* If this frame is going out to an IBSS network, find the station,
  2283. * or create a new station table entry */
  2284. case IEEE80211_IF_TYPE_IBSS: {
  2285. DECLARE_MAC_BUF(mac);
  2286. /* Create new station table entry */
  2287. sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
  2288. if (sta_id != IWL_INVALID_STATION)
  2289. return sta_id;
  2290. sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
  2291. if (sta_id != IWL_INVALID_STATION)
  2292. return sta_id;
  2293. IWL_DEBUG_DROP("Station %s not in station map. "
  2294. "Defaulting to broadcast...\n",
  2295. print_mac(mac, hdr->addr1));
  2296. iwl3945_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
  2297. return priv->hw_setting.bcast_sta_id;
  2298. }
  2299. default:
  2300. IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode);
  2301. return priv->hw_setting.bcast_sta_id;
  2302. }
  2303. }
  2304. /*
  2305. * start REPLY_TX command process
  2306. */
  2307. static int iwl3945_tx_skb(struct iwl3945_priv *priv,
  2308. struct sk_buff *skb, struct ieee80211_tx_control *ctl)
  2309. {
  2310. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  2311. struct iwl3945_tfd_frame *tfd;
  2312. u32 *control_flags;
  2313. int txq_id = ctl->queue;
  2314. struct iwl3945_tx_queue *txq = NULL;
  2315. struct iwl3945_queue *q = NULL;
  2316. dma_addr_t phys_addr;
  2317. dma_addr_t txcmd_phys;
  2318. struct iwl3945_cmd *out_cmd = NULL;
  2319. u16 len, idx, len_org;
  2320. u8 id, hdr_len, unicast;
  2321. u8 sta_id;
  2322. u16 seq_number = 0;
  2323. u16 fc;
  2324. __le16 *qc;
  2325. u8 wait_write_ptr = 0;
  2326. unsigned long flags;
  2327. int rc;
  2328. spin_lock_irqsave(&priv->lock, flags);
  2329. if (iwl3945_is_rfkill(priv)) {
  2330. IWL_DEBUG_DROP("Dropping - RF KILL\n");
  2331. goto drop_unlock;
  2332. }
  2333. if (!priv->interface_id) {
  2334. IWL_DEBUG_DROP("Dropping - !priv->interface_id\n");
  2335. goto drop_unlock;
  2336. }
  2337. if ((ctl->tx_rate & 0xFF) == IWL_INVALID_RATE) {
  2338. IWL_ERROR("ERROR: No TX rate available.\n");
  2339. goto drop_unlock;
  2340. }
  2341. unicast = !is_multicast_ether_addr(hdr->addr1);
  2342. id = 0;
  2343. fc = le16_to_cpu(hdr->frame_control);
  2344. #ifdef CONFIG_IWL3945_DEBUG
  2345. if (ieee80211_is_auth(fc))
  2346. IWL_DEBUG_TX("Sending AUTH frame\n");
  2347. else if (ieee80211_is_assoc_request(fc))
  2348. IWL_DEBUG_TX("Sending ASSOC frame\n");
  2349. else if (ieee80211_is_reassoc_request(fc))
  2350. IWL_DEBUG_TX("Sending REASSOC frame\n");
  2351. #endif
  2352. /* drop all data frame if we are not associated */
  2353. if (!iwl3945_is_associated(priv) && !priv->assoc_id &&
  2354. ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)) {
  2355. IWL_DEBUG_DROP("Dropping - !iwl3945_is_associated\n");
  2356. goto drop_unlock;
  2357. }
  2358. spin_unlock_irqrestore(&priv->lock, flags);
  2359. hdr_len = ieee80211_get_hdrlen(fc);
  2360. /* Find (or create) index into station table for destination station */
  2361. sta_id = iwl3945_get_sta_id(priv, hdr);
  2362. if (sta_id == IWL_INVALID_STATION) {
  2363. DECLARE_MAC_BUF(mac);
  2364. IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n",
  2365. print_mac(mac, hdr->addr1));
  2366. goto drop;
  2367. }
  2368. IWL_DEBUG_RATE("station Id %d\n", sta_id);
  2369. qc = ieee80211_get_qos_ctrl(hdr);
  2370. if (qc) {
  2371. u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
  2372. seq_number = priv->stations[sta_id].tid[tid].seq_number &
  2373. IEEE80211_SCTL_SEQ;
  2374. hdr->seq_ctrl = cpu_to_le16(seq_number) |
  2375. (hdr->seq_ctrl &
  2376. __constant_cpu_to_le16(IEEE80211_SCTL_FRAG));
  2377. seq_number += 0x10;
  2378. }
  2379. /* Descriptor for chosen Tx queue */
  2380. txq = &priv->txq[txq_id];
  2381. q = &txq->q;
  2382. spin_lock_irqsave(&priv->lock, flags);
  2383. /* Set up first empty TFD within this queue's circular TFD buffer */
  2384. tfd = &txq->bd[q->write_ptr];
  2385. memset(tfd, 0, sizeof(*tfd));
  2386. control_flags = (u32 *) tfd;
  2387. idx = get_cmd_index(q, q->write_ptr, 0);
  2388. /* Set up driver data for this TFD */
  2389. memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl3945_tx_info));
  2390. txq->txb[q->write_ptr].skb[0] = skb;
  2391. memcpy(&(txq->txb[q->write_ptr].status.control),
  2392. ctl, sizeof(struct ieee80211_tx_control));
  2393. /* Init first empty entry in queue's array of Tx/cmd buffers */
  2394. out_cmd = &txq->cmd[idx];
  2395. memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
  2396. memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx));
  2397. /*
  2398. * Set up the Tx-command (not MAC!) header.
  2399. * Store the chosen Tx queue and TFD index within the sequence field;
  2400. * after Tx, uCode's Tx response will return this value so driver can
  2401. * locate the frame within the tx queue and do post-tx processing.
  2402. */
  2403. out_cmd->hdr.cmd = REPLY_TX;
  2404. out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
  2405. INDEX_TO_SEQ(q->write_ptr)));
  2406. /* Copy MAC header from skb into command buffer */
  2407. memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len);
  2408. /*
  2409. * Use the first empty entry in this queue's command buffer array
  2410. * to contain the Tx command and MAC header concatenated together
  2411. * (payload data will be in another buffer).
  2412. * Size of this varies, due to varying MAC header length.
  2413. * If end is not dword aligned, we'll have 2 extra bytes at the end
  2414. * of the MAC header (device reads on dword boundaries).
  2415. * We'll tell device about this padding later.
  2416. */
  2417. len = priv->hw_setting.tx_cmd_len +
  2418. sizeof(struct iwl3945_cmd_header) + hdr_len;
  2419. len_org = len;
  2420. len = (len + 3) & ~3;
  2421. if (len_org != len)
  2422. len_org = 1;
  2423. else
  2424. len_org = 0;
  2425. /* Physical address of this Tx command's header (not MAC header!),
  2426. * within command buffer array. */
  2427. txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl3945_cmd) * idx +
  2428. offsetof(struct iwl3945_cmd, hdr);
  2429. /* Add buffer containing Tx command and MAC(!) header to TFD's
  2430. * first entry */
  2431. iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len);
  2432. if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT))
  2433. iwl3945_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0);
  2434. /* Set up TFD's 2nd entry to point directly to remainder of skb,
  2435. * if any (802.11 null frames have no payload). */
  2436. len = skb->len - hdr_len;
  2437. if (len) {
  2438. phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
  2439. len, PCI_DMA_TODEVICE);
  2440. iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len);
  2441. }
  2442. if (!len)
  2443. /* If there is no payload, then we use only one Tx buffer */
  2444. *control_flags = TFD_CTL_COUNT_SET(1);
  2445. else
  2446. /* Else use 2 buffers.
  2447. * Tell 3945 about any padding after MAC header */
  2448. *control_flags = TFD_CTL_COUNT_SET(2) |
  2449. TFD_CTL_PAD_SET(U32_PAD(len));
  2450. /* Total # bytes to be transmitted */
  2451. len = (u16)skb->len;
  2452. out_cmd->cmd.tx.len = cpu_to_le16(len);
  2453. /* TODO need this for burst mode later on */
  2454. iwl3945_build_tx_cmd_basic(priv, out_cmd, ctl, hdr, unicast, sta_id);
  2455. /* set is_hcca to 0; it probably will never be implemented */
  2456. iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, ctl, hdr, sta_id, 0);
  2457. out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
  2458. out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
  2459. if (!ieee80211_get_morefrag(hdr)) {
  2460. txq->need_update = 1;
  2461. if (qc) {
  2462. u8 tid = (u8)(le16_to_cpu(*qc) & 0xf);
  2463. priv->stations[sta_id].tid[tid].seq_number = seq_number;
  2464. }
  2465. } else {
  2466. wait_write_ptr = 1;
  2467. txq->need_update = 0;
  2468. }
  2469. iwl3945_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload,
  2470. sizeof(out_cmd->cmd.tx));
  2471. iwl3945_print_hex_dump(IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr,
  2472. ieee80211_get_hdrlen(fc));
  2473. /* Tell device the write index *just past* this latest filled TFD */
  2474. q->write_ptr = iwl3945_queue_inc_wrap(q->write_ptr, q->n_bd);
  2475. rc = iwl3945_tx_queue_update_write_ptr(priv, txq);
  2476. spin_unlock_irqrestore(&priv->lock, flags);
  2477. if (rc)
  2478. return rc;
  2479. if ((iwl3945_queue_space(q) < q->high_mark)
  2480. && priv->mac80211_registered) {
  2481. if (wait_write_ptr) {
  2482. spin_lock_irqsave(&priv->lock, flags);
  2483. txq->need_update = 1;
  2484. iwl3945_tx_queue_update_write_ptr(priv, txq);
  2485. spin_unlock_irqrestore(&priv->lock, flags);
  2486. }
  2487. ieee80211_stop_queue(priv->hw, ctl->queue);
  2488. }
  2489. return 0;
  2490. drop_unlock:
  2491. spin_unlock_irqrestore(&priv->lock, flags);
  2492. drop:
  2493. return -1;
  2494. }
  2495. static void iwl3945_set_rate(struct iwl3945_priv *priv)
  2496. {
  2497. const struct ieee80211_hw_mode *hw = NULL;
  2498. struct ieee80211_rate *rate;
  2499. int i;
  2500. hw = iwl3945_get_hw_mode(priv, priv->phymode);
  2501. if (!hw) {
  2502. IWL_ERROR("Failed to set rate: unable to get hw mode\n");
  2503. return;
  2504. }
  2505. priv->active_rate = 0;
  2506. priv->active_rate_basic = 0;
  2507. IWL_DEBUG_RATE("Setting rates for 802.11%c\n",
  2508. hw->mode == MODE_IEEE80211A ?
  2509. 'a' : ((hw->mode == MODE_IEEE80211B) ? 'b' : 'g'));
  2510. for (i = 0; i < hw->num_rates; i++) {
  2511. rate = &(hw->rates[i]);
  2512. if ((rate->val < IWL_RATE_COUNT) &&
  2513. (rate->flags & IEEE80211_RATE_SUPPORTED)) {
  2514. IWL_DEBUG_RATE("Adding rate index %d (plcp %d)%s\n",
  2515. rate->val, iwl3945_rates[rate->val].plcp,
  2516. (rate->flags & IEEE80211_RATE_BASIC) ?
  2517. "*" : "");
  2518. priv->active_rate |= (1 << rate->val);
  2519. if (rate->flags & IEEE80211_RATE_BASIC)
  2520. priv->active_rate_basic |= (1 << rate->val);
  2521. } else
  2522. IWL_DEBUG_RATE("Not adding rate %d (plcp %d)\n",
  2523. rate->val, iwl3945_rates[rate->val].plcp);
  2524. }
  2525. IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
  2526. priv->active_rate, priv->active_rate_basic);
  2527. /*
  2528. * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
  2529. * otherwise set it to the default of all CCK rates and 6, 12, 24 for
  2530. * OFDM
  2531. */
  2532. if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
  2533. priv->staging_rxon.cck_basic_rates =
  2534. ((priv->active_rate_basic &
  2535. IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
  2536. else
  2537. priv->staging_rxon.cck_basic_rates =
  2538. (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  2539. if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
  2540. priv->staging_rxon.ofdm_basic_rates =
  2541. ((priv->active_rate_basic &
  2542. (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
  2543. IWL_FIRST_OFDM_RATE) & 0xFF;
  2544. else
  2545. priv->staging_rxon.ofdm_basic_rates =
  2546. (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  2547. }
  2548. static void iwl3945_radio_kill_sw(struct iwl3945_priv *priv, int disable_radio)
  2549. {
  2550. unsigned long flags;
  2551. if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
  2552. return;
  2553. IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
  2554. disable_radio ? "OFF" : "ON");
  2555. if (disable_radio) {
  2556. iwl3945_scan_cancel(priv);
  2557. /* FIXME: This is a workaround for AP */
  2558. if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
  2559. spin_lock_irqsave(&priv->lock, flags);
  2560. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_SET,
  2561. CSR_UCODE_SW_BIT_RFKILL);
  2562. spin_unlock_irqrestore(&priv->lock, flags);
  2563. iwl3945_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0);
  2564. set_bit(STATUS_RF_KILL_SW, &priv->status);
  2565. }
  2566. return;
  2567. }
  2568. spin_lock_irqsave(&priv->lock, flags);
  2569. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  2570. clear_bit(STATUS_RF_KILL_SW, &priv->status);
  2571. spin_unlock_irqrestore(&priv->lock, flags);
  2572. /* wake up ucode */
  2573. msleep(10);
  2574. spin_lock_irqsave(&priv->lock, flags);
  2575. iwl3945_read32(priv, CSR_UCODE_DRV_GP1);
  2576. if (!iwl3945_grab_nic_access(priv))
  2577. iwl3945_release_nic_access(priv);
  2578. spin_unlock_irqrestore(&priv->lock, flags);
  2579. if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
  2580. IWL_DEBUG_RF_KILL("Can not turn radio back on - "
  2581. "disabled by HW switch\n");
  2582. return;
  2583. }
  2584. queue_work(priv->workqueue, &priv->restart);
  2585. return;
  2586. }
  2587. void iwl3945_set_decrypted_flag(struct iwl3945_priv *priv, struct sk_buff *skb,
  2588. u32 decrypt_res, struct ieee80211_rx_status *stats)
  2589. {
  2590. u16 fc =
  2591. le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control);
  2592. if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
  2593. return;
  2594. if (!(fc & IEEE80211_FCTL_PROTECTED))
  2595. return;
  2596. IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
  2597. switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
  2598. case RX_RES_STATUS_SEC_TYPE_TKIP:
  2599. if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
  2600. RX_RES_STATUS_BAD_ICV_MIC)
  2601. stats->flag |= RX_FLAG_MMIC_ERROR;
  2602. case RX_RES_STATUS_SEC_TYPE_WEP:
  2603. case RX_RES_STATUS_SEC_TYPE_CCMP:
  2604. if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
  2605. RX_RES_STATUS_DECRYPT_OK) {
  2606. IWL_DEBUG_RX("hw decrypt successfully!!!\n");
  2607. stats->flag |= RX_FLAG_DECRYPTED;
  2608. }
  2609. break;
  2610. default:
  2611. break;
  2612. }
  2613. }
  2614. void iwl3945_handle_data_packet_monitor(struct iwl3945_priv *priv,
  2615. struct iwl3945_rx_mem_buffer *rxb,
  2616. void *data, short len,
  2617. struct ieee80211_rx_status *stats,
  2618. u16 phy_flags)
  2619. {
  2620. struct iwl3945_rt_rx_hdr *iwl3945_rt;
  2621. /* First cache any information we need before we overwrite
  2622. * the information provided in the skb from the hardware */
  2623. s8 signal = stats->ssi;
  2624. s8 noise = 0;
  2625. int rate = stats->rate;
  2626. u64 tsf = stats->mactime;
  2627. __le16 phy_flags_hw = cpu_to_le16(phy_flags);
  2628. /* We received data from the HW, so stop the watchdog */
  2629. if (len > IWL_RX_BUF_SIZE - sizeof(*iwl3945_rt)) {
  2630. IWL_DEBUG_DROP("Dropping too large packet in monitor\n");
  2631. return;
  2632. }
  2633. /* copy the frame data to write after where the radiotap header goes */
  2634. iwl3945_rt = (void *)rxb->skb->data;
  2635. memmove(iwl3945_rt->payload, data, len);
  2636. iwl3945_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
  2637. iwl3945_rt->rt_hdr.it_pad = 0; /* always good to zero */
  2638. /* total header + data */
  2639. iwl3945_rt->rt_hdr.it_len = cpu_to_le16(sizeof(*iwl3945_rt));
  2640. /* Set the size of the skb to the size of the frame */
  2641. skb_put(rxb->skb, sizeof(*iwl3945_rt) + len);
  2642. /* Big bitfield of all the fields we provide in radiotap */
  2643. iwl3945_rt->rt_hdr.it_present =
  2644. cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) |
  2645. (1 << IEEE80211_RADIOTAP_FLAGS) |
  2646. (1 << IEEE80211_RADIOTAP_RATE) |
  2647. (1 << IEEE80211_RADIOTAP_CHANNEL) |
  2648. (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
  2649. (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
  2650. (1 << IEEE80211_RADIOTAP_ANTENNA));
  2651. /* Zero the flags, we'll add to them as we go */
  2652. iwl3945_rt->rt_flags = 0;
  2653. iwl3945_rt->rt_tsf = cpu_to_le64(tsf);
  2654. /* Convert to dBm */
  2655. iwl3945_rt->rt_dbmsignal = signal;
  2656. iwl3945_rt->rt_dbmnoise = noise;
  2657. /* Convert the channel frequency and set the flags */
  2658. iwl3945_rt->rt_channelMHz = cpu_to_le16(stats->freq);
  2659. if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK))
  2660. iwl3945_rt->rt_chbitmask =
  2661. cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ));
  2662. else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK)
  2663. iwl3945_rt->rt_chbitmask =
  2664. cpu_to_le16((IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ));
  2665. else /* 802.11g */
  2666. iwl3945_rt->rt_chbitmask =
  2667. cpu_to_le16((IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ));
  2668. rate = iwl3945_rate_index_from_plcp(rate);
  2669. if (rate == -1)
  2670. iwl3945_rt->rt_rate = 0;
  2671. else
  2672. iwl3945_rt->rt_rate = iwl3945_rates[rate].ieee;
  2673. /* antenna number */
  2674. iwl3945_rt->rt_antenna =
  2675. le16_to_cpu(phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK) >> 4;
  2676. /* set the preamble flag if we have it */
  2677. if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
  2678. iwl3945_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
  2679. IWL_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
  2680. stats->flag |= RX_FLAG_RADIOTAP;
  2681. ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats);
  2682. rxb->skb = NULL;
  2683. }
  2684. #define IWL_PACKET_RETRY_TIME HZ
  2685. int iwl3945_is_duplicate_packet(struct iwl3945_priv *priv, struct ieee80211_hdr *header)
  2686. {
  2687. u16 sc = le16_to_cpu(header->seq_ctrl);
  2688. u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
  2689. u16 frag = sc & IEEE80211_SCTL_FRAG;
  2690. u16 *last_seq, *last_frag;
  2691. unsigned long *last_time;
  2692. switch (priv->iw_mode) {
  2693. case IEEE80211_IF_TYPE_IBSS:{
  2694. struct list_head *p;
  2695. struct iwl3945_ibss_seq *entry = NULL;
  2696. u8 *mac = header->addr2;
  2697. int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1);
  2698. __list_for_each(p, &priv->ibss_mac_hash[index]) {
  2699. entry = list_entry(p, struct iwl3945_ibss_seq, list);
  2700. if (!compare_ether_addr(entry->mac, mac))
  2701. break;
  2702. }
  2703. if (p == &priv->ibss_mac_hash[index]) {
  2704. entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
  2705. if (!entry) {
  2706. IWL_ERROR("Cannot malloc new mac entry\n");
  2707. return 0;
  2708. }
  2709. memcpy(entry->mac, mac, ETH_ALEN);
  2710. entry->seq_num = seq;
  2711. entry->frag_num = frag;
  2712. entry->packet_time = jiffies;
  2713. list_add(&entry->list, &priv->ibss_mac_hash[index]);
  2714. return 0;
  2715. }
  2716. last_seq = &entry->seq_num;
  2717. last_frag = &entry->frag_num;
  2718. last_time = &entry->packet_time;
  2719. break;
  2720. }
  2721. case IEEE80211_IF_TYPE_STA:
  2722. last_seq = &priv->last_seq_num;
  2723. last_frag = &priv->last_frag_num;
  2724. last_time = &priv->last_packet_time;
  2725. break;
  2726. default:
  2727. return 0;
  2728. }
  2729. if ((*last_seq == seq) &&
  2730. time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) {
  2731. if (*last_frag == frag)
  2732. goto drop;
  2733. if (*last_frag + 1 != frag)
  2734. /* out-of-order fragment */
  2735. goto drop;
  2736. } else
  2737. *last_seq = seq;
  2738. *last_frag = frag;
  2739. *last_time = jiffies;
  2740. return 0;
  2741. drop:
  2742. return 1;
  2743. }
  2744. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  2745. #include "iwl-spectrum.h"
  2746. #define BEACON_TIME_MASK_LOW 0x00FFFFFF
  2747. #define BEACON_TIME_MASK_HIGH 0xFF000000
  2748. #define TIME_UNIT 1024
  2749. /*
  2750. * extended beacon time format
  2751. * time in usec will be changed into a 32-bit value in 8:24 format
  2752. * the high 1 byte is the beacon counts
  2753. * the lower 3 bytes is the time in usec within one beacon interval
  2754. */
  2755. static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
  2756. {
  2757. u32 quot;
  2758. u32 rem;
  2759. u32 interval = beacon_interval * 1024;
  2760. if (!interval || !usec)
  2761. return 0;
  2762. quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
  2763. rem = (usec % interval) & BEACON_TIME_MASK_LOW;
  2764. return (quot << 24) + rem;
  2765. }
  2766. /* base is usually what we get from ucode with each received frame,
  2767. * the same as HW timer counter counting down
  2768. */
  2769. static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
  2770. {
  2771. u32 base_low = base & BEACON_TIME_MASK_LOW;
  2772. u32 addon_low = addon & BEACON_TIME_MASK_LOW;
  2773. u32 interval = beacon_interval * TIME_UNIT;
  2774. u32 res = (base & BEACON_TIME_MASK_HIGH) +
  2775. (addon & BEACON_TIME_MASK_HIGH);
  2776. if (base_low > addon_low)
  2777. res += base_low - addon_low;
  2778. else if (base_low < addon_low) {
  2779. res += interval + base_low - addon_low;
  2780. res += (1 << 24);
  2781. } else
  2782. res += (1 << 24);
  2783. return cpu_to_le32(res);
  2784. }
  2785. static int iwl3945_get_measurement(struct iwl3945_priv *priv,
  2786. struct ieee80211_measurement_params *params,
  2787. u8 type)
  2788. {
  2789. struct iwl3945_spectrum_cmd spectrum;
  2790. struct iwl3945_rx_packet *res;
  2791. struct iwl3945_host_cmd cmd = {
  2792. .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
  2793. .data = (void *)&spectrum,
  2794. .meta.flags = CMD_WANT_SKB,
  2795. };
  2796. u32 add_time = le64_to_cpu(params->start_time);
  2797. int rc;
  2798. int spectrum_resp_status;
  2799. int duration = le16_to_cpu(params->duration);
  2800. if (iwl3945_is_associated(priv))
  2801. add_time =
  2802. iwl3945_usecs_to_beacons(
  2803. le64_to_cpu(params->start_time) - priv->last_tsf,
  2804. le16_to_cpu(priv->rxon_timing.beacon_interval));
  2805. memset(&spectrum, 0, sizeof(spectrum));
  2806. spectrum.channel_count = cpu_to_le16(1);
  2807. spectrum.flags =
  2808. RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
  2809. spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
  2810. cmd.len = sizeof(spectrum);
  2811. spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
  2812. if (iwl3945_is_associated(priv))
  2813. spectrum.start_time =
  2814. iwl3945_add_beacon_time(priv->last_beacon_time,
  2815. add_time,
  2816. le16_to_cpu(priv->rxon_timing.beacon_interval));
  2817. else
  2818. spectrum.start_time = 0;
  2819. spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
  2820. spectrum.channels[0].channel = params->channel;
  2821. spectrum.channels[0].type = type;
  2822. if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
  2823. spectrum.flags |= RXON_FLG_BAND_24G_MSK |
  2824. RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
  2825. rc = iwl3945_send_cmd_sync(priv, &cmd);
  2826. if (rc)
  2827. return rc;
  2828. res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data;
  2829. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  2830. IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
  2831. rc = -EIO;
  2832. }
  2833. spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
  2834. switch (spectrum_resp_status) {
  2835. case 0: /* Command will be handled */
  2836. if (res->u.spectrum.id != 0xff) {
  2837. IWL_DEBUG_INFO("Replaced existing measurement: %d\n",
  2838. res->u.spectrum.id);
  2839. priv->measurement_status &= ~MEASUREMENT_READY;
  2840. }
  2841. priv->measurement_status |= MEASUREMENT_ACTIVE;
  2842. rc = 0;
  2843. break;
  2844. case 1: /* Command will not be handled */
  2845. rc = -EAGAIN;
  2846. break;
  2847. }
  2848. dev_kfree_skb_any(cmd.meta.u.skb);
  2849. return rc;
  2850. }
  2851. #endif
  2852. static void iwl3945_txstatus_to_ieee(struct iwl3945_priv *priv,
  2853. struct iwl3945_tx_info *tx_sta)
  2854. {
  2855. tx_sta->status.ack_signal = 0;
  2856. tx_sta->status.excessive_retries = 0;
  2857. tx_sta->status.queue_length = 0;
  2858. tx_sta->status.queue_number = 0;
  2859. if (in_interrupt())
  2860. ieee80211_tx_status_irqsafe(priv->hw,
  2861. tx_sta->skb[0], &(tx_sta->status));
  2862. else
  2863. ieee80211_tx_status(priv->hw,
  2864. tx_sta->skb[0], &(tx_sta->status));
  2865. tx_sta->skb[0] = NULL;
  2866. }
  2867. /**
  2868. * iwl3945_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd
  2869. *
  2870. * When FW advances 'R' index, all entries between old and new 'R' index
  2871. * need to be reclaimed. As result, some free space forms. If there is
  2872. * enough free space (> low mark), wake the stack that feeds us.
  2873. */
  2874. static int iwl3945_tx_queue_reclaim(struct iwl3945_priv *priv, int txq_id, int index)
  2875. {
  2876. struct iwl3945_tx_queue *txq = &priv->txq[txq_id];
  2877. struct iwl3945_queue *q = &txq->q;
  2878. int nfreed = 0;
  2879. if ((index >= q->n_bd) || (x2_queue_used(q, index) == 0)) {
  2880. IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
  2881. "is out of range [0-%d] %d %d.\n", txq_id,
  2882. index, q->n_bd, q->write_ptr, q->read_ptr);
  2883. return 0;
  2884. }
  2885. for (index = iwl3945_queue_inc_wrap(index, q->n_bd);
  2886. q->read_ptr != index;
  2887. q->read_ptr = iwl3945_queue_inc_wrap(q->read_ptr, q->n_bd)) {
  2888. if (txq_id != IWL_CMD_QUEUE_NUM) {
  2889. iwl3945_txstatus_to_ieee(priv,
  2890. &(txq->txb[txq->q.read_ptr]));
  2891. iwl3945_hw_txq_free_tfd(priv, txq);
  2892. } else if (nfreed > 1) {
  2893. IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index,
  2894. q->write_ptr, q->read_ptr);
  2895. queue_work(priv->workqueue, &priv->restart);
  2896. }
  2897. nfreed++;
  2898. }
  2899. if (iwl3945_queue_space(q) > q->low_mark && (txq_id >= 0) &&
  2900. (txq_id != IWL_CMD_QUEUE_NUM) &&
  2901. priv->mac80211_registered)
  2902. ieee80211_wake_queue(priv->hw, txq_id);
  2903. return nfreed;
  2904. }
  2905. static int iwl3945_is_tx_success(u32 status)
  2906. {
  2907. return (status & 0xFF) == 0x1;
  2908. }
  2909. /******************************************************************************
  2910. *
  2911. * Generic RX handler implementations
  2912. *
  2913. ******************************************************************************/
  2914. /**
  2915. * iwl3945_rx_reply_tx - Handle Tx response
  2916. */
  2917. static void iwl3945_rx_reply_tx(struct iwl3945_priv *priv,
  2918. struct iwl3945_rx_mem_buffer *rxb)
  2919. {
  2920. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2921. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  2922. int txq_id = SEQ_TO_QUEUE(sequence);
  2923. int index = SEQ_TO_INDEX(sequence);
  2924. struct iwl3945_tx_queue *txq = &priv->txq[txq_id];
  2925. struct ieee80211_tx_status *tx_status;
  2926. struct iwl3945_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
  2927. u32 status = le32_to_cpu(tx_resp->status);
  2928. if ((index >= txq->q.n_bd) || (x2_queue_used(&txq->q, index) == 0)) {
  2929. IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
  2930. "is out of range [0-%d] %d %d\n", txq_id,
  2931. index, txq->q.n_bd, txq->q.write_ptr,
  2932. txq->q.read_ptr);
  2933. return;
  2934. }
  2935. tx_status = &(txq->txb[txq->q.read_ptr].status);
  2936. tx_status->retry_count = tx_resp->failure_frame;
  2937. tx_status->queue_number = status;
  2938. tx_status->queue_length = tx_resp->bt_kill_count;
  2939. tx_status->queue_length |= tx_resp->failure_rts;
  2940. tx_status->flags =
  2941. iwl3945_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0;
  2942. tx_status->control.tx_rate = iwl3945_rate_index_from_plcp(tx_resp->rate);
  2943. IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) plcp rate %d retries %d\n",
  2944. txq_id, iwl3945_get_tx_fail_reason(status), status,
  2945. tx_resp->rate, tx_resp->failure_frame);
  2946. IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
  2947. if (index != -1)
  2948. iwl3945_tx_queue_reclaim(priv, txq_id, index);
  2949. if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
  2950. IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
  2951. }
  2952. static void iwl3945_rx_reply_alive(struct iwl3945_priv *priv,
  2953. struct iwl3945_rx_mem_buffer *rxb)
  2954. {
  2955. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2956. struct iwl3945_alive_resp *palive;
  2957. struct delayed_work *pwork;
  2958. palive = &pkt->u.alive_frame;
  2959. IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
  2960. "0x%01X 0x%01X\n",
  2961. palive->is_valid, palive->ver_type,
  2962. palive->ver_subtype);
  2963. if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
  2964. IWL_DEBUG_INFO("Initialization Alive received.\n");
  2965. memcpy(&priv->card_alive_init,
  2966. &pkt->u.alive_frame,
  2967. sizeof(struct iwl3945_init_alive_resp));
  2968. pwork = &priv->init_alive_start;
  2969. } else {
  2970. IWL_DEBUG_INFO("Runtime Alive received.\n");
  2971. memcpy(&priv->card_alive, &pkt->u.alive_frame,
  2972. sizeof(struct iwl3945_alive_resp));
  2973. pwork = &priv->alive_start;
  2974. iwl3945_disable_events(priv);
  2975. }
  2976. /* We delay the ALIVE response by 5ms to
  2977. * give the HW RF Kill time to activate... */
  2978. if (palive->is_valid == UCODE_VALID_OK)
  2979. queue_delayed_work(priv->workqueue, pwork,
  2980. msecs_to_jiffies(5));
  2981. else
  2982. IWL_WARNING("uCode did not respond OK.\n");
  2983. }
  2984. static void iwl3945_rx_reply_add_sta(struct iwl3945_priv *priv,
  2985. struct iwl3945_rx_mem_buffer *rxb)
  2986. {
  2987. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2988. IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
  2989. return;
  2990. }
  2991. static void iwl3945_rx_reply_error(struct iwl3945_priv *priv,
  2992. struct iwl3945_rx_mem_buffer *rxb)
  2993. {
  2994. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  2995. IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
  2996. "seq 0x%04X ser 0x%08X\n",
  2997. le32_to_cpu(pkt->u.err_resp.error_type),
  2998. get_cmd_string(pkt->u.err_resp.cmd_id),
  2999. pkt->u.err_resp.cmd_id,
  3000. le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
  3001. le32_to_cpu(pkt->u.err_resp.error_info));
  3002. }
  3003. #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
  3004. static void iwl3945_rx_csa(struct iwl3945_priv *priv, struct iwl3945_rx_mem_buffer *rxb)
  3005. {
  3006. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  3007. struct iwl3945_rxon_cmd *rxon = (void *)&priv->active_rxon;
  3008. struct iwl3945_csa_notification *csa = &(pkt->u.csa_notif);
  3009. IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
  3010. le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
  3011. rxon->channel = csa->channel;
  3012. priv->staging_rxon.channel = csa->channel;
  3013. }
  3014. static void iwl3945_rx_spectrum_measure_notif(struct iwl3945_priv *priv,
  3015. struct iwl3945_rx_mem_buffer *rxb)
  3016. {
  3017. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  3018. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  3019. struct iwl3945_spectrum_notification *report = &(pkt->u.spectrum_notif);
  3020. if (!report->state) {
  3021. IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO,
  3022. "Spectrum Measure Notification: Start\n");
  3023. return;
  3024. }
  3025. memcpy(&priv->measure_report, report, sizeof(*report));
  3026. priv->measurement_status |= MEASUREMENT_READY;
  3027. #endif
  3028. }
  3029. static void iwl3945_rx_pm_sleep_notif(struct iwl3945_priv *priv,
  3030. struct iwl3945_rx_mem_buffer *rxb)
  3031. {
  3032. #ifdef CONFIG_IWL3945_DEBUG
  3033. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  3034. struct iwl3945_sleep_notification *sleep = &(pkt->u.sleep_notif);
  3035. IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
  3036. sleep->pm_sleep_mode, sleep->pm_wakeup_src);
  3037. #endif
  3038. }
  3039. static void iwl3945_rx_pm_debug_statistics_notif(struct iwl3945_priv *priv,
  3040. struct iwl3945_rx_mem_buffer *rxb)
  3041. {
  3042. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  3043. IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
  3044. "notification for %s:\n",
  3045. le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
  3046. iwl3945_print_hex_dump(IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
  3047. }
  3048. static void iwl3945_bg_beacon_update(struct work_struct *work)
  3049. {
  3050. struct iwl3945_priv *priv =
  3051. container_of(work, struct iwl3945_priv, beacon_update);
  3052. struct sk_buff *beacon;
  3053. /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
  3054. beacon = ieee80211_beacon_get(priv->hw, priv->interface_id, NULL);
  3055. if (!beacon) {
  3056. IWL_ERROR("update beacon failed\n");
  3057. return;
  3058. }
  3059. mutex_lock(&priv->mutex);
  3060. /* new beacon skb is allocated every time; dispose previous.*/
  3061. if (priv->ibss_beacon)
  3062. dev_kfree_skb(priv->ibss_beacon);
  3063. priv->ibss_beacon = beacon;
  3064. mutex_unlock(&priv->mutex);
  3065. iwl3945_send_beacon_cmd(priv);
  3066. }
  3067. static void iwl3945_rx_beacon_notif(struct iwl3945_priv *priv,
  3068. struct iwl3945_rx_mem_buffer *rxb)
  3069. {
  3070. #ifdef CONFIG_IWL3945_DEBUG
  3071. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  3072. struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
  3073. u8 rate = beacon->beacon_notify_hdr.rate;
  3074. IWL_DEBUG_RX("beacon status %x retries %d iss %d "
  3075. "tsf %d %d rate %d\n",
  3076. le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
  3077. beacon->beacon_notify_hdr.failure_frame,
  3078. le32_to_cpu(beacon->ibss_mgr_status),
  3079. le32_to_cpu(beacon->high_tsf),
  3080. le32_to_cpu(beacon->low_tsf), rate);
  3081. #endif
  3082. if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
  3083. (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
  3084. queue_work(priv->workqueue, &priv->beacon_update);
  3085. }
  3086. /* Service response to REPLY_SCAN_CMD (0x80) */
  3087. static void iwl3945_rx_reply_scan(struct iwl3945_priv *priv,
  3088. struct iwl3945_rx_mem_buffer *rxb)
  3089. {
  3090. #ifdef CONFIG_IWL3945_DEBUG
  3091. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  3092. struct iwl3945_scanreq_notification *notif =
  3093. (struct iwl3945_scanreq_notification *)pkt->u.raw;
  3094. IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status);
  3095. #endif
  3096. }
  3097. /* Service SCAN_START_NOTIFICATION (0x82) */
  3098. static void iwl3945_rx_scan_start_notif(struct iwl3945_priv *priv,
  3099. struct iwl3945_rx_mem_buffer *rxb)
  3100. {
  3101. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  3102. struct iwl3945_scanstart_notification *notif =
  3103. (struct iwl3945_scanstart_notification *)pkt->u.raw;
  3104. priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
  3105. IWL_DEBUG_SCAN("Scan start: "
  3106. "%d [802.11%s] "
  3107. "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
  3108. notif->channel,
  3109. notif->band ? "bg" : "a",
  3110. notif->tsf_high,
  3111. notif->tsf_low, notif->status, notif->beacon_timer);
  3112. }
  3113. /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
  3114. static void iwl3945_rx_scan_results_notif(struct iwl3945_priv *priv,
  3115. struct iwl3945_rx_mem_buffer *rxb)
  3116. {
  3117. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  3118. struct iwl3945_scanresults_notification *notif =
  3119. (struct iwl3945_scanresults_notification *)pkt->u.raw;
  3120. IWL_DEBUG_SCAN("Scan ch.res: "
  3121. "%d [802.11%s] "
  3122. "(TSF: 0x%08X:%08X) - %d "
  3123. "elapsed=%lu usec (%dms since last)\n",
  3124. notif->channel,
  3125. notif->band ? "bg" : "a",
  3126. le32_to_cpu(notif->tsf_high),
  3127. le32_to_cpu(notif->tsf_low),
  3128. le32_to_cpu(notif->statistics[0]),
  3129. le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf,
  3130. jiffies_to_msecs(elapsed_jiffies
  3131. (priv->last_scan_jiffies, jiffies)));
  3132. priv->last_scan_jiffies = jiffies;
  3133. priv->next_scan_jiffies = 0;
  3134. }
  3135. /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
  3136. static void iwl3945_rx_scan_complete_notif(struct iwl3945_priv *priv,
  3137. struct iwl3945_rx_mem_buffer *rxb)
  3138. {
  3139. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  3140. struct iwl3945_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
  3141. IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
  3142. scan_notif->scanned_channels,
  3143. scan_notif->tsf_low,
  3144. scan_notif->tsf_high, scan_notif->status);
  3145. /* The HW is no longer scanning */
  3146. clear_bit(STATUS_SCAN_HW, &priv->status);
  3147. /* The scan completion notification came in, so kill that timer... */
  3148. cancel_delayed_work(&priv->scan_check);
  3149. IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
  3150. (priv->scan_bands == 2) ? "2.4" : "5.2",
  3151. jiffies_to_msecs(elapsed_jiffies
  3152. (priv->scan_pass_start, jiffies)));
  3153. /* Remove this scanned band from the list
  3154. * of pending bands to scan */
  3155. priv->scan_bands--;
  3156. /* If a request to abort was given, or the scan did not succeed
  3157. * then we reset the scan state machine and terminate,
  3158. * re-queuing another scan if one has been requested */
  3159. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  3160. IWL_DEBUG_INFO("Aborted scan completed.\n");
  3161. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  3162. } else {
  3163. /* If there are more bands on this scan pass reschedule */
  3164. if (priv->scan_bands > 0)
  3165. goto reschedule;
  3166. }
  3167. priv->last_scan_jiffies = jiffies;
  3168. priv->next_scan_jiffies = 0;
  3169. IWL_DEBUG_INFO("Setting scan to off\n");
  3170. clear_bit(STATUS_SCANNING, &priv->status);
  3171. IWL_DEBUG_INFO("Scan took %dms\n",
  3172. jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies)));
  3173. queue_work(priv->workqueue, &priv->scan_completed);
  3174. return;
  3175. reschedule:
  3176. priv->scan_pass_start = jiffies;
  3177. queue_work(priv->workqueue, &priv->request_scan);
  3178. }
  3179. /* Handle notification from uCode that card's power state is changing
  3180. * due to software, hardware, or critical temperature RFKILL */
  3181. static void iwl3945_rx_card_state_notif(struct iwl3945_priv *priv,
  3182. struct iwl3945_rx_mem_buffer *rxb)
  3183. {
  3184. struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data;
  3185. u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
  3186. unsigned long status = priv->status;
  3187. IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
  3188. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  3189. (flags & SW_CARD_DISABLED) ? "Kill" : "On");
  3190. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_SET,
  3191. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  3192. if (flags & HW_CARD_DISABLED)
  3193. set_bit(STATUS_RF_KILL_HW, &priv->status);
  3194. else
  3195. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  3196. if (flags & SW_CARD_DISABLED)
  3197. set_bit(STATUS_RF_KILL_SW, &priv->status);
  3198. else
  3199. clear_bit(STATUS_RF_KILL_SW, &priv->status);
  3200. iwl3945_scan_cancel(priv);
  3201. if ((test_bit(STATUS_RF_KILL_HW, &status) !=
  3202. test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
  3203. (test_bit(STATUS_RF_KILL_SW, &status) !=
  3204. test_bit(STATUS_RF_KILL_SW, &priv->status)))
  3205. queue_work(priv->workqueue, &priv->rf_kill);
  3206. else
  3207. wake_up_interruptible(&priv->wait_command_queue);
  3208. }
  3209. /**
  3210. * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
  3211. *
  3212. * Setup the RX handlers for each of the reply types sent from the uCode
  3213. * to the host.
  3214. *
  3215. * This function chains into the hardware specific files for them to setup
  3216. * any hardware specific handlers as well.
  3217. */
  3218. static void iwl3945_setup_rx_handlers(struct iwl3945_priv *priv)
  3219. {
  3220. priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
  3221. priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
  3222. priv->rx_handlers[REPLY_ERROR] = iwl3945_rx_reply_error;
  3223. priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl3945_rx_csa;
  3224. priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
  3225. iwl3945_rx_spectrum_measure_notif;
  3226. priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl3945_rx_pm_sleep_notif;
  3227. priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
  3228. iwl3945_rx_pm_debug_statistics_notif;
  3229. priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
  3230. /*
  3231. * The same handler is used for both the REPLY to a discrete
  3232. * statistics request from the host as well as for the periodic
  3233. * statistics notifications (after received beacons) from the uCode.
  3234. */
  3235. priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
  3236. priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
  3237. priv->rx_handlers[REPLY_SCAN_CMD] = iwl3945_rx_reply_scan;
  3238. priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl3945_rx_scan_start_notif;
  3239. priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
  3240. iwl3945_rx_scan_results_notif;
  3241. priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
  3242. iwl3945_rx_scan_complete_notif;
  3243. priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
  3244. priv->rx_handlers[REPLY_TX] = iwl3945_rx_reply_tx;
  3245. /* Set up hardware specific Rx handlers */
  3246. iwl3945_hw_rx_handler_setup(priv);
  3247. }
  3248. /**
  3249. * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
  3250. * @rxb: Rx buffer to reclaim
  3251. *
  3252. * If an Rx buffer has an async callback associated with it the callback
  3253. * will be executed. The attached skb (if present) will only be freed
  3254. * if the callback returns 1
  3255. */
  3256. static void iwl3945_tx_cmd_complete(struct iwl3945_priv *priv,
  3257. struct iwl3945_rx_mem_buffer *rxb)
  3258. {
  3259. struct iwl3945_rx_packet *pkt = (struct iwl3945_rx_packet *)rxb->skb->data;
  3260. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  3261. int txq_id = SEQ_TO_QUEUE(sequence);
  3262. int index = SEQ_TO_INDEX(sequence);
  3263. int huge = sequence & SEQ_HUGE_FRAME;
  3264. int cmd_index;
  3265. struct iwl3945_cmd *cmd;
  3266. /* If a Tx command is being handled and it isn't in the actual
  3267. * command queue then there a command routing bug has been introduced
  3268. * in the queue management code. */
  3269. if (txq_id != IWL_CMD_QUEUE_NUM)
  3270. IWL_ERROR("Error wrong command queue %d command id 0x%X\n",
  3271. txq_id, pkt->hdr.cmd);
  3272. BUG_ON(txq_id != IWL_CMD_QUEUE_NUM);
  3273. cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
  3274. cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
  3275. /* Input error checking is done when commands are added to queue. */
  3276. if (cmd->meta.flags & CMD_WANT_SKB) {
  3277. cmd->meta.source->u.skb = rxb->skb;
  3278. rxb->skb = NULL;
  3279. } else if (cmd->meta.u.callback &&
  3280. !cmd->meta.u.callback(priv, cmd, rxb->skb))
  3281. rxb->skb = NULL;
  3282. iwl3945_tx_queue_reclaim(priv, txq_id, index);
  3283. if (!(cmd->meta.flags & CMD_ASYNC)) {
  3284. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  3285. wake_up_interruptible(&priv->wait_command_queue);
  3286. }
  3287. }
  3288. /************************** RX-FUNCTIONS ****************************/
  3289. /*
  3290. * Rx theory of operation
  3291. *
  3292. * The host allocates 32 DMA target addresses and passes the host address
  3293. * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
  3294. * 0 to 31
  3295. *
  3296. * Rx Queue Indexes
  3297. * The host/firmware share two index registers for managing the Rx buffers.
  3298. *
  3299. * The READ index maps to the first position that the firmware may be writing
  3300. * to -- the driver can read up to (but not including) this position and get
  3301. * good data.
  3302. * The READ index is managed by the firmware once the card is enabled.
  3303. *
  3304. * The WRITE index maps to the last position the driver has read from -- the
  3305. * position preceding WRITE is the last slot the firmware can place a packet.
  3306. *
  3307. * The queue is empty (no good data) if WRITE = READ - 1, and is full if
  3308. * WRITE = READ.
  3309. *
  3310. * During initialization, the host sets up the READ queue position to the first
  3311. * INDEX position, and WRITE to the last (READ - 1 wrapped)
  3312. *
  3313. * When the firmware places a packet in a buffer, it will advance the READ index
  3314. * and fire the RX interrupt. The driver can then query the READ index and
  3315. * process as many packets as possible, moving the WRITE index forward as it
  3316. * resets the Rx queue buffers with new memory.
  3317. *
  3318. * The management in the driver is as follows:
  3319. * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
  3320. * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
  3321. * to replenish the iwl->rxq->rx_free.
  3322. * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
  3323. * iwl->rxq is replenished and the READ INDEX is updated (updating the
  3324. * 'processed' and 'read' driver indexes as well)
  3325. * + A received packet is processed and handed to the kernel network stack,
  3326. * detached from the iwl->rxq. The driver 'processed' index is updated.
  3327. * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
  3328. * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
  3329. * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
  3330. * were enough free buffers and RX_STALLED is set it is cleared.
  3331. *
  3332. *
  3333. * Driver sequence:
  3334. *
  3335. * iwl3945_rx_queue_alloc() Allocates rx_free
  3336. * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
  3337. * iwl3945_rx_queue_restock
  3338. * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
  3339. * queue, updates firmware pointers, and updates
  3340. * the WRITE index. If insufficient rx_free buffers
  3341. * are available, schedules iwl3945_rx_replenish
  3342. *
  3343. * -- enable interrupts --
  3344. * ISR - iwl3945_rx() Detach iwl3945_rx_mem_buffers from pool up to the
  3345. * READ INDEX, detaching the SKB from the pool.
  3346. * Moves the packet buffer from queue to rx_used.
  3347. * Calls iwl3945_rx_queue_restock to refill any empty
  3348. * slots.
  3349. * ...
  3350. *
  3351. */
  3352. /**
  3353. * iwl3945_rx_queue_space - Return number of free slots available in queue.
  3354. */
  3355. static int iwl3945_rx_queue_space(const struct iwl3945_rx_queue *q)
  3356. {
  3357. int s = q->read - q->write;
  3358. if (s <= 0)
  3359. s += RX_QUEUE_SIZE;
  3360. /* keep some buffer to not confuse full and empty queue */
  3361. s -= 2;
  3362. if (s < 0)
  3363. s = 0;
  3364. return s;
  3365. }
  3366. /**
  3367. * iwl3945_rx_queue_update_write_ptr - Update the write pointer for the RX queue
  3368. */
  3369. int iwl3945_rx_queue_update_write_ptr(struct iwl3945_priv *priv, struct iwl3945_rx_queue *q)
  3370. {
  3371. u32 reg = 0;
  3372. int rc = 0;
  3373. unsigned long flags;
  3374. spin_lock_irqsave(&q->lock, flags);
  3375. if (q->need_update == 0)
  3376. goto exit_unlock;
  3377. /* If power-saving is in use, make sure device is awake */
  3378. if (test_bit(STATUS_POWER_PMI, &priv->status)) {
  3379. reg = iwl3945_read32(priv, CSR_UCODE_DRV_GP1);
  3380. if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
  3381. iwl3945_set_bit(priv, CSR_GP_CNTRL,
  3382. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  3383. goto exit_unlock;
  3384. }
  3385. rc = iwl3945_grab_nic_access(priv);
  3386. if (rc)
  3387. goto exit_unlock;
  3388. /* Device expects a multiple of 8 */
  3389. iwl3945_write_direct32(priv, FH_RSCSR_CHNL0_WPTR,
  3390. q->write & ~0x7);
  3391. iwl3945_release_nic_access(priv);
  3392. /* Else device is assumed to be awake */
  3393. } else
  3394. /* Device expects a multiple of 8 */
  3395. iwl3945_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7);
  3396. q->need_update = 0;
  3397. exit_unlock:
  3398. spin_unlock_irqrestore(&q->lock, flags);
  3399. return rc;
  3400. }
  3401. /**
  3402. * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
  3403. */
  3404. static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl3945_priv *priv,
  3405. dma_addr_t dma_addr)
  3406. {
  3407. return cpu_to_le32((u32)dma_addr);
  3408. }
  3409. /**
  3410. * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
  3411. *
  3412. * If there are slots in the RX queue that need to be restocked,
  3413. * and we have free pre-allocated buffers, fill the ranks as much
  3414. * as we can, pulling from rx_free.
  3415. *
  3416. * This moves the 'write' index forward to catch up with 'processed', and
  3417. * also updates the memory address in the firmware to reference the new
  3418. * target buffer.
  3419. */
  3420. static int iwl3945_rx_queue_restock(struct iwl3945_priv *priv)
  3421. {
  3422. struct iwl3945_rx_queue *rxq = &priv->rxq;
  3423. struct list_head *element;
  3424. struct iwl3945_rx_mem_buffer *rxb;
  3425. unsigned long flags;
  3426. int write, rc;
  3427. spin_lock_irqsave(&rxq->lock, flags);
  3428. write = rxq->write & ~0x7;
  3429. while ((iwl3945_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
  3430. /* Get next free Rx buffer, remove from free list */
  3431. element = rxq->rx_free.next;
  3432. rxb = list_entry(element, struct iwl3945_rx_mem_buffer, list);
  3433. list_del(element);
  3434. /* Point to Rx buffer via next RBD in circular buffer */
  3435. rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->dma_addr);
  3436. rxq->queue[rxq->write] = rxb;
  3437. rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
  3438. rxq->free_count--;
  3439. }
  3440. spin_unlock_irqrestore(&rxq->lock, flags);
  3441. /* If the pre-allocated buffer pool is dropping low, schedule to
  3442. * refill it */
  3443. if (rxq->free_count <= RX_LOW_WATERMARK)
  3444. queue_work(priv->workqueue, &priv->rx_replenish);
  3445. /* If we've added more space for the firmware to place data, tell it.
  3446. * Increment device's write pointer in multiples of 8. */
  3447. if ((write != (rxq->write & ~0x7))
  3448. || (abs(rxq->write - rxq->read) > 7)) {
  3449. spin_lock_irqsave(&rxq->lock, flags);
  3450. rxq->need_update = 1;
  3451. spin_unlock_irqrestore(&rxq->lock, flags);
  3452. rc = iwl3945_rx_queue_update_write_ptr(priv, rxq);
  3453. if (rc)
  3454. return rc;
  3455. }
  3456. return 0;
  3457. }
  3458. /**
  3459. * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
  3460. *
  3461. * When moving to rx_free an SKB is allocated for the slot.
  3462. *
  3463. * Also restock the Rx queue via iwl3945_rx_queue_restock.
  3464. * This is called as a scheduled work item (except for during initialization)
  3465. */
  3466. void iwl3945_rx_replenish(void *data)
  3467. {
  3468. struct iwl3945_priv *priv = data;
  3469. struct iwl3945_rx_queue *rxq = &priv->rxq;
  3470. struct list_head *element;
  3471. struct iwl3945_rx_mem_buffer *rxb;
  3472. unsigned long flags;
  3473. spin_lock_irqsave(&rxq->lock, flags);
  3474. while (!list_empty(&rxq->rx_used)) {
  3475. element = rxq->rx_used.next;
  3476. rxb = list_entry(element, struct iwl3945_rx_mem_buffer, list);
  3477. /* Alloc a new receive buffer */
  3478. rxb->skb =
  3479. alloc_skb(IWL_RX_BUF_SIZE, __GFP_NOWARN | GFP_ATOMIC);
  3480. if (!rxb->skb) {
  3481. if (net_ratelimit())
  3482. printk(KERN_CRIT DRV_NAME
  3483. ": Can not allocate SKB buffers\n");
  3484. /* We don't reschedule replenish work here -- we will
  3485. * call the restock method and if it still needs
  3486. * more buffers it will schedule replenish */
  3487. break;
  3488. }
  3489. priv->alloc_rxb_skb++;
  3490. list_del(element);
  3491. /* Get physical address of RB/SKB */
  3492. rxb->dma_addr =
  3493. pci_map_single(priv->pci_dev, rxb->skb->data,
  3494. IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
  3495. list_add_tail(&rxb->list, &rxq->rx_free);
  3496. rxq->free_count++;
  3497. }
  3498. spin_unlock_irqrestore(&rxq->lock, flags);
  3499. spin_lock_irqsave(&priv->lock, flags);
  3500. iwl3945_rx_queue_restock(priv);
  3501. spin_unlock_irqrestore(&priv->lock, flags);
  3502. }
  3503. /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
  3504. * If an SKB has been detached, the POOL needs to have its SKB set to NULL
  3505. * This free routine walks the list of POOL entries and if SKB is set to
  3506. * non NULL it is unmapped and freed
  3507. */
  3508. static void iwl3945_rx_queue_free(struct iwl3945_priv *priv, struct iwl3945_rx_queue *rxq)
  3509. {
  3510. int i;
  3511. for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
  3512. if (rxq->pool[i].skb != NULL) {
  3513. pci_unmap_single(priv->pci_dev,
  3514. rxq->pool[i].dma_addr,
  3515. IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
  3516. dev_kfree_skb(rxq->pool[i].skb);
  3517. }
  3518. }
  3519. pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd,
  3520. rxq->dma_addr);
  3521. rxq->bd = NULL;
  3522. }
  3523. int iwl3945_rx_queue_alloc(struct iwl3945_priv *priv)
  3524. {
  3525. struct iwl3945_rx_queue *rxq = &priv->rxq;
  3526. struct pci_dev *dev = priv->pci_dev;
  3527. int i;
  3528. spin_lock_init(&rxq->lock);
  3529. INIT_LIST_HEAD(&rxq->rx_free);
  3530. INIT_LIST_HEAD(&rxq->rx_used);
  3531. /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */
  3532. rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr);
  3533. if (!rxq->bd)
  3534. return -ENOMEM;
  3535. /* Fill the rx_used queue with _all_ of the Rx buffers */
  3536. for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
  3537. list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
  3538. /* Set us so that we have processed and used all buffers, but have
  3539. * not restocked the Rx queue with fresh buffers */
  3540. rxq->read = rxq->write = 0;
  3541. rxq->free_count = 0;
  3542. rxq->need_update = 0;
  3543. return 0;
  3544. }
  3545. void iwl3945_rx_queue_reset(struct iwl3945_priv *priv, struct iwl3945_rx_queue *rxq)
  3546. {
  3547. unsigned long flags;
  3548. int i;
  3549. spin_lock_irqsave(&rxq->lock, flags);
  3550. INIT_LIST_HEAD(&rxq->rx_free);
  3551. INIT_LIST_HEAD(&rxq->rx_used);
  3552. /* Fill the rx_used queue with _all_ of the Rx buffers */
  3553. for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
  3554. /* In the reset function, these buffers may have been allocated
  3555. * to an SKB, so we need to unmap and free potential storage */
  3556. if (rxq->pool[i].skb != NULL) {
  3557. pci_unmap_single(priv->pci_dev,
  3558. rxq->pool[i].dma_addr,
  3559. IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
  3560. priv->alloc_rxb_skb--;
  3561. dev_kfree_skb(rxq->pool[i].skb);
  3562. rxq->pool[i].skb = NULL;
  3563. }
  3564. list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
  3565. }
  3566. /* Set us so that we have processed and used all buffers, but have
  3567. * not restocked the Rx queue with fresh buffers */
  3568. rxq->read = rxq->write = 0;
  3569. rxq->free_count = 0;
  3570. spin_unlock_irqrestore(&rxq->lock, flags);
  3571. }
  3572. /* Convert linear signal-to-noise ratio into dB */
  3573. static u8 ratio2dB[100] = {
  3574. /* 0 1 2 3 4 5 6 7 8 9 */
  3575. 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
  3576. 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
  3577. 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
  3578. 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
  3579. 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
  3580. 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
  3581. 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
  3582. 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
  3583. 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
  3584. 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
  3585. };
  3586. /* Calculates a relative dB value from a ratio of linear
  3587. * (i.e. not dB) signal levels.
  3588. * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
  3589. int iwl3945_calc_db_from_ratio(int sig_ratio)
  3590. {
  3591. /* Anything above 1000:1 just report as 60 dB */
  3592. if (sig_ratio > 1000)
  3593. return 60;
  3594. /* Above 100:1, divide by 10 and use table,
  3595. * add 20 dB to make up for divide by 10 */
  3596. if (sig_ratio > 100)
  3597. return (20 + (int)ratio2dB[sig_ratio/10]);
  3598. /* We shouldn't see this */
  3599. if (sig_ratio < 1)
  3600. return 0;
  3601. /* Use table for ratios 1:1 - 99:1 */
  3602. return (int)ratio2dB[sig_ratio];
  3603. }
  3604. #define PERFECT_RSSI (-20) /* dBm */
  3605. #define WORST_RSSI (-95) /* dBm */
  3606. #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
  3607. /* Calculate an indication of rx signal quality (a percentage, not dBm!).
  3608. * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
  3609. * about formulas used below. */
  3610. int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
  3611. {
  3612. int sig_qual;
  3613. int degradation = PERFECT_RSSI - rssi_dbm;
  3614. /* If we get a noise measurement, use signal-to-noise ratio (SNR)
  3615. * as indicator; formula is (signal dbm - noise dbm).
  3616. * SNR at or above 40 is a great signal (100%).
  3617. * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
  3618. * Weakest usable signal is usually 10 - 15 dB SNR. */
  3619. if (noise_dbm) {
  3620. if (rssi_dbm - noise_dbm >= 40)
  3621. return 100;
  3622. else if (rssi_dbm < noise_dbm)
  3623. return 0;
  3624. sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
  3625. /* Else use just the signal level.
  3626. * This formula is a least squares fit of data points collected and
  3627. * compared with a reference system that had a percentage (%) display
  3628. * for signal quality. */
  3629. } else
  3630. sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
  3631. (15 * RSSI_RANGE + 62 * degradation)) /
  3632. (RSSI_RANGE * RSSI_RANGE);
  3633. if (sig_qual > 100)
  3634. sig_qual = 100;
  3635. else if (sig_qual < 1)
  3636. sig_qual = 0;
  3637. return sig_qual;
  3638. }
  3639. /**
  3640. * iwl3945_rx_handle - Main entry function for receiving responses from uCode
  3641. *
  3642. * Uses the priv->rx_handlers callback function array to invoke
  3643. * the appropriate handlers, including command responses,
  3644. * frame-received notifications, and other notifications.
  3645. */
  3646. static void iwl3945_rx_handle(struct iwl3945_priv *priv)
  3647. {
  3648. struct iwl3945_rx_mem_buffer *rxb;
  3649. struct iwl3945_rx_packet *pkt;
  3650. struct iwl3945_rx_queue *rxq = &priv->rxq;
  3651. u32 r, i;
  3652. int reclaim;
  3653. unsigned long flags;
  3654. /* uCode's read index (stored in shared DRAM) indicates the last Rx
  3655. * buffer that the driver may process (last buffer filled by ucode). */
  3656. r = iwl3945_hw_get_rx_read(priv);
  3657. i = rxq->read;
  3658. /* Rx interrupt, but nothing sent from uCode */
  3659. if (i == r)
  3660. IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
  3661. while (i != r) {
  3662. rxb = rxq->queue[i];
  3663. /* If an RXB doesn't have a Rx queue slot associated with it,
  3664. * then a bug has been introduced in the queue refilling
  3665. * routines -- catch it here */
  3666. BUG_ON(rxb == NULL);
  3667. rxq->queue[i] = NULL;
  3668. pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
  3669. IWL_RX_BUF_SIZE,
  3670. PCI_DMA_FROMDEVICE);
  3671. pkt = (struct iwl3945_rx_packet *)rxb->skb->data;
  3672. /* Reclaim a command buffer only if this packet is a response
  3673. * to a (driver-originated) command.
  3674. * If the packet (e.g. Rx frame) originated from uCode,
  3675. * there is no command buffer to reclaim.
  3676. * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
  3677. * but apparently a few don't get set; catch them here. */
  3678. reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
  3679. (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
  3680. (pkt->hdr.cmd != REPLY_TX);
  3681. /* Based on type of command response or notification,
  3682. * handle those that need handling via function in
  3683. * rx_handlers table. See iwl3945_setup_rx_handlers() */
  3684. if (priv->rx_handlers[pkt->hdr.cmd]) {
  3685. IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR,
  3686. "r = %d, i = %d, %s, 0x%02x\n", r, i,
  3687. get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
  3688. priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
  3689. } else {
  3690. /* No handling needed */
  3691. IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR,
  3692. "r %d i %d No handler needed for %s, 0x%02x\n",
  3693. r, i, get_cmd_string(pkt->hdr.cmd),
  3694. pkt->hdr.cmd);
  3695. }
  3696. if (reclaim) {
  3697. /* Invoke any callbacks, transfer the skb to caller, and
  3698. * fire off the (possibly) blocking iwl3945_send_cmd()
  3699. * as we reclaim the driver command queue */
  3700. if (rxb && rxb->skb)
  3701. iwl3945_tx_cmd_complete(priv, rxb);
  3702. else
  3703. IWL_WARNING("Claim null rxb?\n");
  3704. }
  3705. /* For now we just don't re-use anything. We can tweak this
  3706. * later to try and re-use notification packets and SKBs that
  3707. * fail to Rx correctly */
  3708. if (rxb->skb != NULL) {
  3709. priv->alloc_rxb_skb--;
  3710. dev_kfree_skb_any(rxb->skb);
  3711. rxb->skb = NULL;
  3712. }
  3713. pci_unmap_single(priv->pci_dev, rxb->dma_addr,
  3714. IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
  3715. spin_lock_irqsave(&rxq->lock, flags);
  3716. list_add_tail(&rxb->list, &priv->rxq.rx_used);
  3717. spin_unlock_irqrestore(&rxq->lock, flags);
  3718. i = (i + 1) & RX_QUEUE_MASK;
  3719. }
  3720. /* Backtrack one entry */
  3721. priv->rxq.read = i;
  3722. iwl3945_rx_queue_restock(priv);
  3723. }
  3724. /**
  3725. * iwl3945_tx_queue_update_write_ptr - Send new write index to hardware
  3726. */
  3727. static int iwl3945_tx_queue_update_write_ptr(struct iwl3945_priv *priv,
  3728. struct iwl3945_tx_queue *txq)
  3729. {
  3730. u32 reg = 0;
  3731. int rc = 0;
  3732. int txq_id = txq->q.id;
  3733. if (txq->need_update == 0)
  3734. return rc;
  3735. /* if we're trying to save power */
  3736. if (test_bit(STATUS_POWER_PMI, &priv->status)) {
  3737. /* wake up nic if it's powered down ...
  3738. * uCode will wake up, and interrupt us again, so next
  3739. * time we'll skip this part. */
  3740. reg = iwl3945_read32(priv, CSR_UCODE_DRV_GP1);
  3741. if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
  3742. IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg);
  3743. iwl3945_set_bit(priv, CSR_GP_CNTRL,
  3744. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  3745. return rc;
  3746. }
  3747. /* restore this queue's parameters in nic hardware. */
  3748. rc = iwl3945_grab_nic_access(priv);
  3749. if (rc)
  3750. return rc;
  3751. iwl3945_write_direct32(priv, HBUS_TARG_WRPTR,
  3752. txq->q.write_ptr | (txq_id << 8));
  3753. iwl3945_release_nic_access(priv);
  3754. /* else not in power-save mode, uCode will never sleep when we're
  3755. * trying to tx (during RFKILL, we're not trying to tx). */
  3756. } else
  3757. iwl3945_write32(priv, HBUS_TARG_WRPTR,
  3758. txq->q.write_ptr | (txq_id << 8));
  3759. txq->need_update = 0;
  3760. return rc;
  3761. }
  3762. #ifdef CONFIG_IWL3945_DEBUG
  3763. static void iwl3945_print_rx_config_cmd(struct iwl3945_rxon_cmd *rxon)
  3764. {
  3765. DECLARE_MAC_BUF(mac);
  3766. IWL_DEBUG_RADIO("RX CONFIG:\n");
  3767. iwl3945_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
  3768. IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
  3769. IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
  3770. IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
  3771. le32_to_cpu(rxon->filter_flags));
  3772. IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
  3773. IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
  3774. rxon->ofdm_basic_rates);
  3775. IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
  3776. IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
  3777. print_mac(mac, rxon->node_addr));
  3778. IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
  3779. print_mac(mac, rxon->bssid_addr));
  3780. IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
  3781. }
  3782. #endif
  3783. static void iwl3945_enable_interrupts(struct iwl3945_priv *priv)
  3784. {
  3785. IWL_DEBUG_ISR("Enabling interrupts\n");
  3786. set_bit(STATUS_INT_ENABLED, &priv->status);
  3787. iwl3945_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
  3788. }
  3789. static inline void iwl3945_disable_interrupts(struct iwl3945_priv *priv)
  3790. {
  3791. clear_bit(STATUS_INT_ENABLED, &priv->status);
  3792. /* disable interrupts from uCode/NIC to host */
  3793. iwl3945_write32(priv, CSR_INT_MASK, 0x00000000);
  3794. /* acknowledge/clear/reset any interrupts still pending
  3795. * from uCode or flow handler (Rx/Tx DMA) */
  3796. iwl3945_write32(priv, CSR_INT, 0xffffffff);
  3797. iwl3945_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
  3798. IWL_DEBUG_ISR("Disabled interrupts\n");
  3799. }
  3800. static const char *desc_lookup(int i)
  3801. {
  3802. switch (i) {
  3803. case 1:
  3804. return "FAIL";
  3805. case 2:
  3806. return "BAD_PARAM";
  3807. case 3:
  3808. return "BAD_CHECKSUM";
  3809. case 4:
  3810. return "NMI_INTERRUPT";
  3811. case 5:
  3812. return "SYSASSERT";
  3813. case 6:
  3814. return "FATAL_ERROR";
  3815. }
  3816. return "UNKNOWN";
  3817. }
  3818. #define ERROR_START_OFFSET (1 * sizeof(u32))
  3819. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  3820. static void iwl3945_dump_nic_error_log(struct iwl3945_priv *priv)
  3821. {
  3822. u32 i;
  3823. u32 desc, time, count, base, data1;
  3824. u32 blink1, blink2, ilink1, ilink2;
  3825. int rc;
  3826. base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
  3827. if (!iwl3945_hw_valid_rtc_data_addr(base)) {
  3828. IWL_ERROR("Not valid error log pointer 0x%08X\n", base);
  3829. return;
  3830. }
  3831. rc = iwl3945_grab_nic_access(priv);
  3832. if (rc) {
  3833. IWL_WARNING("Can not read from adapter at this time.\n");
  3834. return;
  3835. }
  3836. count = iwl3945_read_targ_mem(priv, base);
  3837. if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
  3838. IWL_ERROR("Start IWL Error Log Dump:\n");
  3839. IWL_ERROR("Status: 0x%08lX, Config: %08X count: %d\n",
  3840. priv->status, priv->config, count);
  3841. }
  3842. IWL_ERROR("Desc Time asrtPC blink2 "
  3843. "ilink1 nmiPC Line\n");
  3844. for (i = ERROR_START_OFFSET;
  3845. i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
  3846. i += ERROR_ELEM_SIZE) {
  3847. desc = iwl3945_read_targ_mem(priv, base + i);
  3848. time =
  3849. iwl3945_read_targ_mem(priv, base + i + 1 * sizeof(u32));
  3850. blink1 =
  3851. iwl3945_read_targ_mem(priv, base + i + 2 * sizeof(u32));
  3852. blink2 =
  3853. iwl3945_read_targ_mem(priv, base + i + 3 * sizeof(u32));
  3854. ilink1 =
  3855. iwl3945_read_targ_mem(priv, base + i + 4 * sizeof(u32));
  3856. ilink2 =
  3857. iwl3945_read_targ_mem(priv, base + i + 5 * sizeof(u32));
  3858. data1 =
  3859. iwl3945_read_targ_mem(priv, base + i + 6 * sizeof(u32));
  3860. IWL_ERROR
  3861. ("%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
  3862. desc_lookup(desc), desc, time, blink1, blink2,
  3863. ilink1, ilink2, data1);
  3864. }
  3865. iwl3945_release_nic_access(priv);
  3866. }
  3867. #define EVENT_START_OFFSET (6 * sizeof(u32))
  3868. /**
  3869. * iwl3945_print_event_log - Dump error event log to syslog
  3870. *
  3871. * NOTE: Must be called with iwl3945_grab_nic_access() already obtained!
  3872. */
  3873. static void iwl3945_print_event_log(struct iwl3945_priv *priv, u32 start_idx,
  3874. u32 num_events, u32 mode)
  3875. {
  3876. u32 i;
  3877. u32 base; /* SRAM byte address of event log header */
  3878. u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
  3879. u32 ptr; /* SRAM byte address of log data */
  3880. u32 ev, time, data; /* event log data */
  3881. if (num_events == 0)
  3882. return;
  3883. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  3884. if (mode == 0)
  3885. event_size = 2 * sizeof(u32);
  3886. else
  3887. event_size = 3 * sizeof(u32);
  3888. ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
  3889. /* "time" is actually "data" for mode 0 (no timestamp).
  3890. * place event id # at far right for easier visual parsing. */
  3891. for (i = 0; i < num_events; i++) {
  3892. ev = iwl3945_read_targ_mem(priv, ptr);
  3893. ptr += sizeof(u32);
  3894. time = iwl3945_read_targ_mem(priv, ptr);
  3895. ptr += sizeof(u32);
  3896. if (mode == 0)
  3897. IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */
  3898. else {
  3899. data = iwl3945_read_targ_mem(priv, ptr);
  3900. ptr += sizeof(u32);
  3901. IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev);
  3902. }
  3903. }
  3904. }
  3905. static void iwl3945_dump_nic_event_log(struct iwl3945_priv *priv)
  3906. {
  3907. int rc;
  3908. u32 base; /* SRAM byte address of event log header */
  3909. u32 capacity; /* event log capacity in # entries */
  3910. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  3911. u32 num_wraps; /* # times uCode wrapped to top of log */
  3912. u32 next_entry; /* index of next entry to be written by uCode */
  3913. u32 size; /* # entries that we'll print */
  3914. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  3915. if (!iwl3945_hw_valid_rtc_data_addr(base)) {
  3916. IWL_ERROR("Invalid event log pointer 0x%08X\n", base);
  3917. return;
  3918. }
  3919. rc = iwl3945_grab_nic_access(priv);
  3920. if (rc) {
  3921. IWL_WARNING("Can not read from adapter at this time.\n");
  3922. return;
  3923. }
  3924. /* event log header */
  3925. capacity = iwl3945_read_targ_mem(priv, base);
  3926. mode = iwl3945_read_targ_mem(priv, base + (1 * sizeof(u32)));
  3927. num_wraps = iwl3945_read_targ_mem(priv, base + (2 * sizeof(u32)));
  3928. next_entry = iwl3945_read_targ_mem(priv, base + (3 * sizeof(u32)));
  3929. size = num_wraps ? capacity : next_entry;
  3930. /* bail out if nothing in log */
  3931. if (size == 0) {
  3932. IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
  3933. iwl3945_release_nic_access(priv);
  3934. return;
  3935. }
  3936. IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
  3937. size, num_wraps);
  3938. /* if uCode has wrapped back to top of log, start at the oldest entry,
  3939. * i.e the next one that uCode would fill. */
  3940. if (num_wraps)
  3941. iwl3945_print_event_log(priv, next_entry,
  3942. capacity - next_entry, mode);
  3943. /* (then/else) start at top of log */
  3944. iwl3945_print_event_log(priv, 0, next_entry, mode);
  3945. iwl3945_release_nic_access(priv);
  3946. }
  3947. /**
  3948. * iwl3945_irq_handle_error - called for HW or SW error interrupt from card
  3949. */
  3950. static void iwl3945_irq_handle_error(struct iwl3945_priv *priv)
  3951. {
  3952. /* Set the FW error flag -- cleared on iwl3945_down */
  3953. set_bit(STATUS_FW_ERROR, &priv->status);
  3954. /* Cancel currently queued command. */
  3955. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  3956. #ifdef CONFIG_IWL3945_DEBUG
  3957. if (iwl3945_debug_level & IWL_DL_FW_ERRORS) {
  3958. iwl3945_dump_nic_error_log(priv);
  3959. iwl3945_dump_nic_event_log(priv);
  3960. iwl3945_print_rx_config_cmd(&priv->staging_rxon);
  3961. }
  3962. #endif
  3963. wake_up_interruptible(&priv->wait_command_queue);
  3964. /* Keep the restart process from trying to send host
  3965. * commands by clearing the INIT status bit */
  3966. clear_bit(STATUS_READY, &priv->status);
  3967. if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  3968. IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS,
  3969. "Restarting adapter due to uCode error.\n");
  3970. if (iwl3945_is_associated(priv)) {
  3971. memcpy(&priv->recovery_rxon, &priv->active_rxon,
  3972. sizeof(priv->recovery_rxon));
  3973. priv->error_recovering = 1;
  3974. }
  3975. queue_work(priv->workqueue, &priv->restart);
  3976. }
  3977. }
  3978. static void iwl3945_error_recovery(struct iwl3945_priv *priv)
  3979. {
  3980. unsigned long flags;
  3981. memcpy(&priv->staging_rxon, &priv->recovery_rxon,
  3982. sizeof(priv->staging_rxon));
  3983. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3984. iwl3945_commit_rxon(priv);
  3985. iwl3945_add_station(priv, priv->bssid, 1, 0);
  3986. spin_lock_irqsave(&priv->lock, flags);
  3987. priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
  3988. priv->error_recovering = 0;
  3989. spin_unlock_irqrestore(&priv->lock, flags);
  3990. }
  3991. static void iwl3945_irq_tasklet(struct iwl3945_priv *priv)
  3992. {
  3993. u32 inta, handled = 0;
  3994. u32 inta_fh;
  3995. unsigned long flags;
  3996. #ifdef CONFIG_IWL3945_DEBUG
  3997. u32 inta_mask;
  3998. #endif
  3999. spin_lock_irqsave(&priv->lock, flags);
  4000. /* Ack/clear/reset pending uCode interrupts.
  4001. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
  4002. * and will clear only when CSR_FH_INT_STATUS gets cleared. */
  4003. inta = iwl3945_read32(priv, CSR_INT);
  4004. iwl3945_write32(priv, CSR_INT, inta);
  4005. /* Ack/clear/reset pending flow-handler (DMA) interrupts.
  4006. * Any new interrupts that happen after this, either while we're
  4007. * in this tasklet, or later, will show up in next ISR/tasklet. */
  4008. inta_fh = iwl3945_read32(priv, CSR_FH_INT_STATUS);
  4009. iwl3945_write32(priv, CSR_FH_INT_STATUS, inta_fh);
  4010. #ifdef CONFIG_IWL3945_DEBUG
  4011. if (iwl3945_debug_level & IWL_DL_ISR) {
  4012. /* just for debug */
  4013. inta_mask = iwl3945_read32(priv, CSR_INT_MASK);
  4014. IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  4015. inta, inta_mask, inta_fh);
  4016. }
  4017. #endif
  4018. /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
  4019. * atomic, make sure that inta covers all the interrupts that
  4020. * we've discovered, even if FH interrupt came in just after
  4021. * reading CSR_INT. */
  4022. if (inta_fh & CSR_FH_INT_RX_MASK)
  4023. inta |= CSR_INT_BIT_FH_RX;
  4024. if (inta_fh & CSR_FH_INT_TX_MASK)
  4025. inta |= CSR_INT_BIT_FH_TX;
  4026. /* Now service all interrupt bits discovered above. */
  4027. if (inta & CSR_INT_BIT_HW_ERR) {
  4028. IWL_ERROR("Microcode HW error detected. Restarting.\n");
  4029. /* Tell the device to stop sending interrupts */
  4030. iwl3945_disable_interrupts(priv);
  4031. iwl3945_irq_handle_error(priv);
  4032. handled |= CSR_INT_BIT_HW_ERR;
  4033. spin_unlock_irqrestore(&priv->lock, flags);
  4034. return;
  4035. }
  4036. #ifdef CONFIG_IWL3945_DEBUG
  4037. if (iwl3945_debug_level & (IWL_DL_ISR)) {
  4038. /* NIC fires this, but we don't use it, redundant with WAKEUP */
  4039. if (inta & CSR_INT_BIT_MAC_CLK_ACTV)
  4040. IWL_DEBUG_ISR("Microcode started or stopped.\n");
  4041. /* Alive notification via Rx interrupt will do the real work */
  4042. if (inta & CSR_INT_BIT_ALIVE)
  4043. IWL_DEBUG_ISR("Alive interrupt\n");
  4044. }
  4045. #endif
  4046. /* Safely ignore these bits for debug checks below */
  4047. inta &= ~(CSR_INT_BIT_MAC_CLK_ACTV | CSR_INT_BIT_ALIVE);
  4048. /* HW RF KILL switch toggled (4965 only) */
  4049. if (inta & CSR_INT_BIT_RF_KILL) {
  4050. int hw_rf_kill = 0;
  4051. if (!(iwl3945_read32(priv, CSR_GP_CNTRL) &
  4052. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
  4053. hw_rf_kill = 1;
  4054. IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL | IWL_DL_ISR,
  4055. "RF_KILL bit toggled to %s.\n",
  4056. hw_rf_kill ? "disable radio":"enable radio");
  4057. /* Queue restart only if RF_KILL switch was set to "kill"
  4058. * when we loaded driver, and is now set to "enable".
  4059. * After we're Alive, RF_KILL gets handled by
  4060. * iwl_rx_card_state_notif() */
  4061. if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) {
  4062. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  4063. queue_work(priv->workqueue, &priv->restart);
  4064. }
  4065. handled |= CSR_INT_BIT_RF_KILL;
  4066. }
  4067. /* Chip got too hot and stopped itself (4965 only) */
  4068. if (inta & CSR_INT_BIT_CT_KILL) {
  4069. IWL_ERROR("Microcode CT kill error detected.\n");
  4070. handled |= CSR_INT_BIT_CT_KILL;
  4071. }
  4072. /* Error detected by uCode */
  4073. if (inta & CSR_INT_BIT_SW_ERR) {
  4074. IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
  4075. inta);
  4076. iwl3945_irq_handle_error(priv);
  4077. handled |= CSR_INT_BIT_SW_ERR;
  4078. }
  4079. /* uCode wakes up after power-down sleep */
  4080. if (inta & CSR_INT_BIT_WAKEUP) {
  4081. IWL_DEBUG_ISR("Wakeup interrupt\n");
  4082. iwl3945_rx_queue_update_write_ptr(priv, &priv->rxq);
  4083. iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[0]);
  4084. iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[1]);
  4085. iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[2]);
  4086. iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[3]);
  4087. iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[4]);
  4088. iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[5]);
  4089. handled |= CSR_INT_BIT_WAKEUP;
  4090. }
  4091. /* All uCode command responses, including Tx command responses,
  4092. * Rx "responses" (frame-received notification), and other
  4093. * notifications from uCode come through here*/
  4094. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
  4095. iwl3945_rx_handle(priv);
  4096. handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
  4097. }
  4098. if (inta & CSR_INT_BIT_FH_TX) {
  4099. IWL_DEBUG_ISR("Tx interrupt\n");
  4100. iwl3945_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
  4101. if (!iwl3945_grab_nic_access(priv)) {
  4102. iwl3945_write_direct32(priv,
  4103. FH_TCSR_CREDIT
  4104. (ALM_FH_SRVC_CHNL), 0x0);
  4105. iwl3945_release_nic_access(priv);
  4106. }
  4107. handled |= CSR_INT_BIT_FH_TX;
  4108. }
  4109. if (inta & ~handled)
  4110. IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
  4111. if (inta & ~CSR_INI_SET_MASK) {
  4112. IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
  4113. inta & ~CSR_INI_SET_MASK);
  4114. IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh);
  4115. }
  4116. /* Re-enable all interrupts */
  4117. iwl3945_enable_interrupts(priv);
  4118. #ifdef CONFIG_IWL3945_DEBUG
  4119. if (iwl3945_debug_level & (IWL_DL_ISR)) {
  4120. inta = iwl3945_read32(priv, CSR_INT);
  4121. inta_mask = iwl3945_read32(priv, CSR_INT_MASK);
  4122. inta_fh = iwl3945_read32(priv, CSR_FH_INT_STATUS);
  4123. IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
  4124. "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
  4125. }
  4126. #endif
  4127. spin_unlock_irqrestore(&priv->lock, flags);
  4128. }
  4129. static irqreturn_t iwl3945_isr(int irq, void *data)
  4130. {
  4131. struct iwl3945_priv *priv = data;
  4132. u32 inta, inta_mask;
  4133. u32 inta_fh;
  4134. if (!priv)
  4135. return IRQ_NONE;
  4136. spin_lock(&priv->lock);
  4137. /* Disable (but don't clear!) interrupts here to avoid
  4138. * back-to-back ISRs and sporadic interrupts from our NIC.
  4139. * If we have something to service, the tasklet will re-enable ints.
  4140. * If we *don't* have something, we'll re-enable before leaving here. */
  4141. inta_mask = iwl3945_read32(priv, CSR_INT_MASK); /* just for debug */
  4142. iwl3945_write32(priv, CSR_INT_MASK, 0x00000000);
  4143. /* Discover which interrupts are active/pending */
  4144. inta = iwl3945_read32(priv, CSR_INT);
  4145. inta_fh = iwl3945_read32(priv, CSR_FH_INT_STATUS);
  4146. /* Ignore interrupt if there's nothing in NIC to service.
  4147. * This may be due to IRQ shared with another device,
  4148. * or due to sporadic interrupts thrown from our NIC. */
  4149. if (!inta && !inta_fh) {
  4150. IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
  4151. goto none;
  4152. }
  4153. if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
  4154. /* Hardware disappeared */
  4155. IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
  4156. goto unplugged;
  4157. }
  4158. IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  4159. inta, inta_mask, inta_fh);
  4160. /* iwl3945_irq_tasklet() will service interrupts and re-enable them */
  4161. tasklet_schedule(&priv->irq_tasklet);
  4162. unplugged:
  4163. spin_unlock(&priv->lock);
  4164. return IRQ_HANDLED;
  4165. none:
  4166. /* re-enable interrupts here since we don't have anything to service. */
  4167. iwl3945_enable_interrupts(priv);
  4168. spin_unlock(&priv->lock);
  4169. return IRQ_NONE;
  4170. }
  4171. /************************** EEPROM BANDS ****************************
  4172. *
  4173. * The iwl3945_eeprom_band definitions below provide the mapping from the
  4174. * EEPROM contents to the specific channel number supported for each
  4175. * band.
  4176. *
  4177. * For example, iwl3945_priv->eeprom.band_3_channels[4] from the band_3
  4178. * definition below maps to physical channel 42 in the 5.2GHz spectrum.
  4179. * The specific geography and calibration information for that channel
  4180. * is contained in the eeprom map itself.
  4181. *
  4182. * During init, we copy the eeprom information and channel map
  4183. * information into priv->channel_info_24/52 and priv->channel_map_24/52
  4184. *
  4185. * channel_map_24/52 provides the index in the channel_info array for a
  4186. * given channel. We have to have two separate maps as there is channel
  4187. * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
  4188. * band_2
  4189. *
  4190. * A value of 0xff stored in the channel_map indicates that the channel
  4191. * is not supported by the hardware at all.
  4192. *
  4193. * A value of 0xfe in the channel_map indicates that the channel is not
  4194. * valid for Tx with the current hardware. This means that
  4195. * while the system can tune and receive on a given channel, it may not
  4196. * be able to associate or transmit any frames on that
  4197. * channel. There is no corresponding channel information for that
  4198. * entry.
  4199. *
  4200. *********************************************************************/
  4201. /* 2.4 GHz */
  4202. static const u8 iwl3945_eeprom_band_1[14] = {
  4203. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
  4204. };
  4205. /* 5.2 GHz bands */
  4206. static const u8 iwl3945_eeprom_band_2[] = { /* 4915-5080MHz */
  4207. 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
  4208. };
  4209. static const u8 iwl3945_eeprom_band_3[] = { /* 5170-5320MHz */
  4210. 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
  4211. };
  4212. static const u8 iwl3945_eeprom_band_4[] = { /* 5500-5700MHz */
  4213. 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
  4214. };
  4215. static const u8 iwl3945_eeprom_band_5[] = { /* 5725-5825MHz */
  4216. 145, 149, 153, 157, 161, 165
  4217. };
  4218. static void iwl3945_init_band_reference(const struct iwl3945_priv *priv, int band,
  4219. int *eeprom_ch_count,
  4220. const struct iwl3945_eeprom_channel
  4221. **eeprom_ch_info,
  4222. const u8 **eeprom_ch_index)
  4223. {
  4224. switch (band) {
  4225. case 1: /* 2.4GHz band */
  4226. *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_1);
  4227. *eeprom_ch_info = priv->eeprom.band_1_channels;
  4228. *eeprom_ch_index = iwl3945_eeprom_band_1;
  4229. break;
  4230. case 2: /* 4.9GHz band */
  4231. *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_2);
  4232. *eeprom_ch_info = priv->eeprom.band_2_channels;
  4233. *eeprom_ch_index = iwl3945_eeprom_band_2;
  4234. break;
  4235. case 3: /* 5.2GHz band */
  4236. *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_3);
  4237. *eeprom_ch_info = priv->eeprom.band_3_channels;
  4238. *eeprom_ch_index = iwl3945_eeprom_band_3;
  4239. break;
  4240. case 4: /* 5.5GHz band */
  4241. *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_4);
  4242. *eeprom_ch_info = priv->eeprom.band_4_channels;
  4243. *eeprom_ch_index = iwl3945_eeprom_band_4;
  4244. break;
  4245. case 5: /* 5.7GHz band */
  4246. *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_5);
  4247. *eeprom_ch_info = priv->eeprom.band_5_channels;
  4248. *eeprom_ch_index = iwl3945_eeprom_band_5;
  4249. break;
  4250. default:
  4251. BUG();
  4252. return;
  4253. }
  4254. }
  4255. /**
  4256. * iwl3945_get_channel_info - Find driver's private channel info
  4257. *
  4258. * Based on band and channel number.
  4259. */
  4260. const struct iwl3945_channel_info *iwl3945_get_channel_info(const struct iwl3945_priv *priv,
  4261. int phymode, u16 channel)
  4262. {
  4263. int i;
  4264. switch (phymode) {
  4265. case MODE_IEEE80211A:
  4266. for (i = 14; i < priv->channel_count; i++) {
  4267. if (priv->channel_info[i].channel == channel)
  4268. return &priv->channel_info[i];
  4269. }
  4270. break;
  4271. case MODE_IEEE80211B:
  4272. case MODE_IEEE80211G:
  4273. if (channel >= 1 && channel <= 14)
  4274. return &priv->channel_info[channel - 1];
  4275. break;
  4276. }
  4277. return NULL;
  4278. }
  4279. #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
  4280. ? # x " " : "")
  4281. /**
  4282. * iwl3945_init_channel_map - Set up driver's info for all possible channels
  4283. */
  4284. static int iwl3945_init_channel_map(struct iwl3945_priv *priv)
  4285. {
  4286. int eeprom_ch_count = 0;
  4287. const u8 *eeprom_ch_index = NULL;
  4288. const struct iwl3945_eeprom_channel *eeprom_ch_info = NULL;
  4289. int band, ch;
  4290. struct iwl3945_channel_info *ch_info;
  4291. if (priv->channel_count) {
  4292. IWL_DEBUG_INFO("Channel map already initialized.\n");
  4293. return 0;
  4294. }
  4295. if (priv->eeprom.version < 0x2f) {
  4296. IWL_WARNING("Unsupported EEPROM version: 0x%04X\n",
  4297. priv->eeprom.version);
  4298. return -EINVAL;
  4299. }
  4300. IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n");
  4301. priv->channel_count =
  4302. ARRAY_SIZE(iwl3945_eeprom_band_1) +
  4303. ARRAY_SIZE(iwl3945_eeprom_band_2) +
  4304. ARRAY_SIZE(iwl3945_eeprom_band_3) +
  4305. ARRAY_SIZE(iwl3945_eeprom_band_4) +
  4306. ARRAY_SIZE(iwl3945_eeprom_band_5);
  4307. IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count);
  4308. priv->channel_info = kzalloc(sizeof(struct iwl3945_channel_info) *
  4309. priv->channel_count, GFP_KERNEL);
  4310. if (!priv->channel_info) {
  4311. IWL_ERROR("Could not allocate channel_info\n");
  4312. priv->channel_count = 0;
  4313. return -ENOMEM;
  4314. }
  4315. ch_info = priv->channel_info;
  4316. /* Loop through the 5 EEPROM bands adding them in order to the
  4317. * channel map we maintain (that contains additional information than
  4318. * what just in the EEPROM) */
  4319. for (band = 1; band <= 5; band++) {
  4320. iwl3945_init_band_reference(priv, band, &eeprom_ch_count,
  4321. &eeprom_ch_info, &eeprom_ch_index);
  4322. /* Loop through each band adding each of the channels */
  4323. for (ch = 0; ch < eeprom_ch_count; ch++) {
  4324. ch_info->channel = eeprom_ch_index[ch];
  4325. ch_info->phymode = (band == 1) ? MODE_IEEE80211B :
  4326. MODE_IEEE80211A;
  4327. /* permanently store EEPROM's channel regulatory flags
  4328. * and max power in channel info database. */
  4329. ch_info->eeprom = eeprom_ch_info[ch];
  4330. /* Copy the run-time flags so they are there even on
  4331. * invalid channels */
  4332. ch_info->flags = eeprom_ch_info[ch].flags;
  4333. if (!(is_channel_valid(ch_info))) {
  4334. IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - "
  4335. "No traffic\n",
  4336. ch_info->channel,
  4337. ch_info->flags,
  4338. is_channel_a_band(ch_info) ?
  4339. "5.2" : "2.4");
  4340. ch_info++;
  4341. continue;
  4342. }
  4343. /* Initialize regulatory-based run-time data */
  4344. ch_info->max_power_avg = ch_info->curr_txpow =
  4345. eeprom_ch_info[ch].max_power_avg;
  4346. ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
  4347. ch_info->min_power = 0;
  4348. IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x"
  4349. " %ddBm): Ad-Hoc %ssupported\n",
  4350. ch_info->channel,
  4351. is_channel_a_band(ch_info) ?
  4352. "5.2" : "2.4",
  4353. CHECK_AND_PRINT(IBSS),
  4354. CHECK_AND_PRINT(ACTIVE),
  4355. CHECK_AND_PRINT(RADAR),
  4356. CHECK_AND_PRINT(WIDE),
  4357. CHECK_AND_PRINT(NARROW),
  4358. CHECK_AND_PRINT(DFS),
  4359. eeprom_ch_info[ch].flags,
  4360. eeprom_ch_info[ch].max_power_avg,
  4361. ((eeprom_ch_info[ch].
  4362. flags & EEPROM_CHANNEL_IBSS)
  4363. && !(eeprom_ch_info[ch].
  4364. flags & EEPROM_CHANNEL_RADAR))
  4365. ? "" : "not ");
  4366. /* Set the user_txpower_limit to the highest power
  4367. * supported by any channel */
  4368. if (eeprom_ch_info[ch].max_power_avg >
  4369. priv->user_txpower_limit)
  4370. priv->user_txpower_limit =
  4371. eeprom_ch_info[ch].max_power_avg;
  4372. ch_info++;
  4373. }
  4374. }
  4375. /* Set up txpower settings in driver for all channels */
  4376. if (iwl3945_txpower_set_from_eeprom(priv))
  4377. return -EIO;
  4378. return 0;
  4379. }
  4380. /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
  4381. * sending probe req. This should be set long enough to hear probe responses
  4382. * from more than one AP. */
  4383. #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
  4384. #define IWL_ACTIVE_DWELL_TIME_52 (10)
  4385. /* For faster active scanning, scan will move to the next channel if fewer than
  4386. * PLCP_QUIET_THRESH packets are heard on this channel within
  4387. * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
  4388. * time if it's a quiet channel (nothing responded to our probe, and there's
  4389. * no other traffic).
  4390. * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
  4391. #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
  4392. #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
  4393. /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
  4394. * Must be set longer than active dwell time.
  4395. * For the most reliable scan, set > AP beacon interval (typically 100msec). */
  4396. #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
  4397. #define IWL_PASSIVE_DWELL_TIME_52 (10)
  4398. #define IWL_PASSIVE_DWELL_BASE (100)
  4399. #define IWL_CHANNEL_TUNE_TIME 5
  4400. static inline u16 iwl3945_get_active_dwell_time(struct iwl3945_priv *priv, int phymode)
  4401. {
  4402. if (phymode == MODE_IEEE80211A)
  4403. return IWL_ACTIVE_DWELL_TIME_52;
  4404. else
  4405. return IWL_ACTIVE_DWELL_TIME_24;
  4406. }
  4407. static u16 iwl3945_get_passive_dwell_time(struct iwl3945_priv *priv, int phymode)
  4408. {
  4409. u16 active = iwl3945_get_active_dwell_time(priv, phymode);
  4410. u16 passive = (phymode != MODE_IEEE80211A) ?
  4411. IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
  4412. IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
  4413. if (iwl3945_is_associated(priv)) {
  4414. /* If we're associated, we clamp the maximum passive
  4415. * dwell time to be 98% of the beacon interval (minus
  4416. * 2 * channel tune time) */
  4417. passive = priv->beacon_int;
  4418. if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive)
  4419. passive = IWL_PASSIVE_DWELL_BASE;
  4420. passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
  4421. }
  4422. if (passive <= active)
  4423. passive = active + 1;
  4424. return passive;
  4425. }
  4426. static int iwl3945_get_channels_for_scan(struct iwl3945_priv *priv, int phymode,
  4427. u8 is_active, u8 direct_mask,
  4428. struct iwl3945_scan_channel *scan_ch)
  4429. {
  4430. const struct ieee80211_channel *channels = NULL;
  4431. const struct ieee80211_hw_mode *hw_mode;
  4432. const struct iwl3945_channel_info *ch_info;
  4433. u16 passive_dwell = 0;
  4434. u16 active_dwell = 0;
  4435. int added, i;
  4436. hw_mode = iwl3945_get_hw_mode(priv, phymode);
  4437. if (!hw_mode)
  4438. return 0;
  4439. channels = hw_mode->channels;
  4440. active_dwell = iwl3945_get_active_dwell_time(priv, phymode);
  4441. passive_dwell = iwl3945_get_passive_dwell_time(priv, phymode);
  4442. for (i = 0, added = 0; i < hw_mode->num_channels; i++) {
  4443. if (channels[i].chan ==
  4444. le16_to_cpu(priv->active_rxon.channel)) {
  4445. if (iwl3945_is_associated(priv)) {
  4446. IWL_DEBUG_SCAN
  4447. ("Skipping current channel %d\n",
  4448. le16_to_cpu(priv->active_rxon.channel));
  4449. continue;
  4450. }
  4451. } else if (priv->only_active_channel)
  4452. continue;
  4453. scan_ch->channel = channels[i].chan;
  4454. ch_info = iwl3945_get_channel_info(priv, phymode, scan_ch->channel);
  4455. if (!is_channel_valid(ch_info)) {
  4456. IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
  4457. scan_ch->channel);
  4458. continue;
  4459. }
  4460. if (!is_active || is_channel_passive(ch_info) ||
  4461. !(channels[i].flag & IEEE80211_CHAN_W_ACTIVE_SCAN))
  4462. scan_ch->type = 0; /* passive */
  4463. else
  4464. scan_ch->type = 1; /* active */
  4465. if (scan_ch->type & 1)
  4466. scan_ch->type |= (direct_mask << 1);
  4467. if (is_channel_narrow(ch_info))
  4468. scan_ch->type |= (1 << 7);
  4469. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  4470. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  4471. /* Set txpower levels to defaults */
  4472. scan_ch->tpc.dsp_atten = 110;
  4473. /* scan_pwr_info->tpc.dsp_atten; */
  4474. /*scan_pwr_info->tpc.tx_gain; */
  4475. if (phymode == MODE_IEEE80211A)
  4476. scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
  4477. else {
  4478. scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
  4479. /* NOTE: if we were doing 6Mb OFDM for scans we'd use
  4480. * power level:
  4481. * scan_ch->tpc.tx_gain = ((1<<5) | (2 << 3)) | 3;
  4482. */
  4483. }
  4484. IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
  4485. scan_ch->channel,
  4486. (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
  4487. (scan_ch->type & 1) ?
  4488. active_dwell : passive_dwell);
  4489. scan_ch++;
  4490. added++;
  4491. }
  4492. IWL_DEBUG_SCAN("total channels to scan %d \n", added);
  4493. return added;
  4494. }
  4495. static void iwl3945_reset_channel_flag(struct iwl3945_priv *priv)
  4496. {
  4497. int i, j;
  4498. for (i = 0; i < 3; i++) {
  4499. struct ieee80211_hw_mode *hw_mode = (void *)&priv->modes[i];
  4500. for (j = 0; j < hw_mode->num_channels; j++)
  4501. hw_mode->channels[j].flag = hw_mode->channels[j].val;
  4502. }
  4503. }
  4504. static void iwl3945_init_hw_rates(struct iwl3945_priv *priv,
  4505. struct ieee80211_rate *rates)
  4506. {
  4507. int i;
  4508. for (i = 0; i < IWL_RATE_COUNT; i++) {
  4509. rates[i].rate = iwl3945_rates[i].ieee * 5;
  4510. rates[i].val = i; /* Rate scaling will work on indexes */
  4511. rates[i].val2 = i;
  4512. rates[i].flags = IEEE80211_RATE_SUPPORTED;
  4513. /* Only OFDM have the bits-per-symbol set */
  4514. if ((i <= IWL_LAST_OFDM_RATE) && (i >= IWL_FIRST_OFDM_RATE))
  4515. rates[i].flags |= IEEE80211_RATE_OFDM;
  4516. else {
  4517. /*
  4518. * If CCK 1M then set rate flag to CCK else CCK_2
  4519. * which is CCK | PREAMBLE2
  4520. */
  4521. rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
  4522. IEEE80211_RATE_CCK : IEEE80211_RATE_CCK_2;
  4523. }
  4524. /* Set up which ones are basic rates... */
  4525. if (IWL_BASIC_RATES_MASK & (1 << i))
  4526. rates[i].flags |= IEEE80211_RATE_BASIC;
  4527. }
  4528. }
  4529. /**
  4530. * iwl3945_init_geos - Initialize mac80211's geo/channel info based from eeprom
  4531. */
  4532. static int iwl3945_init_geos(struct iwl3945_priv *priv)
  4533. {
  4534. struct iwl3945_channel_info *ch;
  4535. struct ieee80211_hw_mode *modes;
  4536. struct ieee80211_channel *channels;
  4537. struct ieee80211_channel *geo_ch;
  4538. struct ieee80211_rate *rates;
  4539. int i = 0;
  4540. enum {
  4541. A = 0,
  4542. B = 1,
  4543. G = 2,
  4544. };
  4545. int mode_count = 3;
  4546. if (priv->modes) {
  4547. IWL_DEBUG_INFO("Geography modes already initialized.\n");
  4548. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  4549. return 0;
  4550. }
  4551. modes = kzalloc(sizeof(struct ieee80211_hw_mode) * mode_count,
  4552. GFP_KERNEL);
  4553. if (!modes)
  4554. return -ENOMEM;
  4555. channels = kzalloc(sizeof(struct ieee80211_channel) *
  4556. priv->channel_count, GFP_KERNEL);
  4557. if (!channels) {
  4558. kfree(modes);
  4559. return -ENOMEM;
  4560. }
  4561. rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_MAX_RATES + 1)),
  4562. GFP_KERNEL);
  4563. if (!rates) {
  4564. kfree(modes);
  4565. kfree(channels);
  4566. return -ENOMEM;
  4567. }
  4568. /* 0 = 802.11a
  4569. * 1 = 802.11b
  4570. * 2 = 802.11g
  4571. */
  4572. /* 5.2GHz channels start after the 2.4GHz channels */
  4573. modes[A].mode = MODE_IEEE80211A;
  4574. modes[A].channels = &channels[ARRAY_SIZE(iwl3945_eeprom_band_1)];
  4575. modes[A].rates = &rates[4];
  4576. modes[A].num_rates = 8; /* just OFDM */
  4577. modes[A].num_channels = 0;
  4578. modes[B].mode = MODE_IEEE80211B;
  4579. modes[B].channels = channels;
  4580. modes[B].rates = rates;
  4581. modes[B].num_rates = 4; /* just CCK */
  4582. modes[B].num_channels = 0;
  4583. modes[G].mode = MODE_IEEE80211G;
  4584. modes[G].channels = channels;
  4585. modes[G].rates = rates;
  4586. modes[G].num_rates = 12; /* OFDM & CCK */
  4587. modes[G].num_channels = 0;
  4588. priv->ieee_channels = channels;
  4589. priv->ieee_rates = rates;
  4590. iwl3945_init_hw_rates(priv, rates);
  4591. for (i = 0, geo_ch = channels; i < priv->channel_count; i++) {
  4592. ch = &priv->channel_info[i];
  4593. if (!is_channel_valid(ch)) {
  4594. IWL_DEBUG_INFO("Channel %d [%sGHz] is restricted -- "
  4595. "skipping.\n",
  4596. ch->channel, is_channel_a_band(ch) ?
  4597. "5.2" : "2.4");
  4598. continue;
  4599. }
  4600. if (is_channel_a_band(ch))
  4601. geo_ch = &modes[A].channels[modes[A].num_channels++];
  4602. else {
  4603. geo_ch = &modes[B].channels[modes[B].num_channels++];
  4604. modes[G].num_channels++;
  4605. }
  4606. geo_ch->freq = ieee80211chan2mhz(ch->channel);
  4607. geo_ch->chan = ch->channel;
  4608. geo_ch->power_level = ch->max_power_avg;
  4609. geo_ch->antenna_max = 0xff;
  4610. if (is_channel_valid(ch)) {
  4611. geo_ch->flag = IEEE80211_CHAN_W_SCAN;
  4612. if (ch->flags & EEPROM_CHANNEL_IBSS)
  4613. geo_ch->flag |= IEEE80211_CHAN_W_IBSS;
  4614. if (ch->flags & EEPROM_CHANNEL_ACTIVE)
  4615. geo_ch->flag |= IEEE80211_CHAN_W_ACTIVE_SCAN;
  4616. if (ch->flags & EEPROM_CHANNEL_RADAR)
  4617. geo_ch->flag |= IEEE80211_CHAN_W_RADAR_DETECT;
  4618. if (ch->max_power_avg > priv->max_channel_txpower_limit)
  4619. priv->max_channel_txpower_limit =
  4620. ch->max_power_avg;
  4621. }
  4622. geo_ch->val = geo_ch->flag;
  4623. }
  4624. if ((modes[A].num_channels == 0) && priv->is_abg) {
  4625. printk(KERN_INFO DRV_NAME
  4626. ": Incorrectly detected BG card as ABG. Please send "
  4627. "your PCI ID 0x%04X:0x%04X to maintainer.\n",
  4628. priv->pci_dev->device, priv->pci_dev->subsystem_device);
  4629. priv->is_abg = 0;
  4630. }
  4631. printk(KERN_INFO DRV_NAME
  4632. ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
  4633. modes[G].num_channels, modes[A].num_channels);
  4634. /*
  4635. * NOTE: We register these in preference of order -- the
  4636. * stack doesn't currently (as of 7.0.6 / Apr 24 '07) pick
  4637. * a phymode based on rates or AP capabilities but seems to
  4638. * configure it purely on if the channel being configured
  4639. * is supported by a mode -- and the first match is taken
  4640. */
  4641. if (modes[G].num_channels)
  4642. ieee80211_register_hwmode(priv->hw, &modes[G]);
  4643. if (modes[B].num_channels)
  4644. ieee80211_register_hwmode(priv->hw, &modes[B]);
  4645. if (modes[A].num_channels)
  4646. ieee80211_register_hwmode(priv->hw, &modes[A]);
  4647. priv->modes = modes;
  4648. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  4649. return 0;
  4650. }
  4651. /******************************************************************************
  4652. *
  4653. * uCode download functions
  4654. *
  4655. ******************************************************************************/
  4656. static void iwl3945_dealloc_ucode_pci(struct iwl3945_priv *priv)
  4657. {
  4658. if (priv->ucode_code.v_addr != NULL) {
  4659. pci_free_consistent(priv->pci_dev,
  4660. priv->ucode_code.len,
  4661. priv->ucode_code.v_addr,
  4662. priv->ucode_code.p_addr);
  4663. priv->ucode_code.v_addr = NULL;
  4664. }
  4665. if (priv->ucode_data.v_addr != NULL) {
  4666. pci_free_consistent(priv->pci_dev,
  4667. priv->ucode_data.len,
  4668. priv->ucode_data.v_addr,
  4669. priv->ucode_data.p_addr);
  4670. priv->ucode_data.v_addr = NULL;
  4671. }
  4672. if (priv->ucode_data_backup.v_addr != NULL) {
  4673. pci_free_consistent(priv->pci_dev,
  4674. priv->ucode_data_backup.len,
  4675. priv->ucode_data_backup.v_addr,
  4676. priv->ucode_data_backup.p_addr);
  4677. priv->ucode_data_backup.v_addr = NULL;
  4678. }
  4679. if (priv->ucode_init.v_addr != NULL) {
  4680. pci_free_consistent(priv->pci_dev,
  4681. priv->ucode_init.len,
  4682. priv->ucode_init.v_addr,
  4683. priv->ucode_init.p_addr);
  4684. priv->ucode_init.v_addr = NULL;
  4685. }
  4686. if (priv->ucode_init_data.v_addr != NULL) {
  4687. pci_free_consistent(priv->pci_dev,
  4688. priv->ucode_init_data.len,
  4689. priv->ucode_init_data.v_addr,
  4690. priv->ucode_init_data.p_addr);
  4691. priv->ucode_init_data.v_addr = NULL;
  4692. }
  4693. if (priv->ucode_boot.v_addr != NULL) {
  4694. pci_free_consistent(priv->pci_dev,
  4695. priv->ucode_boot.len,
  4696. priv->ucode_boot.v_addr,
  4697. priv->ucode_boot.p_addr);
  4698. priv->ucode_boot.v_addr = NULL;
  4699. }
  4700. }
  4701. /**
  4702. * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
  4703. * looking at all data.
  4704. */
  4705. static int iwl3945_verify_inst_full(struct iwl3945_priv *priv, __le32 * image, u32 len)
  4706. {
  4707. u32 val;
  4708. u32 save_len = len;
  4709. int rc = 0;
  4710. u32 errcnt;
  4711. IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
  4712. rc = iwl3945_grab_nic_access(priv);
  4713. if (rc)
  4714. return rc;
  4715. iwl3945_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND);
  4716. errcnt = 0;
  4717. for (; len > 0; len -= sizeof(u32), image++) {
  4718. /* read data comes through single port, auto-incr addr */
  4719. /* NOTE: Use the debugless read so we don't flood kernel log
  4720. * if IWL_DL_IO is set */
  4721. val = _iwl3945_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  4722. if (val != le32_to_cpu(*image)) {
  4723. IWL_ERROR("uCode INST section is invalid at "
  4724. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  4725. save_len - len, val, le32_to_cpu(*image));
  4726. rc = -EIO;
  4727. errcnt++;
  4728. if (errcnt >= 20)
  4729. break;
  4730. }
  4731. }
  4732. iwl3945_release_nic_access(priv);
  4733. if (!errcnt)
  4734. IWL_DEBUG_INFO("ucode image in INSTRUCTION memory is good\n");
  4735. return rc;
  4736. }
  4737. /**
  4738. * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
  4739. * using sample data 100 bytes apart. If these sample points are good,
  4740. * it's a pretty good bet that everything between them is good, too.
  4741. */
  4742. static int iwl3945_verify_inst_sparse(struct iwl3945_priv *priv, __le32 *image, u32 len)
  4743. {
  4744. u32 val;
  4745. int rc = 0;
  4746. u32 errcnt = 0;
  4747. u32 i;
  4748. IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
  4749. rc = iwl3945_grab_nic_access(priv);
  4750. if (rc)
  4751. return rc;
  4752. for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
  4753. /* read data comes through single port, auto-incr addr */
  4754. /* NOTE: Use the debugless read so we don't flood kernel log
  4755. * if IWL_DL_IO is set */
  4756. iwl3945_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  4757. i + RTC_INST_LOWER_BOUND);
  4758. val = _iwl3945_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  4759. if (val != le32_to_cpu(*image)) {
  4760. #if 0 /* Enable this if you want to see details */
  4761. IWL_ERROR("uCode INST section is invalid at "
  4762. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  4763. i, val, *image);
  4764. #endif
  4765. rc = -EIO;
  4766. errcnt++;
  4767. if (errcnt >= 3)
  4768. break;
  4769. }
  4770. }
  4771. iwl3945_release_nic_access(priv);
  4772. return rc;
  4773. }
  4774. /**
  4775. * iwl3945_verify_ucode - determine which instruction image is in SRAM,
  4776. * and verify its contents
  4777. */
  4778. static int iwl3945_verify_ucode(struct iwl3945_priv *priv)
  4779. {
  4780. __le32 *image;
  4781. u32 len;
  4782. int rc = 0;
  4783. /* Try bootstrap */
  4784. image = (__le32 *)priv->ucode_boot.v_addr;
  4785. len = priv->ucode_boot.len;
  4786. rc = iwl3945_verify_inst_sparse(priv, image, len);
  4787. if (rc == 0) {
  4788. IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
  4789. return 0;
  4790. }
  4791. /* Try initialize */
  4792. image = (__le32 *)priv->ucode_init.v_addr;
  4793. len = priv->ucode_init.len;
  4794. rc = iwl3945_verify_inst_sparse(priv, image, len);
  4795. if (rc == 0) {
  4796. IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
  4797. return 0;
  4798. }
  4799. /* Try runtime/protocol */
  4800. image = (__le32 *)priv->ucode_code.v_addr;
  4801. len = priv->ucode_code.len;
  4802. rc = iwl3945_verify_inst_sparse(priv, image, len);
  4803. if (rc == 0) {
  4804. IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
  4805. return 0;
  4806. }
  4807. IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
  4808. /* Since nothing seems to match, show first several data entries in
  4809. * instruction SRAM, so maybe visual inspection will give a clue.
  4810. * Selection of bootstrap image (vs. other images) is arbitrary. */
  4811. image = (__le32 *)priv->ucode_boot.v_addr;
  4812. len = priv->ucode_boot.len;
  4813. rc = iwl3945_verify_inst_full(priv, image, len);
  4814. return rc;
  4815. }
  4816. /* check contents of special bootstrap uCode SRAM */
  4817. static int iwl3945_verify_bsm(struct iwl3945_priv *priv)
  4818. {
  4819. __le32 *image = priv->ucode_boot.v_addr;
  4820. u32 len = priv->ucode_boot.len;
  4821. u32 reg;
  4822. u32 val;
  4823. IWL_DEBUG_INFO("Begin verify bsm\n");
  4824. /* verify BSM SRAM contents */
  4825. val = iwl3945_read_prph(priv, BSM_WR_DWCOUNT_REG);
  4826. for (reg = BSM_SRAM_LOWER_BOUND;
  4827. reg < BSM_SRAM_LOWER_BOUND + len;
  4828. reg += sizeof(u32), image ++) {
  4829. val = iwl3945_read_prph(priv, reg);
  4830. if (val != le32_to_cpu(*image)) {
  4831. IWL_ERROR("BSM uCode verification failed at "
  4832. "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
  4833. BSM_SRAM_LOWER_BOUND,
  4834. reg - BSM_SRAM_LOWER_BOUND, len,
  4835. val, le32_to_cpu(*image));
  4836. return -EIO;
  4837. }
  4838. }
  4839. IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n");
  4840. return 0;
  4841. }
  4842. /**
  4843. * iwl3945_load_bsm - Load bootstrap instructions
  4844. *
  4845. * BSM operation:
  4846. *
  4847. * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
  4848. * in special SRAM that does not power down during RFKILL. When powering back
  4849. * up after power-saving sleeps (or during initial uCode load), the BSM loads
  4850. * the bootstrap program into the on-board processor, and starts it.
  4851. *
  4852. * The bootstrap program loads (via DMA) instructions and data for a new
  4853. * program from host DRAM locations indicated by the host driver in the
  4854. * BSM_DRAM_* registers. Once the new program is loaded, it starts
  4855. * automatically.
  4856. *
  4857. * When initializing the NIC, the host driver points the BSM to the
  4858. * "initialize" uCode image. This uCode sets up some internal data, then
  4859. * notifies host via "initialize alive" that it is complete.
  4860. *
  4861. * The host then replaces the BSM_DRAM_* pointer values to point to the
  4862. * normal runtime uCode instructions and a backup uCode data cache buffer
  4863. * (filled initially with starting data values for the on-board processor),
  4864. * then triggers the "initialize" uCode to load and launch the runtime uCode,
  4865. * which begins normal operation.
  4866. *
  4867. * When doing a power-save shutdown, runtime uCode saves data SRAM into
  4868. * the backup data cache in DRAM before SRAM is powered down.
  4869. *
  4870. * When powering back up, the BSM loads the bootstrap program. This reloads
  4871. * the runtime uCode instructions and the backup data cache into SRAM,
  4872. * and re-launches the runtime uCode from where it left off.
  4873. */
  4874. static int iwl3945_load_bsm(struct iwl3945_priv *priv)
  4875. {
  4876. __le32 *image = priv->ucode_boot.v_addr;
  4877. u32 len = priv->ucode_boot.len;
  4878. dma_addr_t pinst;
  4879. dma_addr_t pdata;
  4880. u32 inst_len;
  4881. u32 data_len;
  4882. int rc;
  4883. int i;
  4884. u32 done;
  4885. u32 reg_offset;
  4886. IWL_DEBUG_INFO("Begin load bsm\n");
  4887. /* make sure bootstrap program is no larger than BSM's SRAM size */
  4888. if (len > IWL_MAX_BSM_SIZE)
  4889. return -EINVAL;
  4890. /* Tell bootstrap uCode where to find the "Initialize" uCode
  4891. * in host DRAM ... host DRAM physical address bits 31:0 for 3945.
  4892. * NOTE: iwl3945_initialize_alive_start() will replace these values,
  4893. * after the "initialize" uCode has run, to point to
  4894. * runtime/protocol instructions and backup data cache. */
  4895. pinst = priv->ucode_init.p_addr;
  4896. pdata = priv->ucode_init_data.p_addr;
  4897. inst_len = priv->ucode_init.len;
  4898. data_len = priv->ucode_init_data.len;
  4899. rc = iwl3945_grab_nic_access(priv);
  4900. if (rc)
  4901. return rc;
  4902. iwl3945_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
  4903. iwl3945_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
  4904. iwl3945_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
  4905. iwl3945_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len);
  4906. /* Fill BSM memory with bootstrap instructions */
  4907. for (reg_offset = BSM_SRAM_LOWER_BOUND;
  4908. reg_offset < BSM_SRAM_LOWER_BOUND + len;
  4909. reg_offset += sizeof(u32), image++)
  4910. _iwl3945_write_prph(priv, reg_offset,
  4911. le32_to_cpu(*image));
  4912. rc = iwl3945_verify_bsm(priv);
  4913. if (rc) {
  4914. iwl3945_release_nic_access(priv);
  4915. return rc;
  4916. }
  4917. /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
  4918. iwl3945_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0);
  4919. iwl3945_write_prph(priv, BSM_WR_MEM_DST_REG,
  4920. RTC_INST_LOWER_BOUND);
  4921. iwl3945_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
  4922. /* Load bootstrap code into instruction SRAM now,
  4923. * to prepare to load "initialize" uCode */
  4924. iwl3945_write_prph(priv, BSM_WR_CTRL_REG,
  4925. BSM_WR_CTRL_REG_BIT_START);
  4926. /* Wait for load of bootstrap uCode to finish */
  4927. for (i = 0; i < 100; i++) {
  4928. done = iwl3945_read_prph(priv, BSM_WR_CTRL_REG);
  4929. if (!(done & BSM_WR_CTRL_REG_BIT_START))
  4930. break;
  4931. udelay(10);
  4932. }
  4933. if (i < 100)
  4934. IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i);
  4935. else {
  4936. IWL_ERROR("BSM write did not complete!\n");
  4937. return -EIO;
  4938. }
  4939. /* Enable future boot loads whenever power management unit triggers it
  4940. * (e.g. when powering back up after power-save shutdown) */
  4941. iwl3945_write_prph(priv, BSM_WR_CTRL_REG,
  4942. BSM_WR_CTRL_REG_BIT_START_EN);
  4943. iwl3945_release_nic_access(priv);
  4944. return 0;
  4945. }
  4946. static void iwl3945_nic_start(struct iwl3945_priv *priv)
  4947. {
  4948. /* Remove all resets to allow NIC to operate */
  4949. iwl3945_write32(priv, CSR_RESET, 0);
  4950. }
  4951. static int iwl3945_alloc_fw_desc(struct pci_dev *pci_dev, struct fw_desc *desc)
  4952. {
  4953. desc->v_addr = pci_alloc_consistent(pci_dev, desc->len, &desc->p_addr);
  4954. return (desc->v_addr != NULL) ? 0 : -ENOMEM;
  4955. }
  4956. /**
  4957. * iwl3945_read_ucode - Read uCode images from disk file.
  4958. *
  4959. * Copy into buffers for card to fetch via bus-mastering
  4960. */
  4961. static int iwl3945_read_ucode(struct iwl3945_priv *priv)
  4962. {
  4963. struct iwl3945_ucode *ucode;
  4964. int ret = 0;
  4965. const struct firmware *ucode_raw;
  4966. /* firmware file name contains uCode/driver compatibility version */
  4967. const char *name = "iwlwifi-3945" IWL3945_UCODE_API ".ucode";
  4968. u8 *src;
  4969. size_t len;
  4970. u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
  4971. /* Ask kernel firmware_class module to get the boot firmware off disk.
  4972. * request_firmware() is synchronous, file is in memory on return. */
  4973. ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
  4974. if (ret < 0) {
  4975. IWL_ERROR("%s firmware file req failed: Reason %d\n",
  4976. name, ret);
  4977. goto error;
  4978. }
  4979. IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
  4980. name, ucode_raw->size);
  4981. /* Make sure that we got at least our header! */
  4982. if (ucode_raw->size < sizeof(*ucode)) {
  4983. IWL_ERROR("File size way too small!\n");
  4984. ret = -EINVAL;
  4985. goto err_release;
  4986. }
  4987. /* Data from ucode file: header followed by uCode images */
  4988. ucode = (void *)ucode_raw->data;
  4989. ver = le32_to_cpu(ucode->ver);
  4990. inst_size = le32_to_cpu(ucode->inst_size);
  4991. data_size = le32_to_cpu(ucode->data_size);
  4992. init_size = le32_to_cpu(ucode->init_size);
  4993. init_data_size = le32_to_cpu(ucode->init_data_size);
  4994. boot_size = le32_to_cpu(ucode->boot_size);
  4995. IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver);
  4996. IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", inst_size);
  4997. IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", data_size);
  4998. IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", init_size);
  4999. IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", init_data_size);
  5000. IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", boot_size);
  5001. /* Verify size of file vs. image size info in file's header */
  5002. if (ucode_raw->size < sizeof(*ucode) +
  5003. inst_size + data_size + init_size +
  5004. init_data_size + boot_size) {
  5005. IWL_DEBUG_INFO("uCode file size %d too small\n",
  5006. (int)ucode_raw->size);
  5007. ret = -EINVAL;
  5008. goto err_release;
  5009. }
  5010. /* Verify that uCode images will fit in card's SRAM */
  5011. if (inst_size > IWL_MAX_INST_SIZE) {
  5012. IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
  5013. inst_size);
  5014. ret = -EINVAL;
  5015. goto err_release;
  5016. }
  5017. if (data_size > IWL_MAX_DATA_SIZE) {
  5018. IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
  5019. data_size);
  5020. ret = -EINVAL;
  5021. goto err_release;
  5022. }
  5023. if (init_size > IWL_MAX_INST_SIZE) {
  5024. IWL_DEBUG_INFO("uCode init instr len %d too large to fit in\n",
  5025. init_size);
  5026. ret = -EINVAL;
  5027. goto err_release;
  5028. }
  5029. if (init_data_size > IWL_MAX_DATA_SIZE) {
  5030. IWL_DEBUG_INFO("uCode init data len %d too large to fit in\n",
  5031. init_data_size);
  5032. ret = -EINVAL;
  5033. goto err_release;
  5034. }
  5035. if (boot_size > IWL_MAX_BSM_SIZE) {
  5036. IWL_DEBUG_INFO("uCode boot instr len %d too large to fit in\n",
  5037. boot_size);
  5038. ret = -EINVAL;
  5039. goto err_release;
  5040. }
  5041. /* Allocate ucode buffers for card's bus-master loading ... */
  5042. /* Runtime instructions and 2 copies of data:
  5043. * 1) unmodified from disk
  5044. * 2) backup cache for save/restore during power-downs */
  5045. priv->ucode_code.len = inst_size;
  5046. iwl3945_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
  5047. priv->ucode_data.len = data_size;
  5048. iwl3945_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
  5049. priv->ucode_data_backup.len = data_size;
  5050. iwl3945_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  5051. if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
  5052. !priv->ucode_data_backup.v_addr)
  5053. goto err_pci_alloc;
  5054. /* Initialization instructions and data */
  5055. if (init_size && init_data_size) {
  5056. priv->ucode_init.len = init_size;
  5057. iwl3945_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
  5058. priv->ucode_init_data.len = init_data_size;
  5059. iwl3945_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  5060. if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
  5061. goto err_pci_alloc;
  5062. }
  5063. /* Bootstrap (instructions only, no data) */
  5064. if (boot_size) {
  5065. priv->ucode_boot.len = boot_size;
  5066. iwl3945_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
  5067. if (!priv->ucode_boot.v_addr)
  5068. goto err_pci_alloc;
  5069. }
  5070. /* Copy images into buffers for card's bus-master reads ... */
  5071. /* Runtime instructions (first block of data in file) */
  5072. src = &ucode->data[0];
  5073. len = priv->ucode_code.len;
  5074. IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
  5075. memcpy(priv->ucode_code.v_addr, src, len);
  5076. IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
  5077. priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
  5078. /* Runtime data (2nd block)
  5079. * NOTE: Copy into backup buffer will be done in iwl3945_up() */
  5080. src = &ucode->data[inst_size];
  5081. len = priv->ucode_data.len;
  5082. IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
  5083. memcpy(priv->ucode_data.v_addr, src, len);
  5084. memcpy(priv->ucode_data_backup.v_addr, src, len);
  5085. /* Initialization instructions (3rd block) */
  5086. if (init_size) {
  5087. src = &ucode->data[inst_size + data_size];
  5088. len = priv->ucode_init.len;
  5089. IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
  5090. len);
  5091. memcpy(priv->ucode_init.v_addr, src, len);
  5092. }
  5093. /* Initialization data (4th block) */
  5094. if (init_data_size) {
  5095. src = &ucode->data[inst_size + data_size + init_size];
  5096. len = priv->ucode_init_data.len;
  5097. IWL_DEBUG_INFO("Copying (but not loading) init data len %d\n",
  5098. (int)len);
  5099. memcpy(priv->ucode_init_data.v_addr, src, len);
  5100. }
  5101. /* Bootstrap instructions (5th block) */
  5102. src = &ucode->data[inst_size + data_size + init_size + init_data_size];
  5103. len = priv->ucode_boot.len;
  5104. IWL_DEBUG_INFO("Copying (but not loading) boot instr len %d\n",
  5105. (int)len);
  5106. memcpy(priv->ucode_boot.v_addr, src, len);
  5107. /* We have our copies now, allow OS release its copies */
  5108. release_firmware(ucode_raw);
  5109. return 0;
  5110. err_pci_alloc:
  5111. IWL_ERROR("failed to allocate pci memory\n");
  5112. ret = -ENOMEM;
  5113. iwl3945_dealloc_ucode_pci(priv);
  5114. err_release:
  5115. release_firmware(ucode_raw);
  5116. error:
  5117. return ret;
  5118. }
  5119. /**
  5120. * iwl3945_set_ucode_ptrs - Set uCode address location
  5121. *
  5122. * Tell initialization uCode where to find runtime uCode.
  5123. *
  5124. * BSM registers initially contain pointers to initialization uCode.
  5125. * We need to replace them to load runtime uCode inst and data,
  5126. * and to save runtime data when powering down.
  5127. */
  5128. static int iwl3945_set_ucode_ptrs(struct iwl3945_priv *priv)
  5129. {
  5130. dma_addr_t pinst;
  5131. dma_addr_t pdata;
  5132. int rc = 0;
  5133. unsigned long flags;
  5134. /* bits 31:0 for 3945 */
  5135. pinst = priv->ucode_code.p_addr;
  5136. pdata = priv->ucode_data_backup.p_addr;
  5137. spin_lock_irqsave(&priv->lock, flags);
  5138. rc = iwl3945_grab_nic_access(priv);
  5139. if (rc) {
  5140. spin_unlock_irqrestore(&priv->lock, flags);
  5141. return rc;
  5142. }
  5143. /* Tell bootstrap uCode where to find image to load */
  5144. iwl3945_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
  5145. iwl3945_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
  5146. iwl3945_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
  5147. priv->ucode_data.len);
  5148. /* Inst bytecount must be last to set up, bit 31 signals uCode
  5149. * that all new ptr/size info is in place */
  5150. iwl3945_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
  5151. priv->ucode_code.len | BSM_DRAM_INST_LOAD);
  5152. iwl3945_release_nic_access(priv);
  5153. spin_unlock_irqrestore(&priv->lock, flags);
  5154. IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
  5155. return rc;
  5156. }
  5157. /**
  5158. * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
  5159. *
  5160. * Called after REPLY_ALIVE notification received from "initialize" uCode.
  5161. *
  5162. * Tell "initialize" uCode to go ahead and load the runtime uCode.
  5163. */
  5164. static void iwl3945_init_alive_start(struct iwl3945_priv *priv)
  5165. {
  5166. /* Check alive response for "valid" sign from uCode */
  5167. if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
  5168. /* We had an error bringing up the hardware, so take it
  5169. * all the way back down so we can try again */
  5170. IWL_DEBUG_INFO("Initialize Alive failed.\n");
  5171. goto restart;
  5172. }
  5173. /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
  5174. * This is a paranoid check, because we would not have gotten the
  5175. * "initialize" alive if code weren't properly loaded. */
  5176. if (iwl3945_verify_ucode(priv)) {
  5177. /* Runtime instruction load was bad;
  5178. * take it all the way back down so we can try again */
  5179. IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
  5180. goto restart;
  5181. }
  5182. /* Send pointers to protocol/runtime uCode image ... init code will
  5183. * load and launch runtime uCode, which will send us another "Alive"
  5184. * notification. */
  5185. IWL_DEBUG_INFO("Initialization Alive received.\n");
  5186. if (iwl3945_set_ucode_ptrs(priv)) {
  5187. /* Runtime instruction load won't happen;
  5188. * take it all the way back down so we can try again */
  5189. IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
  5190. goto restart;
  5191. }
  5192. return;
  5193. restart:
  5194. queue_work(priv->workqueue, &priv->restart);
  5195. }
  5196. /**
  5197. * iwl3945_alive_start - called after REPLY_ALIVE notification received
  5198. * from protocol/runtime uCode (initialization uCode's
  5199. * Alive gets handled by iwl3945_init_alive_start()).
  5200. */
  5201. static void iwl3945_alive_start(struct iwl3945_priv *priv)
  5202. {
  5203. int rc = 0;
  5204. int thermal_spin = 0;
  5205. u32 rfkill;
  5206. IWL_DEBUG_INFO("Runtime Alive received.\n");
  5207. if (priv->card_alive.is_valid != UCODE_VALID_OK) {
  5208. /* We had an error bringing up the hardware, so take it
  5209. * all the way back down so we can try again */
  5210. IWL_DEBUG_INFO("Alive failed.\n");
  5211. goto restart;
  5212. }
  5213. /* Initialize uCode has loaded Runtime uCode ... verify inst image.
  5214. * This is a paranoid check, because we would not have gotten the
  5215. * "runtime" alive if code weren't properly loaded. */
  5216. if (iwl3945_verify_ucode(priv)) {
  5217. /* Runtime instruction load was bad;
  5218. * take it all the way back down so we can try again */
  5219. IWL_DEBUG_INFO("Bad runtime uCode load.\n");
  5220. goto restart;
  5221. }
  5222. iwl3945_clear_stations_table(priv);
  5223. rc = iwl3945_grab_nic_access(priv);
  5224. if (rc) {
  5225. IWL_WARNING("Can not read rfkill status from adapter\n");
  5226. return;
  5227. }
  5228. rfkill = iwl3945_read_prph(priv, APMG_RFKILL_REG);
  5229. IWL_DEBUG_INFO("RFKILL status: 0x%x\n", rfkill);
  5230. iwl3945_release_nic_access(priv);
  5231. if (rfkill & 0x1) {
  5232. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  5233. /* if rfkill is not on, then wait for thermal
  5234. * sensor in adapter to kick in */
  5235. while (iwl3945_hw_get_temperature(priv) == 0) {
  5236. thermal_spin++;
  5237. udelay(10);
  5238. }
  5239. if (thermal_spin)
  5240. IWL_DEBUG_INFO("Thermal calibration took %dus\n",
  5241. thermal_spin * 10);
  5242. } else
  5243. set_bit(STATUS_RF_KILL_HW, &priv->status);
  5244. /* After the ALIVE response, we can send commands to 3945 uCode */
  5245. set_bit(STATUS_ALIVE, &priv->status);
  5246. /* Clear out the uCode error bit if it is set */
  5247. clear_bit(STATUS_FW_ERROR, &priv->status);
  5248. rc = iwl3945_init_channel_map(priv);
  5249. if (rc) {
  5250. IWL_ERROR("initializing regulatory failed: %d\n", rc);
  5251. return;
  5252. }
  5253. iwl3945_init_geos(priv);
  5254. if (iwl3945_is_rfkill(priv))
  5255. return;
  5256. if (!priv->mac80211_registered) {
  5257. /* Unlock so any user space entry points can call back into
  5258. * the driver without a deadlock... */
  5259. mutex_unlock(&priv->mutex);
  5260. iwl3945_rate_control_register(priv->hw);
  5261. rc = ieee80211_register_hw(priv->hw);
  5262. priv->hw->conf.beacon_int = 100;
  5263. mutex_lock(&priv->mutex);
  5264. if (rc) {
  5265. iwl3945_rate_control_unregister(priv->hw);
  5266. IWL_ERROR("Failed to register network "
  5267. "device (error %d)\n", rc);
  5268. return;
  5269. }
  5270. priv->mac80211_registered = 1;
  5271. iwl3945_reset_channel_flag(priv);
  5272. } else
  5273. ieee80211_start_queues(priv->hw);
  5274. priv->active_rate = priv->rates_mask;
  5275. priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
  5276. iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode));
  5277. if (iwl3945_is_associated(priv)) {
  5278. struct iwl3945_rxon_cmd *active_rxon =
  5279. (struct iwl3945_rxon_cmd *)(&priv->active_rxon);
  5280. memcpy(&priv->staging_rxon, &priv->active_rxon,
  5281. sizeof(priv->staging_rxon));
  5282. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  5283. } else {
  5284. /* Initialize our rx_config data */
  5285. iwl3945_connection_init_rx_config(priv);
  5286. memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  5287. }
  5288. /* Configure Bluetooth device coexistence support */
  5289. iwl3945_send_bt_config(priv);
  5290. /* Configure the adapter for unassociated operation */
  5291. iwl3945_commit_rxon(priv);
  5292. /* At this point, the NIC is initialized and operational */
  5293. priv->notif_missed_beacons = 0;
  5294. set_bit(STATUS_READY, &priv->status);
  5295. iwl3945_reg_txpower_periodic(priv);
  5296. IWL_DEBUG_INFO("ALIVE processing complete.\n");
  5297. if (priv->error_recovering)
  5298. iwl3945_error_recovery(priv);
  5299. return;
  5300. restart:
  5301. queue_work(priv->workqueue, &priv->restart);
  5302. }
  5303. static void iwl3945_cancel_deferred_work(struct iwl3945_priv *priv);
  5304. static void __iwl3945_down(struct iwl3945_priv *priv)
  5305. {
  5306. unsigned long flags;
  5307. int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
  5308. struct ieee80211_conf *conf = NULL;
  5309. IWL_DEBUG_INFO(DRV_NAME " is going down\n");
  5310. conf = ieee80211_get_hw_conf(priv->hw);
  5311. if (!exit_pending)
  5312. set_bit(STATUS_EXIT_PENDING, &priv->status);
  5313. iwl3945_clear_stations_table(priv);
  5314. /* Unblock any waiting calls */
  5315. wake_up_interruptible_all(&priv->wait_command_queue);
  5316. /* Wipe out the EXIT_PENDING status bit if we are not actually
  5317. * exiting the module */
  5318. if (!exit_pending)
  5319. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  5320. /* stop and reset the on-board processor */
  5321. iwl3945_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  5322. /* tell the device to stop sending interrupts */
  5323. iwl3945_disable_interrupts(priv);
  5324. if (priv->mac80211_registered)
  5325. ieee80211_stop_queues(priv->hw);
  5326. /* If we have not previously called iwl3945_init() then
  5327. * clear all bits but the RF Kill and SUSPEND bits and return */
  5328. if (!iwl3945_is_init(priv)) {
  5329. priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  5330. STATUS_RF_KILL_HW |
  5331. test_bit(STATUS_RF_KILL_SW, &priv->status) <<
  5332. STATUS_RF_KILL_SW |
  5333. test_bit(STATUS_IN_SUSPEND, &priv->status) <<
  5334. STATUS_IN_SUSPEND;
  5335. goto exit;
  5336. }
  5337. /* ...otherwise clear out all the status bits but the RF Kill and
  5338. * SUSPEND bits and continue taking the NIC down. */
  5339. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  5340. STATUS_RF_KILL_HW |
  5341. test_bit(STATUS_RF_KILL_SW, &priv->status) <<
  5342. STATUS_RF_KILL_SW |
  5343. test_bit(STATUS_IN_SUSPEND, &priv->status) <<
  5344. STATUS_IN_SUSPEND |
  5345. test_bit(STATUS_FW_ERROR, &priv->status) <<
  5346. STATUS_FW_ERROR;
  5347. spin_lock_irqsave(&priv->lock, flags);
  5348. iwl3945_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  5349. spin_unlock_irqrestore(&priv->lock, flags);
  5350. iwl3945_hw_txq_ctx_stop(priv);
  5351. iwl3945_hw_rxq_stop(priv);
  5352. spin_lock_irqsave(&priv->lock, flags);
  5353. if (!iwl3945_grab_nic_access(priv)) {
  5354. iwl3945_write_prph(priv, APMG_CLK_DIS_REG,
  5355. APMG_CLK_VAL_DMA_CLK_RQT);
  5356. iwl3945_release_nic_access(priv);
  5357. }
  5358. spin_unlock_irqrestore(&priv->lock, flags);
  5359. udelay(5);
  5360. iwl3945_hw_nic_stop_master(priv);
  5361. iwl3945_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  5362. iwl3945_hw_nic_reset(priv);
  5363. exit:
  5364. memset(&priv->card_alive, 0, sizeof(struct iwl3945_alive_resp));
  5365. if (priv->ibss_beacon)
  5366. dev_kfree_skb(priv->ibss_beacon);
  5367. priv->ibss_beacon = NULL;
  5368. /* clear out any free frames */
  5369. iwl3945_clear_free_frames(priv);
  5370. }
  5371. static void iwl3945_down(struct iwl3945_priv *priv)
  5372. {
  5373. mutex_lock(&priv->mutex);
  5374. __iwl3945_down(priv);
  5375. mutex_unlock(&priv->mutex);
  5376. iwl3945_cancel_deferred_work(priv);
  5377. }
  5378. #define MAX_HW_RESTARTS 5
  5379. static int __iwl3945_up(struct iwl3945_priv *priv)
  5380. {
  5381. DECLARE_MAC_BUF(mac);
  5382. int rc, i;
  5383. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  5384. IWL_WARNING("Exit pending; will not bring the NIC up\n");
  5385. return -EIO;
  5386. }
  5387. if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
  5388. IWL_WARNING("Radio disabled by SW RF kill (module "
  5389. "parameter)\n");
  5390. return 0;
  5391. }
  5392. if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
  5393. IWL_ERROR("ucode not available for device bringup\n");
  5394. return -EIO;
  5395. }
  5396. iwl3945_write32(priv, CSR_INT, 0xFFFFFFFF);
  5397. rc = iwl3945_hw_nic_init(priv);
  5398. if (rc) {
  5399. IWL_ERROR("Unable to int nic\n");
  5400. return rc;
  5401. }
  5402. /* make sure rfkill handshake bits are cleared */
  5403. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  5404. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  5405. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  5406. /* clear (again), then enable host interrupts */
  5407. iwl3945_write32(priv, CSR_INT, 0xFFFFFFFF);
  5408. iwl3945_enable_interrupts(priv);
  5409. /* really make sure rfkill handshake bits are cleared */
  5410. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  5411. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  5412. /* Copy original ucode data image from disk into backup cache.
  5413. * This will be used to initialize the on-board processor's
  5414. * data SRAM for a clean start when the runtime program first loads. */
  5415. memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
  5416. priv->ucode_data.len);
  5417. for (i = 0; i < MAX_HW_RESTARTS; i++) {
  5418. iwl3945_clear_stations_table(priv);
  5419. /* load bootstrap state machine,
  5420. * load bootstrap program into processor's memory,
  5421. * prepare to load the "initialize" uCode */
  5422. rc = iwl3945_load_bsm(priv);
  5423. if (rc) {
  5424. IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc);
  5425. continue;
  5426. }
  5427. /* start card; "initialize" will load runtime ucode */
  5428. iwl3945_nic_start(priv);
  5429. /* MAC Address location in EEPROM is same for 3945/4965 */
  5430. get_eeprom_mac(priv, priv->mac_addr);
  5431. IWL_DEBUG_INFO("MAC address: %s\n",
  5432. print_mac(mac, priv->mac_addr));
  5433. SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
  5434. IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
  5435. return 0;
  5436. }
  5437. set_bit(STATUS_EXIT_PENDING, &priv->status);
  5438. __iwl3945_down(priv);
  5439. /* tried to restart and config the device for as long as our
  5440. * patience could withstand */
  5441. IWL_ERROR("Unable to initialize device after %d attempts.\n", i);
  5442. return -EIO;
  5443. }
  5444. /*****************************************************************************
  5445. *
  5446. * Workqueue callbacks
  5447. *
  5448. *****************************************************************************/
  5449. static void iwl3945_bg_init_alive_start(struct work_struct *data)
  5450. {
  5451. struct iwl3945_priv *priv =
  5452. container_of(data, struct iwl3945_priv, init_alive_start.work);
  5453. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5454. return;
  5455. mutex_lock(&priv->mutex);
  5456. iwl3945_init_alive_start(priv);
  5457. mutex_unlock(&priv->mutex);
  5458. }
  5459. static void iwl3945_bg_alive_start(struct work_struct *data)
  5460. {
  5461. struct iwl3945_priv *priv =
  5462. container_of(data, struct iwl3945_priv, alive_start.work);
  5463. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5464. return;
  5465. mutex_lock(&priv->mutex);
  5466. iwl3945_alive_start(priv);
  5467. mutex_unlock(&priv->mutex);
  5468. }
  5469. static void iwl3945_bg_rf_kill(struct work_struct *work)
  5470. {
  5471. struct iwl3945_priv *priv = container_of(work, struct iwl3945_priv, rf_kill);
  5472. wake_up_interruptible(&priv->wait_command_queue);
  5473. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5474. return;
  5475. mutex_lock(&priv->mutex);
  5476. if (!iwl3945_is_rfkill(priv)) {
  5477. IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL,
  5478. "HW and/or SW RF Kill no longer active, restarting "
  5479. "device\n");
  5480. if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
  5481. queue_work(priv->workqueue, &priv->restart);
  5482. } else {
  5483. if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
  5484. IWL_DEBUG_RF_KILL("Can not turn radio back on - "
  5485. "disabled by SW switch\n");
  5486. else
  5487. IWL_WARNING("Radio Frequency Kill Switch is On:\n"
  5488. "Kill switch must be turned off for "
  5489. "wireless networking to work.\n");
  5490. }
  5491. mutex_unlock(&priv->mutex);
  5492. }
  5493. #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
  5494. static void iwl3945_bg_scan_check(struct work_struct *data)
  5495. {
  5496. struct iwl3945_priv *priv =
  5497. container_of(data, struct iwl3945_priv, scan_check.work);
  5498. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5499. return;
  5500. mutex_lock(&priv->mutex);
  5501. if (test_bit(STATUS_SCANNING, &priv->status) ||
  5502. test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  5503. IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN,
  5504. "Scan completion watchdog resetting adapter (%dms)\n",
  5505. jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG));
  5506. if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
  5507. iwl3945_send_scan_abort(priv);
  5508. }
  5509. mutex_unlock(&priv->mutex);
  5510. }
  5511. static void iwl3945_bg_request_scan(struct work_struct *data)
  5512. {
  5513. struct iwl3945_priv *priv =
  5514. container_of(data, struct iwl3945_priv, request_scan);
  5515. struct iwl3945_host_cmd cmd = {
  5516. .id = REPLY_SCAN_CMD,
  5517. .len = sizeof(struct iwl3945_scan_cmd),
  5518. .meta.flags = CMD_SIZE_HUGE,
  5519. };
  5520. int rc = 0;
  5521. struct iwl3945_scan_cmd *scan;
  5522. struct ieee80211_conf *conf = NULL;
  5523. u8 direct_mask;
  5524. int phymode;
  5525. conf = ieee80211_get_hw_conf(priv->hw);
  5526. mutex_lock(&priv->mutex);
  5527. if (!iwl3945_is_ready(priv)) {
  5528. IWL_WARNING("request scan called when driver not ready.\n");
  5529. goto done;
  5530. }
  5531. /* Make sure the scan wasn't cancelled before this queued work
  5532. * was given the chance to run... */
  5533. if (!test_bit(STATUS_SCANNING, &priv->status))
  5534. goto done;
  5535. /* This should never be called or scheduled if there is currently
  5536. * a scan active in the hardware. */
  5537. if (test_bit(STATUS_SCAN_HW, &priv->status)) {
  5538. IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
  5539. "Ignoring second request.\n");
  5540. rc = -EIO;
  5541. goto done;
  5542. }
  5543. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  5544. IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
  5545. goto done;
  5546. }
  5547. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  5548. IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
  5549. goto done;
  5550. }
  5551. if (iwl3945_is_rfkill(priv)) {
  5552. IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
  5553. goto done;
  5554. }
  5555. if (!test_bit(STATUS_READY, &priv->status)) {
  5556. IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
  5557. goto done;
  5558. }
  5559. if (!priv->scan_bands) {
  5560. IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
  5561. goto done;
  5562. }
  5563. if (!priv->scan) {
  5564. priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
  5565. IWL_MAX_SCAN_SIZE, GFP_KERNEL);
  5566. if (!priv->scan) {
  5567. rc = -ENOMEM;
  5568. goto done;
  5569. }
  5570. }
  5571. scan = priv->scan;
  5572. memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
  5573. scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
  5574. scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
  5575. if (iwl3945_is_associated(priv)) {
  5576. u16 interval = 0;
  5577. u32 extra;
  5578. u32 suspend_time = 100;
  5579. u32 scan_suspend_time = 100;
  5580. unsigned long flags;
  5581. IWL_DEBUG_INFO("Scanning while associated...\n");
  5582. spin_lock_irqsave(&priv->lock, flags);
  5583. interval = priv->beacon_int;
  5584. spin_unlock_irqrestore(&priv->lock, flags);
  5585. scan->suspend_time = 0;
  5586. scan->max_out_time = cpu_to_le32(200 * 1024);
  5587. if (!interval)
  5588. interval = suspend_time;
  5589. /*
  5590. * suspend time format:
  5591. * 0-19: beacon interval in usec (time before exec.)
  5592. * 20-23: 0
  5593. * 24-31: number of beacons (suspend between channels)
  5594. */
  5595. extra = (suspend_time / interval) << 24;
  5596. scan_suspend_time = 0xFF0FFFFF &
  5597. (extra | ((suspend_time % interval) * 1024));
  5598. scan->suspend_time = cpu_to_le32(scan_suspend_time);
  5599. IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
  5600. scan_suspend_time, interval);
  5601. }
  5602. /* We should add the ability for user to lock to PASSIVE ONLY */
  5603. if (priv->one_direct_scan) {
  5604. IWL_DEBUG_SCAN
  5605. ("Kicking off one direct scan for '%s'\n",
  5606. iwl3945_escape_essid(priv->direct_ssid,
  5607. priv->direct_ssid_len));
  5608. scan->direct_scan[0].id = WLAN_EID_SSID;
  5609. scan->direct_scan[0].len = priv->direct_ssid_len;
  5610. memcpy(scan->direct_scan[0].ssid,
  5611. priv->direct_ssid, priv->direct_ssid_len);
  5612. direct_mask = 1;
  5613. } else if (!iwl3945_is_associated(priv) && priv->essid_len) {
  5614. scan->direct_scan[0].id = WLAN_EID_SSID;
  5615. scan->direct_scan[0].len = priv->essid_len;
  5616. memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len);
  5617. direct_mask = 1;
  5618. } else
  5619. direct_mask = 0;
  5620. /* We don't build a direct scan probe request; the uCode will do
  5621. * that based on the direct_mask added to each channel entry */
  5622. scan->tx_cmd.len = cpu_to_le16(
  5623. iwl3945_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data,
  5624. IWL_MAX_SCAN_SIZE - sizeof(scan), 0));
  5625. scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
  5626. scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id;
  5627. scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  5628. /* flags + rate selection */
  5629. switch (priv->scan_bands) {
  5630. case 2:
  5631. scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
  5632. scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
  5633. scan->good_CRC_th = 0;
  5634. phymode = MODE_IEEE80211G;
  5635. break;
  5636. case 1:
  5637. scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
  5638. scan->good_CRC_th = IWL_GOOD_CRC_TH;
  5639. phymode = MODE_IEEE80211A;
  5640. break;
  5641. default:
  5642. IWL_WARNING("Invalid scan band count\n");
  5643. goto done;
  5644. }
  5645. /* select Rx antennas */
  5646. scan->flags |= iwl3945_get_antenna_flags(priv);
  5647. if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR)
  5648. scan->filter_flags = RXON_FILTER_PROMISC_MSK;
  5649. if (direct_mask)
  5650. IWL_DEBUG_SCAN
  5651. ("Initiating direct scan for %s.\n",
  5652. iwl3945_escape_essid(priv->essid, priv->essid_len));
  5653. else
  5654. IWL_DEBUG_SCAN("Initiating indirect scan.\n");
  5655. scan->channel_count =
  5656. iwl3945_get_channels_for_scan(
  5657. priv, phymode, 1, /* active */
  5658. direct_mask,
  5659. (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
  5660. cmd.len += le16_to_cpu(scan->tx_cmd.len) +
  5661. scan->channel_count * sizeof(struct iwl3945_scan_channel);
  5662. cmd.data = scan;
  5663. scan->len = cpu_to_le16(cmd.len);
  5664. set_bit(STATUS_SCAN_HW, &priv->status);
  5665. rc = iwl3945_send_cmd_sync(priv, &cmd);
  5666. if (rc)
  5667. goto done;
  5668. queue_delayed_work(priv->workqueue, &priv->scan_check,
  5669. IWL_SCAN_CHECK_WATCHDOG);
  5670. mutex_unlock(&priv->mutex);
  5671. return;
  5672. done:
  5673. /* inform mac80211 scan aborted */
  5674. queue_work(priv->workqueue, &priv->scan_completed);
  5675. mutex_unlock(&priv->mutex);
  5676. }
  5677. static void iwl3945_bg_up(struct work_struct *data)
  5678. {
  5679. struct iwl3945_priv *priv = container_of(data, struct iwl3945_priv, up);
  5680. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5681. return;
  5682. mutex_lock(&priv->mutex);
  5683. __iwl3945_up(priv);
  5684. mutex_unlock(&priv->mutex);
  5685. }
  5686. static void iwl3945_bg_restart(struct work_struct *data)
  5687. {
  5688. struct iwl3945_priv *priv = container_of(data, struct iwl3945_priv, restart);
  5689. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5690. return;
  5691. iwl3945_down(priv);
  5692. queue_work(priv->workqueue, &priv->up);
  5693. }
  5694. static void iwl3945_bg_rx_replenish(struct work_struct *data)
  5695. {
  5696. struct iwl3945_priv *priv =
  5697. container_of(data, struct iwl3945_priv, rx_replenish);
  5698. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5699. return;
  5700. mutex_lock(&priv->mutex);
  5701. iwl3945_rx_replenish(priv);
  5702. mutex_unlock(&priv->mutex);
  5703. }
  5704. #define IWL_DELAY_NEXT_SCAN (HZ*2)
  5705. static void iwl3945_bg_post_associate(struct work_struct *data)
  5706. {
  5707. struct iwl3945_priv *priv = container_of(data, struct iwl3945_priv,
  5708. post_associate.work);
  5709. int rc = 0;
  5710. struct ieee80211_conf *conf = NULL;
  5711. DECLARE_MAC_BUF(mac);
  5712. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  5713. IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__);
  5714. return;
  5715. }
  5716. IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
  5717. priv->assoc_id,
  5718. print_mac(mac, priv->active_rxon.bssid_addr));
  5719. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5720. return;
  5721. mutex_lock(&priv->mutex);
  5722. if (!priv->interface_id || !priv->is_open) {
  5723. mutex_unlock(&priv->mutex);
  5724. return;
  5725. }
  5726. iwl3945_scan_cancel_timeout(priv, 200);
  5727. conf = ieee80211_get_hw_conf(priv->hw);
  5728. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  5729. iwl3945_commit_rxon(priv);
  5730. memset(&priv->rxon_timing, 0, sizeof(struct iwl3945_rxon_time_cmd));
  5731. iwl3945_setup_rxon_timing(priv);
  5732. rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING,
  5733. sizeof(priv->rxon_timing), &priv->rxon_timing);
  5734. if (rc)
  5735. IWL_WARNING("REPLY_RXON_TIMING failed - "
  5736. "Attempting to continue.\n");
  5737. priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  5738. priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
  5739. IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
  5740. priv->assoc_id, priv->beacon_int);
  5741. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  5742. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  5743. else
  5744. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  5745. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
  5746. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
  5747. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  5748. else
  5749. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  5750. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  5751. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  5752. }
  5753. iwl3945_commit_rxon(priv);
  5754. switch (priv->iw_mode) {
  5755. case IEEE80211_IF_TYPE_STA:
  5756. iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
  5757. break;
  5758. case IEEE80211_IF_TYPE_IBSS:
  5759. /* clear out the station table */
  5760. iwl3945_clear_stations_table(priv);
  5761. iwl3945_add_station(priv, iwl3945_broadcast_addr, 0, 0);
  5762. iwl3945_add_station(priv, priv->bssid, 0, 0);
  5763. iwl3945_sync_sta(priv, IWL_STA_ID,
  5764. (priv->phymode == MODE_IEEE80211A)?
  5765. IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
  5766. CMD_ASYNC);
  5767. iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
  5768. iwl3945_send_beacon_cmd(priv);
  5769. break;
  5770. default:
  5771. IWL_ERROR("%s Should not be called in %d mode\n",
  5772. __FUNCTION__, priv->iw_mode);
  5773. break;
  5774. }
  5775. iwl3945_sequence_reset(priv);
  5776. #ifdef CONFIG_IWL3945_QOS
  5777. iwl3945_activate_qos(priv, 0);
  5778. #endif /* CONFIG_IWL3945_QOS */
  5779. /* we have just associated, don't start scan too early */
  5780. priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
  5781. mutex_unlock(&priv->mutex);
  5782. }
  5783. static void iwl3945_bg_abort_scan(struct work_struct *work)
  5784. {
  5785. struct iwl3945_priv *priv = container_of(work, struct iwl3945_priv, abort_scan);
  5786. if (!iwl3945_is_ready(priv))
  5787. return;
  5788. mutex_lock(&priv->mutex);
  5789. set_bit(STATUS_SCAN_ABORTING, &priv->status);
  5790. iwl3945_send_scan_abort(priv);
  5791. mutex_unlock(&priv->mutex);
  5792. }
  5793. static void iwl3945_bg_scan_completed(struct work_struct *work)
  5794. {
  5795. struct iwl3945_priv *priv =
  5796. container_of(work, struct iwl3945_priv, scan_completed);
  5797. IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n");
  5798. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  5799. return;
  5800. ieee80211_scan_completed(priv->hw);
  5801. /* Since setting the TXPOWER may have been deferred while
  5802. * performing the scan, fire one off */
  5803. mutex_lock(&priv->mutex);
  5804. iwl3945_hw_reg_send_txpower(priv);
  5805. mutex_unlock(&priv->mutex);
  5806. }
  5807. /*****************************************************************************
  5808. *
  5809. * mac80211 entry point functions
  5810. *
  5811. *****************************************************************************/
  5812. static int iwl3945_mac_start(struct ieee80211_hw *hw)
  5813. {
  5814. struct iwl3945_priv *priv = hw->priv;
  5815. IWL_DEBUG_MAC80211("enter\n");
  5816. /* we should be verifying the device is ready to be opened */
  5817. mutex_lock(&priv->mutex);
  5818. priv->is_open = 1;
  5819. if (!iwl3945_is_rfkill(priv))
  5820. ieee80211_start_queues(priv->hw);
  5821. mutex_unlock(&priv->mutex);
  5822. IWL_DEBUG_MAC80211("leave\n");
  5823. return 0;
  5824. }
  5825. static void iwl3945_mac_stop(struct ieee80211_hw *hw)
  5826. {
  5827. struct iwl3945_priv *priv = hw->priv;
  5828. IWL_DEBUG_MAC80211("enter\n");
  5829. mutex_lock(&priv->mutex);
  5830. /* stop mac, cancel any scan request and clear
  5831. * RXON_FILTER_ASSOC_MSK BIT
  5832. */
  5833. priv->is_open = 0;
  5834. iwl3945_scan_cancel_timeout(priv, 100);
  5835. cancel_delayed_work(&priv->post_associate);
  5836. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  5837. iwl3945_commit_rxon(priv);
  5838. mutex_unlock(&priv->mutex);
  5839. IWL_DEBUG_MAC80211("leave\n");
  5840. }
  5841. static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
  5842. struct ieee80211_tx_control *ctl)
  5843. {
  5844. struct iwl3945_priv *priv = hw->priv;
  5845. IWL_DEBUG_MAC80211("enter\n");
  5846. if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
  5847. IWL_DEBUG_MAC80211("leave - monitor\n");
  5848. return -1;
  5849. }
  5850. IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  5851. ctl->tx_rate);
  5852. if (iwl3945_tx_skb(priv, skb, ctl))
  5853. dev_kfree_skb_any(skb);
  5854. IWL_DEBUG_MAC80211("leave\n");
  5855. return 0;
  5856. }
  5857. static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
  5858. struct ieee80211_if_init_conf *conf)
  5859. {
  5860. struct iwl3945_priv *priv = hw->priv;
  5861. unsigned long flags;
  5862. DECLARE_MAC_BUF(mac);
  5863. IWL_DEBUG_MAC80211("enter: id %d, type %d\n", conf->if_id, conf->type);
  5864. if (priv->interface_id) {
  5865. IWL_DEBUG_MAC80211("leave - interface_id != 0\n");
  5866. return -EOPNOTSUPP;
  5867. }
  5868. spin_lock_irqsave(&priv->lock, flags);
  5869. priv->interface_id = conf->if_id;
  5870. spin_unlock_irqrestore(&priv->lock, flags);
  5871. mutex_lock(&priv->mutex);
  5872. if (conf->mac_addr) {
  5873. IWL_DEBUG_MAC80211("Set: %s\n", print_mac(mac, conf->mac_addr));
  5874. memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
  5875. }
  5876. iwl3945_set_mode(priv, conf->type);
  5877. IWL_DEBUG_MAC80211("leave\n");
  5878. mutex_unlock(&priv->mutex);
  5879. return 0;
  5880. }
  5881. /**
  5882. * iwl3945_mac_config - mac80211 config callback
  5883. *
  5884. * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
  5885. * be set inappropriately and the driver currently sets the hardware up to
  5886. * use it whenever needed.
  5887. */
  5888. static int iwl3945_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
  5889. {
  5890. struct iwl3945_priv *priv = hw->priv;
  5891. const struct iwl3945_channel_info *ch_info;
  5892. unsigned long flags;
  5893. mutex_lock(&priv->mutex);
  5894. IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel);
  5895. if (!iwl3945_is_ready(priv)) {
  5896. IWL_DEBUG_MAC80211("leave - not ready\n");
  5897. mutex_unlock(&priv->mutex);
  5898. return -EIO;
  5899. }
  5900. /* TODO: Figure out how to get ieee80211_local->sta_scanning w/ only
  5901. * what is exposed through include/ declarations */
  5902. if (unlikely(!iwl3945_param_disable_hw_scan &&
  5903. test_bit(STATUS_SCANNING, &priv->status))) {
  5904. IWL_DEBUG_MAC80211("leave - scanning\n");
  5905. mutex_unlock(&priv->mutex);
  5906. return 0;
  5907. }
  5908. spin_lock_irqsave(&priv->lock, flags);
  5909. ch_info = iwl3945_get_channel_info(priv, conf->phymode, conf->channel);
  5910. if (!is_channel_valid(ch_info)) {
  5911. IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this SKU.\n",
  5912. conf->channel, conf->phymode);
  5913. IWL_DEBUG_MAC80211("leave - invalid channel\n");
  5914. spin_unlock_irqrestore(&priv->lock, flags);
  5915. mutex_unlock(&priv->mutex);
  5916. return -EINVAL;
  5917. }
  5918. iwl3945_set_rxon_channel(priv, conf->phymode, conf->channel);
  5919. iwl3945_set_flags_for_phymode(priv, conf->phymode);
  5920. /* The list of supported rates and rate mask can be different
  5921. * for each phymode; since the phymode may have changed, reset
  5922. * the rate mask to what mac80211 lists */
  5923. iwl3945_set_rate(priv);
  5924. spin_unlock_irqrestore(&priv->lock, flags);
  5925. #ifdef IEEE80211_CONF_CHANNEL_SWITCH
  5926. if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
  5927. iwl3945_hw_channel_switch(priv, conf->channel);
  5928. mutex_unlock(&priv->mutex);
  5929. return 0;
  5930. }
  5931. #endif
  5932. iwl3945_radio_kill_sw(priv, !conf->radio_enabled);
  5933. if (!conf->radio_enabled) {
  5934. IWL_DEBUG_MAC80211("leave - radio disabled\n");
  5935. mutex_unlock(&priv->mutex);
  5936. return 0;
  5937. }
  5938. if (iwl3945_is_rfkill(priv)) {
  5939. IWL_DEBUG_MAC80211("leave - RF kill\n");
  5940. mutex_unlock(&priv->mutex);
  5941. return -EIO;
  5942. }
  5943. iwl3945_set_rate(priv);
  5944. if (memcmp(&priv->active_rxon,
  5945. &priv->staging_rxon, sizeof(priv->staging_rxon)))
  5946. iwl3945_commit_rxon(priv);
  5947. else
  5948. IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
  5949. IWL_DEBUG_MAC80211("leave\n");
  5950. mutex_unlock(&priv->mutex);
  5951. return 0;
  5952. }
  5953. static void iwl3945_config_ap(struct iwl3945_priv *priv)
  5954. {
  5955. int rc = 0;
  5956. if (priv->status & STATUS_EXIT_PENDING)
  5957. return;
  5958. /* The following should be done only at AP bring up */
  5959. if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) {
  5960. /* RXON - unassoc (to set timing command) */
  5961. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  5962. iwl3945_commit_rxon(priv);
  5963. /* RXON Timing */
  5964. memset(&priv->rxon_timing, 0, sizeof(struct iwl3945_rxon_time_cmd));
  5965. iwl3945_setup_rxon_timing(priv);
  5966. rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING,
  5967. sizeof(priv->rxon_timing), &priv->rxon_timing);
  5968. if (rc)
  5969. IWL_WARNING("REPLY_RXON_TIMING failed - "
  5970. "Attempting to continue.\n");
  5971. /* FIXME: what should be the assoc_id for AP? */
  5972. priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
  5973. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  5974. priv->staging_rxon.flags |=
  5975. RXON_FLG_SHORT_PREAMBLE_MSK;
  5976. else
  5977. priv->staging_rxon.flags &=
  5978. ~RXON_FLG_SHORT_PREAMBLE_MSK;
  5979. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
  5980. if (priv->assoc_capability &
  5981. WLAN_CAPABILITY_SHORT_SLOT_TIME)
  5982. priv->staging_rxon.flags |=
  5983. RXON_FLG_SHORT_SLOT_MSK;
  5984. else
  5985. priv->staging_rxon.flags &=
  5986. ~RXON_FLG_SHORT_SLOT_MSK;
  5987. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
  5988. priv->staging_rxon.flags &=
  5989. ~RXON_FLG_SHORT_SLOT_MSK;
  5990. }
  5991. /* restore RXON assoc */
  5992. priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  5993. iwl3945_commit_rxon(priv);
  5994. iwl3945_add_station(priv, iwl3945_broadcast_addr, 0, 0);
  5995. }
  5996. iwl3945_send_beacon_cmd(priv);
  5997. /* FIXME - we need to add code here to detect a totally new
  5998. * configuration, reset the AP, unassoc, rxon timing, assoc,
  5999. * clear sta table, add BCAST sta... */
  6000. }
  6001. static int iwl3945_mac_config_interface(struct ieee80211_hw *hw, int if_id,
  6002. struct ieee80211_if_conf *conf)
  6003. {
  6004. struct iwl3945_priv *priv = hw->priv;
  6005. DECLARE_MAC_BUF(mac);
  6006. unsigned long flags;
  6007. int rc;
  6008. if (conf == NULL)
  6009. return -EIO;
  6010. /* XXX: this MUST use conf->mac_addr */
  6011. if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
  6012. (!conf->beacon || !conf->ssid_len)) {
  6013. IWL_DEBUG_MAC80211
  6014. ("Leaving in AP mode because HostAPD is not ready.\n");
  6015. return 0;
  6016. }
  6017. mutex_lock(&priv->mutex);
  6018. IWL_DEBUG_MAC80211("enter: interface id %d\n", if_id);
  6019. if (conf->bssid)
  6020. IWL_DEBUG_MAC80211("bssid: %s\n",
  6021. print_mac(mac, conf->bssid));
  6022. /*
  6023. * very dubious code was here; the probe filtering flag is never set:
  6024. *
  6025. if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
  6026. !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
  6027. */
  6028. if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
  6029. IWL_DEBUG_MAC80211("leave - scanning\n");
  6030. mutex_unlock(&priv->mutex);
  6031. return 0;
  6032. }
  6033. if (priv->interface_id != if_id) {
  6034. IWL_DEBUG_MAC80211("leave - interface_id != if_id\n");
  6035. mutex_unlock(&priv->mutex);
  6036. return 0;
  6037. }
  6038. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  6039. if (!conf->bssid) {
  6040. conf->bssid = priv->mac_addr;
  6041. memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
  6042. IWL_DEBUG_MAC80211("bssid was set to: %s\n",
  6043. print_mac(mac, conf->bssid));
  6044. }
  6045. if (priv->ibss_beacon)
  6046. dev_kfree_skb(priv->ibss_beacon);
  6047. priv->ibss_beacon = conf->beacon;
  6048. }
  6049. if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
  6050. !is_multicast_ether_addr(conf->bssid)) {
  6051. /* If there is currently a HW scan going on in the background
  6052. * then we need to cancel it else the RXON below will fail. */
  6053. if (iwl3945_scan_cancel_timeout(priv, 100)) {
  6054. IWL_WARNING("Aborted scan still in progress "
  6055. "after 100ms\n");
  6056. IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
  6057. mutex_unlock(&priv->mutex);
  6058. return -EAGAIN;
  6059. }
  6060. memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
  6061. /* TODO: Audit driver for usage of these members and see
  6062. * if mac80211 deprecates them (priv->bssid looks like it
  6063. * shouldn't be there, but I haven't scanned the IBSS code
  6064. * to verify) - jpk */
  6065. memcpy(priv->bssid, conf->bssid, ETH_ALEN);
  6066. if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
  6067. iwl3945_config_ap(priv);
  6068. else {
  6069. rc = iwl3945_commit_rxon(priv);
  6070. if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc)
  6071. iwl3945_add_station(priv,
  6072. priv->active_rxon.bssid_addr, 1, 0);
  6073. }
  6074. } else {
  6075. iwl3945_scan_cancel_timeout(priv, 100);
  6076. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  6077. iwl3945_commit_rxon(priv);
  6078. }
  6079. spin_lock_irqsave(&priv->lock, flags);
  6080. if (!conf->ssid_len)
  6081. memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
  6082. else
  6083. memcpy(priv->essid, conf->ssid, conf->ssid_len);
  6084. priv->essid_len = conf->ssid_len;
  6085. spin_unlock_irqrestore(&priv->lock, flags);
  6086. IWL_DEBUG_MAC80211("leave\n");
  6087. mutex_unlock(&priv->mutex);
  6088. return 0;
  6089. }
  6090. static void iwl3945_configure_filter(struct ieee80211_hw *hw,
  6091. unsigned int changed_flags,
  6092. unsigned int *total_flags,
  6093. int mc_count, struct dev_addr_list *mc_list)
  6094. {
  6095. /*
  6096. * XXX: dummy
  6097. * see also iwl3945_connection_init_rx_config
  6098. */
  6099. *total_flags = 0;
  6100. }
  6101. static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
  6102. struct ieee80211_if_init_conf *conf)
  6103. {
  6104. struct iwl3945_priv *priv = hw->priv;
  6105. IWL_DEBUG_MAC80211("enter\n");
  6106. mutex_lock(&priv->mutex);
  6107. iwl3945_scan_cancel_timeout(priv, 100);
  6108. cancel_delayed_work(&priv->post_associate);
  6109. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  6110. iwl3945_commit_rxon(priv);
  6111. if (priv->interface_id == conf->if_id) {
  6112. priv->interface_id = 0;
  6113. memset(priv->bssid, 0, ETH_ALEN);
  6114. memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
  6115. priv->essid_len = 0;
  6116. }
  6117. mutex_unlock(&priv->mutex);
  6118. IWL_DEBUG_MAC80211("leave\n");
  6119. }
  6120. static int iwl3945_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
  6121. {
  6122. int rc = 0;
  6123. unsigned long flags;
  6124. struct iwl3945_priv *priv = hw->priv;
  6125. IWL_DEBUG_MAC80211("enter\n");
  6126. mutex_lock(&priv->mutex);
  6127. spin_lock_irqsave(&priv->lock, flags);
  6128. if (!iwl3945_is_ready_rf(priv)) {
  6129. rc = -EIO;
  6130. IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
  6131. goto out_unlock;
  6132. }
  6133. if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */
  6134. rc = -EIO;
  6135. IWL_ERROR("ERROR: APs don't scan\n");
  6136. goto out_unlock;
  6137. }
  6138. /* we don't schedule scan within next_scan_jiffies period */
  6139. if (priv->next_scan_jiffies &&
  6140. time_after(priv->next_scan_jiffies, jiffies)) {
  6141. rc = -EAGAIN;
  6142. goto out_unlock;
  6143. }
  6144. /* if we just finished scan ask for delay */
  6145. if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies +
  6146. IWL_DELAY_NEXT_SCAN, jiffies)) {
  6147. rc = -EAGAIN;
  6148. goto out_unlock;
  6149. }
  6150. if (len) {
  6151. IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
  6152. iwl3945_escape_essid(ssid, len), (int)len);
  6153. priv->one_direct_scan = 1;
  6154. priv->direct_ssid_len = (u8)
  6155. min((u8) len, (u8) IW_ESSID_MAX_SIZE);
  6156. memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
  6157. } else
  6158. priv->one_direct_scan = 0;
  6159. rc = iwl3945_scan_initiate(priv);
  6160. IWL_DEBUG_MAC80211("leave\n");
  6161. out_unlock:
  6162. spin_unlock_irqrestore(&priv->lock, flags);
  6163. mutex_unlock(&priv->mutex);
  6164. return rc;
  6165. }
  6166. static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  6167. const u8 *local_addr, const u8 *addr,
  6168. struct ieee80211_key_conf *key)
  6169. {
  6170. struct iwl3945_priv *priv = hw->priv;
  6171. int rc = 0;
  6172. u8 sta_id;
  6173. IWL_DEBUG_MAC80211("enter\n");
  6174. if (!iwl3945_param_hwcrypto) {
  6175. IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
  6176. return -EOPNOTSUPP;
  6177. }
  6178. if (is_zero_ether_addr(addr))
  6179. /* only support pairwise keys */
  6180. return -EOPNOTSUPP;
  6181. sta_id = iwl3945_hw_find_station(priv, addr);
  6182. if (sta_id == IWL_INVALID_STATION) {
  6183. DECLARE_MAC_BUF(mac);
  6184. IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
  6185. print_mac(mac, addr));
  6186. return -EINVAL;
  6187. }
  6188. mutex_lock(&priv->mutex);
  6189. iwl3945_scan_cancel_timeout(priv, 100);
  6190. switch (cmd) {
  6191. case SET_KEY:
  6192. rc = iwl3945_update_sta_key_info(priv, key, sta_id);
  6193. if (!rc) {
  6194. iwl3945_set_rxon_hwcrypto(priv, 1);
  6195. iwl3945_commit_rxon(priv);
  6196. key->hw_key_idx = sta_id;
  6197. IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n");
  6198. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  6199. }
  6200. break;
  6201. case DISABLE_KEY:
  6202. rc = iwl3945_clear_sta_key_info(priv, sta_id);
  6203. if (!rc) {
  6204. iwl3945_set_rxon_hwcrypto(priv, 0);
  6205. iwl3945_commit_rxon(priv);
  6206. IWL_DEBUG_MAC80211("disable hwcrypto key\n");
  6207. }
  6208. break;
  6209. default:
  6210. rc = -EINVAL;
  6211. }
  6212. IWL_DEBUG_MAC80211("leave\n");
  6213. mutex_unlock(&priv->mutex);
  6214. return rc;
  6215. }
  6216. static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, int queue,
  6217. const struct ieee80211_tx_queue_params *params)
  6218. {
  6219. struct iwl3945_priv *priv = hw->priv;
  6220. #ifdef CONFIG_IWL3945_QOS
  6221. unsigned long flags;
  6222. int q;
  6223. #endif /* CONFIG_IWL3945_QOS */
  6224. IWL_DEBUG_MAC80211("enter\n");
  6225. if (!iwl3945_is_ready_rf(priv)) {
  6226. IWL_DEBUG_MAC80211("leave - RF not ready\n");
  6227. return -EIO;
  6228. }
  6229. if (queue >= AC_NUM) {
  6230. IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
  6231. return 0;
  6232. }
  6233. #ifdef CONFIG_IWL3945_QOS
  6234. if (!priv->qos_data.qos_enable) {
  6235. priv->qos_data.qos_active = 0;
  6236. IWL_DEBUG_MAC80211("leave - qos not enabled\n");
  6237. return 0;
  6238. }
  6239. q = AC_NUM - 1 - queue;
  6240. spin_lock_irqsave(&priv->lock, flags);
  6241. priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
  6242. priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
  6243. priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
  6244. priv->qos_data.def_qos_parm.ac[q].edca_txop =
  6245. cpu_to_le16((params->burst_time * 100));
  6246. priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
  6247. priv->qos_data.qos_active = 1;
  6248. spin_unlock_irqrestore(&priv->lock, flags);
  6249. mutex_lock(&priv->mutex);
  6250. if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
  6251. iwl3945_activate_qos(priv, 1);
  6252. else if (priv->assoc_id && iwl3945_is_associated(priv))
  6253. iwl3945_activate_qos(priv, 0);
  6254. mutex_unlock(&priv->mutex);
  6255. #endif /*CONFIG_IWL3945_QOS */
  6256. IWL_DEBUG_MAC80211("leave\n");
  6257. return 0;
  6258. }
  6259. static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
  6260. struct ieee80211_tx_queue_stats *stats)
  6261. {
  6262. struct iwl3945_priv *priv = hw->priv;
  6263. int i, avail;
  6264. struct iwl3945_tx_queue *txq;
  6265. struct iwl3945_queue *q;
  6266. unsigned long flags;
  6267. IWL_DEBUG_MAC80211("enter\n");
  6268. if (!iwl3945_is_ready_rf(priv)) {
  6269. IWL_DEBUG_MAC80211("leave - RF not ready\n");
  6270. return -EIO;
  6271. }
  6272. spin_lock_irqsave(&priv->lock, flags);
  6273. for (i = 0; i < AC_NUM; i++) {
  6274. txq = &priv->txq[i];
  6275. q = &txq->q;
  6276. avail = iwl3945_queue_space(q);
  6277. stats->data[i].len = q->n_window - avail;
  6278. stats->data[i].limit = q->n_window - q->high_mark;
  6279. stats->data[i].count = q->n_window;
  6280. }
  6281. spin_unlock_irqrestore(&priv->lock, flags);
  6282. IWL_DEBUG_MAC80211("leave\n");
  6283. return 0;
  6284. }
  6285. static int iwl3945_mac_get_stats(struct ieee80211_hw *hw,
  6286. struct ieee80211_low_level_stats *stats)
  6287. {
  6288. IWL_DEBUG_MAC80211("enter\n");
  6289. IWL_DEBUG_MAC80211("leave\n");
  6290. return 0;
  6291. }
  6292. static u64 iwl3945_mac_get_tsf(struct ieee80211_hw *hw)
  6293. {
  6294. IWL_DEBUG_MAC80211("enter\n");
  6295. IWL_DEBUG_MAC80211("leave\n");
  6296. return 0;
  6297. }
  6298. static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
  6299. {
  6300. struct iwl3945_priv *priv = hw->priv;
  6301. unsigned long flags;
  6302. mutex_lock(&priv->mutex);
  6303. IWL_DEBUG_MAC80211("enter\n");
  6304. #ifdef CONFIG_IWL3945_QOS
  6305. iwl3945_reset_qos(priv);
  6306. #endif
  6307. cancel_delayed_work(&priv->post_associate);
  6308. spin_lock_irqsave(&priv->lock, flags);
  6309. priv->assoc_id = 0;
  6310. priv->assoc_capability = 0;
  6311. priv->call_post_assoc_from_beacon = 0;
  6312. /* new association get rid of ibss beacon skb */
  6313. if (priv->ibss_beacon)
  6314. dev_kfree_skb(priv->ibss_beacon);
  6315. priv->ibss_beacon = NULL;
  6316. priv->beacon_int = priv->hw->conf.beacon_int;
  6317. priv->timestamp1 = 0;
  6318. priv->timestamp0 = 0;
  6319. if ((priv->iw_mode == IEEE80211_IF_TYPE_STA))
  6320. priv->beacon_int = 0;
  6321. spin_unlock_irqrestore(&priv->lock, flags);
  6322. /* we are restarting association process
  6323. * clear RXON_FILTER_ASSOC_MSK bit
  6324. */
  6325. if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
  6326. iwl3945_scan_cancel_timeout(priv, 100);
  6327. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  6328. iwl3945_commit_rxon(priv);
  6329. }
  6330. /* Per mac80211.h: This is only used in IBSS mode... */
  6331. if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
  6332. IWL_DEBUG_MAC80211("leave - not in IBSS\n");
  6333. mutex_unlock(&priv->mutex);
  6334. return;
  6335. }
  6336. if (!iwl3945_is_ready_rf(priv)) {
  6337. IWL_DEBUG_MAC80211("leave - not ready\n");
  6338. mutex_unlock(&priv->mutex);
  6339. return;
  6340. }
  6341. priv->only_active_channel = 0;
  6342. iwl3945_set_rate(priv);
  6343. mutex_unlock(&priv->mutex);
  6344. IWL_DEBUG_MAC80211("leave\n");
  6345. }
  6346. static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb,
  6347. struct ieee80211_tx_control *control)
  6348. {
  6349. struct iwl3945_priv *priv = hw->priv;
  6350. unsigned long flags;
  6351. mutex_lock(&priv->mutex);
  6352. IWL_DEBUG_MAC80211("enter\n");
  6353. if (!iwl3945_is_ready_rf(priv)) {
  6354. IWL_DEBUG_MAC80211("leave - RF not ready\n");
  6355. mutex_unlock(&priv->mutex);
  6356. return -EIO;
  6357. }
  6358. if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
  6359. IWL_DEBUG_MAC80211("leave - not IBSS\n");
  6360. mutex_unlock(&priv->mutex);
  6361. return -EIO;
  6362. }
  6363. spin_lock_irqsave(&priv->lock, flags);
  6364. if (priv->ibss_beacon)
  6365. dev_kfree_skb(priv->ibss_beacon);
  6366. priv->ibss_beacon = skb;
  6367. priv->assoc_id = 0;
  6368. IWL_DEBUG_MAC80211("leave\n");
  6369. spin_unlock_irqrestore(&priv->lock, flags);
  6370. #ifdef CONFIG_IWL3945_QOS
  6371. iwl3945_reset_qos(priv);
  6372. #endif
  6373. queue_work(priv->workqueue, &priv->post_associate.work);
  6374. mutex_unlock(&priv->mutex);
  6375. return 0;
  6376. }
  6377. /*****************************************************************************
  6378. *
  6379. * sysfs attributes
  6380. *
  6381. *****************************************************************************/
  6382. #ifdef CONFIG_IWL3945_DEBUG
  6383. /*
  6384. * The following adds a new attribute to the sysfs representation
  6385. * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
  6386. * used for controlling the debug level.
  6387. *
  6388. * See the level definitions in iwl for details.
  6389. */
  6390. static ssize_t show_debug_level(struct device_driver *d, char *buf)
  6391. {
  6392. return sprintf(buf, "0x%08X\n", iwl3945_debug_level);
  6393. }
  6394. static ssize_t store_debug_level(struct device_driver *d,
  6395. const char *buf, size_t count)
  6396. {
  6397. char *p = (char *)buf;
  6398. u32 val;
  6399. val = simple_strtoul(p, &p, 0);
  6400. if (p == buf)
  6401. printk(KERN_INFO DRV_NAME
  6402. ": %s is not in hex or decimal form.\n", buf);
  6403. else
  6404. iwl3945_debug_level = val;
  6405. return strnlen(buf, count);
  6406. }
  6407. static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
  6408. show_debug_level, store_debug_level);
  6409. #endif /* CONFIG_IWL3945_DEBUG */
  6410. static ssize_t show_rf_kill(struct device *d,
  6411. struct device_attribute *attr, char *buf)
  6412. {
  6413. /*
  6414. * 0 - RF kill not enabled
  6415. * 1 - SW based RF kill active (sysfs)
  6416. * 2 - HW based RF kill active
  6417. * 3 - Both HW and SW based RF kill active
  6418. */
  6419. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6420. int val = (test_bit(STATUS_RF_KILL_SW, &priv->status) ? 0x1 : 0x0) |
  6421. (test_bit(STATUS_RF_KILL_HW, &priv->status) ? 0x2 : 0x0);
  6422. return sprintf(buf, "%i\n", val);
  6423. }
  6424. static ssize_t store_rf_kill(struct device *d,
  6425. struct device_attribute *attr,
  6426. const char *buf, size_t count)
  6427. {
  6428. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6429. mutex_lock(&priv->mutex);
  6430. iwl3945_radio_kill_sw(priv, buf[0] == '1');
  6431. mutex_unlock(&priv->mutex);
  6432. return count;
  6433. }
  6434. static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
  6435. static ssize_t show_temperature(struct device *d,
  6436. struct device_attribute *attr, char *buf)
  6437. {
  6438. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6439. if (!iwl3945_is_alive(priv))
  6440. return -EAGAIN;
  6441. return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
  6442. }
  6443. static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
  6444. static ssize_t show_rs_window(struct device *d,
  6445. struct device_attribute *attr,
  6446. char *buf)
  6447. {
  6448. struct iwl3945_priv *priv = d->driver_data;
  6449. return iwl3945_fill_rs_info(priv->hw, buf, IWL_AP_ID);
  6450. }
  6451. static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL);
  6452. static ssize_t show_tx_power(struct device *d,
  6453. struct device_attribute *attr, char *buf)
  6454. {
  6455. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6456. return sprintf(buf, "%d\n", priv->user_txpower_limit);
  6457. }
  6458. static ssize_t store_tx_power(struct device *d,
  6459. struct device_attribute *attr,
  6460. const char *buf, size_t count)
  6461. {
  6462. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6463. char *p = (char *)buf;
  6464. u32 val;
  6465. val = simple_strtoul(p, &p, 10);
  6466. if (p == buf)
  6467. printk(KERN_INFO DRV_NAME
  6468. ": %s is not in decimal form.\n", buf);
  6469. else
  6470. iwl3945_hw_reg_set_txpower(priv, val);
  6471. return count;
  6472. }
  6473. static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
  6474. static ssize_t show_flags(struct device *d,
  6475. struct device_attribute *attr, char *buf)
  6476. {
  6477. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6478. return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
  6479. }
  6480. static ssize_t store_flags(struct device *d,
  6481. struct device_attribute *attr,
  6482. const char *buf, size_t count)
  6483. {
  6484. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6485. u32 flags = simple_strtoul(buf, NULL, 0);
  6486. mutex_lock(&priv->mutex);
  6487. if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
  6488. /* Cancel any currently running scans... */
  6489. if (iwl3945_scan_cancel_timeout(priv, 100))
  6490. IWL_WARNING("Could not cancel scan.\n");
  6491. else {
  6492. IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
  6493. flags);
  6494. priv->staging_rxon.flags = cpu_to_le32(flags);
  6495. iwl3945_commit_rxon(priv);
  6496. }
  6497. }
  6498. mutex_unlock(&priv->mutex);
  6499. return count;
  6500. }
  6501. static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
  6502. static ssize_t show_filter_flags(struct device *d,
  6503. struct device_attribute *attr, char *buf)
  6504. {
  6505. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6506. return sprintf(buf, "0x%04X\n",
  6507. le32_to_cpu(priv->active_rxon.filter_flags));
  6508. }
  6509. static ssize_t store_filter_flags(struct device *d,
  6510. struct device_attribute *attr,
  6511. const char *buf, size_t count)
  6512. {
  6513. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6514. u32 filter_flags = simple_strtoul(buf, NULL, 0);
  6515. mutex_lock(&priv->mutex);
  6516. if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
  6517. /* Cancel any currently running scans... */
  6518. if (iwl3945_scan_cancel_timeout(priv, 100))
  6519. IWL_WARNING("Could not cancel scan.\n");
  6520. else {
  6521. IWL_DEBUG_INFO("Committing rxon.filter_flags = "
  6522. "0x%04X\n", filter_flags);
  6523. priv->staging_rxon.filter_flags =
  6524. cpu_to_le32(filter_flags);
  6525. iwl3945_commit_rxon(priv);
  6526. }
  6527. }
  6528. mutex_unlock(&priv->mutex);
  6529. return count;
  6530. }
  6531. static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
  6532. store_filter_flags);
  6533. static ssize_t show_tune(struct device *d,
  6534. struct device_attribute *attr, char *buf)
  6535. {
  6536. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6537. return sprintf(buf, "0x%04X\n",
  6538. (priv->phymode << 8) |
  6539. le16_to_cpu(priv->active_rxon.channel));
  6540. }
  6541. static void iwl3945_set_flags_for_phymode(struct iwl3945_priv *priv, u8 phymode);
  6542. static ssize_t store_tune(struct device *d,
  6543. struct device_attribute *attr,
  6544. const char *buf, size_t count)
  6545. {
  6546. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6547. char *p = (char *)buf;
  6548. u16 tune = simple_strtoul(p, &p, 0);
  6549. u8 phymode = (tune >> 8) & 0xff;
  6550. u16 channel = tune & 0xff;
  6551. IWL_DEBUG_INFO("Tune request to:%d channel:%d\n", phymode, channel);
  6552. mutex_lock(&priv->mutex);
  6553. if ((le16_to_cpu(priv->staging_rxon.channel) != channel) ||
  6554. (priv->phymode != phymode)) {
  6555. const struct iwl3945_channel_info *ch_info;
  6556. ch_info = iwl3945_get_channel_info(priv, phymode, channel);
  6557. if (!ch_info) {
  6558. IWL_WARNING("Requested invalid phymode/channel "
  6559. "combination: %d %d\n", phymode, channel);
  6560. mutex_unlock(&priv->mutex);
  6561. return -EINVAL;
  6562. }
  6563. /* Cancel any currently running scans... */
  6564. if (iwl3945_scan_cancel_timeout(priv, 100))
  6565. IWL_WARNING("Could not cancel scan.\n");
  6566. else {
  6567. IWL_DEBUG_INFO("Committing phymode and "
  6568. "rxon.channel = %d %d\n",
  6569. phymode, channel);
  6570. iwl3945_set_rxon_channel(priv, phymode, channel);
  6571. iwl3945_set_flags_for_phymode(priv, phymode);
  6572. iwl3945_set_rate(priv);
  6573. iwl3945_commit_rxon(priv);
  6574. }
  6575. }
  6576. mutex_unlock(&priv->mutex);
  6577. return count;
  6578. }
  6579. static DEVICE_ATTR(tune, S_IWUSR | S_IRUGO, show_tune, store_tune);
  6580. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  6581. static ssize_t show_measurement(struct device *d,
  6582. struct device_attribute *attr, char *buf)
  6583. {
  6584. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6585. struct iwl3945_spectrum_notification measure_report;
  6586. u32 size = sizeof(measure_report), len = 0, ofs = 0;
  6587. u8 *data = (u8 *) & measure_report;
  6588. unsigned long flags;
  6589. spin_lock_irqsave(&priv->lock, flags);
  6590. if (!(priv->measurement_status & MEASUREMENT_READY)) {
  6591. spin_unlock_irqrestore(&priv->lock, flags);
  6592. return 0;
  6593. }
  6594. memcpy(&measure_report, &priv->measure_report, size);
  6595. priv->measurement_status = 0;
  6596. spin_unlock_irqrestore(&priv->lock, flags);
  6597. while (size && (PAGE_SIZE - len)) {
  6598. hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
  6599. PAGE_SIZE - len, 1);
  6600. len = strlen(buf);
  6601. if (PAGE_SIZE - len)
  6602. buf[len++] = '\n';
  6603. ofs += 16;
  6604. size -= min(size, 16U);
  6605. }
  6606. return len;
  6607. }
  6608. static ssize_t store_measurement(struct device *d,
  6609. struct device_attribute *attr,
  6610. const char *buf, size_t count)
  6611. {
  6612. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6613. struct ieee80211_measurement_params params = {
  6614. .channel = le16_to_cpu(priv->active_rxon.channel),
  6615. .start_time = cpu_to_le64(priv->last_tsf),
  6616. .duration = cpu_to_le16(1),
  6617. };
  6618. u8 type = IWL_MEASURE_BASIC;
  6619. u8 buffer[32];
  6620. u8 channel;
  6621. if (count) {
  6622. char *p = buffer;
  6623. strncpy(buffer, buf, min(sizeof(buffer), count));
  6624. channel = simple_strtoul(p, NULL, 0);
  6625. if (channel)
  6626. params.channel = channel;
  6627. p = buffer;
  6628. while (*p && *p != ' ')
  6629. p++;
  6630. if (*p)
  6631. type = simple_strtoul(p + 1, NULL, 0);
  6632. }
  6633. IWL_DEBUG_INFO("Invoking measurement of type %d on "
  6634. "channel %d (for '%s')\n", type, params.channel, buf);
  6635. iwl3945_get_measurement(priv, &params, type);
  6636. return count;
  6637. }
  6638. static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
  6639. show_measurement, store_measurement);
  6640. #endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
  6641. static ssize_t show_rate(struct device *d,
  6642. struct device_attribute *attr, char *buf)
  6643. {
  6644. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6645. unsigned long flags;
  6646. int i;
  6647. spin_lock_irqsave(&priv->sta_lock, flags);
  6648. if (priv->iw_mode == IEEE80211_IF_TYPE_STA)
  6649. i = priv->stations[IWL_AP_ID].current_rate.s.rate;
  6650. else
  6651. i = priv->stations[IWL_STA_ID].current_rate.s.rate;
  6652. spin_unlock_irqrestore(&priv->sta_lock, flags);
  6653. i = iwl3945_rate_index_from_plcp(i);
  6654. if (i == -1)
  6655. return sprintf(buf, "0\n");
  6656. return sprintf(buf, "%d%s\n",
  6657. (iwl3945_rates[i].ieee >> 1),
  6658. (iwl3945_rates[i].ieee & 0x1) ? ".5" : "");
  6659. }
  6660. static DEVICE_ATTR(rate, S_IRUSR, show_rate, NULL);
  6661. static ssize_t store_retry_rate(struct device *d,
  6662. struct device_attribute *attr,
  6663. const char *buf, size_t count)
  6664. {
  6665. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6666. priv->retry_rate = simple_strtoul(buf, NULL, 0);
  6667. if (priv->retry_rate <= 0)
  6668. priv->retry_rate = 1;
  6669. return count;
  6670. }
  6671. static ssize_t show_retry_rate(struct device *d,
  6672. struct device_attribute *attr, char *buf)
  6673. {
  6674. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6675. return sprintf(buf, "%d", priv->retry_rate);
  6676. }
  6677. static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
  6678. store_retry_rate);
  6679. static ssize_t store_power_level(struct device *d,
  6680. struct device_attribute *attr,
  6681. const char *buf, size_t count)
  6682. {
  6683. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6684. int rc;
  6685. int mode;
  6686. mode = simple_strtoul(buf, NULL, 0);
  6687. mutex_lock(&priv->mutex);
  6688. if (!iwl3945_is_ready(priv)) {
  6689. rc = -EAGAIN;
  6690. goto out;
  6691. }
  6692. if ((mode < 1) || (mode > IWL_POWER_LIMIT) || (mode == IWL_POWER_AC))
  6693. mode = IWL_POWER_AC;
  6694. else
  6695. mode |= IWL_POWER_ENABLED;
  6696. if (mode != priv->power_mode) {
  6697. rc = iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(mode));
  6698. if (rc) {
  6699. IWL_DEBUG_MAC80211("failed setting power mode.\n");
  6700. goto out;
  6701. }
  6702. priv->power_mode = mode;
  6703. }
  6704. rc = count;
  6705. out:
  6706. mutex_unlock(&priv->mutex);
  6707. return rc;
  6708. }
  6709. #define MAX_WX_STRING 80
  6710. /* Values are in microsecond */
  6711. static const s32 timeout_duration[] = {
  6712. 350000,
  6713. 250000,
  6714. 75000,
  6715. 37000,
  6716. 25000,
  6717. };
  6718. static const s32 period_duration[] = {
  6719. 400000,
  6720. 700000,
  6721. 1000000,
  6722. 1000000,
  6723. 1000000
  6724. };
  6725. static ssize_t show_power_level(struct device *d,
  6726. struct device_attribute *attr, char *buf)
  6727. {
  6728. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6729. int level = IWL_POWER_LEVEL(priv->power_mode);
  6730. char *p = buf;
  6731. p += sprintf(p, "%d ", level);
  6732. switch (level) {
  6733. case IWL_POWER_MODE_CAM:
  6734. case IWL_POWER_AC:
  6735. p += sprintf(p, "(AC)");
  6736. break;
  6737. case IWL_POWER_BATTERY:
  6738. p += sprintf(p, "(BATTERY)");
  6739. break;
  6740. default:
  6741. p += sprintf(p,
  6742. "(Timeout %dms, Period %dms)",
  6743. timeout_duration[level - 1] / 1000,
  6744. period_duration[level - 1] / 1000);
  6745. }
  6746. if (!(priv->power_mode & IWL_POWER_ENABLED))
  6747. p += sprintf(p, " OFF\n");
  6748. else
  6749. p += sprintf(p, " \n");
  6750. return (p - buf + 1);
  6751. }
  6752. static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
  6753. store_power_level);
  6754. static ssize_t show_channels(struct device *d,
  6755. struct device_attribute *attr, char *buf)
  6756. {
  6757. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6758. int len = 0, i;
  6759. struct ieee80211_channel *channels = NULL;
  6760. const struct ieee80211_hw_mode *hw_mode = NULL;
  6761. int count = 0;
  6762. if (!iwl3945_is_ready(priv))
  6763. return -EAGAIN;
  6764. hw_mode = iwl3945_get_hw_mode(priv, MODE_IEEE80211G);
  6765. if (!hw_mode)
  6766. hw_mode = iwl3945_get_hw_mode(priv, MODE_IEEE80211B);
  6767. if (hw_mode) {
  6768. channels = hw_mode->channels;
  6769. count = hw_mode->num_channels;
  6770. }
  6771. len +=
  6772. sprintf(&buf[len],
  6773. "Displaying %d channels in 2.4GHz band "
  6774. "(802.11bg):\n", count);
  6775. for (i = 0; i < count; i++)
  6776. len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
  6777. channels[i].chan,
  6778. channels[i].power_level,
  6779. channels[i].
  6780. flag & IEEE80211_CHAN_W_RADAR_DETECT ?
  6781. " (IEEE 802.11h required)" : "",
  6782. (!(channels[i].flag & IEEE80211_CHAN_W_IBSS)
  6783. || (channels[i].
  6784. flag &
  6785. IEEE80211_CHAN_W_RADAR_DETECT)) ? "" :
  6786. ", IBSS",
  6787. channels[i].
  6788. flag & IEEE80211_CHAN_W_ACTIVE_SCAN ?
  6789. "active/passive" : "passive only");
  6790. hw_mode = iwl3945_get_hw_mode(priv, MODE_IEEE80211A);
  6791. if (hw_mode) {
  6792. channels = hw_mode->channels;
  6793. count = hw_mode->num_channels;
  6794. } else {
  6795. channels = NULL;
  6796. count = 0;
  6797. }
  6798. len += sprintf(&buf[len], "Displaying %d channels in 5.2GHz band "
  6799. "(802.11a):\n", count);
  6800. for (i = 0; i < count; i++)
  6801. len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
  6802. channels[i].chan,
  6803. channels[i].power_level,
  6804. channels[i].
  6805. flag & IEEE80211_CHAN_W_RADAR_DETECT ?
  6806. " (IEEE 802.11h required)" : "",
  6807. (!(channels[i].flag & IEEE80211_CHAN_W_IBSS)
  6808. || (channels[i].
  6809. flag &
  6810. IEEE80211_CHAN_W_RADAR_DETECT)) ? "" :
  6811. ", IBSS",
  6812. channels[i].
  6813. flag & IEEE80211_CHAN_W_ACTIVE_SCAN ?
  6814. "active/passive" : "passive only");
  6815. return len;
  6816. }
  6817. static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
  6818. static ssize_t show_statistics(struct device *d,
  6819. struct device_attribute *attr, char *buf)
  6820. {
  6821. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6822. u32 size = sizeof(struct iwl3945_notif_statistics);
  6823. u32 len = 0, ofs = 0;
  6824. u8 *data = (u8 *) & priv->statistics;
  6825. int rc = 0;
  6826. if (!iwl3945_is_alive(priv))
  6827. return -EAGAIN;
  6828. mutex_lock(&priv->mutex);
  6829. rc = iwl3945_send_statistics_request(priv);
  6830. mutex_unlock(&priv->mutex);
  6831. if (rc) {
  6832. len = sprintf(buf,
  6833. "Error sending statistics request: 0x%08X\n", rc);
  6834. return len;
  6835. }
  6836. while (size && (PAGE_SIZE - len)) {
  6837. hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
  6838. PAGE_SIZE - len, 1);
  6839. len = strlen(buf);
  6840. if (PAGE_SIZE - len)
  6841. buf[len++] = '\n';
  6842. ofs += 16;
  6843. size -= min(size, 16U);
  6844. }
  6845. return len;
  6846. }
  6847. static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
  6848. static ssize_t show_antenna(struct device *d,
  6849. struct device_attribute *attr, char *buf)
  6850. {
  6851. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6852. if (!iwl3945_is_alive(priv))
  6853. return -EAGAIN;
  6854. return sprintf(buf, "%d\n", priv->antenna);
  6855. }
  6856. static ssize_t store_antenna(struct device *d,
  6857. struct device_attribute *attr,
  6858. const char *buf, size_t count)
  6859. {
  6860. int ant;
  6861. struct iwl3945_priv *priv = dev_get_drvdata(d);
  6862. if (count == 0)
  6863. return 0;
  6864. if (sscanf(buf, "%1i", &ant) != 1) {
  6865. IWL_DEBUG_INFO("not in hex or decimal form.\n");
  6866. return count;
  6867. }
  6868. if ((ant >= 0) && (ant <= 2)) {
  6869. IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant);
  6870. priv->antenna = (enum iwl3945_antenna)ant;
  6871. } else
  6872. IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant);
  6873. return count;
  6874. }
  6875. static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
  6876. static ssize_t show_status(struct device *d,
  6877. struct device_attribute *attr, char *buf)
  6878. {
  6879. struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data;
  6880. if (!iwl3945_is_alive(priv))
  6881. return -EAGAIN;
  6882. return sprintf(buf, "0x%08x\n", (int)priv->status);
  6883. }
  6884. static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
  6885. static ssize_t dump_error_log(struct device *d,
  6886. struct device_attribute *attr,
  6887. const char *buf, size_t count)
  6888. {
  6889. char *p = (char *)buf;
  6890. if (p[0] == '1')
  6891. iwl3945_dump_nic_error_log((struct iwl3945_priv *)d->driver_data);
  6892. return strnlen(buf, count);
  6893. }
  6894. static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
  6895. static ssize_t dump_event_log(struct device *d,
  6896. struct device_attribute *attr,
  6897. const char *buf, size_t count)
  6898. {
  6899. char *p = (char *)buf;
  6900. if (p[0] == '1')
  6901. iwl3945_dump_nic_event_log((struct iwl3945_priv *)d->driver_data);
  6902. return strnlen(buf, count);
  6903. }
  6904. static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
  6905. /*****************************************************************************
  6906. *
  6907. * driver setup and teardown
  6908. *
  6909. *****************************************************************************/
  6910. static void iwl3945_setup_deferred_work(struct iwl3945_priv *priv)
  6911. {
  6912. priv->workqueue = create_workqueue(DRV_NAME);
  6913. init_waitqueue_head(&priv->wait_command_queue);
  6914. INIT_WORK(&priv->up, iwl3945_bg_up);
  6915. INIT_WORK(&priv->restart, iwl3945_bg_restart);
  6916. INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
  6917. INIT_WORK(&priv->scan_completed, iwl3945_bg_scan_completed);
  6918. INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
  6919. INIT_WORK(&priv->abort_scan, iwl3945_bg_abort_scan);
  6920. INIT_WORK(&priv->rf_kill, iwl3945_bg_rf_kill);
  6921. INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
  6922. INIT_DELAYED_WORK(&priv->post_associate, iwl3945_bg_post_associate);
  6923. INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
  6924. INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
  6925. INIT_DELAYED_WORK(&priv->scan_check, iwl3945_bg_scan_check);
  6926. iwl3945_hw_setup_deferred_work(priv);
  6927. tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
  6928. iwl3945_irq_tasklet, (unsigned long)priv);
  6929. }
  6930. static void iwl3945_cancel_deferred_work(struct iwl3945_priv *priv)
  6931. {
  6932. iwl3945_hw_cancel_deferred_work(priv);
  6933. cancel_delayed_work_sync(&priv->init_alive_start);
  6934. cancel_delayed_work(&priv->scan_check);
  6935. cancel_delayed_work(&priv->alive_start);
  6936. cancel_delayed_work(&priv->post_associate);
  6937. cancel_work_sync(&priv->beacon_update);
  6938. }
  6939. static struct attribute *iwl3945_sysfs_entries[] = {
  6940. &dev_attr_antenna.attr,
  6941. &dev_attr_channels.attr,
  6942. &dev_attr_dump_errors.attr,
  6943. &dev_attr_dump_events.attr,
  6944. &dev_attr_flags.attr,
  6945. &dev_attr_filter_flags.attr,
  6946. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  6947. &dev_attr_measurement.attr,
  6948. #endif
  6949. &dev_attr_power_level.attr,
  6950. &dev_attr_rate.attr,
  6951. &dev_attr_retry_rate.attr,
  6952. &dev_attr_rf_kill.attr,
  6953. &dev_attr_rs_window.attr,
  6954. &dev_attr_statistics.attr,
  6955. &dev_attr_status.attr,
  6956. &dev_attr_temperature.attr,
  6957. &dev_attr_tune.attr,
  6958. &dev_attr_tx_power.attr,
  6959. NULL
  6960. };
  6961. static struct attribute_group iwl3945_attribute_group = {
  6962. .name = NULL, /* put in device directory */
  6963. .attrs = iwl3945_sysfs_entries,
  6964. };
  6965. static struct ieee80211_ops iwl3945_hw_ops = {
  6966. .tx = iwl3945_mac_tx,
  6967. .start = iwl3945_mac_start,
  6968. .stop = iwl3945_mac_stop,
  6969. .add_interface = iwl3945_mac_add_interface,
  6970. .remove_interface = iwl3945_mac_remove_interface,
  6971. .config = iwl3945_mac_config,
  6972. .config_interface = iwl3945_mac_config_interface,
  6973. .configure_filter = iwl3945_configure_filter,
  6974. .set_key = iwl3945_mac_set_key,
  6975. .get_stats = iwl3945_mac_get_stats,
  6976. .get_tx_stats = iwl3945_mac_get_tx_stats,
  6977. .conf_tx = iwl3945_mac_conf_tx,
  6978. .get_tsf = iwl3945_mac_get_tsf,
  6979. .reset_tsf = iwl3945_mac_reset_tsf,
  6980. .beacon_update = iwl3945_mac_beacon_update,
  6981. .hw_scan = iwl3945_mac_hw_scan
  6982. };
  6983. static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  6984. {
  6985. int err = 0;
  6986. u32 pci_id;
  6987. struct iwl3945_priv *priv;
  6988. struct ieee80211_hw *hw;
  6989. int i;
  6990. /* Disabling hardware scan means that mac80211 will perform scans
  6991. * "the hard way", rather than using device's scan. */
  6992. if (iwl3945_param_disable_hw_scan) {
  6993. IWL_DEBUG_INFO("Disabling hw_scan\n");
  6994. iwl3945_hw_ops.hw_scan = NULL;
  6995. }
  6996. if ((iwl3945_param_queues_num > IWL_MAX_NUM_QUEUES) ||
  6997. (iwl3945_param_queues_num < IWL_MIN_NUM_QUEUES)) {
  6998. IWL_ERROR("invalid queues_num, should be between %d and %d\n",
  6999. IWL_MIN_NUM_QUEUES, IWL_MAX_NUM_QUEUES);
  7000. err = -EINVAL;
  7001. goto out;
  7002. }
  7003. /* mac80211 allocates memory for this device instance, including
  7004. * space for this driver's private structure */
  7005. hw = ieee80211_alloc_hw(sizeof(struct iwl3945_priv), &iwl3945_hw_ops);
  7006. if (hw == NULL) {
  7007. IWL_ERROR("Can not allocate network device\n");
  7008. err = -ENOMEM;
  7009. goto out;
  7010. }
  7011. SET_IEEE80211_DEV(hw, &pdev->dev);
  7012. hw->rate_control_algorithm = "iwl-3945-rs";
  7013. IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
  7014. priv = hw->priv;
  7015. priv->hw = hw;
  7016. priv->pci_dev = pdev;
  7017. /* Select antenna (may be helpful if only one antenna is connected) */
  7018. priv->antenna = (enum iwl3945_antenna)iwl3945_param_antenna;
  7019. #ifdef CONFIG_IWL3945_DEBUG
  7020. iwl3945_debug_level = iwl3945_param_debug;
  7021. atomic_set(&priv->restrict_refcnt, 0);
  7022. #endif
  7023. priv->retry_rate = 1;
  7024. priv->ibss_beacon = NULL;
  7025. /* Tell mac80211 and its clients (e.g. Wireless Extensions)
  7026. * the range of signal quality values that we'll provide.
  7027. * Negative values for level/noise indicate that we'll provide dBm.
  7028. * For WE, at least, non-0 values here *enable* display of values
  7029. * in app (iwconfig). */
  7030. hw->max_rssi = -20; /* signal level, negative indicates dBm */
  7031. hw->max_noise = -20; /* noise level, negative indicates dBm */
  7032. hw->max_signal = 100; /* link quality indication (%) */
  7033. /* Tell mac80211 our Tx characteristics */
  7034. hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE;
  7035. /* 4 EDCA QOS priorities */
  7036. hw->queues = 4;
  7037. spin_lock_init(&priv->lock);
  7038. spin_lock_init(&priv->power_data.lock);
  7039. spin_lock_init(&priv->sta_lock);
  7040. spin_lock_init(&priv->hcmd_lock);
  7041. for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++)
  7042. INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
  7043. INIT_LIST_HEAD(&priv->free_frames);
  7044. mutex_init(&priv->mutex);
  7045. if (pci_enable_device(pdev)) {
  7046. err = -ENODEV;
  7047. goto out_ieee80211_free_hw;
  7048. }
  7049. pci_set_master(pdev);
  7050. /* Clear the driver's (not device's) station table */
  7051. iwl3945_clear_stations_table(priv);
  7052. priv->data_retry_limit = -1;
  7053. priv->ieee_channels = NULL;
  7054. priv->ieee_rates = NULL;
  7055. priv->phymode = -1;
  7056. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  7057. if (!err)
  7058. err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  7059. if (err) {
  7060. printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
  7061. goto out_pci_disable_device;
  7062. }
  7063. pci_set_drvdata(pdev, priv);
  7064. err = pci_request_regions(pdev, DRV_NAME);
  7065. if (err)
  7066. goto out_pci_disable_device;
  7067. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  7068. * PCI Tx retries from interfering with C3 CPU state */
  7069. pci_write_config_byte(pdev, 0x41, 0x00);
  7070. priv->hw_base = pci_iomap(pdev, 0, 0);
  7071. if (!priv->hw_base) {
  7072. err = -ENODEV;
  7073. goto out_pci_release_regions;
  7074. }
  7075. IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
  7076. (unsigned long long) pci_resource_len(pdev, 0));
  7077. IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
  7078. /* Initialize module parameter values here */
  7079. /* Disable radio (SW RF KILL) via parameter when loading driver */
  7080. if (iwl3945_param_disable) {
  7081. set_bit(STATUS_RF_KILL_SW, &priv->status);
  7082. IWL_DEBUG_INFO("Radio disabled.\n");
  7083. }
  7084. priv->iw_mode = IEEE80211_IF_TYPE_STA;
  7085. pci_id =
  7086. (priv->pci_dev->device << 16) | priv->pci_dev->subsystem_device;
  7087. switch (pci_id) {
  7088. case 0x42221005: /* 0x4222 0x8086 0x1005 is BG SKU */
  7089. case 0x42221034: /* 0x4222 0x8086 0x1034 is BG SKU */
  7090. case 0x42271014: /* 0x4227 0x8086 0x1014 is BG SKU */
  7091. case 0x42221044: /* 0x4222 0x8086 0x1044 is BG SKU */
  7092. priv->is_abg = 0;
  7093. break;
  7094. /*
  7095. * Rest are assumed ABG SKU -- if this is not the
  7096. * case then the card will get the wrong 'Detected'
  7097. * line in the kernel log however the code that
  7098. * initializes the GEO table will detect no A-band
  7099. * channels and remove the is_abg mask.
  7100. */
  7101. default:
  7102. priv->is_abg = 1;
  7103. break;
  7104. }
  7105. printk(KERN_INFO DRV_NAME
  7106. ": Detected Intel PRO/Wireless 3945%sBG Network Connection\n",
  7107. priv->is_abg ? "A" : "");
  7108. /* Device-specific setup */
  7109. if (iwl3945_hw_set_hw_setting(priv)) {
  7110. IWL_ERROR("failed to set hw settings\n");
  7111. mutex_unlock(&priv->mutex);
  7112. goto out_iounmap;
  7113. }
  7114. #ifdef CONFIG_IWL3945_QOS
  7115. if (iwl3945_param_qos_enable)
  7116. priv->qos_data.qos_enable = 1;
  7117. iwl3945_reset_qos(priv);
  7118. priv->qos_data.qos_active = 0;
  7119. priv->qos_data.qos_cap.val = 0;
  7120. #endif /* CONFIG_IWL3945_QOS */
  7121. iwl3945_set_rxon_channel(priv, MODE_IEEE80211G, 6);
  7122. iwl3945_setup_deferred_work(priv);
  7123. iwl3945_setup_rx_handlers(priv);
  7124. priv->rates_mask = IWL_RATES_MASK;
  7125. /* If power management is turned on, default to AC mode */
  7126. priv->power_mode = IWL_POWER_AC;
  7127. priv->user_txpower_limit = IWL_DEFAULT_TX_POWER;
  7128. iwl3945_disable_interrupts(priv);
  7129. pci_enable_msi(pdev);
  7130. err = request_irq(pdev->irq, iwl3945_isr, IRQF_SHARED, DRV_NAME, priv);
  7131. if (err) {
  7132. IWL_ERROR("Error allocating IRQ %d\n", pdev->irq);
  7133. goto out_disable_msi;
  7134. }
  7135. mutex_lock(&priv->mutex);
  7136. err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
  7137. if (err) {
  7138. IWL_ERROR("failed to create sysfs device attributes\n");
  7139. mutex_unlock(&priv->mutex);
  7140. goto out_release_irq;
  7141. }
  7142. /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
  7143. * ucode filename and max sizes are card-specific. */
  7144. err = iwl3945_read_ucode(priv);
  7145. if (err) {
  7146. IWL_ERROR("Could not read microcode: %d\n", err);
  7147. mutex_unlock(&priv->mutex);
  7148. goto out_pci_alloc;
  7149. }
  7150. mutex_unlock(&priv->mutex);
  7151. IWL_DEBUG_INFO("Queueing UP work.\n");
  7152. queue_work(priv->workqueue, &priv->up);
  7153. return 0;
  7154. out_pci_alloc:
  7155. iwl3945_dealloc_ucode_pci(priv);
  7156. sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
  7157. out_release_irq:
  7158. free_irq(pdev->irq, priv);
  7159. out_disable_msi:
  7160. pci_disable_msi(pdev);
  7161. destroy_workqueue(priv->workqueue);
  7162. priv->workqueue = NULL;
  7163. iwl3945_unset_hw_setting(priv);
  7164. out_iounmap:
  7165. pci_iounmap(pdev, priv->hw_base);
  7166. out_pci_release_regions:
  7167. pci_release_regions(pdev);
  7168. out_pci_disable_device:
  7169. pci_disable_device(pdev);
  7170. pci_set_drvdata(pdev, NULL);
  7171. out_ieee80211_free_hw:
  7172. ieee80211_free_hw(priv->hw);
  7173. out:
  7174. return err;
  7175. }
  7176. static void iwl3945_pci_remove(struct pci_dev *pdev)
  7177. {
  7178. struct iwl3945_priv *priv = pci_get_drvdata(pdev);
  7179. struct list_head *p, *q;
  7180. int i;
  7181. if (!priv)
  7182. return;
  7183. IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
  7184. set_bit(STATUS_EXIT_PENDING, &priv->status);
  7185. iwl3945_down(priv);
  7186. /* Free MAC hash list for ADHOC */
  7187. for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) {
  7188. list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
  7189. list_del(p);
  7190. kfree(list_entry(p, struct iwl3945_ibss_seq, list));
  7191. }
  7192. }
  7193. sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
  7194. iwl3945_dealloc_ucode_pci(priv);
  7195. if (priv->rxq.bd)
  7196. iwl3945_rx_queue_free(priv, &priv->rxq);
  7197. iwl3945_hw_txq_ctx_free(priv);
  7198. iwl3945_unset_hw_setting(priv);
  7199. iwl3945_clear_stations_table(priv);
  7200. if (priv->mac80211_registered) {
  7201. ieee80211_unregister_hw(priv->hw);
  7202. iwl3945_rate_control_unregister(priv->hw);
  7203. }
  7204. /*netif_stop_queue(dev); */
  7205. flush_workqueue(priv->workqueue);
  7206. /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
  7207. * priv->workqueue... so we can't take down the workqueue
  7208. * until now... */
  7209. destroy_workqueue(priv->workqueue);
  7210. priv->workqueue = NULL;
  7211. free_irq(pdev->irq, priv);
  7212. pci_disable_msi(pdev);
  7213. pci_iounmap(pdev, priv->hw_base);
  7214. pci_release_regions(pdev);
  7215. pci_disable_device(pdev);
  7216. pci_set_drvdata(pdev, NULL);
  7217. kfree(priv->channel_info);
  7218. kfree(priv->ieee_channels);
  7219. kfree(priv->ieee_rates);
  7220. if (priv->ibss_beacon)
  7221. dev_kfree_skb(priv->ibss_beacon);
  7222. ieee80211_free_hw(priv->hw);
  7223. }
  7224. #ifdef CONFIG_PM
  7225. static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  7226. {
  7227. struct iwl3945_priv *priv = pci_get_drvdata(pdev);
  7228. set_bit(STATUS_IN_SUSPEND, &priv->status);
  7229. /* Take down the device; powers it off, etc. */
  7230. iwl3945_down(priv);
  7231. if (priv->mac80211_registered)
  7232. ieee80211_stop_queues(priv->hw);
  7233. pci_save_state(pdev);
  7234. pci_disable_device(pdev);
  7235. pci_set_power_state(pdev, PCI_D3hot);
  7236. return 0;
  7237. }
  7238. static void iwl3945_resume(struct iwl3945_priv *priv)
  7239. {
  7240. unsigned long flags;
  7241. /* The following it a temporary work around due to the
  7242. * suspend / resume not fully initializing the NIC correctly.
  7243. * Without all of the following, resume will not attempt to take
  7244. * down the NIC (it shouldn't really need to) and will just try
  7245. * and bring the NIC back up. However that fails during the
  7246. * ucode verification process. This then causes iwl3945_down to be
  7247. * called *after* iwl3945_hw_nic_init() has succeeded -- which
  7248. * then lets the next init sequence succeed. So, we've
  7249. * replicated all of that NIC init code here... */
  7250. iwl3945_write32(priv, CSR_INT, 0xFFFFFFFF);
  7251. iwl3945_hw_nic_init(priv);
  7252. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  7253. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  7254. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  7255. iwl3945_write32(priv, CSR_INT, 0xFFFFFFFF);
  7256. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  7257. iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  7258. /* tell the device to stop sending interrupts */
  7259. iwl3945_disable_interrupts(priv);
  7260. spin_lock_irqsave(&priv->lock, flags);
  7261. iwl3945_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  7262. if (!iwl3945_grab_nic_access(priv)) {
  7263. iwl3945_write_prph(priv, APMG_CLK_DIS_REG,
  7264. APMG_CLK_VAL_DMA_CLK_RQT);
  7265. iwl3945_release_nic_access(priv);
  7266. }
  7267. spin_unlock_irqrestore(&priv->lock, flags);
  7268. udelay(5);
  7269. iwl3945_hw_nic_reset(priv);
  7270. /* Bring the device back up */
  7271. clear_bit(STATUS_IN_SUSPEND, &priv->status);
  7272. queue_work(priv->workqueue, &priv->up);
  7273. }
  7274. static int iwl3945_pci_resume(struct pci_dev *pdev)
  7275. {
  7276. struct iwl3945_priv *priv = pci_get_drvdata(pdev);
  7277. int err;
  7278. printk(KERN_INFO "Coming out of suspend...\n");
  7279. pci_set_power_state(pdev, PCI_D0);
  7280. err = pci_enable_device(pdev);
  7281. pci_restore_state(pdev);
  7282. /*
  7283. * Suspend/Resume resets the PCI configuration space, so we have to
  7284. * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
  7285. * from interfering with C3 CPU state. pci_restore_state won't help
  7286. * here since it only restores the first 64 bytes pci config header.
  7287. */
  7288. pci_write_config_byte(pdev, 0x41, 0x00);
  7289. iwl3945_resume(priv);
  7290. return 0;
  7291. }
  7292. #endif /* CONFIG_PM */
  7293. /*****************************************************************************
  7294. *
  7295. * driver and module entry point
  7296. *
  7297. *****************************************************************************/
  7298. static struct pci_driver iwl3945_driver = {
  7299. .name = DRV_NAME,
  7300. .id_table = iwl3945_hw_card_ids,
  7301. .probe = iwl3945_pci_probe,
  7302. .remove = __devexit_p(iwl3945_pci_remove),
  7303. #ifdef CONFIG_PM
  7304. .suspend = iwl3945_pci_suspend,
  7305. .resume = iwl3945_pci_resume,
  7306. #endif
  7307. };
  7308. static int __init iwl3945_init(void)
  7309. {
  7310. int ret;
  7311. printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
  7312. printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
  7313. ret = pci_register_driver(&iwl3945_driver);
  7314. if (ret) {
  7315. IWL_ERROR("Unable to initialize PCI module\n");
  7316. return ret;
  7317. }
  7318. #ifdef CONFIG_IWL3945_DEBUG
  7319. ret = driver_create_file(&iwl3945_driver.driver, &driver_attr_debug_level);
  7320. if (ret) {
  7321. IWL_ERROR("Unable to create driver sysfs file\n");
  7322. pci_unregister_driver(&iwl3945_driver);
  7323. return ret;
  7324. }
  7325. #endif
  7326. return ret;
  7327. }
  7328. static void __exit iwl3945_exit(void)
  7329. {
  7330. #ifdef CONFIG_IWL3945_DEBUG
  7331. driver_remove_file(&iwl3945_driver.driver, &driver_attr_debug_level);
  7332. #endif
  7333. pci_unregister_driver(&iwl3945_driver);
  7334. }
  7335. module_param_named(antenna, iwl3945_param_antenna, int, 0444);
  7336. MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
  7337. module_param_named(disable, iwl3945_param_disable, int, 0444);
  7338. MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
  7339. module_param_named(hwcrypto, iwl3945_param_hwcrypto, int, 0444);
  7340. MODULE_PARM_DESC(hwcrypto,
  7341. "using hardware crypto engine (default 0 [software])\n");
  7342. module_param_named(debug, iwl3945_param_debug, int, 0444);
  7343. MODULE_PARM_DESC(debug, "debug output mask");
  7344. module_param_named(disable_hw_scan, iwl3945_param_disable_hw_scan, int, 0444);
  7345. MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
  7346. module_param_named(queues_num, iwl3945_param_queues_num, int, 0444);
  7347. MODULE_PARM_DESC(queues_num, "number of hw queues.");
  7348. /* QoS */
  7349. module_param_named(qos_enable, iwl3945_param_qos_enable, int, 0444);
  7350. MODULE_PARM_DESC(qos_enable, "enable all QoS functionality");
  7351. module_exit(iwl3945_exit);
  7352. module_init(iwl3945_init);