iwl3945-base.c 247 KB

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