iwl3945-base.c 233 KB

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