iwl4965-base.c 258 KB

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