iwl4965-base.c 195 KB

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