iwl4965-base.c 164 KB

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