4965-mac.c 177 KB

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