4965-mac.c 176 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2011 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. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  30. #include <linux/kernel.h>
  31. #include <linux/module.h>
  32. #include <linux/init.h>
  33. #include <linux/pci.h>
  34. #include <linux/pci-aspm.h>
  35. #include <linux/slab.h>
  36. #include <linux/dma-mapping.h>
  37. #include <linux/delay.h>
  38. #include <linux/sched.h>
  39. #include <linux/skbuff.h>
  40. #include <linux/netdevice.h>
  41. #include <linux/firmware.h>
  42. #include <linux/etherdevice.h>
  43. #include <linux/if_arp.h>
  44. #include <net/mac80211.h>
  45. #include <asm/div64.h>
  46. #define DRV_NAME "iwl4965"
  47. #include "common.h"
  48. #include "4965.h"
  49. /******************************************************************************
  50. *
  51. * module boiler plate
  52. *
  53. ******************************************************************************/
  54. /*
  55. * module name, copyright, version, etc.
  56. */
  57. #define DRV_DESCRIPTION "Intel(R) Wireless WiFi 4965 driver for Linux"
  58. #ifdef CONFIG_IWLEGACY_DEBUG
  59. #define VD "d"
  60. #else
  61. #define VD
  62. #endif
  63. #define DRV_VERSION IWLWIFI_VERSION VD
  64. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  65. MODULE_VERSION(DRV_VERSION);
  66. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  67. MODULE_LICENSE("GPL");
  68. MODULE_ALIAS("iwl4965");
  69. void
  70. il4965_check_abort_status(struct il_priv *il, u8 frame_count, u32 status)
  71. {
  72. if (frame_count == 1 && status == TX_STATUS_FAIL_RFKILL_FLUSH) {
  73. IL_ERR("Tx flush command to flush out all frames\n");
  74. if (!test_bit(S_EXIT_PENDING, &il->status))
  75. queue_work(il->workqueue, &il->tx_flush);
  76. }
  77. }
  78. /*
  79. * EEPROM
  80. */
  81. struct il_mod_params il4965_mod_params = {
  82. .amsdu_size_8K = 1,
  83. .restart_fw = 1,
  84. /* the rest are 0 by default */
  85. };
  86. void
  87. il4965_rx_queue_reset(struct il_priv *il, struct il_rx_queue *rxq)
  88. {
  89. unsigned long flags;
  90. int i;
  91. spin_lock_irqsave(&rxq->lock, flags);
  92. INIT_LIST_HEAD(&rxq->rx_free);
  93. INIT_LIST_HEAD(&rxq->rx_used);
  94. /* Fill the rx_used queue with _all_ of the Rx buffers */
  95. for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
  96. /* In the reset function, these buffers may have been allocated
  97. * to an SKB, so we need to unmap and free potential storage */
  98. if (rxq->pool[i].page != NULL) {
  99. pci_unmap_page(il->pci_dev, rxq->pool[i].page_dma,
  100. PAGE_SIZE << il->hw_params.rx_page_order,
  101. PCI_DMA_FROMDEVICE);
  102. __il_free_pages(il, rxq->pool[i].page);
  103. rxq->pool[i].page = NULL;
  104. }
  105. list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
  106. }
  107. for (i = 0; i < RX_QUEUE_SIZE; i++)
  108. rxq->queue[i] = NULL;
  109. /* Set us so that we have processed and used all buffers, but have
  110. * not restocked the Rx queue with fresh buffers */
  111. rxq->read = rxq->write = 0;
  112. rxq->write_actual = 0;
  113. rxq->free_count = 0;
  114. spin_unlock_irqrestore(&rxq->lock, flags);
  115. }
  116. int
  117. il4965_rx_init(struct il_priv *il, struct il_rx_queue *rxq)
  118. {
  119. u32 rb_size;
  120. const u32 rfdnlog = RX_QUEUE_SIZE_LOG; /* 256 RBDs */
  121. u32 rb_timeout = 0;
  122. if (il->cfg->mod_params->amsdu_size_8K)
  123. rb_size = FH49_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K;
  124. else
  125. rb_size = FH49_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K;
  126. /* Stop Rx DMA */
  127. il_wr(il, FH49_MEM_RCSR_CHNL0_CONFIG_REG, 0);
  128. /* Reset driver's Rx queue write idx */
  129. il_wr(il, FH49_RSCSR_CHNL0_RBDCB_WPTR_REG, 0);
  130. /* Tell device where to find RBD circular buffer in DRAM */
  131. il_wr(il, FH49_RSCSR_CHNL0_RBDCB_BASE_REG, (u32) (rxq->bd_dma >> 8));
  132. /* Tell device where in DRAM to update its Rx status */
  133. il_wr(il, FH49_RSCSR_CHNL0_STTS_WPTR_REG, rxq->rb_stts_dma >> 4);
  134. /* Enable Rx DMA
  135. * Direct rx interrupts to hosts
  136. * Rx buffer size 4 or 8k
  137. * RB timeout 0x10
  138. * 256 RBDs
  139. */
  140. il_wr(il, FH49_MEM_RCSR_CHNL0_CONFIG_REG,
  141. FH49_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL |
  142. FH49_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL |
  143. FH49_RCSR_CHNL0_RX_CONFIG_SINGLE_FRAME_MSK |
  144. rb_size |
  145. (rb_timeout << FH49_RCSR_RX_CONFIG_REG_IRQ_RBTH_POS) |
  146. (rfdnlog << FH49_RCSR_RX_CONFIG_RBDCB_SIZE_POS));
  147. /* Set interrupt coalescing timer to default (2048 usecs) */
  148. il_write8(il, CSR_INT_COALESCING, IL_HOST_INT_TIMEOUT_DEF);
  149. return 0;
  150. }
  151. static void
  152. il4965_set_pwr_vmain(struct il_priv *il)
  153. {
  154. /*
  155. * (for documentation purposes)
  156. * to set power to V_AUX, do:
  157. if (pci_pme_capable(il->pci_dev, PCI_D3cold))
  158. il_set_bits_mask_prph(il, APMG_PS_CTRL_REG,
  159. APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
  160. ~APMG_PS_CTRL_MSK_PWR_SRC);
  161. */
  162. il_set_bits_mask_prph(il, APMG_PS_CTRL_REG,
  163. APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
  164. ~APMG_PS_CTRL_MSK_PWR_SRC);
  165. }
  166. int
  167. il4965_hw_nic_init(struct il_priv *il)
  168. {
  169. unsigned long flags;
  170. struct il_rx_queue *rxq = &il->rxq;
  171. int ret;
  172. /* nic_init */
  173. spin_lock_irqsave(&il->lock, flags);
  174. il->cfg->ops->lib->apm_ops.init(il);
  175. /* Set interrupt coalescing calibration timer to default (512 usecs) */
  176. il_write8(il, CSR_INT_COALESCING, IL_HOST_INT_CALIB_TIMEOUT_DEF);
  177. spin_unlock_irqrestore(&il->lock, flags);
  178. il4965_set_pwr_vmain(il);
  179. il->cfg->ops->lib->apm_ops.config(il);
  180. /* Allocate the RX queue, or reset if it is already allocated */
  181. if (!rxq->bd) {
  182. ret = il_rx_queue_alloc(il);
  183. if (ret) {
  184. IL_ERR("Unable to initialize Rx queue\n");
  185. return -ENOMEM;
  186. }
  187. } else
  188. il4965_rx_queue_reset(il, rxq);
  189. il4965_rx_replenish(il);
  190. il4965_rx_init(il, rxq);
  191. spin_lock_irqsave(&il->lock, flags);
  192. rxq->need_update = 1;
  193. il_rx_queue_update_write_ptr(il, rxq);
  194. spin_unlock_irqrestore(&il->lock, flags);
  195. /* Allocate or reset and init all Tx and Command queues */
  196. if (!il->txq) {
  197. ret = il4965_txq_ctx_alloc(il);
  198. if (ret)
  199. return ret;
  200. } else
  201. il4965_txq_ctx_reset(il);
  202. set_bit(S_INIT, &il->status);
  203. return 0;
  204. }
  205. /**
  206. * il4965_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
  207. */
  208. static inline __le32
  209. il4965_dma_addr2rbd_ptr(struct il_priv *il, dma_addr_t dma_addr)
  210. {
  211. return cpu_to_le32((u32) (dma_addr >> 8));
  212. }
  213. /**
  214. * il4965_rx_queue_restock - refill RX queue from pre-allocated pool
  215. *
  216. * If there are slots in the RX queue that need to be restocked,
  217. * and we have free pre-allocated buffers, fill the ranks as much
  218. * as we can, pulling from rx_free.
  219. *
  220. * This moves the 'write' idx forward to catch up with 'processed', and
  221. * also updates the memory address in the firmware to reference the new
  222. * target buffer.
  223. */
  224. void
  225. il4965_rx_queue_restock(struct il_priv *il)
  226. {
  227. struct il_rx_queue *rxq = &il->rxq;
  228. struct list_head *element;
  229. struct il_rx_buf *rxb;
  230. unsigned long flags;
  231. spin_lock_irqsave(&rxq->lock, flags);
  232. while (il_rx_queue_space(rxq) > 0 && rxq->free_count) {
  233. /* The overwritten rxb must be a used one */
  234. rxb = rxq->queue[rxq->write];
  235. BUG_ON(rxb && rxb->page);
  236. /* Get next free Rx buffer, remove from free list */
  237. element = rxq->rx_free.next;
  238. rxb = list_entry(element, struct il_rx_buf, list);
  239. list_del(element);
  240. /* Point to Rx buffer via next RBD in circular buffer */
  241. rxq->bd[rxq->write] =
  242. il4965_dma_addr2rbd_ptr(il, rxb->page_dma);
  243. rxq->queue[rxq->write] = rxb;
  244. rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
  245. rxq->free_count--;
  246. }
  247. spin_unlock_irqrestore(&rxq->lock, flags);
  248. /* If the pre-allocated buffer pool is dropping low, schedule to
  249. * refill it */
  250. if (rxq->free_count <= RX_LOW_WATERMARK)
  251. queue_work(il->workqueue, &il->rx_replenish);
  252. /* If we've added more space for the firmware to place data, tell it.
  253. * Increment device's write pointer in multiples of 8. */
  254. if (rxq->write_actual != (rxq->write & ~0x7)) {
  255. spin_lock_irqsave(&rxq->lock, flags);
  256. rxq->need_update = 1;
  257. spin_unlock_irqrestore(&rxq->lock, flags);
  258. il_rx_queue_update_write_ptr(il, rxq);
  259. }
  260. }
  261. /**
  262. * il4965_rx_replenish - Move all used packet from rx_used to rx_free
  263. *
  264. * When moving to rx_free an SKB is allocated for the slot.
  265. *
  266. * Also restock the Rx queue via il_rx_queue_restock.
  267. * This is called as a scheduled work item (except for during initialization)
  268. */
  269. static void
  270. il4965_rx_allocate(struct il_priv *il, gfp_t priority)
  271. {
  272. struct il_rx_queue *rxq = &il->rxq;
  273. struct list_head *element;
  274. struct il_rx_buf *rxb;
  275. struct page *page;
  276. unsigned long flags;
  277. gfp_t gfp_mask = priority;
  278. while (1) {
  279. spin_lock_irqsave(&rxq->lock, flags);
  280. if (list_empty(&rxq->rx_used)) {
  281. spin_unlock_irqrestore(&rxq->lock, flags);
  282. return;
  283. }
  284. spin_unlock_irqrestore(&rxq->lock, flags);
  285. if (rxq->free_count > RX_LOW_WATERMARK)
  286. gfp_mask |= __GFP_NOWARN;
  287. if (il->hw_params.rx_page_order > 0)
  288. gfp_mask |= __GFP_COMP;
  289. /* Alloc a new receive buffer */
  290. page = alloc_pages(gfp_mask, il->hw_params.rx_page_order);
  291. if (!page) {
  292. if (net_ratelimit())
  293. D_INFO("alloc_pages failed, " "order: %d\n",
  294. il->hw_params.rx_page_order);
  295. if (rxq->free_count <= RX_LOW_WATERMARK &&
  296. net_ratelimit())
  297. IL_ERR("Failed to alloc_pages with %s. "
  298. "Only %u free buffers remaining.\n",
  299. priority ==
  300. GFP_ATOMIC ? "GFP_ATOMIC" : "GFP_KERNEL",
  301. rxq->free_count);
  302. /* We don't reschedule replenish work here -- we will
  303. * call the restock method and if it still needs
  304. * more buffers it will schedule replenish */
  305. return;
  306. }
  307. spin_lock_irqsave(&rxq->lock, flags);
  308. if (list_empty(&rxq->rx_used)) {
  309. spin_unlock_irqrestore(&rxq->lock, flags);
  310. __free_pages(page, il->hw_params.rx_page_order);
  311. return;
  312. }
  313. element = rxq->rx_used.next;
  314. rxb = list_entry(element, struct il_rx_buf, list);
  315. list_del(element);
  316. spin_unlock_irqrestore(&rxq->lock, flags);
  317. BUG_ON(rxb->page);
  318. rxb->page = page;
  319. /* Get physical address of the RB */
  320. rxb->page_dma =
  321. pci_map_page(il->pci_dev, page, 0,
  322. PAGE_SIZE << il->hw_params.rx_page_order,
  323. PCI_DMA_FROMDEVICE);
  324. /* dma address must be no more than 36 bits */
  325. BUG_ON(rxb->page_dma & ~DMA_BIT_MASK(36));
  326. /* and also 256 byte aligned! */
  327. BUG_ON(rxb->page_dma & DMA_BIT_MASK(8));
  328. spin_lock_irqsave(&rxq->lock, flags);
  329. list_add_tail(&rxb->list, &rxq->rx_free);
  330. rxq->free_count++;
  331. il->alloc_rxb_page++;
  332. spin_unlock_irqrestore(&rxq->lock, flags);
  333. }
  334. }
  335. void
  336. il4965_rx_replenish(struct il_priv *il)
  337. {
  338. unsigned long flags;
  339. il4965_rx_allocate(il, GFP_KERNEL);
  340. spin_lock_irqsave(&il->lock, flags);
  341. il4965_rx_queue_restock(il);
  342. spin_unlock_irqrestore(&il->lock, flags);
  343. }
  344. void
  345. il4965_rx_replenish_now(struct il_priv *il)
  346. {
  347. il4965_rx_allocate(il, GFP_ATOMIC);
  348. il4965_rx_queue_restock(il);
  349. }
  350. /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
  351. * If an SKB has been detached, the POOL needs to have its SKB set to NULL
  352. * This free routine walks the list of POOL entries and if SKB is set to
  353. * non NULL it is unmapped and freed
  354. */
  355. void
  356. il4965_rx_queue_free(struct il_priv *il, struct il_rx_queue *rxq)
  357. {
  358. int i;
  359. for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
  360. if (rxq->pool[i].page != NULL) {
  361. pci_unmap_page(il->pci_dev, rxq->pool[i].page_dma,
  362. PAGE_SIZE << il->hw_params.rx_page_order,
  363. PCI_DMA_FROMDEVICE);
  364. __il_free_pages(il, rxq->pool[i].page);
  365. rxq->pool[i].page = NULL;
  366. }
  367. }
  368. dma_free_coherent(&il->pci_dev->dev, 4 * RX_QUEUE_SIZE, rxq->bd,
  369. rxq->bd_dma);
  370. dma_free_coherent(&il->pci_dev->dev, sizeof(struct il_rb_status),
  371. rxq->rb_stts, rxq->rb_stts_dma);
  372. rxq->bd = NULL;
  373. rxq->rb_stts = NULL;
  374. }
  375. int
  376. il4965_rxq_stop(struct il_priv *il)
  377. {
  378. /* stop Rx DMA */
  379. il_wr(il, FH49_MEM_RCSR_CHNL0_CONFIG_REG, 0);
  380. il_poll_bit(il, FH49_MEM_RSSR_RX_STATUS_REG,
  381. FH49_RSSR_CHNL0_RX_STATUS_CHNL_IDLE, 1000);
  382. return 0;
  383. }
  384. int
  385. il4965_hwrate_to_mac80211_idx(u32 rate_n_flags, enum ieee80211_band band)
  386. {
  387. int idx = 0;
  388. int band_offset = 0;
  389. /* HT rate format: mac80211 wants an MCS number, which is just LSB */
  390. if (rate_n_flags & RATE_MCS_HT_MSK) {
  391. idx = (rate_n_flags & 0xff);
  392. return idx;
  393. /* Legacy rate format, search for match in table */
  394. } else {
  395. if (band == IEEE80211_BAND_5GHZ)
  396. band_offset = IL_FIRST_OFDM_RATE;
  397. for (idx = band_offset; idx < RATE_COUNT_LEGACY; idx++)
  398. if (il_rates[idx].plcp == (rate_n_flags & 0xFF))
  399. return idx - band_offset;
  400. }
  401. return -1;
  402. }
  403. static int
  404. il4965_calc_rssi(struct il_priv *il, struct il_rx_phy_res *rx_resp)
  405. {
  406. /* data from PHY/DSP regarding signal strength, etc.,
  407. * contents are always there, not configurable by host. */
  408. struct il4965_rx_non_cfg_phy *ncphy =
  409. (struct il4965_rx_non_cfg_phy *)rx_resp->non_cfg_phy_buf;
  410. u32 agc =
  411. (le16_to_cpu(ncphy->agc_info) & IL49_AGC_DB_MASK) >>
  412. IL49_AGC_DB_POS;
  413. u32 valid_antennae =
  414. (le16_to_cpu(rx_resp->phy_flags) & IL49_RX_PHY_FLAGS_ANTENNAE_MASK)
  415. >> IL49_RX_PHY_FLAGS_ANTENNAE_OFFSET;
  416. u8 max_rssi = 0;
  417. u32 i;
  418. /* Find max rssi among 3 possible receivers.
  419. * These values are measured by the digital signal processor (DSP).
  420. * They should stay fairly constant even as the signal strength varies,
  421. * if the radio's automatic gain control (AGC) is working right.
  422. * AGC value (see below) will provide the "interesting" info. */
  423. for (i = 0; i < 3; i++)
  424. if (valid_antennae & (1 << i))
  425. max_rssi = max(ncphy->rssi_info[i << 1], max_rssi);
  426. D_STATS("Rssi In A %d B %d C %d Max %d AGC dB %d\n",
  427. ncphy->rssi_info[0], ncphy->rssi_info[2], ncphy->rssi_info[4],
  428. max_rssi, agc);
  429. /* dBm = max_rssi dB - agc dB - constant.
  430. * Higher AGC (higher radio gain) means lower signal. */
  431. return max_rssi - agc - IL4965_RSSI_OFFSET;
  432. }
  433. static u32
  434. il4965_translate_rx_status(struct il_priv *il, u32 decrypt_in)
  435. {
  436. u32 decrypt_out = 0;
  437. if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
  438. RX_RES_STATUS_STATION_FOUND)
  439. decrypt_out |=
  440. (RX_RES_STATUS_STATION_FOUND |
  441. RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
  442. decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
  443. /* packet was not encrypted */
  444. if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
  445. RX_RES_STATUS_SEC_TYPE_NONE)
  446. return decrypt_out;
  447. /* packet was encrypted with unknown alg */
  448. if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
  449. RX_RES_STATUS_SEC_TYPE_ERR)
  450. return decrypt_out;
  451. /* decryption was not done in HW */
  452. if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
  453. RX_MPDU_RES_STATUS_DEC_DONE_MSK)
  454. return decrypt_out;
  455. switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
  456. case RX_RES_STATUS_SEC_TYPE_CCMP:
  457. /* alg is CCM: check MIC only */
  458. if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
  459. /* Bad MIC */
  460. decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
  461. else
  462. decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
  463. break;
  464. case RX_RES_STATUS_SEC_TYPE_TKIP:
  465. if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
  466. /* Bad TTAK */
  467. decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
  468. break;
  469. }
  470. /* fall through if TTAK OK */
  471. default:
  472. if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
  473. decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
  474. else
  475. decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
  476. break;
  477. }
  478. D_RX("decrypt_in:0x%x decrypt_out = 0x%x\n", decrypt_in, decrypt_out);
  479. return decrypt_out;
  480. }
  481. static void
  482. il4965_pass_packet_to_mac80211(struct il_priv *il, struct ieee80211_hdr *hdr,
  483. u16 len, u32 ampdu_status, struct il_rx_buf *rxb,
  484. struct ieee80211_rx_status *stats)
  485. {
  486. struct sk_buff *skb;
  487. __le16 fc = hdr->frame_control;
  488. /* We only process data packets if the interface is open */
  489. if (unlikely(!il->is_open)) {
  490. D_DROP("Dropping packet while interface is not open.\n");
  491. return;
  492. }
  493. /* In case of HW accelerated crypto and bad decryption, drop */
  494. if (!il->cfg->mod_params->sw_crypto &&
  495. il_set_decrypted_flag(il, hdr, ampdu_status, stats))
  496. return;
  497. skb = dev_alloc_skb(128);
  498. if (!skb) {
  499. IL_ERR("dev_alloc_skb failed\n");
  500. return;
  501. }
  502. skb_add_rx_frag(skb, 0, rxb->page, (void *)hdr - rxb_addr(rxb), len);
  503. il_update_stats(il, false, fc, len);
  504. memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats));
  505. ieee80211_rx(il->hw, skb);
  506. il->alloc_rxb_page--;
  507. rxb->page = NULL;
  508. }
  509. /* Called for N_RX (legacy ABG frames), or
  510. * N_RX_MPDU (HT high-throughput N frames). */
  511. void
  512. il4965_hdl_rx(struct il_priv *il, struct il_rx_buf *rxb)
  513. {
  514. struct ieee80211_hdr *header;
  515. struct ieee80211_rx_status rx_status;
  516. struct il_rx_pkt *pkt = rxb_addr(rxb);
  517. struct il_rx_phy_res *phy_res;
  518. __le32 rx_pkt_status;
  519. struct il_rx_mpdu_res_start *amsdu;
  520. u32 len;
  521. u32 ampdu_status;
  522. u32 rate_n_flags;
  523. /**
  524. * N_RX and N_RX_MPDU are handled differently.
  525. * N_RX: physical layer info is in this buffer
  526. * N_RX_MPDU: physical layer info was sent in separate
  527. * command and cached in il->last_phy_res
  528. *
  529. * Here we set up local variables depending on which command is
  530. * received.
  531. */
  532. if (pkt->hdr.cmd == N_RX) {
  533. phy_res = (struct il_rx_phy_res *)pkt->u.raw;
  534. header =
  535. (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*phy_res) +
  536. phy_res->cfg_phy_cnt);
  537. len = le16_to_cpu(phy_res->byte_count);
  538. rx_pkt_status =
  539. *(__le32 *) (pkt->u.raw + sizeof(*phy_res) +
  540. phy_res->cfg_phy_cnt + len);
  541. ampdu_status = le32_to_cpu(rx_pkt_status);
  542. } else {
  543. if (!il->_4965.last_phy_res_valid) {
  544. IL_ERR("MPDU frame without cached PHY data\n");
  545. return;
  546. }
  547. phy_res = &il->_4965.last_phy_res;
  548. amsdu = (struct il_rx_mpdu_res_start *)pkt->u.raw;
  549. header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*amsdu));
  550. len = le16_to_cpu(amsdu->byte_count);
  551. rx_pkt_status = *(__le32 *) (pkt->u.raw + sizeof(*amsdu) + len);
  552. ampdu_status =
  553. il4965_translate_rx_status(il, le32_to_cpu(rx_pkt_status));
  554. }
  555. if ((unlikely(phy_res->cfg_phy_cnt > 20))) {
  556. D_DROP("dsp size out of range [0,20]: %d/n",
  557. phy_res->cfg_phy_cnt);
  558. return;
  559. }
  560. if (!(rx_pkt_status & RX_RES_STATUS_NO_CRC32_ERROR) ||
  561. !(rx_pkt_status & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
  562. D_RX("Bad CRC or FIFO: 0x%08X.\n", le32_to_cpu(rx_pkt_status));
  563. return;
  564. }
  565. /* This will be used in several places later */
  566. rate_n_flags = le32_to_cpu(phy_res->rate_n_flags);
  567. /* rx_status carries information about the packet to mac80211 */
  568. rx_status.mactime = le64_to_cpu(phy_res->timestamp);
  569. rx_status.band =
  570. (phy_res->
  571. phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ? IEEE80211_BAND_2GHZ :
  572. IEEE80211_BAND_5GHZ;
  573. rx_status.freq =
  574. ieee80211_channel_to_frequency(le16_to_cpu(phy_res->channel),
  575. rx_status.band);
  576. rx_status.rate_idx =
  577. il4965_hwrate_to_mac80211_idx(rate_n_flags, rx_status.band);
  578. rx_status.flag = 0;
  579. /* TSF isn't reliable. In order to allow smooth user experience,
  580. * this W/A doesn't propagate it to the mac80211 */
  581. /*rx_status.flag |= RX_FLAG_MACTIME_MPDU; */
  582. il->ucode_beacon_time = le32_to_cpu(phy_res->beacon_time_stamp);
  583. /* Find max signal strength (dBm) among 3 antenna/receiver chains */
  584. rx_status.signal = il4965_calc_rssi(il, phy_res);
  585. il_dbg_log_rx_data_frame(il, len, header);
  586. D_STATS("Rssi %d, TSF %llu\n", rx_status.signal,
  587. (unsigned long long)rx_status.mactime);
  588. /*
  589. * "antenna number"
  590. *
  591. * It seems that the antenna field in the phy flags value
  592. * is actually a bit field. This is undefined by radiotap,
  593. * it wants an actual antenna number but I always get "7"
  594. * for most legacy frames I receive indicating that the
  595. * same frame was received on all three RX chains.
  596. *
  597. * I think this field should be removed in favor of a
  598. * new 802.11n radiotap field "RX chains" that is defined
  599. * as a bitmask.
  600. */
  601. rx_status.antenna =
  602. (le16_to_cpu(phy_res->phy_flags) & RX_RES_PHY_FLAGS_ANTENNA_MSK) >>
  603. RX_RES_PHY_FLAGS_ANTENNA_POS;
  604. /* set the preamble flag if appropriate */
  605. if (phy_res->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
  606. rx_status.flag |= RX_FLAG_SHORTPRE;
  607. /* Set up the HT phy flags */
  608. if (rate_n_flags & RATE_MCS_HT_MSK)
  609. rx_status.flag |= RX_FLAG_HT;
  610. if (rate_n_flags & RATE_MCS_HT40_MSK)
  611. rx_status.flag |= RX_FLAG_40MHZ;
  612. if (rate_n_flags & RATE_MCS_SGI_MSK)
  613. rx_status.flag |= RX_FLAG_SHORT_GI;
  614. il4965_pass_packet_to_mac80211(il, header, len, ampdu_status, rxb,
  615. &rx_status);
  616. }
  617. /* Cache phy data (Rx signal strength, etc) for HT frame (N_RX_PHY).
  618. * This will be used later in il_hdl_rx() for N_RX_MPDU. */
  619. void
  620. il4965_hdl_rx_phy(struct il_priv *il, struct il_rx_buf *rxb)
  621. {
  622. struct il_rx_pkt *pkt = rxb_addr(rxb);
  623. il->_4965.last_phy_res_valid = true;
  624. memcpy(&il->_4965.last_phy_res, pkt->u.raw,
  625. sizeof(struct il_rx_phy_res));
  626. }
  627. static int
  628. il4965_get_channels_for_scan(struct il_priv *il, struct ieee80211_vif *vif,
  629. enum ieee80211_band band, u8 is_active,
  630. u8 n_probes, struct il_scan_channel *scan_ch)
  631. {
  632. struct ieee80211_channel *chan;
  633. const struct ieee80211_supported_band *sband;
  634. const struct il_channel_info *ch_info;
  635. u16 passive_dwell = 0;
  636. u16 active_dwell = 0;
  637. int added, i;
  638. u16 channel;
  639. sband = il_get_hw_mode(il, band);
  640. if (!sband)
  641. return 0;
  642. active_dwell = il_get_active_dwell_time(il, band, n_probes);
  643. passive_dwell = il_get_passive_dwell_time(il, band, vif);
  644. if (passive_dwell <= active_dwell)
  645. passive_dwell = active_dwell + 1;
  646. for (i = 0, added = 0; i < il->scan_request->n_channels; i++) {
  647. chan = il->scan_request->channels[i];
  648. if (chan->band != band)
  649. continue;
  650. channel = chan->hw_value;
  651. scan_ch->channel = cpu_to_le16(channel);
  652. ch_info = il_get_channel_info(il, band, channel);
  653. if (!il_is_channel_valid(ch_info)) {
  654. D_SCAN("Channel %d is INVALID for this band.\n",
  655. channel);
  656. continue;
  657. }
  658. if (!is_active || il_is_channel_passive(ch_info) ||
  659. (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN))
  660. scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
  661. else
  662. scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE;
  663. if (n_probes)
  664. scan_ch->type |= IL_SCAN_PROBE_MASK(n_probes);
  665. scan_ch->active_dwell = cpu_to_le16(active_dwell);
  666. scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
  667. /* Set txpower levels to defaults */
  668. scan_ch->dsp_atten = 110;
  669. /* NOTE: if we were doing 6Mb OFDM for scans we'd use
  670. * power level:
  671. * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3;
  672. */
  673. if (band == IEEE80211_BAND_5GHZ)
  674. scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3;
  675. else
  676. scan_ch->tx_gain = ((1 << 5) | (5 << 3));
  677. D_SCAN("Scanning ch=%d prob=0x%X [%s %d]\n", channel,
  678. le32_to_cpu(scan_ch->type),
  679. (scan_ch->
  680. type & SCAN_CHANNEL_TYPE_ACTIVE) ? "ACTIVE" : "PASSIVE",
  681. (scan_ch->
  682. type & SCAN_CHANNEL_TYPE_ACTIVE) ? active_dwell :
  683. passive_dwell);
  684. scan_ch++;
  685. added++;
  686. }
  687. D_SCAN("total channels to scan %d\n", added);
  688. return added;
  689. }
  690. static inline u32
  691. il4965_ant_idx_to_flags(u8 ant_idx)
  692. {
  693. return BIT(ant_idx) << RATE_MCS_ANT_POS;
  694. }
  695. int
  696. il4965_request_scan(struct il_priv *il, struct ieee80211_vif *vif)
  697. {
  698. struct il_host_cmd cmd = {
  699. .id = C_SCAN,
  700. .len = sizeof(struct il_scan_cmd),
  701. .flags = CMD_SIZE_HUGE,
  702. };
  703. struct il_scan_cmd *scan;
  704. struct il_rxon_context *ctx = &il->ctx;
  705. u32 rate_flags = 0;
  706. u16 cmd_len;
  707. u16 rx_chain = 0;
  708. enum ieee80211_band band;
  709. u8 n_probes = 0;
  710. u8 rx_ant = il->hw_params.valid_rx_ant;
  711. u8 rate;
  712. bool is_active = false;
  713. int chan_mod;
  714. u8 active_chains;
  715. u8 scan_tx_antennas = il->hw_params.valid_tx_ant;
  716. int ret;
  717. lockdep_assert_held(&il->mutex);
  718. ctx = il_rxon_ctx_from_vif(vif);
  719. if (!il->scan_cmd) {
  720. il->scan_cmd =
  721. kmalloc(sizeof(struct il_scan_cmd) + IL_MAX_SCAN_SIZE,
  722. GFP_KERNEL);
  723. if (!il->scan_cmd) {
  724. D_SCAN("fail to allocate memory for scan\n");
  725. return -ENOMEM;
  726. }
  727. }
  728. scan = il->scan_cmd;
  729. memset(scan, 0, sizeof(struct il_scan_cmd) + IL_MAX_SCAN_SIZE);
  730. scan->quiet_plcp_th = IL_PLCP_QUIET_THRESH;
  731. scan->quiet_time = IL_ACTIVE_QUIET_TIME;
  732. if (il_is_any_associated(il)) {
  733. u16 interval;
  734. u32 extra;
  735. u32 suspend_time = 100;
  736. u32 scan_suspend_time = 100;
  737. D_INFO("Scanning while associated...\n");
  738. interval = vif->bss_conf.beacon_int;
  739. scan->suspend_time = 0;
  740. scan->max_out_time = cpu_to_le32(200 * 1024);
  741. if (!interval)
  742. interval = suspend_time;
  743. extra = (suspend_time / interval) << 22;
  744. scan_suspend_time =
  745. (extra | ((suspend_time % interval) * 1024));
  746. scan->suspend_time = cpu_to_le32(scan_suspend_time);
  747. D_SCAN("suspend_time 0x%X beacon interval %d\n",
  748. scan_suspend_time, interval);
  749. }
  750. if (il->scan_request->n_ssids) {
  751. int i, p = 0;
  752. D_SCAN("Kicking off active scan\n");
  753. for (i = 0; i < il->scan_request->n_ssids; i++) {
  754. /* always does wildcard anyway */
  755. if (!il->scan_request->ssids[i].ssid_len)
  756. continue;
  757. scan->direct_scan[p].id = WLAN_EID_SSID;
  758. scan->direct_scan[p].len =
  759. il->scan_request->ssids[i].ssid_len;
  760. memcpy(scan->direct_scan[p].ssid,
  761. il->scan_request->ssids[i].ssid,
  762. il->scan_request->ssids[i].ssid_len);
  763. n_probes++;
  764. p++;
  765. }
  766. is_active = true;
  767. } else
  768. D_SCAN("Start passive scan.\n");
  769. scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
  770. scan->tx_cmd.sta_id = ctx->bcast_sta_id;
  771. scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  772. switch (il->scan_band) {
  773. case IEEE80211_BAND_2GHZ:
  774. scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
  775. chan_mod =
  776. le32_to_cpu(il->ctx.active.
  777. flags & RXON_FLG_CHANNEL_MODE_MSK) >>
  778. RXON_FLG_CHANNEL_MODE_POS;
  779. if (chan_mod == CHANNEL_MODE_PURE_40) {
  780. rate = RATE_6M_PLCP;
  781. } else {
  782. rate = RATE_1M_PLCP;
  783. rate_flags = RATE_MCS_CCK_MSK;
  784. }
  785. break;
  786. case IEEE80211_BAND_5GHZ:
  787. rate = RATE_6M_PLCP;
  788. break;
  789. default:
  790. IL_WARN("Invalid scan band\n");
  791. return -EIO;
  792. }
  793. /*
  794. * If active scanning is requested but a certain channel is
  795. * marked passive, we can do active scanning if we detect
  796. * transmissions.
  797. *
  798. * There is an issue with some firmware versions that triggers
  799. * a sysassert on a "good CRC threshold" of zero (== disabled),
  800. * on a radar channel even though this means that we should NOT
  801. * send probes.
  802. *
  803. * The "good CRC threshold" is the number of frames that we
  804. * need to receive during our dwell time on a channel before
  805. * sending out probes -- setting this to a huge value will
  806. * mean we never reach it, but at the same time work around
  807. * the aforementioned issue. Thus use IL_GOOD_CRC_TH_NEVER
  808. * here instead of IL_GOOD_CRC_TH_DISABLED.
  809. */
  810. scan->good_CRC_th =
  811. is_active ? IL_GOOD_CRC_TH_DEFAULT : IL_GOOD_CRC_TH_NEVER;
  812. band = il->scan_band;
  813. if (il->cfg->scan_rx_antennas[band])
  814. rx_ant = il->cfg->scan_rx_antennas[band];
  815. il->scan_tx_ant[band] =
  816. il4965_toggle_tx_ant(il, il->scan_tx_ant[band], scan_tx_antennas);
  817. rate_flags |= il4965_ant_idx_to_flags(il->scan_tx_ant[band]);
  818. scan->tx_cmd.rate_n_flags =
  819. il4965_hw_set_rate_n_flags(rate, rate_flags);
  820. /* In power save mode use one chain, otherwise use all chains */
  821. if (test_bit(S_POWER_PMI, &il->status)) {
  822. /* rx_ant has been set to all valid chains previously */
  823. active_chains =
  824. rx_ant & ((u8) (il->chain_noise_data.active_chains));
  825. if (!active_chains)
  826. active_chains = rx_ant;
  827. D_SCAN("chain_noise_data.active_chains: %u\n",
  828. il->chain_noise_data.active_chains);
  829. rx_ant = il4965_first_antenna(active_chains);
  830. }
  831. /* MIMO is not used here, but value is required */
  832. rx_chain |= il->hw_params.valid_rx_ant << RXON_RX_CHAIN_VALID_POS;
  833. rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS;
  834. rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_SEL_POS;
  835. rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS;
  836. scan->rx_chain = cpu_to_le16(rx_chain);
  837. cmd_len =
  838. il_fill_probe_req(il, (struct ieee80211_mgmt *)scan->data,
  839. vif->addr, il->scan_request->ie,
  840. il->scan_request->ie_len,
  841. IL_MAX_SCAN_SIZE - sizeof(*scan));
  842. scan->tx_cmd.len = cpu_to_le16(cmd_len);
  843. scan->filter_flags |=
  844. (RXON_FILTER_ACCEPT_GRP_MSK | RXON_FILTER_BCON_AWARE_MSK);
  845. scan->channel_count =
  846. il4965_get_channels_for_scan(il, vif, band, is_active, n_probes,
  847. (void *)&scan->data[cmd_len]);
  848. if (scan->channel_count == 0) {
  849. D_SCAN("channel count %d\n", scan->channel_count);
  850. return -EIO;
  851. }
  852. cmd.len +=
  853. le16_to_cpu(scan->tx_cmd.len) +
  854. scan->channel_count * sizeof(struct il_scan_channel);
  855. cmd.data = scan;
  856. scan->len = cpu_to_le16(cmd.len);
  857. set_bit(S_SCAN_HW, &il->status);
  858. ret = il_send_cmd_sync(il, &cmd);
  859. if (ret)
  860. clear_bit(S_SCAN_HW, &il->status);
  861. return ret;
  862. }
  863. int
  864. il4965_manage_ibss_station(struct il_priv *il, struct ieee80211_vif *vif,
  865. bool add)
  866. {
  867. struct il_vif_priv *vif_priv = (void *)vif->drv_priv;
  868. if (add)
  869. return il4965_add_bssid_station(il, vif_priv->ctx,
  870. vif->bss_conf.bssid,
  871. &vif_priv->ibss_bssid_sta_id);
  872. return il_remove_station(il, vif_priv->ibss_bssid_sta_id,
  873. vif->bss_conf.bssid);
  874. }
  875. void
  876. il4965_free_tfds_in_queue(struct il_priv *il, int sta_id, int tid, int freed)
  877. {
  878. lockdep_assert_held(&il->sta_lock);
  879. if (il->stations[sta_id].tid[tid].tfds_in_queue >= freed)
  880. il->stations[sta_id].tid[tid].tfds_in_queue -= freed;
  881. else {
  882. D_TX("free more than tfds_in_queue (%u:%d)\n",
  883. il->stations[sta_id].tid[tid].tfds_in_queue, freed);
  884. il->stations[sta_id].tid[tid].tfds_in_queue = 0;
  885. }
  886. }
  887. #define IL_TX_QUEUE_MSK 0xfffff
  888. static bool
  889. il4965_is_single_rx_stream(struct il_priv *il)
  890. {
  891. return il->current_ht_config.smps == IEEE80211_SMPS_STATIC ||
  892. il->current_ht_config.single_chain_sufficient;
  893. }
  894. #define IL_NUM_RX_CHAINS_MULTIPLE 3
  895. #define IL_NUM_RX_CHAINS_SINGLE 2
  896. #define IL_NUM_IDLE_CHAINS_DUAL 2
  897. #define IL_NUM_IDLE_CHAINS_SINGLE 1
  898. /*
  899. * Determine how many receiver/antenna chains to use.
  900. *
  901. * More provides better reception via diversity. Fewer saves power
  902. * at the expense of throughput, but only when not in powersave to
  903. * start with.
  904. *
  905. * MIMO (dual stream) requires at least 2, but works better with 3.
  906. * This does not determine *which* chains to use, just how many.
  907. */
  908. static int
  909. il4965_get_active_rx_chain_count(struct il_priv *il)
  910. {
  911. /* # of Rx chains to use when expecting MIMO. */
  912. if (il4965_is_single_rx_stream(il))
  913. return IL_NUM_RX_CHAINS_SINGLE;
  914. else
  915. return IL_NUM_RX_CHAINS_MULTIPLE;
  916. }
  917. /*
  918. * When we are in power saving mode, unless device support spatial
  919. * multiplexing power save, use the active count for rx chain count.
  920. */
  921. static int
  922. il4965_get_idle_rx_chain_count(struct il_priv *il, int active_cnt)
  923. {
  924. /* # Rx chains when idling, depending on SMPS mode */
  925. switch (il->current_ht_config.smps) {
  926. case IEEE80211_SMPS_STATIC:
  927. case IEEE80211_SMPS_DYNAMIC:
  928. return IL_NUM_IDLE_CHAINS_SINGLE;
  929. case IEEE80211_SMPS_OFF:
  930. return active_cnt;
  931. default:
  932. WARN(1, "invalid SMPS mode %d", il->current_ht_config.smps);
  933. return active_cnt;
  934. }
  935. }
  936. /* up to 4 chains */
  937. static u8
  938. il4965_count_chain_bitmap(u32 chain_bitmap)
  939. {
  940. u8 res;
  941. res = (chain_bitmap & BIT(0)) >> 0;
  942. res += (chain_bitmap & BIT(1)) >> 1;
  943. res += (chain_bitmap & BIT(2)) >> 2;
  944. res += (chain_bitmap & BIT(3)) >> 3;
  945. return res;
  946. }
  947. /**
  948. * il4965_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
  949. *
  950. * Selects how many and which Rx receivers/antennas/chains to use.
  951. * This should not be used for scan command ... it puts data in wrong place.
  952. */
  953. void
  954. il4965_set_rxon_chain(struct il_priv *il, struct il_rxon_context *ctx)
  955. {
  956. bool is_single = il4965_is_single_rx_stream(il);
  957. bool is_cam = !test_bit(S_POWER_PMI, &il->status);
  958. u8 idle_rx_cnt, active_rx_cnt, valid_rx_cnt;
  959. u32 active_chains;
  960. u16 rx_chain;
  961. /* Tell uCode which antennas are actually connected.
  962. * Before first association, we assume all antennas are connected.
  963. * Just after first association, il4965_chain_noise_calibration()
  964. * checks which antennas actually *are* connected. */
  965. if (il->chain_noise_data.active_chains)
  966. active_chains = il->chain_noise_data.active_chains;
  967. else
  968. active_chains = il->hw_params.valid_rx_ant;
  969. rx_chain = active_chains << RXON_RX_CHAIN_VALID_POS;
  970. /* How many receivers should we use? */
  971. active_rx_cnt = il4965_get_active_rx_chain_count(il);
  972. idle_rx_cnt = il4965_get_idle_rx_chain_count(il, active_rx_cnt);
  973. /* correct rx chain count according hw settings
  974. * and chain noise calibration
  975. */
  976. valid_rx_cnt = il4965_count_chain_bitmap(active_chains);
  977. if (valid_rx_cnt < active_rx_cnt)
  978. active_rx_cnt = valid_rx_cnt;
  979. if (valid_rx_cnt < idle_rx_cnt)
  980. idle_rx_cnt = valid_rx_cnt;
  981. rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS;
  982. rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS;
  983. ctx->staging.rx_chain = cpu_to_le16(rx_chain);
  984. if (!is_single && active_rx_cnt >= IL_NUM_RX_CHAINS_SINGLE && is_cam)
  985. ctx->staging.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
  986. else
  987. ctx->staging.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
  988. D_ASSOC("rx_chain=0x%X active=%d idle=%d\n", ctx->staging.rx_chain,
  989. active_rx_cnt, idle_rx_cnt);
  990. WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 ||
  991. active_rx_cnt < idle_rx_cnt);
  992. }
  993. u8
  994. il4965_toggle_tx_ant(struct il_priv *il, u8 ant, u8 valid)
  995. {
  996. int i;
  997. u8 ind = ant;
  998. for (i = 0; i < RATE_ANT_NUM - 1; i++) {
  999. ind = (ind + 1) < RATE_ANT_NUM ? ind + 1 : 0;
  1000. if (valid & BIT(ind))
  1001. return ind;
  1002. }
  1003. return ant;
  1004. }
  1005. static const char *
  1006. il4965_get_fh_string(int cmd)
  1007. {
  1008. switch (cmd) {
  1009. IL_CMD(FH49_RSCSR_CHNL0_STTS_WPTR_REG);
  1010. IL_CMD(FH49_RSCSR_CHNL0_RBDCB_BASE_REG);
  1011. IL_CMD(FH49_RSCSR_CHNL0_WPTR);
  1012. IL_CMD(FH49_MEM_RCSR_CHNL0_CONFIG_REG);
  1013. IL_CMD(FH49_MEM_RSSR_SHARED_CTRL_REG);
  1014. IL_CMD(FH49_MEM_RSSR_RX_STATUS_REG);
  1015. IL_CMD(FH49_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV);
  1016. IL_CMD(FH49_TSSR_TX_STATUS_REG);
  1017. IL_CMD(FH49_TSSR_TX_ERROR_REG);
  1018. default:
  1019. return "UNKNOWN";
  1020. }
  1021. }
  1022. int
  1023. il4965_dump_fh(struct il_priv *il, char **buf, bool display)
  1024. {
  1025. int i;
  1026. #ifdef CONFIG_IWLEGACY_DEBUG
  1027. int pos = 0;
  1028. size_t bufsz = 0;
  1029. #endif
  1030. static const u32 fh_tbl[] = {
  1031. FH49_RSCSR_CHNL0_STTS_WPTR_REG,
  1032. FH49_RSCSR_CHNL0_RBDCB_BASE_REG,
  1033. FH49_RSCSR_CHNL0_WPTR,
  1034. FH49_MEM_RCSR_CHNL0_CONFIG_REG,
  1035. FH49_MEM_RSSR_SHARED_CTRL_REG,
  1036. FH49_MEM_RSSR_RX_STATUS_REG,
  1037. FH49_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV,
  1038. FH49_TSSR_TX_STATUS_REG,
  1039. FH49_TSSR_TX_ERROR_REG
  1040. };
  1041. #ifdef CONFIG_IWLEGACY_DEBUG
  1042. if (display) {
  1043. bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40;
  1044. *buf = kmalloc(bufsz, GFP_KERNEL);
  1045. if (!*buf)
  1046. return -ENOMEM;
  1047. pos +=
  1048. scnprintf(*buf + pos, bufsz - pos, "FH register values:\n");
  1049. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) {
  1050. pos +=
  1051. scnprintf(*buf + pos, bufsz - pos,
  1052. " %34s: 0X%08x\n",
  1053. il4965_get_fh_string(fh_tbl[i]),
  1054. il_rd(il, fh_tbl[i]));
  1055. }
  1056. return pos;
  1057. }
  1058. #endif
  1059. IL_ERR("FH register values:\n");
  1060. for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) {
  1061. IL_ERR(" %34s: 0X%08x\n", il4965_get_fh_string(fh_tbl[i]),
  1062. il_rd(il, fh_tbl[i]));
  1063. }
  1064. return 0;
  1065. }
  1066. void
  1067. il4965_hdl_missed_beacon(struct il_priv *il, struct il_rx_buf *rxb)
  1068. {
  1069. struct il_rx_pkt *pkt = rxb_addr(rxb);
  1070. struct il_missed_beacon_notif *missed_beacon;
  1071. missed_beacon = &pkt->u.missed_beacon;
  1072. if (le32_to_cpu(missed_beacon->consecutive_missed_beacons) >
  1073. il->missed_beacon_threshold) {
  1074. D_CALIB("missed bcn cnsq %d totl %d rcd %d expctd %d\n",
  1075. le32_to_cpu(missed_beacon->consecutive_missed_beacons),
  1076. le32_to_cpu(missed_beacon->total_missed_becons),
  1077. le32_to_cpu(missed_beacon->num_recvd_beacons),
  1078. le32_to_cpu(missed_beacon->num_expected_beacons));
  1079. if (!test_bit(S_SCANNING, &il->status))
  1080. il4965_init_sensitivity(il);
  1081. }
  1082. }
  1083. /* Calculate noise level, based on measurements during network silence just
  1084. * before arriving beacon. This measurement can be done only if we know
  1085. * exactly when to expect beacons, therefore only when we're associated. */
  1086. static void
  1087. il4965_rx_calc_noise(struct il_priv *il)
  1088. {
  1089. struct stats_rx_non_phy *rx_info;
  1090. int num_active_rx = 0;
  1091. int total_silence = 0;
  1092. int bcn_silence_a, bcn_silence_b, bcn_silence_c;
  1093. int last_rx_noise;
  1094. rx_info = &(il->_4965.stats.rx.general);
  1095. bcn_silence_a =
  1096. le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
  1097. bcn_silence_b =
  1098. le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
  1099. bcn_silence_c =
  1100. le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
  1101. if (bcn_silence_a) {
  1102. total_silence += bcn_silence_a;
  1103. num_active_rx++;
  1104. }
  1105. if (bcn_silence_b) {
  1106. total_silence += bcn_silence_b;
  1107. num_active_rx++;
  1108. }
  1109. if (bcn_silence_c) {
  1110. total_silence += bcn_silence_c;
  1111. num_active_rx++;
  1112. }
  1113. /* Average among active antennas */
  1114. if (num_active_rx)
  1115. last_rx_noise = (total_silence / num_active_rx) - 107;
  1116. else
  1117. last_rx_noise = IL_NOISE_MEAS_NOT_AVAILABLE;
  1118. D_CALIB("inband silence a %u, b %u, c %u, dBm %d\n", bcn_silence_a,
  1119. bcn_silence_b, bcn_silence_c, last_rx_noise);
  1120. }
  1121. #ifdef CONFIG_IWLEGACY_DEBUGFS
  1122. /*
  1123. * based on the assumption of all stats counter are in DWORD
  1124. * FIXME: This function is for debugging, do not deal with
  1125. * the case of counters roll-over.
  1126. */
  1127. static void
  1128. il4965_accumulative_stats(struct il_priv *il, __le32 * stats)
  1129. {
  1130. int i, size;
  1131. __le32 *prev_stats;
  1132. u32 *accum_stats;
  1133. u32 *delta, *max_delta;
  1134. struct stats_general_common *general, *accum_general;
  1135. struct stats_tx *tx, *accum_tx;
  1136. prev_stats = (__le32 *) &il->_4965.stats;
  1137. accum_stats = (u32 *) &il->_4965.accum_stats;
  1138. size = sizeof(struct il_notif_stats);
  1139. general = &il->_4965.stats.general.common;
  1140. accum_general = &il->_4965.accum_stats.general.common;
  1141. tx = &il->_4965.stats.tx;
  1142. accum_tx = &il->_4965.accum_stats.tx;
  1143. delta = (u32 *) &il->_4965.delta_stats;
  1144. max_delta = (u32 *) &il->_4965.max_delta;
  1145. for (i = sizeof(__le32); i < size;
  1146. i +=
  1147. sizeof(__le32), stats++, prev_stats++, delta++, max_delta++,
  1148. accum_stats++) {
  1149. if (le32_to_cpu(*stats) > le32_to_cpu(*prev_stats)) {
  1150. *delta =
  1151. (le32_to_cpu(*stats) - le32_to_cpu(*prev_stats));
  1152. *accum_stats += *delta;
  1153. if (*delta > *max_delta)
  1154. *max_delta = *delta;
  1155. }
  1156. }
  1157. /* reset accumulative stats for "no-counter" type stats */
  1158. accum_general->temperature = general->temperature;
  1159. accum_general->ttl_timestamp = general->ttl_timestamp;
  1160. }
  1161. #endif
  1162. #define REG_RECALIB_PERIOD (60)
  1163. void
  1164. il4965_hdl_stats(struct il_priv *il, struct il_rx_buf *rxb)
  1165. {
  1166. int change;
  1167. struct il_rx_pkt *pkt = rxb_addr(rxb);
  1168. D_RX("Statistics notification received (%d vs %d).\n",
  1169. (int)sizeof(struct il_notif_stats),
  1170. le32_to_cpu(pkt->len_n_flags) & IL_RX_FRAME_SIZE_MSK);
  1171. change =
  1172. ((il->_4965.stats.general.common.temperature !=
  1173. pkt->u.stats.general.common.temperature) ||
  1174. ((il->_4965.stats.flag & STATS_REPLY_FLG_HT40_MODE_MSK) !=
  1175. (pkt->u.stats.flag & STATS_REPLY_FLG_HT40_MODE_MSK)));
  1176. #ifdef CONFIG_IWLEGACY_DEBUGFS
  1177. il4965_accumulative_stats(il, (__le32 *) &pkt->u.stats);
  1178. #endif
  1179. /* TODO: reading some of stats is unneeded */
  1180. memcpy(&il->_4965.stats, &pkt->u.stats, sizeof(il->_4965.stats));
  1181. set_bit(S_STATS, &il->status);
  1182. /* Reschedule the stats timer to occur in
  1183. * REG_RECALIB_PERIOD seconds to ensure we get a
  1184. * thermal update even if the uCode doesn't give
  1185. * us one */
  1186. mod_timer(&il->stats_periodic,
  1187. jiffies + msecs_to_jiffies(REG_RECALIB_PERIOD * 1000));
  1188. if (unlikely(!test_bit(S_SCANNING, &il->status)) &&
  1189. (pkt->hdr.cmd == N_STATS)) {
  1190. il4965_rx_calc_noise(il);
  1191. queue_work(il->workqueue, &il->run_time_calib_work);
  1192. }
  1193. if (il->cfg->ops->lib->temp_ops.temperature && change)
  1194. il->cfg->ops->lib->temp_ops.temperature(il);
  1195. }
  1196. void
  1197. il4965_hdl_c_stats(struct il_priv *il, struct il_rx_buf *rxb)
  1198. {
  1199. struct il_rx_pkt *pkt = rxb_addr(rxb);
  1200. if (le32_to_cpu(pkt->u.stats.flag) & UCODE_STATS_CLEAR_MSK) {
  1201. #ifdef CONFIG_IWLEGACY_DEBUGFS
  1202. memset(&il->_4965.accum_stats, 0,
  1203. sizeof(struct il_notif_stats));
  1204. memset(&il->_4965.delta_stats, 0,
  1205. sizeof(struct il_notif_stats));
  1206. memset(&il->_4965.max_delta, 0, sizeof(struct il_notif_stats));
  1207. #endif
  1208. D_RX("Statistics have been cleared\n");
  1209. }
  1210. il4965_hdl_stats(il, rxb);
  1211. }
  1212. /*
  1213. * mac80211 queues, ACs, hardware queues, FIFOs.
  1214. *
  1215. * Cf. http://wireless.kernel.org/en/developers/Documentation/mac80211/queues
  1216. *
  1217. * Mac80211 uses the following numbers, which we get as from it
  1218. * by way of skb_get_queue_mapping(skb):
  1219. *
  1220. * VO 0
  1221. * VI 1
  1222. * BE 2
  1223. * BK 3
  1224. *
  1225. *
  1226. * Regular (not A-MPDU) frames are put into hardware queues corresponding
  1227. * to the FIFOs, see comments in iwl-prph.h. Aggregated frames get their
  1228. * own queue per aggregation session (RA/TID combination), such queues are
  1229. * set up to map into FIFOs too, for which we need an AC->FIFO mapping. In
  1230. * order to map frames to the right queue, we also need an AC->hw queue
  1231. * mapping. This is implemented here.
  1232. *
  1233. * Due to the way hw queues are set up (by the hw specific modules like
  1234. * 4965.c), the AC->hw queue mapping is the identity
  1235. * mapping.
  1236. */
  1237. static const u8 tid_to_ac[] = {
  1238. IEEE80211_AC_BE,
  1239. IEEE80211_AC_BK,
  1240. IEEE80211_AC_BK,
  1241. IEEE80211_AC_BE,
  1242. IEEE80211_AC_VI,
  1243. IEEE80211_AC_VI,
  1244. IEEE80211_AC_VO,
  1245. IEEE80211_AC_VO
  1246. };
  1247. static inline int
  1248. il4965_get_ac_from_tid(u16 tid)
  1249. {
  1250. if (likely(tid < ARRAY_SIZE(tid_to_ac)))
  1251. return tid_to_ac[tid];
  1252. /* no support for TIDs 8-15 yet */
  1253. return -EINVAL;
  1254. }
  1255. static inline int
  1256. il4965_get_fifo_from_tid(struct il_rxon_context *ctx, u16 tid)
  1257. {
  1258. if (likely(tid < ARRAY_SIZE(tid_to_ac)))
  1259. return ctx->ac_to_fifo[tid_to_ac[tid]];
  1260. /* no support for TIDs 8-15 yet */
  1261. return -EINVAL;
  1262. }
  1263. /*
  1264. * handle build C_TX command notification.
  1265. */
  1266. static void
  1267. il4965_tx_cmd_build_basic(struct il_priv *il, struct sk_buff *skb,
  1268. struct il_tx_cmd *tx_cmd,
  1269. struct ieee80211_tx_info *info,
  1270. struct ieee80211_hdr *hdr, u8 std_id)
  1271. {
  1272. __le16 fc = hdr->frame_control;
  1273. __le32 tx_flags = tx_cmd->tx_flags;
  1274. tx_cmd->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  1275. if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
  1276. tx_flags |= TX_CMD_FLG_ACK_MSK;
  1277. if (ieee80211_is_mgmt(fc))
  1278. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  1279. if (ieee80211_is_probe_resp(fc) &&
  1280. !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
  1281. tx_flags |= TX_CMD_FLG_TSF_MSK;
  1282. } else {
  1283. tx_flags &= (~TX_CMD_FLG_ACK_MSK);
  1284. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  1285. }
  1286. if (ieee80211_is_back_req(fc))
  1287. tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK;
  1288. tx_cmd->sta_id = std_id;
  1289. if (ieee80211_has_morefrags(fc))
  1290. tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
  1291. if (ieee80211_is_data_qos(fc)) {
  1292. u8 *qc = ieee80211_get_qos_ctl(hdr);
  1293. tx_cmd->tid_tspec = qc[0] & 0xf;
  1294. tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
  1295. } else {
  1296. tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
  1297. }
  1298. il_tx_cmd_protection(il, info, fc, &tx_flags);
  1299. tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
  1300. if (ieee80211_is_mgmt(fc)) {
  1301. if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
  1302. tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(3);
  1303. else
  1304. tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(2);
  1305. } else {
  1306. tx_cmd->timeout.pm_frame_timeout = 0;
  1307. }
  1308. tx_cmd->driver_txop = 0;
  1309. tx_cmd->tx_flags = tx_flags;
  1310. tx_cmd->next_frame_len = 0;
  1311. }
  1312. #define RTS_DFAULT_RETRY_LIMIT 60
  1313. static void
  1314. il4965_tx_cmd_build_rate(struct il_priv *il, struct il_tx_cmd *tx_cmd,
  1315. struct ieee80211_tx_info *info, __le16 fc)
  1316. {
  1317. u32 rate_flags;
  1318. int rate_idx;
  1319. u8 rts_retry_limit;
  1320. u8 data_retry_limit;
  1321. u8 rate_plcp;
  1322. /* Set retry limit on DATA packets and Probe Responses */
  1323. if (ieee80211_is_probe_resp(fc))
  1324. data_retry_limit = 3;
  1325. else
  1326. data_retry_limit = IL4965_DEFAULT_TX_RETRY;
  1327. tx_cmd->data_retry_limit = data_retry_limit;
  1328. /* Set retry limit on RTS packets */
  1329. rts_retry_limit = RTS_DFAULT_RETRY_LIMIT;
  1330. if (data_retry_limit < rts_retry_limit)
  1331. rts_retry_limit = data_retry_limit;
  1332. tx_cmd->rts_retry_limit = rts_retry_limit;
  1333. /* DATA packets will use the uCode station table for rate/antenna
  1334. * selection */
  1335. if (ieee80211_is_data(fc)) {
  1336. tx_cmd->initial_rate_idx = 0;
  1337. tx_cmd->tx_flags |= TX_CMD_FLG_STA_RATE_MSK;
  1338. return;
  1339. }
  1340. /**
  1341. * If the current TX rate stored in mac80211 has the MCS bit set, it's
  1342. * not really a TX rate. Thus, we use the lowest supported rate for
  1343. * this band. Also use the lowest supported rate if the stored rate
  1344. * idx is invalid.
  1345. */
  1346. rate_idx = info->control.rates[0].idx;
  1347. if ((info->control.rates[0].flags & IEEE80211_TX_RC_MCS) || rate_idx < 0
  1348. || rate_idx > RATE_COUNT_LEGACY)
  1349. rate_idx =
  1350. rate_lowest_index(&il->bands[info->band],
  1351. info->control.sta);
  1352. /* For 5 GHZ band, remap mac80211 rate indices into driver indices */
  1353. if (info->band == IEEE80211_BAND_5GHZ)
  1354. rate_idx += IL_FIRST_OFDM_RATE;
  1355. /* Get PLCP rate for tx_cmd->rate_n_flags */
  1356. rate_plcp = il_rates[rate_idx].plcp;
  1357. /* Zero out flags for this packet */
  1358. rate_flags = 0;
  1359. /* Set CCK flag as needed */
  1360. if (rate_idx >= IL_FIRST_CCK_RATE && rate_idx <= IL_LAST_CCK_RATE)
  1361. rate_flags |= RATE_MCS_CCK_MSK;
  1362. /* Set up antennas */
  1363. il->mgmt_tx_ant =
  1364. il4965_toggle_tx_ant(il, il->mgmt_tx_ant,
  1365. il->hw_params.valid_tx_ant);
  1366. rate_flags |= il4965_ant_idx_to_flags(il->mgmt_tx_ant);
  1367. /* Set the rate in the TX cmd */
  1368. tx_cmd->rate_n_flags =
  1369. il4965_hw_set_rate_n_flags(rate_plcp, rate_flags);
  1370. }
  1371. static void
  1372. il4965_tx_cmd_build_hwcrypto(struct il_priv *il, struct ieee80211_tx_info *info,
  1373. struct il_tx_cmd *tx_cmd, struct sk_buff *skb_frag,
  1374. int sta_id)
  1375. {
  1376. struct ieee80211_key_conf *keyconf = info->control.hw_key;
  1377. switch (keyconf->cipher) {
  1378. case WLAN_CIPHER_SUITE_CCMP:
  1379. tx_cmd->sec_ctl = TX_CMD_SEC_CCM;
  1380. memcpy(tx_cmd->key, keyconf->key, keyconf->keylen);
  1381. if (info->flags & IEEE80211_TX_CTL_AMPDU)
  1382. tx_cmd->tx_flags |= TX_CMD_FLG_AGG_CCMP_MSK;
  1383. D_TX("tx_cmd with AES hwcrypto\n");
  1384. break;
  1385. case WLAN_CIPHER_SUITE_TKIP:
  1386. tx_cmd->sec_ctl = TX_CMD_SEC_TKIP;
  1387. ieee80211_get_tkip_p2k(keyconf, skb_frag, tx_cmd->key);
  1388. D_TX("tx_cmd with tkip hwcrypto\n");
  1389. break;
  1390. case WLAN_CIPHER_SUITE_WEP104:
  1391. tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128;
  1392. /* fall through */
  1393. case WLAN_CIPHER_SUITE_WEP40:
  1394. tx_cmd->sec_ctl |=
  1395. (TX_CMD_SEC_WEP | (keyconf->keyidx & TX_CMD_SEC_MSK) <<
  1396. TX_CMD_SEC_SHIFT);
  1397. memcpy(&tx_cmd->key[3], keyconf->key, keyconf->keylen);
  1398. D_TX("Configuring packet for WEP encryption " "with key %d\n",
  1399. keyconf->keyidx);
  1400. break;
  1401. default:
  1402. IL_ERR("Unknown encode cipher %x\n", keyconf->cipher);
  1403. break;
  1404. }
  1405. }
  1406. /*
  1407. * start C_TX command process
  1408. */
  1409. int
  1410. il4965_tx_skb(struct il_priv *il, struct sk_buff *skb)
  1411. {
  1412. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1413. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1414. struct ieee80211_sta *sta = info->control.sta;
  1415. struct il_station_priv *sta_priv = NULL;
  1416. struct il_tx_queue *txq;
  1417. struct il_queue *q;
  1418. struct il_device_cmd *out_cmd;
  1419. struct il_cmd_meta *out_meta;
  1420. struct il_tx_cmd *tx_cmd;
  1421. struct il_rxon_context *ctx = &il->ctx;
  1422. int txq_id;
  1423. dma_addr_t phys_addr;
  1424. dma_addr_t txcmd_phys;
  1425. dma_addr_t scratch_phys;
  1426. u16 len, firstlen, secondlen;
  1427. u16 seq_number = 0;
  1428. __le16 fc;
  1429. u8 hdr_len;
  1430. u8 sta_id;
  1431. u8 wait_write_ptr = 0;
  1432. u8 tid = 0;
  1433. u8 *qc = NULL;
  1434. unsigned long flags;
  1435. bool is_agg = false;
  1436. if (info->control.vif)
  1437. ctx = il_rxon_ctx_from_vif(info->control.vif);
  1438. spin_lock_irqsave(&il->lock, flags);
  1439. if (il_is_rfkill(il)) {
  1440. D_DROP("Dropping - RF KILL\n");
  1441. goto drop_unlock;
  1442. }
  1443. fc = hdr->frame_control;
  1444. #ifdef CONFIG_IWLEGACY_DEBUG
  1445. if (ieee80211_is_auth(fc))
  1446. D_TX("Sending AUTH frame\n");
  1447. else if (ieee80211_is_assoc_req(fc))
  1448. D_TX("Sending ASSOC frame\n");
  1449. else if (ieee80211_is_reassoc_req(fc))
  1450. D_TX("Sending REASSOC frame\n");
  1451. #endif
  1452. hdr_len = ieee80211_hdrlen(fc);
  1453. /* For management frames use broadcast id to do not break aggregation */
  1454. if (!ieee80211_is_data(fc))
  1455. sta_id = ctx->bcast_sta_id;
  1456. else {
  1457. /* Find idx into station table for destination station */
  1458. sta_id = il_sta_id_or_broadcast(il, ctx, info->control.sta);
  1459. if (sta_id == IL_INVALID_STATION) {
  1460. D_DROP("Dropping - INVALID STATION: %pM\n", hdr->addr1);
  1461. goto drop_unlock;
  1462. }
  1463. }
  1464. D_TX("station Id %d\n", sta_id);
  1465. if (sta)
  1466. sta_priv = (void *)sta->drv_priv;
  1467. if (sta_priv && sta_priv->asleep &&
  1468. (info->flags & IEEE80211_TX_CTL_POLL_RESPONSE)) {
  1469. /*
  1470. * This sends an asynchronous command to the device,
  1471. * but we can rely on it being processed before the
  1472. * next frame is processed -- and the next frame to
  1473. * this station is the one that will consume this
  1474. * counter.
  1475. * For now set the counter to just 1 since we do not
  1476. * support uAPSD yet.
  1477. */
  1478. il4965_sta_modify_sleep_tx_count(il, sta_id, 1);
  1479. }
  1480. /*
  1481. * Send this frame after DTIM -- there's a special queue
  1482. * reserved for this for contexts that support AP mode.
  1483. */
  1484. if (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) {
  1485. txq_id = ctx->mcast_queue;
  1486. /*
  1487. * The microcode will clear the more data
  1488. * bit in the last frame it transmits.
  1489. */
  1490. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
  1491. } else
  1492. txq_id = ctx->ac_to_queue[skb_get_queue_mapping(skb)];
  1493. /* irqs already disabled/saved above when locking il->lock */
  1494. spin_lock(&il->sta_lock);
  1495. if (ieee80211_is_data_qos(fc)) {
  1496. qc = ieee80211_get_qos_ctl(hdr);
  1497. tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
  1498. if (WARN_ON_ONCE(tid >= MAX_TID_COUNT)) {
  1499. spin_unlock(&il->sta_lock);
  1500. goto drop_unlock;
  1501. }
  1502. seq_number = il->stations[sta_id].tid[tid].seq_number;
  1503. seq_number &= IEEE80211_SCTL_SEQ;
  1504. hdr->seq_ctrl =
  1505. hdr->seq_ctrl & cpu_to_le16(IEEE80211_SCTL_FRAG);
  1506. hdr->seq_ctrl |= cpu_to_le16(seq_number);
  1507. seq_number += 0x10;
  1508. /* aggregation is on for this <sta,tid> */
  1509. if (info->flags & IEEE80211_TX_CTL_AMPDU &&
  1510. il->stations[sta_id].tid[tid].agg.state == IL_AGG_ON) {
  1511. txq_id = il->stations[sta_id].tid[tid].agg.txq_id;
  1512. is_agg = true;
  1513. }
  1514. }
  1515. txq = &il->txq[txq_id];
  1516. q = &txq->q;
  1517. if (unlikely(il_queue_space(q) < q->high_mark)) {
  1518. spin_unlock(&il->sta_lock);
  1519. goto drop_unlock;
  1520. }
  1521. if (ieee80211_is_data_qos(fc)) {
  1522. il->stations[sta_id].tid[tid].tfds_in_queue++;
  1523. if (!ieee80211_has_morefrags(fc))
  1524. il->stations[sta_id].tid[tid].seq_number = seq_number;
  1525. }
  1526. spin_unlock(&il->sta_lock);
  1527. /* Set up driver data for this TFD */
  1528. memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct il_tx_info));
  1529. txq->txb[q->write_ptr].skb = skb;
  1530. txq->txb[q->write_ptr].ctx = ctx;
  1531. /* Set up first empty entry in queue's array of Tx/cmd buffers */
  1532. out_cmd = txq->cmd[q->write_ptr];
  1533. out_meta = &txq->meta[q->write_ptr];
  1534. tx_cmd = &out_cmd->cmd.tx;
  1535. memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
  1536. memset(tx_cmd, 0, sizeof(struct il_tx_cmd));
  1537. /*
  1538. * Set up the Tx-command (not MAC!) header.
  1539. * Store the chosen Tx queue and TFD idx within the sequence field;
  1540. * after Tx, uCode's Tx response will return this value so driver can
  1541. * locate the frame within the tx queue and do post-tx processing.
  1542. */
  1543. out_cmd->hdr.cmd = C_TX;
  1544. out_cmd->hdr.sequence =
  1545. cpu_to_le16((u16)
  1546. (QUEUE_TO_SEQ(txq_id) | IDX_TO_SEQ(q->write_ptr)));
  1547. /* Copy MAC header from skb into command buffer */
  1548. memcpy(tx_cmd->hdr, hdr, hdr_len);
  1549. /* Total # bytes to be transmitted */
  1550. len = (u16) skb->len;
  1551. tx_cmd->len = cpu_to_le16(len);
  1552. if (info->control.hw_key)
  1553. il4965_tx_cmd_build_hwcrypto(il, info, tx_cmd, skb, sta_id);
  1554. /* TODO need this for burst mode later on */
  1555. il4965_tx_cmd_build_basic(il, skb, tx_cmd, info, hdr, sta_id);
  1556. il_dbg_log_tx_data_frame(il, len, hdr);
  1557. il4965_tx_cmd_build_rate(il, tx_cmd, info, fc);
  1558. il_update_stats(il, true, fc, len);
  1559. /*
  1560. * Use the first empty entry in this queue's command buffer array
  1561. * to contain the Tx command and MAC header concatenated together
  1562. * (payload data will be in another buffer).
  1563. * Size of this varies, due to varying MAC header length.
  1564. * If end is not dword aligned, we'll have 2 extra bytes at the end
  1565. * of the MAC header (device reads on dword boundaries).
  1566. * We'll tell device about this padding later.
  1567. */
  1568. len = sizeof(struct il_tx_cmd) + sizeof(struct il_cmd_header) + hdr_len;
  1569. firstlen = (len + 3) & ~3;
  1570. /* Tell NIC about any 2-byte padding after MAC header */
  1571. if (firstlen != len)
  1572. tx_cmd->tx_flags |= TX_CMD_FLG_MH_PAD_MSK;
  1573. /* Physical address of this Tx command's header (not MAC header!),
  1574. * within command buffer array. */
  1575. txcmd_phys =
  1576. pci_map_single(il->pci_dev, &out_cmd->hdr, firstlen,
  1577. PCI_DMA_BIDIRECTIONAL);
  1578. dma_unmap_addr_set(out_meta, mapping, txcmd_phys);
  1579. dma_unmap_len_set(out_meta, len, firstlen);
  1580. /* Add buffer containing Tx command and MAC(!) header to TFD's
  1581. * first entry */
  1582. il->cfg->ops->lib->txq_attach_buf_to_tfd(il, txq, txcmd_phys, firstlen,
  1583. 1, 0);
  1584. if (!ieee80211_has_morefrags(hdr->frame_control)) {
  1585. txq->need_update = 1;
  1586. } else {
  1587. wait_write_ptr = 1;
  1588. txq->need_update = 0;
  1589. }
  1590. /* Set up TFD's 2nd entry to point directly to remainder of skb,
  1591. * if any (802.11 null frames have no payload). */
  1592. secondlen = skb->len - hdr_len;
  1593. if (secondlen > 0) {
  1594. phys_addr =
  1595. pci_map_single(il->pci_dev, skb->data + hdr_len, secondlen,
  1596. PCI_DMA_TODEVICE);
  1597. il->cfg->ops->lib->txq_attach_buf_to_tfd(il, txq, phys_addr,
  1598. secondlen, 0, 0);
  1599. }
  1600. scratch_phys =
  1601. txcmd_phys + sizeof(struct il_cmd_header) +
  1602. offsetof(struct il_tx_cmd, scratch);
  1603. /* take back ownership of DMA buffer to enable update */
  1604. pci_dma_sync_single_for_cpu(il->pci_dev, txcmd_phys, firstlen,
  1605. PCI_DMA_BIDIRECTIONAL);
  1606. tx_cmd->dram_lsb_ptr = cpu_to_le32(scratch_phys);
  1607. tx_cmd->dram_msb_ptr = il_get_dma_hi_addr(scratch_phys);
  1608. D_TX("sequence nr = 0X%x\n", le16_to_cpu(out_cmd->hdr.sequence));
  1609. D_TX("tx_flags = 0X%x\n", le32_to_cpu(tx_cmd->tx_flags));
  1610. il_print_hex_dump(il, IL_DL_TX, (u8 *) tx_cmd, sizeof(*tx_cmd));
  1611. il_print_hex_dump(il, IL_DL_TX, (u8 *) tx_cmd->hdr, hdr_len);
  1612. /* Set up entry for this TFD in Tx byte-count array */
  1613. if (info->flags & IEEE80211_TX_CTL_AMPDU)
  1614. il->cfg->ops->lib->txq_update_byte_cnt_tbl(il, txq,
  1615. le16_to_cpu(tx_cmd->
  1616. len));
  1617. pci_dma_sync_single_for_device(il->pci_dev, txcmd_phys, firstlen,
  1618. PCI_DMA_BIDIRECTIONAL);
  1619. /* Tell device the write idx *just past* this latest filled TFD */
  1620. q->write_ptr = il_queue_inc_wrap(q->write_ptr, q->n_bd);
  1621. il_txq_update_write_ptr(il, txq);
  1622. spin_unlock_irqrestore(&il->lock, flags);
  1623. /*
  1624. * At this point the frame is "transmitted" successfully
  1625. * and we will get a TX status notification eventually,
  1626. * regardless of the value of ret. "ret" only indicates
  1627. * whether or not we should update the write pointer.
  1628. */
  1629. /*
  1630. * Avoid atomic ops if it isn't an associated client.
  1631. * Also, if this is a packet for aggregation, don't
  1632. * increase the counter because the ucode will stop
  1633. * aggregation queues when their respective station
  1634. * goes to sleep.
  1635. */
  1636. if (sta_priv && sta_priv->client && !is_agg)
  1637. atomic_inc(&sta_priv->pending_frames);
  1638. if (il_queue_space(q) < q->high_mark && il->mac80211_registered) {
  1639. if (wait_write_ptr) {
  1640. spin_lock_irqsave(&il->lock, flags);
  1641. txq->need_update = 1;
  1642. il_txq_update_write_ptr(il, txq);
  1643. spin_unlock_irqrestore(&il->lock, flags);
  1644. } else {
  1645. il_stop_queue(il, txq);
  1646. }
  1647. }
  1648. return 0;
  1649. drop_unlock:
  1650. spin_unlock_irqrestore(&il->lock, flags);
  1651. return -1;
  1652. }
  1653. static inline int
  1654. il4965_alloc_dma_ptr(struct il_priv *il, struct il_dma_ptr *ptr, size_t size)
  1655. {
  1656. ptr->addr =
  1657. dma_alloc_coherent(&il->pci_dev->dev, size, &ptr->dma, GFP_KERNEL);
  1658. if (!ptr->addr)
  1659. return -ENOMEM;
  1660. ptr->size = size;
  1661. return 0;
  1662. }
  1663. static inline void
  1664. il4965_free_dma_ptr(struct il_priv *il, struct il_dma_ptr *ptr)
  1665. {
  1666. if (unlikely(!ptr->addr))
  1667. return;
  1668. dma_free_coherent(&il->pci_dev->dev, ptr->size, ptr->addr, ptr->dma);
  1669. memset(ptr, 0, sizeof(*ptr));
  1670. }
  1671. /**
  1672. * il4965_hw_txq_ctx_free - Free TXQ Context
  1673. *
  1674. * Destroy all TX DMA queues and structures
  1675. */
  1676. void
  1677. il4965_hw_txq_ctx_free(struct il_priv *il)
  1678. {
  1679. int txq_id;
  1680. /* Tx queues */
  1681. if (il->txq) {
  1682. for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++)
  1683. if (txq_id == il->cmd_queue)
  1684. il_cmd_queue_free(il);
  1685. else
  1686. il_tx_queue_free(il, txq_id);
  1687. }
  1688. il4965_free_dma_ptr(il, &il->kw);
  1689. il4965_free_dma_ptr(il, &il->scd_bc_tbls);
  1690. /* free tx queue structure */
  1691. il_txq_mem(il);
  1692. }
  1693. /**
  1694. * il4965_txq_ctx_alloc - allocate TX queue context
  1695. * Allocate all Tx DMA structures and initialize them
  1696. *
  1697. * @param il
  1698. * @return error code
  1699. */
  1700. int
  1701. il4965_txq_ctx_alloc(struct il_priv *il)
  1702. {
  1703. int ret;
  1704. int txq_id, slots_num;
  1705. unsigned long flags;
  1706. /* Free all tx/cmd queues and keep-warm buffer */
  1707. il4965_hw_txq_ctx_free(il);
  1708. ret =
  1709. il4965_alloc_dma_ptr(il, &il->scd_bc_tbls,
  1710. il->hw_params.scd_bc_tbls_size);
  1711. if (ret) {
  1712. IL_ERR("Scheduler BC Table allocation failed\n");
  1713. goto error_bc_tbls;
  1714. }
  1715. /* Alloc keep-warm buffer */
  1716. ret = il4965_alloc_dma_ptr(il, &il->kw, IL_KW_SIZE);
  1717. if (ret) {
  1718. IL_ERR("Keep Warm allocation failed\n");
  1719. goto error_kw;
  1720. }
  1721. /* allocate tx queue structure */
  1722. ret = il_alloc_txq_mem(il);
  1723. if (ret)
  1724. goto error;
  1725. spin_lock_irqsave(&il->lock, flags);
  1726. /* Turn off all Tx DMA fifos */
  1727. il4965_txq_set_sched(il, 0);
  1728. /* Tell NIC where to find the "keep warm" buffer */
  1729. il_wr(il, FH49_KW_MEM_ADDR_REG, il->kw.dma >> 4);
  1730. spin_unlock_irqrestore(&il->lock, flags);
  1731. /* Alloc and init all Tx queues, including the command queue (#4/#9) */
  1732. for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++) {
  1733. slots_num =
  1734. (txq_id ==
  1735. il->cmd_queue) ? TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS;
  1736. ret = il_tx_queue_init(il, &il->txq[txq_id], slots_num, txq_id);
  1737. if (ret) {
  1738. IL_ERR("Tx %d queue init failed\n", txq_id);
  1739. goto error;
  1740. }
  1741. }
  1742. return ret;
  1743. error:
  1744. il4965_hw_txq_ctx_free(il);
  1745. il4965_free_dma_ptr(il, &il->kw);
  1746. error_kw:
  1747. il4965_free_dma_ptr(il, &il->scd_bc_tbls);
  1748. error_bc_tbls:
  1749. return ret;
  1750. }
  1751. void
  1752. il4965_txq_ctx_reset(struct il_priv *il)
  1753. {
  1754. int txq_id, slots_num;
  1755. unsigned long flags;
  1756. spin_lock_irqsave(&il->lock, flags);
  1757. /* Turn off all Tx DMA fifos */
  1758. il4965_txq_set_sched(il, 0);
  1759. /* Tell NIC where to find the "keep warm" buffer */
  1760. il_wr(il, FH49_KW_MEM_ADDR_REG, il->kw.dma >> 4);
  1761. spin_unlock_irqrestore(&il->lock, flags);
  1762. /* Alloc and init all Tx queues, including the command queue (#4) */
  1763. for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++) {
  1764. slots_num =
  1765. txq_id == il->cmd_queue ? TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS;
  1766. il_tx_queue_reset(il, &il->txq[txq_id], slots_num, txq_id);
  1767. }
  1768. }
  1769. /**
  1770. * il4965_txq_ctx_stop - Stop all Tx DMA channels
  1771. */
  1772. void
  1773. il4965_txq_ctx_stop(struct il_priv *il)
  1774. {
  1775. int ch, txq_id;
  1776. unsigned long flags;
  1777. /* Turn off all Tx DMA fifos */
  1778. spin_lock_irqsave(&il->lock, flags);
  1779. il4965_txq_set_sched(il, 0);
  1780. /* Stop each Tx DMA channel, and wait for it to be idle */
  1781. for (ch = 0; ch < il->hw_params.dma_chnl_num; ch++) {
  1782. il_wr(il, FH49_TCSR_CHNL_TX_CONFIG_REG(ch), 0x0);
  1783. if (il_poll_bit
  1784. (il, FH49_TSSR_TX_STATUS_REG,
  1785. FH49_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(ch), 1000))
  1786. IL_ERR("Failing on timeout while stopping"
  1787. " DMA channel %d [0x%08x]", ch,
  1788. il_rd(il, FH49_TSSR_TX_STATUS_REG));
  1789. }
  1790. spin_unlock_irqrestore(&il->lock, flags);
  1791. if (!il->txq)
  1792. return;
  1793. /* Unmap DMA from host system and free skb's */
  1794. for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++)
  1795. if (txq_id == il->cmd_queue)
  1796. il_cmd_queue_unmap(il);
  1797. else
  1798. il_tx_queue_unmap(il, txq_id);
  1799. }
  1800. /*
  1801. * Find first available (lowest unused) Tx Queue, mark it "active".
  1802. * Called only when finding queue for aggregation.
  1803. * Should never return anything < 7, because they should already
  1804. * be in use as EDCA AC (0-3), Command (4), reserved (5, 6)
  1805. */
  1806. static int
  1807. il4965_txq_ctx_activate_free(struct il_priv *il)
  1808. {
  1809. int txq_id;
  1810. for (txq_id = 0; txq_id < il->hw_params.max_txq_num; txq_id++)
  1811. if (!test_and_set_bit(txq_id, &il->txq_ctx_active_msk))
  1812. return txq_id;
  1813. return -1;
  1814. }
  1815. /**
  1816. * il4965_tx_queue_stop_scheduler - Stop queue, but keep configuration
  1817. */
  1818. static void
  1819. il4965_tx_queue_stop_scheduler(struct il_priv *il, u16 txq_id)
  1820. {
  1821. /* Simply stop the queue, but don't change any configuration;
  1822. * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
  1823. il_wr_prph(il, IL49_SCD_QUEUE_STATUS_BITS(txq_id),
  1824. (0 << IL49_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
  1825. (1 << IL49_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
  1826. }
  1827. /**
  1828. * il4965_tx_queue_set_q2ratid - Map unique receiver/tid combination to a queue
  1829. */
  1830. static int
  1831. il4965_tx_queue_set_q2ratid(struct il_priv *il, u16 ra_tid, u16 txq_id)
  1832. {
  1833. u32 tbl_dw_addr;
  1834. u32 tbl_dw;
  1835. u16 scd_q2ratid;
  1836. scd_q2ratid = ra_tid & IL_SCD_QUEUE_RA_TID_MAP_RATID_MSK;
  1837. tbl_dw_addr =
  1838. il->scd_base_addr + IL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id);
  1839. tbl_dw = il_read_targ_mem(il, tbl_dw_addr);
  1840. if (txq_id & 0x1)
  1841. tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF);
  1842. else
  1843. tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000);
  1844. il_write_targ_mem(il, tbl_dw_addr, tbl_dw);
  1845. return 0;
  1846. }
  1847. /**
  1848. * il4965_tx_queue_agg_enable - Set up & enable aggregation for selected queue
  1849. *
  1850. * NOTE: txq_id must be greater than IL49_FIRST_AMPDU_QUEUE,
  1851. * i.e. it must be one of the higher queues used for aggregation
  1852. */
  1853. static int
  1854. il4965_txq_agg_enable(struct il_priv *il, int txq_id, int tx_fifo, int sta_id,
  1855. int tid, u16 ssn_idx)
  1856. {
  1857. unsigned long flags;
  1858. u16 ra_tid;
  1859. int ret;
  1860. if ((IL49_FIRST_AMPDU_QUEUE > txq_id) ||
  1861. (IL49_FIRST_AMPDU_QUEUE +
  1862. il->cfg->base_params->num_of_ampdu_queues <= txq_id)) {
  1863. IL_WARN("queue number out of range: %d, must be %d to %d\n",
  1864. txq_id, IL49_FIRST_AMPDU_QUEUE,
  1865. IL49_FIRST_AMPDU_QUEUE +
  1866. il->cfg->base_params->num_of_ampdu_queues - 1);
  1867. return -EINVAL;
  1868. }
  1869. ra_tid = BUILD_RAxTID(sta_id, tid);
  1870. /* Modify device's station table to Tx this TID */
  1871. ret = il4965_sta_tx_modify_enable_tid(il, sta_id, tid);
  1872. if (ret)
  1873. return ret;
  1874. spin_lock_irqsave(&il->lock, flags);
  1875. /* Stop this Tx queue before configuring it */
  1876. il4965_tx_queue_stop_scheduler(il, txq_id);
  1877. /* Map receiver-address / traffic-ID to this queue */
  1878. il4965_tx_queue_set_q2ratid(il, ra_tid, txq_id);
  1879. /* Set this queue as a chain-building queue */
  1880. il_set_bits_prph(il, IL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
  1881. /* Place first TFD at idx corresponding to start sequence number.
  1882. * Assumes that ssn_idx is valid (!= 0xFFF) */
  1883. il->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
  1884. il->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
  1885. il4965_set_wr_ptrs(il, txq_id, ssn_idx);
  1886. /* Set up Tx win size and frame limit for this queue */
  1887. il_write_targ_mem(il,
  1888. il->scd_base_addr +
  1889. IL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id),
  1890. (SCD_WIN_SIZE << IL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS)
  1891. & IL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
  1892. il_write_targ_mem(il,
  1893. il->scd_base_addr +
  1894. IL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32),
  1895. (SCD_FRAME_LIMIT <<
  1896. IL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
  1897. IL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
  1898. il_set_bits_prph(il, IL49_SCD_INTERRUPT_MASK, (1 << txq_id));
  1899. /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */
  1900. il4965_tx_queue_set_status(il, &il->txq[txq_id], tx_fifo, 1);
  1901. spin_unlock_irqrestore(&il->lock, flags);
  1902. return 0;
  1903. }
  1904. int
  1905. il4965_tx_agg_start(struct il_priv *il, struct ieee80211_vif *vif,
  1906. struct ieee80211_sta *sta, u16 tid, u16 * ssn)
  1907. {
  1908. int sta_id;
  1909. int tx_fifo;
  1910. int txq_id;
  1911. int ret;
  1912. unsigned long flags;
  1913. struct il_tid_data *tid_data;
  1914. tx_fifo = il4965_get_fifo_from_tid(il_rxon_ctx_from_vif(vif), tid);
  1915. if (unlikely(tx_fifo < 0))
  1916. return tx_fifo;
  1917. D_HT("%s on ra = %pM tid = %d\n", __func__, sta->addr, tid);
  1918. sta_id = il_sta_id(sta);
  1919. if (sta_id == IL_INVALID_STATION) {
  1920. IL_ERR("Start AGG on invalid station\n");
  1921. return -ENXIO;
  1922. }
  1923. if (unlikely(tid >= MAX_TID_COUNT))
  1924. return -EINVAL;
  1925. if (il->stations[sta_id].tid[tid].agg.state != IL_AGG_OFF) {
  1926. IL_ERR("Start AGG when state is not IL_AGG_OFF !\n");
  1927. return -ENXIO;
  1928. }
  1929. txq_id = il4965_txq_ctx_activate_free(il);
  1930. if (txq_id == -1) {
  1931. IL_ERR("No free aggregation queue available\n");
  1932. return -ENXIO;
  1933. }
  1934. spin_lock_irqsave(&il->sta_lock, flags);
  1935. tid_data = &il->stations[sta_id].tid[tid];
  1936. *ssn = SEQ_TO_SN(tid_data->seq_number);
  1937. tid_data->agg.txq_id = txq_id;
  1938. il_set_swq_id(&il->txq[txq_id], il4965_get_ac_from_tid(tid), txq_id);
  1939. spin_unlock_irqrestore(&il->sta_lock, flags);
  1940. ret = il4965_txq_agg_enable(il, txq_id, tx_fifo, sta_id, tid, *ssn);
  1941. if (ret)
  1942. return ret;
  1943. spin_lock_irqsave(&il->sta_lock, flags);
  1944. tid_data = &il->stations[sta_id].tid[tid];
  1945. if (tid_data->tfds_in_queue == 0) {
  1946. D_HT("HW queue is empty\n");
  1947. tid_data->agg.state = IL_AGG_ON;
  1948. ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  1949. } else {
  1950. D_HT("HW queue is NOT empty: %d packets in HW queue\n",
  1951. tid_data->tfds_in_queue);
  1952. tid_data->agg.state = IL_EMPTYING_HW_QUEUE_ADDBA;
  1953. }
  1954. spin_unlock_irqrestore(&il->sta_lock, flags);
  1955. return ret;
  1956. }
  1957. /**
  1958. * txq_id must be greater than IL49_FIRST_AMPDU_QUEUE
  1959. * il->lock must be held by the caller
  1960. */
  1961. static int
  1962. il4965_txq_agg_disable(struct il_priv *il, u16 txq_id, u16 ssn_idx, u8 tx_fifo)
  1963. {
  1964. if ((IL49_FIRST_AMPDU_QUEUE > txq_id) ||
  1965. (IL49_FIRST_AMPDU_QUEUE +
  1966. il->cfg->base_params->num_of_ampdu_queues <= txq_id)) {
  1967. IL_WARN("queue number out of range: %d, must be %d to %d\n",
  1968. txq_id, IL49_FIRST_AMPDU_QUEUE,
  1969. IL49_FIRST_AMPDU_QUEUE +
  1970. il->cfg->base_params->num_of_ampdu_queues - 1);
  1971. return -EINVAL;
  1972. }
  1973. il4965_tx_queue_stop_scheduler(il, txq_id);
  1974. il_clear_bits_prph(il, IL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
  1975. il->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
  1976. il->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
  1977. /* supposes that ssn_idx is valid (!= 0xFFF) */
  1978. il4965_set_wr_ptrs(il, txq_id, ssn_idx);
  1979. il_clear_bits_prph(il, IL49_SCD_INTERRUPT_MASK, (1 << txq_id));
  1980. il_txq_ctx_deactivate(il, txq_id);
  1981. il4965_tx_queue_set_status(il, &il->txq[txq_id], tx_fifo, 0);
  1982. return 0;
  1983. }
  1984. int
  1985. il4965_tx_agg_stop(struct il_priv *il, struct ieee80211_vif *vif,
  1986. struct ieee80211_sta *sta, u16 tid)
  1987. {
  1988. int tx_fifo_id, txq_id, sta_id, ssn;
  1989. struct il_tid_data *tid_data;
  1990. int write_ptr, read_ptr;
  1991. unsigned long flags;
  1992. tx_fifo_id = il4965_get_fifo_from_tid(il_rxon_ctx_from_vif(vif), tid);
  1993. if (unlikely(tx_fifo_id < 0))
  1994. return tx_fifo_id;
  1995. sta_id = il_sta_id(sta);
  1996. if (sta_id == IL_INVALID_STATION) {
  1997. IL_ERR("Invalid station for AGG tid %d\n", tid);
  1998. return -ENXIO;
  1999. }
  2000. spin_lock_irqsave(&il->sta_lock, flags);
  2001. tid_data = &il->stations[sta_id].tid[tid];
  2002. ssn = (tid_data->seq_number & IEEE80211_SCTL_SEQ) >> 4;
  2003. txq_id = tid_data->agg.txq_id;
  2004. switch (il->stations[sta_id].tid[tid].agg.state) {
  2005. case IL_EMPTYING_HW_QUEUE_ADDBA:
  2006. /*
  2007. * This can happen if the peer stops aggregation
  2008. * again before we've had a chance to drain the
  2009. * queue we selected previously, i.e. before the
  2010. * session was really started completely.
  2011. */
  2012. D_HT("AGG stop before setup done\n");
  2013. goto turn_off;
  2014. case IL_AGG_ON:
  2015. break;
  2016. default:
  2017. IL_WARN("Stopping AGG while state not ON or starting\n");
  2018. }
  2019. write_ptr = il->txq[txq_id].q.write_ptr;
  2020. read_ptr = il->txq[txq_id].q.read_ptr;
  2021. /* The queue is not empty */
  2022. if (write_ptr != read_ptr) {
  2023. D_HT("Stopping a non empty AGG HW QUEUE\n");
  2024. il->stations[sta_id].tid[tid].agg.state =
  2025. IL_EMPTYING_HW_QUEUE_DELBA;
  2026. spin_unlock_irqrestore(&il->sta_lock, flags);
  2027. return 0;
  2028. }
  2029. D_HT("HW queue is empty\n");
  2030. turn_off:
  2031. il->stations[sta_id].tid[tid].agg.state = IL_AGG_OFF;
  2032. /* do not restore/save irqs */
  2033. spin_unlock(&il->sta_lock);
  2034. spin_lock(&il->lock);
  2035. /*
  2036. * the only reason this call can fail is queue number out of range,
  2037. * which can happen if uCode is reloaded and all the station
  2038. * information are lost. if it is outside the range, there is no need
  2039. * to deactivate the uCode queue, just return "success" to allow
  2040. * mac80211 to clean up it own data.
  2041. */
  2042. il4965_txq_agg_disable(il, txq_id, ssn, tx_fifo_id);
  2043. spin_unlock_irqrestore(&il->lock, flags);
  2044. ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
  2045. return 0;
  2046. }
  2047. int
  2048. il4965_txq_check_empty(struct il_priv *il, int sta_id, u8 tid, int txq_id)
  2049. {
  2050. struct il_queue *q = &il->txq[txq_id].q;
  2051. u8 *addr = il->stations[sta_id].sta.sta.addr;
  2052. struct il_tid_data *tid_data = &il->stations[sta_id].tid[tid];
  2053. struct il_rxon_context *ctx;
  2054. ctx = &il->ctx;
  2055. lockdep_assert_held(&il->sta_lock);
  2056. switch (il->stations[sta_id].tid[tid].agg.state) {
  2057. case IL_EMPTYING_HW_QUEUE_DELBA:
  2058. /* We are reclaiming the last packet of the */
  2059. /* aggregated HW queue */
  2060. if (txq_id == tid_data->agg.txq_id &&
  2061. q->read_ptr == q->write_ptr) {
  2062. u16 ssn = SEQ_TO_SN(tid_data->seq_number);
  2063. int tx_fifo = il4965_get_fifo_from_tid(ctx, tid);
  2064. D_HT("HW queue empty: continue DELBA flow\n");
  2065. il4965_txq_agg_disable(il, txq_id, ssn, tx_fifo);
  2066. tid_data->agg.state = IL_AGG_OFF;
  2067. ieee80211_stop_tx_ba_cb_irqsafe(ctx->vif, addr, tid);
  2068. }
  2069. break;
  2070. case IL_EMPTYING_HW_QUEUE_ADDBA:
  2071. /* We are reclaiming the last packet of the queue */
  2072. if (tid_data->tfds_in_queue == 0) {
  2073. D_HT("HW queue empty: continue ADDBA flow\n");
  2074. tid_data->agg.state = IL_AGG_ON;
  2075. ieee80211_start_tx_ba_cb_irqsafe(ctx->vif, addr, tid);
  2076. }
  2077. break;
  2078. }
  2079. return 0;
  2080. }
  2081. static void
  2082. il4965_non_agg_tx_status(struct il_priv *il, struct il_rxon_context *ctx,
  2083. const u8 *addr1)
  2084. {
  2085. struct ieee80211_sta *sta;
  2086. struct il_station_priv *sta_priv;
  2087. rcu_read_lock();
  2088. sta = ieee80211_find_sta(ctx->vif, addr1);
  2089. if (sta) {
  2090. sta_priv = (void *)sta->drv_priv;
  2091. /* avoid atomic ops if this isn't a client */
  2092. if (sta_priv->client &&
  2093. atomic_dec_return(&sta_priv->pending_frames) == 0)
  2094. ieee80211_sta_block_awake(il->hw, sta, false);
  2095. }
  2096. rcu_read_unlock();
  2097. }
  2098. static void
  2099. il4965_tx_status(struct il_priv *il, struct il_tx_info *tx_info, bool is_agg)
  2100. {
  2101. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx_info->skb->data;
  2102. if (!is_agg)
  2103. il4965_non_agg_tx_status(il, tx_info->ctx, hdr->addr1);
  2104. ieee80211_tx_status_irqsafe(il->hw, tx_info->skb);
  2105. }
  2106. int
  2107. il4965_tx_queue_reclaim(struct il_priv *il, int txq_id, int idx)
  2108. {
  2109. struct il_tx_queue *txq = &il->txq[txq_id];
  2110. struct il_queue *q = &txq->q;
  2111. struct il_tx_info *tx_info;
  2112. int nfreed = 0;
  2113. struct ieee80211_hdr *hdr;
  2114. if (idx >= q->n_bd || il_queue_used(q, idx) == 0) {
  2115. IL_ERR("Read idx for DMA queue txq id (%d), idx %d, "
  2116. "is out of range [0-%d] %d %d.\n", txq_id, idx, q->n_bd,
  2117. q->write_ptr, q->read_ptr);
  2118. return 0;
  2119. }
  2120. for (idx = il_queue_inc_wrap(idx, q->n_bd); q->read_ptr != idx;
  2121. q->read_ptr = il_queue_inc_wrap(q->read_ptr, q->n_bd)) {
  2122. tx_info = &txq->txb[txq->q.read_ptr];
  2123. if (WARN_ON_ONCE(tx_info->skb == NULL))
  2124. continue;
  2125. hdr = (struct ieee80211_hdr *)tx_info->skb->data;
  2126. if (ieee80211_is_data_qos(hdr->frame_control))
  2127. nfreed++;
  2128. il4965_tx_status(il, tx_info,
  2129. txq_id >= IL4965_FIRST_AMPDU_QUEUE);
  2130. tx_info->skb = NULL;
  2131. il->cfg->ops->lib->txq_free_tfd(il, txq);
  2132. }
  2133. return nfreed;
  2134. }
  2135. /**
  2136. * il4965_tx_status_reply_compressed_ba - Update tx status from block-ack
  2137. *
  2138. * Go through block-ack's bitmap of ACK'd frames, update driver's record of
  2139. * ACK vs. not. This gets sent to mac80211, then to rate scaling algo.
  2140. */
  2141. static int
  2142. il4965_tx_status_reply_compressed_ba(struct il_priv *il, struct il_ht_agg *agg,
  2143. struct il_compressed_ba_resp *ba_resp)
  2144. {
  2145. int i, sh, ack;
  2146. u16 seq_ctl = le16_to_cpu(ba_resp->seq_ctl);
  2147. u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
  2148. int successes = 0;
  2149. struct ieee80211_tx_info *info;
  2150. u64 bitmap, sent_bitmap;
  2151. if (unlikely(!agg->wait_for_ba)) {
  2152. if (unlikely(ba_resp->bitmap))
  2153. IL_ERR("Received BA when not expected\n");
  2154. return -EINVAL;
  2155. }
  2156. /* Mark that the expected block-ack response arrived */
  2157. agg->wait_for_ba = 0;
  2158. D_TX_REPLY("BA %d %d\n", agg->start_idx, ba_resp->seq_ctl);
  2159. /* Calculate shift to align block-ack bits with our Tx win bits */
  2160. sh = agg->start_idx - SEQ_TO_IDX(seq_ctl >> 4);
  2161. if (sh < 0) /* tbw something is wrong with indices */
  2162. sh += 0x100;
  2163. if (agg->frame_count > (64 - sh)) {
  2164. D_TX_REPLY("more frames than bitmap size");
  2165. return -1;
  2166. }
  2167. /* don't use 64-bit values for now */
  2168. bitmap = le64_to_cpu(ba_resp->bitmap) >> sh;
  2169. /* check for success or failure according to the
  2170. * transmitted bitmap and block-ack bitmap */
  2171. sent_bitmap = bitmap & agg->bitmap;
  2172. /* For each frame attempted in aggregation,
  2173. * update driver's record of tx frame's status. */
  2174. i = 0;
  2175. while (sent_bitmap) {
  2176. ack = sent_bitmap & 1ULL;
  2177. successes += ack;
  2178. D_TX_REPLY("%s ON i=%d idx=%d raw=%d\n", ack ? "ACK" : "NACK",
  2179. i, (agg->start_idx + i) & 0xff, agg->start_idx + i);
  2180. sent_bitmap >>= 1;
  2181. ++i;
  2182. }
  2183. D_TX_REPLY("Bitmap %llx\n", (unsigned long long)bitmap);
  2184. info = IEEE80211_SKB_CB(il->txq[scd_flow].txb[agg->start_idx].skb);
  2185. memset(&info->status, 0, sizeof(info->status));
  2186. info->flags |= IEEE80211_TX_STAT_ACK;
  2187. info->flags |= IEEE80211_TX_STAT_AMPDU;
  2188. info->status.ampdu_ack_len = successes;
  2189. info->status.ampdu_len = agg->frame_count;
  2190. il4965_hwrate_to_tx_control(il, agg->rate_n_flags, info);
  2191. return 0;
  2192. }
  2193. /**
  2194. * translate ucode response to mac80211 tx status control values
  2195. */
  2196. void
  2197. il4965_hwrate_to_tx_control(struct il_priv *il, u32 rate_n_flags,
  2198. struct ieee80211_tx_info *info)
  2199. {
  2200. struct ieee80211_tx_rate *r = &info->control.rates[0];
  2201. info->antenna_sel_tx =
  2202. ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS);
  2203. if (rate_n_flags & RATE_MCS_HT_MSK)
  2204. r->flags |= IEEE80211_TX_RC_MCS;
  2205. if (rate_n_flags & RATE_MCS_GF_MSK)
  2206. r->flags |= IEEE80211_TX_RC_GREEN_FIELD;
  2207. if (rate_n_flags & RATE_MCS_HT40_MSK)
  2208. r->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
  2209. if (rate_n_flags & RATE_MCS_DUP_MSK)
  2210. r->flags |= IEEE80211_TX_RC_DUP_DATA;
  2211. if (rate_n_flags & RATE_MCS_SGI_MSK)
  2212. r->flags |= IEEE80211_TX_RC_SHORT_GI;
  2213. r->idx = il4965_hwrate_to_mac80211_idx(rate_n_flags, info->band);
  2214. }
  2215. /**
  2216. * il4965_hdl_compressed_ba - Handler for N_COMPRESSED_BA
  2217. *
  2218. * Handles block-acknowledge notification from device, which reports success
  2219. * of frames sent via aggregation.
  2220. */
  2221. void
  2222. il4965_hdl_compressed_ba(struct il_priv *il, struct il_rx_buf *rxb)
  2223. {
  2224. struct il_rx_pkt *pkt = rxb_addr(rxb);
  2225. struct il_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba;
  2226. struct il_tx_queue *txq = NULL;
  2227. struct il_ht_agg *agg;
  2228. int idx;
  2229. int sta_id;
  2230. int tid;
  2231. unsigned long flags;
  2232. /* "flow" corresponds to Tx queue */
  2233. u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
  2234. /* "ssn" is start of block-ack Tx win, corresponds to idx
  2235. * (in Tx queue's circular buffer) of first TFD/frame in win */
  2236. u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn);
  2237. if (scd_flow >= il->hw_params.max_txq_num) {
  2238. IL_ERR("BUG_ON scd_flow is bigger than number of queues\n");
  2239. return;
  2240. }
  2241. txq = &il->txq[scd_flow];
  2242. sta_id = ba_resp->sta_id;
  2243. tid = ba_resp->tid;
  2244. agg = &il->stations[sta_id].tid[tid].agg;
  2245. if (unlikely(agg->txq_id != scd_flow)) {
  2246. /*
  2247. * FIXME: this is a uCode bug which need to be addressed,
  2248. * log the information and return for now!
  2249. * since it is possible happen very often and in order
  2250. * not to fill the syslog, don't enable the logging by default
  2251. */
  2252. D_TX_REPLY("BA scd_flow %d does not match txq_id %d\n",
  2253. scd_flow, agg->txq_id);
  2254. return;
  2255. }
  2256. /* Find idx just before block-ack win */
  2257. idx = il_queue_dec_wrap(ba_resp_scd_ssn & 0xff, txq->q.n_bd);
  2258. spin_lock_irqsave(&il->sta_lock, flags);
  2259. D_TX_REPLY("N_COMPRESSED_BA [%d] Received from %pM, " "sta_id = %d\n",
  2260. agg->wait_for_ba, (u8 *) &ba_resp->sta_addr_lo32,
  2261. ba_resp->sta_id);
  2262. D_TX_REPLY("TID = %d, SeqCtl = %d, bitmap = 0x%llx," "scd_flow = "
  2263. "%d, scd_ssn = %d\n", ba_resp->tid, ba_resp->seq_ctl,
  2264. (unsigned long long)le64_to_cpu(ba_resp->bitmap),
  2265. ba_resp->scd_flow, ba_resp->scd_ssn);
  2266. D_TX_REPLY("DAT start_idx = %d, bitmap = 0x%llx\n", agg->start_idx,
  2267. (unsigned long long)agg->bitmap);
  2268. /* Update driver's record of ACK vs. not for each frame in win */
  2269. il4965_tx_status_reply_compressed_ba(il, agg, ba_resp);
  2270. /* Release all TFDs before the SSN, i.e. all TFDs in front of
  2271. * block-ack win (we assume that they've been successfully
  2272. * transmitted ... if not, it's too late anyway). */
  2273. if (txq->q.read_ptr != (ba_resp_scd_ssn & 0xff)) {
  2274. /* calculate mac80211 ampdu sw queue to wake */
  2275. int freed = il4965_tx_queue_reclaim(il, scd_flow, idx);
  2276. il4965_free_tfds_in_queue(il, sta_id, tid, freed);
  2277. if (il_queue_space(&txq->q) > txq->q.low_mark &&
  2278. il->mac80211_registered &&
  2279. agg->state != IL_EMPTYING_HW_QUEUE_DELBA)
  2280. il_wake_queue(il, txq);
  2281. il4965_txq_check_empty(il, sta_id, tid, scd_flow);
  2282. }
  2283. spin_unlock_irqrestore(&il->sta_lock, flags);
  2284. }
  2285. #ifdef CONFIG_IWLEGACY_DEBUG
  2286. const char *
  2287. il4965_get_tx_fail_reason(u32 status)
  2288. {
  2289. #define TX_STATUS_FAIL(x) case TX_STATUS_FAIL_ ## x: return #x
  2290. #define TX_STATUS_POSTPONE(x) case TX_STATUS_POSTPONE_ ## x: return #x
  2291. switch (status & TX_STATUS_MSK) {
  2292. case TX_STATUS_SUCCESS:
  2293. return "SUCCESS";
  2294. TX_STATUS_POSTPONE(DELAY);
  2295. TX_STATUS_POSTPONE(FEW_BYTES);
  2296. TX_STATUS_POSTPONE(QUIET_PERIOD);
  2297. TX_STATUS_POSTPONE(CALC_TTAK);
  2298. TX_STATUS_FAIL(INTERNAL_CROSSED_RETRY);
  2299. TX_STATUS_FAIL(SHORT_LIMIT);
  2300. TX_STATUS_FAIL(LONG_LIMIT);
  2301. TX_STATUS_FAIL(FIFO_UNDERRUN);
  2302. TX_STATUS_FAIL(DRAIN_FLOW);
  2303. TX_STATUS_FAIL(RFKILL_FLUSH);
  2304. TX_STATUS_FAIL(LIFE_EXPIRE);
  2305. TX_STATUS_FAIL(DEST_PS);
  2306. TX_STATUS_FAIL(HOST_ABORTED);
  2307. TX_STATUS_FAIL(BT_RETRY);
  2308. TX_STATUS_FAIL(STA_INVALID);
  2309. TX_STATUS_FAIL(FRAG_DROPPED);
  2310. TX_STATUS_FAIL(TID_DISABLE);
  2311. TX_STATUS_FAIL(FIFO_FLUSHED);
  2312. TX_STATUS_FAIL(INSUFFICIENT_CF_POLL);
  2313. TX_STATUS_FAIL(PASSIVE_NO_RX);
  2314. TX_STATUS_FAIL(NO_BEACON_ON_RADAR);
  2315. }
  2316. return "UNKNOWN";
  2317. #undef TX_STATUS_FAIL
  2318. #undef TX_STATUS_POSTPONE
  2319. }
  2320. #endif /* CONFIG_IWLEGACY_DEBUG */
  2321. static struct il_link_quality_cmd *
  2322. il4965_sta_alloc_lq(struct il_priv *il, u8 sta_id)
  2323. {
  2324. int i, r;
  2325. struct il_link_quality_cmd *link_cmd;
  2326. u32 rate_flags = 0;
  2327. __le32 rate_n_flags;
  2328. link_cmd = kzalloc(sizeof(struct il_link_quality_cmd), GFP_KERNEL);
  2329. if (!link_cmd) {
  2330. IL_ERR("Unable to allocate memory for LQ cmd.\n");
  2331. return NULL;
  2332. }
  2333. /* Set up the rate scaling to start at selected rate, fall back
  2334. * all the way down to 1M in IEEE order, and then spin on 1M */
  2335. if (il->band == IEEE80211_BAND_5GHZ)
  2336. r = RATE_6M_IDX;
  2337. else
  2338. r = RATE_1M_IDX;
  2339. if (r >= IL_FIRST_CCK_RATE && r <= IL_LAST_CCK_RATE)
  2340. rate_flags |= RATE_MCS_CCK_MSK;
  2341. rate_flags |=
  2342. il4965_first_antenna(il->hw_params.
  2343. valid_tx_ant) << RATE_MCS_ANT_POS;
  2344. rate_n_flags = il4965_hw_set_rate_n_flags(il_rates[r].plcp, rate_flags);
  2345. for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
  2346. link_cmd->rs_table[i].rate_n_flags = rate_n_flags;
  2347. link_cmd->general_params.single_stream_ant_msk =
  2348. il4965_first_antenna(il->hw_params.valid_tx_ant);
  2349. link_cmd->general_params.dual_stream_ant_msk =
  2350. il->hw_params.valid_tx_ant & ~il4965_first_antenna(il->hw_params.
  2351. valid_tx_ant);
  2352. if (!link_cmd->general_params.dual_stream_ant_msk) {
  2353. link_cmd->general_params.dual_stream_ant_msk = ANT_AB;
  2354. } else if (il4965_num_of_ant(il->hw_params.valid_tx_ant) == 2) {
  2355. link_cmd->general_params.dual_stream_ant_msk =
  2356. il->hw_params.valid_tx_ant;
  2357. }
  2358. link_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
  2359. link_cmd->agg_params.agg_time_limit =
  2360. cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
  2361. link_cmd->sta_id = sta_id;
  2362. return link_cmd;
  2363. }
  2364. /*
  2365. * il4965_add_bssid_station - Add the special IBSS BSSID station
  2366. *
  2367. * Function sleeps.
  2368. */
  2369. int
  2370. il4965_add_bssid_station(struct il_priv *il, struct il_rxon_context *ctx,
  2371. const u8 *addr, u8 *sta_id_r)
  2372. {
  2373. int ret;
  2374. u8 sta_id;
  2375. struct il_link_quality_cmd *link_cmd;
  2376. unsigned long flags;
  2377. if (sta_id_r)
  2378. *sta_id_r = IL_INVALID_STATION;
  2379. ret = il_add_station_common(il, ctx, addr, 0, NULL, &sta_id);
  2380. if (ret) {
  2381. IL_ERR("Unable to add station %pM\n", addr);
  2382. return ret;
  2383. }
  2384. if (sta_id_r)
  2385. *sta_id_r = sta_id;
  2386. spin_lock_irqsave(&il->sta_lock, flags);
  2387. il->stations[sta_id].used |= IL_STA_LOCAL;
  2388. spin_unlock_irqrestore(&il->sta_lock, flags);
  2389. /* Set up default rate scaling table in device's station table */
  2390. link_cmd = il4965_sta_alloc_lq(il, sta_id);
  2391. if (!link_cmd) {
  2392. IL_ERR("Unable to initialize rate scaling for station %pM.\n",
  2393. addr);
  2394. return -ENOMEM;
  2395. }
  2396. ret = il_send_lq_cmd(il, ctx, link_cmd, CMD_SYNC, true);
  2397. if (ret)
  2398. IL_ERR("Link quality command failed (%d)\n", ret);
  2399. spin_lock_irqsave(&il->sta_lock, flags);
  2400. il->stations[sta_id].lq = link_cmd;
  2401. spin_unlock_irqrestore(&il->sta_lock, flags);
  2402. return 0;
  2403. }
  2404. static int
  2405. il4965_static_wepkey_cmd(struct il_priv *il, struct il_rxon_context *ctx,
  2406. bool send_if_empty)
  2407. {
  2408. int i, not_empty = 0;
  2409. u8 buff[sizeof(struct il_wep_cmd) +
  2410. sizeof(struct il_wep_key) * WEP_KEYS_MAX];
  2411. struct il_wep_cmd *wep_cmd = (struct il_wep_cmd *)buff;
  2412. size_t cmd_size = sizeof(struct il_wep_cmd);
  2413. struct il_host_cmd cmd = {
  2414. .id = ctx->wep_key_cmd,
  2415. .data = wep_cmd,
  2416. .flags = CMD_SYNC,
  2417. };
  2418. might_sleep();
  2419. memset(wep_cmd, 0,
  2420. cmd_size + (sizeof(struct il_wep_key) * WEP_KEYS_MAX));
  2421. for (i = 0; i < WEP_KEYS_MAX; i++) {
  2422. wep_cmd->key[i].key_idx = i;
  2423. if (ctx->wep_keys[i].key_size) {
  2424. wep_cmd->key[i].key_offset = i;
  2425. not_empty = 1;
  2426. } else {
  2427. wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET;
  2428. }
  2429. wep_cmd->key[i].key_size = ctx->wep_keys[i].key_size;
  2430. memcpy(&wep_cmd->key[i].key[3], ctx->wep_keys[i].key,
  2431. ctx->wep_keys[i].key_size);
  2432. }
  2433. wep_cmd->global_key_type = WEP_KEY_WEP_TYPE;
  2434. wep_cmd->num_keys = WEP_KEYS_MAX;
  2435. cmd_size += sizeof(struct il_wep_key) * WEP_KEYS_MAX;
  2436. cmd.len = cmd_size;
  2437. if (not_empty || send_if_empty)
  2438. return il_send_cmd(il, &cmd);
  2439. else
  2440. return 0;
  2441. }
  2442. int
  2443. il4965_restore_default_wep_keys(struct il_priv *il, struct il_rxon_context *ctx)
  2444. {
  2445. lockdep_assert_held(&il->mutex);
  2446. return il4965_static_wepkey_cmd(il, ctx, false);
  2447. }
  2448. int
  2449. il4965_remove_default_wep_key(struct il_priv *il, struct il_rxon_context *ctx,
  2450. struct ieee80211_key_conf *keyconf)
  2451. {
  2452. int ret;
  2453. lockdep_assert_held(&il->mutex);
  2454. D_WEP("Removing default WEP key: idx=%d\n", keyconf->keyidx);
  2455. memset(&ctx->wep_keys[keyconf->keyidx], 0, sizeof(ctx->wep_keys[0]));
  2456. if (il_is_rfkill(il)) {
  2457. D_WEP("Not sending C_WEPKEY command due to RFKILL.\n");
  2458. /* but keys in device are clear anyway so return success */
  2459. return 0;
  2460. }
  2461. ret = il4965_static_wepkey_cmd(il, ctx, 1);
  2462. D_WEP("Remove default WEP key: idx=%d ret=%d\n", keyconf->keyidx, ret);
  2463. return ret;
  2464. }
  2465. int
  2466. il4965_set_default_wep_key(struct il_priv *il, struct il_rxon_context *ctx,
  2467. struct ieee80211_key_conf *keyconf)
  2468. {
  2469. int ret;
  2470. lockdep_assert_held(&il->mutex);
  2471. if (keyconf->keylen != WEP_KEY_LEN_128 &&
  2472. keyconf->keylen != WEP_KEY_LEN_64) {
  2473. D_WEP("Bad WEP key length %d\n", keyconf->keylen);
  2474. return -EINVAL;
  2475. }
  2476. keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
  2477. keyconf->hw_key_idx = HW_KEY_DEFAULT;
  2478. il->stations[ctx->ap_sta_id].keyinfo.cipher = keyconf->cipher;
  2479. ctx->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
  2480. memcpy(&ctx->wep_keys[keyconf->keyidx].key, &keyconf->key,
  2481. keyconf->keylen);
  2482. ret = il4965_static_wepkey_cmd(il, ctx, false);
  2483. D_WEP("Set default WEP key: len=%d idx=%d ret=%d\n", keyconf->keylen,
  2484. keyconf->keyidx, ret);
  2485. return ret;
  2486. }
  2487. static int
  2488. il4965_set_wep_dynamic_key_info(struct il_priv *il, struct il_rxon_context *ctx,
  2489. struct ieee80211_key_conf *keyconf, u8 sta_id)
  2490. {
  2491. unsigned long flags;
  2492. __le16 key_flags = 0;
  2493. struct il_addsta_cmd sta_cmd;
  2494. lockdep_assert_held(&il->mutex);
  2495. keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
  2496. key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK);
  2497. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  2498. key_flags &= ~STA_KEY_FLG_INVALID;
  2499. if (keyconf->keylen == WEP_KEY_LEN_128)
  2500. key_flags |= STA_KEY_FLG_KEY_SIZE_MSK;
  2501. if (sta_id == ctx->bcast_sta_id)
  2502. key_flags |= STA_KEY_MULTICAST_MSK;
  2503. spin_lock_irqsave(&il->sta_lock, flags);
  2504. il->stations[sta_id].keyinfo.cipher = keyconf->cipher;
  2505. il->stations[sta_id].keyinfo.keylen = keyconf->keylen;
  2506. il->stations[sta_id].keyinfo.keyidx = keyconf->keyidx;
  2507. memcpy(il->stations[sta_id].keyinfo.key, keyconf->key, keyconf->keylen);
  2508. memcpy(&il->stations[sta_id].sta.key.key[3], keyconf->key,
  2509. keyconf->keylen);
  2510. if ((il->stations[sta_id].sta.key.
  2511. key_flags & STA_KEY_FLG_ENCRYPT_MSK) == STA_KEY_FLG_NO_ENC)
  2512. il->stations[sta_id].sta.key.key_offset =
  2513. il_get_free_ucode_key_idx(il);
  2514. /* else, we are overriding an existing key => no need to allocated room
  2515. * in uCode. */
  2516. WARN(il->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
  2517. "no space for a new key");
  2518. il->stations[sta_id].sta.key.key_flags = key_flags;
  2519. il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  2520. il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2521. memcpy(&sta_cmd, &il->stations[sta_id].sta,
  2522. sizeof(struct il_addsta_cmd));
  2523. spin_unlock_irqrestore(&il->sta_lock, flags);
  2524. return il_send_add_sta(il, &sta_cmd, CMD_SYNC);
  2525. }
  2526. static int
  2527. il4965_set_ccmp_dynamic_key_info(struct il_priv *il,
  2528. struct il_rxon_context *ctx,
  2529. struct ieee80211_key_conf *keyconf, u8 sta_id)
  2530. {
  2531. unsigned long flags;
  2532. __le16 key_flags = 0;
  2533. struct il_addsta_cmd sta_cmd;
  2534. lockdep_assert_held(&il->mutex);
  2535. key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
  2536. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  2537. key_flags &= ~STA_KEY_FLG_INVALID;
  2538. if (sta_id == ctx->bcast_sta_id)
  2539. key_flags |= STA_KEY_MULTICAST_MSK;
  2540. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  2541. spin_lock_irqsave(&il->sta_lock, flags);
  2542. il->stations[sta_id].keyinfo.cipher = keyconf->cipher;
  2543. il->stations[sta_id].keyinfo.keylen = keyconf->keylen;
  2544. memcpy(il->stations[sta_id].keyinfo.key, keyconf->key, keyconf->keylen);
  2545. memcpy(il->stations[sta_id].sta.key.key, keyconf->key, keyconf->keylen);
  2546. if ((il->stations[sta_id].sta.key.
  2547. key_flags & STA_KEY_FLG_ENCRYPT_MSK) == STA_KEY_FLG_NO_ENC)
  2548. il->stations[sta_id].sta.key.key_offset =
  2549. il_get_free_ucode_key_idx(il);
  2550. /* else, we are overriding an existing key => no need to allocated room
  2551. * in uCode. */
  2552. WARN(il->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
  2553. "no space for a new key");
  2554. il->stations[sta_id].sta.key.key_flags = key_flags;
  2555. il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  2556. il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2557. memcpy(&sta_cmd, &il->stations[sta_id].sta,
  2558. sizeof(struct il_addsta_cmd));
  2559. spin_unlock_irqrestore(&il->sta_lock, flags);
  2560. return il_send_add_sta(il, &sta_cmd, CMD_SYNC);
  2561. }
  2562. static int
  2563. il4965_set_tkip_dynamic_key_info(struct il_priv *il,
  2564. struct il_rxon_context *ctx,
  2565. struct ieee80211_key_conf *keyconf, u8 sta_id)
  2566. {
  2567. unsigned long flags;
  2568. int ret = 0;
  2569. __le16 key_flags = 0;
  2570. key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
  2571. key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
  2572. key_flags &= ~STA_KEY_FLG_INVALID;
  2573. if (sta_id == ctx->bcast_sta_id)
  2574. key_flags |= STA_KEY_MULTICAST_MSK;
  2575. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  2576. keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  2577. spin_lock_irqsave(&il->sta_lock, flags);
  2578. il->stations[sta_id].keyinfo.cipher = keyconf->cipher;
  2579. il->stations[sta_id].keyinfo.keylen = 16;
  2580. if ((il->stations[sta_id].sta.key.
  2581. key_flags & STA_KEY_FLG_ENCRYPT_MSK) == STA_KEY_FLG_NO_ENC)
  2582. il->stations[sta_id].sta.key.key_offset =
  2583. il_get_free_ucode_key_idx(il);
  2584. /* else, we are overriding an existing key => no need to allocated room
  2585. * in uCode. */
  2586. WARN(il->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
  2587. "no space for a new key");
  2588. il->stations[sta_id].sta.key.key_flags = key_flags;
  2589. /* This copy is acutally not needed: we get the key with each TX */
  2590. memcpy(il->stations[sta_id].keyinfo.key, keyconf->key, 16);
  2591. memcpy(il->stations[sta_id].sta.key.key, keyconf->key, 16);
  2592. spin_unlock_irqrestore(&il->sta_lock, flags);
  2593. return ret;
  2594. }
  2595. void
  2596. il4965_update_tkip_key(struct il_priv *il, struct il_rxon_context *ctx,
  2597. struct ieee80211_key_conf *keyconf,
  2598. struct ieee80211_sta *sta, u32 iv32, u16 * phase1key)
  2599. {
  2600. u8 sta_id;
  2601. unsigned long flags;
  2602. int i;
  2603. if (il_scan_cancel(il)) {
  2604. /* cancel scan failed, just live w/ bad key and rely
  2605. briefly on SW decryption */
  2606. return;
  2607. }
  2608. sta_id = il_sta_id_or_broadcast(il, ctx, sta);
  2609. if (sta_id == IL_INVALID_STATION)
  2610. return;
  2611. spin_lock_irqsave(&il->sta_lock, flags);
  2612. il->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
  2613. for (i = 0; i < 5; i++)
  2614. il->stations[sta_id].sta.key.tkip_rx_ttak[i] =
  2615. cpu_to_le16(phase1key[i]);
  2616. il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  2617. il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2618. il_send_add_sta(il, &il->stations[sta_id].sta, CMD_ASYNC);
  2619. spin_unlock_irqrestore(&il->sta_lock, flags);
  2620. }
  2621. int
  2622. il4965_remove_dynamic_key(struct il_priv *il, struct il_rxon_context *ctx,
  2623. struct ieee80211_key_conf *keyconf, u8 sta_id)
  2624. {
  2625. unsigned long flags;
  2626. u16 key_flags;
  2627. u8 keyidx;
  2628. struct il_addsta_cmd sta_cmd;
  2629. lockdep_assert_held(&il->mutex);
  2630. ctx->key_mapping_keys--;
  2631. spin_lock_irqsave(&il->sta_lock, flags);
  2632. key_flags = le16_to_cpu(il->stations[sta_id].sta.key.key_flags);
  2633. keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3;
  2634. D_WEP("Remove dynamic key: idx=%d sta=%d\n", keyconf->keyidx, sta_id);
  2635. if (keyconf->keyidx != keyidx) {
  2636. /* We need to remove a key with idx different that the one
  2637. * in the uCode. This means that the key we need to remove has
  2638. * been replaced by another one with different idx.
  2639. * Don't do anything and return ok
  2640. */
  2641. spin_unlock_irqrestore(&il->sta_lock, flags);
  2642. return 0;
  2643. }
  2644. if (il->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET) {
  2645. IL_WARN("Removing wrong key %d 0x%x\n", keyconf->keyidx,
  2646. key_flags);
  2647. spin_unlock_irqrestore(&il->sta_lock, flags);
  2648. return 0;
  2649. }
  2650. if (!test_and_clear_bit
  2651. (il->stations[sta_id].sta.key.key_offset, &il->ucode_key_table))
  2652. IL_ERR("idx %d not used in uCode key table.\n",
  2653. il->stations[sta_id].sta.key.key_offset);
  2654. memset(&il->stations[sta_id].keyinfo, 0, sizeof(struct il_hw_key));
  2655. memset(&il->stations[sta_id].sta.key, 0, sizeof(struct il4965_keyinfo));
  2656. il->stations[sta_id].sta.key.key_flags =
  2657. STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID;
  2658. il->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET;
  2659. il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
  2660. il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2661. if (il_is_rfkill(il)) {
  2662. D_WEP
  2663. ("Not sending C_ADD_STA command because RFKILL enabled.\n");
  2664. spin_unlock_irqrestore(&il->sta_lock, flags);
  2665. return 0;
  2666. }
  2667. memcpy(&sta_cmd, &il->stations[sta_id].sta,
  2668. sizeof(struct il_addsta_cmd));
  2669. spin_unlock_irqrestore(&il->sta_lock, flags);
  2670. return il_send_add_sta(il, &sta_cmd, CMD_SYNC);
  2671. }
  2672. int
  2673. il4965_set_dynamic_key(struct il_priv *il, struct il_rxon_context *ctx,
  2674. struct ieee80211_key_conf *keyconf, u8 sta_id)
  2675. {
  2676. int ret;
  2677. lockdep_assert_held(&il->mutex);
  2678. ctx->key_mapping_keys++;
  2679. keyconf->hw_key_idx = HW_KEY_DYNAMIC;
  2680. switch (keyconf->cipher) {
  2681. case WLAN_CIPHER_SUITE_CCMP:
  2682. ret =
  2683. il4965_set_ccmp_dynamic_key_info(il, ctx, keyconf, sta_id);
  2684. break;
  2685. case WLAN_CIPHER_SUITE_TKIP:
  2686. ret =
  2687. il4965_set_tkip_dynamic_key_info(il, ctx, keyconf, sta_id);
  2688. break;
  2689. case WLAN_CIPHER_SUITE_WEP40:
  2690. case WLAN_CIPHER_SUITE_WEP104:
  2691. ret = il4965_set_wep_dynamic_key_info(il, ctx, keyconf, sta_id);
  2692. break;
  2693. default:
  2694. IL_ERR("Unknown alg: %s cipher = %x\n", __func__,
  2695. keyconf->cipher);
  2696. ret = -EINVAL;
  2697. }
  2698. D_WEP("Set dynamic key: cipher=%x len=%d idx=%d sta=%d ret=%d\n",
  2699. keyconf->cipher, keyconf->keylen, keyconf->keyidx, sta_id, ret);
  2700. return ret;
  2701. }
  2702. /**
  2703. * il4965_alloc_bcast_station - add broadcast station into driver's station table.
  2704. *
  2705. * This adds the broadcast station into the driver's station table
  2706. * and marks it driver active, so that it will be restored to the
  2707. * device at the next best time.
  2708. */
  2709. int
  2710. il4965_alloc_bcast_station(struct il_priv *il, struct il_rxon_context *ctx)
  2711. {
  2712. struct il_link_quality_cmd *link_cmd;
  2713. unsigned long flags;
  2714. u8 sta_id;
  2715. spin_lock_irqsave(&il->sta_lock, flags);
  2716. sta_id = il_prep_station(il, ctx, il_bcast_addr, false, NULL);
  2717. if (sta_id == IL_INVALID_STATION) {
  2718. IL_ERR("Unable to prepare broadcast station\n");
  2719. spin_unlock_irqrestore(&il->sta_lock, flags);
  2720. return -EINVAL;
  2721. }
  2722. il->stations[sta_id].used |= IL_STA_DRIVER_ACTIVE;
  2723. il->stations[sta_id].used |= IL_STA_BCAST;
  2724. spin_unlock_irqrestore(&il->sta_lock, flags);
  2725. link_cmd = il4965_sta_alloc_lq(il, sta_id);
  2726. if (!link_cmd) {
  2727. IL_ERR
  2728. ("Unable to initialize rate scaling for bcast station.\n");
  2729. return -ENOMEM;
  2730. }
  2731. spin_lock_irqsave(&il->sta_lock, flags);
  2732. il->stations[sta_id].lq = link_cmd;
  2733. spin_unlock_irqrestore(&il->sta_lock, flags);
  2734. return 0;
  2735. }
  2736. /**
  2737. * il4965_update_bcast_station - update broadcast station's LQ command
  2738. *
  2739. * Only used by iwl4965. Placed here to have all bcast station management
  2740. * code together.
  2741. */
  2742. static int
  2743. il4965_update_bcast_station(struct il_priv *il, struct il_rxon_context *ctx)
  2744. {
  2745. unsigned long flags;
  2746. struct il_link_quality_cmd *link_cmd;
  2747. u8 sta_id = ctx->bcast_sta_id;
  2748. link_cmd = il4965_sta_alloc_lq(il, sta_id);
  2749. if (!link_cmd) {
  2750. IL_ERR("Unable to initialize rate scaling for bcast sta.\n");
  2751. return -ENOMEM;
  2752. }
  2753. spin_lock_irqsave(&il->sta_lock, flags);
  2754. if (il->stations[sta_id].lq)
  2755. kfree(il->stations[sta_id].lq);
  2756. else
  2757. D_INFO("Bcast sta rate scaling has not been initialized.\n");
  2758. il->stations[sta_id].lq = link_cmd;
  2759. spin_unlock_irqrestore(&il->sta_lock, flags);
  2760. return 0;
  2761. }
  2762. int
  2763. il4965_update_bcast_stations(struct il_priv *il)
  2764. {
  2765. return il4965_update_bcast_station(il, &il->ctx);
  2766. }
  2767. /**
  2768. * il4965_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
  2769. */
  2770. int
  2771. il4965_sta_tx_modify_enable_tid(struct il_priv *il, int sta_id, int tid)
  2772. {
  2773. unsigned long flags;
  2774. struct il_addsta_cmd sta_cmd;
  2775. lockdep_assert_held(&il->mutex);
  2776. /* Remove "disable" flag, to enable Tx for this TID */
  2777. spin_lock_irqsave(&il->sta_lock, flags);
  2778. il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
  2779. il->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
  2780. il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2781. memcpy(&sta_cmd, &il->stations[sta_id].sta,
  2782. sizeof(struct il_addsta_cmd));
  2783. spin_unlock_irqrestore(&il->sta_lock, flags);
  2784. return il_send_add_sta(il, &sta_cmd, CMD_SYNC);
  2785. }
  2786. int
  2787. il4965_sta_rx_agg_start(struct il_priv *il, struct ieee80211_sta *sta, int tid,
  2788. u16 ssn)
  2789. {
  2790. unsigned long flags;
  2791. int sta_id;
  2792. struct il_addsta_cmd sta_cmd;
  2793. lockdep_assert_held(&il->mutex);
  2794. sta_id = il_sta_id(sta);
  2795. if (sta_id == IL_INVALID_STATION)
  2796. return -ENXIO;
  2797. spin_lock_irqsave(&il->sta_lock, flags);
  2798. il->stations[sta_id].sta.station_flags_msk = 0;
  2799. il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
  2800. il->stations[sta_id].sta.add_immediate_ba_tid = (u8) tid;
  2801. il->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
  2802. il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2803. memcpy(&sta_cmd, &il->stations[sta_id].sta,
  2804. sizeof(struct il_addsta_cmd));
  2805. spin_unlock_irqrestore(&il->sta_lock, flags);
  2806. return il_send_add_sta(il, &sta_cmd, CMD_SYNC);
  2807. }
  2808. int
  2809. il4965_sta_rx_agg_stop(struct il_priv *il, struct ieee80211_sta *sta, int tid)
  2810. {
  2811. unsigned long flags;
  2812. int sta_id;
  2813. struct il_addsta_cmd sta_cmd;
  2814. lockdep_assert_held(&il->mutex);
  2815. sta_id = il_sta_id(sta);
  2816. if (sta_id == IL_INVALID_STATION) {
  2817. IL_ERR("Invalid station for AGG tid %d\n", tid);
  2818. return -ENXIO;
  2819. }
  2820. spin_lock_irqsave(&il->sta_lock, flags);
  2821. il->stations[sta_id].sta.station_flags_msk = 0;
  2822. il->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
  2823. il->stations[sta_id].sta.remove_immediate_ba_tid = (u8) tid;
  2824. il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2825. memcpy(&sta_cmd, &il->stations[sta_id].sta,
  2826. sizeof(struct il_addsta_cmd));
  2827. spin_unlock_irqrestore(&il->sta_lock, flags);
  2828. return il_send_add_sta(il, &sta_cmd, CMD_SYNC);
  2829. }
  2830. void
  2831. il4965_sta_modify_sleep_tx_count(struct il_priv *il, int sta_id, int cnt)
  2832. {
  2833. unsigned long flags;
  2834. spin_lock_irqsave(&il->sta_lock, flags);
  2835. il->stations[sta_id].sta.station_flags |= STA_FLG_PWR_SAVE_MSK;
  2836. il->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
  2837. il->stations[sta_id].sta.sta.modify_mask =
  2838. STA_MODIFY_SLEEP_TX_COUNT_MSK;
  2839. il->stations[sta_id].sta.sleep_tx_count = cpu_to_le16(cnt);
  2840. il->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2841. il_send_add_sta(il, &il->stations[sta_id].sta, CMD_ASYNC);
  2842. spin_unlock_irqrestore(&il->sta_lock, flags);
  2843. }
  2844. void
  2845. il4965_update_chain_flags(struct il_priv *il)
  2846. {
  2847. if (il->cfg->ops->hcmd->set_rxon_chain) {
  2848. il->cfg->ops->hcmd->set_rxon_chain(il, &il->ctx);
  2849. if (il->ctx.active.rx_chain != il->ctx.staging.rx_chain)
  2850. il_commit_rxon(il, &il->ctx);
  2851. }
  2852. }
  2853. static void
  2854. il4965_clear_free_frames(struct il_priv *il)
  2855. {
  2856. struct list_head *element;
  2857. D_INFO("%d frames on pre-allocated heap on clear.\n", il->frames_count);
  2858. while (!list_empty(&il->free_frames)) {
  2859. element = il->free_frames.next;
  2860. list_del(element);
  2861. kfree(list_entry(element, struct il_frame, list));
  2862. il->frames_count--;
  2863. }
  2864. if (il->frames_count) {
  2865. IL_WARN("%d frames still in use. Did we lose one?\n",
  2866. il->frames_count);
  2867. il->frames_count = 0;
  2868. }
  2869. }
  2870. static struct il_frame *
  2871. il4965_get_free_frame(struct il_priv *il)
  2872. {
  2873. struct il_frame *frame;
  2874. struct list_head *element;
  2875. if (list_empty(&il->free_frames)) {
  2876. frame = kzalloc(sizeof(*frame), GFP_KERNEL);
  2877. if (!frame) {
  2878. IL_ERR("Could not allocate frame!\n");
  2879. return NULL;
  2880. }
  2881. il->frames_count++;
  2882. return frame;
  2883. }
  2884. element = il->free_frames.next;
  2885. list_del(element);
  2886. return list_entry(element, struct il_frame, list);
  2887. }
  2888. static void
  2889. il4965_free_frame(struct il_priv *il, struct il_frame *frame)
  2890. {
  2891. memset(frame, 0, sizeof(*frame));
  2892. list_add(&frame->list, &il->free_frames);
  2893. }
  2894. static u32
  2895. il4965_fill_beacon_frame(struct il_priv *il, struct ieee80211_hdr *hdr,
  2896. int left)
  2897. {
  2898. lockdep_assert_held(&il->mutex);
  2899. if (!il->beacon_skb)
  2900. return 0;
  2901. if (il->beacon_skb->len > left)
  2902. return 0;
  2903. memcpy(hdr, il->beacon_skb->data, il->beacon_skb->len);
  2904. return il->beacon_skb->len;
  2905. }
  2906. /* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
  2907. static void
  2908. il4965_set_beacon_tim(struct il_priv *il,
  2909. struct il_tx_beacon_cmd *tx_beacon_cmd, u8 * beacon,
  2910. u32 frame_size)
  2911. {
  2912. u16 tim_idx;
  2913. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
  2914. /*
  2915. * The idx is relative to frame start but we start looking at the
  2916. * variable-length part of the beacon.
  2917. */
  2918. tim_idx = mgmt->u.beacon.variable - beacon;
  2919. /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
  2920. while ((tim_idx < (frame_size - 2)) &&
  2921. (beacon[tim_idx] != WLAN_EID_TIM))
  2922. tim_idx += beacon[tim_idx + 1] + 2;
  2923. /* If TIM field was found, set variables */
  2924. if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
  2925. tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
  2926. tx_beacon_cmd->tim_size = beacon[tim_idx + 1];
  2927. } else
  2928. IL_WARN("Unable to find TIM Element in beacon\n");
  2929. }
  2930. static unsigned int
  2931. il4965_hw_get_beacon_cmd(struct il_priv *il, struct il_frame *frame)
  2932. {
  2933. struct il_tx_beacon_cmd *tx_beacon_cmd;
  2934. u32 frame_size;
  2935. u32 rate_flags;
  2936. u32 rate;
  2937. /*
  2938. * We have to set up the TX command, the TX Beacon command, and the
  2939. * beacon contents.
  2940. */
  2941. lockdep_assert_held(&il->mutex);
  2942. if (!il->beacon_ctx) {
  2943. IL_ERR("trying to build beacon w/o beacon context!\n");
  2944. return 0;
  2945. }
  2946. /* Initialize memory */
  2947. tx_beacon_cmd = &frame->u.beacon;
  2948. memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
  2949. /* Set up TX beacon contents */
  2950. frame_size =
  2951. il4965_fill_beacon_frame(il, tx_beacon_cmd->frame,
  2952. sizeof(frame->u) - sizeof(*tx_beacon_cmd));
  2953. if (WARN_ON_ONCE(frame_size > MAX_MPDU_SIZE))
  2954. return 0;
  2955. if (!frame_size)
  2956. return 0;
  2957. /* Set up TX command fields */
  2958. tx_beacon_cmd->tx.len = cpu_to_le16((u16) frame_size);
  2959. tx_beacon_cmd->tx.sta_id = il->beacon_ctx->bcast_sta_id;
  2960. tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  2961. tx_beacon_cmd->tx.tx_flags =
  2962. TX_CMD_FLG_SEQ_CTL_MSK | TX_CMD_FLG_TSF_MSK |
  2963. TX_CMD_FLG_STA_RATE_MSK;
  2964. /* Set up TX beacon command fields */
  2965. il4965_set_beacon_tim(il, tx_beacon_cmd, (u8 *) tx_beacon_cmd->frame,
  2966. frame_size);
  2967. /* Set up packet rate and flags */
  2968. rate = il_get_lowest_plcp(il, il->beacon_ctx);
  2969. il->mgmt_tx_ant =
  2970. il4965_toggle_tx_ant(il, il->mgmt_tx_ant,
  2971. il->hw_params.valid_tx_ant);
  2972. rate_flags = il4965_ant_idx_to_flags(il->mgmt_tx_ant);
  2973. if ((rate >= IL_FIRST_CCK_RATE) && (rate <= IL_LAST_CCK_RATE))
  2974. rate_flags |= RATE_MCS_CCK_MSK;
  2975. tx_beacon_cmd->tx.rate_n_flags =
  2976. il4965_hw_set_rate_n_flags(rate, rate_flags);
  2977. return sizeof(*tx_beacon_cmd) + frame_size;
  2978. }
  2979. int
  2980. il4965_send_beacon_cmd(struct il_priv *il)
  2981. {
  2982. struct il_frame *frame;
  2983. unsigned int frame_size;
  2984. int rc;
  2985. frame = il4965_get_free_frame(il);
  2986. if (!frame) {
  2987. IL_ERR("Could not obtain free frame buffer for beacon "
  2988. "command.\n");
  2989. return -ENOMEM;
  2990. }
  2991. frame_size = il4965_hw_get_beacon_cmd(il, frame);
  2992. if (!frame_size) {
  2993. IL_ERR("Error configuring the beacon command\n");
  2994. il4965_free_frame(il, frame);
  2995. return -EINVAL;
  2996. }
  2997. rc = il_send_cmd_pdu(il, C_TX_BEACON, frame_size, &frame->u.cmd[0]);
  2998. il4965_free_frame(il, frame);
  2999. return rc;
  3000. }
  3001. static inline dma_addr_t
  3002. il4965_tfd_tb_get_addr(struct il_tfd *tfd, u8 idx)
  3003. {
  3004. struct il_tfd_tb *tb = &tfd->tbs[idx];
  3005. dma_addr_t addr = get_unaligned_le32(&tb->lo);
  3006. if (sizeof(dma_addr_t) > sizeof(u32))
  3007. addr |=
  3008. ((dma_addr_t) (le16_to_cpu(tb->hi_n_len) & 0xF) << 16) <<
  3009. 16;
  3010. return addr;
  3011. }
  3012. static inline u16
  3013. il4965_tfd_tb_get_len(struct il_tfd *tfd, u8 idx)
  3014. {
  3015. struct il_tfd_tb *tb = &tfd->tbs[idx];
  3016. return le16_to_cpu(tb->hi_n_len) >> 4;
  3017. }
  3018. static inline void
  3019. il4965_tfd_set_tb(struct il_tfd *tfd, u8 idx, dma_addr_t addr, u16 len)
  3020. {
  3021. struct il_tfd_tb *tb = &tfd->tbs[idx];
  3022. u16 hi_n_len = len << 4;
  3023. put_unaligned_le32(addr, &tb->lo);
  3024. if (sizeof(dma_addr_t) > sizeof(u32))
  3025. hi_n_len |= ((addr >> 16) >> 16) & 0xF;
  3026. tb->hi_n_len = cpu_to_le16(hi_n_len);
  3027. tfd->num_tbs = idx + 1;
  3028. }
  3029. static inline u8
  3030. il4965_tfd_get_num_tbs(struct il_tfd *tfd)
  3031. {
  3032. return tfd->num_tbs & 0x1f;
  3033. }
  3034. /**
  3035. * il4965_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
  3036. * @il - driver ilate data
  3037. * @txq - tx queue
  3038. *
  3039. * Does NOT advance any TFD circular buffer read/write idxes
  3040. * Does NOT free the TFD itself (which is within circular buffer)
  3041. */
  3042. void
  3043. il4965_hw_txq_free_tfd(struct il_priv *il, struct il_tx_queue *txq)
  3044. {
  3045. struct il_tfd *tfd_tmp = (struct il_tfd *)txq->tfds;
  3046. struct il_tfd *tfd;
  3047. struct pci_dev *dev = il->pci_dev;
  3048. int idx = txq->q.read_ptr;
  3049. int i;
  3050. int num_tbs;
  3051. tfd = &tfd_tmp[idx];
  3052. /* Sanity check on number of chunks */
  3053. num_tbs = il4965_tfd_get_num_tbs(tfd);
  3054. if (num_tbs >= IL_NUM_OF_TBS) {
  3055. IL_ERR("Too many chunks: %i\n", num_tbs);
  3056. /* @todo issue fatal error, it is quite serious situation */
  3057. return;
  3058. }
  3059. /* Unmap tx_cmd */
  3060. if (num_tbs)
  3061. pci_unmap_single(dev, dma_unmap_addr(&txq->meta[idx], mapping),
  3062. dma_unmap_len(&txq->meta[idx], len),
  3063. PCI_DMA_BIDIRECTIONAL);
  3064. /* Unmap chunks, if any. */
  3065. for (i = 1; i < num_tbs; i++)
  3066. pci_unmap_single(dev, il4965_tfd_tb_get_addr(tfd, i),
  3067. il4965_tfd_tb_get_len(tfd, i),
  3068. PCI_DMA_TODEVICE);
  3069. /* free SKB */
  3070. if (txq->txb) {
  3071. struct sk_buff *skb;
  3072. skb = txq->txb[txq->q.read_ptr].skb;
  3073. /* can be called from irqs-disabled context */
  3074. if (skb) {
  3075. dev_kfree_skb_any(skb);
  3076. txq->txb[txq->q.read_ptr].skb = NULL;
  3077. }
  3078. }
  3079. }
  3080. int
  3081. il4965_hw_txq_attach_buf_to_tfd(struct il_priv *il, struct il_tx_queue *txq,
  3082. dma_addr_t addr, u16 len, u8 reset, u8 pad)
  3083. {
  3084. struct il_queue *q;
  3085. struct il_tfd *tfd, *tfd_tmp;
  3086. u32 num_tbs;
  3087. q = &txq->q;
  3088. tfd_tmp = (struct il_tfd *)txq->tfds;
  3089. tfd = &tfd_tmp[q->write_ptr];
  3090. if (reset)
  3091. memset(tfd, 0, sizeof(*tfd));
  3092. num_tbs = il4965_tfd_get_num_tbs(tfd);
  3093. /* Each TFD can point to a maximum 20 Tx buffers */
  3094. if (num_tbs >= IL_NUM_OF_TBS) {
  3095. IL_ERR("Error can not send more than %d chunks\n",
  3096. IL_NUM_OF_TBS);
  3097. return -EINVAL;
  3098. }
  3099. BUG_ON(addr & ~DMA_BIT_MASK(36));
  3100. if (unlikely(addr & ~IL_TX_DMA_MASK))
  3101. IL_ERR("Unaligned address = %llx\n", (unsigned long long)addr);
  3102. il4965_tfd_set_tb(tfd, num_tbs, addr, len);
  3103. return 0;
  3104. }
  3105. /*
  3106. * Tell nic where to find circular buffer of Tx Frame Descriptors for
  3107. * given Tx queue, and enable the DMA channel used for that queue.
  3108. *
  3109. * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA
  3110. * channels supported in hardware.
  3111. */
  3112. int
  3113. il4965_hw_tx_queue_init(struct il_priv *il, struct il_tx_queue *txq)
  3114. {
  3115. int txq_id = txq->q.id;
  3116. /* Circular buffer (TFD queue in DRAM) physical base address */
  3117. il_wr(il, FH49_MEM_CBBC_QUEUE(txq_id), txq->q.dma_addr >> 8);
  3118. return 0;
  3119. }
  3120. /******************************************************************************
  3121. *
  3122. * Generic RX handler implementations
  3123. *
  3124. ******************************************************************************/
  3125. static void
  3126. il4965_hdl_alive(struct il_priv *il, struct il_rx_buf *rxb)
  3127. {
  3128. struct il_rx_pkt *pkt = rxb_addr(rxb);
  3129. struct il_alive_resp *palive;
  3130. struct delayed_work *pwork;
  3131. palive = &pkt->u.alive_frame;
  3132. D_INFO("Alive ucode status 0x%08X revision " "0x%01X 0x%01X\n",
  3133. palive->is_valid, palive->ver_type, palive->ver_subtype);
  3134. if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
  3135. D_INFO("Initialization Alive received.\n");
  3136. memcpy(&il->card_alive_init, &pkt->u.alive_frame,
  3137. sizeof(struct il_init_alive_resp));
  3138. pwork = &il->init_alive_start;
  3139. } else {
  3140. D_INFO("Runtime Alive received.\n");
  3141. memcpy(&il->card_alive, &pkt->u.alive_frame,
  3142. sizeof(struct il_alive_resp));
  3143. pwork = &il->alive_start;
  3144. }
  3145. /* We delay the ALIVE response by 5ms to
  3146. * give the HW RF Kill time to activate... */
  3147. if (palive->is_valid == UCODE_VALID_OK)
  3148. queue_delayed_work(il->workqueue, pwork, msecs_to_jiffies(5));
  3149. else
  3150. IL_WARN("uCode did not respond OK.\n");
  3151. }
  3152. /**
  3153. * il4965_bg_stats_periodic - Timer callback to queue stats
  3154. *
  3155. * This callback is provided in order to send a stats request.
  3156. *
  3157. * This timer function is continually reset to execute within
  3158. * REG_RECALIB_PERIOD seconds since the last N_STATS
  3159. * was received. We need to ensure we receive the stats in order
  3160. * to update the temperature used for calibrating the TXPOWER.
  3161. */
  3162. static void
  3163. il4965_bg_stats_periodic(unsigned long data)
  3164. {
  3165. struct il_priv *il = (struct il_priv *)data;
  3166. if (test_bit(S_EXIT_PENDING, &il->status))
  3167. return;
  3168. /* dont send host command if rf-kill is on */
  3169. if (!il_is_ready_rf(il))
  3170. return;
  3171. il_send_stats_request(il, CMD_ASYNC, false);
  3172. }
  3173. static void
  3174. il4965_hdl_beacon(struct il_priv *il, struct il_rx_buf *rxb)
  3175. {
  3176. struct il_rx_pkt *pkt = rxb_addr(rxb);
  3177. struct il4965_beacon_notif *beacon =
  3178. (struct il4965_beacon_notif *)pkt->u.raw;
  3179. #ifdef CONFIG_IWLEGACY_DEBUG
  3180. u8 rate = il4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
  3181. D_RX("beacon status %x retries %d iss %d " "tsf %d %d rate %d\n",
  3182. le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
  3183. beacon->beacon_notify_hdr.failure_frame,
  3184. le32_to_cpu(beacon->ibss_mgr_status),
  3185. le32_to_cpu(beacon->high_tsf), le32_to_cpu(beacon->low_tsf), rate);
  3186. #endif
  3187. il->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status);
  3188. }
  3189. static void
  3190. il4965_perform_ct_kill_task(struct il_priv *il)
  3191. {
  3192. unsigned long flags;
  3193. D_POWER("Stop all queues\n");
  3194. if (il->mac80211_registered)
  3195. ieee80211_stop_queues(il->hw);
  3196. _il_wr(il, CSR_UCODE_DRV_GP1_SET,
  3197. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  3198. _il_rd(il, CSR_UCODE_DRV_GP1);
  3199. spin_lock_irqsave(&il->reg_lock, flags);
  3200. if (!_il_grab_nic_access(il))
  3201. _il_release_nic_access(il);
  3202. spin_unlock_irqrestore(&il->reg_lock, flags);
  3203. }
  3204. /* Handle notification from uCode that card's power state is changing
  3205. * due to software, hardware, or critical temperature RFKILL */
  3206. static void
  3207. il4965_hdl_card_state(struct il_priv *il, struct il_rx_buf *rxb)
  3208. {
  3209. struct il_rx_pkt *pkt = rxb_addr(rxb);
  3210. u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
  3211. unsigned long status = il->status;
  3212. D_RF_KILL("Card state received: HW:%s SW:%s CT:%s\n",
  3213. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  3214. (flags & SW_CARD_DISABLED) ? "Kill" : "On",
  3215. (flags & CT_CARD_DISABLED) ? "Reached" : "Not reached");
  3216. if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | CT_CARD_DISABLED)) {
  3217. _il_wr(il, CSR_UCODE_DRV_GP1_SET,
  3218. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  3219. il_wr(il, HBUS_TARG_MBX_C, HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  3220. if (!(flags & RXON_CARD_DISABLED)) {
  3221. _il_wr(il, CSR_UCODE_DRV_GP1_CLR,
  3222. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  3223. il_wr(il, HBUS_TARG_MBX_C,
  3224. HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  3225. }
  3226. }
  3227. if (flags & CT_CARD_DISABLED)
  3228. il4965_perform_ct_kill_task(il);
  3229. if (flags & HW_CARD_DISABLED)
  3230. set_bit(S_RF_KILL_HW, &il->status);
  3231. else
  3232. clear_bit(S_RF_KILL_HW, &il->status);
  3233. if (!(flags & RXON_CARD_DISABLED))
  3234. il_scan_cancel(il);
  3235. if ((test_bit(S_RF_KILL_HW, &status) !=
  3236. test_bit(S_RF_KILL_HW, &il->status)))
  3237. wiphy_rfkill_set_hw_state(il->hw->wiphy,
  3238. test_bit(S_RF_KILL_HW, &il->status));
  3239. else
  3240. wake_up(&il->wait_command_queue);
  3241. }
  3242. /**
  3243. * il4965_setup_handlers - Initialize Rx handler callbacks
  3244. *
  3245. * Setup the RX handlers for each of the reply types sent from the uCode
  3246. * to the host.
  3247. *
  3248. * This function chains into the hardware specific files for them to setup
  3249. * any hardware specific handlers as well.
  3250. */
  3251. static void
  3252. il4965_setup_handlers(struct il_priv *il)
  3253. {
  3254. il->handlers[N_ALIVE] = il4965_hdl_alive;
  3255. il->handlers[N_ERROR] = il_hdl_error;
  3256. il->handlers[N_CHANNEL_SWITCH] = il_hdl_csa;
  3257. il->handlers[N_SPECTRUM_MEASUREMENT] = il_hdl_spectrum_measurement;
  3258. il->handlers[N_PM_SLEEP] = il_hdl_pm_sleep;
  3259. il->handlers[N_PM_DEBUG_STATS] = il_hdl_pm_debug_stats;
  3260. il->handlers[N_BEACON] = il4965_hdl_beacon;
  3261. /*
  3262. * The same handler is used for both the REPLY to a discrete
  3263. * stats request from the host as well as for the periodic
  3264. * stats notifications (after received beacons) from the uCode.
  3265. */
  3266. il->handlers[C_STATS] = il4965_hdl_c_stats;
  3267. il->handlers[N_STATS] = il4965_hdl_stats;
  3268. il_setup_rx_scan_handlers(il);
  3269. /* status change handler */
  3270. il->handlers[N_CARD_STATE] = il4965_hdl_card_state;
  3271. il->handlers[N_MISSED_BEACONS] = il4965_hdl_missed_beacon;
  3272. /* Rx handlers */
  3273. il->handlers[N_RX_PHY] = il4965_hdl_rx_phy;
  3274. il->handlers[N_RX_MPDU] = il4965_hdl_rx;
  3275. /* block ack */
  3276. il->handlers[N_COMPRESSED_BA] = il4965_hdl_compressed_ba;
  3277. /* Set up hardware specific Rx handlers */
  3278. il->cfg->ops->lib->handler_setup(il);
  3279. }
  3280. /**
  3281. * il4965_rx_handle - Main entry function for receiving responses from uCode
  3282. *
  3283. * Uses the il->handlers callback function array to invoke
  3284. * the appropriate handlers, including command responses,
  3285. * frame-received notifications, and other notifications.
  3286. */
  3287. void
  3288. il4965_rx_handle(struct il_priv *il)
  3289. {
  3290. struct il_rx_buf *rxb;
  3291. struct il_rx_pkt *pkt;
  3292. struct il_rx_queue *rxq = &il->rxq;
  3293. u32 r, i;
  3294. int reclaim;
  3295. unsigned long flags;
  3296. u8 fill_rx = 0;
  3297. u32 count = 8;
  3298. int total_empty;
  3299. /* uCode's read idx (stored in shared DRAM) indicates the last Rx
  3300. * buffer that the driver may process (last buffer filled by ucode). */
  3301. r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
  3302. i = rxq->read;
  3303. /* Rx interrupt, but nothing sent from uCode */
  3304. if (i == r)
  3305. D_RX("r = %d, i = %d\n", r, i);
  3306. /* calculate total frames need to be restock after handling RX */
  3307. total_empty = r - rxq->write_actual;
  3308. if (total_empty < 0)
  3309. total_empty += RX_QUEUE_SIZE;
  3310. if (total_empty > (RX_QUEUE_SIZE / 2))
  3311. fill_rx = 1;
  3312. while (i != r) {
  3313. int len;
  3314. rxb = rxq->queue[i];
  3315. /* If an RXB doesn't have a Rx queue slot associated with it,
  3316. * then a bug has been introduced in the queue refilling
  3317. * routines -- catch it here */
  3318. BUG_ON(rxb == NULL);
  3319. rxq->queue[i] = NULL;
  3320. pci_unmap_page(il->pci_dev, rxb->page_dma,
  3321. PAGE_SIZE << il->hw_params.rx_page_order,
  3322. PCI_DMA_FROMDEVICE);
  3323. pkt = rxb_addr(rxb);
  3324. len = le32_to_cpu(pkt->len_n_flags) & IL_RX_FRAME_SIZE_MSK;
  3325. len += sizeof(u32); /* account for status word */
  3326. /* Reclaim a command buffer only if this packet is a response
  3327. * to a (driver-originated) command.
  3328. * If the packet (e.g. Rx frame) originated from uCode,
  3329. * there is no command buffer to reclaim.
  3330. * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
  3331. * but apparently a few don't get set; catch them here. */
  3332. reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
  3333. (pkt->hdr.cmd != N_RX_PHY) && (pkt->hdr.cmd != N_RX) &&
  3334. (pkt->hdr.cmd != N_RX_MPDU) &&
  3335. (pkt->hdr.cmd != N_COMPRESSED_BA) &&
  3336. (pkt->hdr.cmd != N_STATS) && (pkt->hdr.cmd != C_TX);
  3337. /* Based on type of command response or notification,
  3338. * handle those that need handling via function in
  3339. * handlers table. See il4965_setup_handlers() */
  3340. if (il->handlers[pkt->hdr.cmd]) {
  3341. D_RX("r = %d, i = %d, %s, 0x%02x\n", r, i,
  3342. il_get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
  3343. il->isr_stats.handlers[pkt->hdr.cmd]++;
  3344. il->handlers[pkt->hdr.cmd] (il, rxb);
  3345. } else {
  3346. /* No handling needed */
  3347. D_RX("r %d i %d No handler needed for %s, 0x%02x\n", r,
  3348. i, il_get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
  3349. }
  3350. /*
  3351. * XXX: After here, we should always check rxb->page
  3352. * against NULL before touching it or its virtual
  3353. * memory (pkt). Because some handler might have
  3354. * already taken or freed the pages.
  3355. */
  3356. if (reclaim) {
  3357. /* Invoke any callbacks, transfer the buffer to caller,
  3358. * and fire off the (possibly) blocking il_send_cmd()
  3359. * as we reclaim the driver command queue */
  3360. if (rxb->page)
  3361. il_tx_cmd_complete(il, rxb);
  3362. else
  3363. IL_WARN("Claim null rxb?\n");
  3364. }
  3365. /* Reuse the page if possible. For notification packets and
  3366. * SKBs that fail to Rx correctly, add them back into the
  3367. * rx_free list for reuse later. */
  3368. spin_lock_irqsave(&rxq->lock, flags);
  3369. if (rxb->page != NULL) {
  3370. rxb->page_dma =
  3371. pci_map_page(il->pci_dev, rxb->page, 0,
  3372. PAGE_SIZE << il->hw_params.
  3373. rx_page_order, PCI_DMA_FROMDEVICE);
  3374. list_add_tail(&rxb->list, &rxq->rx_free);
  3375. rxq->free_count++;
  3376. } else
  3377. list_add_tail(&rxb->list, &rxq->rx_used);
  3378. spin_unlock_irqrestore(&rxq->lock, flags);
  3379. i = (i + 1) & RX_QUEUE_MASK;
  3380. /* If there are a lot of unused frames,
  3381. * restock the Rx queue so ucode wont assert. */
  3382. if (fill_rx) {
  3383. count++;
  3384. if (count >= 8) {
  3385. rxq->read = i;
  3386. il4965_rx_replenish_now(il);
  3387. count = 0;
  3388. }
  3389. }
  3390. }
  3391. /* Backtrack one entry */
  3392. rxq->read = i;
  3393. if (fill_rx)
  3394. il4965_rx_replenish_now(il);
  3395. else
  3396. il4965_rx_queue_restock(il);
  3397. }
  3398. /* call this function to flush any scheduled tasklet */
  3399. static inline void
  3400. il4965_synchronize_irq(struct il_priv *il)
  3401. {
  3402. /* wait to make sure we flush pending tasklet */
  3403. synchronize_irq(il->pci_dev->irq);
  3404. tasklet_kill(&il->irq_tasklet);
  3405. }
  3406. static void
  3407. il4965_irq_tasklet(struct il_priv *il)
  3408. {
  3409. u32 inta, handled = 0;
  3410. u32 inta_fh;
  3411. unsigned long flags;
  3412. u32 i;
  3413. #ifdef CONFIG_IWLEGACY_DEBUG
  3414. u32 inta_mask;
  3415. #endif
  3416. spin_lock_irqsave(&il->lock, flags);
  3417. /* Ack/clear/reset pending uCode interrupts.
  3418. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
  3419. * and will clear only when CSR_FH_INT_STATUS gets cleared. */
  3420. inta = _il_rd(il, CSR_INT);
  3421. _il_wr(il, CSR_INT, inta);
  3422. /* Ack/clear/reset pending flow-handler (DMA) interrupts.
  3423. * Any new interrupts that happen after this, either while we're
  3424. * in this tasklet, or later, will show up in next ISR/tasklet. */
  3425. inta_fh = _il_rd(il, CSR_FH_INT_STATUS);
  3426. _il_wr(il, CSR_FH_INT_STATUS, inta_fh);
  3427. #ifdef CONFIG_IWLEGACY_DEBUG
  3428. if (il_get_debug_level(il) & IL_DL_ISR) {
  3429. /* just for debug */
  3430. inta_mask = _il_rd(il, CSR_INT_MASK);
  3431. D_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", inta,
  3432. inta_mask, inta_fh);
  3433. }
  3434. #endif
  3435. spin_unlock_irqrestore(&il->lock, flags);
  3436. /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
  3437. * atomic, make sure that inta covers all the interrupts that
  3438. * we've discovered, even if FH interrupt came in just after
  3439. * reading CSR_INT. */
  3440. if (inta_fh & CSR49_FH_INT_RX_MASK)
  3441. inta |= CSR_INT_BIT_FH_RX;
  3442. if (inta_fh & CSR49_FH_INT_TX_MASK)
  3443. inta |= CSR_INT_BIT_FH_TX;
  3444. /* Now service all interrupt bits discovered above. */
  3445. if (inta & CSR_INT_BIT_HW_ERR) {
  3446. IL_ERR("Hardware error detected. Restarting.\n");
  3447. /* Tell the device to stop sending interrupts */
  3448. il_disable_interrupts(il);
  3449. il->isr_stats.hw++;
  3450. il_irq_handle_error(il);
  3451. handled |= CSR_INT_BIT_HW_ERR;
  3452. return;
  3453. }
  3454. #ifdef CONFIG_IWLEGACY_DEBUG
  3455. if (il_get_debug_level(il) & (IL_DL_ISR)) {
  3456. /* NIC fires this, but we don't use it, redundant with WAKEUP */
  3457. if (inta & CSR_INT_BIT_SCD) {
  3458. D_ISR("Scheduler finished to transmit "
  3459. "the frame/frames.\n");
  3460. il->isr_stats.sch++;
  3461. }
  3462. /* Alive notification via Rx interrupt will do the real work */
  3463. if (inta & CSR_INT_BIT_ALIVE) {
  3464. D_ISR("Alive interrupt\n");
  3465. il->isr_stats.alive++;
  3466. }
  3467. }
  3468. #endif
  3469. /* Safely ignore these bits for debug checks below */
  3470. inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
  3471. /* HW RF KILL switch toggled */
  3472. if (inta & CSR_INT_BIT_RF_KILL) {
  3473. int hw_rf_kill = 0;
  3474. if (!
  3475. (_il_rd(il, CSR_GP_CNTRL) &
  3476. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
  3477. hw_rf_kill = 1;
  3478. IL_WARN("RF_KILL bit toggled to %s.\n",
  3479. hw_rf_kill ? "disable radio" : "enable radio");
  3480. il->isr_stats.rfkill++;
  3481. /* driver only loads ucode once setting the interface up.
  3482. * the driver allows loading the ucode even if the radio
  3483. * is killed. Hence update the killswitch state here. The
  3484. * rfkill handler will care about restarting if needed.
  3485. */
  3486. if (!test_bit(S_ALIVE, &il->status)) {
  3487. if (hw_rf_kill)
  3488. set_bit(S_RF_KILL_HW, &il->status);
  3489. else
  3490. clear_bit(S_RF_KILL_HW, &il->status);
  3491. wiphy_rfkill_set_hw_state(il->hw->wiphy, hw_rf_kill);
  3492. }
  3493. handled |= CSR_INT_BIT_RF_KILL;
  3494. }
  3495. /* Chip got too hot and stopped itself */
  3496. if (inta & CSR_INT_BIT_CT_KILL) {
  3497. IL_ERR("Microcode CT kill error detected.\n");
  3498. il->isr_stats.ctkill++;
  3499. handled |= CSR_INT_BIT_CT_KILL;
  3500. }
  3501. /* Error detected by uCode */
  3502. if (inta & CSR_INT_BIT_SW_ERR) {
  3503. IL_ERR("Microcode SW error detected. " " Restarting 0x%X.\n",
  3504. inta);
  3505. il->isr_stats.sw++;
  3506. il_irq_handle_error(il);
  3507. handled |= CSR_INT_BIT_SW_ERR;
  3508. }
  3509. /*
  3510. * uCode wakes up after power-down sleep.
  3511. * Tell device about any new tx or host commands enqueued,
  3512. * and about any Rx buffers made available while asleep.
  3513. */
  3514. if (inta & CSR_INT_BIT_WAKEUP) {
  3515. D_ISR("Wakeup interrupt\n");
  3516. il_rx_queue_update_write_ptr(il, &il->rxq);
  3517. for (i = 0; i < il->hw_params.max_txq_num; i++)
  3518. il_txq_update_write_ptr(il, &il->txq[i]);
  3519. il->isr_stats.wakeup++;
  3520. handled |= CSR_INT_BIT_WAKEUP;
  3521. }
  3522. /* All uCode command responses, including Tx command responses,
  3523. * Rx "responses" (frame-received notification), and other
  3524. * notifications from uCode come through here*/
  3525. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
  3526. il4965_rx_handle(il);
  3527. il->isr_stats.rx++;
  3528. handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
  3529. }
  3530. /* This "Tx" DMA channel is used only for loading uCode */
  3531. if (inta & CSR_INT_BIT_FH_TX) {
  3532. D_ISR("uCode load interrupt\n");
  3533. il->isr_stats.tx++;
  3534. handled |= CSR_INT_BIT_FH_TX;
  3535. /* Wake up uCode load routine, now that load is complete */
  3536. il->ucode_write_complete = 1;
  3537. wake_up(&il->wait_command_queue);
  3538. }
  3539. if (inta & ~handled) {
  3540. IL_ERR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
  3541. il->isr_stats.unhandled++;
  3542. }
  3543. if (inta & ~(il->inta_mask)) {
  3544. IL_WARN("Disabled INTA bits 0x%08x were pending\n",
  3545. inta & ~il->inta_mask);
  3546. IL_WARN(" with FH49_INT = 0x%08x\n", inta_fh);
  3547. }
  3548. /* Re-enable all interrupts */
  3549. /* only Re-enable if disabled by irq */
  3550. if (test_bit(S_INT_ENABLED, &il->status))
  3551. il_enable_interrupts(il);
  3552. /* Re-enable RF_KILL if it occurred */
  3553. else if (handled & CSR_INT_BIT_RF_KILL)
  3554. il_enable_rfkill_int(il);
  3555. #ifdef CONFIG_IWLEGACY_DEBUG
  3556. if (il_get_debug_level(il) & (IL_DL_ISR)) {
  3557. inta = _il_rd(il, CSR_INT);
  3558. inta_mask = _il_rd(il, CSR_INT_MASK);
  3559. inta_fh = _il_rd(il, CSR_FH_INT_STATUS);
  3560. D_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
  3561. "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
  3562. }
  3563. #endif
  3564. }
  3565. /*****************************************************************************
  3566. *
  3567. * sysfs attributes
  3568. *
  3569. *****************************************************************************/
  3570. #ifdef CONFIG_IWLEGACY_DEBUG
  3571. /*
  3572. * The following adds a new attribute to the sysfs representation
  3573. * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/)
  3574. * used for controlling the debug level.
  3575. *
  3576. * See the level definitions in iwl for details.
  3577. *
  3578. * The debug_level being managed using sysfs below is a per device debug
  3579. * level that is used instead of the global debug level if it (the per
  3580. * device debug level) is set.
  3581. */
  3582. static ssize_t
  3583. il4965_show_debug_level(struct device *d, struct device_attribute *attr,
  3584. char *buf)
  3585. {
  3586. struct il_priv *il = dev_get_drvdata(d);
  3587. return sprintf(buf, "0x%08X\n", il_get_debug_level(il));
  3588. }
  3589. static ssize_t
  3590. il4965_store_debug_level(struct device *d, struct device_attribute *attr,
  3591. const char *buf, size_t count)
  3592. {
  3593. struct il_priv *il = dev_get_drvdata(d);
  3594. unsigned long val;
  3595. int ret;
  3596. ret = strict_strtoul(buf, 0, &val);
  3597. if (ret)
  3598. IL_ERR("%s is not in hex or decimal form.\n", buf);
  3599. else {
  3600. il->debug_level = val;
  3601. if (il_alloc_traffic_mem(il))
  3602. IL_ERR("Not enough memory to generate traffic log\n");
  3603. }
  3604. return strnlen(buf, count);
  3605. }
  3606. static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, il4965_show_debug_level,
  3607. il4965_store_debug_level);
  3608. #endif /* CONFIG_IWLEGACY_DEBUG */
  3609. static ssize_t
  3610. il4965_show_temperature(struct device *d, struct device_attribute *attr,
  3611. char *buf)
  3612. {
  3613. struct il_priv *il = dev_get_drvdata(d);
  3614. if (!il_is_alive(il))
  3615. return -EAGAIN;
  3616. return sprintf(buf, "%d\n", il->temperature);
  3617. }
  3618. static DEVICE_ATTR(temperature, S_IRUGO, il4965_show_temperature, NULL);
  3619. static ssize_t
  3620. il4965_show_tx_power(struct device *d, struct device_attribute *attr, char *buf)
  3621. {
  3622. struct il_priv *il = dev_get_drvdata(d);
  3623. if (!il_is_ready_rf(il))
  3624. return sprintf(buf, "off\n");
  3625. else
  3626. return sprintf(buf, "%d\n", il->tx_power_user_lmt);
  3627. }
  3628. static ssize_t
  3629. il4965_store_tx_power(struct device *d, struct device_attribute *attr,
  3630. const char *buf, size_t count)
  3631. {
  3632. struct il_priv *il = dev_get_drvdata(d);
  3633. unsigned long val;
  3634. int ret;
  3635. ret = strict_strtoul(buf, 10, &val);
  3636. if (ret)
  3637. IL_INFO("%s is not in decimal form.\n", buf);
  3638. else {
  3639. ret = il_set_tx_power(il, val, false);
  3640. if (ret)
  3641. IL_ERR("failed setting tx power (0x%d).\n", ret);
  3642. else
  3643. ret = count;
  3644. }
  3645. return ret;
  3646. }
  3647. static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, il4965_show_tx_power,
  3648. il4965_store_tx_power);
  3649. static struct attribute *il_sysfs_entries[] = {
  3650. &dev_attr_temperature.attr,
  3651. &dev_attr_tx_power.attr,
  3652. #ifdef CONFIG_IWLEGACY_DEBUG
  3653. &dev_attr_debug_level.attr,
  3654. #endif
  3655. NULL
  3656. };
  3657. static struct attribute_group il_attribute_group = {
  3658. .name = NULL, /* put in device directory */
  3659. .attrs = il_sysfs_entries,
  3660. };
  3661. /******************************************************************************
  3662. *
  3663. * uCode download functions
  3664. *
  3665. ******************************************************************************/
  3666. static void
  3667. il4965_dealloc_ucode_pci(struct il_priv *il)
  3668. {
  3669. il_free_fw_desc(il->pci_dev, &il->ucode_code);
  3670. il_free_fw_desc(il->pci_dev, &il->ucode_data);
  3671. il_free_fw_desc(il->pci_dev, &il->ucode_data_backup);
  3672. il_free_fw_desc(il->pci_dev, &il->ucode_init);
  3673. il_free_fw_desc(il->pci_dev, &il->ucode_init_data);
  3674. il_free_fw_desc(il->pci_dev, &il->ucode_boot);
  3675. }
  3676. static void
  3677. il4965_nic_start(struct il_priv *il)
  3678. {
  3679. /* Remove all resets to allow NIC to operate */
  3680. _il_wr(il, CSR_RESET, 0);
  3681. }
  3682. static void il4965_ucode_callback(const struct firmware *ucode_raw,
  3683. void *context);
  3684. static int il4965_mac_setup_register(struct il_priv *il, u32 max_probe_length);
  3685. static int __must_check
  3686. il4965_request_firmware(struct il_priv *il, bool first)
  3687. {
  3688. const char *name_pre = il->cfg->fw_name_pre;
  3689. char tag[8];
  3690. if (first) {
  3691. il->fw_idx = il->cfg->ucode_api_max;
  3692. sprintf(tag, "%d", il->fw_idx);
  3693. } else {
  3694. il->fw_idx--;
  3695. sprintf(tag, "%d", il->fw_idx);
  3696. }
  3697. if (il->fw_idx < il->cfg->ucode_api_min) {
  3698. IL_ERR("no suitable firmware found!\n");
  3699. return -ENOENT;
  3700. }
  3701. sprintf(il->firmware_name, "%s%s%s", name_pre, tag, ".ucode");
  3702. D_INFO("attempting to load firmware '%s'\n", il->firmware_name);
  3703. return request_firmware_nowait(THIS_MODULE, 1, il->firmware_name,
  3704. &il->pci_dev->dev, GFP_KERNEL, il,
  3705. il4965_ucode_callback);
  3706. }
  3707. struct il4965_firmware_pieces {
  3708. const void *inst, *data, *init, *init_data, *boot;
  3709. size_t inst_size, data_size, init_size, init_data_size, boot_size;
  3710. };
  3711. static int
  3712. il4965_load_firmware(struct il_priv *il, const struct firmware *ucode_raw,
  3713. struct il4965_firmware_pieces *pieces)
  3714. {
  3715. struct il_ucode_header *ucode = (void *)ucode_raw->data;
  3716. u32 api_ver, hdr_size;
  3717. const u8 *src;
  3718. il->ucode_ver = le32_to_cpu(ucode->ver);
  3719. api_ver = IL_UCODE_API(il->ucode_ver);
  3720. switch (api_ver) {
  3721. default:
  3722. case 0:
  3723. case 1:
  3724. case 2:
  3725. hdr_size = 24;
  3726. if (ucode_raw->size < hdr_size) {
  3727. IL_ERR("File size too small!\n");
  3728. return -EINVAL;
  3729. }
  3730. pieces->inst_size = le32_to_cpu(ucode->v1.inst_size);
  3731. pieces->data_size = le32_to_cpu(ucode->v1.data_size);
  3732. pieces->init_size = le32_to_cpu(ucode->v1.init_size);
  3733. pieces->init_data_size = le32_to_cpu(ucode->v1.init_data_size);
  3734. pieces->boot_size = le32_to_cpu(ucode->v1.boot_size);
  3735. src = ucode->v1.data;
  3736. break;
  3737. }
  3738. /* Verify size of file vs. image size info in file's header */
  3739. if (ucode_raw->size !=
  3740. hdr_size + pieces->inst_size + pieces->data_size +
  3741. pieces->init_size + pieces->init_data_size + pieces->boot_size) {
  3742. IL_ERR("uCode file size %d does not match expected size\n",
  3743. (int)ucode_raw->size);
  3744. return -EINVAL;
  3745. }
  3746. pieces->inst = src;
  3747. src += pieces->inst_size;
  3748. pieces->data = src;
  3749. src += pieces->data_size;
  3750. pieces->init = src;
  3751. src += pieces->init_size;
  3752. pieces->init_data = src;
  3753. src += pieces->init_data_size;
  3754. pieces->boot = src;
  3755. src += pieces->boot_size;
  3756. return 0;
  3757. }
  3758. /**
  3759. * il4965_ucode_callback - callback when firmware was loaded
  3760. *
  3761. * If loaded successfully, copies the firmware into buffers
  3762. * for the card to fetch (via DMA).
  3763. */
  3764. static void
  3765. il4965_ucode_callback(const struct firmware *ucode_raw, void *context)
  3766. {
  3767. struct il_priv *il = context;
  3768. struct il_ucode_header *ucode;
  3769. int err;
  3770. struct il4965_firmware_pieces pieces;
  3771. const unsigned int api_max = il->cfg->ucode_api_max;
  3772. const unsigned int api_min = il->cfg->ucode_api_min;
  3773. u32 api_ver;
  3774. u32 max_probe_length = 200;
  3775. u32 standard_phy_calibration_size =
  3776. IL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE;
  3777. memset(&pieces, 0, sizeof(pieces));
  3778. if (!ucode_raw) {
  3779. if (il->fw_idx <= il->cfg->ucode_api_max)
  3780. IL_ERR("request for firmware file '%s' failed.\n",
  3781. il->firmware_name);
  3782. goto try_again;
  3783. }
  3784. D_INFO("Loaded firmware file '%s' (%zd bytes).\n", il->firmware_name,
  3785. ucode_raw->size);
  3786. /* Make sure that we got at least the API version number */
  3787. if (ucode_raw->size < 4) {
  3788. IL_ERR("File size way too small!\n");
  3789. goto try_again;
  3790. }
  3791. /* Data from ucode file: header followed by uCode images */
  3792. ucode = (struct il_ucode_header *)ucode_raw->data;
  3793. err = il4965_load_firmware(il, ucode_raw, &pieces);
  3794. if (err)
  3795. goto try_again;
  3796. api_ver = IL_UCODE_API(il->ucode_ver);
  3797. /*
  3798. * api_ver should match the api version forming part of the
  3799. * firmware filename ... but we don't check for that and only rely
  3800. * on the API version read from firmware header from here on forward
  3801. */
  3802. if (api_ver < api_min || api_ver > api_max) {
  3803. IL_ERR("Driver unable to support your firmware API. "
  3804. "Driver supports v%u, firmware is v%u.\n", api_max,
  3805. api_ver);
  3806. goto try_again;
  3807. }
  3808. if (api_ver != api_max)
  3809. IL_ERR("Firmware has old API version. Expected v%u, "
  3810. "got v%u. New firmware can be obtained "
  3811. "from http://www.intellinuxwireless.org.\n", api_max,
  3812. api_ver);
  3813. IL_INFO("loaded firmware version %u.%u.%u.%u\n",
  3814. IL_UCODE_MAJOR(il->ucode_ver), IL_UCODE_MINOR(il->ucode_ver),
  3815. IL_UCODE_API(il->ucode_ver), IL_UCODE_SERIAL(il->ucode_ver));
  3816. snprintf(il->hw->wiphy->fw_version, sizeof(il->hw->wiphy->fw_version),
  3817. "%u.%u.%u.%u", IL_UCODE_MAJOR(il->ucode_ver),
  3818. IL_UCODE_MINOR(il->ucode_ver), IL_UCODE_API(il->ucode_ver),
  3819. IL_UCODE_SERIAL(il->ucode_ver));
  3820. /*
  3821. * For any of the failures below (before allocating pci memory)
  3822. * we will try to load a version with a smaller API -- maybe the
  3823. * user just got a corrupted version of the latest API.
  3824. */
  3825. D_INFO("f/w package hdr ucode version raw = 0x%x\n", il->ucode_ver);
  3826. D_INFO("f/w package hdr runtime inst size = %Zd\n", pieces.inst_size);
  3827. D_INFO("f/w package hdr runtime data size = %Zd\n", pieces.data_size);
  3828. D_INFO("f/w package hdr init inst size = %Zd\n", pieces.init_size);
  3829. D_INFO("f/w package hdr init data size = %Zd\n", pieces.init_data_size);
  3830. D_INFO("f/w package hdr boot inst size = %Zd\n", pieces.boot_size);
  3831. /* Verify that uCode images will fit in card's SRAM */
  3832. if (pieces.inst_size > il->hw_params.max_inst_size) {
  3833. IL_ERR("uCode instr len %Zd too large to fit in\n",
  3834. pieces.inst_size);
  3835. goto try_again;
  3836. }
  3837. if (pieces.data_size > il->hw_params.max_data_size) {
  3838. IL_ERR("uCode data len %Zd too large to fit in\n",
  3839. pieces.data_size);
  3840. goto try_again;
  3841. }
  3842. if (pieces.init_size > il->hw_params.max_inst_size) {
  3843. IL_ERR("uCode init instr len %Zd too large to fit in\n",
  3844. pieces.init_size);
  3845. goto try_again;
  3846. }
  3847. if (pieces.init_data_size > il->hw_params.max_data_size) {
  3848. IL_ERR("uCode init data len %Zd too large to fit in\n",
  3849. pieces.init_data_size);
  3850. goto try_again;
  3851. }
  3852. if (pieces.boot_size > il->hw_params.max_bsm_size) {
  3853. IL_ERR("uCode boot instr len %Zd too large to fit in\n",
  3854. pieces.boot_size);
  3855. goto try_again;
  3856. }
  3857. /* Allocate ucode buffers for card's bus-master loading ... */
  3858. /* Runtime instructions and 2 copies of data:
  3859. * 1) unmodified from disk
  3860. * 2) backup cache for save/restore during power-downs */
  3861. il->ucode_code.len = pieces.inst_size;
  3862. il_alloc_fw_desc(il->pci_dev, &il->ucode_code);
  3863. il->ucode_data.len = pieces.data_size;
  3864. il_alloc_fw_desc(il->pci_dev, &il->ucode_data);
  3865. il->ucode_data_backup.len = pieces.data_size;
  3866. il_alloc_fw_desc(il->pci_dev, &il->ucode_data_backup);
  3867. if (!il->ucode_code.v_addr || !il->ucode_data.v_addr ||
  3868. !il->ucode_data_backup.v_addr)
  3869. goto err_pci_alloc;
  3870. /* Initialization instructions and data */
  3871. if (pieces.init_size && pieces.init_data_size) {
  3872. il->ucode_init.len = pieces.init_size;
  3873. il_alloc_fw_desc(il->pci_dev, &il->ucode_init);
  3874. il->ucode_init_data.len = pieces.init_data_size;
  3875. il_alloc_fw_desc(il->pci_dev, &il->ucode_init_data);
  3876. if (!il->ucode_init.v_addr || !il->ucode_init_data.v_addr)
  3877. goto err_pci_alloc;
  3878. }
  3879. /* Bootstrap (instructions only, no data) */
  3880. if (pieces.boot_size) {
  3881. il->ucode_boot.len = pieces.boot_size;
  3882. il_alloc_fw_desc(il->pci_dev, &il->ucode_boot);
  3883. if (!il->ucode_boot.v_addr)
  3884. goto err_pci_alloc;
  3885. }
  3886. /* Now that we can no longer fail, copy information */
  3887. il->sta_key_max_num = STA_KEY_MAX_NUM;
  3888. /* Copy images into buffers for card's bus-master reads ... */
  3889. /* Runtime instructions (first block of data in file) */
  3890. D_INFO("Copying (but not loading) uCode instr len %Zd\n",
  3891. pieces.inst_size);
  3892. memcpy(il->ucode_code.v_addr, pieces.inst, pieces.inst_size);
  3893. D_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
  3894. il->ucode_code.v_addr, (u32) il->ucode_code.p_addr);
  3895. /*
  3896. * Runtime data
  3897. * NOTE: Copy into backup buffer will be done in il_up()
  3898. */
  3899. D_INFO("Copying (but not loading) uCode data len %Zd\n",
  3900. pieces.data_size);
  3901. memcpy(il->ucode_data.v_addr, pieces.data, pieces.data_size);
  3902. memcpy(il->ucode_data_backup.v_addr, pieces.data, pieces.data_size);
  3903. /* Initialization instructions */
  3904. if (pieces.init_size) {
  3905. D_INFO("Copying (but not loading) init instr len %Zd\n",
  3906. pieces.init_size);
  3907. memcpy(il->ucode_init.v_addr, pieces.init, pieces.init_size);
  3908. }
  3909. /* Initialization data */
  3910. if (pieces.init_data_size) {
  3911. D_INFO("Copying (but not loading) init data len %Zd\n",
  3912. pieces.init_data_size);
  3913. memcpy(il->ucode_init_data.v_addr, pieces.init_data,
  3914. pieces.init_data_size);
  3915. }
  3916. /* Bootstrap instructions */
  3917. D_INFO("Copying (but not loading) boot instr len %Zd\n",
  3918. pieces.boot_size);
  3919. memcpy(il->ucode_boot.v_addr, pieces.boot, pieces.boot_size);
  3920. /*
  3921. * figure out the offset of chain noise reset and gain commands
  3922. * base on the size of standard phy calibration commands table size
  3923. */
  3924. il->_4965.phy_calib_chain_noise_reset_cmd =
  3925. standard_phy_calibration_size;
  3926. il->_4965.phy_calib_chain_noise_gain_cmd =
  3927. standard_phy_calibration_size + 1;
  3928. /**************************************************
  3929. * This is still part of probe() in a sense...
  3930. *
  3931. * 9. Setup and register with mac80211 and debugfs
  3932. **************************************************/
  3933. err = il4965_mac_setup_register(il, max_probe_length);
  3934. if (err)
  3935. goto out_unbind;
  3936. err = il_dbgfs_register(il, DRV_NAME);
  3937. if (err)
  3938. IL_ERR("failed to create debugfs files. Ignoring error: %d\n",
  3939. err);
  3940. err = sysfs_create_group(&il->pci_dev->dev.kobj, &il_attribute_group);
  3941. if (err) {
  3942. IL_ERR("failed to create sysfs device attributes\n");
  3943. goto out_unbind;
  3944. }
  3945. /* We have our copies now, allow OS release its copies */
  3946. release_firmware(ucode_raw);
  3947. complete(&il->_4965.firmware_loading_complete);
  3948. return;
  3949. try_again:
  3950. /* try next, if any */
  3951. if (il4965_request_firmware(il, false))
  3952. goto out_unbind;
  3953. release_firmware(ucode_raw);
  3954. return;
  3955. err_pci_alloc:
  3956. IL_ERR("failed to allocate pci memory\n");
  3957. il4965_dealloc_ucode_pci(il);
  3958. out_unbind:
  3959. complete(&il->_4965.firmware_loading_complete);
  3960. device_release_driver(&il->pci_dev->dev);
  3961. release_firmware(ucode_raw);
  3962. }
  3963. static const char *const desc_lookup_text[] = {
  3964. "OK",
  3965. "FAIL",
  3966. "BAD_PARAM",
  3967. "BAD_CHECKSUM",
  3968. "NMI_INTERRUPT_WDG",
  3969. "SYSASSERT",
  3970. "FATAL_ERROR",
  3971. "BAD_COMMAND",
  3972. "HW_ERROR_TUNE_LOCK",
  3973. "HW_ERROR_TEMPERATURE",
  3974. "ILLEGAL_CHAN_FREQ",
  3975. "VCC_NOT_STBL",
  3976. "FH49_ERROR",
  3977. "NMI_INTERRUPT_HOST",
  3978. "NMI_INTERRUPT_ACTION_PT",
  3979. "NMI_INTERRUPT_UNKNOWN",
  3980. "UCODE_VERSION_MISMATCH",
  3981. "HW_ERROR_ABS_LOCK",
  3982. "HW_ERROR_CAL_LOCK_FAIL",
  3983. "NMI_INTERRUPT_INST_ACTION_PT",
  3984. "NMI_INTERRUPT_DATA_ACTION_PT",
  3985. "NMI_TRM_HW_ER",
  3986. "NMI_INTERRUPT_TRM",
  3987. "NMI_INTERRUPT_BREAK_POINT",
  3988. "DEBUG_0",
  3989. "DEBUG_1",
  3990. "DEBUG_2",
  3991. "DEBUG_3",
  3992. };
  3993. static struct {
  3994. char *name;
  3995. u8 num;
  3996. } advanced_lookup[] = {
  3997. {
  3998. "NMI_INTERRUPT_WDG", 0x34}, {
  3999. "SYSASSERT", 0x35}, {
  4000. "UCODE_VERSION_MISMATCH", 0x37}, {
  4001. "BAD_COMMAND", 0x38}, {
  4002. "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C}, {
  4003. "FATAL_ERROR", 0x3D}, {
  4004. "NMI_TRM_HW_ERR", 0x46}, {
  4005. "NMI_INTERRUPT_TRM", 0x4C}, {
  4006. "NMI_INTERRUPT_BREAK_POINT", 0x54}, {
  4007. "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C}, {
  4008. "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64}, {
  4009. "NMI_INTERRUPT_HOST", 0x66}, {
  4010. "NMI_INTERRUPT_ACTION_PT", 0x7C}, {
  4011. "NMI_INTERRUPT_UNKNOWN", 0x84}, {
  4012. "NMI_INTERRUPT_INST_ACTION_PT", 0x86}, {
  4013. "ADVANCED_SYSASSERT", 0},};
  4014. static const char *
  4015. il4965_desc_lookup(u32 num)
  4016. {
  4017. int i;
  4018. int max = ARRAY_SIZE(desc_lookup_text);
  4019. if (num < max)
  4020. return desc_lookup_text[num];
  4021. max = ARRAY_SIZE(advanced_lookup) - 1;
  4022. for (i = 0; i < max; i++) {
  4023. if (advanced_lookup[i].num == num)
  4024. break;
  4025. }
  4026. return advanced_lookup[i].name;
  4027. }
  4028. #define ERROR_START_OFFSET (1 * sizeof(u32))
  4029. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  4030. void
  4031. il4965_dump_nic_error_log(struct il_priv *il)
  4032. {
  4033. u32 data2, line;
  4034. u32 desc, time, count, base, data1;
  4035. u32 blink1, blink2, ilink1, ilink2;
  4036. u32 pc, hcmd;
  4037. if (il->ucode_type == UCODE_INIT)
  4038. base = le32_to_cpu(il->card_alive_init.error_event_table_ptr);
  4039. else
  4040. base = le32_to_cpu(il->card_alive.error_event_table_ptr);
  4041. if (!il->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
  4042. IL_ERR("Not valid error log pointer 0x%08X for %s uCode\n",
  4043. base, (il->ucode_type == UCODE_INIT) ? "Init" : "RT");
  4044. return;
  4045. }
  4046. count = il_read_targ_mem(il, base);
  4047. if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
  4048. IL_ERR("Start IWL Error Log Dump:\n");
  4049. IL_ERR("Status: 0x%08lX, count: %d\n", il->status, count);
  4050. }
  4051. desc = il_read_targ_mem(il, base + 1 * sizeof(u32));
  4052. il->isr_stats.err_code = desc;
  4053. pc = il_read_targ_mem(il, base + 2 * sizeof(u32));
  4054. blink1 = il_read_targ_mem(il, base + 3 * sizeof(u32));
  4055. blink2 = il_read_targ_mem(il, base + 4 * sizeof(u32));
  4056. ilink1 = il_read_targ_mem(il, base + 5 * sizeof(u32));
  4057. ilink2 = il_read_targ_mem(il, base + 6 * sizeof(u32));
  4058. data1 = il_read_targ_mem(il, base + 7 * sizeof(u32));
  4059. data2 = il_read_targ_mem(il, base + 8 * sizeof(u32));
  4060. line = il_read_targ_mem(il, base + 9 * sizeof(u32));
  4061. time = il_read_targ_mem(il, base + 11 * sizeof(u32));
  4062. hcmd = il_read_targ_mem(il, base + 22 * sizeof(u32));
  4063. IL_ERR("Desc Time "
  4064. "data1 data2 line\n");
  4065. IL_ERR("%-28s (0x%04X) %010u 0x%08X 0x%08X %u\n",
  4066. il4965_desc_lookup(desc), desc, time, data1, data2, line);
  4067. IL_ERR("pc blink1 blink2 ilink1 ilink2 hcmd\n");
  4068. IL_ERR("0x%05X 0x%05X 0x%05X 0x%05X 0x%05X 0x%05X\n", pc, blink1,
  4069. blink2, ilink1, ilink2, hcmd);
  4070. }
  4071. static void
  4072. il4965_rf_kill_ct_config(struct il_priv *il)
  4073. {
  4074. struct il_ct_kill_config cmd;
  4075. unsigned long flags;
  4076. int ret = 0;
  4077. spin_lock_irqsave(&il->lock, flags);
  4078. _il_wr(il, CSR_UCODE_DRV_GP1_CLR,
  4079. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  4080. spin_unlock_irqrestore(&il->lock, flags);
  4081. cmd.critical_temperature_R =
  4082. cpu_to_le32(il->hw_params.ct_kill_threshold);
  4083. ret = il_send_cmd_pdu(il, C_CT_KILL_CONFIG, sizeof(cmd), &cmd);
  4084. if (ret)
  4085. IL_ERR("C_CT_KILL_CONFIG failed\n");
  4086. else
  4087. D_INFO("C_CT_KILL_CONFIG " "succeeded, "
  4088. "critical temperature is %d\n",
  4089. il->hw_params.ct_kill_threshold);
  4090. }
  4091. static const s8 default_queue_to_tx_fifo[] = {
  4092. IL_TX_FIFO_VO,
  4093. IL_TX_FIFO_VI,
  4094. IL_TX_FIFO_BE,
  4095. IL_TX_FIFO_BK,
  4096. IL49_CMD_FIFO_NUM,
  4097. IL_TX_FIFO_UNUSED,
  4098. IL_TX_FIFO_UNUSED,
  4099. };
  4100. #define IL_MASK(lo, hi) ((1 << (hi)) | ((1 << (hi)) - (1 << (lo))))
  4101. static int
  4102. il4965_alive_notify(struct il_priv *il)
  4103. {
  4104. u32 a;
  4105. unsigned long flags;
  4106. int i, chan;
  4107. u32 reg_val;
  4108. spin_lock_irqsave(&il->lock, flags);
  4109. /* Clear 4965's internal Tx Scheduler data base */
  4110. il->scd_base_addr = il_rd_prph(il, IL49_SCD_SRAM_BASE_ADDR);
  4111. a = il->scd_base_addr + IL49_SCD_CONTEXT_DATA_OFFSET;
  4112. for (; a < il->scd_base_addr + IL49_SCD_TX_STTS_BITMAP_OFFSET; a += 4)
  4113. il_write_targ_mem(il, a, 0);
  4114. for (; a < il->scd_base_addr + IL49_SCD_TRANSLATE_TBL_OFFSET; a += 4)
  4115. il_write_targ_mem(il, a, 0);
  4116. for (;
  4117. a <
  4118. il->scd_base_addr +
  4119. IL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(il->hw_params.max_txq_num);
  4120. a += 4)
  4121. il_write_targ_mem(il, a, 0);
  4122. /* Tel 4965 where to find Tx byte count tables */
  4123. il_wr_prph(il, IL49_SCD_DRAM_BASE_ADDR, il->scd_bc_tbls.dma >> 10);
  4124. /* Enable DMA channel */
  4125. for (chan = 0; chan < FH49_TCSR_CHNL_NUM; chan++)
  4126. il_wr(il, FH49_TCSR_CHNL_TX_CONFIG_REG(chan),
  4127. FH49_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  4128. FH49_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE);
  4129. /* Update FH chicken bits */
  4130. reg_val = il_rd(il, FH49_TX_CHICKEN_BITS_REG);
  4131. il_wr(il, FH49_TX_CHICKEN_BITS_REG,
  4132. reg_val | FH49_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN);
  4133. /* Disable chain mode for all queues */
  4134. il_wr_prph(il, IL49_SCD_QUEUECHAIN_SEL, 0);
  4135. /* Initialize each Tx queue (including the command queue) */
  4136. for (i = 0; i < il->hw_params.max_txq_num; i++) {
  4137. /* TFD circular buffer read/write idxes */
  4138. il_wr_prph(il, IL49_SCD_QUEUE_RDPTR(i), 0);
  4139. il_wr(il, HBUS_TARG_WRPTR, 0 | (i << 8));
  4140. /* Max Tx Window size for Scheduler-ACK mode */
  4141. il_write_targ_mem(il,
  4142. il->scd_base_addr +
  4143. IL49_SCD_CONTEXT_QUEUE_OFFSET(i),
  4144. (SCD_WIN_SIZE <<
  4145. IL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
  4146. IL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
  4147. /* Frame limit */
  4148. il_write_targ_mem(il,
  4149. il->scd_base_addr +
  4150. IL49_SCD_CONTEXT_QUEUE_OFFSET(i) +
  4151. sizeof(u32),
  4152. (SCD_FRAME_LIMIT <<
  4153. IL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
  4154. IL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
  4155. }
  4156. il_wr_prph(il, IL49_SCD_INTERRUPT_MASK,
  4157. (1 << il->hw_params.max_txq_num) - 1);
  4158. /* Activate all Tx DMA/FIFO channels */
  4159. il4965_txq_set_sched(il, IL_MASK(0, 6));
  4160. il4965_set_wr_ptrs(il, IL_DEFAULT_CMD_QUEUE_NUM, 0);
  4161. /* make sure all queue are not stopped */
  4162. memset(&il->queue_stopped[0], 0, sizeof(il->queue_stopped));
  4163. for (i = 0; i < 4; i++)
  4164. atomic_set(&il->queue_stop_count[i], 0);
  4165. /* reset to 0 to enable all the queue first */
  4166. il->txq_ctx_active_msk = 0;
  4167. /* Map each Tx/cmd queue to its corresponding fifo */
  4168. BUILD_BUG_ON(ARRAY_SIZE(default_queue_to_tx_fifo) != 7);
  4169. for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) {
  4170. int ac = default_queue_to_tx_fifo[i];
  4171. il_txq_ctx_activate(il, i);
  4172. if (ac == IL_TX_FIFO_UNUSED)
  4173. continue;
  4174. il4965_tx_queue_set_status(il, &il->txq[i], ac, 0);
  4175. }
  4176. spin_unlock_irqrestore(&il->lock, flags);
  4177. return 0;
  4178. }
  4179. /**
  4180. * il4965_alive_start - called after N_ALIVE notification received
  4181. * from protocol/runtime uCode (initialization uCode's
  4182. * Alive gets handled by il_init_alive_start()).
  4183. */
  4184. static void
  4185. il4965_alive_start(struct il_priv *il)
  4186. {
  4187. int ret = 0;
  4188. struct il_rxon_context *ctx = &il->ctx;
  4189. D_INFO("Runtime Alive received.\n");
  4190. if (il->card_alive.is_valid != UCODE_VALID_OK) {
  4191. /* We had an error bringing up the hardware, so take it
  4192. * all the way back down so we can try again */
  4193. D_INFO("Alive failed.\n");
  4194. goto restart;
  4195. }
  4196. /* Initialize uCode has loaded Runtime uCode ... verify inst image.
  4197. * This is a paranoid check, because we would not have gotten the
  4198. * "runtime" alive if code weren't properly loaded. */
  4199. if (il4965_verify_ucode(il)) {
  4200. /* Runtime instruction load was bad;
  4201. * take it all the way back down so we can try again */
  4202. D_INFO("Bad runtime uCode load.\n");
  4203. goto restart;
  4204. }
  4205. ret = il4965_alive_notify(il);
  4206. if (ret) {
  4207. IL_WARN("Could not complete ALIVE transition [ntf]: %d\n", ret);
  4208. goto restart;
  4209. }
  4210. /* After the ALIVE response, we can send host commands to the uCode */
  4211. set_bit(S_ALIVE, &il->status);
  4212. /* Enable watchdog to monitor the driver tx queues */
  4213. il_setup_watchdog(il);
  4214. if (il_is_rfkill(il))
  4215. return;
  4216. ieee80211_wake_queues(il->hw);
  4217. il->active_rate = RATES_MASK;
  4218. if (il_is_associated_ctx(ctx)) {
  4219. struct il_rxon_cmd *active_rxon =
  4220. (struct il_rxon_cmd *)&ctx->active;
  4221. /* apply any changes in staging */
  4222. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  4223. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  4224. } else {
  4225. /* Initialize our rx_config data */
  4226. il_connection_init_rx_config(il, &il->ctx);
  4227. if (il->cfg->ops->hcmd->set_rxon_chain)
  4228. il->cfg->ops->hcmd->set_rxon_chain(il, ctx);
  4229. }
  4230. /* Configure bluetooth coexistence if enabled */
  4231. il_send_bt_config(il);
  4232. il4965_reset_run_time_calib(il);
  4233. set_bit(S_READY, &il->status);
  4234. /* Configure the adapter for unassociated operation */
  4235. il_commit_rxon(il, ctx);
  4236. /* At this point, the NIC is initialized and operational */
  4237. il4965_rf_kill_ct_config(il);
  4238. D_INFO("ALIVE processing complete.\n");
  4239. wake_up(&il->wait_command_queue);
  4240. il_power_update_mode(il, true);
  4241. D_INFO("Updated power mode\n");
  4242. return;
  4243. restart:
  4244. queue_work(il->workqueue, &il->restart);
  4245. }
  4246. static void il4965_cancel_deferred_work(struct il_priv *il);
  4247. static void
  4248. __il4965_down(struct il_priv *il)
  4249. {
  4250. unsigned long flags;
  4251. int exit_pending;
  4252. D_INFO(DRV_NAME " is going down\n");
  4253. il_scan_cancel_timeout(il, 200);
  4254. exit_pending = test_and_set_bit(S_EXIT_PENDING, &il->status);
  4255. /* Stop TX queues watchdog. We need to have S_EXIT_PENDING bit set
  4256. * to prevent rearm timer */
  4257. del_timer_sync(&il->watchdog);
  4258. il_clear_ucode_stations(il, NULL);
  4259. il_dealloc_bcast_stations(il);
  4260. il_clear_driver_stations(il);
  4261. /* Unblock any waiting calls */
  4262. wake_up_all(&il->wait_command_queue);
  4263. /* Wipe out the EXIT_PENDING status bit if we are not actually
  4264. * exiting the module */
  4265. if (!exit_pending)
  4266. clear_bit(S_EXIT_PENDING, &il->status);
  4267. /* stop and reset the on-board processor */
  4268. _il_wr(il, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  4269. /* tell the device to stop sending interrupts */
  4270. spin_lock_irqsave(&il->lock, flags);
  4271. il_disable_interrupts(il);
  4272. spin_unlock_irqrestore(&il->lock, flags);
  4273. il4965_synchronize_irq(il);
  4274. if (il->mac80211_registered)
  4275. ieee80211_stop_queues(il->hw);
  4276. /* If we have not previously called il_init() then
  4277. * clear all bits but the RF Kill bit and return */
  4278. if (!il_is_init(il)) {
  4279. il->status =
  4280. test_bit(S_RF_KILL_HW,
  4281. &il->
  4282. status) << S_RF_KILL_HW |
  4283. test_bit(S_GEO_CONFIGURED,
  4284. &il->
  4285. status) << S_GEO_CONFIGURED |
  4286. test_bit(S_EXIT_PENDING, &il->status) << S_EXIT_PENDING;
  4287. goto exit;
  4288. }
  4289. /* ...otherwise clear out all the status bits but the RF Kill
  4290. * bit and continue taking the NIC down. */
  4291. il->status &=
  4292. test_bit(S_RF_KILL_HW,
  4293. &il->status) << S_RF_KILL_HW | test_bit(S_GEO_CONFIGURED,
  4294. &il->
  4295. status) <<
  4296. S_GEO_CONFIGURED | test_bit(S_FW_ERROR,
  4297. &il->
  4298. status) << S_FW_ERROR |
  4299. test_bit(S_EXIT_PENDING, &il->status) << S_EXIT_PENDING;
  4300. il4965_txq_ctx_stop(il);
  4301. il4965_rxq_stop(il);
  4302. /* Power-down device's busmaster DMA clocks */
  4303. il_wr_prph(il, APMG_CLK_DIS_REG, APMG_CLK_VAL_DMA_CLK_RQT);
  4304. udelay(5);
  4305. /* Make sure (redundant) we've released our request to stay awake */
  4306. il_clear_bit(il, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  4307. /* Stop the device, and put it in low power state */
  4308. il_apm_stop(il);
  4309. exit:
  4310. memset(&il->card_alive, 0, sizeof(struct il_alive_resp));
  4311. dev_kfree_skb(il->beacon_skb);
  4312. il->beacon_skb = NULL;
  4313. /* clear out any free frames */
  4314. il4965_clear_free_frames(il);
  4315. }
  4316. static void
  4317. il4965_down(struct il_priv *il)
  4318. {
  4319. mutex_lock(&il->mutex);
  4320. __il4965_down(il);
  4321. mutex_unlock(&il->mutex);
  4322. il4965_cancel_deferred_work(il);
  4323. }
  4324. #define HW_READY_TIMEOUT (50)
  4325. static int
  4326. il4965_set_hw_ready(struct il_priv *il)
  4327. {
  4328. int ret = 0;
  4329. il_set_bit(il, CSR_HW_IF_CONFIG_REG,
  4330. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY);
  4331. /* See if we got it */
  4332. ret =
  4333. _il_poll_bit(il, CSR_HW_IF_CONFIG_REG,
  4334. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
  4335. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY, HW_READY_TIMEOUT);
  4336. if (ret != -ETIMEDOUT)
  4337. il->hw_ready = true;
  4338. else
  4339. il->hw_ready = false;
  4340. D_INFO("hardware %s\n", (il->hw_ready == 1) ? "ready" : "not ready");
  4341. return ret;
  4342. }
  4343. static int
  4344. il4965_prepare_card_hw(struct il_priv *il)
  4345. {
  4346. int ret = 0;
  4347. D_INFO("il4965_prepare_card_hw enter\n");
  4348. ret = il4965_set_hw_ready(il);
  4349. if (il->hw_ready)
  4350. return ret;
  4351. /* If HW is not ready, prepare the conditions to check again */
  4352. il_set_bit(il, CSR_HW_IF_CONFIG_REG, CSR_HW_IF_CONFIG_REG_PREPARE);
  4353. ret =
  4354. _il_poll_bit(il, CSR_HW_IF_CONFIG_REG,
  4355. ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE,
  4356. CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000);
  4357. /* HW should be ready by now, check again. */
  4358. if (ret != -ETIMEDOUT)
  4359. il4965_set_hw_ready(il);
  4360. return ret;
  4361. }
  4362. #define MAX_HW_RESTARTS 5
  4363. static int
  4364. __il4965_up(struct il_priv *il)
  4365. {
  4366. int i;
  4367. int ret;
  4368. if (test_bit(S_EXIT_PENDING, &il->status)) {
  4369. IL_WARN("Exit pending; will not bring the NIC up\n");
  4370. return -EIO;
  4371. }
  4372. if (!il->ucode_data_backup.v_addr || !il->ucode_data.v_addr) {
  4373. IL_ERR("ucode not available for device bringup\n");
  4374. return -EIO;
  4375. }
  4376. ret = il4965_alloc_bcast_station(il, &il->ctx);
  4377. if (ret) {
  4378. il_dealloc_bcast_stations(il);
  4379. return ret;
  4380. }
  4381. il4965_prepare_card_hw(il);
  4382. if (!il->hw_ready) {
  4383. IL_WARN("Exit HW not ready\n");
  4384. return -EIO;
  4385. }
  4386. /* If platform's RF_KILL switch is NOT set to KILL */
  4387. if (_il_rd(il, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  4388. clear_bit(S_RF_KILL_HW, &il->status);
  4389. else
  4390. set_bit(S_RF_KILL_HW, &il->status);
  4391. if (il_is_rfkill(il)) {
  4392. wiphy_rfkill_set_hw_state(il->hw->wiphy, true);
  4393. il_enable_interrupts(il);
  4394. IL_WARN("Radio disabled by HW RF Kill switch\n");
  4395. return 0;
  4396. }
  4397. _il_wr(il, CSR_INT, 0xFFFFFFFF);
  4398. /* must be initialised before il_hw_nic_init */
  4399. il->cmd_queue = IL_DEFAULT_CMD_QUEUE_NUM;
  4400. ret = il4965_hw_nic_init(il);
  4401. if (ret) {
  4402. IL_ERR("Unable to init nic\n");
  4403. return ret;
  4404. }
  4405. /* make sure rfkill handshake bits are cleared */
  4406. _il_wr(il, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  4407. _il_wr(il, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  4408. /* clear (again), then enable host interrupts */
  4409. _il_wr(il, CSR_INT, 0xFFFFFFFF);
  4410. il_enable_interrupts(il);
  4411. /* really make sure rfkill handshake bits are cleared */
  4412. _il_wr(il, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  4413. _il_wr(il, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  4414. /* Copy original ucode data image from disk into backup cache.
  4415. * This will be used to initialize the on-board processor's
  4416. * data SRAM for a clean start when the runtime program first loads. */
  4417. memcpy(il->ucode_data_backup.v_addr, il->ucode_data.v_addr,
  4418. il->ucode_data.len);
  4419. for (i = 0; i < MAX_HW_RESTARTS; i++) {
  4420. /* load bootstrap state machine,
  4421. * load bootstrap program into processor's memory,
  4422. * prepare to load the "initialize" uCode */
  4423. ret = il->cfg->ops->lib->load_ucode(il);
  4424. if (ret) {
  4425. IL_ERR("Unable to set up bootstrap uCode: %d\n", ret);
  4426. continue;
  4427. }
  4428. /* start card; "initialize" will load runtime ucode */
  4429. il4965_nic_start(il);
  4430. D_INFO(DRV_NAME " is coming up\n");
  4431. return 0;
  4432. }
  4433. set_bit(S_EXIT_PENDING, &il->status);
  4434. __il4965_down(il);
  4435. clear_bit(S_EXIT_PENDING, &il->status);
  4436. /* tried to restart and config the device for as long as our
  4437. * patience could withstand */
  4438. IL_ERR("Unable to initialize device after %d attempts.\n", i);
  4439. return -EIO;
  4440. }
  4441. /*****************************************************************************
  4442. *
  4443. * Workqueue callbacks
  4444. *
  4445. *****************************************************************************/
  4446. static void
  4447. il4965_bg_init_alive_start(struct work_struct *data)
  4448. {
  4449. struct il_priv *il =
  4450. container_of(data, struct il_priv, init_alive_start.work);
  4451. mutex_lock(&il->mutex);
  4452. if (test_bit(S_EXIT_PENDING, &il->status))
  4453. goto out;
  4454. il->cfg->ops->lib->init_alive_start(il);
  4455. out:
  4456. mutex_unlock(&il->mutex);
  4457. }
  4458. static void
  4459. il4965_bg_alive_start(struct work_struct *data)
  4460. {
  4461. struct il_priv *il =
  4462. container_of(data, struct il_priv, alive_start.work);
  4463. mutex_lock(&il->mutex);
  4464. if (test_bit(S_EXIT_PENDING, &il->status))
  4465. goto out;
  4466. il4965_alive_start(il);
  4467. out:
  4468. mutex_unlock(&il->mutex);
  4469. }
  4470. static void
  4471. il4965_bg_run_time_calib_work(struct work_struct *work)
  4472. {
  4473. struct il_priv *il = container_of(work, struct il_priv,
  4474. run_time_calib_work);
  4475. mutex_lock(&il->mutex);
  4476. if (test_bit(S_EXIT_PENDING, &il->status) ||
  4477. test_bit(S_SCANNING, &il->status)) {
  4478. mutex_unlock(&il->mutex);
  4479. return;
  4480. }
  4481. if (il->start_calib) {
  4482. il4965_chain_noise_calibration(il, (void *)&il->_4965.stats);
  4483. il4965_sensitivity_calibration(il, (void *)&il->_4965.stats);
  4484. }
  4485. mutex_unlock(&il->mutex);
  4486. }
  4487. static void
  4488. il4965_bg_restart(struct work_struct *data)
  4489. {
  4490. struct il_priv *il = container_of(data, struct il_priv, restart);
  4491. if (test_bit(S_EXIT_PENDING, &il->status))
  4492. return;
  4493. if (test_and_clear_bit(S_FW_ERROR, &il->status)) {
  4494. mutex_lock(&il->mutex);
  4495. il->ctx.vif = NULL;
  4496. il->is_open = 0;
  4497. __il4965_down(il);
  4498. mutex_unlock(&il->mutex);
  4499. il4965_cancel_deferred_work(il);
  4500. ieee80211_restart_hw(il->hw);
  4501. } else {
  4502. il4965_down(il);
  4503. mutex_lock(&il->mutex);
  4504. if (test_bit(S_EXIT_PENDING, &il->status)) {
  4505. mutex_unlock(&il->mutex);
  4506. return;
  4507. }
  4508. __il4965_up(il);
  4509. mutex_unlock(&il->mutex);
  4510. }
  4511. }
  4512. static void
  4513. il4965_bg_rx_replenish(struct work_struct *data)
  4514. {
  4515. struct il_priv *il = container_of(data, struct il_priv, rx_replenish);
  4516. if (test_bit(S_EXIT_PENDING, &il->status))
  4517. return;
  4518. mutex_lock(&il->mutex);
  4519. il4965_rx_replenish(il);
  4520. mutex_unlock(&il->mutex);
  4521. }
  4522. /*****************************************************************************
  4523. *
  4524. * mac80211 entry point functions
  4525. *
  4526. *****************************************************************************/
  4527. #define UCODE_READY_TIMEOUT (4 * HZ)
  4528. /*
  4529. * Not a mac80211 entry point function, but it fits in with all the
  4530. * other mac80211 functions grouped here.
  4531. */
  4532. static int
  4533. il4965_mac_setup_register(struct il_priv *il, u32 max_probe_length)
  4534. {
  4535. int ret;
  4536. struct ieee80211_hw *hw = il->hw;
  4537. hw->rate_control_algorithm = "iwl-4965-rs";
  4538. /* Tell mac80211 our characteristics */
  4539. hw->flags =
  4540. IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_AMPDU_AGGREGATION |
  4541. IEEE80211_HW_NEED_DTIM_PERIOD | IEEE80211_HW_SPECTRUM_MGMT |
  4542. IEEE80211_HW_REPORTS_TX_ACK_STATUS;
  4543. if (il->cfg->sku & IL_SKU_N)
  4544. hw->flags |=
  4545. IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
  4546. IEEE80211_HW_SUPPORTS_STATIC_SMPS;
  4547. hw->sta_data_size = sizeof(struct il_station_priv);
  4548. hw->vif_data_size = sizeof(struct il_vif_priv);
  4549. hw->wiphy->interface_modes |= il->ctx.interface_modes;
  4550. hw->wiphy->interface_modes |= il->ctx.exclusive_interface_modes;
  4551. hw->wiphy->flags |=
  4552. WIPHY_FLAG_CUSTOM_REGULATORY | WIPHY_FLAG_DISABLE_BEACON_HINTS;
  4553. /*
  4554. * For now, disable PS by default because it affects
  4555. * RX performance significantly.
  4556. */
  4557. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  4558. hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
  4559. /* we create the 802.11 header and a zero-length SSID element */
  4560. hw->wiphy->max_scan_ie_len = max_probe_length - 24 - 2;
  4561. /* Default value; 4 EDCA QOS priorities */
  4562. hw->queues = 4;
  4563. hw->max_listen_interval = IL_CONN_MAX_LISTEN_INTERVAL;
  4564. if (il->bands[IEEE80211_BAND_2GHZ].n_channels)
  4565. il->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  4566. &il->bands[IEEE80211_BAND_2GHZ];
  4567. if (il->bands[IEEE80211_BAND_5GHZ].n_channels)
  4568. il->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  4569. &il->bands[IEEE80211_BAND_5GHZ];
  4570. il_leds_init(il);
  4571. ret = ieee80211_register_hw(il->hw);
  4572. if (ret) {
  4573. IL_ERR("Failed to register hw (error %d)\n", ret);
  4574. return ret;
  4575. }
  4576. il->mac80211_registered = 1;
  4577. return 0;
  4578. }
  4579. int
  4580. il4965_mac_start(struct ieee80211_hw *hw)
  4581. {
  4582. struct il_priv *il = hw->priv;
  4583. int ret;
  4584. D_MAC80211("enter\n");
  4585. /* we should be verifying the device is ready to be opened */
  4586. mutex_lock(&il->mutex);
  4587. ret = __il4965_up(il);
  4588. mutex_unlock(&il->mutex);
  4589. if (ret)
  4590. return ret;
  4591. if (il_is_rfkill(il))
  4592. goto out;
  4593. D_INFO("Start UP work done.\n");
  4594. /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
  4595. * mac80211 will not be run successfully. */
  4596. ret = wait_event_timeout(il->wait_command_queue,
  4597. test_bit(S_READY, &il->status),
  4598. UCODE_READY_TIMEOUT);
  4599. if (!ret) {
  4600. if (!test_bit(S_READY, &il->status)) {
  4601. IL_ERR("START_ALIVE timeout after %dms.\n",
  4602. jiffies_to_msecs(UCODE_READY_TIMEOUT));
  4603. return -ETIMEDOUT;
  4604. }
  4605. }
  4606. il4965_led_enable(il);
  4607. out:
  4608. il->is_open = 1;
  4609. D_MAC80211("leave\n");
  4610. return 0;
  4611. }
  4612. void
  4613. il4965_mac_stop(struct ieee80211_hw *hw)
  4614. {
  4615. struct il_priv *il = hw->priv;
  4616. D_MAC80211("enter\n");
  4617. if (!il->is_open)
  4618. return;
  4619. il->is_open = 0;
  4620. il4965_down(il);
  4621. flush_workqueue(il->workqueue);
  4622. /* User space software may expect getting rfkill changes
  4623. * even if interface is down */
  4624. _il_wr(il, CSR_INT, 0xFFFFFFFF);
  4625. il_enable_rfkill_int(il);
  4626. D_MAC80211("leave\n");
  4627. }
  4628. void
  4629. il4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  4630. {
  4631. struct il_priv *il = hw->priv;
  4632. D_MACDUMP("enter\n");
  4633. D_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  4634. ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
  4635. if (il4965_tx_skb(il, skb))
  4636. dev_kfree_skb_any(skb);
  4637. D_MACDUMP("leave\n");
  4638. }
  4639. void
  4640. il4965_mac_update_tkip_key(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  4641. struct ieee80211_key_conf *keyconf,
  4642. struct ieee80211_sta *sta, u32 iv32, u16 * phase1key)
  4643. {
  4644. struct il_priv *il = hw->priv;
  4645. struct il_vif_priv *vif_priv = (void *)vif->drv_priv;
  4646. D_MAC80211("enter\n");
  4647. il4965_update_tkip_key(il, vif_priv->ctx, keyconf, sta, iv32,
  4648. phase1key);
  4649. D_MAC80211("leave\n");
  4650. }
  4651. int
  4652. il4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  4653. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  4654. struct ieee80211_key_conf *key)
  4655. {
  4656. struct il_priv *il = hw->priv;
  4657. struct il_vif_priv *vif_priv = (void *)vif->drv_priv;
  4658. struct il_rxon_context *ctx = vif_priv->ctx;
  4659. int ret;
  4660. u8 sta_id;
  4661. bool is_default_wep_key = false;
  4662. D_MAC80211("enter\n");
  4663. if (il->cfg->mod_params->sw_crypto) {
  4664. D_MAC80211("leave - hwcrypto disabled\n");
  4665. return -EOPNOTSUPP;
  4666. }
  4667. sta_id = il_sta_id_or_broadcast(il, vif_priv->ctx, sta);
  4668. if (sta_id == IL_INVALID_STATION)
  4669. return -EINVAL;
  4670. mutex_lock(&il->mutex);
  4671. il_scan_cancel_timeout(il, 100);
  4672. /*
  4673. * If we are getting WEP group key and we didn't receive any key mapping
  4674. * so far, we are in legacy wep mode (group key only), otherwise we are
  4675. * in 1X mode.
  4676. * In legacy wep mode, we use another host command to the uCode.
  4677. */
  4678. if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  4679. key->cipher == WLAN_CIPHER_SUITE_WEP104) && !sta) {
  4680. if (cmd == SET_KEY)
  4681. is_default_wep_key = !ctx->key_mapping_keys;
  4682. else
  4683. is_default_wep_key =
  4684. (key->hw_key_idx == HW_KEY_DEFAULT);
  4685. }
  4686. switch (cmd) {
  4687. case SET_KEY:
  4688. if (is_default_wep_key)
  4689. ret =
  4690. il4965_set_default_wep_key(il, vif_priv->ctx, key);
  4691. else
  4692. ret =
  4693. il4965_set_dynamic_key(il, vif_priv->ctx, key,
  4694. sta_id);
  4695. D_MAC80211("enable hwcrypto key\n");
  4696. break;
  4697. case DISABLE_KEY:
  4698. if (is_default_wep_key)
  4699. ret = il4965_remove_default_wep_key(il, ctx, key);
  4700. else
  4701. ret = il4965_remove_dynamic_key(il, ctx, key, sta_id);
  4702. D_MAC80211("disable hwcrypto key\n");
  4703. break;
  4704. default:
  4705. ret = -EINVAL;
  4706. }
  4707. mutex_unlock(&il->mutex);
  4708. D_MAC80211("leave\n");
  4709. return ret;
  4710. }
  4711. int
  4712. il4965_mac_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  4713. enum ieee80211_ampdu_mlme_action action,
  4714. struct ieee80211_sta *sta, u16 tid, u16 * ssn,
  4715. u8 buf_size)
  4716. {
  4717. struct il_priv *il = hw->priv;
  4718. int ret = -EINVAL;
  4719. D_HT("A-MPDU action on addr %pM tid %d\n", sta->addr, tid);
  4720. if (!(il->cfg->sku & IL_SKU_N))
  4721. return -EACCES;
  4722. mutex_lock(&il->mutex);
  4723. switch (action) {
  4724. case IEEE80211_AMPDU_RX_START:
  4725. D_HT("start Rx\n");
  4726. ret = il4965_sta_rx_agg_start(il, sta, tid, *ssn);
  4727. break;
  4728. case IEEE80211_AMPDU_RX_STOP:
  4729. D_HT("stop Rx\n");
  4730. ret = il4965_sta_rx_agg_stop(il, sta, tid);
  4731. if (test_bit(S_EXIT_PENDING, &il->status))
  4732. ret = 0;
  4733. break;
  4734. case IEEE80211_AMPDU_TX_START:
  4735. D_HT("start Tx\n");
  4736. ret = il4965_tx_agg_start(il, vif, sta, tid, ssn);
  4737. break;
  4738. case IEEE80211_AMPDU_TX_STOP:
  4739. D_HT("stop Tx\n");
  4740. ret = il4965_tx_agg_stop(il, vif, sta, tid);
  4741. if (test_bit(S_EXIT_PENDING, &il->status))
  4742. ret = 0;
  4743. break;
  4744. case IEEE80211_AMPDU_TX_OPERATIONAL:
  4745. ret = 0;
  4746. break;
  4747. }
  4748. mutex_unlock(&il->mutex);
  4749. return ret;
  4750. }
  4751. int
  4752. il4965_mac_sta_add(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  4753. struct ieee80211_sta *sta)
  4754. {
  4755. struct il_priv *il = hw->priv;
  4756. struct il_station_priv *sta_priv = (void *)sta->drv_priv;
  4757. struct il_vif_priv *vif_priv = (void *)vif->drv_priv;
  4758. bool is_ap = vif->type == NL80211_IFTYPE_STATION;
  4759. int ret;
  4760. u8 sta_id;
  4761. D_INFO("received request to add station %pM\n", sta->addr);
  4762. mutex_lock(&il->mutex);
  4763. D_INFO("proceeding to add station %pM\n", sta->addr);
  4764. sta_priv->common.sta_id = IL_INVALID_STATION;
  4765. atomic_set(&sta_priv->pending_frames, 0);
  4766. ret =
  4767. il_add_station_common(il, vif_priv->ctx, sta->addr, is_ap, sta,
  4768. &sta_id);
  4769. if (ret) {
  4770. IL_ERR("Unable to add station %pM (%d)\n", sta->addr, ret);
  4771. /* Should we return success if return code is EEXIST ? */
  4772. mutex_unlock(&il->mutex);
  4773. return ret;
  4774. }
  4775. sta_priv->common.sta_id = sta_id;
  4776. /* Initialize rate scaling */
  4777. D_INFO("Initializing rate scaling for station %pM\n", sta->addr);
  4778. il4965_rs_rate_init(il, sta, sta_id);
  4779. mutex_unlock(&il->mutex);
  4780. return 0;
  4781. }
  4782. void
  4783. il4965_mac_channel_switch(struct ieee80211_hw *hw,
  4784. struct ieee80211_channel_switch *ch_switch)
  4785. {
  4786. struct il_priv *il = hw->priv;
  4787. const struct il_channel_info *ch_info;
  4788. struct ieee80211_conf *conf = &hw->conf;
  4789. struct ieee80211_channel *channel = ch_switch->channel;
  4790. struct il_ht_config *ht_conf = &il->current_ht_config;
  4791. struct il_rxon_context *ctx = &il->ctx;
  4792. u16 ch;
  4793. D_MAC80211("enter\n");
  4794. mutex_lock(&il->mutex);
  4795. if (il_is_rfkill(il))
  4796. goto out;
  4797. if (test_bit(S_EXIT_PENDING, &il->status) ||
  4798. test_bit(S_SCANNING, &il->status) ||
  4799. test_bit(S_CHANNEL_SWITCH_PENDING, &il->status))
  4800. goto out;
  4801. if (!il_is_associated_ctx(ctx))
  4802. goto out;
  4803. if (!il->cfg->ops->lib->set_channel_switch)
  4804. goto out;
  4805. ch = channel->hw_value;
  4806. if (le16_to_cpu(ctx->active.channel) == ch)
  4807. goto out;
  4808. ch_info = il_get_channel_info(il, channel->band, ch);
  4809. if (!il_is_channel_valid(ch_info)) {
  4810. D_MAC80211("invalid channel\n");
  4811. goto out;
  4812. }
  4813. spin_lock_irq(&il->lock);
  4814. il->current_ht_config.smps = conf->smps_mode;
  4815. /* Configure HT40 channels */
  4816. ctx->ht.enabled = conf_is_ht(conf);
  4817. if (ctx->ht.enabled) {
  4818. if (conf_is_ht40_minus(conf)) {
  4819. ctx->ht.extension_chan_offset =
  4820. IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  4821. ctx->ht.is_40mhz = true;
  4822. } else if (conf_is_ht40_plus(conf)) {
  4823. ctx->ht.extension_chan_offset =
  4824. IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  4825. ctx->ht.is_40mhz = true;
  4826. } else {
  4827. ctx->ht.extension_chan_offset =
  4828. IEEE80211_HT_PARAM_CHA_SEC_NONE;
  4829. ctx->ht.is_40mhz = false;
  4830. }
  4831. } else
  4832. ctx->ht.is_40mhz = false;
  4833. if ((le16_to_cpu(ctx->staging.channel) != ch))
  4834. ctx->staging.flags = 0;
  4835. il_set_rxon_channel(il, channel, ctx);
  4836. il_set_rxon_ht(il, ht_conf);
  4837. il_set_flags_for_band(il, ctx, channel->band, ctx->vif);
  4838. spin_unlock_irq(&il->lock);
  4839. il_set_rate(il);
  4840. /*
  4841. * at this point, staging_rxon has the
  4842. * configuration for channel switch
  4843. */
  4844. set_bit(S_CHANNEL_SWITCH_PENDING, &il->status);
  4845. il->switch_channel = cpu_to_le16(ch);
  4846. if (il->cfg->ops->lib->set_channel_switch(il, ch_switch)) {
  4847. clear_bit(S_CHANNEL_SWITCH_PENDING, &il->status);
  4848. il->switch_channel = 0;
  4849. ieee80211_chswitch_done(ctx->vif, false);
  4850. }
  4851. out:
  4852. mutex_unlock(&il->mutex);
  4853. D_MAC80211("leave\n");
  4854. }
  4855. void
  4856. il4965_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
  4857. unsigned int *total_flags, u64 multicast)
  4858. {
  4859. struct il_priv *il = hw->priv;
  4860. __le32 filter_or = 0, filter_nand = 0;
  4861. #define CHK(test, flag) do { \
  4862. if (*total_flags & (test)) \
  4863. filter_or |= (flag); \
  4864. else \
  4865. filter_nand |= (flag); \
  4866. } while (0)
  4867. D_MAC80211("Enter: changed: 0x%x, total: 0x%x\n", changed_flags,
  4868. *total_flags);
  4869. CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
  4870. /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */
  4871. CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK);
  4872. CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
  4873. #undef CHK
  4874. mutex_lock(&il->mutex);
  4875. il->ctx.staging.filter_flags &= ~filter_nand;
  4876. il->ctx.staging.filter_flags |= filter_or;
  4877. /*
  4878. * Not committing directly because hardware can perform a scan,
  4879. * but we'll eventually commit the filter flags change anyway.
  4880. */
  4881. mutex_unlock(&il->mutex);
  4882. /*
  4883. * Receiving all multicast frames is always enabled by the
  4884. * default flags setup in il_connection_init_rx_config()
  4885. * since we currently do not support programming multicast
  4886. * filters into the device.
  4887. */
  4888. *total_flags &=
  4889. FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
  4890. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
  4891. }
  4892. /*****************************************************************************
  4893. *
  4894. * driver setup and teardown
  4895. *
  4896. *****************************************************************************/
  4897. static void
  4898. il4965_bg_txpower_work(struct work_struct *work)
  4899. {
  4900. struct il_priv *il = container_of(work, struct il_priv,
  4901. txpower_work);
  4902. mutex_lock(&il->mutex);
  4903. /* If a scan happened to start before we got here
  4904. * then just return; the stats notification will
  4905. * kick off another scheduled work to compensate for
  4906. * any temperature delta we missed here. */
  4907. if (test_bit(S_EXIT_PENDING, &il->status) ||
  4908. test_bit(S_SCANNING, &il->status))
  4909. goto out;
  4910. /* Regardless of if we are associated, we must reconfigure the
  4911. * TX power since frames can be sent on non-radar channels while
  4912. * not associated */
  4913. il->cfg->ops->lib->send_tx_power(il);
  4914. /* Update last_temperature to keep is_calib_needed from running
  4915. * when it isn't needed... */
  4916. il->last_temperature = il->temperature;
  4917. out:
  4918. mutex_unlock(&il->mutex);
  4919. }
  4920. static void
  4921. il4965_setup_deferred_work(struct il_priv *il)
  4922. {
  4923. il->workqueue = create_singlethread_workqueue(DRV_NAME);
  4924. init_waitqueue_head(&il->wait_command_queue);
  4925. INIT_WORK(&il->restart, il4965_bg_restart);
  4926. INIT_WORK(&il->rx_replenish, il4965_bg_rx_replenish);
  4927. INIT_WORK(&il->run_time_calib_work, il4965_bg_run_time_calib_work);
  4928. INIT_DELAYED_WORK(&il->init_alive_start, il4965_bg_init_alive_start);
  4929. INIT_DELAYED_WORK(&il->alive_start, il4965_bg_alive_start);
  4930. il_setup_scan_deferred_work(il);
  4931. INIT_WORK(&il->txpower_work, il4965_bg_txpower_work);
  4932. init_timer(&il->stats_periodic);
  4933. il->stats_periodic.data = (unsigned long)il;
  4934. il->stats_periodic.function = il4965_bg_stats_periodic;
  4935. init_timer(&il->watchdog);
  4936. il->watchdog.data = (unsigned long)il;
  4937. il->watchdog.function = il_bg_watchdog;
  4938. tasklet_init(&il->irq_tasklet,
  4939. (void (*)(unsigned long))il4965_irq_tasklet,
  4940. (unsigned long)il);
  4941. }
  4942. static void
  4943. il4965_cancel_deferred_work(struct il_priv *il)
  4944. {
  4945. cancel_work_sync(&il->txpower_work);
  4946. cancel_delayed_work_sync(&il->init_alive_start);
  4947. cancel_delayed_work(&il->alive_start);
  4948. cancel_work_sync(&il->run_time_calib_work);
  4949. il_cancel_scan_deferred_work(il);
  4950. del_timer_sync(&il->stats_periodic);
  4951. }
  4952. static void
  4953. il4965_init_hw_rates(struct il_priv *il, struct ieee80211_rate *rates)
  4954. {
  4955. int i;
  4956. for (i = 0; i < RATE_COUNT_LEGACY; i++) {
  4957. rates[i].bitrate = il_rates[i].ieee * 5;
  4958. rates[i].hw_value = i; /* Rate scaling will work on idxes */
  4959. rates[i].hw_value_short = i;
  4960. rates[i].flags = 0;
  4961. if ((i >= IL_FIRST_CCK_RATE) && (i <= IL_LAST_CCK_RATE)) {
  4962. /*
  4963. * If CCK != 1M then set short preamble rate flag.
  4964. */
  4965. rates[i].flags |=
  4966. (il_rates[i].plcp ==
  4967. RATE_1M_PLCP) ? 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  4968. }
  4969. }
  4970. }
  4971. /*
  4972. * Acquire il->lock before calling this function !
  4973. */
  4974. void
  4975. il4965_set_wr_ptrs(struct il_priv *il, int txq_id, u32 idx)
  4976. {
  4977. il_wr(il, HBUS_TARG_WRPTR, (idx & 0xff) | (txq_id << 8));
  4978. il_wr_prph(il, IL49_SCD_QUEUE_RDPTR(txq_id), idx);
  4979. }
  4980. void
  4981. il4965_tx_queue_set_status(struct il_priv *il, struct il_tx_queue *txq,
  4982. int tx_fifo_id, int scd_retry)
  4983. {
  4984. int txq_id = txq->q.id;
  4985. /* Find out whether to activate Tx queue */
  4986. int active = test_bit(txq_id, &il->txq_ctx_active_msk) ? 1 : 0;
  4987. /* Set up and activate */
  4988. il_wr_prph(il, IL49_SCD_QUEUE_STATUS_BITS(txq_id),
  4989. (active << IL49_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
  4990. (tx_fifo_id << IL49_SCD_QUEUE_STTS_REG_POS_TXF) |
  4991. (scd_retry << IL49_SCD_QUEUE_STTS_REG_POS_WSL) |
  4992. (scd_retry << IL49_SCD_QUEUE_STTS_REG_POS_SCD_ACK) |
  4993. IL49_SCD_QUEUE_STTS_REG_MSK);
  4994. txq->sched_retry = scd_retry;
  4995. D_INFO("%s %s Queue %d on AC %d\n", active ? "Activate" : "Deactivate",
  4996. scd_retry ? "BA" : "AC", txq_id, tx_fifo_id);
  4997. }
  4998. static int
  4999. il4965_init_drv(struct il_priv *il)
  5000. {
  5001. int ret;
  5002. spin_lock_init(&il->sta_lock);
  5003. spin_lock_init(&il->hcmd_lock);
  5004. INIT_LIST_HEAD(&il->free_frames);
  5005. mutex_init(&il->mutex);
  5006. il->ieee_channels = NULL;
  5007. il->ieee_rates = NULL;
  5008. il->band = IEEE80211_BAND_2GHZ;
  5009. il->iw_mode = NL80211_IFTYPE_STATION;
  5010. il->current_ht_config.smps = IEEE80211_SMPS_STATIC;
  5011. il->missed_beacon_threshold = IL_MISSED_BEACON_THRESHOLD_DEF;
  5012. /* initialize force reset */
  5013. il->force_reset.reset_duration = IL_DELAY_NEXT_FORCE_FW_RELOAD;
  5014. /* Choose which receivers/antennas to use */
  5015. if (il->cfg->ops->hcmd->set_rxon_chain)
  5016. il->cfg->ops->hcmd->set_rxon_chain(il, &il->ctx);
  5017. il_init_scan_params(il);
  5018. ret = il_init_channel_map(il);
  5019. if (ret) {
  5020. IL_ERR("initializing regulatory failed: %d\n", ret);
  5021. goto err;
  5022. }
  5023. ret = il_init_geos(il);
  5024. if (ret) {
  5025. IL_ERR("initializing geos failed: %d\n", ret);
  5026. goto err_free_channel_map;
  5027. }
  5028. il4965_init_hw_rates(il, il->ieee_rates);
  5029. return 0;
  5030. err_free_channel_map:
  5031. il_free_channel_map(il);
  5032. err:
  5033. return ret;
  5034. }
  5035. static void
  5036. il4965_uninit_drv(struct il_priv *il)
  5037. {
  5038. il4965_calib_free_results(il);
  5039. il_free_geos(il);
  5040. il_free_channel_map(il);
  5041. kfree(il->scan_cmd);
  5042. }
  5043. static void
  5044. il4965_hw_detect(struct il_priv *il)
  5045. {
  5046. il->hw_rev = _il_rd(il, CSR_HW_REV);
  5047. il->hw_wa_rev = _il_rd(il, CSR_HW_REV_WA_REG);
  5048. il->rev_id = il->pci_dev->revision;
  5049. D_INFO("HW Revision ID = 0x%X\n", il->rev_id);
  5050. }
  5051. static int
  5052. il4965_set_hw_params(struct il_priv *il)
  5053. {
  5054. il->hw_params.max_rxq_size = RX_QUEUE_SIZE;
  5055. il->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
  5056. if (il->cfg->mod_params->amsdu_size_8K)
  5057. il->hw_params.rx_page_order = get_order(IL_RX_BUF_SIZE_8K);
  5058. else
  5059. il->hw_params.rx_page_order = get_order(IL_RX_BUF_SIZE_4K);
  5060. il->hw_params.max_beacon_itrvl = IL_MAX_UCODE_BEACON_INTERVAL;
  5061. if (il->cfg->mod_params->disable_11n)
  5062. il->cfg->sku &= ~IL_SKU_N;
  5063. /* Device-specific setup */
  5064. return il->cfg->ops->lib->set_hw_params(il);
  5065. }
  5066. static const u8 il4965_bss_ac_to_fifo[] = {
  5067. IL_TX_FIFO_VO,
  5068. IL_TX_FIFO_VI,
  5069. IL_TX_FIFO_BE,
  5070. IL_TX_FIFO_BK,
  5071. };
  5072. static const u8 il4965_bss_ac_to_queue[] = {
  5073. 0, 1, 2, 3,
  5074. };
  5075. static int
  5076. il4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  5077. {
  5078. int err = 0;
  5079. struct il_priv *il;
  5080. struct ieee80211_hw *hw;
  5081. struct il_cfg *cfg = (struct il_cfg *)(ent->driver_data);
  5082. unsigned long flags;
  5083. u16 pci_cmd;
  5084. /************************
  5085. * 1. Allocating HW data
  5086. ************************/
  5087. hw = il_alloc_all(cfg);
  5088. if (!hw) {
  5089. err = -ENOMEM;
  5090. goto out;
  5091. }
  5092. il = hw->priv;
  5093. /* At this point both hw and il are allocated. */
  5094. il->ctx.ctxid = 0;
  5095. il->ctx.always_active = true;
  5096. il->ctx.is_active = true;
  5097. il->ctx.rxon_cmd = C_RXON;
  5098. il->ctx.rxon_timing_cmd = C_RXON_TIMING;
  5099. il->ctx.rxon_assoc_cmd = C_RXON_ASSOC;
  5100. il->ctx.qos_cmd = C_QOS_PARAM;
  5101. il->ctx.ap_sta_id = IL_AP_ID;
  5102. il->ctx.wep_key_cmd = C_WEPKEY;
  5103. il->ctx.ac_to_fifo = il4965_bss_ac_to_fifo;
  5104. il->ctx.ac_to_queue = il4965_bss_ac_to_queue;
  5105. il->ctx.exclusive_interface_modes = BIT(NL80211_IFTYPE_ADHOC);
  5106. il->ctx.interface_modes = BIT(NL80211_IFTYPE_STATION);
  5107. il->ctx.ap_devtype = RXON_DEV_TYPE_AP;
  5108. il->ctx.ibss_devtype = RXON_DEV_TYPE_IBSS;
  5109. il->ctx.station_devtype = RXON_DEV_TYPE_ESS;
  5110. il->ctx.unused_devtype = RXON_DEV_TYPE_ESS;
  5111. SET_IEEE80211_DEV(hw, &pdev->dev);
  5112. D_INFO("*** LOAD DRIVER ***\n");
  5113. il->cfg = cfg;
  5114. il->pci_dev = pdev;
  5115. il->inta_mask = CSR_INI_SET_MASK;
  5116. if (il_alloc_traffic_mem(il))
  5117. IL_ERR("Not enough memory to generate traffic log\n");
  5118. /**************************
  5119. * 2. Initializing PCI bus
  5120. **************************/
  5121. pci_disable_link_state(pdev,
  5122. PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
  5123. PCIE_LINK_STATE_CLKPM);
  5124. if (pci_enable_device(pdev)) {
  5125. err = -ENODEV;
  5126. goto out_ieee80211_free_hw;
  5127. }
  5128. pci_set_master(pdev);
  5129. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
  5130. if (!err)
  5131. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
  5132. if (err) {
  5133. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  5134. if (!err)
  5135. err =
  5136. pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  5137. /* both attempts failed: */
  5138. if (err) {
  5139. IL_WARN("No suitable DMA available.\n");
  5140. goto out_pci_disable_device;
  5141. }
  5142. }
  5143. err = pci_request_regions(pdev, DRV_NAME);
  5144. if (err)
  5145. goto out_pci_disable_device;
  5146. pci_set_drvdata(pdev, il);
  5147. /***********************
  5148. * 3. Read REV register
  5149. ***********************/
  5150. il->hw_base = pci_iomap(pdev, 0, 0);
  5151. if (!il->hw_base) {
  5152. err = -ENODEV;
  5153. goto out_pci_release_regions;
  5154. }
  5155. D_INFO("pci_resource_len = 0x%08llx\n",
  5156. (unsigned long long)pci_resource_len(pdev, 0));
  5157. D_INFO("pci_resource_base = %p\n", il->hw_base);
  5158. /* these spin locks will be used in apm_ops.init and EEPROM access
  5159. * we should init now
  5160. */
  5161. spin_lock_init(&il->reg_lock);
  5162. spin_lock_init(&il->lock);
  5163. /*
  5164. * stop and reset the on-board processor just in case it is in a
  5165. * strange state ... like being left stranded by a primary kernel
  5166. * and this is now the kdump kernel trying to start up
  5167. */
  5168. _il_wr(il, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  5169. il4965_hw_detect(il);
  5170. IL_INFO("Detected %s, REV=0x%X\n", il->cfg->name, il->hw_rev);
  5171. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  5172. * PCI Tx retries from interfering with C3 CPU state */
  5173. pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
  5174. il4965_prepare_card_hw(il);
  5175. if (!il->hw_ready) {
  5176. IL_WARN("Failed, HW not ready\n");
  5177. goto out_iounmap;
  5178. }
  5179. /*****************
  5180. * 4. Read EEPROM
  5181. *****************/
  5182. /* Read the EEPROM */
  5183. err = il_eeprom_init(il);
  5184. if (err) {
  5185. IL_ERR("Unable to init EEPROM\n");
  5186. goto out_iounmap;
  5187. }
  5188. err = il4965_eeprom_check_version(il);
  5189. if (err)
  5190. goto out_free_eeprom;
  5191. if (err)
  5192. goto out_free_eeprom;
  5193. /* extract MAC Address */
  5194. il4965_eeprom_get_mac(il, il->addresses[0].addr);
  5195. D_INFO("MAC address: %pM\n", il->addresses[0].addr);
  5196. il->hw->wiphy->addresses = il->addresses;
  5197. il->hw->wiphy->n_addresses = 1;
  5198. /************************
  5199. * 5. Setup HW constants
  5200. ************************/
  5201. if (il4965_set_hw_params(il)) {
  5202. IL_ERR("failed to set hw parameters\n");
  5203. goto out_free_eeprom;
  5204. }
  5205. /*******************
  5206. * 6. Setup il
  5207. *******************/
  5208. err = il4965_init_drv(il);
  5209. if (err)
  5210. goto out_free_eeprom;
  5211. /* At this point both hw and il are initialized. */
  5212. /********************
  5213. * 7. Setup services
  5214. ********************/
  5215. spin_lock_irqsave(&il->lock, flags);
  5216. il_disable_interrupts(il);
  5217. spin_unlock_irqrestore(&il->lock, flags);
  5218. pci_enable_msi(il->pci_dev);
  5219. err = request_irq(il->pci_dev->irq, il_isr, IRQF_SHARED, DRV_NAME, il);
  5220. if (err) {
  5221. IL_ERR("Error allocating IRQ %d\n", il->pci_dev->irq);
  5222. goto out_disable_msi;
  5223. }
  5224. il4965_setup_deferred_work(il);
  5225. il4965_setup_handlers(il);
  5226. /*********************************************
  5227. * 8. Enable interrupts and read RFKILL state
  5228. *********************************************/
  5229. /* enable rfkill interrupt: hw bug w/a */
  5230. pci_read_config_word(il->pci_dev, PCI_COMMAND, &pci_cmd);
  5231. if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
  5232. pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
  5233. pci_write_config_word(il->pci_dev, PCI_COMMAND, pci_cmd);
  5234. }
  5235. il_enable_rfkill_int(il);
  5236. /* If platform's RF_KILL switch is NOT set to KILL */
  5237. if (_il_rd(il, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  5238. clear_bit(S_RF_KILL_HW, &il->status);
  5239. else
  5240. set_bit(S_RF_KILL_HW, &il->status);
  5241. wiphy_rfkill_set_hw_state(il->hw->wiphy,
  5242. test_bit(S_RF_KILL_HW, &il->status));
  5243. il_power_initialize(il);
  5244. init_completion(&il->_4965.firmware_loading_complete);
  5245. err = il4965_request_firmware(il, true);
  5246. if (err)
  5247. goto out_destroy_workqueue;
  5248. return 0;
  5249. out_destroy_workqueue:
  5250. destroy_workqueue(il->workqueue);
  5251. il->workqueue = NULL;
  5252. free_irq(il->pci_dev->irq, il);
  5253. out_disable_msi:
  5254. pci_disable_msi(il->pci_dev);
  5255. il4965_uninit_drv(il);
  5256. out_free_eeprom:
  5257. il_eeprom_free(il);
  5258. out_iounmap:
  5259. pci_iounmap(pdev, il->hw_base);
  5260. out_pci_release_regions:
  5261. pci_set_drvdata(pdev, NULL);
  5262. pci_release_regions(pdev);
  5263. out_pci_disable_device:
  5264. pci_disable_device(pdev);
  5265. out_ieee80211_free_hw:
  5266. il_free_traffic_mem(il);
  5267. ieee80211_free_hw(il->hw);
  5268. out:
  5269. return err;
  5270. }
  5271. static void __devexit
  5272. il4965_pci_remove(struct pci_dev *pdev)
  5273. {
  5274. struct il_priv *il = pci_get_drvdata(pdev);
  5275. unsigned long flags;
  5276. if (!il)
  5277. return;
  5278. wait_for_completion(&il->_4965.firmware_loading_complete);
  5279. D_INFO("*** UNLOAD DRIVER ***\n");
  5280. il_dbgfs_unregister(il);
  5281. sysfs_remove_group(&pdev->dev.kobj, &il_attribute_group);
  5282. /* ieee80211_unregister_hw call wil cause il_mac_stop to
  5283. * to be called and il4965_down since we are removing the device
  5284. * we need to set S_EXIT_PENDING bit.
  5285. */
  5286. set_bit(S_EXIT_PENDING, &il->status);
  5287. il_leds_exit(il);
  5288. if (il->mac80211_registered) {
  5289. ieee80211_unregister_hw(il->hw);
  5290. il->mac80211_registered = 0;
  5291. } else {
  5292. il4965_down(il);
  5293. }
  5294. /*
  5295. * Make sure device is reset to low power before unloading driver.
  5296. * This may be redundant with il4965_down(), but there are paths to
  5297. * run il4965_down() without calling apm_ops.stop(), and there are
  5298. * paths to avoid running il4965_down() at all before leaving driver.
  5299. * This (inexpensive) call *makes sure* device is reset.
  5300. */
  5301. il_apm_stop(il);
  5302. /* make sure we flush any pending irq or
  5303. * tasklet for the driver
  5304. */
  5305. spin_lock_irqsave(&il->lock, flags);
  5306. il_disable_interrupts(il);
  5307. spin_unlock_irqrestore(&il->lock, flags);
  5308. il4965_synchronize_irq(il);
  5309. il4965_dealloc_ucode_pci(il);
  5310. if (il->rxq.bd)
  5311. il4965_rx_queue_free(il, &il->rxq);
  5312. il4965_hw_txq_ctx_free(il);
  5313. il_eeprom_free(il);
  5314. /*netif_stop_queue(dev); */
  5315. flush_workqueue(il->workqueue);
  5316. /* ieee80211_unregister_hw calls il_mac_stop, which flushes
  5317. * il->workqueue... so we can't take down the workqueue
  5318. * until now... */
  5319. destroy_workqueue(il->workqueue);
  5320. il->workqueue = NULL;
  5321. il_free_traffic_mem(il);
  5322. free_irq(il->pci_dev->irq, il);
  5323. pci_disable_msi(il->pci_dev);
  5324. pci_iounmap(pdev, il->hw_base);
  5325. pci_release_regions(pdev);
  5326. pci_disable_device(pdev);
  5327. pci_set_drvdata(pdev, NULL);
  5328. il4965_uninit_drv(il);
  5329. dev_kfree_skb(il->beacon_skb);
  5330. ieee80211_free_hw(il->hw);
  5331. }
  5332. /*
  5333. * Activate/Deactivate Tx DMA/FIFO channels according tx fifos mask
  5334. * must be called under il->lock and mac access
  5335. */
  5336. void
  5337. il4965_txq_set_sched(struct il_priv *il, u32 mask)
  5338. {
  5339. il_wr_prph(il, IL49_SCD_TXFACT, mask);
  5340. }
  5341. /*****************************************************************************
  5342. *
  5343. * driver and module entry point
  5344. *
  5345. *****************************************************************************/
  5346. /* Hardware specific file defines the PCI IDs table for that hardware module */
  5347. static DEFINE_PCI_DEVICE_TABLE(il4965_hw_card_ids) = {
  5348. {IL_PCI_DEVICE(0x4229, PCI_ANY_ID, il4965_cfg)},
  5349. {IL_PCI_DEVICE(0x4230, PCI_ANY_ID, il4965_cfg)},
  5350. {0}
  5351. };
  5352. MODULE_DEVICE_TABLE(pci, il4965_hw_card_ids);
  5353. static struct pci_driver il4965_driver = {
  5354. .name = DRV_NAME,
  5355. .id_table = il4965_hw_card_ids,
  5356. .probe = il4965_pci_probe,
  5357. .remove = __devexit_p(il4965_pci_remove),
  5358. .driver.pm = IL_LEGACY_PM_OPS,
  5359. };
  5360. static int __init
  5361. il4965_init(void)
  5362. {
  5363. int ret;
  5364. pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
  5365. pr_info(DRV_COPYRIGHT "\n");
  5366. ret = il4965_rate_control_register();
  5367. if (ret) {
  5368. pr_err("Unable to register rate control algorithm: %d\n", ret);
  5369. return ret;
  5370. }
  5371. ret = pci_register_driver(&il4965_driver);
  5372. if (ret) {
  5373. pr_err("Unable to initialize PCI module\n");
  5374. goto error_register;
  5375. }
  5376. return ret;
  5377. error_register:
  5378. il4965_rate_control_unregister();
  5379. return ret;
  5380. }
  5381. static void __exit
  5382. il4965_exit(void)
  5383. {
  5384. pci_unregister_driver(&il4965_driver);
  5385. il4965_rate_control_unregister();
  5386. }
  5387. module_exit(il4965_exit);
  5388. module_init(il4965_init);
  5389. #ifdef CONFIG_IWLEGACY_DEBUG
  5390. module_param_named(debug, il_debug_level, uint, S_IRUGO | S_IWUSR);
  5391. MODULE_PARM_DESC(debug, "debug output mask");
  5392. #endif
  5393. module_param_named(swcrypto, il4965_mod_params.sw_crypto, int, S_IRUGO);
  5394. MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
  5395. module_param_named(queues_num, il4965_mod_params.num_of_queues, int, S_IRUGO);
  5396. MODULE_PARM_DESC(queues_num, "number of hw queues.");
  5397. module_param_named(11n_disable, il4965_mod_params.disable_11n, int, S_IRUGO);
  5398. MODULE_PARM_DESC(11n_disable, "disable 11n functionality");
  5399. module_param_named(amsdu_size_8K, il4965_mod_params.amsdu_size_8K, int,
  5400. S_IRUGO);
  5401. MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
  5402. module_param_named(fw_restart, il4965_mod_params.restart_fw, int, S_IRUGO);
  5403. MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");