iwl4965-base.c 264 KB

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