4965-mac.c 185 KB

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