iwl4965-base.c 189 KB

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