iwl4965-base.c 232 KB

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