iwl3945-base.c 179 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2009 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. * Intel Linux Wireless <ilw@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. #define DRV_NAME "iwl3945"
  46. #include "iwl-fh.h"
  47. #include "iwl-3945-fh.h"
  48. #include "iwl-commands.h"
  49. #include "iwl-3945.h"
  50. #include "iwl-helpers.h"
  51. #include "iwl-core.h"
  52. #include "iwl-dev.h"
  53. /*
  54. * module name, copyright, version, etc.
  55. */
  56. #define DRV_DESCRIPTION \
  57. "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
  58. #ifdef CONFIG_IWLWIFI_DEBUG
  59. #define VD "d"
  60. #else
  61. #define VD
  62. #endif
  63. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  64. #define VS "s"
  65. #else
  66. #define VS
  67. #endif
  68. #define IWL39_VERSION "1.2.26k" VD VS
  69. #define DRV_COPYRIGHT "Copyright(c) 2003-2009 Intel Corporation"
  70. #define DRV_AUTHOR "<ilw@linux.intel.com>"
  71. #define DRV_VERSION IWL39_VERSION
  72. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  73. MODULE_VERSION(DRV_VERSION);
  74. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  75. MODULE_LICENSE("GPL");
  76. /* module parameters */
  77. struct iwl_mod_params iwl3945_mod_params = {
  78. .num_of_queues = IWL39_MAX_NUM_QUEUES,
  79. .sw_crypto = 1,
  80. /* the rest are 0 by default */
  81. };
  82. /*************** STATION TABLE MANAGEMENT ****
  83. * mac80211 should be examined to determine if sta_info is duplicating
  84. * the functionality provided here
  85. */
  86. /**************************************************************/
  87. #if 0 /* temporary disable till we add real remove station */
  88. /**
  89. * iwl3945_remove_station - Remove driver's knowledge of station.
  90. *
  91. * NOTE: This does not remove station from device's station table.
  92. */
  93. static u8 iwl3945_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
  94. {
  95. int index = IWL_INVALID_STATION;
  96. int i;
  97. unsigned long flags;
  98. spin_lock_irqsave(&priv->sta_lock, flags);
  99. if (is_ap)
  100. index = IWL_AP_ID;
  101. else if (is_broadcast_ether_addr(addr))
  102. index = priv->hw_params.bcast_sta_id;
  103. else
  104. for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
  105. if (priv->stations_39[i].used &&
  106. !compare_ether_addr(priv->stations_39[i].sta.sta.addr,
  107. addr)) {
  108. index = i;
  109. break;
  110. }
  111. if (unlikely(index == IWL_INVALID_STATION))
  112. goto out;
  113. if (priv->stations_39[index].used) {
  114. priv->stations_39[index].used = 0;
  115. priv->num_stations--;
  116. }
  117. BUG_ON(priv->num_stations < 0);
  118. out:
  119. spin_unlock_irqrestore(&priv->sta_lock, flags);
  120. return 0;
  121. }
  122. #endif
  123. /**
  124. * iwl3945_clear_stations_table - Clear the driver's station table
  125. *
  126. * NOTE: This does not clear or otherwise alter the device's station table.
  127. */
  128. static void iwl3945_clear_stations_table(struct iwl_priv *priv)
  129. {
  130. unsigned long flags;
  131. spin_lock_irqsave(&priv->sta_lock, flags);
  132. priv->num_stations = 0;
  133. memset(priv->stations_39, 0, sizeof(priv->stations_39));
  134. spin_unlock_irqrestore(&priv->sta_lock, flags);
  135. }
  136. /**
  137. * iwl3945_add_station - Add station to station tables in driver and device
  138. */
  139. u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags)
  140. {
  141. int i;
  142. int index = IWL_INVALID_STATION;
  143. struct iwl3945_station_entry *station;
  144. unsigned long flags_spin;
  145. u8 rate;
  146. spin_lock_irqsave(&priv->sta_lock, flags_spin);
  147. if (is_ap)
  148. index = IWL_AP_ID;
  149. else if (is_broadcast_ether_addr(addr))
  150. index = priv->hw_params.bcast_sta_id;
  151. else
  152. for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
  153. if (!compare_ether_addr(priv->stations_39[i].sta.sta.addr,
  154. addr)) {
  155. index = i;
  156. break;
  157. }
  158. if (!priv->stations_39[i].used &&
  159. index == IWL_INVALID_STATION)
  160. index = i;
  161. }
  162. /* These two conditions has the same outcome but keep them separate
  163. since they have different meaning */
  164. if (unlikely(index == IWL_INVALID_STATION)) {
  165. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  166. return index;
  167. }
  168. if (priv->stations_39[index].used &&
  169. !compare_ether_addr(priv->stations_39[index].sta.sta.addr, addr)) {
  170. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  171. return index;
  172. }
  173. IWL_DEBUG_ASSOC("Add STA ID %d: %pM\n", index, addr);
  174. station = &priv->stations_39[index];
  175. station->used = 1;
  176. priv->num_stations++;
  177. /* Set up the REPLY_ADD_STA command to send to device */
  178. memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd));
  179. memcpy(station->sta.sta.addr, addr, ETH_ALEN);
  180. station->sta.mode = 0;
  181. station->sta.sta.sta_id = index;
  182. station->sta.station_flags = 0;
  183. if (priv->band == IEEE80211_BAND_5GHZ)
  184. rate = IWL_RATE_6M_PLCP;
  185. else
  186. rate = IWL_RATE_1M_PLCP;
  187. /* Turn on both antennas for the station... */
  188. station->sta.rate_n_flags =
  189. iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK);
  190. spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
  191. /* Add station to device's station table */
  192. iwl3945_send_add_station(priv, &station->sta, flags);
  193. return index;
  194. }
  195. int iwl3945_send_statistics_request(struct iwl_priv *priv)
  196. {
  197. u32 val = 0;
  198. struct iwl_host_cmd cmd = {
  199. .id = REPLY_STATISTICS_CMD,
  200. .len = sizeof(val),
  201. .data = &val,
  202. };
  203. return iwl_send_cmd_sync(priv, &cmd);
  204. }
  205. /**
  206. * iwl3945_set_rxon_channel - Set the phymode and channel values in staging RXON
  207. * @band: 2.4 or 5 GHz band
  208. * @channel: Any channel valid for the requested band
  209. * In addition to setting the staging RXON, priv->band is also set.
  210. *
  211. * NOTE: Does not commit to the hardware; it sets appropriate bit fields
  212. * in the staging RXON flag structure based on the band
  213. */
  214. static int iwl3945_set_rxon_channel(struct iwl_priv *priv,
  215. enum ieee80211_band band,
  216. u16 channel)
  217. {
  218. if (!iwl_get_channel_info(priv, band, channel)) {
  219. IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
  220. channel, band);
  221. return -EINVAL;
  222. }
  223. if ((le16_to_cpu(priv->staging39_rxon.channel) == channel) &&
  224. (priv->band == band))
  225. return 0;
  226. priv->staging39_rxon.channel = cpu_to_le16(channel);
  227. if (band == IEEE80211_BAND_5GHZ)
  228. priv->staging39_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
  229. else
  230. priv->staging39_rxon.flags |= RXON_FLG_BAND_24G_MSK;
  231. priv->band = band;
  232. IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, band);
  233. return 0;
  234. }
  235. /**
  236. * iwl3945_check_rxon_cmd - validate RXON structure is valid
  237. *
  238. * NOTE: This is really only useful during development and can eventually
  239. * be #ifdef'd out once the driver is stable and folks aren't actively
  240. * making changes
  241. */
  242. static int iwl3945_check_rxon_cmd(struct iwl_priv *priv)
  243. {
  244. int error = 0;
  245. int counter = 1;
  246. struct iwl3945_rxon_cmd *rxon = &priv->staging39_rxon;
  247. if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
  248. error |= le32_to_cpu(rxon->flags &
  249. (RXON_FLG_TGJ_NARROW_BAND_MSK |
  250. RXON_FLG_RADAR_DETECT_MSK));
  251. if (error)
  252. IWL_WARN(priv, "check 24G fields %d | %d\n",
  253. counter++, error);
  254. } else {
  255. error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
  256. 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
  257. if (error)
  258. IWL_WARN(priv, "check 52 fields %d | %d\n",
  259. counter++, error);
  260. error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
  261. if (error)
  262. IWL_WARN(priv, "check 52 CCK %d | %d\n",
  263. counter++, error);
  264. }
  265. error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
  266. if (error)
  267. IWL_WARN(priv, "check mac addr %d | %d\n", counter++, error);
  268. /* make sure basic rates 6Mbps and 1Mbps are supported */
  269. error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
  270. ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
  271. if (error)
  272. IWL_WARN(priv, "check basic rate %d | %d\n", counter++, error);
  273. error |= (le16_to_cpu(rxon->assoc_id) > 2007);
  274. if (error)
  275. IWL_WARN(priv, "check assoc id %d | %d\n", counter++, error);
  276. error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
  277. == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
  278. if (error)
  279. IWL_WARN(priv, "check CCK and short slot %d | %d\n",
  280. counter++, error);
  281. error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
  282. == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
  283. if (error)
  284. IWL_WARN(priv, "check CCK & auto detect %d | %d\n",
  285. counter++, error);
  286. error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
  287. RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
  288. if (error)
  289. IWL_WARN(priv, "check TGG and auto detect %d | %d\n",
  290. counter++, error);
  291. if ((rxon->flags & RXON_FLG_DIS_DIV_MSK))
  292. error |= ((rxon->flags & (RXON_FLG_ANT_B_MSK |
  293. RXON_FLG_ANT_A_MSK)) == 0);
  294. if (error)
  295. IWL_WARN(priv, "check antenna %d %d\n", counter++, error);
  296. if (error)
  297. IWL_WARN(priv, "Tuning to channel %d\n",
  298. le16_to_cpu(rxon->channel));
  299. if (error) {
  300. IWL_ERR(priv, "Not a valid rxon_assoc_cmd field values\n");
  301. return -1;
  302. }
  303. return 0;
  304. }
  305. /**
  306. * iwl3945_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
  307. * @priv: staging_rxon is compared to active_rxon
  308. *
  309. * If the RXON structure is changing enough to require a new tune,
  310. * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
  311. * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
  312. */
  313. static int iwl3945_full_rxon_required(struct iwl_priv *priv)
  314. {
  315. /* These items are only settable from the full RXON command */
  316. if (!(iwl3945_is_associated(priv)) ||
  317. compare_ether_addr(priv->staging39_rxon.bssid_addr,
  318. priv->active39_rxon.bssid_addr) ||
  319. compare_ether_addr(priv->staging39_rxon.node_addr,
  320. priv->active39_rxon.node_addr) ||
  321. compare_ether_addr(priv->staging39_rxon.wlap_bssid_addr,
  322. priv->active39_rxon.wlap_bssid_addr) ||
  323. (priv->staging39_rxon.dev_type != priv->active39_rxon.dev_type) ||
  324. (priv->staging39_rxon.channel != priv->active39_rxon.channel) ||
  325. (priv->staging39_rxon.air_propagation !=
  326. priv->active39_rxon.air_propagation) ||
  327. (priv->staging39_rxon.assoc_id != priv->active39_rxon.assoc_id))
  328. return 1;
  329. /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
  330. * be updated with the RXON_ASSOC command -- however only some
  331. * flag transitions are allowed using RXON_ASSOC */
  332. /* Check if we are not switching bands */
  333. if ((priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
  334. (priv->active39_rxon.flags & RXON_FLG_BAND_24G_MSK))
  335. return 1;
  336. /* Check if we are switching association toggle */
  337. if ((priv->staging39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
  338. (priv->active39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
  339. return 1;
  340. return 0;
  341. }
  342. static int iwl3945_send_rxon_assoc(struct iwl_priv *priv)
  343. {
  344. int rc = 0;
  345. struct iwl_rx_packet *res = NULL;
  346. struct iwl3945_rxon_assoc_cmd rxon_assoc;
  347. struct iwl_host_cmd cmd = {
  348. .id = REPLY_RXON_ASSOC,
  349. .len = sizeof(rxon_assoc),
  350. .meta.flags = CMD_WANT_SKB,
  351. .data = &rxon_assoc,
  352. };
  353. const struct iwl3945_rxon_cmd *rxon1 = &priv->staging39_rxon;
  354. const struct iwl3945_rxon_cmd *rxon2 = &priv->active39_rxon;
  355. if ((rxon1->flags == rxon2->flags) &&
  356. (rxon1->filter_flags == rxon2->filter_flags) &&
  357. (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
  358. (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
  359. IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
  360. return 0;
  361. }
  362. rxon_assoc.flags = priv->staging39_rxon.flags;
  363. rxon_assoc.filter_flags = priv->staging39_rxon.filter_flags;
  364. rxon_assoc.ofdm_basic_rates = priv->staging39_rxon.ofdm_basic_rates;
  365. rxon_assoc.cck_basic_rates = priv->staging39_rxon.cck_basic_rates;
  366. rxon_assoc.reserved = 0;
  367. rc = iwl_send_cmd_sync(priv, &cmd);
  368. if (rc)
  369. return rc;
  370. res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
  371. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  372. IWL_ERR(priv, "Bad return from REPLY_RXON_ASSOC command\n");
  373. rc = -EIO;
  374. }
  375. priv->alloc_rxb_skb--;
  376. dev_kfree_skb_any(cmd.meta.u.skb);
  377. return rc;
  378. }
  379. /**
  380. * iwl3945_commit_rxon - commit staging_rxon to hardware
  381. *
  382. * The RXON command in staging_rxon is committed to the hardware and
  383. * the active_rxon structure is updated with the new data. This
  384. * function correctly transitions out of the RXON_ASSOC_MSK state if
  385. * a HW tune is required based on the RXON structure changes.
  386. */
  387. static int iwl3945_commit_rxon(struct iwl_priv *priv)
  388. {
  389. /* cast away the const for active_rxon in this function */
  390. struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active39_rxon;
  391. int rc = 0;
  392. if (!iwl_is_alive(priv))
  393. return -1;
  394. /* always get timestamp with Rx frame */
  395. priv->staging39_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
  396. /* select antenna */
  397. priv->staging39_rxon.flags &=
  398. ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
  399. priv->staging39_rxon.flags |= iwl3945_get_antenna_flags(priv);
  400. rc = iwl3945_check_rxon_cmd(priv);
  401. if (rc) {
  402. IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
  403. return -EINVAL;
  404. }
  405. /* If we don't need to send a full RXON, we can use
  406. * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
  407. * and other flags for the current radio configuration. */
  408. if (!iwl3945_full_rxon_required(priv)) {
  409. rc = iwl3945_send_rxon_assoc(priv);
  410. if (rc) {
  411. IWL_ERR(priv, "Error setting RXON_ASSOC "
  412. "configuration (%d).\n", rc);
  413. return rc;
  414. }
  415. memcpy(active_rxon, &priv->staging39_rxon, sizeof(*active_rxon));
  416. return 0;
  417. }
  418. /* If we are currently associated and the new config requires
  419. * an RXON_ASSOC and the new config wants the associated mask enabled,
  420. * we must clear the associated from the active configuration
  421. * before we apply the new config */
  422. if (iwl3945_is_associated(priv) &&
  423. (priv->staging39_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) {
  424. IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
  425. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  426. rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
  427. sizeof(struct iwl3945_rxon_cmd),
  428. &priv->active39_rxon);
  429. /* If the mask clearing failed then we set
  430. * active_rxon back to what it was previously */
  431. if (rc) {
  432. active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
  433. IWL_ERR(priv, "Error clearing ASSOC_MSK on current "
  434. "configuration (%d).\n", rc);
  435. return rc;
  436. }
  437. }
  438. IWL_DEBUG_INFO("Sending RXON\n"
  439. "* with%s RXON_FILTER_ASSOC_MSK\n"
  440. "* channel = %d\n"
  441. "* bssid = %pM\n",
  442. ((priv->staging39_rxon.filter_flags &
  443. RXON_FILTER_ASSOC_MSK) ? "" : "out"),
  444. le16_to_cpu(priv->staging39_rxon.channel),
  445. priv->staging_rxon.bssid_addr);
  446. /* Apply the new configuration */
  447. rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
  448. sizeof(struct iwl3945_rxon_cmd), &priv->staging39_rxon);
  449. if (rc) {
  450. IWL_ERR(priv, "Error setting new configuration (%d).\n", rc);
  451. return rc;
  452. }
  453. memcpy(active_rxon, &priv->staging39_rxon, sizeof(*active_rxon));
  454. iwl3945_clear_stations_table(priv);
  455. /* If we issue a new RXON command which required a tune then we must
  456. * send a new TXPOWER command or we won't be able to Tx any frames */
  457. rc = priv->cfg->ops->lib->send_tx_power(priv);
  458. if (rc) {
  459. IWL_ERR(priv, "Error setting Tx power (%d).\n", rc);
  460. return rc;
  461. }
  462. /* Add the broadcast address so we can send broadcast frames */
  463. if (iwl3945_add_station(priv, iwl_bcast_addr, 0, 0) ==
  464. IWL_INVALID_STATION) {
  465. IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
  466. return -EIO;
  467. }
  468. /* If we have set the ASSOC_MSK and we are in BSS mode then
  469. * add the IWL_AP_ID to the station rate table */
  470. if (iwl3945_is_associated(priv) &&
  471. (priv->iw_mode == NL80211_IFTYPE_STATION))
  472. if (iwl3945_add_station(priv, priv->active39_rxon.bssid_addr, 1, 0)
  473. == IWL_INVALID_STATION) {
  474. IWL_ERR(priv, "Error adding AP address for transmit\n");
  475. return -EIO;
  476. }
  477. /* Init the hardware's rate fallback order based on the band */
  478. rc = iwl3945_init_hw_rate_table(priv);
  479. if (rc) {
  480. IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc);
  481. return -EIO;
  482. }
  483. return 0;
  484. }
  485. static int iwl3945_send_bt_config(struct iwl_priv *priv)
  486. {
  487. struct iwl_bt_cmd bt_cmd = {
  488. .flags = 3,
  489. .lead_time = 0xAA,
  490. .max_kill = 1,
  491. .kill_ack_mask = 0,
  492. .kill_cts_mask = 0,
  493. };
  494. return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  495. sizeof(bt_cmd), &bt_cmd);
  496. }
  497. static int iwl3945_add_sta_sync_callback(struct iwl_priv *priv,
  498. struct iwl_cmd *cmd, struct sk_buff *skb)
  499. {
  500. struct iwl_rx_packet *res = NULL;
  501. if (!skb) {
  502. IWL_ERR(priv, "Error: Response NULL in REPLY_ADD_STA.\n");
  503. return 1;
  504. }
  505. res = (struct iwl_rx_packet *)skb->data;
  506. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  507. IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n",
  508. res->hdr.flags);
  509. return 1;
  510. }
  511. switch (res->u.add_sta.status) {
  512. case ADD_STA_SUCCESS_MSK:
  513. break;
  514. default:
  515. break;
  516. }
  517. /* We didn't cache the SKB; let the caller free it */
  518. return 1;
  519. }
  520. int iwl3945_send_add_station(struct iwl_priv *priv,
  521. struct iwl3945_addsta_cmd *sta, u8 flags)
  522. {
  523. struct iwl_rx_packet *res = NULL;
  524. int rc = 0;
  525. struct iwl_host_cmd cmd = {
  526. .id = REPLY_ADD_STA,
  527. .len = sizeof(struct iwl3945_addsta_cmd),
  528. .meta.flags = flags,
  529. .data = sta,
  530. };
  531. if (flags & CMD_ASYNC)
  532. cmd.meta.u.callback = iwl3945_add_sta_sync_callback;
  533. else
  534. cmd.meta.flags |= CMD_WANT_SKB;
  535. rc = iwl_send_cmd(priv, &cmd);
  536. if (rc || (flags & CMD_ASYNC))
  537. return rc;
  538. res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
  539. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  540. IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n",
  541. res->hdr.flags);
  542. rc = -EIO;
  543. }
  544. if (rc == 0) {
  545. switch (res->u.add_sta.status) {
  546. case ADD_STA_SUCCESS_MSK:
  547. IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
  548. break;
  549. default:
  550. rc = -EIO;
  551. IWL_WARN(priv, "REPLY_ADD_STA failed\n");
  552. break;
  553. }
  554. }
  555. priv->alloc_rxb_skb--;
  556. dev_kfree_skb_any(cmd.meta.u.skb);
  557. return rc;
  558. }
  559. static int iwl3945_update_sta_key_info(struct iwl_priv *priv,
  560. struct ieee80211_key_conf *keyconf,
  561. u8 sta_id)
  562. {
  563. unsigned long flags;
  564. __le16 key_flags = 0;
  565. switch (keyconf->alg) {
  566. case ALG_CCMP:
  567. key_flags |= STA_KEY_FLG_CCMP;
  568. key_flags |= cpu_to_le16(
  569. keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  570. key_flags &= ~STA_KEY_FLG_INVALID;
  571. break;
  572. case ALG_TKIP:
  573. case ALG_WEP:
  574. default:
  575. return -EINVAL;
  576. }
  577. spin_lock_irqsave(&priv->sta_lock, flags);
  578. priv->stations_39[sta_id].keyinfo.alg = keyconf->alg;
  579. priv->stations_39[sta_id].keyinfo.keylen = keyconf->keylen;
  580. memcpy(priv->stations_39[sta_id].keyinfo.key, keyconf->key,
  581. keyconf->keylen);
  582. memcpy(priv->stations_39[sta_id].sta.key.key, keyconf->key,
  583. keyconf->keylen);
  584. priv->stations_39[sta_id].sta.key.key_flags = key_flags;
  585. priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  586. priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  587. spin_unlock_irqrestore(&priv->sta_lock, flags);
  588. IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
  589. iwl3945_send_add_station(priv, &priv->stations_39[sta_id].sta, 0);
  590. return 0;
  591. }
  592. static int iwl3945_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
  593. {
  594. unsigned long flags;
  595. spin_lock_irqsave(&priv->sta_lock, flags);
  596. memset(&priv->stations_39[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key));
  597. memset(&priv->stations_39[sta_id].sta.key, 0,
  598. sizeof(struct iwl4965_keyinfo));
  599. priv->stations_39[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
  600. priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  601. priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  602. spin_unlock_irqrestore(&priv->sta_lock, flags);
  603. IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
  604. iwl3945_send_add_station(priv, &priv->stations_39[sta_id].sta, 0);
  605. return 0;
  606. }
  607. static void iwl3945_clear_free_frames(struct iwl_priv *priv)
  608. {
  609. struct list_head *element;
  610. IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
  611. priv->frames_count);
  612. while (!list_empty(&priv->free_frames)) {
  613. element = priv->free_frames.next;
  614. list_del(element);
  615. kfree(list_entry(element, struct iwl3945_frame, list));
  616. priv->frames_count--;
  617. }
  618. if (priv->frames_count) {
  619. IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
  620. priv->frames_count);
  621. priv->frames_count = 0;
  622. }
  623. }
  624. static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv)
  625. {
  626. struct iwl3945_frame *frame;
  627. struct list_head *element;
  628. if (list_empty(&priv->free_frames)) {
  629. frame = kzalloc(sizeof(*frame), GFP_KERNEL);
  630. if (!frame) {
  631. IWL_ERR(priv, "Could not allocate frame!\n");
  632. return NULL;
  633. }
  634. priv->frames_count++;
  635. return frame;
  636. }
  637. element = priv->free_frames.next;
  638. list_del(element);
  639. return list_entry(element, struct iwl3945_frame, list);
  640. }
  641. static void iwl3945_free_frame(struct iwl_priv *priv, struct iwl3945_frame *frame)
  642. {
  643. memset(frame, 0, sizeof(*frame));
  644. list_add(&frame->list, &priv->free_frames);
  645. }
  646. unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv,
  647. struct ieee80211_hdr *hdr,
  648. int left)
  649. {
  650. if (!iwl3945_is_associated(priv) || !priv->ibss_beacon ||
  651. ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
  652. (priv->iw_mode != NL80211_IFTYPE_AP)))
  653. return 0;
  654. if (priv->ibss_beacon->len > left)
  655. return 0;
  656. memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
  657. return priv->ibss_beacon->len;
  658. }
  659. static u8 iwl3945_rate_get_lowest_plcp(struct iwl_priv *priv)
  660. {
  661. u8 i;
  662. int rate_mask;
  663. /* Set rate mask*/
  664. if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK)
  665. rate_mask = priv->active_rate_basic & IWL_CCK_RATES_MASK;
  666. else
  667. rate_mask = priv->active_rate_basic & IWL_OFDM_RATES_MASK;
  668. for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
  669. i = iwl3945_rates[i].next_ieee) {
  670. if (rate_mask & (1 << i))
  671. return iwl3945_rates[i].plcp;
  672. }
  673. /* No valid rate was found. Assign the lowest one */
  674. if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK)
  675. return IWL_RATE_1M_PLCP;
  676. else
  677. return IWL_RATE_6M_PLCP;
  678. }
  679. static int iwl3945_send_beacon_cmd(struct iwl_priv *priv)
  680. {
  681. struct iwl3945_frame *frame;
  682. unsigned int frame_size;
  683. int rc;
  684. u8 rate;
  685. frame = iwl3945_get_free_frame(priv);
  686. if (!frame) {
  687. IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
  688. "command.\n");
  689. return -ENOMEM;
  690. }
  691. rate = iwl3945_rate_get_lowest_plcp(priv);
  692. frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
  693. rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
  694. &frame->u.cmd[0]);
  695. iwl3945_free_frame(priv, frame);
  696. return rc;
  697. }
  698. static void iwl3945_unset_hw_params(struct iwl_priv *priv)
  699. {
  700. if (priv->shared_virt)
  701. pci_free_consistent(priv->pci_dev,
  702. sizeof(struct iwl3945_shared),
  703. priv->shared_virt,
  704. priv->shared_phys);
  705. }
  706. /*
  707. * QoS support
  708. */
  709. static int iwl3945_send_qos_params_command(struct iwl_priv *priv,
  710. struct iwl_qosparam_cmd *qos)
  711. {
  712. return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM,
  713. sizeof(struct iwl_qosparam_cmd), qos);
  714. }
  715. static void iwl3945_activate_qos(struct iwl_priv *priv, u8 force)
  716. {
  717. unsigned long flags;
  718. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  719. return;
  720. spin_lock_irqsave(&priv->lock, flags);
  721. priv->qos_data.def_qos_parm.qos_flags = 0;
  722. if (priv->qos_data.qos_cap.q_AP.queue_request &&
  723. !priv->qos_data.qos_cap.q_AP.txop_request)
  724. priv->qos_data.def_qos_parm.qos_flags |=
  725. QOS_PARAM_FLG_TXOP_TYPE_MSK;
  726. if (priv->qos_data.qos_active)
  727. priv->qos_data.def_qos_parm.qos_flags |=
  728. QOS_PARAM_FLG_UPDATE_EDCA_MSK;
  729. spin_unlock_irqrestore(&priv->lock, flags);
  730. if (force || iwl3945_is_associated(priv)) {
  731. IWL_DEBUG_QOS("send QoS cmd with QoS active %d \n",
  732. priv->qos_data.qos_active);
  733. iwl3945_send_qos_params_command(priv,
  734. &(priv->qos_data.def_qos_parm));
  735. }
  736. }
  737. /*
  738. * Power management (not Tx power!) functions
  739. */
  740. #define MSEC_TO_USEC 1024
  741. /* default power management (not Tx power) table values */
  742. /* for TIM 0-10 */
  743. static struct iwl_power_vec_entry range_0[IWL_POWER_MAX] = {
  744. {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
  745. {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
  746. {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
  747. {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
  748. {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
  749. {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
  750. };
  751. /* for TIM > 10 */
  752. static struct iwl_power_vec_entry range_1[IWL_POWER_MAX] = {
  753. {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
  754. {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
  755. {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
  756. {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
  757. {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
  758. {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
  759. };
  760. int iwl3945_power_init_handle(struct iwl_priv *priv)
  761. {
  762. int rc = 0, i;
  763. struct iwl_power_mgr *pow_data;
  764. int size = sizeof(struct iwl_power_vec_entry) * IWL_POWER_MAX;
  765. u16 pci_pm;
  766. IWL_DEBUG_POWER("Initialize power \n");
  767. pow_data = &priv->power_data;
  768. memset(pow_data, 0, sizeof(*pow_data));
  769. pow_data->dtim_period = 1;
  770. memcpy(&pow_data->pwr_range_0[0], &range_0[0], size);
  771. memcpy(&pow_data->pwr_range_1[0], &range_1[0], size);
  772. rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm);
  773. if (rc != 0)
  774. return 0;
  775. else {
  776. struct iwl_powertable_cmd *cmd;
  777. IWL_DEBUG_POWER("adjust power command flags\n");
  778. for (i = 0; i < IWL_POWER_MAX; i++) {
  779. cmd = &pow_data->pwr_range_0[i].cmd;
  780. if (pci_pm & 0x1)
  781. cmd->flags &= ~IWL_POWER_PCI_PM_MSK;
  782. else
  783. cmd->flags |= IWL_POWER_PCI_PM_MSK;
  784. }
  785. }
  786. return rc;
  787. }
  788. static int iwl3945_update_power_cmd(struct iwl_priv *priv,
  789. struct iwl_powertable_cmd *cmd, u32 mode)
  790. {
  791. struct iwl_power_mgr *pow_data;
  792. struct iwl_power_vec_entry *range;
  793. u32 max_sleep = 0;
  794. int i;
  795. u8 period = 0;
  796. bool skip;
  797. if (mode > IWL_POWER_INDEX_5) {
  798. IWL_DEBUG_POWER("Error invalid power mode \n");
  799. return -EINVAL;
  800. }
  801. pow_data = &priv->power_data;
  802. if (pow_data->dtim_period < 10)
  803. range = &pow_data->pwr_range_0[0];
  804. else
  805. range = &pow_data->pwr_range_1[1];
  806. memcpy(cmd, &range[mode].cmd, sizeof(struct iwl3945_powertable_cmd));
  807. if (period == 0) {
  808. period = 1;
  809. skip = false;
  810. } else {
  811. skip = !!range[mode].no_dtim;
  812. }
  813. if (skip) {
  814. __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1];
  815. max_sleep = (le32_to_cpu(slp_itrvl) / period) * period;
  816. cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK;
  817. } else {
  818. max_sleep = period;
  819. cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK;
  820. }
  821. for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
  822. if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep)
  823. cmd->sleep_interval[i] = cpu_to_le32(max_sleep);
  824. IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags);
  825. IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout));
  826. IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout));
  827. IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
  828. le32_to_cpu(cmd->sleep_interval[0]),
  829. le32_to_cpu(cmd->sleep_interval[1]),
  830. le32_to_cpu(cmd->sleep_interval[2]),
  831. le32_to_cpu(cmd->sleep_interval[3]),
  832. le32_to_cpu(cmd->sleep_interval[4]));
  833. return 0;
  834. }
  835. static int iwl3945_send_power_mode(struct iwl_priv *priv, u32 mode)
  836. {
  837. u32 uninitialized_var(final_mode);
  838. int rc;
  839. struct iwl_powertable_cmd cmd;
  840. /* If on battery, set to 3,
  841. * if plugged into AC power, set to CAM ("continuously aware mode"),
  842. * else user level */
  843. switch (mode) {
  844. case IWL39_POWER_BATTERY:
  845. final_mode = IWL_POWER_INDEX_3;
  846. break;
  847. case IWL39_POWER_AC:
  848. final_mode = IWL_POWER_MODE_CAM;
  849. break;
  850. default:
  851. final_mode = mode;
  852. break;
  853. }
  854. iwl3945_update_power_cmd(priv, &cmd, final_mode);
  855. /* FIXME use get_hcmd_size 3945 command is 4 bytes shorter */
  856. rc = iwl_send_cmd_pdu(priv, POWER_TABLE_CMD,
  857. sizeof(struct iwl3945_powertable_cmd), &cmd);
  858. if (final_mode == IWL_POWER_MODE_CAM)
  859. clear_bit(STATUS_POWER_PMI, &priv->status);
  860. else
  861. set_bit(STATUS_POWER_PMI, &priv->status);
  862. return rc;
  863. }
  864. #define MAX_UCODE_BEACON_INTERVAL 1024
  865. #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
  866. static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val)
  867. {
  868. u16 new_val = 0;
  869. u16 beacon_factor = 0;
  870. beacon_factor =
  871. (beacon_val + MAX_UCODE_BEACON_INTERVAL)
  872. / MAX_UCODE_BEACON_INTERVAL;
  873. new_val = beacon_val / beacon_factor;
  874. return cpu_to_le16(new_val);
  875. }
  876. static void iwl3945_setup_rxon_timing(struct iwl_priv *priv)
  877. {
  878. u64 interval_tm_unit;
  879. u64 tsf, result;
  880. unsigned long flags;
  881. struct ieee80211_conf *conf = NULL;
  882. u16 beacon_int = 0;
  883. conf = ieee80211_get_hw_conf(priv->hw);
  884. spin_lock_irqsave(&priv->lock, flags);
  885. priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
  886. priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
  887. tsf = priv->timestamp;
  888. beacon_int = priv->beacon_int;
  889. spin_unlock_irqrestore(&priv->lock, flags);
  890. if (priv->iw_mode == NL80211_IFTYPE_STATION) {
  891. if (beacon_int == 0) {
  892. priv->rxon_timing.beacon_interval = cpu_to_le16(100);
  893. priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
  894. } else {
  895. priv->rxon_timing.beacon_interval =
  896. cpu_to_le16(beacon_int);
  897. priv->rxon_timing.beacon_interval =
  898. iwl3945_adjust_beacon_interval(
  899. le16_to_cpu(priv->rxon_timing.beacon_interval));
  900. }
  901. priv->rxon_timing.atim_window = 0;
  902. } else {
  903. priv->rxon_timing.beacon_interval =
  904. iwl3945_adjust_beacon_interval(conf->beacon_int);
  905. /* TODO: we need to get atim_window from upper stack
  906. * for now we set to 0 */
  907. priv->rxon_timing.atim_window = 0;
  908. }
  909. interval_tm_unit =
  910. (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
  911. result = do_div(tsf, interval_tm_unit);
  912. priv->rxon_timing.beacon_init_val =
  913. cpu_to_le32((u32) ((u64) interval_tm_unit - result));
  914. IWL_DEBUG_ASSOC
  915. ("beacon interval %d beacon timer %d beacon tim %d\n",
  916. le16_to_cpu(priv->rxon_timing.beacon_interval),
  917. le32_to_cpu(priv->rxon_timing.beacon_init_val),
  918. le16_to_cpu(priv->rxon_timing.atim_window));
  919. }
  920. static int iwl3945_scan_initiate(struct iwl_priv *priv)
  921. {
  922. if (!iwl_is_ready_rf(priv)) {
  923. IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
  924. return -EIO;
  925. }
  926. if (test_bit(STATUS_SCANNING, &priv->status)) {
  927. IWL_DEBUG_SCAN("Scan already in progress.\n");
  928. return -EAGAIN;
  929. }
  930. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  931. IWL_DEBUG_SCAN("Scan request while abort pending. "
  932. "Queuing.\n");
  933. return -EAGAIN;
  934. }
  935. IWL_DEBUG_INFO("Starting scan...\n");
  936. if (priv->cfg->sku & IWL_SKU_G)
  937. priv->scan_bands |= BIT(IEEE80211_BAND_2GHZ);
  938. if (priv->cfg->sku & IWL_SKU_A)
  939. priv->scan_bands |= BIT(IEEE80211_BAND_5GHZ);
  940. set_bit(STATUS_SCANNING, &priv->status);
  941. priv->scan_start = jiffies;
  942. priv->scan_pass_start = priv->scan_start;
  943. queue_work(priv->workqueue, &priv->request_scan);
  944. return 0;
  945. }
  946. static int iwl3945_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
  947. {
  948. struct iwl3945_rxon_cmd *rxon = &priv->staging39_rxon;
  949. if (hw_decrypt)
  950. rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
  951. else
  952. rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
  953. return 0;
  954. }
  955. static void iwl3945_set_flags_for_phymode(struct iwl_priv *priv,
  956. enum ieee80211_band band)
  957. {
  958. if (band == IEEE80211_BAND_5GHZ) {
  959. priv->staging39_rxon.flags &=
  960. ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
  961. | RXON_FLG_CCK_MSK);
  962. priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  963. } else {
  964. /* Copied from iwl3945_bg_post_associate() */
  965. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
  966. priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  967. else
  968. priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  969. if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
  970. priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  971. priv->staging39_rxon.flags |= RXON_FLG_BAND_24G_MSK;
  972. priv->staging39_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
  973. priv->staging39_rxon.flags &= ~RXON_FLG_CCK_MSK;
  974. }
  975. }
  976. /*
  977. * initialize rxon structure with default values from eeprom
  978. */
  979. static void iwl3945_connection_init_rx_config(struct iwl_priv *priv,
  980. int mode)
  981. {
  982. const struct iwl_channel_info *ch_info;
  983. memset(&priv->staging39_rxon, 0, sizeof(priv->staging39_rxon));
  984. switch (mode) {
  985. case NL80211_IFTYPE_AP:
  986. priv->staging39_rxon.dev_type = RXON_DEV_TYPE_AP;
  987. break;
  988. case NL80211_IFTYPE_STATION:
  989. priv->staging39_rxon.dev_type = RXON_DEV_TYPE_ESS;
  990. priv->staging39_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
  991. break;
  992. case NL80211_IFTYPE_ADHOC:
  993. priv->staging39_rxon.dev_type = RXON_DEV_TYPE_IBSS;
  994. priv->staging39_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
  995. priv->staging39_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
  996. RXON_FILTER_ACCEPT_GRP_MSK;
  997. break;
  998. case NL80211_IFTYPE_MONITOR:
  999. priv->staging39_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
  1000. priv->staging39_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
  1001. RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
  1002. break;
  1003. default:
  1004. IWL_ERR(priv, "Unsupported interface type %d\n", mode);
  1005. break;
  1006. }
  1007. #if 0
  1008. /* TODO: Figure out when short_preamble would be set and cache from
  1009. * that */
  1010. if (!hw_to_local(priv->hw)->short_preamble)
  1011. priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  1012. else
  1013. priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  1014. #endif
  1015. ch_info = iwl_get_channel_info(priv, priv->band,
  1016. le16_to_cpu(priv->active39_rxon.channel));
  1017. if (!ch_info)
  1018. ch_info = &priv->channel_info[0];
  1019. /*
  1020. * in some case A channels are all non IBSS
  1021. * in this case force B/G channel
  1022. */
  1023. if ((mode == NL80211_IFTYPE_ADHOC) && !(is_channel_ibss(ch_info)))
  1024. ch_info = &priv->channel_info[0];
  1025. priv->staging39_rxon.channel = cpu_to_le16(ch_info->channel);
  1026. if (is_channel_a_band(ch_info))
  1027. priv->band = IEEE80211_BAND_5GHZ;
  1028. else
  1029. priv->band = IEEE80211_BAND_2GHZ;
  1030. iwl3945_set_flags_for_phymode(priv, priv->band);
  1031. priv->staging39_rxon.ofdm_basic_rates =
  1032. (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  1033. priv->staging39_rxon.cck_basic_rates =
  1034. (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  1035. }
  1036. static int iwl3945_set_mode(struct iwl_priv *priv, int mode)
  1037. {
  1038. if (mode == NL80211_IFTYPE_ADHOC) {
  1039. const struct iwl_channel_info *ch_info;
  1040. ch_info = iwl_get_channel_info(priv,
  1041. priv->band,
  1042. le16_to_cpu(priv->staging39_rxon.channel));
  1043. if (!ch_info || !is_channel_ibss(ch_info)) {
  1044. IWL_ERR(priv, "channel %d not IBSS channel\n",
  1045. le16_to_cpu(priv->staging39_rxon.channel));
  1046. return -EINVAL;
  1047. }
  1048. }
  1049. iwl3945_connection_init_rx_config(priv, mode);
  1050. memcpy(priv->staging39_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  1051. iwl3945_clear_stations_table(priv);
  1052. /* don't commit rxon if rf-kill is on*/
  1053. if (!iwl_is_ready_rf(priv))
  1054. return -EAGAIN;
  1055. cancel_delayed_work(&priv->scan_check);
  1056. if (iwl_scan_cancel_timeout(priv, 100)) {
  1057. IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
  1058. IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
  1059. return -EAGAIN;
  1060. }
  1061. iwl3945_commit_rxon(priv);
  1062. return 0;
  1063. }
  1064. static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
  1065. struct ieee80211_tx_info *info,
  1066. struct iwl_cmd *cmd,
  1067. struct sk_buff *skb_frag,
  1068. int last_frag)
  1069. {
  1070. struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
  1071. struct iwl3945_hw_key *keyinfo =
  1072. &priv->stations_39[info->control.hw_key->hw_key_idx].keyinfo;
  1073. switch (keyinfo->alg) {
  1074. case ALG_CCMP:
  1075. tx->sec_ctl = TX_CMD_SEC_CCM;
  1076. memcpy(tx->key, keyinfo->key, keyinfo->keylen);
  1077. IWL_DEBUG_TX("tx_cmd with AES hwcrypto\n");
  1078. break;
  1079. case ALG_TKIP:
  1080. #if 0
  1081. tx->sec_ctl = TX_CMD_SEC_TKIP;
  1082. if (last_frag)
  1083. memcpy(tx->tkip_mic.byte, skb_frag->tail - 8,
  1084. 8);
  1085. else
  1086. memset(tx->tkip_mic.byte, 0, 8);
  1087. #endif
  1088. break;
  1089. case ALG_WEP:
  1090. tx->sec_ctl = TX_CMD_SEC_WEP |
  1091. (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
  1092. if (keyinfo->keylen == 13)
  1093. tx->sec_ctl |= TX_CMD_SEC_KEY128;
  1094. memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen);
  1095. IWL_DEBUG_TX("Configuring packet for WEP encryption "
  1096. "with key %d\n", info->control.hw_key->hw_key_idx);
  1097. break;
  1098. default:
  1099. IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg);
  1100. break;
  1101. }
  1102. }
  1103. /*
  1104. * handle build REPLY_TX command notification.
  1105. */
  1106. static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
  1107. struct iwl_cmd *cmd,
  1108. struct ieee80211_tx_info *info,
  1109. struct ieee80211_hdr *hdr, u8 std_id)
  1110. {
  1111. struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
  1112. __le32 tx_flags = tx->tx_flags;
  1113. __le16 fc = hdr->frame_control;
  1114. u8 rc_flags = info->control.rates[0].flags;
  1115. tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  1116. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
  1117. tx_flags |= TX_CMD_FLG_ACK_MSK;
  1118. if (ieee80211_is_mgmt(fc))
  1119. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  1120. if (ieee80211_is_probe_resp(fc) &&
  1121. !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
  1122. tx_flags |= TX_CMD_FLG_TSF_MSK;
  1123. } else {
  1124. tx_flags &= (~TX_CMD_FLG_ACK_MSK);
  1125. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  1126. }
  1127. tx->sta_id = std_id;
  1128. if (ieee80211_has_morefrags(fc))
  1129. tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
  1130. if (ieee80211_is_data_qos(fc)) {
  1131. u8 *qc = ieee80211_get_qos_ctl(hdr);
  1132. tx->tid_tspec = qc[0] & 0xf;
  1133. tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
  1134. } else {
  1135. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  1136. }
  1137. if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
  1138. tx_flags |= TX_CMD_FLG_RTS_MSK;
  1139. tx_flags &= ~TX_CMD_FLG_CTS_MSK;
  1140. } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
  1141. tx_flags &= ~TX_CMD_FLG_RTS_MSK;
  1142. tx_flags |= TX_CMD_FLG_CTS_MSK;
  1143. }
  1144. if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
  1145. tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
  1146. tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
  1147. if (ieee80211_is_mgmt(fc)) {
  1148. if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
  1149. tx->timeout.pm_frame_timeout = cpu_to_le16(3);
  1150. else
  1151. tx->timeout.pm_frame_timeout = cpu_to_le16(2);
  1152. } else {
  1153. tx->timeout.pm_frame_timeout = 0;
  1154. #ifdef CONFIG_IWL3945_LEDS
  1155. priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
  1156. #endif
  1157. }
  1158. tx->driver_txop = 0;
  1159. tx->tx_flags = tx_flags;
  1160. tx->next_frame_len = 0;
  1161. }
  1162. /**
  1163. * iwl3945_get_sta_id - Find station's index within station table
  1164. */
  1165. static int iwl3945_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
  1166. {
  1167. int sta_id;
  1168. u16 fc = le16_to_cpu(hdr->frame_control);
  1169. /* If this frame is broadcast or management, use broadcast station id */
  1170. if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
  1171. is_multicast_ether_addr(hdr->addr1))
  1172. return priv->hw_params.bcast_sta_id;
  1173. switch (priv->iw_mode) {
  1174. /* If we are a client station in a BSS network, use the special
  1175. * AP station entry (that's the only station we communicate with) */
  1176. case NL80211_IFTYPE_STATION:
  1177. return IWL_AP_ID;
  1178. /* If we are an AP, then find the station, or use BCAST */
  1179. case NL80211_IFTYPE_AP:
  1180. sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
  1181. if (sta_id != IWL_INVALID_STATION)
  1182. return sta_id;
  1183. return priv->hw_params.bcast_sta_id;
  1184. /* If this frame is going out to an IBSS network, find the station,
  1185. * or create a new station table entry */
  1186. case NL80211_IFTYPE_ADHOC: {
  1187. /* Create new station table entry */
  1188. sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
  1189. if (sta_id != IWL_INVALID_STATION)
  1190. return sta_id;
  1191. sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
  1192. if (sta_id != IWL_INVALID_STATION)
  1193. return sta_id;
  1194. IWL_DEBUG_DROP("Station %pM not in station map. "
  1195. "Defaulting to broadcast...\n",
  1196. hdr->addr1);
  1197. iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
  1198. return priv->hw_params.bcast_sta_id;
  1199. }
  1200. /* If we are in monitor mode, use BCAST. This is required for
  1201. * packet injection. */
  1202. case NL80211_IFTYPE_MONITOR:
  1203. return priv->hw_params.bcast_sta_id;
  1204. default:
  1205. IWL_WARN(priv, "Unknown mode of operation: %d\n",
  1206. priv->iw_mode);
  1207. return priv->hw_params.bcast_sta_id;
  1208. }
  1209. }
  1210. /*
  1211. * start REPLY_TX command process
  1212. */
  1213. static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
  1214. {
  1215. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1216. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1217. struct iwl3945_tx_cmd *tx;
  1218. struct iwl_tx_queue *txq = NULL;
  1219. struct iwl_queue *q = NULL;
  1220. struct iwl_cmd *out_cmd = NULL;
  1221. dma_addr_t phys_addr;
  1222. dma_addr_t txcmd_phys;
  1223. int txq_id = skb_get_queue_mapping(skb);
  1224. u16 len, idx, len_org, hdr_len;
  1225. u8 id;
  1226. u8 unicast;
  1227. u8 sta_id;
  1228. u8 tid = 0;
  1229. u16 seq_number = 0;
  1230. __le16 fc;
  1231. u8 wait_write_ptr = 0;
  1232. u8 *qc = NULL;
  1233. unsigned long flags;
  1234. int rc;
  1235. spin_lock_irqsave(&priv->lock, flags);
  1236. if (iwl_is_rfkill(priv)) {
  1237. IWL_DEBUG_DROP("Dropping - RF KILL\n");
  1238. goto drop_unlock;
  1239. }
  1240. if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
  1241. IWL_ERR(priv, "ERROR: No TX rate available.\n");
  1242. goto drop_unlock;
  1243. }
  1244. unicast = !is_multicast_ether_addr(hdr->addr1);
  1245. id = 0;
  1246. fc = hdr->frame_control;
  1247. #ifdef CONFIG_IWLWIFI_DEBUG
  1248. if (ieee80211_is_auth(fc))
  1249. IWL_DEBUG_TX("Sending AUTH frame\n");
  1250. else if (ieee80211_is_assoc_req(fc))
  1251. IWL_DEBUG_TX("Sending ASSOC frame\n");
  1252. else if (ieee80211_is_reassoc_req(fc))
  1253. IWL_DEBUG_TX("Sending REASSOC frame\n");
  1254. #endif
  1255. /* drop all data frame if we are not associated */
  1256. if (ieee80211_is_data(fc) &&
  1257. (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */
  1258. (!iwl3945_is_associated(priv) ||
  1259. ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
  1260. IWL_DEBUG_DROP("Dropping - !iwl3945_is_associated\n");
  1261. goto drop_unlock;
  1262. }
  1263. spin_unlock_irqrestore(&priv->lock, flags);
  1264. hdr_len = ieee80211_hdrlen(fc);
  1265. /* Find (or create) index into station table for destination station */
  1266. sta_id = iwl3945_get_sta_id(priv, hdr);
  1267. if (sta_id == IWL_INVALID_STATION) {
  1268. IWL_DEBUG_DROP("Dropping - INVALID STATION: %pM\n",
  1269. hdr->addr1);
  1270. goto drop;
  1271. }
  1272. IWL_DEBUG_RATE("station Id %d\n", sta_id);
  1273. if (ieee80211_is_data_qos(fc)) {
  1274. qc = ieee80211_get_qos_ctl(hdr);
  1275. tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
  1276. seq_number = priv->stations_39[sta_id].tid[tid].seq_number &
  1277. IEEE80211_SCTL_SEQ;
  1278. hdr->seq_ctrl = cpu_to_le16(seq_number) |
  1279. (hdr->seq_ctrl &
  1280. __constant_cpu_to_le16(IEEE80211_SCTL_FRAG));
  1281. seq_number += 0x10;
  1282. }
  1283. /* Descriptor for chosen Tx queue */
  1284. txq = &priv->txq[txq_id];
  1285. q = &txq->q;
  1286. spin_lock_irqsave(&priv->lock, flags);
  1287. idx = get_cmd_index(q, q->write_ptr, 0);
  1288. /* Set up driver data for this TFD */
  1289. memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
  1290. txq->txb[q->write_ptr].skb[0] = skb;
  1291. /* Init first empty entry in queue's array of Tx/cmd buffers */
  1292. out_cmd = txq->cmd[idx];
  1293. tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
  1294. memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
  1295. memset(tx, 0, sizeof(*tx));
  1296. /*
  1297. * Set up the Tx-command (not MAC!) header.
  1298. * Store the chosen Tx queue and TFD index within the sequence field;
  1299. * after Tx, uCode's Tx response will return this value so driver can
  1300. * locate the frame within the tx queue and do post-tx processing.
  1301. */
  1302. out_cmd->hdr.cmd = REPLY_TX;
  1303. out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
  1304. INDEX_TO_SEQ(q->write_ptr)));
  1305. /* Copy MAC header from skb into command buffer */
  1306. memcpy(tx->hdr, hdr, hdr_len);
  1307. /*
  1308. * Use the first empty entry in this queue's command buffer array
  1309. * to contain the Tx command and MAC header concatenated together
  1310. * (payload data will be in another buffer).
  1311. * Size of this varies, due to varying MAC header length.
  1312. * If end is not dword aligned, we'll have 2 extra bytes at the end
  1313. * of the MAC header (device reads on dword boundaries).
  1314. * We'll tell device about this padding later.
  1315. */
  1316. len = sizeof(struct iwl3945_tx_cmd) +
  1317. sizeof(struct iwl_cmd_header) + hdr_len;
  1318. len_org = len;
  1319. len = (len + 3) & ~3;
  1320. if (len_org != len)
  1321. len_org = 1;
  1322. else
  1323. len_org = 0;
  1324. /* Physical address of this Tx command's header (not MAC header!),
  1325. * within command buffer array. */
  1326. txcmd_phys = pci_map_single(priv->pci_dev,
  1327. out_cmd, sizeof(struct iwl_cmd),
  1328. PCI_DMA_TODEVICE);
  1329. pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys);
  1330. pci_unmap_len_set(&out_cmd->meta, len, sizeof(struct iwl_cmd));
  1331. /* Add buffer containing Tx command and MAC(!) header to TFD's
  1332. * first entry */
  1333. txcmd_phys += offsetof(struct iwl_cmd, hdr);
  1334. /* Add buffer containing Tx command and MAC(!) header to TFD's
  1335. * first entry */
  1336. priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
  1337. txcmd_phys, len, 1, 0);
  1338. if (info->control.hw_key)
  1339. iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, 0);
  1340. /* Set up TFD's 2nd entry to point directly to remainder of skb,
  1341. * if any (802.11 null frames have no payload). */
  1342. len = skb->len - hdr_len;
  1343. if (len) {
  1344. phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
  1345. len, PCI_DMA_TODEVICE);
  1346. priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
  1347. phys_addr, len,
  1348. 0, U32_PAD(len));
  1349. }
  1350. /* Total # bytes to be transmitted */
  1351. len = (u16)skb->len;
  1352. tx->len = cpu_to_le16(len);
  1353. /* TODO need this for burst mode later on */
  1354. iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
  1355. /* set is_hcca to 0; it probably will never be implemented */
  1356. iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
  1357. tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
  1358. tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
  1359. if (!ieee80211_has_morefrags(hdr->frame_control)) {
  1360. txq->need_update = 1;
  1361. if (qc)
  1362. priv->stations_39[sta_id].tid[tid].seq_number = seq_number;
  1363. } else {
  1364. wait_write_ptr = 1;
  1365. txq->need_update = 0;
  1366. }
  1367. iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx));
  1368. iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr,
  1369. ieee80211_hdrlen(fc));
  1370. /* Tell device the write index *just past* this latest filled TFD */
  1371. q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
  1372. rc = iwl_txq_update_write_ptr(priv, txq);
  1373. spin_unlock_irqrestore(&priv->lock, flags);
  1374. if (rc)
  1375. return rc;
  1376. if ((iwl_queue_space(q) < q->high_mark)
  1377. && priv->mac80211_registered) {
  1378. if (wait_write_ptr) {
  1379. spin_lock_irqsave(&priv->lock, flags);
  1380. txq->need_update = 1;
  1381. iwl_txq_update_write_ptr(priv, txq);
  1382. spin_unlock_irqrestore(&priv->lock, flags);
  1383. }
  1384. ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb));
  1385. }
  1386. return 0;
  1387. drop_unlock:
  1388. spin_unlock_irqrestore(&priv->lock, flags);
  1389. drop:
  1390. return -1;
  1391. }
  1392. static void iwl3945_set_rate(struct iwl_priv *priv)
  1393. {
  1394. const struct ieee80211_supported_band *sband = NULL;
  1395. struct ieee80211_rate *rate;
  1396. int i;
  1397. sband = iwl_get_hw_mode(priv, priv->band);
  1398. if (!sband) {
  1399. IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
  1400. return;
  1401. }
  1402. priv->active_rate = 0;
  1403. priv->active_rate_basic = 0;
  1404. IWL_DEBUG_RATE("Setting rates for %s GHz\n",
  1405. sband->band == IEEE80211_BAND_2GHZ ? "2.4" : "5");
  1406. for (i = 0; i < sband->n_bitrates; i++) {
  1407. rate = &sband->bitrates[i];
  1408. if ((rate->hw_value < IWL_RATE_COUNT) &&
  1409. !(rate->flags & IEEE80211_CHAN_DISABLED)) {
  1410. IWL_DEBUG_RATE("Adding rate index %d (plcp %d)\n",
  1411. rate->hw_value, iwl3945_rates[rate->hw_value].plcp);
  1412. priv->active_rate |= (1 << rate->hw_value);
  1413. }
  1414. }
  1415. IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
  1416. priv->active_rate, priv->active_rate_basic);
  1417. /*
  1418. * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
  1419. * otherwise set it to the default of all CCK rates and 6, 12, 24 for
  1420. * OFDM
  1421. */
  1422. if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
  1423. priv->staging39_rxon.cck_basic_rates =
  1424. ((priv->active_rate_basic &
  1425. IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
  1426. else
  1427. priv->staging39_rxon.cck_basic_rates =
  1428. (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  1429. if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
  1430. priv->staging39_rxon.ofdm_basic_rates =
  1431. ((priv->active_rate_basic &
  1432. (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
  1433. IWL_FIRST_OFDM_RATE) & 0xFF;
  1434. else
  1435. priv->staging39_rxon.ofdm_basic_rates =
  1436. (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  1437. }
  1438. static void iwl3945_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
  1439. {
  1440. unsigned long flags;
  1441. if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
  1442. return;
  1443. IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
  1444. disable_radio ? "OFF" : "ON");
  1445. if (disable_radio) {
  1446. iwl_scan_cancel(priv);
  1447. /* FIXME: This is a workaround for AP */
  1448. if (priv->iw_mode != NL80211_IFTYPE_AP) {
  1449. spin_lock_irqsave(&priv->lock, flags);
  1450. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  1451. CSR_UCODE_SW_BIT_RFKILL);
  1452. spin_unlock_irqrestore(&priv->lock, flags);
  1453. iwl_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0);
  1454. set_bit(STATUS_RF_KILL_SW, &priv->status);
  1455. }
  1456. return;
  1457. }
  1458. spin_lock_irqsave(&priv->lock, flags);
  1459. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  1460. clear_bit(STATUS_RF_KILL_SW, &priv->status);
  1461. spin_unlock_irqrestore(&priv->lock, flags);
  1462. /* wake up ucode */
  1463. msleep(10);
  1464. spin_lock_irqsave(&priv->lock, flags);
  1465. iwl_read32(priv, CSR_UCODE_DRV_GP1);
  1466. if (!iwl_grab_nic_access(priv))
  1467. iwl_release_nic_access(priv);
  1468. spin_unlock_irqrestore(&priv->lock, flags);
  1469. if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
  1470. IWL_DEBUG_RF_KILL("Can not turn radio back on - "
  1471. "disabled by HW switch\n");
  1472. return;
  1473. }
  1474. if (priv->is_open)
  1475. queue_work(priv->workqueue, &priv->restart);
  1476. return;
  1477. }
  1478. void iwl3945_set_decrypted_flag(struct iwl_priv *priv, struct sk_buff *skb,
  1479. u32 decrypt_res, struct ieee80211_rx_status *stats)
  1480. {
  1481. u16 fc =
  1482. le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control);
  1483. if (priv->active39_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
  1484. return;
  1485. if (!(fc & IEEE80211_FCTL_PROTECTED))
  1486. return;
  1487. IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
  1488. switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
  1489. case RX_RES_STATUS_SEC_TYPE_TKIP:
  1490. if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
  1491. RX_RES_STATUS_BAD_ICV_MIC)
  1492. stats->flag |= RX_FLAG_MMIC_ERROR;
  1493. case RX_RES_STATUS_SEC_TYPE_WEP:
  1494. case RX_RES_STATUS_SEC_TYPE_CCMP:
  1495. if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
  1496. RX_RES_STATUS_DECRYPT_OK) {
  1497. IWL_DEBUG_RX("hw decrypt successfully!!!\n");
  1498. stats->flag |= RX_FLAG_DECRYPTED;
  1499. }
  1500. break;
  1501. default:
  1502. break;
  1503. }
  1504. }
  1505. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  1506. #include "iwl-spectrum.h"
  1507. #define BEACON_TIME_MASK_LOW 0x00FFFFFF
  1508. #define BEACON_TIME_MASK_HIGH 0xFF000000
  1509. #define TIME_UNIT 1024
  1510. /*
  1511. * extended beacon time format
  1512. * time in usec will be changed into a 32-bit value in 8:24 format
  1513. * the high 1 byte is the beacon counts
  1514. * the lower 3 bytes is the time in usec within one beacon interval
  1515. */
  1516. static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
  1517. {
  1518. u32 quot;
  1519. u32 rem;
  1520. u32 interval = beacon_interval * 1024;
  1521. if (!interval || !usec)
  1522. return 0;
  1523. quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
  1524. rem = (usec % interval) & BEACON_TIME_MASK_LOW;
  1525. return (quot << 24) + rem;
  1526. }
  1527. /* base is usually what we get from ucode with each received frame,
  1528. * the same as HW timer counter counting down
  1529. */
  1530. static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
  1531. {
  1532. u32 base_low = base & BEACON_TIME_MASK_LOW;
  1533. u32 addon_low = addon & BEACON_TIME_MASK_LOW;
  1534. u32 interval = beacon_interval * TIME_UNIT;
  1535. u32 res = (base & BEACON_TIME_MASK_HIGH) +
  1536. (addon & BEACON_TIME_MASK_HIGH);
  1537. if (base_low > addon_low)
  1538. res += base_low - addon_low;
  1539. else if (base_low < addon_low) {
  1540. res += interval + base_low - addon_low;
  1541. res += (1 << 24);
  1542. } else
  1543. res += (1 << 24);
  1544. return cpu_to_le32(res);
  1545. }
  1546. static int iwl3945_get_measurement(struct iwl_priv *priv,
  1547. struct ieee80211_measurement_params *params,
  1548. u8 type)
  1549. {
  1550. struct iwl_spectrum_cmd spectrum;
  1551. struct iwl_rx_packet *res;
  1552. struct iwl_host_cmd cmd = {
  1553. .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
  1554. .data = (void *)&spectrum,
  1555. .meta.flags = CMD_WANT_SKB,
  1556. };
  1557. u32 add_time = le64_to_cpu(params->start_time);
  1558. int rc;
  1559. int spectrum_resp_status;
  1560. int duration = le16_to_cpu(params->duration);
  1561. if (iwl3945_is_associated(priv))
  1562. add_time =
  1563. iwl3945_usecs_to_beacons(
  1564. le64_to_cpu(params->start_time) - priv->last_tsf,
  1565. le16_to_cpu(priv->rxon_timing.beacon_interval));
  1566. memset(&spectrum, 0, sizeof(spectrum));
  1567. spectrum.channel_count = cpu_to_le16(1);
  1568. spectrum.flags =
  1569. RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
  1570. spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
  1571. cmd.len = sizeof(spectrum);
  1572. spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
  1573. if (iwl3945_is_associated(priv))
  1574. spectrum.start_time =
  1575. iwl3945_add_beacon_time(priv->last_beacon_time,
  1576. add_time,
  1577. le16_to_cpu(priv->rxon_timing.beacon_interval));
  1578. else
  1579. spectrum.start_time = 0;
  1580. spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
  1581. spectrum.channels[0].channel = params->channel;
  1582. spectrum.channels[0].type = type;
  1583. if (priv->active39_rxon.flags & RXON_FLG_BAND_24G_MSK)
  1584. spectrum.flags |= RXON_FLG_BAND_24G_MSK |
  1585. RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
  1586. rc = iwl_send_cmd_sync(priv, &cmd);
  1587. if (rc)
  1588. return rc;
  1589. res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
  1590. if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
  1591. IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
  1592. rc = -EIO;
  1593. }
  1594. spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
  1595. switch (spectrum_resp_status) {
  1596. case 0: /* Command will be handled */
  1597. if (res->u.spectrum.id != 0xff) {
  1598. IWL_DEBUG_INFO("Replaced existing measurement: %d\n",
  1599. res->u.spectrum.id);
  1600. priv->measurement_status &= ~MEASUREMENT_READY;
  1601. }
  1602. priv->measurement_status |= MEASUREMENT_ACTIVE;
  1603. rc = 0;
  1604. break;
  1605. case 1: /* Command will not be handled */
  1606. rc = -EAGAIN;
  1607. break;
  1608. }
  1609. dev_kfree_skb_any(cmd.meta.u.skb);
  1610. return rc;
  1611. }
  1612. #endif
  1613. static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
  1614. struct iwl_rx_mem_buffer *rxb)
  1615. {
  1616. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1617. struct iwl_alive_resp *palive;
  1618. struct delayed_work *pwork;
  1619. palive = &pkt->u.alive_frame;
  1620. IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
  1621. "0x%01X 0x%01X\n",
  1622. palive->is_valid, palive->ver_type,
  1623. palive->ver_subtype);
  1624. if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
  1625. IWL_DEBUG_INFO("Initialization Alive received.\n");
  1626. memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
  1627. sizeof(struct iwl_alive_resp));
  1628. pwork = &priv->init_alive_start;
  1629. } else {
  1630. IWL_DEBUG_INFO("Runtime Alive received.\n");
  1631. memcpy(&priv->card_alive, &pkt->u.alive_frame,
  1632. sizeof(struct iwl_alive_resp));
  1633. pwork = &priv->alive_start;
  1634. iwl3945_disable_events(priv);
  1635. }
  1636. /* We delay the ALIVE response by 5ms to
  1637. * give the HW RF Kill time to activate... */
  1638. if (palive->is_valid == UCODE_VALID_OK)
  1639. queue_delayed_work(priv->workqueue, pwork,
  1640. msecs_to_jiffies(5));
  1641. else
  1642. IWL_WARN(priv, "uCode did not respond OK.\n");
  1643. }
  1644. static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
  1645. struct iwl_rx_mem_buffer *rxb)
  1646. {
  1647. #ifdef CONFIG_IWLWIFI_DEBUG
  1648. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1649. #endif
  1650. IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
  1651. return;
  1652. }
  1653. static void iwl3945_rx_reply_error(struct iwl_priv *priv,
  1654. struct iwl_rx_mem_buffer *rxb)
  1655. {
  1656. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1657. IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
  1658. "seq 0x%04X ser 0x%08X\n",
  1659. le32_to_cpu(pkt->u.err_resp.error_type),
  1660. get_cmd_string(pkt->u.err_resp.cmd_id),
  1661. pkt->u.err_resp.cmd_id,
  1662. le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
  1663. le32_to_cpu(pkt->u.err_resp.error_info));
  1664. }
  1665. #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
  1666. static void iwl3945_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
  1667. {
  1668. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1669. struct iwl3945_rxon_cmd *rxon = (void *)&priv->active39_rxon;
  1670. struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
  1671. IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
  1672. le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
  1673. rxon->channel = csa->channel;
  1674. priv->staging39_rxon.channel = csa->channel;
  1675. }
  1676. static void iwl3945_rx_spectrum_measure_notif(struct iwl_priv *priv,
  1677. struct iwl_rx_mem_buffer *rxb)
  1678. {
  1679. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  1680. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1681. struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif);
  1682. if (!report->state) {
  1683. IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO,
  1684. "Spectrum Measure Notification: Start\n");
  1685. return;
  1686. }
  1687. memcpy(&priv->measure_report, report, sizeof(*report));
  1688. priv->measurement_status |= MEASUREMENT_READY;
  1689. #endif
  1690. }
  1691. static void iwl3945_rx_pm_sleep_notif(struct iwl_priv *priv,
  1692. struct iwl_rx_mem_buffer *rxb)
  1693. {
  1694. #ifdef CONFIG_IWLWIFI_DEBUG
  1695. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1696. struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
  1697. IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
  1698. sleep->pm_sleep_mode, sleep->pm_wakeup_src);
  1699. #endif
  1700. }
  1701. static void iwl3945_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
  1702. struct iwl_rx_mem_buffer *rxb)
  1703. {
  1704. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1705. IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
  1706. "notification for %s:\n",
  1707. le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
  1708. iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw,
  1709. le32_to_cpu(pkt->len));
  1710. }
  1711. static void iwl3945_bg_beacon_update(struct work_struct *work)
  1712. {
  1713. struct iwl_priv *priv =
  1714. container_of(work, struct iwl_priv, beacon_update);
  1715. struct sk_buff *beacon;
  1716. /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
  1717. beacon = ieee80211_beacon_get(priv->hw, priv->vif);
  1718. if (!beacon) {
  1719. IWL_ERR(priv, "update beacon failed\n");
  1720. return;
  1721. }
  1722. mutex_lock(&priv->mutex);
  1723. /* new beacon skb is allocated every time; dispose previous.*/
  1724. if (priv->ibss_beacon)
  1725. dev_kfree_skb(priv->ibss_beacon);
  1726. priv->ibss_beacon = beacon;
  1727. mutex_unlock(&priv->mutex);
  1728. iwl3945_send_beacon_cmd(priv);
  1729. }
  1730. static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
  1731. struct iwl_rx_mem_buffer *rxb)
  1732. {
  1733. #ifdef CONFIG_IWLWIFI_DEBUG
  1734. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1735. struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
  1736. u8 rate = beacon->beacon_notify_hdr.rate;
  1737. IWL_DEBUG_RX("beacon status %x retries %d iss %d "
  1738. "tsf %d %d rate %d\n",
  1739. le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
  1740. beacon->beacon_notify_hdr.failure_frame,
  1741. le32_to_cpu(beacon->ibss_mgr_status),
  1742. le32_to_cpu(beacon->high_tsf),
  1743. le32_to_cpu(beacon->low_tsf), rate);
  1744. #endif
  1745. if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
  1746. (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
  1747. queue_work(priv->workqueue, &priv->beacon_update);
  1748. }
  1749. /* Service response to REPLY_SCAN_CMD (0x80) */
  1750. static void iwl3945_rx_reply_scan(struct iwl_priv *priv,
  1751. struct iwl_rx_mem_buffer *rxb)
  1752. {
  1753. #ifdef CONFIG_IWLWIFI_DEBUG
  1754. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1755. struct iwl_scanreq_notification *notif =
  1756. (struct iwl_scanreq_notification *)pkt->u.raw;
  1757. IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status);
  1758. #endif
  1759. }
  1760. /* Service SCAN_START_NOTIFICATION (0x82) */
  1761. static void iwl3945_rx_scan_start_notif(struct iwl_priv *priv,
  1762. struct iwl_rx_mem_buffer *rxb)
  1763. {
  1764. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1765. struct iwl_scanstart_notification *notif =
  1766. (struct iwl_scanstart_notification *)pkt->u.raw;
  1767. priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
  1768. IWL_DEBUG_SCAN("Scan start: "
  1769. "%d [802.11%s] "
  1770. "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
  1771. notif->channel,
  1772. notif->band ? "bg" : "a",
  1773. notif->tsf_high,
  1774. notif->tsf_low, notif->status, notif->beacon_timer);
  1775. }
  1776. /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
  1777. static void iwl3945_rx_scan_results_notif(struct iwl_priv *priv,
  1778. struct iwl_rx_mem_buffer *rxb)
  1779. {
  1780. #ifdef CONFIG_IWLWIFI_DEBUG
  1781. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1782. struct iwl_scanresults_notification *notif =
  1783. (struct iwl_scanresults_notification *)pkt->u.raw;
  1784. #endif
  1785. IWL_DEBUG_SCAN("Scan ch.res: "
  1786. "%d [802.11%s] "
  1787. "(TSF: 0x%08X:%08X) - %d "
  1788. "elapsed=%lu usec (%dms since last)\n",
  1789. notif->channel,
  1790. notif->band ? "bg" : "a",
  1791. le32_to_cpu(notif->tsf_high),
  1792. le32_to_cpu(notif->tsf_low),
  1793. le32_to_cpu(notif->statistics[0]),
  1794. le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf,
  1795. jiffies_to_msecs(elapsed_jiffies
  1796. (priv->last_scan_jiffies, jiffies)));
  1797. priv->last_scan_jiffies = jiffies;
  1798. priv->next_scan_jiffies = 0;
  1799. }
  1800. /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
  1801. static void iwl3945_rx_scan_complete_notif(struct iwl_priv *priv,
  1802. struct iwl_rx_mem_buffer *rxb)
  1803. {
  1804. #ifdef CONFIG_IWLWIFI_DEBUG
  1805. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1806. struct iwl_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
  1807. #endif
  1808. IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
  1809. scan_notif->scanned_channels,
  1810. scan_notif->tsf_low,
  1811. scan_notif->tsf_high, scan_notif->status);
  1812. /* The HW is no longer scanning */
  1813. clear_bit(STATUS_SCAN_HW, &priv->status);
  1814. /* The scan completion notification came in, so kill that timer... */
  1815. cancel_delayed_work(&priv->scan_check);
  1816. IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
  1817. (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) ?
  1818. "2.4" : "5.2",
  1819. jiffies_to_msecs(elapsed_jiffies
  1820. (priv->scan_pass_start, jiffies)));
  1821. /* Remove this scanned band from the list of pending
  1822. * bands to scan, band G precedes A in order of scanning
  1823. * as seen in iwl3945_bg_request_scan */
  1824. if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ))
  1825. priv->scan_bands &= ~BIT(IEEE80211_BAND_2GHZ);
  1826. else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ))
  1827. priv->scan_bands &= ~BIT(IEEE80211_BAND_5GHZ);
  1828. /* If a request to abort was given, or the scan did not succeed
  1829. * then we reset the scan state machine and terminate,
  1830. * re-queuing another scan if one has been requested */
  1831. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  1832. IWL_DEBUG_INFO("Aborted scan completed.\n");
  1833. clear_bit(STATUS_SCAN_ABORTING, &priv->status);
  1834. } else {
  1835. /* If there are more bands on this scan pass reschedule */
  1836. if (priv->scan_bands > 0)
  1837. goto reschedule;
  1838. }
  1839. priv->last_scan_jiffies = jiffies;
  1840. priv->next_scan_jiffies = 0;
  1841. IWL_DEBUG_INFO("Setting scan to off\n");
  1842. clear_bit(STATUS_SCANNING, &priv->status);
  1843. IWL_DEBUG_INFO("Scan took %dms\n",
  1844. jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies)));
  1845. queue_work(priv->workqueue, &priv->scan_completed);
  1846. return;
  1847. reschedule:
  1848. priv->scan_pass_start = jiffies;
  1849. queue_work(priv->workqueue, &priv->request_scan);
  1850. }
  1851. /* Handle notification from uCode that card's power state is changing
  1852. * due to software, hardware, or critical temperature RFKILL */
  1853. static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
  1854. struct iwl_rx_mem_buffer *rxb)
  1855. {
  1856. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  1857. u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
  1858. unsigned long status = priv->status;
  1859. IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
  1860. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  1861. (flags & SW_CARD_DISABLED) ? "Kill" : "On");
  1862. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  1863. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  1864. if (flags & HW_CARD_DISABLED)
  1865. set_bit(STATUS_RF_KILL_HW, &priv->status);
  1866. else
  1867. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  1868. if (flags & SW_CARD_DISABLED)
  1869. set_bit(STATUS_RF_KILL_SW, &priv->status);
  1870. else
  1871. clear_bit(STATUS_RF_KILL_SW, &priv->status);
  1872. iwl_scan_cancel(priv);
  1873. if ((test_bit(STATUS_RF_KILL_HW, &status) !=
  1874. test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
  1875. (test_bit(STATUS_RF_KILL_SW, &status) !=
  1876. test_bit(STATUS_RF_KILL_SW, &priv->status)))
  1877. queue_work(priv->workqueue, &priv->rf_kill);
  1878. else
  1879. wake_up_interruptible(&priv->wait_command_queue);
  1880. }
  1881. /**
  1882. * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
  1883. *
  1884. * Setup the RX handlers for each of the reply types sent from the uCode
  1885. * to the host.
  1886. *
  1887. * This function chains into the hardware specific files for them to setup
  1888. * any hardware specific handlers as well.
  1889. */
  1890. static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
  1891. {
  1892. priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
  1893. priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
  1894. priv->rx_handlers[REPLY_ERROR] = iwl3945_rx_reply_error;
  1895. priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl3945_rx_csa;
  1896. priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
  1897. iwl3945_rx_spectrum_measure_notif;
  1898. priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl3945_rx_pm_sleep_notif;
  1899. priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
  1900. iwl3945_rx_pm_debug_statistics_notif;
  1901. priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
  1902. /*
  1903. * The same handler is used for both the REPLY to a discrete
  1904. * statistics request from the host as well as for the periodic
  1905. * statistics notifications (after received beacons) from the uCode.
  1906. */
  1907. priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
  1908. priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
  1909. priv->rx_handlers[REPLY_SCAN_CMD] = iwl3945_rx_reply_scan;
  1910. priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl3945_rx_scan_start_notif;
  1911. priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
  1912. iwl3945_rx_scan_results_notif;
  1913. priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
  1914. iwl3945_rx_scan_complete_notif;
  1915. priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
  1916. /* Set up hardware specific Rx handlers */
  1917. iwl3945_hw_rx_handler_setup(priv);
  1918. }
  1919. /**
  1920. * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries
  1921. * When FW advances 'R' index, all entries between old and new 'R' index
  1922. * need to be reclaimed.
  1923. */
  1924. static void iwl3945_cmd_queue_reclaim(struct iwl_priv *priv,
  1925. int txq_id, int index)
  1926. {
  1927. struct iwl_tx_queue *txq = &priv->txq[txq_id];
  1928. struct iwl_queue *q = &txq->q;
  1929. int nfreed = 0;
  1930. if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) {
  1931. IWL_ERR(priv, "Read index for DMA queue txq id (%d), index %d, "
  1932. "is out of range [0-%d] %d %d.\n", txq_id,
  1933. index, q->n_bd, q->write_ptr, q->read_ptr);
  1934. return;
  1935. }
  1936. for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
  1937. q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
  1938. if (nfreed > 1) {
  1939. IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", index,
  1940. q->write_ptr, q->read_ptr);
  1941. queue_work(priv->workqueue, &priv->restart);
  1942. break;
  1943. }
  1944. nfreed++;
  1945. }
  1946. }
  1947. /**
  1948. * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
  1949. * @rxb: Rx buffer to reclaim
  1950. *
  1951. * If an Rx buffer has an async callback associated with it the callback
  1952. * will be executed. The attached skb (if present) will only be freed
  1953. * if the callback returns 1
  1954. */
  1955. static void iwl3945_tx_cmd_complete(struct iwl_priv *priv,
  1956. struct iwl_rx_mem_buffer *rxb)
  1957. {
  1958. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1959. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  1960. int txq_id = SEQ_TO_QUEUE(sequence);
  1961. int index = SEQ_TO_INDEX(sequence);
  1962. int huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME);
  1963. int cmd_index;
  1964. struct iwl_cmd *cmd;
  1965. if (WARN(txq_id != IWL_CMD_QUEUE_NUM,
  1966. "wrong command queue %d, sequence 0x%X readp=%d writep=%d\n",
  1967. txq_id, sequence,
  1968. priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr,
  1969. priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) {
  1970. iwl_print_hex_dump(priv, IWL_DL_INFO , rxb, 32);
  1971. return;
  1972. }
  1973. cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
  1974. cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
  1975. /* Input error checking is done when commands are added to queue. */
  1976. if (cmd->meta.flags & CMD_WANT_SKB) {
  1977. cmd->meta.source->u.skb = rxb->skb;
  1978. rxb->skb = NULL;
  1979. } else if (cmd->meta.u.callback &&
  1980. !cmd->meta.u.callback(priv, cmd, rxb->skb))
  1981. rxb->skb = NULL;
  1982. iwl3945_cmd_queue_reclaim(priv, txq_id, index);
  1983. if (!(cmd->meta.flags & CMD_ASYNC)) {
  1984. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  1985. wake_up_interruptible(&priv->wait_command_queue);
  1986. }
  1987. }
  1988. /************************** RX-FUNCTIONS ****************************/
  1989. /*
  1990. * Rx theory of operation
  1991. *
  1992. * The host allocates 32 DMA target addresses and passes the host address
  1993. * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
  1994. * 0 to 31
  1995. *
  1996. * Rx Queue Indexes
  1997. * The host/firmware share two index registers for managing the Rx buffers.
  1998. *
  1999. * The READ index maps to the first position that the firmware may be writing
  2000. * to -- the driver can read up to (but not including) this position and get
  2001. * good data.
  2002. * The READ index is managed by the firmware once the card is enabled.
  2003. *
  2004. * The WRITE index maps to the last position the driver has read from -- the
  2005. * position preceding WRITE is the last slot the firmware can place a packet.
  2006. *
  2007. * The queue is empty (no good data) if WRITE = READ - 1, and is full if
  2008. * WRITE = READ.
  2009. *
  2010. * During initialization, the host sets up the READ queue position to the first
  2011. * INDEX position, and WRITE to the last (READ - 1 wrapped)
  2012. *
  2013. * When the firmware places a packet in a buffer, it will advance the READ index
  2014. * and fire the RX interrupt. The driver can then query the READ index and
  2015. * process as many packets as possible, moving the WRITE index forward as it
  2016. * resets the Rx queue buffers with new memory.
  2017. *
  2018. * The management in the driver is as follows:
  2019. * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
  2020. * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
  2021. * to replenish the iwl->rxq->rx_free.
  2022. * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
  2023. * iwl->rxq is replenished and the READ INDEX is updated (updating the
  2024. * 'processed' and 'read' driver indexes as well)
  2025. * + A received packet is processed and handed to the kernel network stack,
  2026. * detached from the iwl->rxq. The driver 'processed' index is updated.
  2027. * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
  2028. * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
  2029. * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
  2030. * were enough free buffers and RX_STALLED is set it is cleared.
  2031. *
  2032. *
  2033. * Driver sequence:
  2034. *
  2035. * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
  2036. * iwl3945_rx_queue_restock
  2037. * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
  2038. * queue, updates firmware pointers, and updates
  2039. * the WRITE index. If insufficient rx_free buffers
  2040. * are available, schedules iwl3945_rx_replenish
  2041. *
  2042. * -- enable interrupts --
  2043. * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
  2044. * READ INDEX, detaching the SKB from the pool.
  2045. * Moves the packet buffer from queue to rx_used.
  2046. * Calls iwl3945_rx_queue_restock to refill any empty
  2047. * slots.
  2048. * ...
  2049. *
  2050. */
  2051. /**
  2052. * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
  2053. */
  2054. static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
  2055. dma_addr_t dma_addr)
  2056. {
  2057. return cpu_to_le32((u32)dma_addr);
  2058. }
  2059. /**
  2060. * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
  2061. *
  2062. * If there are slots in the RX queue that need to be restocked,
  2063. * and we have free pre-allocated buffers, fill the ranks as much
  2064. * as we can, pulling from rx_free.
  2065. *
  2066. * This moves the 'write' index forward to catch up with 'processed', and
  2067. * also updates the memory address in the firmware to reference the new
  2068. * target buffer.
  2069. */
  2070. static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
  2071. {
  2072. struct iwl_rx_queue *rxq = &priv->rxq;
  2073. struct list_head *element;
  2074. struct iwl_rx_mem_buffer *rxb;
  2075. unsigned long flags;
  2076. int write, rc;
  2077. spin_lock_irqsave(&rxq->lock, flags);
  2078. write = rxq->write & ~0x7;
  2079. while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
  2080. /* Get next free Rx buffer, remove from free list */
  2081. element = rxq->rx_free.next;
  2082. rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
  2083. list_del(element);
  2084. /* Point to Rx buffer via next RBD in circular buffer */
  2085. rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr);
  2086. rxq->queue[rxq->write] = rxb;
  2087. rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
  2088. rxq->free_count--;
  2089. }
  2090. spin_unlock_irqrestore(&rxq->lock, flags);
  2091. /* If the pre-allocated buffer pool is dropping low, schedule to
  2092. * refill it */
  2093. if (rxq->free_count <= RX_LOW_WATERMARK)
  2094. queue_work(priv->workqueue, &priv->rx_replenish);
  2095. /* If we've added more space for the firmware to place data, tell it.
  2096. * Increment device's write pointer in multiples of 8. */
  2097. if ((write != (rxq->write & ~0x7))
  2098. || (abs(rxq->write - rxq->read) > 7)) {
  2099. spin_lock_irqsave(&rxq->lock, flags);
  2100. rxq->need_update = 1;
  2101. spin_unlock_irqrestore(&rxq->lock, flags);
  2102. rc = iwl_rx_queue_update_write_ptr(priv, rxq);
  2103. if (rc)
  2104. return rc;
  2105. }
  2106. return 0;
  2107. }
  2108. /**
  2109. * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
  2110. *
  2111. * When moving to rx_free an SKB is allocated for the slot.
  2112. *
  2113. * Also restock the Rx queue via iwl3945_rx_queue_restock.
  2114. * This is called as a scheduled work item (except for during initialization)
  2115. */
  2116. static void iwl3945_rx_allocate(struct iwl_priv *priv)
  2117. {
  2118. struct iwl_rx_queue *rxq = &priv->rxq;
  2119. struct list_head *element;
  2120. struct iwl_rx_mem_buffer *rxb;
  2121. unsigned long flags;
  2122. spin_lock_irqsave(&rxq->lock, flags);
  2123. while (!list_empty(&rxq->rx_used)) {
  2124. element = rxq->rx_used.next;
  2125. rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
  2126. /* Alloc a new receive buffer */
  2127. rxb->skb =
  2128. alloc_skb(priv->hw_params.rx_buf_size,
  2129. __GFP_NOWARN | GFP_ATOMIC);
  2130. if (!rxb->skb) {
  2131. if (net_ratelimit())
  2132. IWL_CRIT(priv, ": Can not allocate SKB buffers\n");
  2133. /* We don't reschedule replenish work here -- we will
  2134. * call the restock method and if it still needs
  2135. * more buffers it will schedule replenish */
  2136. break;
  2137. }
  2138. /* If radiotap head is required, reserve some headroom here.
  2139. * The physical head count is a variable rx_stats->phy_count.
  2140. * We reserve 4 bytes here. Plus these extra bytes, the
  2141. * headroom of the physical head should be enough for the
  2142. * radiotap head that iwl3945 supported. See iwl3945_rt.
  2143. */
  2144. skb_reserve(rxb->skb, 4);
  2145. priv->alloc_rxb_skb++;
  2146. list_del(element);
  2147. /* Get physical address of RB/SKB */
  2148. rxb->real_dma_addr = pci_map_single(priv->pci_dev,
  2149. rxb->skb->data,
  2150. priv->hw_params.rx_buf_size,
  2151. PCI_DMA_FROMDEVICE);
  2152. list_add_tail(&rxb->list, &rxq->rx_free);
  2153. rxq->free_count++;
  2154. }
  2155. spin_unlock_irqrestore(&rxq->lock, flags);
  2156. }
  2157. /*
  2158. * this should be called while priv->lock is locked
  2159. */
  2160. static void __iwl3945_rx_replenish(void *data)
  2161. {
  2162. struct iwl_priv *priv = data;
  2163. iwl3945_rx_allocate(priv);
  2164. iwl3945_rx_queue_restock(priv);
  2165. }
  2166. void iwl3945_rx_replenish(void *data)
  2167. {
  2168. struct iwl_priv *priv = data;
  2169. unsigned long flags;
  2170. iwl3945_rx_allocate(priv);
  2171. spin_lock_irqsave(&priv->lock, flags);
  2172. iwl3945_rx_queue_restock(priv);
  2173. spin_unlock_irqrestore(&priv->lock, flags);
  2174. }
  2175. /* Convert linear signal-to-noise ratio into dB */
  2176. static u8 ratio2dB[100] = {
  2177. /* 0 1 2 3 4 5 6 7 8 9 */
  2178. 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
  2179. 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
  2180. 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
  2181. 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
  2182. 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
  2183. 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
  2184. 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
  2185. 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
  2186. 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
  2187. 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
  2188. };
  2189. /* Calculates a relative dB value from a ratio of linear
  2190. * (i.e. not dB) signal levels.
  2191. * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
  2192. int iwl3945_calc_db_from_ratio(int sig_ratio)
  2193. {
  2194. /* 1000:1 or higher just report as 60 dB */
  2195. if (sig_ratio >= 1000)
  2196. return 60;
  2197. /* 100:1 or higher, divide by 10 and use table,
  2198. * add 20 dB to make up for divide by 10 */
  2199. if (sig_ratio >= 100)
  2200. return 20 + (int)ratio2dB[sig_ratio/10];
  2201. /* We shouldn't see this */
  2202. if (sig_ratio < 1)
  2203. return 0;
  2204. /* Use table for ratios 1:1 - 99:1 */
  2205. return (int)ratio2dB[sig_ratio];
  2206. }
  2207. #define PERFECT_RSSI (-20) /* dBm */
  2208. #define WORST_RSSI (-95) /* dBm */
  2209. #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
  2210. /* Calculate an indication of rx signal quality (a percentage, not dBm!).
  2211. * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
  2212. * about formulas used below. */
  2213. int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
  2214. {
  2215. int sig_qual;
  2216. int degradation = PERFECT_RSSI - rssi_dbm;
  2217. /* If we get a noise measurement, use signal-to-noise ratio (SNR)
  2218. * as indicator; formula is (signal dbm - noise dbm).
  2219. * SNR at or above 40 is a great signal (100%).
  2220. * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
  2221. * Weakest usable signal is usually 10 - 15 dB SNR. */
  2222. if (noise_dbm) {
  2223. if (rssi_dbm - noise_dbm >= 40)
  2224. return 100;
  2225. else if (rssi_dbm < noise_dbm)
  2226. return 0;
  2227. sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
  2228. /* Else use just the signal level.
  2229. * This formula is a least squares fit of data points collected and
  2230. * compared with a reference system that had a percentage (%) display
  2231. * for signal quality. */
  2232. } else
  2233. sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
  2234. (15 * RSSI_RANGE + 62 * degradation)) /
  2235. (RSSI_RANGE * RSSI_RANGE);
  2236. if (sig_qual > 100)
  2237. sig_qual = 100;
  2238. else if (sig_qual < 1)
  2239. sig_qual = 0;
  2240. return sig_qual;
  2241. }
  2242. /**
  2243. * iwl3945_rx_handle - Main entry function for receiving responses from uCode
  2244. *
  2245. * Uses the priv->rx_handlers callback function array to invoke
  2246. * the appropriate handlers, including command responses,
  2247. * frame-received notifications, and other notifications.
  2248. */
  2249. static void iwl3945_rx_handle(struct iwl_priv *priv)
  2250. {
  2251. struct iwl_rx_mem_buffer *rxb;
  2252. struct iwl_rx_packet *pkt;
  2253. struct iwl_rx_queue *rxq = &priv->rxq;
  2254. u32 r, i;
  2255. int reclaim;
  2256. unsigned long flags;
  2257. u8 fill_rx = 0;
  2258. u32 count = 8;
  2259. /* uCode's read index (stored in shared DRAM) indicates the last Rx
  2260. * buffer that the driver may process (last buffer filled by ucode). */
  2261. r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
  2262. i = rxq->read;
  2263. if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
  2264. fill_rx = 1;
  2265. /* Rx interrupt, but nothing sent from uCode */
  2266. if (i == r)
  2267. IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
  2268. while (i != r) {
  2269. rxb = rxq->queue[i];
  2270. /* If an RXB doesn't have a Rx queue slot associated with it,
  2271. * then a bug has been introduced in the queue refilling
  2272. * routines -- catch it here */
  2273. BUG_ON(rxb == NULL);
  2274. rxq->queue[i] = NULL;
  2275. pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->real_dma_addr,
  2276. priv->hw_params.rx_buf_size,
  2277. PCI_DMA_FROMDEVICE);
  2278. pkt = (struct iwl_rx_packet *)rxb->skb->data;
  2279. /* Reclaim a command buffer only if this packet is a response
  2280. * to a (driver-originated) command.
  2281. * If the packet (e.g. Rx frame) originated from uCode,
  2282. * there is no command buffer to reclaim.
  2283. * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
  2284. * but apparently a few don't get set; catch them here. */
  2285. reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
  2286. (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
  2287. (pkt->hdr.cmd != REPLY_TX);
  2288. /* Based on type of command response or notification,
  2289. * handle those that need handling via function in
  2290. * rx_handlers table. See iwl3945_setup_rx_handlers() */
  2291. if (priv->rx_handlers[pkt->hdr.cmd]) {
  2292. IWL_DEBUG(IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
  2293. "r = %d, i = %d, %s, 0x%02x\n", r, i,
  2294. get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
  2295. priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
  2296. } else {
  2297. /* No handling needed */
  2298. IWL_DEBUG(IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
  2299. "r %d i %d No handler needed for %s, 0x%02x\n",
  2300. r, i, get_cmd_string(pkt->hdr.cmd),
  2301. pkt->hdr.cmd);
  2302. }
  2303. if (reclaim) {
  2304. /* Invoke any callbacks, transfer the skb to caller, and
  2305. * fire off the (possibly) blocking iwl_send_cmd()
  2306. * as we reclaim the driver command queue */
  2307. if (rxb && rxb->skb)
  2308. iwl3945_tx_cmd_complete(priv, rxb);
  2309. else
  2310. IWL_WARN(priv, "Claim null rxb?\n");
  2311. }
  2312. /* For now we just don't re-use anything. We can tweak this
  2313. * later to try and re-use notification packets and SKBs that
  2314. * fail to Rx correctly */
  2315. if (rxb->skb != NULL) {
  2316. priv->alloc_rxb_skb--;
  2317. dev_kfree_skb_any(rxb->skb);
  2318. rxb->skb = NULL;
  2319. }
  2320. pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
  2321. priv->hw_params.rx_buf_size,
  2322. PCI_DMA_FROMDEVICE);
  2323. spin_lock_irqsave(&rxq->lock, flags);
  2324. list_add_tail(&rxb->list, &priv->rxq.rx_used);
  2325. spin_unlock_irqrestore(&rxq->lock, flags);
  2326. i = (i + 1) & RX_QUEUE_MASK;
  2327. /* If there are a lot of unused frames,
  2328. * restock the Rx queue so ucode won't assert. */
  2329. if (fill_rx) {
  2330. count++;
  2331. if (count >= 8) {
  2332. priv->rxq.read = i;
  2333. __iwl3945_rx_replenish(priv);
  2334. count = 0;
  2335. }
  2336. }
  2337. }
  2338. /* Backtrack one entry */
  2339. priv->rxq.read = i;
  2340. iwl3945_rx_queue_restock(priv);
  2341. }
  2342. #ifdef CONFIG_IWLWIFI_DEBUG
  2343. static void iwl3945_print_rx_config_cmd(struct iwl_priv *priv,
  2344. struct iwl3945_rxon_cmd *rxon)
  2345. {
  2346. IWL_DEBUG_RADIO("RX CONFIG:\n");
  2347. iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
  2348. IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
  2349. IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
  2350. IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
  2351. le32_to_cpu(rxon->filter_flags));
  2352. IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
  2353. IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
  2354. rxon->ofdm_basic_rates);
  2355. IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
  2356. IWL_DEBUG_RADIO("u8[6] node_addr: %pM\n", rxon->node_addr);
  2357. IWL_DEBUG_RADIO("u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
  2358. IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
  2359. }
  2360. #endif
  2361. static void iwl3945_enable_interrupts(struct iwl_priv *priv)
  2362. {
  2363. IWL_DEBUG_ISR("Enabling interrupts\n");
  2364. set_bit(STATUS_INT_ENABLED, &priv->status);
  2365. iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
  2366. }
  2367. /* call this function to flush any scheduled tasklet */
  2368. static inline void iwl_synchronize_irq(struct iwl_priv *priv)
  2369. {
  2370. /* wait to make sure we flush pending tasklet*/
  2371. synchronize_irq(priv->pci_dev->irq);
  2372. tasklet_kill(&priv->irq_tasklet);
  2373. }
  2374. static inline void iwl3945_disable_interrupts(struct iwl_priv *priv)
  2375. {
  2376. clear_bit(STATUS_INT_ENABLED, &priv->status);
  2377. /* disable interrupts from uCode/NIC to host */
  2378. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  2379. /* acknowledge/clear/reset any interrupts still pending
  2380. * from uCode or flow handler (Rx/Tx DMA) */
  2381. iwl_write32(priv, CSR_INT, 0xffffffff);
  2382. iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
  2383. IWL_DEBUG_ISR("Disabled interrupts\n");
  2384. }
  2385. static const char *desc_lookup(int i)
  2386. {
  2387. switch (i) {
  2388. case 1:
  2389. return "FAIL";
  2390. case 2:
  2391. return "BAD_PARAM";
  2392. case 3:
  2393. return "BAD_CHECKSUM";
  2394. case 4:
  2395. return "NMI_INTERRUPT";
  2396. case 5:
  2397. return "SYSASSERT";
  2398. case 6:
  2399. return "FATAL_ERROR";
  2400. }
  2401. return "UNKNOWN";
  2402. }
  2403. #define ERROR_START_OFFSET (1 * sizeof(u32))
  2404. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  2405. static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
  2406. {
  2407. u32 i;
  2408. u32 desc, time, count, base, data1;
  2409. u32 blink1, blink2, ilink1, ilink2;
  2410. int rc;
  2411. base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
  2412. if (!iwl3945_hw_valid_rtc_data_addr(base)) {
  2413. IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
  2414. return;
  2415. }
  2416. rc = iwl_grab_nic_access(priv);
  2417. if (rc) {
  2418. IWL_WARN(priv, "Can not read from adapter at this time.\n");
  2419. return;
  2420. }
  2421. count = iwl_read_targ_mem(priv, base);
  2422. if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
  2423. IWL_ERR(priv, "Start IWL Error Log Dump:\n");
  2424. IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
  2425. priv->status, count);
  2426. }
  2427. IWL_ERR(priv, "Desc Time asrtPC blink2 "
  2428. "ilink1 nmiPC Line\n");
  2429. for (i = ERROR_START_OFFSET;
  2430. i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
  2431. i += ERROR_ELEM_SIZE) {
  2432. desc = iwl_read_targ_mem(priv, base + i);
  2433. time =
  2434. iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
  2435. blink1 =
  2436. iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
  2437. blink2 =
  2438. iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
  2439. ilink1 =
  2440. iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
  2441. ilink2 =
  2442. iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
  2443. data1 =
  2444. iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
  2445. IWL_ERR(priv,
  2446. "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
  2447. desc_lookup(desc), desc, time, blink1, blink2,
  2448. ilink1, ilink2, data1);
  2449. }
  2450. iwl_release_nic_access(priv);
  2451. }
  2452. #define EVENT_START_OFFSET (6 * sizeof(u32))
  2453. /**
  2454. * iwl3945_print_event_log - Dump error event log to syslog
  2455. *
  2456. * NOTE: Must be called with iwl_grab_nic_access() already obtained!
  2457. */
  2458. static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
  2459. u32 num_events, u32 mode)
  2460. {
  2461. u32 i;
  2462. u32 base; /* SRAM byte address of event log header */
  2463. u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
  2464. u32 ptr; /* SRAM byte address of log data */
  2465. u32 ev, time, data; /* event log data */
  2466. if (num_events == 0)
  2467. return;
  2468. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  2469. if (mode == 0)
  2470. event_size = 2 * sizeof(u32);
  2471. else
  2472. event_size = 3 * sizeof(u32);
  2473. ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
  2474. /* "time" is actually "data" for mode 0 (no timestamp).
  2475. * place event id # at far right for easier visual parsing. */
  2476. for (i = 0; i < num_events; i++) {
  2477. ev = iwl_read_targ_mem(priv, ptr);
  2478. ptr += sizeof(u32);
  2479. time = iwl_read_targ_mem(priv, ptr);
  2480. ptr += sizeof(u32);
  2481. if (mode == 0) {
  2482. /* data, ev */
  2483. IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
  2484. } else {
  2485. data = iwl_read_targ_mem(priv, ptr);
  2486. ptr += sizeof(u32);
  2487. IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev);
  2488. }
  2489. }
  2490. }
  2491. static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
  2492. {
  2493. int rc;
  2494. u32 base; /* SRAM byte address of event log header */
  2495. u32 capacity; /* event log capacity in # entries */
  2496. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  2497. u32 num_wraps; /* # times uCode wrapped to top of log */
  2498. u32 next_entry; /* index of next entry to be written by uCode */
  2499. u32 size; /* # entries that we'll print */
  2500. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  2501. if (!iwl3945_hw_valid_rtc_data_addr(base)) {
  2502. IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
  2503. return;
  2504. }
  2505. rc = iwl_grab_nic_access(priv);
  2506. if (rc) {
  2507. IWL_WARN(priv, "Can not read from adapter at this time.\n");
  2508. return;
  2509. }
  2510. /* event log header */
  2511. capacity = iwl_read_targ_mem(priv, base);
  2512. mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
  2513. num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
  2514. next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
  2515. size = num_wraps ? capacity : next_entry;
  2516. /* bail out if nothing in log */
  2517. if (size == 0) {
  2518. IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
  2519. iwl_release_nic_access(priv);
  2520. return;
  2521. }
  2522. IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
  2523. size, num_wraps);
  2524. /* if uCode has wrapped back to top of log, start at the oldest entry,
  2525. * i.e the next one that uCode would fill. */
  2526. if (num_wraps)
  2527. iwl3945_print_event_log(priv, next_entry,
  2528. capacity - next_entry, mode);
  2529. /* (then/else) start at top of log */
  2530. iwl3945_print_event_log(priv, 0, next_entry, mode);
  2531. iwl_release_nic_access(priv);
  2532. }
  2533. /**
  2534. * iwl3945_irq_handle_error - called for HW or SW error interrupt from card
  2535. */
  2536. static void iwl3945_irq_handle_error(struct iwl_priv *priv)
  2537. {
  2538. /* Set the FW error flag -- cleared on iwl3945_down */
  2539. set_bit(STATUS_FW_ERROR, &priv->status);
  2540. /* Cancel currently queued command. */
  2541. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  2542. #ifdef CONFIG_IWLWIFI_DEBUG
  2543. if (priv->debug_level & IWL_DL_FW_ERRORS) {
  2544. iwl3945_dump_nic_error_log(priv);
  2545. iwl3945_dump_nic_event_log(priv);
  2546. iwl3945_print_rx_config_cmd(priv, &priv->staging39_rxon);
  2547. }
  2548. #endif
  2549. wake_up_interruptible(&priv->wait_command_queue);
  2550. /* Keep the restart process from trying to send host
  2551. * commands by clearing the INIT status bit */
  2552. clear_bit(STATUS_READY, &priv->status);
  2553. if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  2554. IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS,
  2555. "Restarting adapter due to uCode error.\n");
  2556. if (iwl3945_is_associated(priv)) {
  2557. memcpy(&priv->recovery39_rxon, &priv->active39_rxon,
  2558. sizeof(priv->recovery39_rxon));
  2559. priv->error_recovering = 1;
  2560. }
  2561. queue_work(priv->workqueue, &priv->restart);
  2562. }
  2563. }
  2564. static void iwl3945_error_recovery(struct iwl_priv *priv)
  2565. {
  2566. unsigned long flags;
  2567. memcpy(&priv->staging39_rxon, &priv->recovery39_rxon,
  2568. sizeof(priv->staging39_rxon));
  2569. priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2570. iwl3945_commit_rxon(priv);
  2571. iwl3945_add_station(priv, priv->bssid, 1, 0);
  2572. spin_lock_irqsave(&priv->lock, flags);
  2573. priv->assoc_id = le16_to_cpu(priv->staging39_rxon.assoc_id);
  2574. priv->error_recovering = 0;
  2575. spin_unlock_irqrestore(&priv->lock, flags);
  2576. }
  2577. static void iwl3945_irq_tasklet(struct iwl_priv *priv)
  2578. {
  2579. u32 inta, handled = 0;
  2580. u32 inta_fh;
  2581. unsigned long flags;
  2582. #ifdef CONFIG_IWLWIFI_DEBUG
  2583. u32 inta_mask;
  2584. #endif
  2585. spin_lock_irqsave(&priv->lock, flags);
  2586. /* Ack/clear/reset pending uCode interrupts.
  2587. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
  2588. * and will clear only when CSR_FH_INT_STATUS gets cleared. */
  2589. inta = iwl_read32(priv, CSR_INT);
  2590. iwl_write32(priv, CSR_INT, inta);
  2591. /* Ack/clear/reset pending flow-handler (DMA) interrupts.
  2592. * Any new interrupts that happen after this, either while we're
  2593. * in this tasklet, or later, will show up in next ISR/tasklet. */
  2594. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  2595. iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
  2596. #ifdef CONFIG_IWLWIFI_DEBUG
  2597. if (priv->debug_level & IWL_DL_ISR) {
  2598. /* just for debug */
  2599. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  2600. IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  2601. inta, inta_mask, inta_fh);
  2602. }
  2603. #endif
  2604. /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
  2605. * atomic, make sure that inta covers all the interrupts that
  2606. * we've discovered, even if FH interrupt came in just after
  2607. * reading CSR_INT. */
  2608. if (inta_fh & CSR39_FH_INT_RX_MASK)
  2609. inta |= CSR_INT_BIT_FH_RX;
  2610. if (inta_fh & CSR39_FH_INT_TX_MASK)
  2611. inta |= CSR_INT_BIT_FH_TX;
  2612. /* Now service all interrupt bits discovered above. */
  2613. if (inta & CSR_INT_BIT_HW_ERR) {
  2614. IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
  2615. /* Tell the device to stop sending interrupts */
  2616. iwl3945_disable_interrupts(priv);
  2617. iwl3945_irq_handle_error(priv);
  2618. handled |= CSR_INT_BIT_HW_ERR;
  2619. spin_unlock_irqrestore(&priv->lock, flags);
  2620. return;
  2621. }
  2622. #ifdef CONFIG_IWLWIFI_DEBUG
  2623. if (priv->debug_level & (IWL_DL_ISR)) {
  2624. /* NIC fires this, but we don't use it, redundant with WAKEUP */
  2625. if (inta & CSR_INT_BIT_SCD)
  2626. IWL_DEBUG_ISR("Scheduler finished to transmit "
  2627. "the frame/frames.\n");
  2628. /* Alive notification via Rx interrupt will do the real work */
  2629. if (inta & CSR_INT_BIT_ALIVE)
  2630. IWL_DEBUG_ISR("Alive interrupt\n");
  2631. }
  2632. #endif
  2633. /* Safely ignore these bits for debug checks below */
  2634. inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
  2635. /* Error detected by uCode */
  2636. if (inta & CSR_INT_BIT_SW_ERR) {
  2637. IWL_ERR(priv, "Microcode SW error detected. "
  2638. "Restarting 0x%X.\n", inta);
  2639. iwl3945_irq_handle_error(priv);
  2640. handled |= CSR_INT_BIT_SW_ERR;
  2641. }
  2642. /* uCode wakes up after power-down sleep */
  2643. if (inta & CSR_INT_BIT_WAKEUP) {
  2644. IWL_DEBUG_ISR("Wakeup interrupt\n");
  2645. iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
  2646. iwl_txq_update_write_ptr(priv, &priv->txq[0]);
  2647. iwl_txq_update_write_ptr(priv, &priv->txq[1]);
  2648. iwl_txq_update_write_ptr(priv, &priv->txq[2]);
  2649. iwl_txq_update_write_ptr(priv, &priv->txq[3]);
  2650. iwl_txq_update_write_ptr(priv, &priv->txq[4]);
  2651. iwl_txq_update_write_ptr(priv, &priv->txq[5]);
  2652. handled |= CSR_INT_BIT_WAKEUP;
  2653. }
  2654. /* All uCode command responses, including Tx command responses,
  2655. * Rx "responses" (frame-received notification), and other
  2656. * notifications from uCode come through here*/
  2657. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
  2658. iwl3945_rx_handle(priv);
  2659. handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
  2660. }
  2661. if (inta & CSR_INT_BIT_FH_TX) {
  2662. IWL_DEBUG_ISR("Tx interrupt\n");
  2663. iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
  2664. if (!iwl_grab_nic_access(priv)) {
  2665. iwl_write_direct32(priv, FH39_TCSR_CREDIT
  2666. (FH39_SRVC_CHNL), 0x0);
  2667. iwl_release_nic_access(priv);
  2668. }
  2669. handled |= CSR_INT_BIT_FH_TX;
  2670. }
  2671. if (inta & ~handled)
  2672. IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
  2673. if (inta & ~CSR_INI_SET_MASK) {
  2674. IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
  2675. inta & ~CSR_INI_SET_MASK);
  2676. IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
  2677. }
  2678. /* Re-enable all interrupts */
  2679. /* only Re-enable if disabled by irq */
  2680. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  2681. iwl3945_enable_interrupts(priv);
  2682. #ifdef CONFIG_IWLWIFI_DEBUG
  2683. if (priv->debug_level & (IWL_DL_ISR)) {
  2684. inta = iwl_read32(priv, CSR_INT);
  2685. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  2686. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  2687. IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
  2688. "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
  2689. }
  2690. #endif
  2691. spin_unlock_irqrestore(&priv->lock, flags);
  2692. }
  2693. static irqreturn_t iwl3945_isr(int irq, void *data)
  2694. {
  2695. struct iwl_priv *priv = data;
  2696. u32 inta, inta_mask;
  2697. u32 inta_fh;
  2698. if (!priv)
  2699. return IRQ_NONE;
  2700. spin_lock(&priv->lock);
  2701. /* Disable (but don't clear!) interrupts here to avoid
  2702. * back-to-back ISRs and sporadic interrupts from our NIC.
  2703. * If we have something to service, the tasklet will re-enable ints.
  2704. * If we *don't* have something, we'll re-enable before leaving here. */
  2705. inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
  2706. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  2707. /* Discover which interrupts are active/pending */
  2708. inta = iwl_read32(priv, CSR_INT);
  2709. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  2710. /* Ignore interrupt if there's nothing in NIC to service.
  2711. * This may be due to IRQ shared with another device,
  2712. * or due to sporadic interrupts thrown from our NIC. */
  2713. if (!inta && !inta_fh) {
  2714. IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
  2715. goto none;
  2716. }
  2717. if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
  2718. /* Hardware disappeared */
  2719. IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
  2720. goto unplugged;
  2721. }
  2722. IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  2723. inta, inta_mask, inta_fh);
  2724. inta &= ~CSR_INT_BIT_SCD;
  2725. /* iwl3945_irq_tasklet() will service interrupts and re-enable them */
  2726. if (likely(inta || inta_fh))
  2727. tasklet_schedule(&priv->irq_tasklet);
  2728. unplugged:
  2729. spin_unlock(&priv->lock);
  2730. return IRQ_HANDLED;
  2731. none:
  2732. /* re-enable interrupts here since we don't have anything to service. */
  2733. /* only Re-enable if disabled by irq */
  2734. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  2735. iwl3945_enable_interrupts(priv);
  2736. spin_unlock(&priv->lock);
  2737. return IRQ_NONE;
  2738. }
  2739. static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
  2740. enum ieee80211_band band,
  2741. u8 is_active, u8 n_probes,
  2742. struct iwl3945_scan_channel *scan_ch)
  2743. {
  2744. const struct ieee80211_channel *channels = NULL;
  2745. const struct ieee80211_supported_band *sband;
  2746. const struct iwl_channel_info *ch_info;
  2747. u16 passive_dwell = 0;
  2748. u16 active_dwell = 0;
  2749. int added, i;
  2750. sband = iwl_get_hw_mode(priv, band);
  2751. if (!sband)
  2752. return 0;
  2753. channels = sband->channels;
  2754. active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
  2755. passive_dwell = iwl_get_passive_dwell_time(priv, band);
  2756. if (passive_dwell <= active_dwell)
  2757. passive_dwell = active_dwell + 1;
  2758. for (i = 0, added = 0; i < sband->n_channels; i++) {
  2759. if (channels[i].flags & IEEE80211_CHAN_DISABLED)
  2760. continue;
  2761. scan_ch->channel = channels[i].hw_value;
  2762. ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
  2763. if (!is_channel_valid(ch_info)) {
  2764. IWL_DEBUG_SCAN("Channel %d is INVALID for this band.\n",
  2765. scan_ch->channel);
  2766. continue;
  2767. }
  2768. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  2769. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  2770. /* If passive , set up for auto-switch
  2771. * and use long active_dwell time.
  2772. */
  2773. if (!is_active || is_channel_passive(ch_info) ||
  2774. (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
  2775. scan_ch->type = 0; /* passive */
  2776. if (IWL_UCODE_API(priv->ucode_ver) == 1)
  2777. scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
  2778. } else {
  2779. scan_ch->type = 1; /* active */
  2780. }
  2781. /* Set direct probe bits. These may be used both for active
  2782. * scan channels (probes gets sent right away),
  2783. * or for passive channels (probes get se sent only after
  2784. * hearing clear Rx packet).*/
  2785. if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
  2786. if (n_probes)
  2787. scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes);
  2788. } else {
  2789. /* uCode v1 does not allow setting direct probe bits on
  2790. * passive channel. */
  2791. if ((scan_ch->type & 1) && n_probes)
  2792. scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes);
  2793. }
  2794. /* Set txpower levels to defaults */
  2795. scan_ch->tpc.dsp_atten = 110;
  2796. /* scan_pwr_info->tpc.dsp_atten; */
  2797. /*scan_pwr_info->tpc.tx_gain; */
  2798. if (band == IEEE80211_BAND_5GHZ)
  2799. scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
  2800. else {
  2801. scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
  2802. /* NOTE: if we were doing 6Mb OFDM for scans we'd use
  2803. * power level:
  2804. * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
  2805. */
  2806. }
  2807. IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
  2808. scan_ch->channel,
  2809. (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
  2810. (scan_ch->type & 1) ?
  2811. active_dwell : passive_dwell);
  2812. scan_ch++;
  2813. added++;
  2814. }
  2815. IWL_DEBUG_SCAN("total channels to scan %d \n", added);
  2816. return added;
  2817. }
  2818. static void iwl3945_init_hw_rates(struct iwl_priv *priv,
  2819. struct ieee80211_rate *rates)
  2820. {
  2821. int i;
  2822. for (i = 0; i < IWL_RATE_COUNT; i++) {
  2823. rates[i].bitrate = iwl3945_rates[i].ieee * 5;
  2824. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  2825. rates[i].hw_value_short = i;
  2826. rates[i].flags = 0;
  2827. if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
  2828. /*
  2829. * If CCK != 1M then set short preamble rate flag.
  2830. */
  2831. rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
  2832. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  2833. }
  2834. }
  2835. }
  2836. /******************************************************************************
  2837. *
  2838. * uCode download functions
  2839. *
  2840. ******************************************************************************/
  2841. static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
  2842. {
  2843. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
  2844. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
  2845. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  2846. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
  2847. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  2848. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
  2849. }
  2850. /**
  2851. * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
  2852. * looking at all data.
  2853. */
  2854. static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
  2855. {
  2856. u32 val;
  2857. u32 save_len = len;
  2858. int rc = 0;
  2859. u32 errcnt;
  2860. IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
  2861. rc = iwl_grab_nic_access(priv);
  2862. if (rc)
  2863. return rc;
  2864. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  2865. IWL39_RTC_INST_LOWER_BOUND);
  2866. errcnt = 0;
  2867. for (; len > 0; len -= sizeof(u32), image++) {
  2868. /* read data comes through single port, auto-incr addr */
  2869. /* NOTE: Use the debugless read so we don't flood kernel log
  2870. * if IWL_DL_IO is set */
  2871. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  2872. if (val != le32_to_cpu(*image)) {
  2873. IWL_ERR(priv, "uCode INST section is invalid at "
  2874. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  2875. save_len - len, val, le32_to_cpu(*image));
  2876. rc = -EIO;
  2877. errcnt++;
  2878. if (errcnt >= 20)
  2879. break;
  2880. }
  2881. }
  2882. iwl_release_nic_access(priv);
  2883. if (!errcnt)
  2884. IWL_DEBUG_INFO("ucode image in INSTRUCTION memory is good\n");
  2885. return rc;
  2886. }
  2887. /**
  2888. * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
  2889. * using sample data 100 bytes apart. If these sample points are good,
  2890. * it's a pretty good bet that everything between them is good, too.
  2891. */
  2892. static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
  2893. {
  2894. u32 val;
  2895. int rc = 0;
  2896. u32 errcnt = 0;
  2897. u32 i;
  2898. IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
  2899. rc = iwl_grab_nic_access(priv);
  2900. if (rc)
  2901. return rc;
  2902. for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
  2903. /* read data comes through single port, auto-incr addr */
  2904. /* NOTE: Use the debugless read so we don't flood kernel log
  2905. * if IWL_DL_IO is set */
  2906. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  2907. i + IWL39_RTC_INST_LOWER_BOUND);
  2908. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  2909. if (val != le32_to_cpu(*image)) {
  2910. #if 0 /* Enable this if you want to see details */
  2911. IWL_ERR(priv, "uCode INST section is invalid at "
  2912. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  2913. i, val, *image);
  2914. #endif
  2915. rc = -EIO;
  2916. errcnt++;
  2917. if (errcnt >= 3)
  2918. break;
  2919. }
  2920. }
  2921. iwl_release_nic_access(priv);
  2922. return rc;
  2923. }
  2924. /**
  2925. * iwl3945_verify_ucode - determine which instruction image is in SRAM,
  2926. * and verify its contents
  2927. */
  2928. static int iwl3945_verify_ucode(struct iwl_priv *priv)
  2929. {
  2930. __le32 *image;
  2931. u32 len;
  2932. int rc = 0;
  2933. /* Try bootstrap */
  2934. image = (__le32 *)priv->ucode_boot.v_addr;
  2935. len = priv->ucode_boot.len;
  2936. rc = iwl3945_verify_inst_sparse(priv, image, len);
  2937. if (rc == 0) {
  2938. IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
  2939. return 0;
  2940. }
  2941. /* Try initialize */
  2942. image = (__le32 *)priv->ucode_init.v_addr;
  2943. len = priv->ucode_init.len;
  2944. rc = iwl3945_verify_inst_sparse(priv, image, len);
  2945. if (rc == 0) {
  2946. IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
  2947. return 0;
  2948. }
  2949. /* Try runtime/protocol */
  2950. image = (__le32 *)priv->ucode_code.v_addr;
  2951. len = priv->ucode_code.len;
  2952. rc = iwl3945_verify_inst_sparse(priv, image, len);
  2953. if (rc == 0) {
  2954. IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
  2955. return 0;
  2956. }
  2957. IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
  2958. /* Since nothing seems to match, show first several data entries in
  2959. * instruction SRAM, so maybe visual inspection will give a clue.
  2960. * Selection of bootstrap image (vs. other images) is arbitrary. */
  2961. image = (__le32 *)priv->ucode_boot.v_addr;
  2962. len = priv->ucode_boot.len;
  2963. rc = iwl3945_verify_inst_full(priv, image, len);
  2964. return rc;
  2965. }
  2966. static void iwl3945_nic_start(struct iwl_priv *priv)
  2967. {
  2968. /* Remove all resets to allow NIC to operate */
  2969. iwl_write32(priv, CSR_RESET, 0);
  2970. }
  2971. /**
  2972. * iwl3945_read_ucode - Read uCode images from disk file.
  2973. *
  2974. * Copy into buffers for card to fetch via bus-mastering
  2975. */
  2976. static int iwl3945_read_ucode(struct iwl_priv *priv)
  2977. {
  2978. struct iwl_ucode *ucode;
  2979. int ret = -EINVAL, index;
  2980. const struct firmware *ucode_raw;
  2981. /* firmware file name contains uCode/driver compatibility version */
  2982. const char *name_pre = priv->cfg->fw_name_pre;
  2983. const unsigned int api_max = priv->cfg->ucode_api_max;
  2984. const unsigned int api_min = priv->cfg->ucode_api_min;
  2985. char buf[25];
  2986. u8 *src;
  2987. size_t len;
  2988. u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
  2989. /* Ask kernel firmware_class module to get the boot firmware off disk.
  2990. * request_firmware() is synchronous, file is in memory on return. */
  2991. for (index = api_max; index >= api_min; index--) {
  2992. sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
  2993. ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
  2994. if (ret < 0) {
  2995. IWL_ERR(priv, "%s firmware file req failed: %d\n",
  2996. buf, ret);
  2997. if (ret == -ENOENT)
  2998. continue;
  2999. else
  3000. goto error;
  3001. } else {
  3002. if (index < api_max)
  3003. IWL_ERR(priv, "Loaded firmware %s, "
  3004. "which is deprecated. "
  3005. " Please use API v%u instead.\n",
  3006. buf, api_max);
  3007. IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
  3008. buf, ucode_raw->size);
  3009. break;
  3010. }
  3011. }
  3012. if (ret < 0)
  3013. goto error;
  3014. /* Make sure that we got at least our header! */
  3015. if (ucode_raw->size < sizeof(*ucode)) {
  3016. IWL_ERR(priv, "File size way too small!\n");
  3017. ret = -EINVAL;
  3018. goto err_release;
  3019. }
  3020. /* Data from ucode file: header followed by uCode images */
  3021. ucode = (void *)ucode_raw->data;
  3022. priv->ucode_ver = le32_to_cpu(ucode->ver);
  3023. api_ver = IWL_UCODE_API(priv->ucode_ver);
  3024. inst_size = le32_to_cpu(ucode->inst_size);
  3025. data_size = le32_to_cpu(ucode->data_size);
  3026. init_size = le32_to_cpu(ucode->init_size);
  3027. init_data_size = le32_to_cpu(ucode->init_data_size);
  3028. boot_size = le32_to_cpu(ucode->boot_size);
  3029. /* api_ver should match the api version forming part of the
  3030. * firmware filename ... but we don't check for that and only rely
  3031. * on the API version read from firware header from here on forward */
  3032. if (api_ver < api_min || api_ver > api_max) {
  3033. IWL_ERR(priv, "Driver unable to support your firmware API. "
  3034. "Driver supports v%u, firmware is v%u.\n",
  3035. api_max, api_ver);
  3036. priv->ucode_ver = 0;
  3037. ret = -EINVAL;
  3038. goto err_release;
  3039. }
  3040. if (api_ver != api_max)
  3041. IWL_ERR(priv, "Firmware has old API version. Expected %u, "
  3042. "got %u. New firmware can be obtained "
  3043. "from http://www.intellinuxwireless.org.\n",
  3044. api_max, api_ver);
  3045. IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
  3046. IWL_UCODE_MAJOR(priv->ucode_ver),
  3047. IWL_UCODE_MINOR(priv->ucode_ver),
  3048. IWL_UCODE_API(priv->ucode_ver),
  3049. IWL_UCODE_SERIAL(priv->ucode_ver));
  3050. IWL_DEBUG_INFO("f/w package hdr ucode version raw = 0x%x\n",
  3051. priv->ucode_ver);
  3052. IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", inst_size);
  3053. IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", data_size);
  3054. IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", init_size);
  3055. IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", init_data_size);
  3056. IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", boot_size);
  3057. /* Verify size of file vs. image size info in file's header */
  3058. if (ucode_raw->size < sizeof(*ucode) +
  3059. inst_size + data_size + init_size +
  3060. init_data_size + boot_size) {
  3061. IWL_DEBUG_INFO("uCode file size %d too small\n",
  3062. (int)ucode_raw->size);
  3063. ret = -EINVAL;
  3064. goto err_release;
  3065. }
  3066. /* Verify that uCode images will fit in card's SRAM */
  3067. if (inst_size > IWL39_MAX_INST_SIZE) {
  3068. IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
  3069. inst_size);
  3070. ret = -EINVAL;
  3071. goto err_release;
  3072. }
  3073. if (data_size > IWL39_MAX_DATA_SIZE) {
  3074. IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
  3075. data_size);
  3076. ret = -EINVAL;
  3077. goto err_release;
  3078. }
  3079. if (init_size > IWL39_MAX_INST_SIZE) {
  3080. IWL_DEBUG_INFO("uCode init instr len %d too large to fit in\n",
  3081. init_size);
  3082. ret = -EINVAL;
  3083. goto err_release;
  3084. }
  3085. if (init_data_size > IWL39_MAX_DATA_SIZE) {
  3086. IWL_DEBUG_INFO("uCode init data len %d too large to fit in\n",
  3087. init_data_size);
  3088. ret = -EINVAL;
  3089. goto err_release;
  3090. }
  3091. if (boot_size > IWL39_MAX_BSM_SIZE) {
  3092. IWL_DEBUG_INFO("uCode boot instr len %d too large to fit in\n",
  3093. boot_size);
  3094. ret = -EINVAL;
  3095. goto err_release;
  3096. }
  3097. /* Allocate ucode buffers for card's bus-master loading ... */
  3098. /* Runtime instructions and 2 copies of data:
  3099. * 1) unmodified from disk
  3100. * 2) backup cache for save/restore during power-downs */
  3101. priv->ucode_code.len = inst_size;
  3102. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
  3103. priv->ucode_data.len = data_size;
  3104. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
  3105. priv->ucode_data_backup.len = data_size;
  3106. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  3107. if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
  3108. !priv->ucode_data_backup.v_addr)
  3109. goto err_pci_alloc;
  3110. /* Initialization instructions and data */
  3111. if (init_size && init_data_size) {
  3112. priv->ucode_init.len = init_size;
  3113. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
  3114. priv->ucode_init_data.len = init_data_size;
  3115. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  3116. if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
  3117. goto err_pci_alloc;
  3118. }
  3119. /* Bootstrap (instructions only, no data) */
  3120. if (boot_size) {
  3121. priv->ucode_boot.len = boot_size;
  3122. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
  3123. if (!priv->ucode_boot.v_addr)
  3124. goto err_pci_alloc;
  3125. }
  3126. /* Copy images into buffers for card's bus-master reads ... */
  3127. /* Runtime instructions (first block of data in file) */
  3128. src = &ucode->data[0];
  3129. len = priv->ucode_code.len;
  3130. IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
  3131. memcpy(priv->ucode_code.v_addr, src, len);
  3132. IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
  3133. priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
  3134. /* Runtime data (2nd block)
  3135. * NOTE: Copy into backup buffer will be done in iwl3945_up() */
  3136. src = &ucode->data[inst_size];
  3137. len = priv->ucode_data.len;
  3138. IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
  3139. memcpy(priv->ucode_data.v_addr, src, len);
  3140. memcpy(priv->ucode_data_backup.v_addr, src, len);
  3141. /* Initialization instructions (3rd block) */
  3142. if (init_size) {
  3143. src = &ucode->data[inst_size + data_size];
  3144. len = priv->ucode_init.len;
  3145. IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
  3146. len);
  3147. memcpy(priv->ucode_init.v_addr, src, len);
  3148. }
  3149. /* Initialization data (4th block) */
  3150. if (init_data_size) {
  3151. src = &ucode->data[inst_size + data_size + init_size];
  3152. len = priv->ucode_init_data.len;
  3153. IWL_DEBUG_INFO("Copying (but not loading) init data len %d\n",
  3154. (int)len);
  3155. memcpy(priv->ucode_init_data.v_addr, src, len);
  3156. }
  3157. /* Bootstrap instructions (5th block) */
  3158. src = &ucode->data[inst_size + data_size + init_size + init_data_size];
  3159. len = priv->ucode_boot.len;
  3160. IWL_DEBUG_INFO("Copying (but not loading) boot instr len %d\n",
  3161. (int)len);
  3162. memcpy(priv->ucode_boot.v_addr, src, len);
  3163. /* We have our copies now, allow OS release its copies */
  3164. release_firmware(ucode_raw);
  3165. return 0;
  3166. err_pci_alloc:
  3167. IWL_ERR(priv, "failed to allocate pci memory\n");
  3168. ret = -ENOMEM;
  3169. iwl3945_dealloc_ucode_pci(priv);
  3170. err_release:
  3171. release_firmware(ucode_raw);
  3172. error:
  3173. return ret;
  3174. }
  3175. /**
  3176. * iwl3945_set_ucode_ptrs - Set uCode address location
  3177. *
  3178. * Tell initialization uCode where to find runtime uCode.
  3179. *
  3180. * BSM registers initially contain pointers to initialization uCode.
  3181. * We need to replace them to load runtime uCode inst and data,
  3182. * and to save runtime data when powering down.
  3183. */
  3184. static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
  3185. {
  3186. dma_addr_t pinst;
  3187. dma_addr_t pdata;
  3188. int rc = 0;
  3189. unsigned long flags;
  3190. /* bits 31:0 for 3945 */
  3191. pinst = priv->ucode_code.p_addr;
  3192. pdata = priv->ucode_data_backup.p_addr;
  3193. spin_lock_irqsave(&priv->lock, flags);
  3194. rc = iwl_grab_nic_access(priv);
  3195. if (rc) {
  3196. spin_unlock_irqrestore(&priv->lock, flags);
  3197. return rc;
  3198. }
  3199. /* Tell bootstrap uCode where to find image to load */
  3200. iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
  3201. iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
  3202. iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
  3203. priv->ucode_data.len);
  3204. /* Inst byte count must be last to set up, bit 31 signals uCode
  3205. * that all new ptr/size info is in place */
  3206. iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
  3207. priv->ucode_code.len | BSM_DRAM_INST_LOAD);
  3208. iwl_release_nic_access(priv);
  3209. spin_unlock_irqrestore(&priv->lock, flags);
  3210. IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
  3211. return rc;
  3212. }
  3213. /**
  3214. * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
  3215. *
  3216. * Called after REPLY_ALIVE notification received from "initialize" uCode.
  3217. *
  3218. * Tell "initialize" uCode to go ahead and load the runtime uCode.
  3219. */
  3220. static void iwl3945_init_alive_start(struct iwl_priv *priv)
  3221. {
  3222. /* Check alive response for "valid" sign from uCode */
  3223. if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
  3224. /* We had an error bringing up the hardware, so take it
  3225. * all the way back down so we can try again */
  3226. IWL_DEBUG_INFO("Initialize Alive failed.\n");
  3227. goto restart;
  3228. }
  3229. /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
  3230. * This is a paranoid check, because we would not have gotten the
  3231. * "initialize" alive if code weren't properly loaded. */
  3232. if (iwl3945_verify_ucode(priv)) {
  3233. /* Runtime instruction load was bad;
  3234. * take it all the way back down so we can try again */
  3235. IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
  3236. goto restart;
  3237. }
  3238. /* Send pointers to protocol/runtime uCode image ... init code will
  3239. * load and launch runtime uCode, which will send us another "Alive"
  3240. * notification. */
  3241. IWL_DEBUG_INFO("Initialization Alive received.\n");
  3242. if (iwl3945_set_ucode_ptrs(priv)) {
  3243. /* Runtime instruction load won't happen;
  3244. * take it all the way back down so we can try again */
  3245. IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
  3246. goto restart;
  3247. }
  3248. return;
  3249. restart:
  3250. queue_work(priv->workqueue, &priv->restart);
  3251. }
  3252. /* temporary */
  3253. static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw,
  3254. struct sk_buff *skb);
  3255. /**
  3256. * iwl3945_alive_start - called after REPLY_ALIVE notification received
  3257. * from protocol/runtime uCode (initialization uCode's
  3258. * Alive gets handled by iwl3945_init_alive_start()).
  3259. */
  3260. static void iwl3945_alive_start(struct iwl_priv *priv)
  3261. {
  3262. int rc = 0;
  3263. int thermal_spin = 0;
  3264. u32 rfkill;
  3265. IWL_DEBUG_INFO("Runtime Alive received.\n");
  3266. if (priv->card_alive.is_valid != UCODE_VALID_OK) {
  3267. /* We had an error bringing up the hardware, so take it
  3268. * all the way back down so we can try again */
  3269. IWL_DEBUG_INFO("Alive failed.\n");
  3270. goto restart;
  3271. }
  3272. /* Initialize uCode has loaded Runtime uCode ... verify inst image.
  3273. * This is a paranoid check, because we would not have gotten the
  3274. * "runtime" alive if code weren't properly loaded. */
  3275. if (iwl3945_verify_ucode(priv)) {
  3276. /* Runtime instruction load was bad;
  3277. * take it all the way back down so we can try again */
  3278. IWL_DEBUG_INFO("Bad runtime uCode load.\n");
  3279. goto restart;
  3280. }
  3281. iwl3945_clear_stations_table(priv);
  3282. rc = iwl_grab_nic_access(priv);
  3283. if (rc) {
  3284. IWL_WARN(priv, "Can not read RFKILL status from adapter\n");
  3285. return;
  3286. }
  3287. rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
  3288. IWL_DEBUG_INFO("RFKILL status: 0x%x\n", rfkill);
  3289. iwl_release_nic_access(priv);
  3290. if (rfkill & 0x1) {
  3291. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  3292. /* if RFKILL is not on, then wait for thermal
  3293. * sensor in adapter to kick in */
  3294. while (iwl3945_hw_get_temperature(priv) == 0) {
  3295. thermal_spin++;
  3296. udelay(10);
  3297. }
  3298. if (thermal_spin)
  3299. IWL_DEBUG_INFO("Thermal calibration took %dus\n",
  3300. thermal_spin * 10);
  3301. } else
  3302. set_bit(STATUS_RF_KILL_HW, &priv->status);
  3303. /* After the ALIVE response, we can send commands to 3945 uCode */
  3304. set_bit(STATUS_ALIVE, &priv->status);
  3305. /* Clear out the uCode error bit if it is set */
  3306. clear_bit(STATUS_FW_ERROR, &priv->status);
  3307. if (iwl_is_rfkill(priv))
  3308. return;
  3309. ieee80211_wake_queues(priv->hw);
  3310. priv->active_rate = priv->rates_mask;
  3311. priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
  3312. iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode));
  3313. if (iwl3945_is_associated(priv)) {
  3314. struct iwl3945_rxon_cmd *active_rxon =
  3315. (struct iwl3945_rxon_cmd *)(&priv->active39_rxon);
  3316. memcpy(&priv->staging39_rxon, &priv->active39_rxon,
  3317. sizeof(priv->staging39_rxon));
  3318. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3319. } else {
  3320. /* Initialize our rx_config data */
  3321. iwl3945_connection_init_rx_config(priv, priv->iw_mode);
  3322. memcpy(priv->staging39_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  3323. }
  3324. /* Configure Bluetooth device coexistence support */
  3325. iwl3945_send_bt_config(priv);
  3326. /* Configure the adapter for unassociated operation */
  3327. iwl3945_commit_rxon(priv);
  3328. iwl3945_reg_txpower_periodic(priv);
  3329. iwl3945_led_register(priv);
  3330. IWL_DEBUG_INFO("ALIVE processing complete.\n");
  3331. set_bit(STATUS_READY, &priv->status);
  3332. wake_up_interruptible(&priv->wait_command_queue);
  3333. if (priv->error_recovering)
  3334. iwl3945_error_recovery(priv);
  3335. /* reassociate for ADHOC mode */
  3336. if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
  3337. struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
  3338. priv->vif);
  3339. if (beacon)
  3340. iwl3945_mac_beacon_update(priv->hw, beacon);
  3341. }
  3342. return;
  3343. restart:
  3344. queue_work(priv->workqueue, &priv->restart);
  3345. }
  3346. static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
  3347. static void __iwl3945_down(struct iwl_priv *priv)
  3348. {
  3349. unsigned long flags;
  3350. int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
  3351. struct ieee80211_conf *conf = NULL;
  3352. IWL_DEBUG_INFO(DRV_NAME " is going down\n");
  3353. conf = ieee80211_get_hw_conf(priv->hw);
  3354. if (!exit_pending)
  3355. set_bit(STATUS_EXIT_PENDING, &priv->status);
  3356. iwl3945_led_unregister(priv);
  3357. iwl3945_clear_stations_table(priv);
  3358. /* Unblock any waiting calls */
  3359. wake_up_interruptible_all(&priv->wait_command_queue);
  3360. /* Wipe out the EXIT_PENDING status bit if we are not actually
  3361. * exiting the module */
  3362. if (!exit_pending)
  3363. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  3364. /* stop and reset the on-board processor */
  3365. iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  3366. /* tell the device to stop sending interrupts */
  3367. spin_lock_irqsave(&priv->lock, flags);
  3368. iwl3945_disable_interrupts(priv);
  3369. spin_unlock_irqrestore(&priv->lock, flags);
  3370. iwl_synchronize_irq(priv);
  3371. if (priv->mac80211_registered)
  3372. ieee80211_stop_queues(priv->hw);
  3373. /* If we have not previously called iwl3945_init() then
  3374. * clear all bits but the RF Kill and SUSPEND bits and return */
  3375. if (!iwl_is_init(priv)) {
  3376. priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  3377. STATUS_RF_KILL_HW |
  3378. test_bit(STATUS_RF_KILL_SW, &priv->status) <<
  3379. STATUS_RF_KILL_SW |
  3380. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  3381. STATUS_GEO_CONFIGURED |
  3382. test_bit(STATUS_IN_SUSPEND, &priv->status) <<
  3383. STATUS_IN_SUSPEND |
  3384. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  3385. STATUS_EXIT_PENDING;
  3386. goto exit;
  3387. }
  3388. /* ...otherwise clear out all the status bits but the RF Kill and
  3389. * SUSPEND bits and continue taking the NIC down. */
  3390. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  3391. STATUS_RF_KILL_HW |
  3392. test_bit(STATUS_RF_KILL_SW, &priv->status) <<
  3393. STATUS_RF_KILL_SW |
  3394. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  3395. STATUS_GEO_CONFIGURED |
  3396. test_bit(STATUS_IN_SUSPEND, &priv->status) <<
  3397. STATUS_IN_SUSPEND |
  3398. test_bit(STATUS_FW_ERROR, &priv->status) <<
  3399. STATUS_FW_ERROR |
  3400. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  3401. STATUS_EXIT_PENDING;
  3402. priv->cfg->ops->lib->apm_ops.reset(priv);
  3403. spin_lock_irqsave(&priv->lock, flags);
  3404. iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  3405. spin_unlock_irqrestore(&priv->lock, flags);
  3406. iwl3945_hw_txq_ctx_stop(priv);
  3407. iwl3945_hw_rxq_stop(priv);
  3408. spin_lock_irqsave(&priv->lock, flags);
  3409. if (!iwl_grab_nic_access(priv)) {
  3410. iwl_write_prph(priv, APMG_CLK_DIS_REG,
  3411. APMG_CLK_VAL_DMA_CLK_RQT);
  3412. iwl_release_nic_access(priv);
  3413. }
  3414. spin_unlock_irqrestore(&priv->lock, flags);
  3415. udelay(5);
  3416. if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
  3417. priv->cfg->ops->lib->apm_ops.stop(priv);
  3418. else
  3419. priv->cfg->ops->lib->apm_ops.reset(priv);
  3420. exit:
  3421. memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
  3422. if (priv->ibss_beacon)
  3423. dev_kfree_skb(priv->ibss_beacon);
  3424. priv->ibss_beacon = NULL;
  3425. /* clear out any free frames */
  3426. iwl3945_clear_free_frames(priv);
  3427. }
  3428. static void iwl3945_down(struct iwl_priv *priv)
  3429. {
  3430. mutex_lock(&priv->mutex);
  3431. __iwl3945_down(priv);
  3432. mutex_unlock(&priv->mutex);
  3433. iwl3945_cancel_deferred_work(priv);
  3434. }
  3435. #define MAX_HW_RESTARTS 5
  3436. static int __iwl3945_up(struct iwl_priv *priv)
  3437. {
  3438. int rc, i;
  3439. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  3440. IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
  3441. return -EIO;
  3442. }
  3443. if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
  3444. IWL_WARN(priv, "Radio disabled by SW RF kill (module "
  3445. "parameter)\n");
  3446. return -ENODEV;
  3447. }
  3448. if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
  3449. IWL_ERR(priv, "ucode not available for device bring up\n");
  3450. return -EIO;
  3451. }
  3452. /* If platform's RF_KILL switch is NOT set to KILL */
  3453. if (iwl_read32(priv, CSR_GP_CNTRL) &
  3454. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  3455. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  3456. else {
  3457. set_bit(STATUS_RF_KILL_HW, &priv->status);
  3458. if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
  3459. IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
  3460. return -ENODEV;
  3461. }
  3462. }
  3463. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  3464. rc = iwl3945_hw_nic_init(priv);
  3465. if (rc) {
  3466. IWL_ERR(priv, "Unable to int nic\n");
  3467. return rc;
  3468. }
  3469. /* make sure rfkill handshake bits are cleared */
  3470. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  3471. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  3472. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  3473. /* clear (again), then enable host interrupts */
  3474. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  3475. iwl3945_enable_interrupts(priv);
  3476. /* really make sure rfkill handshake bits are cleared */
  3477. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  3478. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  3479. /* Copy original ucode data image from disk into backup cache.
  3480. * This will be used to initialize the on-board processor's
  3481. * data SRAM for a clean start when the runtime program first loads. */
  3482. memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
  3483. priv->ucode_data.len);
  3484. /* We return success when we resume from suspend and rf_kill is on. */
  3485. if (test_bit(STATUS_RF_KILL_HW, &priv->status))
  3486. return 0;
  3487. for (i = 0; i < MAX_HW_RESTARTS; i++) {
  3488. iwl3945_clear_stations_table(priv);
  3489. /* load bootstrap state machine,
  3490. * load bootstrap program into processor's memory,
  3491. * prepare to load the "initialize" uCode */
  3492. priv->cfg->ops->lib->load_ucode(priv);
  3493. if (rc) {
  3494. IWL_ERR(priv,
  3495. "Unable to set up bootstrap uCode: %d\n", rc);
  3496. continue;
  3497. }
  3498. /* start card; "initialize" will load runtime ucode */
  3499. iwl3945_nic_start(priv);
  3500. IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
  3501. return 0;
  3502. }
  3503. set_bit(STATUS_EXIT_PENDING, &priv->status);
  3504. __iwl3945_down(priv);
  3505. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  3506. /* tried to restart and config the device for as long as our
  3507. * patience could withstand */
  3508. IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
  3509. return -EIO;
  3510. }
  3511. /*****************************************************************************
  3512. *
  3513. * Workqueue callbacks
  3514. *
  3515. *****************************************************************************/
  3516. static void iwl3945_bg_init_alive_start(struct work_struct *data)
  3517. {
  3518. struct iwl_priv *priv =
  3519. container_of(data, struct iwl_priv, init_alive_start.work);
  3520. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3521. return;
  3522. mutex_lock(&priv->mutex);
  3523. iwl3945_init_alive_start(priv);
  3524. mutex_unlock(&priv->mutex);
  3525. }
  3526. static void iwl3945_bg_alive_start(struct work_struct *data)
  3527. {
  3528. struct iwl_priv *priv =
  3529. container_of(data, struct iwl_priv, alive_start.work);
  3530. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3531. return;
  3532. mutex_lock(&priv->mutex);
  3533. iwl3945_alive_start(priv);
  3534. mutex_unlock(&priv->mutex);
  3535. }
  3536. static void iwl3945_rfkill_poll(struct work_struct *data)
  3537. {
  3538. struct iwl_priv *priv =
  3539. container_of(data, struct iwl_priv, rfkill_poll.work);
  3540. unsigned long status = priv->status;
  3541. if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  3542. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  3543. else
  3544. set_bit(STATUS_RF_KILL_HW, &priv->status);
  3545. if (test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status))
  3546. queue_work(priv->workqueue, &priv->rf_kill);
  3547. queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
  3548. round_jiffies_relative(2 * HZ));
  3549. }
  3550. #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
  3551. static void iwl3945_bg_request_scan(struct work_struct *data)
  3552. {
  3553. struct iwl_priv *priv =
  3554. container_of(data, struct iwl_priv, request_scan);
  3555. struct iwl_host_cmd cmd = {
  3556. .id = REPLY_SCAN_CMD,
  3557. .len = sizeof(struct iwl3945_scan_cmd),
  3558. .meta.flags = CMD_SIZE_HUGE,
  3559. };
  3560. int rc = 0;
  3561. struct iwl3945_scan_cmd *scan;
  3562. struct ieee80211_conf *conf = NULL;
  3563. u8 n_probes = 2;
  3564. enum ieee80211_band band;
  3565. DECLARE_SSID_BUF(ssid);
  3566. conf = ieee80211_get_hw_conf(priv->hw);
  3567. mutex_lock(&priv->mutex);
  3568. if (!iwl_is_ready(priv)) {
  3569. IWL_WARN(priv, "request scan called when driver not ready.\n");
  3570. goto done;
  3571. }
  3572. /* Make sure the scan wasn't canceled before this queued work
  3573. * was given the chance to run... */
  3574. if (!test_bit(STATUS_SCANNING, &priv->status))
  3575. goto done;
  3576. /* This should never be called or scheduled if there is currently
  3577. * a scan active in the hardware. */
  3578. if (test_bit(STATUS_SCAN_HW, &priv->status)) {
  3579. IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
  3580. "Ignoring second request.\n");
  3581. rc = -EIO;
  3582. goto done;
  3583. }
  3584. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  3585. IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
  3586. goto done;
  3587. }
  3588. if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
  3589. IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
  3590. goto done;
  3591. }
  3592. if (iwl_is_rfkill(priv)) {
  3593. IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
  3594. goto done;
  3595. }
  3596. if (!test_bit(STATUS_READY, &priv->status)) {
  3597. IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
  3598. goto done;
  3599. }
  3600. if (!priv->scan_bands) {
  3601. IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
  3602. goto done;
  3603. }
  3604. if (!priv->scan) {
  3605. priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
  3606. IWL_MAX_SCAN_SIZE, GFP_KERNEL);
  3607. if (!priv->scan) {
  3608. rc = -ENOMEM;
  3609. goto done;
  3610. }
  3611. }
  3612. scan = priv->scan;
  3613. memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
  3614. scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
  3615. scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
  3616. if (iwl3945_is_associated(priv)) {
  3617. u16 interval = 0;
  3618. u32 extra;
  3619. u32 suspend_time = 100;
  3620. u32 scan_suspend_time = 100;
  3621. unsigned long flags;
  3622. IWL_DEBUG_INFO("Scanning while associated...\n");
  3623. spin_lock_irqsave(&priv->lock, flags);
  3624. interval = priv->beacon_int;
  3625. spin_unlock_irqrestore(&priv->lock, flags);
  3626. scan->suspend_time = 0;
  3627. scan->max_out_time = cpu_to_le32(200 * 1024);
  3628. if (!interval)
  3629. interval = suspend_time;
  3630. /*
  3631. * suspend time format:
  3632. * 0-19: beacon interval in usec (time before exec.)
  3633. * 20-23: 0
  3634. * 24-31: number of beacons (suspend between channels)
  3635. */
  3636. extra = (suspend_time / interval) << 24;
  3637. scan_suspend_time = 0xFF0FFFFF &
  3638. (extra | ((suspend_time % interval) * 1024));
  3639. scan->suspend_time = cpu_to_le32(scan_suspend_time);
  3640. IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
  3641. scan_suspend_time, interval);
  3642. }
  3643. /* We should add the ability for user to lock to PASSIVE ONLY */
  3644. if (priv->one_direct_scan) {
  3645. IWL_DEBUG_SCAN
  3646. ("Kicking off one direct scan for '%s'\n",
  3647. print_ssid(ssid, priv->direct_ssid,
  3648. priv->direct_ssid_len));
  3649. scan->direct_scan[0].id = WLAN_EID_SSID;
  3650. scan->direct_scan[0].len = priv->direct_ssid_len;
  3651. memcpy(scan->direct_scan[0].ssid,
  3652. priv->direct_ssid, priv->direct_ssid_len);
  3653. n_probes++;
  3654. } else
  3655. IWL_DEBUG_SCAN("Kicking off one indirect scan.\n");
  3656. /* We don't build a direct scan probe request; the uCode will do
  3657. * that based on the direct_mask added to each channel entry */
  3658. scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
  3659. scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
  3660. scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  3661. /* flags + rate selection */
  3662. if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
  3663. scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
  3664. scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
  3665. scan->good_CRC_th = 0;
  3666. band = IEEE80211_BAND_2GHZ;
  3667. } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
  3668. scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
  3669. scan->good_CRC_th = IWL_GOOD_CRC_TH;
  3670. band = IEEE80211_BAND_5GHZ;
  3671. } else {
  3672. IWL_WARN(priv, "Invalid scan band count\n");
  3673. goto done;
  3674. }
  3675. scan->tx_cmd.len = cpu_to_le16(
  3676. iwl_fill_probe_req(priv, band,
  3677. (struct ieee80211_mgmt *)scan->data,
  3678. IWL_MAX_SCAN_SIZE - sizeof(*scan)));
  3679. /* select Rx antennas */
  3680. scan->flags |= iwl3945_get_antenna_flags(priv);
  3681. if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
  3682. scan->filter_flags = RXON_FILTER_PROMISC_MSK;
  3683. scan->channel_count =
  3684. iwl3945_get_channels_for_scan(priv, band, 1, /* active */
  3685. n_probes,
  3686. (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
  3687. if (scan->channel_count == 0) {
  3688. IWL_DEBUG_SCAN("channel count %d\n", scan->channel_count);
  3689. goto done;
  3690. }
  3691. cmd.len += le16_to_cpu(scan->tx_cmd.len) +
  3692. scan->channel_count * sizeof(struct iwl3945_scan_channel);
  3693. cmd.data = scan;
  3694. scan->len = cpu_to_le16(cmd.len);
  3695. set_bit(STATUS_SCAN_HW, &priv->status);
  3696. rc = iwl_send_cmd_sync(priv, &cmd);
  3697. if (rc)
  3698. goto done;
  3699. queue_delayed_work(priv->workqueue, &priv->scan_check,
  3700. IWL_SCAN_CHECK_WATCHDOG);
  3701. mutex_unlock(&priv->mutex);
  3702. return;
  3703. done:
  3704. /* can not perform scan make sure we clear scanning
  3705. * bits from status so next scan request can be performed.
  3706. * if we dont clear scanning status bit here all next scan
  3707. * will fail
  3708. */
  3709. clear_bit(STATUS_SCAN_HW, &priv->status);
  3710. clear_bit(STATUS_SCANNING, &priv->status);
  3711. /* inform mac80211 scan aborted */
  3712. queue_work(priv->workqueue, &priv->scan_completed);
  3713. mutex_unlock(&priv->mutex);
  3714. }
  3715. static void iwl3945_bg_up(struct work_struct *data)
  3716. {
  3717. struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
  3718. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3719. return;
  3720. mutex_lock(&priv->mutex);
  3721. __iwl3945_up(priv);
  3722. mutex_unlock(&priv->mutex);
  3723. iwl_rfkill_set_hw_state(priv);
  3724. }
  3725. static void iwl3945_bg_restart(struct work_struct *data)
  3726. {
  3727. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  3728. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3729. return;
  3730. iwl3945_down(priv);
  3731. queue_work(priv->workqueue, &priv->up);
  3732. }
  3733. static void iwl3945_bg_rx_replenish(struct work_struct *data)
  3734. {
  3735. struct iwl_priv *priv =
  3736. container_of(data, struct iwl_priv, rx_replenish);
  3737. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3738. return;
  3739. mutex_lock(&priv->mutex);
  3740. iwl3945_rx_replenish(priv);
  3741. mutex_unlock(&priv->mutex);
  3742. }
  3743. #define IWL_DELAY_NEXT_SCAN (HZ*2)
  3744. static void iwl3945_post_associate(struct iwl_priv *priv)
  3745. {
  3746. int rc = 0;
  3747. struct ieee80211_conf *conf = NULL;
  3748. if (priv->iw_mode == NL80211_IFTYPE_AP) {
  3749. IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
  3750. return;
  3751. }
  3752. IWL_DEBUG_ASSOC("Associated as %d to: %pM\n",
  3753. priv->assoc_id, priv->active39_rxon.bssid_addr);
  3754. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  3755. return;
  3756. if (!priv->vif || !priv->is_open)
  3757. return;
  3758. iwl_scan_cancel_timeout(priv, 200);
  3759. conf = ieee80211_get_hw_conf(priv->hw);
  3760. priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  3761. iwl3945_commit_rxon(priv);
  3762. memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
  3763. iwl3945_setup_rxon_timing(priv);
  3764. rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
  3765. sizeof(priv->rxon_timing), &priv->rxon_timing);
  3766. if (rc)
  3767. IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
  3768. "Attempting to continue.\n");
  3769. priv->staging39_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  3770. priv->staging39_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
  3771. IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
  3772. priv->assoc_id, priv->beacon_int);
  3773. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  3774. priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  3775. else
  3776. priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  3777. if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) {
  3778. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
  3779. priv->staging39_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  3780. else
  3781. priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  3782. if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
  3783. priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  3784. }
  3785. iwl3945_commit_rxon(priv);
  3786. switch (priv->iw_mode) {
  3787. case NL80211_IFTYPE_STATION:
  3788. iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
  3789. break;
  3790. case NL80211_IFTYPE_ADHOC:
  3791. priv->assoc_id = 1;
  3792. iwl3945_add_station(priv, priv->bssid, 0, 0);
  3793. iwl3945_sync_sta(priv, IWL_STA_ID,
  3794. (priv->band == IEEE80211_BAND_5GHZ) ?
  3795. IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
  3796. CMD_ASYNC);
  3797. iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
  3798. iwl3945_send_beacon_cmd(priv);
  3799. break;
  3800. default:
  3801. IWL_ERR(priv, "%s Should not be called in %d mode\n",
  3802. __func__, priv->iw_mode);
  3803. break;
  3804. }
  3805. iwl3945_activate_qos(priv, 0);
  3806. /* we have just associated, don't start scan too early */
  3807. priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
  3808. }
  3809. static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed);
  3810. /*****************************************************************************
  3811. *
  3812. * mac80211 entry point functions
  3813. *
  3814. *****************************************************************************/
  3815. #define UCODE_READY_TIMEOUT (2 * HZ)
  3816. static int iwl3945_mac_start(struct ieee80211_hw *hw)
  3817. {
  3818. struct iwl_priv *priv = hw->priv;
  3819. int ret;
  3820. IWL_DEBUG_MAC80211("enter\n");
  3821. /* we should be verifying the device is ready to be opened */
  3822. mutex_lock(&priv->mutex);
  3823. memset(&priv->staging39_rxon, 0, sizeof(struct iwl3945_rxon_cmd));
  3824. /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
  3825. * ucode filename and max sizes are card-specific. */
  3826. if (!priv->ucode_code.len) {
  3827. ret = iwl3945_read_ucode(priv);
  3828. if (ret) {
  3829. IWL_ERR(priv, "Could not read microcode: %d\n", ret);
  3830. mutex_unlock(&priv->mutex);
  3831. goto out_release_irq;
  3832. }
  3833. }
  3834. ret = __iwl3945_up(priv);
  3835. mutex_unlock(&priv->mutex);
  3836. iwl_rfkill_set_hw_state(priv);
  3837. if (ret)
  3838. goto out_release_irq;
  3839. IWL_DEBUG_INFO("Start UP work.\n");
  3840. if (test_bit(STATUS_IN_SUSPEND, &priv->status))
  3841. return 0;
  3842. /* Wait for START_ALIVE from ucode. Otherwise callbacks from
  3843. * mac80211 will not be run successfully. */
  3844. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  3845. test_bit(STATUS_READY, &priv->status),
  3846. UCODE_READY_TIMEOUT);
  3847. if (!ret) {
  3848. if (!test_bit(STATUS_READY, &priv->status)) {
  3849. IWL_ERR(priv,
  3850. "Wait for START_ALIVE timeout after %dms.\n",
  3851. jiffies_to_msecs(UCODE_READY_TIMEOUT));
  3852. ret = -ETIMEDOUT;
  3853. goto out_release_irq;
  3854. }
  3855. }
  3856. /* ucode is running and will send rfkill notifications,
  3857. * no need to poll the killswitch state anymore */
  3858. cancel_delayed_work(&priv->rfkill_poll);
  3859. priv->is_open = 1;
  3860. IWL_DEBUG_MAC80211("leave\n");
  3861. return 0;
  3862. out_release_irq:
  3863. priv->is_open = 0;
  3864. IWL_DEBUG_MAC80211("leave - failed\n");
  3865. return ret;
  3866. }
  3867. static void iwl3945_mac_stop(struct ieee80211_hw *hw)
  3868. {
  3869. struct iwl_priv *priv = hw->priv;
  3870. IWL_DEBUG_MAC80211("enter\n");
  3871. if (!priv->is_open) {
  3872. IWL_DEBUG_MAC80211("leave - skip\n");
  3873. return;
  3874. }
  3875. priv->is_open = 0;
  3876. if (iwl_is_ready_rf(priv)) {
  3877. /* stop mac, cancel any scan request and clear
  3878. * RXON_FILTER_ASSOC_MSK BIT
  3879. */
  3880. mutex_lock(&priv->mutex);
  3881. iwl_scan_cancel_timeout(priv, 100);
  3882. mutex_unlock(&priv->mutex);
  3883. }
  3884. iwl3945_down(priv);
  3885. flush_workqueue(priv->workqueue);
  3886. /* start polling the killswitch state again */
  3887. queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
  3888. round_jiffies_relative(2 * HZ));
  3889. IWL_DEBUG_MAC80211("leave\n");
  3890. }
  3891. static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  3892. {
  3893. struct iwl_priv *priv = hw->priv;
  3894. IWL_DEBUG_MAC80211("enter\n");
  3895. IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  3896. ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
  3897. if (iwl3945_tx_skb(priv, skb))
  3898. dev_kfree_skb_any(skb);
  3899. IWL_DEBUG_MAC80211("leave\n");
  3900. return NETDEV_TX_OK;
  3901. }
  3902. static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
  3903. struct ieee80211_if_init_conf *conf)
  3904. {
  3905. struct iwl_priv *priv = hw->priv;
  3906. unsigned long flags;
  3907. IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
  3908. if (priv->vif) {
  3909. IWL_DEBUG_MAC80211("leave - vif != NULL\n");
  3910. return -EOPNOTSUPP;
  3911. }
  3912. spin_lock_irqsave(&priv->lock, flags);
  3913. priv->vif = conf->vif;
  3914. priv->iw_mode = conf->type;
  3915. spin_unlock_irqrestore(&priv->lock, flags);
  3916. mutex_lock(&priv->mutex);
  3917. if (conf->mac_addr) {
  3918. IWL_DEBUG_MAC80211("Set: %pM\n", conf->mac_addr);
  3919. memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
  3920. }
  3921. if (iwl_is_ready(priv))
  3922. iwl3945_set_mode(priv, conf->type);
  3923. mutex_unlock(&priv->mutex);
  3924. IWL_DEBUG_MAC80211("leave\n");
  3925. return 0;
  3926. }
  3927. /**
  3928. * iwl3945_mac_config - mac80211 config callback
  3929. *
  3930. * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
  3931. * be set inappropriately and the driver currently sets the hardware up to
  3932. * use it whenever needed.
  3933. */
  3934. static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed)
  3935. {
  3936. struct iwl_priv *priv = hw->priv;
  3937. const struct iwl_channel_info *ch_info;
  3938. struct ieee80211_conf *conf = &hw->conf;
  3939. unsigned long flags;
  3940. int ret = 0;
  3941. mutex_lock(&priv->mutex);
  3942. IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
  3943. if (!iwl_is_ready(priv)) {
  3944. IWL_DEBUG_MAC80211("leave - not ready\n");
  3945. ret = -EIO;
  3946. goto out;
  3947. }
  3948. if (unlikely(!iwl3945_mod_params.disable_hw_scan &&
  3949. test_bit(STATUS_SCANNING, &priv->status))) {
  3950. IWL_DEBUG_MAC80211("leave - scanning\n");
  3951. set_bit(STATUS_CONF_PENDING, &priv->status);
  3952. mutex_unlock(&priv->mutex);
  3953. return 0;
  3954. }
  3955. spin_lock_irqsave(&priv->lock, flags);
  3956. ch_info = iwl_get_channel_info(priv, conf->channel->band,
  3957. conf->channel->hw_value);
  3958. if (!is_channel_valid(ch_info)) {
  3959. IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this band.\n",
  3960. conf->channel->hw_value, conf->channel->band);
  3961. IWL_DEBUG_MAC80211("leave - invalid channel\n");
  3962. spin_unlock_irqrestore(&priv->lock, flags);
  3963. ret = -EINVAL;
  3964. goto out;
  3965. }
  3966. iwl3945_set_rxon_channel(priv, conf->channel->band, conf->channel->hw_value);
  3967. iwl3945_set_flags_for_phymode(priv, conf->channel->band);
  3968. /* The list of supported rates and rate mask can be different
  3969. * for each phymode; since the phymode may have changed, reset
  3970. * the rate mask to what mac80211 lists */
  3971. iwl3945_set_rate(priv);
  3972. spin_unlock_irqrestore(&priv->lock, flags);
  3973. #ifdef IEEE80211_CONF_CHANNEL_SWITCH
  3974. if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
  3975. iwl3945_hw_channel_switch(priv, conf->channel);
  3976. goto out;
  3977. }
  3978. #endif
  3979. iwl3945_radio_kill_sw(priv, !conf->radio_enabled);
  3980. if (!conf->radio_enabled) {
  3981. IWL_DEBUG_MAC80211("leave - radio disabled\n");
  3982. goto out;
  3983. }
  3984. if (iwl_is_rfkill(priv)) {
  3985. IWL_DEBUG_MAC80211("leave - RF kill\n");
  3986. ret = -EIO;
  3987. goto out;
  3988. }
  3989. iwl3945_set_rate(priv);
  3990. if (memcmp(&priv->active39_rxon,
  3991. &priv->staging39_rxon, sizeof(priv->staging39_rxon)))
  3992. iwl3945_commit_rxon(priv);
  3993. else
  3994. IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
  3995. IWL_DEBUG_MAC80211("leave\n");
  3996. out:
  3997. clear_bit(STATUS_CONF_PENDING, &priv->status);
  3998. mutex_unlock(&priv->mutex);
  3999. return ret;
  4000. }
  4001. static void iwl3945_config_ap(struct iwl_priv *priv)
  4002. {
  4003. int rc = 0;
  4004. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  4005. return;
  4006. /* The following should be done only at AP bring up */
  4007. if (!(iwl3945_is_associated(priv))) {
  4008. /* RXON - unassoc (to set timing command) */
  4009. priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  4010. iwl3945_commit_rxon(priv);
  4011. /* RXON Timing */
  4012. memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
  4013. iwl3945_setup_rxon_timing(priv);
  4014. rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
  4015. sizeof(priv->rxon_timing),
  4016. &priv->rxon_timing);
  4017. if (rc)
  4018. IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
  4019. "Attempting to continue.\n");
  4020. /* FIXME: what should be the assoc_id for AP? */
  4021. priv->staging39_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
  4022. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  4023. priv->staging39_rxon.flags |=
  4024. RXON_FLG_SHORT_PREAMBLE_MSK;
  4025. else
  4026. priv->staging39_rxon.flags &=
  4027. ~RXON_FLG_SHORT_PREAMBLE_MSK;
  4028. if (priv->staging39_rxon.flags & RXON_FLG_BAND_24G_MSK) {
  4029. if (priv->assoc_capability &
  4030. WLAN_CAPABILITY_SHORT_SLOT_TIME)
  4031. priv->staging39_rxon.flags |=
  4032. RXON_FLG_SHORT_SLOT_MSK;
  4033. else
  4034. priv->staging39_rxon.flags &=
  4035. ~RXON_FLG_SHORT_SLOT_MSK;
  4036. if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
  4037. priv->staging39_rxon.flags &=
  4038. ~RXON_FLG_SHORT_SLOT_MSK;
  4039. }
  4040. /* restore RXON assoc */
  4041. priv->staging39_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  4042. iwl3945_commit_rxon(priv);
  4043. iwl3945_add_station(priv, iwl_bcast_addr, 0, 0);
  4044. }
  4045. iwl3945_send_beacon_cmd(priv);
  4046. /* FIXME - we need to add code here to detect a totally new
  4047. * configuration, reset the AP, unassoc, rxon timing, assoc,
  4048. * clear sta table, add BCAST sta... */
  4049. }
  4050. static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
  4051. struct ieee80211_vif *vif,
  4052. struct ieee80211_if_conf *conf)
  4053. {
  4054. struct iwl_priv *priv = hw->priv;
  4055. int rc;
  4056. if (conf == NULL)
  4057. return -EIO;
  4058. if (priv->vif != vif) {
  4059. IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
  4060. return 0;
  4061. }
  4062. /* handle this temporarily here */
  4063. if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
  4064. conf->changed & IEEE80211_IFCC_BEACON) {
  4065. struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
  4066. if (!beacon)
  4067. return -ENOMEM;
  4068. mutex_lock(&priv->mutex);
  4069. rc = iwl3945_mac_beacon_update(hw, beacon);
  4070. mutex_unlock(&priv->mutex);
  4071. if (rc)
  4072. return rc;
  4073. }
  4074. if (!iwl_is_alive(priv))
  4075. return -EAGAIN;
  4076. mutex_lock(&priv->mutex);
  4077. if (conf->bssid)
  4078. IWL_DEBUG_MAC80211("bssid: %pM\n", conf->bssid);
  4079. /*
  4080. * very dubious code was here; the probe filtering flag is never set:
  4081. *
  4082. if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
  4083. !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
  4084. */
  4085. if (priv->iw_mode == NL80211_IFTYPE_AP) {
  4086. if (!conf->bssid) {
  4087. conf->bssid = priv->mac_addr;
  4088. memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
  4089. IWL_DEBUG_MAC80211("bssid was set to: %pM\n",
  4090. conf->bssid);
  4091. }
  4092. if (priv->ibss_beacon)
  4093. dev_kfree_skb(priv->ibss_beacon);
  4094. priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
  4095. }
  4096. if (iwl_is_rfkill(priv))
  4097. goto done;
  4098. if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
  4099. !is_multicast_ether_addr(conf->bssid)) {
  4100. /* If there is currently a HW scan going on in the background
  4101. * then we need to cancel it else the RXON below will fail. */
  4102. if (iwl_scan_cancel_timeout(priv, 100)) {
  4103. IWL_WARN(priv, "Aborted scan still in progress "
  4104. "after 100ms\n");
  4105. IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
  4106. mutex_unlock(&priv->mutex);
  4107. return -EAGAIN;
  4108. }
  4109. memcpy(priv->staging39_rxon.bssid_addr, conf->bssid, ETH_ALEN);
  4110. /* TODO: Audit driver for usage of these members and see
  4111. * if mac80211 deprecates them (priv->bssid looks like it
  4112. * shouldn't be there, but I haven't scanned the IBSS code
  4113. * to verify) - jpk */
  4114. memcpy(priv->bssid, conf->bssid, ETH_ALEN);
  4115. if (priv->iw_mode == NL80211_IFTYPE_AP)
  4116. iwl3945_config_ap(priv);
  4117. else {
  4118. rc = iwl3945_commit_rxon(priv);
  4119. if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
  4120. iwl3945_add_station(priv,
  4121. priv->active39_rxon.bssid_addr, 1, 0);
  4122. }
  4123. } else {
  4124. iwl_scan_cancel_timeout(priv, 100);
  4125. priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  4126. iwl3945_commit_rxon(priv);
  4127. }
  4128. done:
  4129. IWL_DEBUG_MAC80211("leave\n");
  4130. mutex_unlock(&priv->mutex);
  4131. return 0;
  4132. }
  4133. static void iwl3945_configure_filter(struct ieee80211_hw *hw,
  4134. unsigned int changed_flags,
  4135. unsigned int *total_flags,
  4136. int mc_count, struct dev_addr_list *mc_list)
  4137. {
  4138. struct iwl_priv *priv = hw->priv;
  4139. __le32 *filter_flags = &priv->staging39_rxon.filter_flags;
  4140. IWL_DEBUG_MAC80211("Enter: changed: 0x%x, total: 0x%x\n",
  4141. changed_flags, *total_flags);
  4142. if (changed_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) {
  4143. if (*total_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS))
  4144. *filter_flags |= RXON_FILTER_PROMISC_MSK;
  4145. else
  4146. *filter_flags &= ~RXON_FILTER_PROMISC_MSK;
  4147. }
  4148. if (changed_flags & FIF_ALLMULTI) {
  4149. if (*total_flags & FIF_ALLMULTI)
  4150. *filter_flags |= RXON_FILTER_ACCEPT_GRP_MSK;
  4151. else
  4152. *filter_flags &= ~RXON_FILTER_ACCEPT_GRP_MSK;
  4153. }
  4154. if (changed_flags & FIF_CONTROL) {
  4155. if (*total_flags & FIF_CONTROL)
  4156. *filter_flags |= RXON_FILTER_CTL2HOST_MSK;
  4157. else
  4158. *filter_flags &= ~RXON_FILTER_CTL2HOST_MSK;
  4159. }
  4160. if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
  4161. if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
  4162. *filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
  4163. else
  4164. *filter_flags &= ~RXON_FILTER_BCON_AWARE_MSK;
  4165. }
  4166. /* We avoid iwl_commit_rxon here to commit the new filter flags
  4167. * since mac80211 will call ieee80211_hw_config immediately.
  4168. * (mc_list is not supported at this time). Otherwise, we need to
  4169. * queue a background iwl_commit_rxon work.
  4170. */
  4171. *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
  4172. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
  4173. }
  4174. static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
  4175. struct ieee80211_if_init_conf *conf)
  4176. {
  4177. struct iwl_priv *priv = hw->priv;
  4178. IWL_DEBUG_MAC80211("enter\n");
  4179. mutex_lock(&priv->mutex);
  4180. if (iwl_is_ready_rf(priv)) {
  4181. iwl_scan_cancel_timeout(priv, 100);
  4182. priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  4183. iwl3945_commit_rxon(priv);
  4184. }
  4185. if (priv->vif == conf->vif) {
  4186. priv->vif = NULL;
  4187. memset(priv->bssid, 0, ETH_ALEN);
  4188. }
  4189. mutex_unlock(&priv->mutex);
  4190. IWL_DEBUG_MAC80211("leave\n");
  4191. }
  4192. #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
  4193. static void iwl3945_bss_info_changed(struct ieee80211_hw *hw,
  4194. struct ieee80211_vif *vif,
  4195. struct ieee80211_bss_conf *bss_conf,
  4196. u32 changes)
  4197. {
  4198. struct iwl_priv *priv = hw->priv;
  4199. IWL_DEBUG_MAC80211("changes = 0x%X\n", changes);
  4200. if (changes & BSS_CHANGED_ERP_PREAMBLE) {
  4201. IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
  4202. bss_conf->use_short_preamble);
  4203. if (bss_conf->use_short_preamble)
  4204. priv->staging39_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  4205. else
  4206. priv->staging39_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  4207. }
  4208. if (changes & BSS_CHANGED_ERP_CTS_PROT) {
  4209. IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot);
  4210. if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
  4211. priv->staging39_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
  4212. else
  4213. priv->staging39_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
  4214. }
  4215. if (changes & BSS_CHANGED_ASSOC) {
  4216. IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc);
  4217. /* This should never happen as this function should
  4218. * never be called from interrupt context. */
  4219. if (WARN_ON_ONCE(in_interrupt()))
  4220. return;
  4221. if (bss_conf->assoc) {
  4222. priv->assoc_id = bss_conf->aid;
  4223. priv->beacon_int = bss_conf->beacon_int;
  4224. priv->timestamp = bss_conf->timestamp;
  4225. priv->assoc_capability = bss_conf->assoc_capability;
  4226. priv->power_data.dtim_period = bss_conf->dtim_period;
  4227. priv->next_scan_jiffies = jiffies +
  4228. IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
  4229. mutex_lock(&priv->mutex);
  4230. iwl3945_post_associate(priv);
  4231. mutex_unlock(&priv->mutex);
  4232. } else {
  4233. priv->assoc_id = 0;
  4234. IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc);
  4235. }
  4236. } else if (changes && iwl3945_is_associated(priv) && priv->assoc_id) {
  4237. IWL_DEBUG_MAC80211("Associated Changes %d\n", changes);
  4238. iwl3945_send_rxon_assoc(priv);
  4239. }
  4240. }
  4241. static int iwl3945_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
  4242. {
  4243. int rc = 0;
  4244. unsigned long flags;
  4245. struct iwl_priv *priv = hw->priv;
  4246. DECLARE_SSID_BUF(ssid_buf);
  4247. IWL_DEBUG_MAC80211("enter\n");
  4248. mutex_lock(&priv->mutex);
  4249. spin_lock_irqsave(&priv->lock, flags);
  4250. if (!iwl_is_ready_rf(priv)) {
  4251. rc = -EIO;
  4252. IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
  4253. goto out_unlock;
  4254. }
  4255. /* we don't schedule scan within next_scan_jiffies period */
  4256. if (priv->next_scan_jiffies &&
  4257. time_after(priv->next_scan_jiffies, jiffies)) {
  4258. rc = -EAGAIN;
  4259. goto out_unlock;
  4260. }
  4261. /* if we just finished scan ask for delay for a broadcast scan */
  4262. if ((len == 0) && priv->last_scan_jiffies &&
  4263. time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN,
  4264. jiffies)) {
  4265. rc = -EAGAIN;
  4266. goto out_unlock;
  4267. }
  4268. if (len) {
  4269. IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
  4270. print_ssid(ssid_buf, ssid, len), (int)len);
  4271. priv->one_direct_scan = 1;
  4272. priv->direct_ssid_len = (u8)
  4273. min((u8) len, (u8) IW_ESSID_MAX_SIZE);
  4274. memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
  4275. } else
  4276. priv->one_direct_scan = 0;
  4277. rc = iwl3945_scan_initiate(priv);
  4278. IWL_DEBUG_MAC80211("leave\n");
  4279. out_unlock:
  4280. spin_unlock_irqrestore(&priv->lock, flags);
  4281. mutex_unlock(&priv->mutex);
  4282. return rc;
  4283. }
  4284. static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  4285. struct ieee80211_vif *vif,
  4286. struct ieee80211_sta *sta,
  4287. struct ieee80211_key_conf *key)
  4288. {
  4289. struct iwl_priv *priv = hw->priv;
  4290. const u8 *addr;
  4291. int ret;
  4292. u8 sta_id;
  4293. IWL_DEBUG_MAC80211("enter\n");
  4294. if (iwl3945_mod_params.sw_crypto) {
  4295. IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
  4296. return -EOPNOTSUPP;
  4297. }
  4298. addr = sta ? sta->addr : iwl_bcast_addr;
  4299. sta_id = iwl3945_hw_find_station(priv, addr);
  4300. if (sta_id == IWL_INVALID_STATION) {
  4301. IWL_DEBUG_MAC80211("leave - %pM not in station map.\n",
  4302. addr);
  4303. return -EINVAL;
  4304. }
  4305. mutex_lock(&priv->mutex);
  4306. iwl_scan_cancel_timeout(priv, 100);
  4307. switch (cmd) {
  4308. case SET_KEY:
  4309. ret = iwl3945_update_sta_key_info(priv, key, sta_id);
  4310. if (!ret) {
  4311. iwl3945_set_rxon_hwcrypto(priv, 1);
  4312. iwl3945_commit_rxon(priv);
  4313. key->hw_key_idx = sta_id;
  4314. IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n");
  4315. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  4316. }
  4317. break;
  4318. case DISABLE_KEY:
  4319. ret = iwl3945_clear_sta_key_info(priv, sta_id);
  4320. if (!ret) {
  4321. iwl3945_set_rxon_hwcrypto(priv, 0);
  4322. iwl3945_commit_rxon(priv);
  4323. IWL_DEBUG_MAC80211("disable hwcrypto key\n");
  4324. }
  4325. break;
  4326. default:
  4327. ret = -EINVAL;
  4328. }
  4329. IWL_DEBUG_MAC80211("leave\n");
  4330. mutex_unlock(&priv->mutex);
  4331. return ret;
  4332. }
  4333. static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  4334. const struct ieee80211_tx_queue_params *params)
  4335. {
  4336. struct iwl_priv *priv = hw->priv;
  4337. unsigned long flags;
  4338. int q;
  4339. IWL_DEBUG_MAC80211("enter\n");
  4340. if (!iwl_is_ready_rf(priv)) {
  4341. IWL_DEBUG_MAC80211("leave - RF not ready\n");
  4342. return -EIO;
  4343. }
  4344. if (queue >= AC_NUM) {
  4345. IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
  4346. return 0;
  4347. }
  4348. q = AC_NUM - 1 - queue;
  4349. spin_lock_irqsave(&priv->lock, flags);
  4350. priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
  4351. priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
  4352. priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
  4353. priv->qos_data.def_qos_parm.ac[q].edca_txop =
  4354. cpu_to_le16((params->txop * 32));
  4355. priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
  4356. priv->qos_data.qos_active = 1;
  4357. spin_unlock_irqrestore(&priv->lock, flags);
  4358. mutex_lock(&priv->mutex);
  4359. if (priv->iw_mode == NL80211_IFTYPE_AP)
  4360. iwl3945_activate_qos(priv, 1);
  4361. else if (priv->assoc_id && iwl3945_is_associated(priv))
  4362. iwl3945_activate_qos(priv, 0);
  4363. mutex_unlock(&priv->mutex);
  4364. IWL_DEBUG_MAC80211("leave\n");
  4365. return 0;
  4366. }
  4367. static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
  4368. struct ieee80211_tx_queue_stats *stats)
  4369. {
  4370. struct iwl_priv *priv = hw->priv;
  4371. int i, avail;
  4372. struct iwl_tx_queue *txq;
  4373. struct iwl_queue *q;
  4374. unsigned long flags;
  4375. IWL_DEBUG_MAC80211("enter\n");
  4376. if (!iwl_is_ready_rf(priv)) {
  4377. IWL_DEBUG_MAC80211("leave - RF not ready\n");
  4378. return -EIO;
  4379. }
  4380. spin_lock_irqsave(&priv->lock, flags);
  4381. for (i = 0; i < AC_NUM; i++) {
  4382. txq = &priv->txq[i];
  4383. q = &txq->q;
  4384. avail = iwl_queue_space(q);
  4385. stats[i].len = q->n_window - avail;
  4386. stats[i].limit = q->n_window - q->high_mark;
  4387. stats[i].count = q->n_window;
  4388. }
  4389. spin_unlock_irqrestore(&priv->lock, flags);
  4390. IWL_DEBUG_MAC80211("leave\n");
  4391. return 0;
  4392. }
  4393. static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
  4394. {
  4395. struct iwl_priv *priv = hw->priv;
  4396. unsigned long flags;
  4397. mutex_lock(&priv->mutex);
  4398. IWL_DEBUG_MAC80211("enter\n");
  4399. iwl_reset_qos(priv);
  4400. spin_lock_irqsave(&priv->lock, flags);
  4401. priv->assoc_id = 0;
  4402. priv->assoc_capability = 0;
  4403. /* new association get rid of ibss beacon skb */
  4404. if (priv->ibss_beacon)
  4405. dev_kfree_skb(priv->ibss_beacon);
  4406. priv->ibss_beacon = NULL;
  4407. priv->beacon_int = priv->hw->conf.beacon_int;
  4408. priv->timestamp = 0;
  4409. if ((priv->iw_mode == NL80211_IFTYPE_STATION))
  4410. priv->beacon_int = 0;
  4411. spin_unlock_irqrestore(&priv->lock, flags);
  4412. if (!iwl_is_ready_rf(priv)) {
  4413. IWL_DEBUG_MAC80211("leave - not ready\n");
  4414. mutex_unlock(&priv->mutex);
  4415. return;
  4416. }
  4417. /* we are restarting association process
  4418. * clear RXON_FILTER_ASSOC_MSK bit
  4419. */
  4420. if (priv->iw_mode != NL80211_IFTYPE_AP) {
  4421. iwl_scan_cancel_timeout(priv, 100);
  4422. priv->staging39_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  4423. iwl3945_commit_rxon(priv);
  4424. }
  4425. /* Per mac80211.h: This is only used in IBSS mode... */
  4426. if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
  4427. IWL_DEBUG_MAC80211("leave - not in IBSS\n");
  4428. mutex_unlock(&priv->mutex);
  4429. return;
  4430. }
  4431. iwl3945_set_rate(priv);
  4432. mutex_unlock(&priv->mutex);
  4433. IWL_DEBUG_MAC80211("leave\n");
  4434. }
  4435. static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
  4436. {
  4437. struct iwl_priv *priv = hw->priv;
  4438. unsigned long flags;
  4439. IWL_DEBUG_MAC80211("enter\n");
  4440. if (!iwl_is_ready_rf(priv)) {
  4441. IWL_DEBUG_MAC80211("leave - RF not ready\n");
  4442. return -EIO;
  4443. }
  4444. if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
  4445. IWL_DEBUG_MAC80211("leave - not IBSS\n");
  4446. return -EIO;
  4447. }
  4448. spin_lock_irqsave(&priv->lock, flags);
  4449. if (priv->ibss_beacon)
  4450. dev_kfree_skb(priv->ibss_beacon);
  4451. priv->ibss_beacon = skb;
  4452. priv->assoc_id = 0;
  4453. IWL_DEBUG_MAC80211("leave\n");
  4454. spin_unlock_irqrestore(&priv->lock, flags);
  4455. iwl_reset_qos(priv);
  4456. iwl3945_post_associate(priv);
  4457. return 0;
  4458. }
  4459. /*****************************************************************************
  4460. *
  4461. * sysfs attributes
  4462. *
  4463. *****************************************************************************/
  4464. #ifdef CONFIG_IWLWIFI_DEBUG
  4465. /*
  4466. * The following adds a new attribute to the sysfs representation
  4467. * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
  4468. * used for controlling the debug level.
  4469. *
  4470. * See the level definitions in iwl for details.
  4471. */
  4472. static ssize_t show_debug_level(struct device *d,
  4473. struct device_attribute *attr, char *buf)
  4474. {
  4475. struct iwl_priv *priv = d->driver_data;
  4476. return sprintf(buf, "0x%08X\n", priv->debug_level);
  4477. }
  4478. static ssize_t store_debug_level(struct device *d,
  4479. struct device_attribute *attr,
  4480. const char *buf, size_t count)
  4481. {
  4482. struct iwl_priv *priv = d->driver_data;
  4483. unsigned long val;
  4484. int ret;
  4485. ret = strict_strtoul(buf, 0, &val);
  4486. if (ret)
  4487. IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
  4488. else
  4489. priv->debug_level = val;
  4490. return strnlen(buf, count);
  4491. }
  4492. static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
  4493. show_debug_level, store_debug_level);
  4494. #endif /* CONFIG_IWLWIFI_DEBUG */
  4495. static ssize_t show_temperature(struct device *d,
  4496. struct device_attribute *attr, char *buf)
  4497. {
  4498. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  4499. if (!iwl_is_alive(priv))
  4500. return -EAGAIN;
  4501. return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
  4502. }
  4503. static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
  4504. static ssize_t show_tx_power(struct device *d,
  4505. struct device_attribute *attr, char *buf)
  4506. {
  4507. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  4508. return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
  4509. }
  4510. static ssize_t store_tx_power(struct device *d,
  4511. struct device_attribute *attr,
  4512. const char *buf, size_t count)
  4513. {
  4514. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  4515. char *p = (char *)buf;
  4516. u32 val;
  4517. val = simple_strtoul(p, &p, 10);
  4518. if (p == buf)
  4519. IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
  4520. else
  4521. iwl3945_hw_reg_set_txpower(priv, val);
  4522. return count;
  4523. }
  4524. static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
  4525. static ssize_t show_flags(struct device *d,
  4526. struct device_attribute *attr, char *buf)
  4527. {
  4528. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  4529. return sprintf(buf, "0x%04X\n", priv->active39_rxon.flags);
  4530. }
  4531. static ssize_t store_flags(struct device *d,
  4532. struct device_attribute *attr,
  4533. const char *buf, size_t count)
  4534. {
  4535. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  4536. u32 flags = simple_strtoul(buf, NULL, 0);
  4537. mutex_lock(&priv->mutex);
  4538. if (le32_to_cpu(priv->staging39_rxon.flags) != flags) {
  4539. /* Cancel any currently running scans... */
  4540. if (iwl_scan_cancel_timeout(priv, 100))
  4541. IWL_WARN(priv, "Could not cancel scan.\n");
  4542. else {
  4543. IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
  4544. flags);
  4545. priv->staging39_rxon.flags = cpu_to_le32(flags);
  4546. iwl3945_commit_rxon(priv);
  4547. }
  4548. }
  4549. mutex_unlock(&priv->mutex);
  4550. return count;
  4551. }
  4552. static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
  4553. static ssize_t show_filter_flags(struct device *d,
  4554. struct device_attribute *attr, char *buf)
  4555. {
  4556. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  4557. return sprintf(buf, "0x%04X\n",
  4558. le32_to_cpu(priv->active39_rxon.filter_flags));
  4559. }
  4560. static ssize_t store_filter_flags(struct device *d,
  4561. struct device_attribute *attr,
  4562. const char *buf, size_t count)
  4563. {
  4564. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  4565. u32 filter_flags = simple_strtoul(buf, NULL, 0);
  4566. mutex_lock(&priv->mutex);
  4567. if (le32_to_cpu(priv->staging39_rxon.filter_flags) != filter_flags) {
  4568. /* Cancel any currently running scans... */
  4569. if (iwl_scan_cancel_timeout(priv, 100))
  4570. IWL_WARN(priv, "Could not cancel scan.\n");
  4571. else {
  4572. IWL_DEBUG_INFO("Committing rxon.filter_flags = "
  4573. "0x%04X\n", filter_flags);
  4574. priv->staging39_rxon.filter_flags =
  4575. cpu_to_le32(filter_flags);
  4576. iwl3945_commit_rxon(priv);
  4577. }
  4578. }
  4579. mutex_unlock(&priv->mutex);
  4580. return count;
  4581. }
  4582. static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
  4583. store_filter_flags);
  4584. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  4585. static ssize_t show_measurement(struct device *d,
  4586. struct device_attribute *attr, char *buf)
  4587. {
  4588. struct iwl_priv *priv = dev_get_drvdata(d);
  4589. struct iwl_spectrum_notification measure_report;
  4590. u32 size = sizeof(measure_report), len = 0, ofs = 0;
  4591. u8 *data = (u8 *)&measure_report;
  4592. unsigned long flags;
  4593. spin_lock_irqsave(&priv->lock, flags);
  4594. if (!(priv->measurement_status & MEASUREMENT_READY)) {
  4595. spin_unlock_irqrestore(&priv->lock, flags);
  4596. return 0;
  4597. }
  4598. memcpy(&measure_report, &priv->measure_report, size);
  4599. priv->measurement_status = 0;
  4600. spin_unlock_irqrestore(&priv->lock, flags);
  4601. while (size && (PAGE_SIZE - len)) {
  4602. hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
  4603. PAGE_SIZE - len, 1);
  4604. len = strlen(buf);
  4605. if (PAGE_SIZE - len)
  4606. buf[len++] = '\n';
  4607. ofs += 16;
  4608. size -= min(size, 16U);
  4609. }
  4610. return len;
  4611. }
  4612. static ssize_t store_measurement(struct device *d,
  4613. struct device_attribute *attr,
  4614. const char *buf, size_t count)
  4615. {
  4616. struct iwl_priv *priv = dev_get_drvdata(d);
  4617. struct ieee80211_measurement_params params = {
  4618. .channel = le16_to_cpu(priv->active39_rxon.channel),
  4619. .start_time = cpu_to_le64(priv->last_tsf),
  4620. .duration = cpu_to_le16(1),
  4621. };
  4622. u8 type = IWL_MEASURE_BASIC;
  4623. u8 buffer[32];
  4624. u8 channel;
  4625. if (count) {
  4626. char *p = buffer;
  4627. strncpy(buffer, buf, min(sizeof(buffer), count));
  4628. channel = simple_strtoul(p, NULL, 0);
  4629. if (channel)
  4630. params.channel = channel;
  4631. p = buffer;
  4632. while (*p && *p != ' ')
  4633. p++;
  4634. if (*p)
  4635. type = simple_strtoul(p + 1, NULL, 0);
  4636. }
  4637. IWL_DEBUG_INFO("Invoking measurement of type %d on "
  4638. "channel %d (for '%s')\n", type, params.channel, buf);
  4639. iwl3945_get_measurement(priv, &params, type);
  4640. return count;
  4641. }
  4642. static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
  4643. show_measurement, store_measurement);
  4644. #endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
  4645. static ssize_t store_retry_rate(struct device *d,
  4646. struct device_attribute *attr,
  4647. const char *buf, size_t count)
  4648. {
  4649. struct iwl_priv *priv = dev_get_drvdata(d);
  4650. priv->retry_rate = simple_strtoul(buf, NULL, 0);
  4651. if (priv->retry_rate <= 0)
  4652. priv->retry_rate = 1;
  4653. return count;
  4654. }
  4655. static ssize_t show_retry_rate(struct device *d,
  4656. struct device_attribute *attr, char *buf)
  4657. {
  4658. struct iwl_priv *priv = dev_get_drvdata(d);
  4659. return sprintf(buf, "%d", priv->retry_rate);
  4660. }
  4661. static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
  4662. store_retry_rate);
  4663. static ssize_t store_power_level(struct device *d,
  4664. struct device_attribute *attr,
  4665. const char *buf, size_t count)
  4666. {
  4667. struct iwl_priv *priv = dev_get_drvdata(d);
  4668. int rc;
  4669. int mode;
  4670. mode = simple_strtoul(buf, NULL, 0);
  4671. mutex_lock(&priv->mutex);
  4672. if (!iwl_is_ready(priv)) {
  4673. rc = -EAGAIN;
  4674. goto out;
  4675. }
  4676. if ((mode < 1) || (mode > IWL39_POWER_LIMIT) ||
  4677. (mode == IWL39_POWER_AC))
  4678. mode = IWL39_POWER_AC;
  4679. else
  4680. mode |= IWL_POWER_ENABLED;
  4681. if (mode != priv->power_mode) {
  4682. rc = iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(mode));
  4683. if (rc) {
  4684. IWL_DEBUG_MAC80211("failed setting power mode.\n");
  4685. goto out;
  4686. }
  4687. priv->power_mode = mode;
  4688. }
  4689. rc = count;
  4690. out:
  4691. mutex_unlock(&priv->mutex);
  4692. return rc;
  4693. }
  4694. #define MAX_WX_STRING 80
  4695. /* Values are in microsecond */
  4696. static const s32 timeout_duration[] = {
  4697. 350000,
  4698. 250000,
  4699. 75000,
  4700. 37000,
  4701. 25000,
  4702. };
  4703. static const s32 period_duration[] = {
  4704. 400000,
  4705. 700000,
  4706. 1000000,
  4707. 1000000,
  4708. 1000000
  4709. };
  4710. static ssize_t show_power_level(struct device *d,
  4711. struct device_attribute *attr, char *buf)
  4712. {
  4713. struct iwl_priv *priv = dev_get_drvdata(d);
  4714. int level = IWL_POWER_LEVEL(priv->power_mode);
  4715. char *p = buf;
  4716. p += sprintf(p, "%d ", level);
  4717. switch (level) {
  4718. case IWL_POWER_MODE_CAM:
  4719. case IWL39_POWER_AC:
  4720. p += sprintf(p, "(AC)");
  4721. break;
  4722. case IWL39_POWER_BATTERY:
  4723. p += sprintf(p, "(BATTERY)");
  4724. break;
  4725. default:
  4726. p += sprintf(p,
  4727. "(Timeout %dms, Period %dms)",
  4728. timeout_duration[level - 1] / 1000,
  4729. period_duration[level - 1] / 1000);
  4730. }
  4731. if (!(priv->power_mode & IWL_POWER_ENABLED))
  4732. p += sprintf(p, " OFF\n");
  4733. else
  4734. p += sprintf(p, " \n");
  4735. return p - buf + 1;
  4736. }
  4737. static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
  4738. store_power_level);
  4739. static ssize_t show_channels(struct device *d,
  4740. struct device_attribute *attr, char *buf)
  4741. {
  4742. /* all this shit doesn't belong into sysfs anyway */
  4743. return 0;
  4744. }
  4745. static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
  4746. static ssize_t show_statistics(struct device *d,
  4747. struct device_attribute *attr, char *buf)
  4748. {
  4749. struct iwl_priv *priv = dev_get_drvdata(d);
  4750. u32 size = sizeof(struct iwl3945_notif_statistics);
  4751. u32 len = 0, ofs = 0;
  4752. u8 *data = (u8 *)&priv->statistics_39;
  4753. int rc = 0;
  4754. if (!iwl_is_alive(priv))
  4755. return -EAGAIN;
  4756. mutex_lock(&priv->mutex);
  4757. rc = iwl3945_send_statistics_request(priv);
  4758. mutex_unlock(&priv->mutex);
  4759. if (rc) {
  4760. len = sprintf(buf,
  4761. "Error sending statistics request: 0x%08X\n", rc);
  4762. return len;
  4763. }
  4764. while (size && (PAGE_SIZE - len)) {
  4765. hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
  4766. PAGE_SIZE - len, 1);
  4767. len = strlen(buf);
  4768. if (PAGE_SIZE - len)
  4769. buf[len++] = '\n';
  4770. ofs += 16;
  4771. size -= min(size, 16U);
  4772. }
  4773. return len;
  4774. }
  4775. static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
  4776. static ssize_t show_antenna(struct device *d,
  4777. struct device_attribute *attr, char *buf)
  4778. {
  4779. struct iwl_priv *priv = dev_get_drvdata(d);
  4780. if (!iwl_is_alive(priv))
  4781. return -EAGAIN;
  4782. return sprintf(buf, "%d\n", priv->antenna);
  4783. }
  4784. static ssize_t store_antenna(struct device *d,
  4785. struct device_attribute *attr,
  4786. const char *buf, size_t count)
  4787. {
  4788. int ant;
  4789. struct iwl_priv *priv = dev_get_drvdata(d);
  4790. if (count == 0)
  4791. return 0;
  4792. if (sscanf(buf, "%1i", &ant) != 1) {
  4793. IWL_DEBUG_INFO("not in hex or decimal form.\n");
  4794. return count;
  4795. }
  4796. if ((ant >= 0) && (ant <= 2)) {
  4797. IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant);
  4798. priv->antenna = (enum iwl3945_antenna)ant;
  4799. } else
  4800. IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant);
  4801. return count;
  4802. }
  4803. static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
  4804. static ssize_t show_status(struct device *d,
  4805. struct device_attribute *attr, char *buf)
  4806. {
  4807. struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
  4808. if (!iwl_is_alive(priv))
  4809. return -EAGAIN;
  4810. return sprintf(buf, "0x%08x\n", (int)priv->status);
  4811. }
  4812. static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
  4813. static ssize_t dump_error_log(struct device *d,
  4814. struct device_attribute *attr,
  4815. const char *buf, size_t count)
  4816. {
  4817. char *p = (char *)buf;
  4818. if (p[0] == '1')
  4819. iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data);
  4820. return strnlen(buf, count);
  4821. }
  4822. static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
  4823. static ssize_t dump_event_log(struct device *d,
  4824. struct device_attribute *attr,
  4825. const char *buf, size_t count)
  4826. {
  4827. char *p = (char *)buf;
  4828. if (p[0] == '1')
  4829. iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data);
  4830. return strnlen(buf, count);
  4831. }
  4832. static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
  4833. /*****************************************************************************
  4834. *
  4835. * driver setup and tear down
  4836. *
  4837. *****************************************************************************/
  4838. static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
  4839. {
  4840. priv->workqueue = create_workqueue(DRV_NAME);
  4841. init_waitqueue_head(&priv->wait_command_queue);
  4842. INIT_WORK(&priv->up, iwl3945_bg_up);
  4843. INIT_WORK(&priv->restart, iwl3945_bg_restart);
  4844. INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
  4845. INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
  4846. INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
  4847. INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
  4848. INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
  4849. INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll);
  4850. INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
  4851. INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
  4852. INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
  4853. INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
  4854. iwl3945_hw_setup_deferred_work(priv);
  4855. tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
  4856. iwl3945_irq_tasklet, (unsigned long)priv);
  4857. }
  4858. static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
  4859. {
  4860. iwl3945_hw_cancel_deferred_work(priv);
  4861. cancel_delayed_work_sync(&priv->init_alive_start);
  4862. cancel_delayed_work(&priv->scan_check);
  4863. cancel_delayed_work(&priv->alive_start);
  4864. cancel_work_sync(&priv->beacon_update);
  4865. }
  4866. static struct attribute *iwl3945_sysfs_entries[] = {
  4867. &dev_attr_antenna.attr,
  4868. &dev_attr_channels.attr,
  4869. &dev_attr_dump_errors.attr,
  4870. &dev_attr_dump_events.attr,
  4871. &dev_attr_flags.attr,
  4872. &dev_attr_filter_flags.attr,
  4873. #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
  4874. &dev_attr_measurement.attr,
  4875. #endif
  4876. &dev_attr_power_level.attr,
  4877. &dev_attr_retry_rate.attr,
  4878. &dev_attr_statistics.attr,
  4879. &dev_attr_status.attr,
  4880. &dev_attr_temperature.attr,
  4881. &dev_attr_tx_power.attr,
  4882. #ifdef CONFIG_IWLWIFI_DEBUG
  4883. &dev_attr_debug_level.attr,
  4884. #endif
  4885. NULL
  4886. };
  4887. static struct attribute_group iwl3945_attribute_group = {
  4888. .name = NULL, /* put in device directory */
  4889. .attrs = iwl3945_sysfs_entries,
  4890. };
  4891. static struct ieee80211_ops iwl3945_hw_ops = {
  4892. .tx = iwl3945_mac_tx,
  4893. .start = iwl3945_mac_start,
  4894. .stop = iwl3945_mac_stop,
  4895. .add_interface = iwl3945_mac_add_interface,
  4896. .remove_interface = iwl3945_mac_remove_interface,
  4897. .config = iwl3945_mac_config,
  4898. .config_interface = iwl3945_mac_config_interface,
  4899. .configure_filter = iwl3945_configure_filter,
  4900. .set_key = iwl3945_mac_set_key,
  4901. .get_tx_stats = iwl3945_mac_get_tx_stats,
  4902. .conf_tx = iwl3945_mac_conf_tx,
  4903. .reset_tsf = iwl3945_mac_reset_tsf,
  4904. .bss_info_changed = iwl3945_bss_info_changed,
  4905. .hw_scan = iwl3945_mac_hw_scan
  4906. };
  4907. static int iwl3945_init_drv(struct iwl_priv *priv)
  4908. {
  4909. int ret;
  4910. struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
  4911. priv->retry_rate = 1;
  4912. priv->ibss_beacon = NULL;
  4913. spin_lock_init(&priv->lock);
  4914. spin_lock_init(&priv->power_data.lock);
  4915. spin_lock_init(&priv->sta_lock);
  4916. spin_lock_init(&priv->hcmd_lock);
  4917. INIT_LIST_HEAD(&priv->free_frames);
  4918. mutex_init(&priv->mutex);
  4919. /* Clear the driver's (not device's) station table */
  4920. iwl3945_clear_stations_table(priv);
  4921. priv->data_retry_limit = -1;
  4922. priv->ieee_channels = NULL;
  4923. priv->ieee_rates = NULL;
  4924. priv->band = IEEE80211_BAND_2GHZ;
  4925. priv->iw_mode = NL80211_IFTYPE_STATION;
  4926. iwl_reset_qos(priv);
  4927. priv->qos_data.qos_active = 0;
  4928. priv->qos_data.qos_cap.val = 0;
  4929. priv->rates_mask = IWL_RATES_MASK;
  4930. /* If power management is turned on, default to AC mode */
  4931. priv->power_mode = IWL39_POWER_AC;
  4932. priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
  4933. if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
  4934. IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
  4935. eeprom->version);
  4936. ret = -EINVAL;
  4937. goto err;
  4938. }
  4939. ret = iwl_init_channel_map(priv);
  4940. if (ret) {
  4941. IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
  4942. goto err;
  4943. }
  4944. /* Set up txpower settings in driver for all channels */
  4945. if (iwl3945_txpower_set_from_eeprom(priv)) {
  4946. ret = -EIO;
  4947. goto err_free_channel_map;
  4948. }
  4949. ret = iwlcore_init_geos(priv);
  4950. if (ret) {
  4951. IWL_ERR(priv, "initializing geos failed: %d\n", ret);
  4952. goto err_free_channel_map;
  4953. }
  4954. iwl3945_init_hw_rates(priv, priv->ieee_rates);
  4955. if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
  4956. priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  4957. &priv->bands[IEEE80211_BAND_2GHZ];
  4958. if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
  4959. priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  4960. &priv->bands[IEEE80211_BAND_5GHZ];
  4961. return 0;
  4962. err_free_channel_map:
  4963. iwl_free_channel_map(priv);
  4964. err:
  4965. return ret;
  4966. }
  4967. static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  4968. {
  4969. int err = 0;
  4970. struct iwl_priv *priv;
  4971. struct ieee80211_hw *hw;
  4972. struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
  4973. struct iwl3945_eeprom *eeprom;
  4974. unsigned long flags;
  4975. /***********************
  4976. * 1. Allocating HW data
  4977. * ********************/
  4978. /* mac80211 allocates memory for this device instance, including
  4979. * space for this driver's private structure */
  4980. hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
  4981. if (hw == NULL) {
  4982. printk(KERN_ERR DRV_NAME "Can not allocate network device\n");
  4983. err = -ENOMEM;
  4984. goto out;
  4985. }
  4986. priv = hw->priv;
  4987. SET_IEEE80211_DEV(hw, &pdev->dev);
  4988. if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) ||
  4989. (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) {
  4990. IWL_ERR(priv,
  4991. "invalid queues_num, should be between %d and %d\n",
  4992. IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES);
  4993. err = -EINVAL;
  4994. goto out;
  4995. }
  4996. /*
  4997. * Disabling hardware scan means that mac80211 will perform scans
  4998. * "the hard way", rather than using device's scan.
  4999. */
  5000. if (iwl3945_mod_params.disable_hw_scan) {
  5001. IWL_DEBUG_INFO("Disabling hw_scan\n");
  5002. iwl3945_hw_ops.hw_scan = NULL;
  5003. }
  5004. IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
  5005. priv->cfg = cfg;
  5006. priv->pci_dev = pdev;
  5007. #ifdef CONFIG_IWLWIFI_DEBUG
  5008. priv->debug_level = iwl3945_mod_params.debug;
  5009. atomic_set(&priv->restrict_refcnt, 0);
  5010. #endif
  5011. hw->rate_control_algorithm = "iwl-3945-rs";
  5012. hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
  5013. /* Select antenna (may be helpful if only one antenna is connected) */
  5014. priv->antenna = (enum iwl3945_antenna)iwl3945_mod_params.antenna;
  5015. /* Tell mac80211 our characteristics */
  5016. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  5017. IEEE80211_HW_NOISE_DBM;
  5018. hw->wiphy->interface_modes =
  5019. BIT(NL80211_IFTYPE_STATION) |
  5020. BIT(NL80211_IFTYPE_ADHOC);
  5021. hw->wiphy->custom_regulatory = true;
  5022. /* 4 EDCA QOS priorities */
  5023. hw->queues = 4;
  5024. /***************************
  5025. * 2. Initializing PCI bus
  5026. * *************************/
  5027. if (pci_enable_device(pdev)) {
  5028. err = -ENODEV;
  5029. goto out_ieee80211_free_hw;
  5030. }
  5031. pci_set_master(pdev);
  5032. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  5033. if (!err)
  5034. err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  5035. if (err) {
  5036. IWL_WARN(priv, "No suitable DMA available.\n");
  5037. goto out_pci_disable_device;
  5038. }
  5039. pci_set_drvdata(pdev, priv);
  5040. err = pci_request_regions(pdev, DRV_NAME);
  5041. if (err)
  5042. goto out_pci_disable_device;
  5043. /***********************
  5044. * 3. Read REV Register
  5045. * ********************/
  5046. priv->hw_base = pci_iomap(pdev, 0, 0);
  5047. if (!priv->hw_base) {
  5048. err = -ENODEV;
  5049. goto out_pci_release_regions;
  5050. }
  5051. IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
  5052. (unsigned long long) pci_resource_len(pdev, 0));
  5053. IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
  5054. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  5055. * PCI Tx retries from interfering with C3 CPU state */
  5056. pci_write_config_byte(pdev, 0x41, 0x00);
  5057. /* amp init */
  5058. err = priv->cfg->ops->lib->apm_ops.init(priv);
  5059. if (err < 0) {
  5060. IWL_DEBUG_INFO("Failed to init APMG\n");
  5061. goto out_iounmap;
  5062. }
  5063. /***********************
  5064. * 4. Read EEPROM
  5065. * ********************/
  5066. /* Read the EEPROM */
  5067. err = iwl_eeprom_init(priv);
  5068. if (err) {
  5069. IWL_ERR(priv, "Unable to init EEPROM\n");
  5070. goto out_remove_sysfs;
  5071. }
  5072. /* MAC Address location in EEPROM same for 3945/4965 */
  5073. eeprom = (struct iwl3945_eeprom *)priv->eeprom;
  5074. memcpy(priv->mac_addr, eeprom->mac_address, ETH_ALEN);
  5075. IWL_DEBUG_INFO("MAC address: %pM\n", priv->mac_addr);
  5076. SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
  5077. /***********************
  5078. * 5. Setup HW Constants
  5079. * ********************/
  5080. /* Device-specific setup */
  5081. if (iwl3945_hw_set_hw_params(priv)) {
  5082. IWL_ERR(priv, "failed to set hw settings\n");
  5083. goto out_iounmap;
  5084. }
  5085. /***********************
  5086. * 6. Setup priv
  5087. * ********************/
  5088. err = iwl3945_init_drv(priv);
  5089. if (err) {
  5090. IWL_ERR(priv, "initializing driver failed\n");
  5091. goto out_free_geos;
  5092. }
  5093. IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
  5094. priv->cfg->name);
  5095. /***********************************
  5096. * 7. Initialize Module Parameters
  5097. * **********************************/
  5098. /* Initialize module parameter values here */
  5099. /* Disable radio (SW RF KILL) via parameter when loading driver */
  5100. if (iwl3945_mod_params.disable) {
  5101. set_bit(STATUS_RF_KILL_SW, &priv->status);
  5102. IWL_DEBUG_INFO("Radio disabled.\n");
  5103. }
  5104. /***********************
  5105. * 8. Setup Services
  5106. * ********************/
  5107. spin_lock_irqsave(&priv->lock, flags);
  5108. iwl3945_disable_interrupts(priv);
  5109. spin_unlock_irqrestore(&priv->lock, flags);
  5110. pci_enable_msi(priv->pci_dev);
  5111. err = request_irq(priv->pci_dev->irq, iwl3945_isr, IRQF_SHARED,
  5112. DRV_NAME, priv);
  5113. if (err) {
  5114. IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
  5115. goto out_disable_msi;
  5116. }
  5117. err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
  5118. if (err) {
  5119. IWL_ERR(priv, "failed to create sysfs device attributes\n");
  5120. goto out_release_irq;
  5121. }
  5122. iwl3945_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
  5123. iwl3945_setup_deferred_work(priv);
  5124. iwl3945_setup_rx_handlers(priv);
  5125. /*********************************
  5126. * 9. Setup and Register mac80211
  5127. * *******************************/
  5128. err = ieee80211_register_hw(priv->hw);
  5129. if (err) {
  5130. IWL_ERR(priv, "Failed to register network device: %d\n", err);
  5131. goto out_remove_sysfs;
  5132. }
  5133. priv->hw->conf.beacon_int = 100;
  5134. priv->mac80211_registered = 1;
  5135. err = iwl_rfkill_init(priv);
  5136. if (err)
  5137. IWL_ERR(priv, "Unable to initialize RFKILL system. "
  5138. "Ignoring error: %d\n", err);
  5139. /* Start monitoring the killswitch */
  5140. queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
  5141. 2 * HZ);
  5142. return 0;
  5143. out_remove_sysfs:
  5144. sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
  5145. out_free_geos:
  5146. iwlcore_free_geos(priv);
  5147. out_release_irq:
  5148. free_irq(priv->pci_dev->irq, priv);
  5149. destroy_workqueue(priv->workqueue);
  5150. priv->workqueue = NULL;
  5151. iwl3945_unset_hw_params(priv);
  5152. out_disable_msi:
  5153. pci_disable_msi(priv->pci_dev);
  5154. out_iounmap:
  5155. pci_iounmap(pdev, priv->hw_base);
  5156. out_pci_release_regions:
  5157. pci_release_regions(pdev);
  5158. out_pci_disable_device:
  5159. pci_disable_device(pdev);
  5160. pci_set_drvdata(pdev, NULL);
  5161. out_ieee80211_free_hw:
  5162. ieee80211_free_hw(priv->hw);
  5163. out:
  5164. return err;
  5165. }
  5166. static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
  5167. {
  5168. struct iwl_priv *priv = pci_get_drvdata(pdev);
  5169. unsigned long flags;
  5170. if (!priv)
  5171. return;
  5172. IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
  5173. set_bit(STATUS_EXIT_PENDING, &priv->status);
  5174. if (priv->mac80211_registered) {
  5175. ieee80211_unregister_hw(priv->hw);
  5176. priv->mac80211_registered = 0;
  5177. } else {
  5178. iwl3945_down(priv);
  5179. }
  5180. /* make sure we flush any pending irq or
  5181. * tasklet for the driver
  5182. */
  5183. spin_lock_irqsave(&priv->lock, flags);
  5184. iwl3945_disable_interrupts(priv);
  5185. spin_unlock_irqrestore(&priv->lock, flags);
  5186. iwl_synchronize_irq(priv);
  5187. sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
  5188. iwl_rfkill_unregister(priv);
  5189. cancel_delayed_work(&priv->rfkill_poll);
  5190. iwl3945_dealloc_ucode_pci(priv);
  5191. if (priv->rxq.bd)
  5192. iwl_rx_queue_free(priv, &priv->rxq);
  5193. iwl3945_hw_txq_ctx_free(priv);
  5194. iwl3945_unset_hw_params(priv);
  5195. iwl3945_clear_stations_table(priv);
  5196. /*netif_stop_queue(dev); */
  5197. flush_workqueue(priv->workqueue);
  5198. /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
  5199. * priv->workqueue... so we can't take down the workqueue
  5200. * until now... */
  5201. destroy_workqueue(priv->workqueue);
  5202. priv->workqueue = NULL;
  5203. free_irq(pdev->irq, priv);
  5204. pci_disable_msi(pdev);
  5205. pci_iounmap(pdev, priv->hw_base);
  5206. pci_release_regions(pdev);
  5207. pci_disable_device(pdev);
  5208. pci_set_drvdata(pdev, NULL);
  5209. iwl_free_channel_map(priv);
  5210. iwlcore_free_geos(priv);
  5211. kfree(priv->scan);
  5212. if (priv->ibss_beacon)
  5213. dev_kfree_skb(priv->ibss_beacon);
  5214. ieee80211_free_hw(priv->hw);
  5215. }
  5216. #ifdef CONFIG_PM
  5217. static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  5218. {
  5219. struct iwl_priv *priv = pci_get_drvdata(pdev);
  5220. if (priv->is_open) {
  5221. set_bit(STATUS_IN_SUSPEND, &priv->status);
  5222. iwl3945_mac_stop(priv->hw);
  5223. priv->is_open = 1;
  5224. }
  5225. pci_save_state(pdev);
  5226. pci_disable_device(pdev);
  5227. pci_set_power_state(pdev, PCI_D3hot);
  5228. return 0;
  5229. }
  5230. static int iwl3945_pci_resume(struct pci_dev *pdev)
  5231. {
  5232. struct iwl_priv *priv = pci_get_drvdata(pdev);
  5233. pci_set_power_state(pdev, PCI_D0);
  5234. pci_enable_device(pdev);
  5235. pci_restore_state(pdev);
  5236. if (priv->is_open)
  5237. iwl3945_mac_start(priv->hw);
  5238. clear_bit(STATUS_IN_SUSPEND, &priv->status);
  5239. return 0;
  5240. }
  5241. #endif /* CONFIG_PM */
  5242. /*****************************************************************************
  5243. *
  5244. * driver and module entry point
  5245. *
  5246. *****************************************************************************/
  5247. static struct pci_driver iwl3945_driver = {
  5248. .name = DRV_NAME,
  5249. .id_table = iwl3945_hw_card_ids,
  5250. .probe = iwl3945_pci_probe,
  5251. .remove = __devexit_p(iwl3945_pci_remove),
  5252. #ifdef CONFIG_PM
  5253. .suspend = iwl3945_pci_suspend,
  5254. .resume = iwl3945_pci_resume,
  5255. #endif
  5256. };
  5257. static int __init iwl3945_init(void)
  5258. {
  5259. int ret;
  5260. printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
  5261. printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
  5262. ret = iwl3945_rate_control_register();
  5263. if (ret) {
  5264. printk(KERN_ERR DRV_NAME
  5265. "Unable to register rate control algorithm: %d\n", ret);
  5266. return ret;
  5267. }
  5268. ret = pci_register_driver(&iwl3945_driver);
  5269. if (ret) {
  5270. printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
  5271. goto error_register;
  5272. }
  5273. return ret;
  5274. error_register:
  5275. iwl3945_rate_control_unregister();
  5276. return ret;
  5277. }
  5278. static void __exit iwl3945_exit(void)
  5279. {
  5280. pci_unregister_driver(&iwl3945_driver);
  5281. iwl3945_rate_control_unregister();
  5282. }
  5283. MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
  5284. module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444);
  5285. MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
  5286. module_param_named(disable, iwl3945_mod_params.disable, int, 0444);
  5287. MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
  5288. module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444);
  5289. MODULE_PARM_DESC(swcrypto,
  5290. "using software crypto (default 1 [software])\n");
  5291. module_param_named(debug, iwl3945_mod_params.debug, uint, 0444);
  5292. MODULE_PARM_DESC(debug, "debug output mask");
  5293. module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, int, 0444);
  5294. MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
  5295. module_param_named(queues_num, iwl3945_mod_params.num_of_queues, int, 0444);
  5296. MODULE_PARM_DESC(queues_num, "number of hw queues.");
  5297. module_exit(iwl3945_exit);
  5298. module_init(iwl3945_init);