iwl4965-base.c 258 KB

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