iwl4965-base.c 223 KB

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