4965-mac.c 186 KB

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