iwl4965-base.c 224 KB

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