4965-mac.c 177 KB

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