iwl4965-base.c 189 KB

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