i40e_main.c 242 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2014 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. * Contact Information:
  22. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. ******************************************************************************/
  26. /* Local includes */
  27. #include "i40e.h"
  28. #include "i40e_diag.h"
  29. #ifdef CONFIG_I40E_VXLAN
  30. #include <net/vxlan.h>
  31. #endif
  32. const char i40e_driver_name[] = "i40e";
  33. static const char i40e_driver_string[] =
  34. "Intel(R) Ethernet Connection XL710 Network Driver";
  35. #define DRV_KERN "-k"
  36. #define DRV_VERSION_MAJOR 0
  37. #define DRV_VERSION_MINOR 4
  38. #define DRV_VERSION_BUILD 10
  39. #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
  40. __stringify(DRV_VERSION_MINOR) "." \
  41. __stringify(DRV_VERSION_BUILD) DRV_KERN
  42. const char i40e_driver_version_str[] = DRV_VERSION;
  43. static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation.";
  44. /* a bit of forward declarations */
  45. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi);
  46. static void i40e_handle_reset_warning(struct i40e_pf *pf);
  47. static int i40e_add_vsi(struct i40e_vsi *vsi);
  48. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi);
  49. static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit);
  50. static int i40e_setup_misc_vector(struct i40e_pf *pf);
  51. static void i40e_determine_queue_usage(struct i40e_pf *pf);
  52. static int i40e_setup_pf_filter_control(struct i40e_pf *pf);
  53. static void i40e_fdir_sb_setup(struct i40e_pf *pf);
  54. static int i40e_veb_get_bw_info(struct i40e_veb *veb);
  55. /* i40e_pci_tbl - PCI Device ID Table
  56. *
  57. * Last entry must be all 0s
  58. *
  59. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  60. * Class, Class Mask, private data (not used) }
  61. */
  62. static DEFINE_PCI_DEVICE_TABLE(i40e_pci_tbl) = {
  63. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0},
  64. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0},
  65. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_A), 0},
  66. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0},
  67. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0},
  68. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0},
  69. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0},
  70. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0},
  71. /* required last entry */
  72. {0, }
  73. };
  74. MODULE_DEVICE_TABLE(pci, i40e_pci_tbl);
  75. #define I40E_MAX_VF_COUNT 128
  76. static int debug = -1;
  77. module_param(debug, int, 0);
  78. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  79. MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
  80. MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
  81. MODULE_LICENSE("GPL");
  82. MODULE_VERSION(DRV_VERSION);
  83. /**
  84. * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
  85. * @hw: pointer to the HW structure
  86. * @mem: ptr to mem struct to fill out
  87. * @size: size of memory requested
  88. * @alignment: what to align the allocation to
  89. **/
  90. int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
  91. u64 size, u32 alignment)
  92. {
  93. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  94. mem->size = ALIGN(size, alignment);
  95. mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size,
  96. &mem->pa, GFP_KERNEL);
  97. if (!mem->va)
  98. return -ENOMEM;
  99. return 0;
  100. }
  101. /**
  102. * i40e_free_dma_mem_d - OS specific memory free for shared code
  103. * @hw: pointer to the HW structure
  104. * @mem: ptr to mem struct to free
  105. **/
  106. int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
  107. {
  108. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  109. dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa);
  110. mem->va = NULL;
  111. mem->pa = 0;
  112. mem->size = 0;
  113. return 0;
  114. }
  115. /**
  116. * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
  117. * @hw: pointer to the HW structure
  118. * @mem: ptr to mem struct to fill out
  119. * @size: size of memory requested
  120. **/
  121. int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem,
  122. u32 size)
  123. {
  124. mem->size = size;
  125. mem->va = kzalloc(size, GFP_KERNEL);
  126. if (!mem->va)
  127. return -ENOMEM;
  128. return 0;
  129. }
  130. /**
  131. * i40e_free_virt_mem_d - OS specific memory free for shared code
  132. * @hw: pointer to the HW structure
  133. * @mem: ptr to mem struct to free
  134. **/
  135. int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem)
  136. {
  137. /* it's ok to kfree a NULL pointer */
  138. kfree(mem->va);
  139. mem->va = NULL;
  140. mem->size = 0;
  141. return 0;
  142. }
  143. /**
  144. * i40e_get_lump - find a lump of free generic resource
  145. * @pf: board private structure
  146. * @pile: the pile of resource to search
  147. * @needed: the number of items needed
  148. * @id: an owner id to stick on the items assigned
  149. *
  150. * Returns the base item index of the lump, or negative for error
  151. *
  152. * The search_hint trick and lack of advanced fit-finding only work
  153. * because we're highly likely to have all the same size lump requests.
  154. * Linear search time and any fragmentation should be minimal.
  155. **/
  156. static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile,
  157. u16 needed, u16 id)
  158. {
  159. int ret = -ENOMEM;
  160. int i, j;
  161. if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) {
  162. dev_info(&pf->pdev->dev,
  163. "param err: pile=%p needed=%d id=0x%04x\n",
  164. pile, needed, id);
  165. return -EINVAL;
  166. }
  167. /* start the linear search with an imperfect hint */
  168. i = pile->search_hint;
  169. while (i < pile->num_entries) {
  170. /* skip already allocated entries */
  171. if (pile->list[i] & I40E_PILE_VALID_BIT) {
  172. i++;
  173. continue;
  174. }
  175. /* do we have enough in this lump? */
  176. for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) {
  177. if (pile->list[i+j] & I40E_PILE_VALID_BIT)
  178. break;
  179. }
  180. if (j == needed) {
  181. /* there was enough, so assign it to the requestor */
  182. for (j = 0; j < needed; j++)
  183. pile->list[i+j] = id | I40E_PILE_VALID_BIT;
  184. ret = i;
  185. pile->search_hint = i + j;
  186. break;
  187. } else {
  188. /* not enough, so skip over it and continue looking */
  189. i += j;
  190. }
  191. }
  192. return ret;
  193. }
  194. /**
  195. * i40e_put_lump - return a lump of generic resource
  196. * @pile: the pile of resource to search
  197. * @index: the base item index
  198. * @id: the owner id of the items assigned
  199. *
  200. * Returns the count of items in the lump
  201. **/
  202. static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id)
  203. {
  204. int valid_id = (id | I40E_PILE_VALID_BIT);
  205. int count = 0;
  206. int i;
  207. if (!pile || index >= pile->num_entries)
  208. return -EINVAL;
  209. for (i = index;
  210. i < pile->num_entries && pile->list[i] == valid_id;
  211. i++) {
  212. pile->list[i] = 0;
  213. count++;
  214. }
  215. if (count && index < pile->search_hint)
  216. pile->search_hint = index;
  217. return count;
  218. }
  219. /**
  220. * i40e_service_event_schedule - Schedule the service task to wake up
  221. * @pf: board private structure
  222. *
  223. * If not already scheduled, this puts the task into the work queue
  224. **/
  225. static void i40e_service_event_schedule(struct i40e_pf *pf)
  226. {
  227. if (!test_bit(__I40E_DOWN, &pf->state) &&
  228. !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state) &&
  229. !test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state))
  230. schedule_work(&pf->service_task);
  231. }
  232. /**
  233. * i40e_tx_timeout - Respond to a Tx Hang
  234. * @netdev: network interface device structure
  235. *
  236. * If any port has noticed a Tx timeout, it is likely that the whole
  237. * device is munged, not just the one netdev port, so go for the full
  238. * reset.
  239. **/
  240. static void i40e_tx_timeout(struct net_device *netdev)
  241. {
  242. struct i40e_netdev_priv *np = netdev_priv(netdev);
  243. struct i40e_vsi *vsi = np->vsi;
  244. struct i40e_pf *pf = vsi->back;
  245. pf->tx_timeout_count++;
  246. if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20)))
  247. pf->tx_timeout_recovery_level = 0;
  248. pf->tx_timeout_last_recovery = jiffies;
  249. netdev_info(netdev, "tx_timeout recovery level %d\n",
  250. pf->tx_timeout_recovery_level);
  251. switch (pf->tx_timeout_recovery_level) {
  252. case 0:
  253. /* disable and re-enable queues for the VSI */
  254. if (in_interrupt()) {
  255. set_bit(__I40E_REINIT_REQUESTED, &pf->state);
  256. set_bit(__I40E_REINIT_REQUESTED, &vsi->state);
  257. } else {
  258. i40e_vsi_reinit_locked(vsi);
  259. }
  260. break;
  261. case 1:
  262. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  263. break;
  264. case 2:
  265. set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
  266. break;
  267. case 3:
  268. set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
  269. break;
  270. default:
  271. netdev_err(netdev, "tx_timeout recovery unsuccessful\n");
  272. set_bit(__I40E_DOWN, &vsi->state);
  273. i40e_down(vsi);
  274. break;
  275. }
  276. i40e_service_event_schedule(pf);
  277. pf->tx_timeout_recovery_level++;
  278. }
  279. /**
  280. * i40e_release_rx_desc - Store the new tail and head values
  281. * @rx_ring: ring to bump
  282. * @val: new head index
  283. **/
  284. static inline void i40e_release_rx_desc(struct i40e_ring *rx_ring, u32 val)
  285. {
  286. rx_ring->next_to_use = val;
  287. /* Force memory writes to complete before letting h/w
  288. * know there are new descriptors to fetch. (Only
  289. * applicable for weak-ordered memory model archs,
  290. * such as IA-64).
  291. */
  292. wmb();
  293. writel(val, rx_ring->tail);
  294. }
  295. /**
  296. * i40e_get_vsi_stats_struct - Get System Network Statistics
  297. * @vsi: the VSI we care about
  298. *
  299. * Returns the address of the device statistics structure.
  300. * The statistics are actually updated from the service task.
  301. **/
  302. struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi)
  303. {
  304. return &vsi->net_stats;
  305. }
  306. /**
  307. * i40e_get_netdev_stats_struct - Get statistics for netdev interface
  308. * @netdev: network interface device structure
  309. *
  310. * Returns the address of the device statistics structure.
  311. * The statistics are actually updated from the service task.
  312. **/
  313. static struct rtnl_link_stats64 *i40e_get_netdev_stats_struct(
  314. struct net_device *netdev,
  315. struct rtnl_link_stats64 *stats)
  316. {
  317. struct i40e_netdev_priv *np = netdev_priv(netdev);
  318. struct i40e_ring *tx_ring, *rx_ring;
  319. struct i40e_vsi *vsi = np->vsi;
  320. struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi);
  321. int i;
  322. if (test_bit(__I40E_DOWN, &vsi->state))
  323. return stats;
  324. if (!vsi->tx_rings)
  325. return stats;
  326. rcu_read_lock();
  327. for (i = 0; i < vsi->num_queue_pairs; i++) {
  328. u64 bytes, packets;
  329. unsigned int start;
  330. tx_ring = ACCESS_ONCE(vsi->tx_rings[i]);
  331. if (!tx_ring)
  332. continue;
  333. do {
  334. start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
  335. packets = tx_ring->stats.packets;
  336. bytes = tx_ring->stats.bytes;
  337. } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
  338. stats->tx_packets += packets;
  339. stats->tx_bytes += bytes;
  340. rx_ring = &tx_ring[1];
  341. do {
  342. start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
  343. packets = rx_ring->stats.packets;
  344. bytes = rx_ring->stats.bytes;
  345. } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
  346. stats->rx_packets += packets;
  347. stats->rx_bytes += bytes;
  348. }
  349. rcu_read_unlock();
  350. /* following stats updated by i40e_watchdog_subtask() */
  351. stats->multicast = vsi_stats->multicast;
  352. stats->tx_errors = vsi_stats->tx_errors;
  353. stats->tx_dropped = vsi_stats->tx_dropped;
  354. stats->rx_errors = vsi_stats->rx_errors;
  355. stats->rx_crc_errors = vsi_stats->rx_crc_errors;
  356. stats->rx_length_errors = vsi_stats->rx_length_errors;
  357. return stats;
  358. }
  359. /**
  360. * i40e_vsi_reset_stats - Resets all stats of the given vsi
  361. * @vsi: the VSI to have its stats reset
  362. **/
  363. void i40e_vsi_reset_stats(struct i40e_vsi *vsi)
  364. {
  365. struct rtnl_link_stats64 *ns;
  366. int i;
  367. if (!vsi)
  368. return;
  369. ns = i40e_get_vsi_stats_struct(vsi);
  370. memset(ns, 0, sizeof(*ns));
  371. memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets));
  372. memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats));
  373. memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets));
  374. if (vsi->rx_rings && vsi->rx_rings[0]) {
  375. for (i = 0; i < vsi->num_queue_pairs; i++) {
  376. memset(&vsi->rx_rings[i]->stats, 0 ,
  377. sizeof(vsi->rx_rings[i]->stats));
  378. memset(&vsi->rx_rings[i]->rx_stats, 0 ,
  379. sizeof(vsi->rx_rings[i]->rx_stats));
  380. memset(&vsi->tx_rings[i]->stats, 0 ,
  381. sizeof(vsi->tx_rings[i]->stats));
  382. memset(&vsi->tx_rings[i]->tx_stats, 0,
  383. sizeof(vsi->tx_rings[i]->tx_stats));
  384. }
  385. }
  386. vsi->stat_offsets_loaded = false;
  387. }
  388. /**
  389. * i40e_pf_reset_stats - Reset all of the stats for the given pf
  390. * @pf: the PF to be reset
  391. **/
  392. void i40e_pf_reset_stats(struct i40e_pf *pf)
  393. {
  394. memset(&pf->stats, 0, sizeof(pf->stats));
  395. memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets));
  396. pf->stat_offsets_loaded = false;
  397. }
  398. /**
  399. * i40e_stat_update48 - read and update a 48 bit stat from the chip
  400. * @hw: ptr to the hardware info
  401. * @hireg: the high 32 bit reg to read
  402. * @loreg: the low 32 bit reg to read
  403. * @offset_loaded: has the initial offset been loaded yet
  404. * @offset: ptr to current offset value
  405. * @stat: ptr to the stat
  406. *
  407. * Since the device stats are not reset at PFReset, they likely will not
  408. * be zeroed when the driver starts. We'll save the first values read
  409. * and use them as offsets to be subtracted from the raw values in order
  410. * to report stats that count from zero. In the process, we also manage
  411. * the potential roll-over.
  412. **/
  413. static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg,
  414. bool offset_loaded, u64 *offset, u64 *stat)
  415. {
  416. u64 new_data;
  417. if (hw->device_id == I40E_DEV_ID_QEMU) {
  418. new_data = rd32(hw, loreg);
  419. new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
  420. } else {
  421. new_data = rd64(hw, loreg);
  422. }
  423. if (!offset_loaded)
  424. *offset = new_data;
  425. if (likely(new_data >= *offset))
  426. *stat = new_data - *offset;
  427. else
  428. *stat = (new_data + ((u64)1 << 48)) - *offset;
  429. *stat &= 0xFFFFFFFFFFFFULL;
  430. }
  431. /**
  432. * i40e_stat_update32 - read and update a 32 bit stat from the chip
  433. * @hw: ptr to the hardware info
  434. * @reg: the hw reg to read
  435. * @offset_loaded: has the initial offset been loaded yet
  436. * @offset: ptr to current offset value
  437. * @stat: ptr to the stat
  438. **/
  439. static void i40e_stat_update32(struct i40e_hw *hw, u32 reg,
  440. bool offset_loaded, u64 *offset, u64 *stat)
  441. {
  442. u32 new_data;
  443. new_data = rd32(hw, reg);
  444. if (!offset_loaded)
  445. *offset = new_data;
  446. if (likely(new_data >= *offset))
  447. *stat = (u32)(new_data - *offset);
  448. else
  449. *stat = (u32)((new_data + ((u64)1 << 32)) - *offset);
  450. }
  451. /**
  452. * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
  453. * @vsi: the VSI to be updated
  454. **/
  455. void i40e_update_eth_stats(struct i40e_vsi *vsi)
  456. {
  457. int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx);
  458. struct i40e_pf *pf = vsi->back;
  459. struct i40e_hw *hw = &pf->hw;
  460. struct i40e_eth_stats *oes;
  461. struct i40e_eth_stats *es; /* device's eth stats */
  462. es = &vsi->eth_stats;
  463. oes = &vsi->eth_stats_offsets;
  464. /* Gather up the stats that the hw collects */
  465. i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
  466. vsi->stat_offsets_loaded,
  467. &oes->tx_errors, &es->tx_errors);
  468. i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx),
  469. vsi->stat_offsets_loaded,
  470. &oes->rx_discards, &es->rx_discards);
  471. i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx),
  472. vsi->stat_offsets_loaded,
  473. &oes->rx_unknown_protocol, &es->rx_unknown_protocol);
  474. i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
  475. vsi->stat_offsets_loaded,
  476. &oes->tx_errors, &es->tx_errors);
  477. i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx),
  478. I40E_GLV_GORCL(stat_idx),
  479. vsi->stat_offsets_loaded,
  480. &oes->rx_bytes, &es->rx_bytes);
  481. i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx),
  482. I40E_GLV_UPRCL(stat_idx),
  483. vsi->stat_offsets_loaded,
  484. &oes->rx_unicast, &es->rx_unicast);
  485. i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx),
  486. I40E_GLV_MPRCL(stat_idx),
  487. vsi->stat_offsets_loaded,
  488. &oes->rx_multicast, &es->rx_multicast);
  489. i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx),
  490. I40E_GLV_BPRCL(stat_idx),
  491. vsi->stat_offsets_loaded,
  492. &oes->rx_broadcast, &es->rx_broadcast);
  493. i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx),
  494. I40E_GLV_GOTCL(stat_idx),
  495. vsi->stat_offsets_loaded,
  496. &oes->tx_bytes, &es->tx_bytes);
  497. i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx),
  498. I40E_GLV_UPTCL(stat_idx),
  499. vsi->stat_offsets_loaded,
  500. &oes->tx_unicast, &es->tx_unicast);
  501. i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx),
  502. I40E_GLV_MPTCL(stat_idx),
  503. vsi->stat_offsets_loaded,
  504. &oes->tx_multicast, &es->tx_multicast);
  505. i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx),
  506. I40E_GLV_BPTCL(stat_idx),
  507. vsi->stat_offsets_loaded,
  508. &oes->tx_broadcast, &es->tx_broadcast);
  509. vsi->stat_offsets_loaded = true;
  510. }
  511. /**
  512. * i40e_update_veb_stats - Update Switch component statistics
  513. * @veb: the VEB being updated
  514. **/
  515. static void i40e_update_veb_stats(struct i40e_veb *veb)
  516. {
  517. struct i40e_pf *pf = veb->pf;
  518. struct i40e_hw *hw = &pf->hw;
  519. struct i40e_eth_stats *oes;
  520. struct i40e_eth_stats *es; /* device's eth stats */
  521. int idx = 0;
  522. idx = veb->stats_idx;
  523. es = &veb->stats;
  524. oes = &veb->stats_offsets;
  525. /* Gather up the stats that the hw collects */
  526. i40e_stat_update32(hw, I40E_GLSW_TDPC(idx),
  527. veb->stat_offsets_loaded,
  528. &oes->tx_discards, &es->tx_discards);
  529. if (hw->revision_id > 0)
  530. i40e_stat_update32(hw, I40E_GLSW_RUPP(idx),
  531. veb->stat_offsets_loaded,
  532. &oes->rx_unknown_protocol,
  533. &es->rx_unknown_protocol);
  534. i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx),
  535. veb->stat_offsets_loaded,
  536. &oes->rx_bytes, &es->rx_bytes);
  537. i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx),
  538. veb->stat_offsets_loaded,
  539. &oes->rx_unicast, &es->rx_unicast);
  540. i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx),
  541. veb->stat_offsets_loaded,
  542. &oes->rx_multicast, &es->rx_multicast);
  543. i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx),
  544. veb->stat_offsets_loaded,
  545. &oes->rx_broadcast, &es->rx_broadcast);
  546. i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx),
  547. veb->stat_offsets_loaded,
  548. &oes->tx_bytes, &es->tx_bytes);
  549. i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx),
  550. veb->stat_offsets_loaded,
  551. &oes->tx_unicast, &es->tx_unicast);
  552. i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx),
  553. veb->stat_offsets_loaded,
  554. &oes->tx_multicast, &es->tx_multicast);
  555. i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx),
  556. veb->stat_offsets_loaded,
  557. &oes->tx_broadcast, &es->tx_broadcast);
  558. veb->stat_offsets_loaded = true;
  559. }
  560. /**
  561. * i40e_update_link_xoff_rx - Update XOFF received in link flow control mode
  562. * @pf: the corresponding PF
  563. *
  564. * Update the Rx XOFF counter (PAUSE frames) in link flow control mode
  565. **/
  566. static void i40e_update_link_xoff_rx(struct i40e_pf *pf)
  567. {
  568. struct i40e_hw_port_stats *osd = &pf->stats_offsets;
  569. struct i40e_hw_port_stats *nsd = &pf->stats;
  570. struct i40e_hw *hw = &pf->hw;
  571. u64 xoff = 0;
  572. u16 i, v;
  573. if ((hw->fc.current_mode != I40E_FC_FULL) &&
  574. (hw->fc.current_mode != I40E_FC_RX_PAUSE))
  575. return;
  576. xoff = nsd->link_xoff_rx;
  577. i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
  578. pf->stat_offsets_loaded,
  579. &osd->link_xoff_rx, &nsd->link_xoff_rx);
  580. /* No new LFC xoff rx */
  581. if (!(nsd->link_xoff_rx - xoff))
  582. return;
  583. /* Clear the __I40E_HANG_CHECK_ARMED bit for all Tx rings */
  584. for (v = 0; v < pf->num_alloc_vsi; v++) {
  585. struct i40e_vsi *vsi = pf->vsi[v];
  586. if (!vsi || !vsi->tx_rings[0])
  587. continue;
  588. for (i = 0; i < vsi->num_queue_pairs; i++) {
  589. struct i40e_ring *ring = vsi->tx_rings[i];
  590. clear_bit(__I40E_HANG_CHECK_ARMED, &ring->state);
  591. }
  592. }
  593. }
  594. /**
  595. * i40e_update_prio_xoff_rx - Update XOFF received in PFC mode
  596. * @pf: the corresponding PF
  597. *
  598. * Update the Rx XOFF counter (PAUSE frames) in PFC mode
  599. **/
  600. static void i40e_update_prio_xoff_rx(struct i40e_pf *pf)
  601. {
  602. struct i40e_hw_port_stats *osd = &pf->stats_offsets;
  603. struct i40e_hw_port_stats *nsd = &pf->stats;
  604. bool xoff[I40E_MAX_TRAFFIC_CLASS] = {false};
  605. struct i40e_dcbx_config *dcb_cfg;
  606. struct i40e_hw *hw = &pf->hw;
  607. u16 i, v;
  608. u8 tc;
  609. dcb_cfg = &hw->local_dcbx_config;
  610. /* See if DCB enabled with PFC TC */
  611. if (!(pf->flags & I40E_FLAG_DCB_ENABLED) ||
  612. !(dcb_cfg->pfc.pfcenable)) {
  613. i40e_update_link_xoff_rx(pf);
  614. return;
  615. }
  616. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  617. u64 prio_xoff = nsd->priority_xoff_rx[i];
  618. i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
  619. pf->stat_offsets_loaded,
  620. &osd->priority_xoff_rx[i],
  621. &nsd->priority_xoff_rx[i]);
  622. /* No new PFC xoff rx */
  623. if (!(nsd->priority_xoff_rx[i] - prio_xoff))
  624. continue;
  625. /* Get the TC for given priority */
  626. tc = dcb_cfg->etscfg.prioritytable[i];
  627. xoff[tc] = true;
  628. }
  629. /* Clear the __I40E_HANG_CHECK_ARMED bit for Tx rings */
  630. for (v = 0; v < pf->num_alloc_vsi; v++) {
  631. struct i40e_vsi *vsi = pf->vsi[v];
  632. if (!vsi || !vsi->tx_rings[0])
  633. continue;
  634. for (i = 0; i < vsi->num_queue_pairs; i++) {
  635. struct i40e_ring *ring = vsi->tx_rings[i];
  636. tc = ring->dcb_tc;
  637. if (xoff[tc])
  638. clear_bit(__I40E_HANG_CHECK_ARMED,
  639. &ring->state);
  640. }
  641. }
  642. }
  643. /**
  644. * i40e_update_vsi_stats - Update the vsi statistics counters.
  645. * @vsi: the VSI to be updated
  646. *
  647. * There are a few instances where we store the same stat in a
  648. * couple of different structs. This is partly because we have
  649. * the netdev stats that need to be filled out, which is slightly
  650. * different from the "eth_stats" defined by the chip and used in
  651. * VF communications. We sort it out here.
  652. **/
  653. static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
  654. {
  655. struct i40e_pf *pf = vsi->back;
  656. struct rtnl_link_stats64 *ons;
  657. struct rtnl_link_stats64 *ns; /* netdev stats */
  658. struct i40e_eth_stats *oes;
  659. struct i40e_eth_stats *es; /* device's eth stats */
  660. u32 tx_restart, tx_busy;
  661. u32 rx_page, rx_buf;
  662. u64 rx_p, rx_b;
  663. u64 tx_p, tx_b;
  664. u16 q;
  665. if (test_bit(__I40E_DOWN, &vsi->state) ||
  666. test_bit(__I40E_CONFIG_BUSY, &pf->state))
  667. return;
  668. ns = i40e_get_vsi_stats_struct(vsi);
  669. ons = &vsi->net_stats_offsets;
  670. es = &vsi->eth_stats;
  671. oes = &vsi->eth_stats_offsets;
  672. /* Gather up the netdev and vsi stats that the driver collects
  673. * on the fly during packet processing
  674. */
  675. rx_b = rx_p = 0;
  676. tx_b = tx_p = 0;
  677. tx_restart = tx_busy = 0;
  678. rx_page = 0;
  679. rx_buf = 0;
  680. rcu_read_lock();
  681. for (q = 0; q < vsi->num_queue_pairs; q++) {
  682. struct i40e_ring *p;
  683. u64 bytes, packets;
  684. unsigned int start;
  685. /* locate Tx ring */
  686. p = ACCESS_ONCE(vsi->tx_rings[q]);
  687. do {
  688. start = u64_stats_fetch_begin_irq(&p->syncp);
  689. packets = p->stats.packets;
  690. bytes = p->stats.bytes;
  691. } while (u64_stats_fetch_retry_irq(&p->syncp, start));
  692. tx_b += bytes;
  693. tx_p += packets;
  694. tx_restart += p->tx_stats.restart_queue;
  695. tx_busy += p->tx_stats.tx_busy;
  696. /* Rx queue is part of the same block as Tx queue */
  697. p = &p[1];
  698. do {
  699. start = u64_stats_fetch_begin_irq(&p->syncp);
  700. packets = p->stats.packets;
  701. bytes = p->stats.bytes;
  702. } while (u64_stats_fetch_retry_irq(&p->syncp, start));
  703. rx_b += bytes;
  704. rx_p += packets;
  705. rx_buf += p->rx_stats.alloc_buff_failed;
  706. rx_page += p->rx_stats.alloc_page_failed;
  707. }
  708. rcu_read_unlock();
  709. vsi->tx_restart = tx_restart;
  710. vsi->tx_busy = tx_busy;
  711. vsi->rx_page_failed = rx_page;
  712. vsi->rx_buf_failed = rx_buf;
  713. ns->rx_packets = rx_p;
  714. ns->rx_bytes = rx_b;
  715. ns->tx_packets = tx_p;
  716. ns->tx_bytes = tx_b;
  717. /* update netdev stats from eth stats */
  718. i40e_update_eth_stats(vsi);
  719. ons->tx_errors = oes->tx_errors;
  720. ns->tx_errors = es->tx_errors;
  721. ons->multicast = oes->rx_multicast;
  722. ns->multicast = es->rx_multicast;
  723. ons->rx_dropped = oes->rx_discards;
  724. ns->rx_dropped = es->rx_discards;
  725. ons->tx_dropped = oes->tx_discards;
  726. ns->tx_dropped = es->tx_discards;
  727. /* pull in a couple PF stats if this is the main vsi */
  728. if (vsi == pf->vsi[pf->lan_vsi]) {
  729. ns->rx_crc_errors = pf->stats.crc_errors;
  730. ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes;
  731. ns->rx_length_errors = pf->stats.rx_length_errors;
  732. }
  733. }
  734. /**
  735. * i40e_update_pf_stats - Update the pf statistics counters.
  736. * @pf: the PF to be updated
  737. **/
  738. static void i40e_update_pf_stats(struct i40e_pf *pf)
  739. {
  740. struct i40e_hw_port_stats *osd = &pf->stats_offsets;
  741. struct i40e_hw_port_stats *nsd = &pf->stats;
  742. struct i40e_hw *hw = &pf->hw;
  743. u32 val;
  744. int i;
  745. i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port),
  746. I40E_GLPRT_GORCL(hw->port),
  747. pf->stat_offsets_loaded,
  748. &osd->eth.rx_bytes, &nsd->eth.rx_bytes);
  749. i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port),
  750. I40E_GLPRT_GOTCL(hw->port),
  751. pf->stat_offsets_loaded,
  752. &osd->eth.tx_bytes, &nsd->eth.tx_bytes);
  753. i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port),
  754. pf->stat_offsets_loaded,
  755. &osd->eth.rx_discards,
  756. &nsd->eth.rx_discards);
  757. i40e_stat_update32(hw, I40E_GLPRT_TDPC(hw->port),
  758. pf->stat_offsets_loaded,
  759. &osd->eth.tx_discards,
  760. &nsd->eth.tx_discards);
  761. i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port),
  762. I40E_GLPRT_UPRCL(hw->port),
  763. pf->stat_offsets_loaded,
  764. &osd->eth.rx_unicast,
  765. &nsd->eth.rx_unicast);
  766. i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port),
  767. I40E_GLPRT_MPRCL(hw->port),
  768. pf->stat_offsets_loaded,
  769. &osd->eth.rx_multicast,
  770. &nsd->eth.rx_multicast);
  771. i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port),
  772. I40E_GLPRT_BPRCL(hw->port),
  773. pf->stat_offsets_loaded,
  774. &osd->eth.rx_broadcast,
  775. &nsd->eth.rx_broadcast);
  776. i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port),
  777. I40E_GLPRT_UPTCL(hw->port),
  778. pf->stat_offsets_loaded,
  779. &osd->eth.tx_unicast,
  780. &nsd->eth.tx_unicast);
  781. i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port),
  782. I40E_GLPRT_MPTCL(hw->port),
  783. pf->stat_offsets_loaded,
  784. &osd->eth.tx_multicast,
  785. &nsd->eth.tx_multicast);
  786. i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port),
  787. I40E_GLPRT_BPTCL(hw->port),
  788. pf->stat_offsets_loaded,
  789. &osd->eth.tx_broadcast,
  790. &nsd->eth.tx_broadcast);
  791. i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port),
  792. pf->stat_offsets_loaded,
  793. &osd->tx_dropped_link_down,
  794. &nsd->tx_dropped_link_down);
  795. i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port),
  796. pf->stat_offsets_loaded,
  797. &osd->crc_errors, &nsd->crc_errors);
  798. i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port),
  799. pf->stat_offsets_loaded,
  800. &osd->illegal_bytes, &nsd->illegal_bytes);
  801. i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port),
  802. pf->stat_offsets_loaded,
  803. &osd->mac_local_faults,
  804. &nsd->mac_local_faults);
  805. i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port),
  806. pf->stat_offsets_loaded,
  807. &osd->mac_remote_faults,
  808. &nsd->mac_remote_faults);
  809. i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port),
  810. pf->stat_offsets_loaded,
  811. &osd->rx_length_errors,
  812. &nsd->rx_length_errors);
  813. i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port),
  814. pf->stat_offsets_loaded,
  815. &osd->link_xon_rx, &nsd->link_xon_rx);
  816. i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port),
  817. pf->stat_offsets_loaded,
  818. &osd->link_xon_tx, &nsd->link_xon_tx);
  819. i40e_update_prio_xoff_rx(pf); /* handles I40E_GLPRT_LXOFFRXC */
  820. i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
  821. pf->stat_offsets_loaded,
  822. &osd->link_xoff_tx, &nsd->link_xoff_tx);
  823. for (i = 0; i < 8; i++) {
  824. i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
  825. pf->stat_offsets_loaded,
  826. &osd->priority_xon_rx[i],
  827. &nsd->priority_xon_rx[i]);
  828. i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
  829. pf->stat_offsets_loaded,
  830. &osd->priority_xon_tx[i],
  831. &nsd->priority_xon_tx[i]);
  832. i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
  833. pf->stat_offsets_loaded,
  834. &osd->priority_xoff_tx[i],
  835. &nsd->priority_xoff_tx[i]);
  836. i40e_stat_update32(hw,
  837. I40E_GLPRT_RXON2OFFCNT(hw->port, i),
  838. pf->stat_offsets_loaded,
  839. &osd->priority_xon_2_xoff[i],
  840. &nsd->priority_xon_2_xoff[i]);
  841. }
  842. i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port),
  843. I40E_GLPRT_PRC64L(hw->port),
  844. pf->stat_offsets_loaded,
  845. &osd->rx_size_64, &nsd->rx_size_64);
  846. i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port),
  847. I40E_GLPRT_PRC127L(hw->port),
  848. pf->stat_offsets_loaded,
  849. &osd->rx_size_127, &nsd->rx_size_127);
  850. i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port),
  851. I40E_GLPRT_PRC255L(hw->port),
  852. pf->stat_offsets_loaded,
  853. &osd->rx_size_255, &nsd->rx_size_255);
  854. i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port),
  855. I40E_GLPRT_PRC511L(hw->port),
  856. pf->stat_offsets_loaded,
  857. &osd->rx_size_511, &nsd->rx_size_511);
  858. i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port),
  859. I40E_GLPRT_PRC1023L(hw->port),
  860. pf->stat_offsets_loaded,
  861. &osd->rx_size_1023, &nsd->rx_size_1023);
  862. i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port),
  863. I40E_GLPRT_PRC1522L(hw->port),
  864. pf->stat_offsets_loaded,
  865. &osd->rx_size_1522, &nsd->rx_size_1522);
  866. i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port),
  867. I40E_GLPRT_PRC9522L(hw->port),
  868. pf->stat_offsets_loaded,
  869. &osd->rx_size_big, &nsd->rx_size_big);
  870. i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port),
  871. I40E_GLPRT_PTC64L(hw->port),
  872. pf->stat_offsets_loaded,
  873. &osd->tx_size_64, &nsd->tx_size_64);
  874. i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port),
  875. I40E_GLPRT_PTC127L(hw->port),
  876. pf->stat_offsets_loaded,
  877. &osd->tx_size_127, &nsd->tx_size_127);
  878. i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port),
  879. I40E_GLPRT_PTC255L(hw->port),
  880. pf->stat_offsets_loaded,
  881. &osd->tx_size_255, &nsd->tx_size_255);
  882. i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port),
  883. I40E_GLPRT_PTC511L(hw->port),
  884. pf->stat_offsets_loaded,
  885. &osd->tx_size_511, &nsd->tx_size_511);
  886. i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port),
  887. I40E_GLPRT_PTC1023L(hw->port),
  888. pf->stat_offsets_loaded,
  889. &osd->tx_size_1023, &nsd->tx_size_1023);
  890. i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port),
  891. I40E_GLPRT_PTC1522L(hw->port),
  892. pf->stat_offsets_loaded,
  893. &osd->tx_size_1522, &nsd->tx_size_1522);
  894. i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port),
  895. I40E_GLPRT_PTC9522L(hw->port),
  896. pf->stat_offsets_loaded,
  897. &osd->tx_size_big, &nsd->tx_size_big);
  898. i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port),
  899. pf->stat_offsets_loaded,
  900. &osd->rx_undersize, &nsd->rx_undersize);
  901. i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port),
  902. pf->stat_offsets_loaded,
  903. &osd->rx_fragments, &nsd->rx_fragments);
  904. i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port),
  905. pf->stat_offsets_loaded,
  906. &osd->rx_oversize, &nsd->rx_oversize);
  907. i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port),
  908. pf->stat_offsets_loaded,
  909. &osd->rx_jabber, &nsd->rx_jabber);
  910. /* FDIR stats */
  911. i40e_stat_update32(hw, I40E_GLQF_PCNT(pf->fd_atr_cnt_idx),
  912. pf->stat_offsets_loaded,
  913. &osd->fd_atr_match, &nsd->fd_atr_match);
  914. i40e_stat_update32(hw, I40E_GLQF_PCNT(pf->fd_sb_cnt_idx),
  915. pf->stat_offsets_loaded,
  916. &osd->fd_sb_match, &nsd->fd_sb_match);
  917. val = rd32(hw, I40E_PRTPM_EEE_STAT);
  918. nsd->tx_lpi_status =
  919. (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >>
  920. I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT;
  921. nsd->rx_lpi_status =
  922. (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >>
  923. I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT;
  924. i40e_stat_update32(hw, I40E_PRTPM_TLPIC,
  925. pf->stat_offsets_loaded,
  926. &osd->tx_lpi_count, &nsd->tx_lpi_count);
  927. i40e_stat_update32(hw, I40E_PRTPM_RLPIC,
  928. pf->stat_offsets_loaded,
  929. &osd->rx_lpi_count, &nsd->rx_lpi_count);
  930. pf->stat_offsets_loaded = true;
  931. }
  932. /**
  933. * i40e_update_stats - Update the various statistics counters.
  934. * @vsi: the VSI to be updated
  935. *
  936. * Update the various stats for this VSI and its related entities.
  937. **/
  938. void i40e_update_stats(struct i40e_vsi *vsi)
  939. {
  940. struct i40e_pf *pf = vsi->back;
  941. if (vsi == pf->vsi[pf->lan_vsi])
  942. i40e_update_pf_stats(pf);
  943. i40e_update_vsi_stats(vsi);
  944. }
  945. /**
  946. * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
  947. * @vsi: the VSI to be searched
  948. * @macaddr: the MAC address
  949. * @vlan: the vlan
  950. * @is_vf: make sure its a vf filter, else doesn't matter
  951. * @is_netdev: make sure its a netdev filter, else doesn't matter
  952. *
  953. * Returns ptr to the filter object or NULL
  954. **/
  955. static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi,
  956. u8 *macaddr, s16 vlan,
  957. bool is_vf, bool is_netdev)
  958. {
  959. struct i40e_mac_filter *f;
  960. if (!vsi || !macaddr)
  961. return NULL;
  962. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  963. if ((ether_addr_equal(macaddr, f->macaddr)) &&
  964. (vlan == f->vlan) &&
  965. (!is_vf || f->is_vf) &&
  966. (!is_netdev || f->is_netdev))
  967. return f;
  968. }
  969. return NULL;
  970. }
  971. /**
  972. * i40e_find_mac - Find a mac addr in the macvlan filters list
  973. * @vsi: the VSI to be searched
  974. * @macaddr: the MAC address we are searching for
  975. * @is_vf: make sure its a vf filter, else doesn't matter
  976. * @is_netdev: make sure its a netdev filter, else doesn't matter
  977. *
  978. * Returns the first filter with the provided MAC address or NULL if
  979. * MAC address was not found
  980. **/
  981. struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, u8 *macaddr,
  982. bool is_vf, bool is_netdev)
  983. {
  984. struct i40e_mac_filter *f;
  985. if (!vsi || !macaddr)
  986. return NULL;
  987. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  988. if ((ether_addr_equal(macaddr, f->macaddr)) &&
  989. (!is_vf || f->is_vf) &&
  990. (!is_netdev || f->is_netdev))
  991. return f;
  992. }
  993. return NULL;
  994. }
  995. /**
  996. * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
  997. * @vsi: the VSI to be searched
  998. *
  999. * Returns true if VSI is in vlan mode or false otherwise
  1000. **/
  1001. bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi)
  1002. {
  1003. struct i40e_mac_filter *f;
  1004. /* Only -1 for all the filters denotes not in vlan mode
  1005. * so we have to go through all the list in order to make sure
  1006. */
  1007. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1008. if (f->vlan >= 0)
  1009. return true;
  1010. }
  1011. return false;
  1012. }
  1013. /**
  1014. * i40e_put_mac_in_vlan - Make macvlan filters from macaddrs and vlans
  1015. * @vsi: the VSI to be searched
  1016. * @macaddr: the mac address to be filtered
  1017. * @is_vf: true if it is a vf
  1018. * @is_netdev: true if it is a netdev
  1019. *
  1020. * Goes through all the macvlan filters and adds a
  1021. * macvlan filter for each unique vlan that already exists
  1022. *
  1023. * Returns first filter found on success, else NULL
  1024. **/
  1025. struct i40e_mac_filter *i40e_put_mac_in_vlan(struct i40e_vsi *vsi, u8 *macaddr,
  1026. bool is_vf, bool is_netdev)
  1027. {
  1028. struct i40e_mac_filter *f;
  1029. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1030. if (!i40e_find_filter(vsi, macaddr, f->vlan,
  1031. is_vf, is_netdev)) {
  1032. if (!i40e_add_filter(vsi, macaddr, f->vlan,
  1033. is_vf, is_netdev))
  1034. return NULL;
  1035. }
  1036. }
  1037. return list_first_entry_or_null(&vsi->mac_filter_list,
  1038. struct i40e_mac_filter, list);
  1039. }
  1040. /**
  1041. * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
  1042. * @vsi: the PF Main VSI - inappropriate for any other VSI
  1043. * @macaddr: the MAC address
  1044. **/
  1045. static void i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr)
  1046. {
  1047. struct i40e_aqc_remove_macvlan_element_data element;
  1048. struct i40e_pf *pf = vsi->back;
  1049. i40e_status aq_ret;
  1050. /* Only appropriate for the PF main VSI */
  1051. if (vsi->type != I40E_VSI_MAIN)
  1052. return;
  1053. ether_addr_copy(element.mac_addr, macaddr);
  1054. element.vlan_tag = 0;
  1055. element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
  1056. I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
  1057. aq_ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
  1058. if (aq_ret)
  1059. dev_err(&pf->pdev->dev, "Could not remove default MAC-VLAN\n");
  1060. }
  1061. /**
  1062. * i40e_add_filter - Add a mac/vlan filter to the VSI
  1063. * @vsi: the VSI to be searched
  1064. * @macaddr: the MAC address
  1065. * @vlan: the vlan
  1066. * @is_vf: make sure its a vf filter, else doesn't matter
  1067. * @is_netdev: make sure its a netdev filter, else doesn't matter
  1068. *
  1069. * Returns ptr to the filter object or NULL when no memory available.
  1070. **/
  1071. struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi,
  1072. u8 *macaddr, s16 vlan,
  1073. bool is_vf, bool is_netdev)
  1074. {
  1075. struct i40e_mac_filter *f;
  1076. if (!vsi || !macaddr)
  1077. return NULL;
  1078. f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev);
  1079. if (!f) {
  1080. f = kzalloc(sizeof(*f), GFP_ATOMIC);
  1081. if (!f)
  1082. goto add_filter_out;
  1083. ether_addr_copy(f->macaddr, macaddr);
  1084. f->vlan = vlan;
  1085. f->changed = true;
  1086. INIT_LIST_HEAD(&f->list);
  1087. list_add(&f->list, &vsi->mac_filter_list);
  1088. }
  1089. /* increment counter and add a new flag if needed */
  1090. if (is_vf) {
  1091. if (!f->is_vf) {
  1092. f->is_vf = true;
  1093. f->counter++;
  1094. }
  1095. } else if (is_netdev) {
  1096. if (!f->is_netdev) {
  1097. f->is_netdev = true;
  1098. f->counter++;
  1099. }
  1100. } else {
  1101. f->counter++;
  1102. }
  1103. /* changed tells sync_filters_subtask to
  1104. * push the filter down to the firmware
  1105. */
  1106. if (f->changed) {
  1107. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1108. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1109. }
  1110. add_filter_out:
  1111. return f;
  1112. }
  1113. /**
  1114. * i40e_del_filter - Remove a mac/vlan filter from the VSI
  1115. * @vsi: the VSI to be searched
  1116. * @macaddr: the MAC address
  1117. * @vlan: the vlan
  1118. * @is_vf: make sure it's a vf filter, else doesn't matter
  1119. * @is_netdev: make sure it's a netdev filter, else doesn't matter
  1120. **/
  1121. void i40e_del_filter(struct i40e_vsi *vsi,
  1122. u8 *macaddr, s16 vlan,
  1123. bool is_vf, bool is_netdev)
  1124. {
  1125. struct i40e_mac_filter *f;
  1126. if (!vsi || !macaddr)
  1127. return;
  1128. f = i40e_find_filter(vsi, macaddr, vlan, is_vf, is_netdev);
  1129. if (!f || f->counter == 0)
  1130. return;
  1131. if (is_vf) {
  1132. if (f->is_vf) {
  1133. f->is_vf = false;
  1134. f->counter--;
  1135. }
  1136. } else if (is_netdev) {
  1137. if (f->is_netdev) {
  1138. f->is_netdev = false;
  1139. f->counter--;
  1140. }
  1141. } else {
  1142. /* make sure we don't remove a filter in use by vf or netdev */
  1143. int min_f = 0;
  1144. min_f += (f->is_vf ? 1 : 0);
  1145. min_f += (f->is_netdev ? 1 : 0);
  1146. if (f->counter > min_f)
  1147. f->counter--;
  1148. }
  1149. /* counter == 0 tells sync_filters_subtask to
  1150. * remove the filter from the firmware's list
  1151. */
  1152. if (f->counter == 0) {
  1153. f->changed = true;
  1154. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1155. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1156. }
  1157. }
  1158. /**
  1159. * i40e_set_mac - NDO callback to set mac address
  1160. * @netdev: network interface device structure
  1161. * @p: pointer to an address structure
  1162. *
  1163. * Returns 0 on success, negative on failure
  1164. **/
  1165. static int i40e_set_mac(struct net_device *netdev, void *p)
  1166. {
  1167. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1168. struct i40e_vsi *vsi = np->vsi;
  1169. struct sockaddr *addr = p;
  1170. struct i40e_mac_filter *f;
  1171. if (!is_valid_ether_addr(addr->sa_data))
  1172. return -EADDRNOTAVAIL;
  1173. netdev_info(netdev, "set mac address=%pM\n", addr->sa_data);
  1174. if (ether_addr_equal(netdev->dev_addr, addr->sa_data))
  1175. return 0;
  1176. if (test_bit(__I40E_DOWN, &vsi->back->state) ||
  1177. test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
  1178. return -EADDRNOTAVAIL;
  1179. if (vsi->type == I40E_VSI_MAIN) {
  1180. i40e_status ret;
  1181. ret = i40e_aq_mac_address_write(&vsi->back->hw,
  1182. I40E_AQC_WRITE_TYPE_LAA_ONLY,
  1183. addr->sa_data, NULL);
  1184. if (ret) {
  1185. netdev_info(netdev,
  1186. "Addr change for Main VSI failed: %d\n",
  1187. ret);
  1188. return -EADDRNOTAVAIL;
  1189. }
  1190. ether_addr_copy(vsi->back->hw.mac.addr, addr->sa_data);
  1191. }
  1192. /* In order to be sure to not drop any packets, add the new address
  1193. * then delete the old one.
  1194. */
  1195. f = i40e_add_filter(vsi, addr->sa_data, I40E_VLAN_ANY, false, false);
  1196. if (!f)
  1197. return -ENOMEM;
  1198. i40e_sync_vsi_filters(vsi);
  1199. i40e_del_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY, false, false);
  1200. i40e_sync_vsi_filters(vsi);
  1201. ether_addr_copy(netdev->dev_addr, addr->sa_data);
  1202. return 0;
  1203. }
  1204. /**
  1205. * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
  1206. * @vsi: the VSI being setup
  1207. * @ctxt: VSI context structure
  1208. * @enabled_tc: Enabled TCs bitmap
  1209. * @is_add: True if called before Add VSI
  1210. *
  1211. * Setup VSI queue mapping for enabled traffic classes.
  1212. **/
  1213. static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
  1214. struct i40e_vsi_context *ctxt,
  1215. u8 enabled_tc,
  1216. bool is_add)
  1217. {
  1218. struct i40e_pf *pf = vsi->back;
  1219. u16 sections = 0;
  1220. u8 netdev_tc = 0;
  1221. u16 numtc = 0;
  1222. u16 qcount;
  1223. u8 offset;
  1224. u16 qmap;
  1225. int i;
  1226. u16 num_tc_qps = 0;
  1227. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  1228. offset = 0;
  1229. if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  1230. /* Find numtc from enabled TC bitmap */
  1231. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1232. if (enabled_tc & (1 << i)) /* TC is enabled */
  1233. numtc++;
  1234. }
  1235. if (!numtc) {
  1236. dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n");
  1237. numtc = 1;
  1238. }
  1239. } else {
  1240. /* At least TC0 is enabled in case of non-DCB case */
  1241. numtc = 1;
  1242. }
  1243. vsi->tc_config.numtc = numtc;
  1244. vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
  1245. /* Number of queues per enabled TC */
  1246. num_tc_qps = vsi->alloc_queue_pairs/numtc;
  1247. num_tc_qps = min_t(int, num_tc_qps, I40E_MAX_QUEUES_PER_TC);
  1248. /* Setup queue offset/count for all TCs for given VSI */
  1249. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1250. /* See if the given TC is enabled for the given VSI */
  1251. if (vsi->tc_config.enabled_tc & (1 << i)) { /* TC is enabled */
  1252. int pow, num_qps;
  1253. switch (vsi->type) {
  1254. case I40E_VSI_MAIN:
  1255. qcount = min_t(int, pf->rss_size, num_tc_qps);
  1256. break;
  1257. case I40E_VSI_FDIR:
  1258. case I40E_VSI_SRIOV:
  1259. case I40E_VSI_VMDQ2:
  1260. default:
  1261. qcount = num_tc_qps;
  1262. WARN_ON(i != 0);
  1263. break;
  1264. }
  1265. vsi->tc_config.tc_info[i].qoffset = offset;
  1266. vsi->tc_config.tc_info[i].qcount = qcount;
  1267. /* find the power-of-2 of the number of queue pairs */
  1268. num_qps = qcount;
  1269. pow = 0;
  1270. while (num_qps && ((1 << pow) < qcount)) {
  1271. pow++;
  1272. num_qps >>= 1;
  1273. }
  1274. vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
  1275. qmap =
  1276. (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  1277. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  1278. offset += qcount;
  1279. } else {
  1280. /* TC is not enabled so set the offset to
  1281. * default queue and allocate one queue
  1282. * for the given TC.
  1283. */
  1284. vsi->tc_config.tc_info[i].qoffset = 0;
  1285. vsi->tc_config.tc_info[i].qcount = 1;
  1286. vsi->tc_config.tc_info[i].netdev_tc = 0;
  1287. qmap = 0;
  1288. }
  1289. ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
  1290. }
  1291. /* Set actual Tx/Rx queue pairs */
  1292. vsi->num_queue_pairs = offset;
  1293. /* Scheduler section valid can only be set for ADD VSI */
  1294. if (is_add) {
  1295. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  1296. ctxt->info.up_enable_bits = enabled_tc;
  1297. }
  1298. if (vsi->type == I40E_VSI_SRIOV) {
  1299. ctxt->info.mapping_flags |=
  1300. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
  1301. for (i = 0; i < vsi->num_queue_pairs; i++)
  1302. ctxt->info.queue_mapping[i] =
  1303. cpu_to_le16(vsi->base_queue + i);
  1304. } else {
  1305. ctxt->info.mapping_flags |=
  1306. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  1307. ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
  1308. }
  1309. ctxt->info.valid_sections |= cpu_to_le16(sections);
  1310. }
  1311. /**
  1312. * i40e_set_rx_mode - NDO callback to set the netdev filters
  1313. * @netdev: network interface device structure
  1314. **/
  1315. static void i40e_set_rx_mode(struct net_device *netdev)
  1316. {
  1317. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1318. struct i40e_mac_filter *f, *ftmp;
  1319. struct i40e_vsi *vsi = np->vsi;
  1320. struct netdev_hw_addr *uca;
  1321. struct netdev_hw_addr *mca;
  1322. struct netdev_hw_addr *ha;
  1323. /* add addr if not already in the filter list */
  1324. netdev_for_each_uc_addr(uca, netdev) {
  1325. if (!i40e_find_mac(vsi, uca->addr, false, true)) {
  1326. if (i40e_is_vsi_in_vlan(vsi))
  1327. i40e_put_mac_in_vlan(vsi, uca->addr,
  1328. false, true);
  1329. else
  1330. i40e_add_filter(vsi, uca->addr, I40E_VLAN_ANY,
  1331. false, true);
  1332. }
  1333. }
  1334. netdev_for_each_mc_addr(mca, netdev) {
  1335. if (!i40e_find_mac(vsi, mca->addr, false, true)) {
  1336. if (i40e_is_vsi_in_vlan(vsi))
  1337. i40e_put_mac_in_vlan(vsi, mca->addr,
  1338. false, true);
  1339. else
  1340. i40e_add_filter(vsi, mca->addr, I40E_VLAN_ANY,
  1341. false, true);
  1342. }
  1343. }
  1344. /* remove filter if not in netdev list */
  1345. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  1346. bool found = false;
  1347. if (!f->is_netdev)
  1348. continue;
  1349. if (is_multicast_ether_addr(f->macaddr)) {
  1350. netdev_for_each_mc_addr(mca, netdev) {
  1351. if (ether_addr_equal(mca->addr, f->macaddr)) {
  1352. found = true;
  1353. break;
  1354. }
  1355. }
  1356. } else {
  1357. netdev_for_each_uc_addr(uca, netdev) {
  1358. if (ether_addr_equal(uca->addr, f->macaddr)) {
  1359. found = true;
  1360. break;
  1361. }
  1362. }
  1363. for_each_dev_addr(netdev, ha) {
  1364. if (ether_addr_equal(ha->addr, f->macaddr)) {
  1365. found = true;
  1366. break;
  1367. }
  1368. }
  1369. }
  1370. if (!found)
  1371. i40e_del_filter(
  1372. vsi, f->macaddr, I40E_VLAN_ANY, false, true);
  1373. }
  1374. /* check for other flag changes */
  1375. if (vsi->current_netdev_flags != vsi->netdev->flags) {
  1376. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1377. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1378. }
  1379. }
  1380. /**
  1381. * i40e_sync_vsi_filters - Update the VSI filter list to the HW
  1382. * @vsi: ptr to the VSI
  1383. *
  1384. * Push any outstanding VSI filter changes through the AdminQ.
  1385. *
  1386. * Returns 0 or error value
  1387. **/
  1388. int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
  1389. {
  1390. struct i40e_mac_filter *f, *ftmp;
  1391. bool promisc_forced_on = false;
  1392. bool add_happened = false;
  1393. int filter_list_len = 0;
  1394. u32 changed_flags = 0;
  1395. i40e_status aq_ret = 0;
  1396. struct i40e_pf *pf;
  1397. int num_add = 0;
  1398. int num_del = 0;
  1399. u16 cmd_flags;
  1400. /* empty array typed pointers, kcalloc later */
  1401. struct i40e_aqc_add_macvlan_element_data *add_list;
  1402. struct i40e_aqc_remove_macvlan_element_data *del_list;
  1403. while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state))
  1404. usleep_range(1000, 2000);
  1405. pf = vsi->back;
  1406. if (vsi->netdev) {
  1407. changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
  1408. vsi->current_netdev_flags = vsi->netdev->flags;
  1409. }
  1410. if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
  1411. vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
  1412. filter_list_len = pf->hw.aq.asq_buf_size /
  1413. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  1414. del_list = kcalloc(filter_list_len,
  1415. sizeof(struct i40e_aqc_remove_macvlan_element_data),
  1416. GFP_KERNEL);
  1417. if (!del_list)
  1418. return -ENOMEM;
  1419. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  1420. if (!f->changed)
  1421. continue;
  1422. if (f->counter != 0)
  1423. continue;
  1424. f->changed = false;
  1425. cmd_flags = 0;
  1426. /* add to delete list */
  1427. ether_addr_copy(del_list[num_del].mac_addr, f->macaddr);
  1428. del_list[num_del].vlan_tag =
  1429. cpu_to_le16((u16)(f->vlan ==
  1430. I40E_VLAN_ANY ? 0 : f->vlan));
  1431. cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  1432. del_list[num_del].flags = cmd_flags;
  1433. num_del++;
  1434. /* unlink from filter list */
  1435. list_del(&f->list);
  1436. kfree(f);
  1437. /* flush a full buffer */
  1438. if (num_del == filter_list_len) {
  1439. aq_ret = i40e_aq_remove_macvlan(&pf->hw,
  1440. vsi->seid, del_list, num_del,
  1441. NULL);
  1442. num_del = 0;
  1443. memset(del_list, 0, sizeof(*del_list));
  1444. if (aq_ret &&
  1445. pf->hw.aq.asq_last_status !=
  1446. I40E_AQ_RC_ENOENT)
  1447. dev_info(&pf->pdev->dev,
  1448. "ignoring delete macvlan error, err %d, aq_err %d while flushing a full buffer\n",
  1449. aq_ret,
  1450. pf->hw.aq.asq_last_status);
  1451. }
  1452. }
  1453. if (num_del) {
  1454. aq_ret = i40e_aq_remove_macvlan(&pf->hw, vsi->seid,
  1455. del_list, num_del, NULL);
  1456. num_del = 0;
  1457. if (aq_ret &&
  1458. pf->hw.aq.asq_last_status != I40E_AQ_RC_ENOENT)
  1459. dev_info(&pf->pdev->dev,
  1460. "ignoring delete macvlan error, err %d, aq_err %d\n",
  1461. aq_ret, pf->hw.aq.asq_last_status);
  1462. }
  1463. kfree(del_list);
  1464. del_list = NULL;
  1465. /* do all the adds now */
  1466. filter_list_len = pf->hw.aq.asq_buf_size /
  1467. sizeof(struct i40e_aqc_add_macvlan_element_data),
  1468. add_list = kcalloc(filter_list_len,
  1469. sizeof(struct i40e_aqc_add_macvlan_element_data),
  1470. GFP_KERNEL);
  1471. if (!add_list)
  1472. return -ENOMEM;
  1473. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  1474. if (!f->changed)
  1475. continue;
  1476. if (f->counter == 0)
  1477. continue;
  1478. f->changed = false;
  1479. add_happened = true;
  1480. cmd_flags = 0;
  1481. /* add to add array */
  1482. ether_addr_copy(add_list[num_add].mac_addr, f->macaddr);
  1483. add_list[num_add].vlan_tag =
  1484. cpu_to_le16(
  1485. (u16)(f->vlan == I40E_VLAN_ANY ? 0 : f->vlan));
  1486. add_list[num_add].queue_number = 0;
  1487. cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
  1488. add_list[num_add].flags = cpu_to_le16(cmd_flags);
  1489. num_add++;
  1490. /* flush a full buffer */
  1491. if (num_add == filter_list_len) {
  1492. aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid,
  1493. add_list, num_add,
  1494. NULL);
  1495. num_add = 0;
  1496. if (aq_ret)
  1497. break;
  1498. memset(add_list, 0, sizeof(*add_list));
  1499. }
  1500. }
  1501. if (num_add) {
  1502. aq_ret = i40e_aq_add_macvlan(&pf->hw, vsi->seid,
  1503. add_list, num_add, NULL);
  1504. num_add = 0;
  1505. }
  1506. kfree(add_list);
  1507. add_list = NULL;
  1508. if (add_happened && (!aq_ret)) {
  1509. /* do nothing */;
  1510. } else if (add_happened && (aq_ret)) {
  1511. dev_info(&pf->pdev->dev,
  1512. "add filter failed, err %d, aq_err %d\n",
  1513. aq_ret, pf->hw.aq.asq_last_status);
  1514. if ((pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOSPC) &&
  1515. !test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  1516. &vsi->state)) {
  1517. promisc_forced_on = true;
  1518. set_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  1519. &vsi->state);
  1520. dev_info(&pf->pdev->dev, "promiscuous mode forced on\n");
  1521. }
  1522. }
  1523. }
  1524. /* check for changes in promiscuous modes */
  1525. if (changed_flags & IFF_ALLMULTI) {
  1526. bool cur_multipromisc;
  1527. cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
  1528. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
  1529. vsi->seid,
  1530. cur_multipromisc,
  1531. NULL);
  1532. if (aq_ret)
  1533. dev_info(&pf->pdev->dev,
  1534. "set multi promisc failed, err %d, aq_err %d\n",
  1535. aq_ret, pf->hw.aq.asq_last_status);
  1536. }
  1537. if ((changed_flags & IFF_PROMISC) || promisc_forced_on) {
  1538. bool cur_promisc;
  1539. cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
  1540. test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  1541. &vsi->state));
  1542. aq_ret = i40e_aq_set_vsi_unicast_promiscuous(&vsi->back->hw,
  1543. vsi->seid,
  1544. cur_promisc, NULL);
  1545. if (aq_ret)
  1546. dev_info(&pf->pdev->dev,
  1547. "set uni promisc failed, err %d, aq_err %d\n",
  1548. aq_ret, pf->hw.aq.asq_last_status);
  1549. aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw,
  1550. vsi->seid,
  1551. cur_promisc, NULL);
  1552. if (aq_ret)
  1553. dev_info(&pf->pdev->dev,
  1554. "set brdcast promisc failed, err %d, aq_err %d\n",
  1555. aq_ret, pf->hw.aq.asq_last_status);
  1556. }
  1557. clear_bit(__I40E_CONFIG_BUSY, &vsi->state);
  1558. return 0;
  1559. }
  1560. /**
  1561. * i40e_sync_filters_subtask - Sync the VSI filter list with HW
  1562. * @pf: board private structure
  1563. **/
  1564. static void i40e_sync_filters_subtask(struct i40e_pf *pf)
  1565. {
  1566. int v;
  1567. if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC))
  1568. return;
  1569. pf->flags &= ~I40E_FLAG_FILTER_SYNC;
  1570. for (v = 0; v < pf->num_alloc_vsi; v++) {
  1571. if (pf->vsi[v] &&
  1572. (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED))
  1573. i40e_sync_vsi_filters(pf->vsi[v]);
  1574. }
  1575. }
  1576. /**
  1577. * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
  1578. * @netdev: network interface device structure
  1579. * @new_mtu: new value for maximum frame size
  1580. *
  1581. * Returns 0 on success, negative on failure
  1582. **/
  1583. static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
  1584. {
  1585. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1586. int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
  1587. struct i40e_vsi *vsi = np->vsi;
  1588. /* MTU < 68 is an error and causes problems on some kernels */
  1589. if ((new_mtu < 68) || (max_frame > I40E_MAX_RXBUFFER))
  1590. return -EINVAL;
  1591. netdev_info(netdev, "changing MTU from %d to %d\n",
  1592. netdev->mtu, new_mtu);
  1593. netdev->mtu = new_mtu;
  1594. if (netif_running(netdev))
  1595. i40e_vsi_reinit_locked(vsi);
  1596. return 0;
  1597. }
  1598. /**
  1599. * i40e_ioctl - Access the hwtstamp interface
  1600. * @netdev: network interface device structure
  1601. * @ifr: interface request data
  1602. * @cmd: ioctl command
  1603. **/
  1604. int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  1605. {
  1606. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1607. struct i40e_pf *pf = np->vsi->back;
  1608. switch (cmd) {
  1609. case SIOCGHWTSTAMP:
  1610. return i40e_ptp_get_ts_config(pf, ifr);
  1611. case SIOCSHWTSTAMP:
  1612. return i40e_ptp_set_ts_config(pf, ifr);
  1613. default:
  1614. return -EOPNOTSUPP;
  1615. }
  1616. }
  1617. /**
  1618. * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
  1619. * @vsi: the vsi being adjusted
  1620. **/
  1621. void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
  1622. {
  1623. struct i40e_vsi_context ctxt;
  1624. i40e_status ret;
  1625. if ((vsi->info.valid_sections &
  1626. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  1627. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
  1628. return; /* already enabled */
  1629. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  1630. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  1631. I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
  1632. ctxt.seid = vsi->seid;
  1633. memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
  1634. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  1635. if (ret) {
  1636. dev_info(&vsi->back->pdev->dev,
  1637. "%s: update vsi failed, aq_err=%d\n",
  1638. __func__, vsi->back->hw.aq.asq_last_status);
  1639. }
  1640. }
  1641. /**
  1642. * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
  1643. * @vsi: the vsi being adjusted
  1644. **/
  1645. void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
  1646. {
  1647. struct i40e_vsi_context ctxt;
  1648. i40e_status ret;
  1649. if ((vsi->info.valid_sections &
  1650. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  1651. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
  1652. I40E_AQ_VSI_PVLAN_EMOD_MASK))
  1653. return; /* already disabled */
  1654. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  1655. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  1656. I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
  1657. ctxt.seid = vsi->seid;
  1658. memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
  1659. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  1660. if (ret) {
  1661. dev_info(&vsi->back->pdev->dev,
  1662. "%s: update vsi failed, aq_err=%d\n",
  1663. __func__, vsi->back->hw.aq.asq_last_status);
  1664. }
  1665. }
  1666. /**
  1667. * i40e_vlan_rx_register - Setup or shutdown vlan offload
  1668. * @netdev: network interface to be adjusted
  1669. * @features: netdev features to test if VLAN offload is enabled or not
  1670. **/
  1671. static void i40e_vlan_rx_register(struct net_device *netdev, u32 features)
  1672. {
  1673. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1674. struct i40e_vsi *vsi = np->vsi;
  1675. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  1676. i40e_vlan_stripping_enable(vsi);
  1677. else
  1678. i40e_vlan_stripping_disable(vsi);
  1679. }
  1680. /**
  1681. * i40e_vsi_add_vlan - Add vsi membership for given vlan
  1682. * @vsi: the vsi being configured
  1683. * @vid: vlan id to be added (0 = untagged only , -1 = any)
  1684. **/
  1685. int i40e_vsi_add_vlan(struct i40e_vsi *vsi, s16 vid)
  1686. {
  1687. struct i40e_mac_filter *f, *add_f;
  1688. bool is_netdev, is_vf;
  1689. is_vf = (vsi->type == I40E_VSI_SRIOV);
  1690. is_netdev = !!(vsi->netdev);
  1691. if (is_netdev) {
  1692. add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, vid,
  1693. is_vf, is_netdev);
  1694. if (!add_f) {
  1695. dev_info(&vsi->back->pdev->dev,
  1696. "Could not add vlan filter %d for %pM\n",
  1697. vid, vsi->netdev->dev_addr);
  1698. return -ENOMEM;
  1699. }
  1700. }
  1701. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1702. add_f = i40e_add_filter(vsi, f->macaddr, vid, is_vf, is_netdev);
  1703. if (!add_f) {
  1704. dev_info(&vsi->back->pdev->dev,
  1705. "Could not add vlan filter %d for %pM\n",
  1706. vid, f->macaddr);
  1707. return -ENOMEM;
  1708. }
  1709. }
  1710. /* Now if we add a vlan tag, make sure to check if it is the first
  1711. * tag (i.e. a "tag" -1 does exist) and if so replace the -1 "tag"
  1712. * with 0, so we now accept untagged and specified tagged traffic
  1713. * (and not any taged and untagged)
  1714. */
  1715. if (vid > 0) {
  1716. if (is_netdev && i40e_find_filter(vsi, vsi->netdev->dev_addr,
  1717. I40E_VLAN_ANY,
  1718. is_vf, is_netdev)) {
  1719. i40e_del_filter(vsi, vsi->netdev->dev_addr,
  1720. I40E_VLAN_ANY, is_vf, is_netdev);
  1721. add_f = i40e_add_filter(vsi, vsi->netdev->dev_addr, 0,
  1722. is_vf, is_netdev);
  1723. if (!add_f) {
  1724. dev_info(&vsi->back->pdev->dev,
  1725. "Could not add filter 0 for %pM\n",
  1726. vsi->netdev->dev_addr);
  1727. return -ENOMEM;
  1728. }
  1729. }
  1730. }
  1731. /* Do not assume that I40E_VLAN_ANY should be reset to VLAN 0 */
  1732. if (vid > 0 && !vsi->info.pvid) {
  1733. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1734. if (i40e_find_filter(vsi, f->macaddr, I40E_VLAN_ANY,
  1735. is_vf, is_netdev)) {
  1736. i40e_del_filter(vsi, f->macaddr, I40E_VLAN_ANY,
  1737. is_vf, is_netdev);
  1738. add_f = i40e_add_filter(vsi, f->macaddr,
  1739. 0, is_vf, is_netdev);
  1740. if (!add_f) {
  1741. dev_info(&vsi->back->pdev->dev,
  1742. "Could not add filter 0 for %pM\n",
  1743. f->macaddr);
  1744. return -ENOMEM;
  1745. }
  1746. }
  1747. }
  1748. }
  1749. if (test_bit(__I40E_DOWN, &vsi->back->state) ||
  1750. test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
  1751. return 0;
  1752. return i40e_sync_vsi_filters(vsi);
  1753. }
  1754. /**
  1755. * i40e_vsi_kill_vlan - Remove vsi membership for given vlan
  1756. * @vsi: the vsi being configured
  1757. * @vid: vlan id to be removed (0 = untagged only , -1 = any)
  1758. *
  1759. * Return: 0 on success or negative otherwise
  1760. **/
  1761. int i40e_vsi_kill_vlan(struct i40e_vsi *vsi, s16 vid)
  1762. {
  1763. struct net_device *netdev = vsi->netdev;
  1764. struct i40e_mac_filter *f, *add_f;
  1765. bool is_vf, is_netdev;
  1766. int filter_count = 0;
  1767. is_vf = (vsi->type == I40E_VSI_SRIOV);
  1768. is_netdev = !!(netdev);
  1769. if (is_netdev)
  1770. i40e_del_filter(vsi, netdev->dev_addr, vid, is_vf, is_netdev);
  1771. list_for_each_entry(f, &vsi->mac_filter_list, list)
  1772. i40e_del_filter(vsi, f->macaddr, vid, is_vf, is_netdev);
  1773. /* go through all the filters for this VSI and if there is only
  1774. * vid == 0 it means there are no other filters, so vid 0 must
  1775. * be replaced with -1. This signifies that we should from now
  1776. * on accept any traffic (with any tag present, or untagged)
  1777. */
  1778. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1779. if (is_netdev) {
  1780. if (f->vlan &&
  1781. ether_addr_equal(netdev->dev_addr, f->macaddr))
  1782. filter_count++;
  1783. }
  1784. if (f->vlan)
  1785. filter_count++;
  1786. }
  1787. if (!filter_count && is_netdev) {
  1788. i40e_del_filter(vsi, netdev->dev_addr, 0, is_vf, is_netdev);
  1789. f = i40e_add_filter(vsi, netdev->dev_addr, I40E_VLAN_ANY,
  1790. is_vf, is_netdev);
  1791. if (!f) {
  1792. dev_info(&vsi->back->pdev->dev,
  1793. "Could not add filter %d for %pM\n",
  1794. I40E_VLAN_ANY, netdev->dev_addr);
  1795. return -ENOMEM;
  1796. }
  1797. }
  1798. if (!filter_count) {
  1799. list_for_each_entry(f, &vsi->mac_filter_list, list) {
  1800. i40e_del_filter(vsi, f->macaddr, 0, is_vf, is_netdev);
  1801. add_f = i40e_add_filter(vsi, f->macaddr, I40E_VLAN_ANY,
  1802. is_vf, is_netdev);
  1803. if (!add_f) {
  1804. dev_info(&vsi->back->pdev->dev,
  1805. "Could not add filter %d for %pM\n",
  1806. I40E_VLAN_ANY, f->macaddr);
  1807. return -ENOMEM;
  1808. }
  1809. }
  1810. }
  1811. if (test_bit(__I40E_DOWN, &vsi->back->state) ||
  1812. test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
  1813. return 0;
  1814. return i40e_sync_vsi_filters(vsi);
  1815. }
  1816. /**
  1817. * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
  1818. * @netdev: network interface to be adjusted
  1819. * @vid: vlan id to be added
  1820. *
  1821. * net_device_ops implementation for adding vlan ids
  1822. **/
  1823. static int i40e_vlan_rx_add_vid(struct net_device *netdev,
  1824. __always_unused __be16 proto, u16 vid)
  1825. {
  1826. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1827. struct i40e_vsi *vsi = np->vsi;
  1828. int ret = 0;
  1829. if (vid > 4095)
  1830. return -EINVAL;
  1831. netdev_info(netdev, "adding %pM vid=%d\n", netdev->dev_addr, vid);
  1832. /* If the network stack called us with vid = 0 then
  1833. * it is asking to receive priority tagged packets with
  1834. * vlan id 0. Our HW receives them by default when configured
  1835. * to receive untagged packets so there is no need to add an
  1836. * extra filter for vlan 0 tagged packets.
  1837. */
  1838. if (vid)
  1839. ret = i40e_vsi_add_vlan(vsi, vid);
  1840. if (!ret && (vid < VLAN_N_VID))
  1841. set_bit(vid, vsi->active_vlans);
  1842. return ret;
  1843. }
  1844. /**
  1845. * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
  1846. * @netdev: network interface to be adjusted
  1847. * @vid: vlan id to be removed
  1848. *
  1849. * net_device_ops implementation for removing vlan ids
  1850. **/
  1851. static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
  1852. __always_unused __be16 proto, u16 vid)
  1853. {
  1854. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1855. struct i40e_vsi *vsi = np->vsi;
  1856. netdev_info(netdev, "removing %pM vid=%d\n", netdev->dev_addr, vid);
  1857. /* return code is ignored as there is nothing a user
  1858. * can do about failure to remove and a log message was
  1859. * already printed from the other function
  1860. */
  1861. i40e_vsi_kill_vlan(vsi, vid);
  1862. clear_bit(vid, vsi->active_vlans);
  1863. return 0;
  1864. }
  1865. /**
  1866. * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
  1867. * @vsi: the vsi being brought back up
  1868. **/
  1869. static void i40e_restore_vlan(struct i40e_vsi *vsi)
  1870. {
  1871. u16 vid;
  1872. if (!vsi->netdev)
  1873. return;
  1874. i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features);
  1875. for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
  1876. i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q),
  1877. vid);
  1878. }
  1879. /**
  1880. * i40e_vsi_add_pvid - Add pvid for the VSI
  1881. * @vsi: the vsi being adjusted
  1882. * @vid: the vlan id to set as a PVID
  1883. **/
  1884. int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
  1885. {
  1886. struct i40e_vsi_context ctxt;
  1887. i40e_status aq_ret;
  1888. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  1889. vsi->info.pvid = cpu_to_le16(vid);
  1890. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
  1891. I40E_AQ_VSI_PVLAN_INSERT_PVID |
  1892. I40E_AQ_VSI_PVLAN_EMOD_STR;
  1893. ctxt.seid = vsi->seid;
  1894. memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
  1895. aq_ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  1896. if (aq_ret) {
  1897. dev_info(&vsi->back->pdev->dev,
  1898. "%s: update vsi failed, aq_err=%d\n",
  1899. __func__, vsi->back->hw.aq.asq_last_status);
  1900. return -ENOENT;
  1901. }
  1902. return 0;
  1903. }
  1904. /**
  1905. * i40e_vsi_remove_pvid - Remove the pvid from the VSI
  1906. * @vsi: the vsi being adjusted
  1907. *
  1908. * Just use the vlan_rx_register() service to put it back to normal
  1909. **/
  1910. void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
  1911. {
  1912. i40e_vlan_stripping_disable(vsi);
  1913. vsi->info.pvid = 0;
  1914. }
  1915. /**
  1916. * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
  1917. * @vsi: ptr to the VSI
  1918. *
  1919. * If this function returns with an error, then it's possible one or
  1920. * more of the rings is populated (while the rest are not). It is the
  1921. * callers duty to clean those orphaned rings.
  1922. *
  1923. * Return 0 on success, negative on failure
  1924. **/
  1925. static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
  1926. {
  1927. int i, err = 0;
  1928. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  1929. err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
  1930. return err;
  1931. }
  1932. /**
  1933. * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
  1934. * @vsi: ptr to the VSI
  1935. *
  1936. * Free VSI's transmit software resources
  1937. **/
  1938. static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
  1939. {
  1940. int i;
  1941. if (!vsi->tx_rings)
  1942. return;
  1943. for (i = 0; i < vsi->num_queue_pairs; i++)
  1944. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
  1945. i40e_free_tx_resources(vsi->tx_rings[i]);
  1946. }
  1947. /**
  1948. * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
  1949. * @vsi: ptr to the VSI
  1950. *
  1951. * If this function returns with an error, then it's possible one or
  1952. * more of the rings is populated (while the rest are not). It is the
  1953. * callers duty to clean those orphaned rings.
  1954. *
  1955. * Return 0 on success, negative on failure
  1956. **/
  1957. static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
  1958. {
  1959. int i, err = 0;
  1960. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  1961. err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
  1962. return err;
  1963. }
  1964. /**
  1965. * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
  1966. * @vsi: ptr to the VSI
  1967. *
  1968. * Free all receive software resources
  1969. **/
  1970. static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
  1971. {
  1972. int i;
  1973. if (!vsi->rx_rings)
  1974. return;
  1975. for (i = 0; i < vsi->num_queue_pairs; i++)
  1976. if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
  1977. i40e_free_rx_resources(vsi->rx_rings[i]);
  1978. }
  1979. /**
  1980. * i40e_configure_tx_ring - Configure a transmit ring context and rest
  1981. * @ring: The Tx ring to configure
  1982. *
  1983. * Configure the Tx descriptor ring in the HMC context.
  1984. **/
  1985. static int i40e_configure_tx_ring(struct i40e_ring *ring)
  1986. {
  1987. struct i40e_vsi *vsi = ring->vsi;
  1988. u16 pf_q = vsi->base_queue + ring->queue_index;
  1989. struct i40e_hw *hw = &vsi->back->hw;
  1990. struct i40e_hmc_obj_txq tx_ctx;
  1991. i40e_status err = 0;
  1992. u32 qtx_ctl = 0;
  1993. /* some ATR related tx ring init */
  1994. if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
  1995. ring->atr_sample_rate = vsi->back->atr_sample_rate;
  1996. ring->atr_count = 0;
  1997. } else {
  1998. ring->atr_sample_rate = 0;
  1999. }
  2000. /* initialize XPS */
  2001. if (ring->q_vector && ring->netdev &&
  2002. vsi->tc_config.numtc <= 1 &&
  2003. !test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state))
  2004. netif_set_xps_queue(ring->netdev,
  2005. &ring->q_vector->affinity_mask,
  2006. ring->queue_index);
  2007. /* clear the context structure first */
  2008. memset(&tx_ctx, 0, sizeof(tx_ctx));
  2009. tx_ctx.new_context = 1;
  2010. tx_ctx.base = (ring->dma / 128);
  2011. tx_ctx.qlen = ring->count;
  2012. tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
  2013. I40E_FLAG_FD_ATR_ENABLED));
  2014. tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
  2015. /* FDIR VSI tx ring can still use RS bit and writebacks */
  2016. if (vsi->type != I40E_VSI_FDIR)
  2017. tx_ctx.head_wb_ena = 1;
  2018. tx_ctx.head_wb_addr = ring->dma +
  2019. (ring->count * sizeof(struct i40e_tx_desc));
  2020. /* As part of VSI creation/update, FW allocates certain
  2021. * Tx arbitration queue sets for each TC enabled for
  2022. * the VSI. The FW returns the handles to these queue
  2023. * sets as part of the response buffer to Add VSI,
  2024. * Update VSI, etc. AQ commands. It is expected that
  2025. * these queue set handles be associated with the Tx
  2026. * queues by the driver as part of the TX queue context
  2027. * initialization. This has to be done regardless of
  2028. * DCB as by default everything is mapped to TC0.
  2029. */
  2030. tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
  2031. tx_ctx.rdylist_act = 0;
  2032. /* clear the context in the HMC */
  2033. err = i40e_clear_lan_tx_queue_context(hw, pf_q);
  2034. if (err) {
  2035. dev_info(&vsi->back->pdev->dev,
  2036. "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
  2037. ring->queue_index, pf_q, err);
  2038. return -ENOMEM;
  2039. }
  2040. /* set the context in the HMC */
  2041. err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
  2042. if (err) {
  2043. dev_info(&vsi->back->pdev->dev,
  2044. "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
  2045. ring->queue_index, pf_q, err);
  2046. return -ENOMEM;
  2047. }
  2048. /* Now associate this queue with this PCI function */
  2049. if (vsi->type == I40E_VSI_VMDQ2)
  2050. qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
  2051. else
  2052. qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
  2053. qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
  2054. I40E_QTX_CTL_PF_INDX_MASK);
  2055. wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
  2056. i40e_flush(hw);
  2057. clear_bit(__I40E_HANG_CHECK_ARMED, &ring->state);
  2058. /* cache tail off for easier writes later */
  2059. ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
  2060. return 0;
  2061. }
  2062. /**
  2063. * i40e_configure_rx_ring - Configure a receive ring context
  2064. * @ring: The Rx ring to configure
  2065. *
  2066. * Configure the Rx descriptor ring in the HMC context.
  2067. **/
  2068. static int i40e_configure_rx_ring(struct i40e_ring *ring)
  2069. {
  2070. struct i40e_vsi *vsi = ring->vsi;
  2071. u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
  2072. u16 pf_q = vsi->base_queue + ring->queue_index;
  2073. struct i40e_hw *hw = &vsi->back->hw;
  2074. struct i40e_hmc_obj_rxq rx_ctx;
  2075. i40e_status err = 0;
  2076. ring->state = 0;
  2077. /* clear the context structure first */
  2078. memset(&rx_ctx, 0, sizeof(rx_ctx));
  2079. ring->rx_buf_len = vsi->rx_buf_len;
  2080. ring->rx_hdr_len = vsi->rx_hdr_len;
  2081. rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT;
  2082. rx_ctx.hbuff = ring->rx_hdr_len >> I40E_RXQ_CTX_HBUFF_SHIFT;
  2083. rx_ctx.base = (ring->dma / 128);
  2084. rx_ctx.qlen = ring->count;
  2085. if (vsi->back->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED) {
  2086. set_ring_16byte_desc_enabled(ring);
  2087. rx_ctx.dsize = 0;
  2088. } else {
  2089. rx_ctx.dsize = 1;
  2090. }
  2091. rx_ctx.dtype = vsi->dtype;
  2092. if (vsi->dtype) {
  2093. set_ring_ps_enabled(ring);
  2094. rx_ctx.hsplit_0 = I40E_RX_SPLIT_L2 |
  2095. I40E_RX_SPLIT_IP |
  2096. I40E_RX_SPLIT_TCP_UDP |
  2097. I40E_RX_SPLIT_SCTP;
  2098. } else {
  2099. rx_ctx.hsplit_0 = 0;
  2100. }
  2101. rx_ctx.rxmax = min_t(u16, vsi->max_frame,
  2102. (chain_len * ring->rx_buf_len));
  2103. rx_ctx.tphrdesc_ena = 1;
  2104. rx_ctx.tphwdesc_ena = 1;
  2105. rx_ctx.tphdata_ena = 1;
  2106. rx_ctx.tphhead_ena = 1;
  2107. if (hw->revision_id == 0)
  2108. rx_ctx.lrxqthresh = 0;
  2109. else
  2110. rx_ctx.lrxqthresh = 2;
  2111. rx_ctx.crcstrip = 1;
  2112. rx_ctx.l2tsel = 1;
  2113. rx_ctx.showiv = 1;
  2114. /* set the prefena field to 1 because the manual says to */
  2115. rx_ctx.prefena = 1;
  2116. /* clear the context in the HMC */
  2117. err = i40e_clear_lan_rx_queue_context(hw, pf_q);
  2118. if (err) {
  2119. dev_info(&vsi->back->pdev->dev,
  2120. "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2121. ring->queue_index, pf_q, err);
  2122. return -ENOMEM;
  2123. }
  2124. /* set the context in the HMC */
  2125. err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
  2126. if (err) {
  2127. dev_info(&vsi->back->pdev->dev,
  2128. "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2129. ring->queue_index, pf_q, err);
  2130. return -ENOMEM;
  2131. }
  2132. /* cache tail for quicker writes, and clear the reg before use */
  2133. ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
  2134. writel(0, ring->tail);
  2135. i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring));
  2136. return 0;
  2137. }
  2138. /**
  2139. * i40e_vsi_configure_tx - Configure the VSI for Tx
  2140. * @vsi: VSI structure describing this set of rings and resources
  2141. *
  2142. * Configure the Tx VSI for operation.
  2143. **/
  2144. static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
  2145. {
  2146. int err = 0;
  2147. u16 i;
  2148. for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
  2149. err = i40e_configure_tx_ring(vsi->tx_rings[i]);
  2150. return err;
  2151. }
  2152. /**
  2153. * i40e_vsi_configure_rx - Configure the VSI for Rx
  2154. * @vsi: the VSI being configured
  2155. *
  2156. * Configure the Rx VSI for operation.
  2157. **/
  2158. static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
  2159. {
  2160. int err = 0;
  2161. u16 i;
  2162. if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN))
  2163. vsi->max_frame = vsi->netdev->mtu + ETH_HLEN
  2164. + ETH_FCS_LEN + VLAN_HLEN;
  2165. else
  2166. vsi->max_frame = I40E_RXBUFFER_2048;
  2167. /* figure out correct receive buffer length */
  2168. switch (vsi->back->flags & (I40E_FLAG_RX_1BUF_ENABLED |
  2169. I40E_FLAG_RX_PS_ENABLED)) {
  2170. case I40E_FLAG_RX_1BUF_ENABLED:
  2171. vsi->rx_hdr_len = 0;
  2172. vsi->rx_buf_len = vsi->max_frame;
  2173. vsi->dtype = I40E_RX_DTYPE_NO_SPLIT;
  2174. break;
  2175. case I40E_FLAG_RX_PS_ENABLED:
  2176. vsi->rx_hdr_len = I40E_RX_HDR_SIZE;
  2177. vsi->rx_buf_len = I40E_RXBUFFER_2048;
  2178. vsi->dtype = I40E_RX_DTYPE_HEADER_SPLIT;
  2179. break;
  2180. default:
  2181. vsi->rx_hdr_len = I40E_RX_HDR_SIZE;
  2182. vsi->rx_buf_len = I40E_RXBUFFER_2048;
  2183. vsi->dtype = I40E_RX_DTYPE_SPLIT_ALWAYS;
  2184. break;
  2185. }
  2186. /* round up for the chip's needs */
  2187. vsi->rx_hdr_len = ALIGN(vsi->rx_hdr_len,
  2188. (1 << I40E_RXQ_CTX_HBUFF_SHIFT));
  2189. vsi->rx_buf_len = ALIGN(vsi->rx_buf_len,
  2190. (1 << I40E_RXQ_CTX_DBUFF_SHIFT));
  2191. /* set up individual rings */
  2192. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2193. err = i40e_configure_rx_ring(vsi->rx_rings[i]);
  2194. return err;
  2195. }
  2196. /**
  2197. * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
  2198. * @vsi: ptr to the VSI
  2199. **/
  2200. static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
  2201. {
  2202. struct i40e_ring *tx_ring, *rx_ring;
  2203. u16 qoffset, qcount;
  2204. int i, n;
  2205. if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED))
  2206. return;
  2207. for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
  2208. if (!(vsi->tc_config.enabled_tc & (1 << n)))
  2209. continue;
  2210. qoffset = vsi->tc_config.tc_info[n].qoffset;
  2211. qcount = vsi->tc_config.tc_info[n].qcount;
  2212. for (i = qoffset; i < (qoffset + qcount); i++) {
  2213. rx_ring = vsi->rx_rings[i];
  2214. tx_ring = vsi->tx_rings[i];
  2215. rx_ring->dcb_tc = n;
  2216. tx_ring->dcb_tc = n;
  2217. }
  2218. }
  2219. }
  2220. /**
  2221. * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
  2222. * @vsi: ptr to the VSI
  2223. **/
  2224. static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
  2225. {
  2226. if (vsi->netdev)
  2227. i40e_set_rx_mode(vsi->netdev);
  2228. }
  2229. /**
  2230. * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
  2231. * @vsi: Pointer to the targeted VSI
  2232. *
  2233. * This function replays the hlist on the hw where all the SB Flow Director
  2234. * filters were saved.
  2235. **/
  2236. static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
  2237. {
  2238. struct i40e_fdir_filter *filter;
  2239. struct i40e_pf *pf = vsi->back;
  2240. struct hlist_node *node;
  2241. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  2242. return;
  2243. hlist_for_each_entry_safe(filter, node,
  2244. &pf->fdir_filter_list, fdir_node) {
  2245. i40e_add_del_fdir(vsi, filter, true);
  2246. }
  2247. }
  2248. /**
  2249. * i40e_vsi_configure - Set up the VSI for action
  2250. * @vsi: the VSI being configured
  2251. **/
  2252. static int i40e_vsi_configure(struct i40e_vsi *vsi)
  2253. {
  2254. int err;
  2255. i40e_set_vsi_rx_mode(vsi);
  2256. i40e_restore_vlan(vsi);
  2257. i40e_vsi_config_dcb_rings(vsi);
  2258. err = i40e_vsi_configure_tx(vsi);
  2259. if (!err)
  2260. err = i40e_vsi_configure_rx(vsi);
  2261. return err;
  2262. }
  2263. /**
  2264. * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
  2265. * @vsi: the VSI being configured
  2266. **/
  2267. static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
  2268. {
  2269. struct i40e_pf *pf = vsi->back;
  2270. struct i40e_q_vector *q_vector;
  2271. struct i40e_hw *hw = &pf->hw;
  2272. u16 vector;
  2273. int i, q;
  2274. u32 val;
  2275. u32 qp;
  2276. /* The interrupt indexing is offset by 1 in the PFINT_ITRn
  2277. * and PFINT_LNKLSTn registers, e.g.:
  2278. * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
  2279. */
  2280. qp = vsi->base_queue;
  2281. vector = vsi->base_vector;
  2282. for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
  2283. q_vector = vsi->q_vectors[i];
  2284. q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
  2285. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  2286. wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
  2287. q_vector->rx.itr);
  2288. q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
  2289. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  2290. wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
  2291. q_vector->tx.itr);
  2292. /* Linked list for the queuepairs assigned to this vector */
  2293. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
  2294. for (q = 0; q < q_vector->num_ringpairs; q++) {
  2295. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  2296. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  2297. (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
  2298. (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
  2299. (I40E_QUEUE_TYPE_TX
  2300. << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
  2301. wr32(hw, I40E_QINT_RQCTL(qp), val);
  2302. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  2303. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  2304. (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
  2305. ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)|
  2306. (I40E_QUEUE_TYPE_RX
  2307. << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  2308. /* Terminate the linked list */
  2309. if (q == (q_vector->num_ringpairs - 1))
  2310. val |= (I40E_QUEUE_END_OF_LIST
  2311. << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  2312. wr32(hw, I40E_QINT_TQCTL(qp), val);
  2313. qp++;
  2314. }
  2315. }
  2316. i40e_flush(hw);
  2317. }
  2318. /**
  2319. * i40e_enable_misc_int_causes - enable the non-queue interrupts
  2320. * @hw: ptr to the hardware info
  2321. **/
  2322. static void i40e_enable_misc_int_causes(struct i40e_hw *hw)
  2323. {
  2324. u32 val;
  2325. /* clear things first */
  2326. wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
  2327. rd32(hw, I40E_PFINT_ICR0); /* read to clear */
  2328. val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
  2329. I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
  2330. I40E_PFINT_ICR0_ENA_GRST_MASK |
  2331. I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
  2332. I40E_PFINT_ICR0_ENA_GPIO_MASK |
  2333. I40E_PFINT_ICR0_ENA_TIMESYNC_MASK |
  2334. I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
  2335. I40E_PFINT_ICR0_ENA_VFLR_MASK |
  2336. I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  2337. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  2338. /* SW_ITR_IDX = 0, but don't change INTENA */
  2339. wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
  2340. I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
  2341. /* OTHER_ITR_IDX = 0 */
  2342. wr32(hw, I40E_PFINT_STAT_CTL0, 0);
  2343. }
  2344. /**
  2345. * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
  2346. * @vsi: the VSI being configured
  2347. **/
  2348. static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
  2349. {
  2350. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  2351. struct i40e_pf *pf = vsi->back;
  2352. struct i40e_hw *hw = &pf->hw;
  2353. u32 val;
  2354. /* set the ITR configuration */
  2355. q_vector->rx.itr = ITR_TO_REG(vsi->rx_itr_setting);
  2356. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  2357. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr);
  2358. q_vector->tx.itr = ITR_TO_REG(vsi->tx_itr_setting);
  2359. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  2360. wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr);
  2361. i40e_enable_misc_int_causes(hw);
  2362. /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
  2363. wr32(hw, I40E_PFINT_LNKLST0, 0);
  2364. /* Associate the queue pair to the vector and enable the queue int */
  2365. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  2366. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  2367. (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  2368. wr32(hw, I40E_QINT_RQCTL(0), val);
  2369. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  2370. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  2371. (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  2372. wr32(hw, I40E_QINT_TQCTL(0), val);
  2373. i40e_flush(hw);
  2374. }
  2375. /**
  2376. * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
  2377. * @pf: board private structure
  2378. **/
  2379. void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
  2380. {
  2381. struct i40e_hw *hw = &pf->hw;
  2382. wr32(hw, I40E_PFINT_DYN_CTL0,
  2383. I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
  2384. i40e_flush(hw);
  2385. }
  2386. /**
  2387. * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
  2388. * @pf: board private structure
  2389. **/
  2390. void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf)
  2391. {
  2392. struct i40e_hw *hw = &pf->hw;
  2393. u32 val;
  2394. val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
  2395. I40E_PFINT_DYN_CTL0_CLEARPBA_MASK |
  2396. (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
  2397. wr32(hw, I40E_PFINT_DYN_CTL0, val);
  2398. i40e_flush(hw);
  2399. }
  2400. /**
  2401. * i40e_irq_dynamic_enable - Enable default interrupt generation settings
  2402. * @vsi: pointer to a vsi
  2403. * @vector: enable a particular Hw Interrupt vector
  2404. **/
  2405. void i40e_irq_dynamic_enable(struct i40e_vsi *vsi, int vector)
  2406. {
  2407. struct i40e_pf *pf = vsi->back;
  2408. struct i40e_hw *hw = &pf->hw;
  2409. u32 val;
  2410. val = I40E_PFINT_DYN_CTLN_INTENA_MASK |
  2411. I40E_PFINT_DYN_CTLN_CLEARPBA_MASK |
  2412. (I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
  2413. wr32(hw, I40E_PFINT_DYN_CTLN(vector - 1), val);
  2414. /* skip the flush */
  2415. }
  2416. /**
  2417. * i40e_msix_clean_rings - MSIX mode Interrupt Handler
  2418. * @irq: interrupt number
  2419. * @data: pointer to a q_vector
  2420. **/
  2421. static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
  2422. {
  2423. struct i40e_q_vector *q_vector = data;
  2424. if (!q_vector->tx.ring && !q_vector->rx.ring)
  2425. return IRQ_HANDLED;
  2426. napi_schedule(&q_vector->napi);
  2427. return IRQ_HANDLED;
  2428. }
  2429. /**
  2430. * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
  2431. * @vsi: the VSI being configured
  2432. * @basename: name for the vector
  2433. *
  2434. * Allocates MSI-X vectors and requests interrupts from the kernel.
  2435. **/
  2436. static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
  2437. {
  2438. int q_vectors = vsi->num_q_vectors;
  2439. struct i40e_pf *pf = vsi->back;
  2440. int base = vsi->base_vector;
  2441. int rx_int_idx = 0;
  2442. int tx_int_idx = 0;
  2443. int vector, err;
  2444. for (vector = 0; vector < q_vectors; vector++) {
  2445. struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
  2446. if (q_vector->tx.ring && q_vector->rx.ring) {
  2447. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2448. "%s-%s-%d", basename, "TxRx", rx_int_idx++);
  2449. tx_int_idx++;
  2450. } else if (q_vector->rx.ring) {
  2451. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2452. "%s-%s-%d", basename, "rx", rx_int_idx++);
  2453. } else if (q_vector->tx.ring) {
  2454. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2455. "%s-%s-%d", basename, "tx", tx_int_idx++);
  2456. } else {
  2457. /* skip this unused q_vector */
  2458. continue;
  2459. }
  2460. err = request_irq(pf->msix_entries[base + vector].vector,
  2461. vsi->irq_handler,
  2462. 0,
  2463. q_vector->name,
  2464. q_vector);
  2465. if (err) {
  2466. dev_info(&pf->pdev->dev,
  2467. "%s: request_irq failed, error: %d\n",
  2468. __func__, err);
  2469. goto free_queue_irqs;
  2470. }
  2471. /* assign the mask for this irq */
  2472. irq_set_affinity_hint(pf->msix_entries[base + vector].vector,
  2473. &q_vector->affinity_mask);
  2474. }
  2475. vsi->irqs_ready = true;
  2476. return 0;
  2477. free_queue_irqs:
  2478. while (vector) {
  2479. vector--;
  2480. irq_set_affinity_hint(pf->msix_entries[base + vector].vector,
  2481. NULL);
  2482. free_irq(pf->msix_entries[base + vector].vector,
  2483. &(vsi->q_vectors[vector]));
  2484. }
  2485. return err;
  2486. }
  2487. /**
  2488. * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
  2489. * @vsi: the VSI being un-configured
  2490. **/
  2491. static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
  2492. {
  2493. struct i40e_pf *pf = vsi->back;
  2494. struct i40e_hw *hw = &pf->hw;
  2495. int base = vsi->base_vector;
  2496. int i;
  2497. for (i = 0; i < vsi->num_queue_pairs; i++) {
  2498. wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0);
  2499. wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0);
  2500. }
  2501. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  2502. for (i = vsi->base_vector;
  2503. i < (vsi->num_q_vectors + vsi->base_vector); i++)
  2504. wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
  2505. i40e_flush(hw);
  2506. for (i = 0; i < vsi->num_q_vectors; i++)
  2507. synchronize_irq(pf->msix_entries[i + base].vector);
  2508. } else {
  2509. /* Legacy and MSI mode - this stops all interrupt handling */
  2510. wr32(hw, I40E_PFINT_ICR0_ENA, 0);
  2511. wr32(hw, I40E_PFINT_DYN_CTL0, 0);
  2512. i40e_flush(hw);
  2513. synchronize_irq(pf->pdev->irq);
  2514. }
  2515. }
  2516. /**
  2517. * i40e_vsi_enable_irq - Enable IRQ for the given VSI
  2518. * @vsi: the VSI being configured
  2519. **/
  2520. static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
  2521. {
  2522. struct i40e_pf *pf = vsi->back;
  2523. int i;
  2524. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  2525. for (i = vsi->base_vector;
  2526. i < (vsi->num_q_vectors + vsi->base_vector); i++)
  2527. i40e_irq_dynamic_enable(vsi, i);
  2528. } else {
  2529. i40e_irq_dynamic_enable_icr0(pf);
  2530. }
  2531. i40e_flush(&pf->hw);
  2532. return 0;
  2533. }
  2534. /**
  2535. * i40e_stop_misc_vector - Stop the vector that handles non-queue events
  2536. * @pf: board private structure
  2537. **/
  2538. static void i40e_stop_misc_vector(struct i40e_pf *pf)
  2539. {
  2540. /* Disable ICR 0 */
  2541. wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
  2542. i40e_flush(&pf->hw);
  2543. }
  2544. /**
  2545. * i40e_intr - MSI/Legacy and non-queue interrupt handler
  2546. * @irq: interrupt number
  2547. * @data: pointer to a q_vector
  2548. *
  2549. * This is the handler used for all MSI/Legacy interrupts, and deals
  2550. * with both queue and non-queue interrupts. This is also used in
  2551. * MSIX mode to handle the non-queue interrupts.
  2552. **/
  2553. static irqreturn_t i40e_intr(int irq, void *data)
  2554. {
  2555. struct i40e_pf *pf = (struct i40e_pf *)data;
  2556. struct i40e_hw *hw = &pf->hw;
  2557. irqreturn_t ret = IRQ_NONE;
  2558. u32 icr0, icr0_remaining;
  2559. u32 val, ena_mask;
  2560. icr0 = rd32(hw, I40E_PFINT_ICR0);
  2561. ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
  2562. /* if sharing a legacy IRQ, we might get called w/o an intr pending */
  2563. if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
  2564. goto enable_intr;
  2565. /* if interrupt but no bits showing, must be SWINT */
  2566. if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
  2567. (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
  2568. pf->sw_int_count++;
  2569. /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
  2570. if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
  2571. /* temporarily disable queue cause for NAPI processing */
  2572. u32 qval = rd32(hw, I40E_QINT_RQCTL(0));
  2573. qval &= ~I40E_QINT_RQCTL_CAUSE_ENA_MASK;
  2574. wr32(hw, I40E_QINT_RQCTL(0), qval);
  2575. qval = rd32(hw, I40E_QINT_TQCTL(0));
  2576. qval &= ~I40E_QINT_TQCTL_CAUSE_ENA_MASK;
  2577. wr32(hw, I40E_QINT_TQCTL(0), qval);
  2578. if (!test_bit(__I40E_DOWN, &pf->state))
  2579. napi_schedule(&pf->vsi[pf->lan_vsi]->q_vectors[0]->napi);
  2580. }
  2581. if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
  2582. ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  2583. set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
  2584. }
  2585. if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
  2586. ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  2587. set_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
  2588. }
  2589. if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
  2590. ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
  2591. set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
  2592. }
  2593. if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
  2594. if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
  2595. set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
  2596. ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
  2597. val = rd32(hw, I40E_GLGEN_RSTAT);
  2598. val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
  2599. >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
  2600. if (val == I40E_RESET_CORER) {
  2601. pf->corer_count++;
  2602. } else if (val == I40E_RESET_GLOBR) {
  2603. pf->globr_count++;
  2604. } else if (val == I40E_RESET_EMPR) {
  2605. pf->empr_count++;
  2606. set_bit(__I40E_EMP_RESET_REQUESTED, &pf->state);
  2607. }
  2608. }
  2609. if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
  2610. icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
  2611. dev_info(&pf->pdev->dev, "HMC error interrupt\n");
  2612. }
  2613. if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
  2614. u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
  2615. if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
  2616. icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  2617. i40e_ptp_tx_hwtstamp(pf);
  2618. }
  2619. }
  2620. /* If a critical error is pending we have no choice but to reset the
  2621. * device.
  2622. * Report and mask out any remaining unexpected interrupts.
  2623. */
  2624. icr0_remaining = icr0 & ena_mask;
  2625. if (icr0_remaining) {
  2626. dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
  2627. icr0_remaining);
  2628. if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
  2629. (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
  2630. (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
  2631. dev_info(&pf->pdev->dev, "device will be reset\n");
  2632. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  2633. i40e_service_event_schedule(pf);
  2634. }
  2635. ena_mask &= ~icr0_remaining;
  2636. }
  2637. ret = IRQ_HANDLED;
  2638. enable_intr:
  2639. /* re-enable interrupt causes */
  2640. wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
  2641. if (!test_bit(__I40E_DOWN, &pf->state)) {
  2642. i40e_service_event_schedule(pf);
  2643. i40e_irq_dynamic_enable_icr0(pf);
  2644. }
  2645. return ret;
  2646. }
  2647. /**
  2648. * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
  2649. * @tx_ring: tx ring to clean
  2650. * @budget: how many cleans we're allowed
  2651. *
  2652. * Returns true if there's any budget left (e.g. the clean is finished)
  2653. **/
  2654. static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
  2655. {
  2656. struct i40e_vsi *vsi = tx_ring->vsi;
  2657. u16 i = tx_ring->next_to_clean;
  2658. struct i40e_tx_buffer *tx_buf;
  2659. struct i40e_tx_desc *tx_desc;
  2660. tx_buf = &tx_ring->tx_bi[i];
  2661. tx_desc = I40E_TX_DESC(tx_ring, i);
  2662. i -= tx_ring->count;
  2663. do {
  2664. struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
  2665. /* if next_to_watch is not set then there is no work pending */
  2666. if (!eop_desc)
  2667. break;
  2668. /* prevent any other reads prior to eop_desc */
  2669. read_barrier_depends();
  2670. /* if the descriptor isn't done, no work yet to do */
  2671. if (!(eop_desc->cmd_type_offset_bsz &
  2672. cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
  2673. break;
  2674. /* clear next_to_watch to prevent false hangs */
  2675. tx_buf->next_to_watch = NULL;
  2676. /* unmap skb header data */
  2677. dma_unmap_single(tx_ring->dev,
  2678. dma_unmap_addr(tx_buf, dma),
  2679. dma_unmap_len(tx_buf, len),
  2680. DMA_TO_DEVICE);
  2681. dma_unmap_len_set(tx_buf, len, 0);
  2682. /* move to the next desc and buffer to clean */
  2683. tx_buf++;
  2684. tx_desc++;
  2685. i++;
  2686. if (unlikely(!i)) {
  2687. i -= tx_ring->count;
  2688. tx_buf = tx_ring->tx_bi;
  2689. tx_desc = I40E_TX_DESC(tx_ring, 0);
  2690. }
  2691. /* update budget accounting */
  2692. budget--;
  2693. } while (likely(budget));
  2694. i += tx_ring->count;
  2695. tx_ring->next_to_clean = i;
  2696. if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED) {
  2697. i40e_irq_dynamic_enable(vsi,
  2698. tx_ring->q_vector->v_idx + vsi->base_vector);
  2699. }
  2700. return budget > 0;
  2701. }
  2702. /**
  2703. * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
  2704. * @irq: interrupt number
  2705. * @data: pointer to a q_vector
  2706. **/
  2707. static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
  2708. {
  2709. struct i40e_q_vector *q_vector = data;
  2710. struct i40e_vsi *vsi;
  2711. if (!q_vector->tx.ring)
  2712. return IRQ_HANDLED;
  2713. vsi = q_vector->tx.ring->vsi;
  2714. i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
  2715. return IRQ_HANDLED;
  2716. }
  2717. /**
  2718. * i40e_map_vector_to_qp - Assigns the queue pair to the vector
  2719. * @vsi: the VSI being configured
  2720. * @v_idx: vector index
  2721. * @qp_idx: queue pair index
  2722. **/
  2723. static void map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
  2724. {
  2725. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  2726. struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
  2727. struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
  2728. tx_ring->q_vector = q_vector;
  2729. tx_ring->next = q_vector->tx.ring;
  2730. q_vector->tx.ring = tx_ring;
  2731. q_vector->tx.count++;
  2732. rx_ring->q_vector = q_vector;
  2733. rx_ring->next = q_vector->rx.ring;
  2734. q_vector->rx.ring = rx_ring;
  2735. q_vector->rx.count++;
  2736. }
  2737. /**
  2738. * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
  2739. * @vsi: the VSI being configured
  2740. *
  2741. * This function maps descriptor rings to the queue-specific vectors
  2742. * we were allotted through the MSI-X enabling code. Ideally, we'd have
  2743. * one vector per queue pair, but on a constrained vector budget, we
  2744. * group the queue pairs as "efficiently" as possible.
  2745. **/
  2746. static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
  2747. {
  2748. int qp_remaining = vsi->num_queue_pairs;
  2749. int q_vectors = vsi->num_q_vectors;
  2750. int num_ringpairs;
  2751. int v_start = 0;
  2752. int qp_idx = 0;
  2753. /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
  2754. * group them so there are multiple queues per vector.
  2755. */
  2756. for (; v_start < q_vectors && qp_remaining; v_start++) {
  2757. struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
  2758. num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
  2759. q_vector->num_ringpairs = num_ringpairs;
  2760. q_vector->rx.count = 0;
  2761. q_vector->tx.count = 0;
  2762. q_vector->rx.ring = NULL;
  2763. q_vector->tx.ring = NULL;
  2764. while (num_ringpairs--) {
  2765. map_vector_to_qp(vsi, v_start, qp_idx);
  2766. qp_idx++;
  2767. qp_remaining--;
  2768. }
  2769. }
  2770. }
  2771. /**
  2772. * i40e_vsi_request_irq - Request IRQ from the OS
  2773. * @vsi: the VSI being configured
  2774. * @basename: name for the vector
  2775. **/
  2776. static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
  2777. {
  2778. struct i40e_pf *pf = vsi->back;
  2779. int err;
  2780. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  2781. err = i40e_vsi_request_irq_msix(vsi, basename);
  2782. else if (pf->flags & I40E_FLAG_MSI_ENABLED)
  2783. err = request_irq(pf->pdev->irq, i40e_intr, 0,
  2784. pf->misc_int_name, pf);
  2785. else
  2786. err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
  2787. pf->misc_int_name, pf);
  2788. if (err)
  2789. dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
  2790. return err;
  2791. }
  2792. #ifdef CONFIG_NET_POLL_CONTROLLER
  2793. /**
  2794. * i40e_netpoll - A Polling 'interrupt'handler
  2795. * @netdev: network interface device structure
  2796. *
  2797. * This is used by netconsole to send skbs without having to re-enable
  2798. * interrupts. It's not called while the normal interrupt routine is executing.
  2799. **/
  2800. static void i40e_netpoll(struct net_device *netdev)
  2801. {
  2802. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2803. struct i40e_vsi *vsi = np->vsi;
  2804. struct i40e_pf *pf = vsi->back;
  2805. int i;
  2806. /* if interface is down do nothing */
  2807. if (test_bit(__I40E_DOWN, &vsi->state))
  2808. return;
  2809. pf->flags |= I40E_FLAG_IN_NETPOLL;
  2810. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  2811. for (i = 0; i < vsi->num_q_vectors; i++)
  2812. i40e_msix_clean_rings(0, vsi->q_vectors[i]);
  2813. } else {
  2814. i40e_intr(pf->pdev->irq, netdev);
  2815. }
  2816. pf->flags &= ~I40E_FLAG_IN_NETPOLL;
  2817. }
  2818. #endif
  2819. /**
  2820. * i40e_vsi_control_tx - Start or stop a VSI's rings
  2821. * @vsi: the VSI being configured
  2822. * @enable: start or stop the rings
  2823. **/
  2824. static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
  2825. {
  2826. struct i40e_pf *pf = vsi->back;
  2827. struct i40e_hw *hw = &pf->hw;
  2828. int i, j, pf_q;
  2829. u32 tx_reg;
  2830. pf_q = vsi->base_queue;
  2831. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  2832. /* warn the TX unit of coming changes */
  2833. i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
  2834. if (!enable)
  2835. udelay(10);
  2836. for (j = 0; j < 50; j++) {
  2837. tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
  2838. if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
  2839. ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
  2840. break;
  2841. usleep_range(1000, 2000);
  2842. }
  2843. /* Skip if the queue is already in the requested state */
  2844. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  2845. continue;
  2846. /* turn on/off the queue */
  2847. if (enable) {
  2848. wr32(hw, I40E_QTX_HEAD(pf_q), 0);
  2849. tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
  2850. } else {
  2851. tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
  2852. }
  2853. wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
  2854. /* wait for the change to finish */
  2855. for (j = 0; j < 10; j++) {
  2856. tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
  2857. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  2858. break;
  2859. udelay(10);
  2860. }
  2861. if (j >= 10) {
  2862. dev_info(&pf->pdev->dev, "Tx ring %d %sable timeout\n",
  2863. pf_q, (enable ? "en" : "dis"));
  2864. return -ETIMEDOUT;
  2865. }
  2866. }
  2867. if (hw->revision_id == 0)
  2868. mdelay(50);
  2869. return 0;
  2870. }
  2871. /**
  2872. * i40e_vsi_control_rx - Start or stop a VSI's rings
  2873. * @vsi: the VSI being configured
  2874. * @enable: start or stop the rings
  2875. **/
  2876. static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
  2877. {
  2878. struct i40e_pf *pf = vsi->back;
  2879. struct i40e_hw *hw = &pf->hw;
  2880. int i, j, pf_q;
  2881. u32 rx_reg;
  2882. pf_q = vsi->base_queue;
  2883. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  2884. for (j = 0; j < 50; j++) {
  2885. rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
  2886. if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
  2887. ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
  2888. break;
  2889. usleep_range(1000, 2000);
  2890. }
  2891. /* Skip if the queue is already in the requested state */
  2892. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  2893. continue;
  2894. /* turn on/off the queue */
  2895. if (enable)
  2896. rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
  2897. else
  2898. rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
  2899. wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
  2900. /* wait for the change to finish */
  2901. for (j = 0; j < 10; j++) {
  2902. rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
  2903. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  2904. break;
  2905. udelay(10);
  2906. }
  2907. if (j >= 10) {
  2908. dev_info(&pf->pdev->dev, "Rx ring %d %sable timeout\n",
  2909. pf_q, (enable ? "en" : "dis"));
  2910. return -ETIMEDOUT;
  2911. }
  2912. }
  2913. return 0;
  2914. }
  2915. /**
  2916. * i40e_vsi_control_rings - Start or stop a VSI's rings
  2917. * @vsi: the VSI being configured
  2918. * @enable: start or stop the rings
  2919. **/
  2920. int i40e_vsi_control_rings(struct i40e_vsi *vsi, bool request)
  2921. {
  2922. int ret = 0;
  2923. /* do rx first for enable and last for disable */
  2924. if (request) {
  2925. ret = i40e_vsi_control_rx(vsi, request);
  2926. if (ret)
  2927. return ret;
  2928. ret = i40e_vsi_control_tx(vsi, request);
  2929. } else {
  2930. /* Ignore return value, we need to shutdown whatever we can */
  2931. i40e_vsi_control_tx(vsi, request);
  2932. i40e_vsi_control_rx(vsi, request);
  2933. }
  2934. return ret;
  2935. }
  2936. /**
  2937. * i40e_vsi_free_irq - Free the irq association with the OS
  2938. * @vsi: the VSI being configured
  2939. **/
  2940. static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
  2941. {
  2942. struct i40e_pf *pf = vsi->back;
  2943. struct i40e_hw *hw = &pf->hw;
  2944. int base = vsi->base_vector;
  2945. u32 val, qp;
  2946. int i;
  2947. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  2948. if (!vsi->q_vectors)
  2949. return;
  2950. if (!vsi->irqs_ready)
  2951. return;
  2952. vsi->irqs_ready = false;
  2953. for (i = 0; i < vsi->num_q_vectors; i++) {
  2954. u16 vector = i + base;
  2955. /* free only the irqs that were actually requested */
  2956. if (!vsi->q_vectors[i] ||
  2957. !vsi->q_vectors[i]->num_ringpairs)
  2958. continue;
  2959. /* clear the affinity_mask in the IRQ descriptor */
  2960. irq_set_affinity_hint(pf->msix_entries[vector].vector,
  2961. NULL);
  2962. free_irq(pf->msix_entries[vector].vector,
  2963. vsi->q_vectors[i]);
  2964. /* Tear down the interrupt queue link list
  2965. *
  2966. * We know that they come in pairs and always
  2967. * the Rx first, then the Tx. To clear the
  2968. * link list, stick the EOL value into the
  2969. * next_q field of the registers.
  2970. */
  2971. val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
  2972. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  2973. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  2974. val |= I40E_QUEUE_END_OF_LIST
  2975. << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  2976. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
  2977. while (qp != I40E_QUEUE_END_OF_LIST) {
  2978. u32 next;
  2979. val = rd32(hw, I40E_QINT_RQCTL(qp));
  2980. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  2981. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  2982. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  2983. I40E_QINT_RQCTL_INTEVENT_MASK);
  2984. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  2985. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  2986. wr32(hw, I40E_QINT_RQCTL(qp), val);
  2987. val = rd32(hw, I40E_QINT_TQCTL(qp));
  2988. next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
  2989. >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
  2990. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  2991. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  2992. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  2993. I40E_QINT_TQCTL_INTEVENT_MASK);
  2994. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  2995. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  2996. wr32(hw, I40E_QINT_TQCTL(qp), val);
  2997. qp = next;
  2998. }
  2999. }
  3000. } else {
  3001. free_irq(pf->pdev->irq, pf);
  3002. val = rd32(hw, I40E_PFINT_LNKLST0);
  3003. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  3004. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3005. val |= I40E_QUEUE_END_OF_LIST
  3006. << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
  3007. wr32(hw, I40E_PFINT_LNKLST0, val);
  3008. val = rd32(hw, I40E_QINT_RQCTL(qp));
  3009. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  3010. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  3011. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3012. I40E_QINT_RQCTL_INTEVENT_MASK);
  3013. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  3014. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  3015. wr32(hw, I40E_QINT_RQCTL(qp), val);
  3016. val = rd32(hw, I40E_QINT_TQCTL(qp));
  3017. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  3018. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  3019. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3020. I40E_QINT_TQCTL_INTEVENT_MASK);
  3021. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  3022. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  3023. wr32(hw, I40E_QINT_TQCTL(qp), val);
  3024. }
  3025. }
  3026. /**
  3027. * i40e_free_q_vector - Free memory allocated for specific interrupt vector
  3028. * @vsi: the VSI being configured
  3029. * @v_idx: Index of vector to be freed
  3030. *
  3031. * This function frees the memory allocated to the q_vector. In addition if
  3032. * NAPI is enabled it will delete any references to the NAPI struct prior
  3033. * to freeing the q_vector.
  3034. **/
  3035. static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
  3036. {
  3037. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  3038. struct i40e_ring *ring;
  3039. if (!q_vector)
  3040. return;
  3041. /* disassociate q_vector from rings */
  3042. i40e_for_each_ring(ring, q_vector->tx)
  3043. ring->q_vector = NULL;
  3044. i40e_for_each_ring(ring, q_vector->rx)
  3045. ring->q_vector = NULL;
  3046. /* only VSI w/ an associated netdev is set up w/ NAPI */
  3047. if (vsi->netdev)
  3048. netif_napi_del(&q_vector->napi);
  3049. vsi->q_vectors[v_idx] = NULL;
  3050. kfree_rcu(q_vector, rcu);
  3051. }
  3052. /**
  3053. * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
  3054. * @vsi: the VSI being un-configured
  3055. *
  3056. * This frees the memory allocated to the q_vectors and
  3057. * deletes references to the NAPI struct.
  3058. **/
  3059. static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
  3060. {
  3061. int v_idx;
  3062. for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
  3063. i40e_free_q_vector(vsi, v_idx);
  3064. }
  3065. /**
  3066. * i40e_reset_interrupt_capability - Disable interrupt setup in OS
  3067. * @pf: board private structure
  3068. **/
  3069. static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
  3070. {
  3071. /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
  3072. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3073. pci_disable_msix(pf->pdev);
  3074. kfree(pf->msix_entries);
  3075. pf->msix_entries = NULL;
  3076. } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
  3077. pci_disable_msi(pf->pdev);
  3078. }
  3079. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
  3080. }
  3081. /**
  3082. * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
  3083. * @pf: board private structure
  3084. *
  3085. * We go through and clear interrupt specific resources and reset the structure
  3086. * to pre-load conditions
  3087. **/
  3088. static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
  3089. {
  3090. int i;
  3091. i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
  3092. for (i = 0; i < pf->num_alloc_vsi; i++)
  3093. if (pf->vsi[i])
  3094. i40e_vsi_free_q_vectors(pf->vsi[i]);
  3095. i40e_reset_interrupt_capability(pf);
  3096. }
  3097. /**
  3098. * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
  3099. * @vsi: the VSI being configured
  3100. **/
  3101. static void i40e_napi_enable_all(struct i40e_vsi *vsi)
  3102. {
  3103. int q_idx;
  3104. if (!vsi->netdev)
  3105. return;
  3106. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
  3107. napi_enable(&vsi->q_vectors[q_idx]->napi);
  3108. }
  3109. /**
  3110. * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
  3111. * @vsi: the VSI being configured
  3112. **/
  3113. static void i40e_napi_disable_all(struct i40e_vsi *vsi)
  3114. {
  3115. int q_idx;
  3116. if (!vsi->netdev)
  3117. return;
  3118. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
  3119. napi_disable(&vsi->q_vectors[q_idx]->napi);
  3120. }
  3121. /**
  3122. * i40e_vsi_close - Shut down a VSI
  3123. * @vsi: the vsi to be quelled
  3124. **/
  3125. static void i40e_vsi_close(struct i40e_vsi *vsi)
  3126. {
  3127. if (!test_and_set_bit(__I40E_DOWN, &vsi->state))
  3128. i40e_down(vsi);
  3129. i40e_vsi_free_irq(vsi);
  3130. i40e_vsi_free_tx_resources(vsi);
  3131. i40e_vsi_free_rx_resources(vsi);
  3132. }
  3133. /**
  3134. * i40e_quiesce_vsi - Pause a given VSI
  3135. * @vsi: the VSI being paused
  3136. **/
  3137. static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
  3138. {
  3139. if (test_bit(__I40E_DOWN, &vsi->state))
  3140. return;
  3141. set_bit(__I40E_NEEDS_RESTART, &vsi->state);
  3142. if (vsi->netdev && netif_running(vsi->netdev)) {
  3143. vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
  3144. } else {
  3145. i40e_vsi_close(vsi);
  3146. }
  3147. }
  3148. /**
  3149. * i40e_unquiesce_vsi - Resume a given VSI
  3150. * @vsi: the VSI being resumed
  3151. **/
  3152. static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
  3153. {
  3154. if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state))
  3155. return;
  3156. clear_bit(__I40E_NEEDS_RESTART, &vsi->state);
  3157. if (vsi->netdev && netif_running(vsi->netdev))
  3158. vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
  3159. else
  3160. i40e_vsi_open(vsi); /* this clears the DOWN bit */
  3161. }
  3162. /**
  3163. * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
  3164. * @pf: the PF
  3165. **/
  3166. static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
  3167. {
  3168. int v;
  3169. for (v = 0; v < pf->num_alloc_vsi; v++) {
  3170. if (pf->vsi[v])
  3171. i40e_quiesce_vsi(pf->vsi[v]);
  3172. }
  3173. }
  3174. /**
  3175. * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
  3176. * @pf: the PF
  3177. **/
  3178. static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
  3179. {
  3180. int v;
  3181. for (v = 0; v < pf->num_alloc_vsi; v++) {
  3182. if (pf->vsi[v])
  3183. i40e_unquiesce_vsi(pf->vsi[v]);
  3184. }
  3185. }
  3186. /**
  3187. * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
  3188. * @dcbcfg: the corresponding DCBx configuration structure
  3189. *
  3190. * Return the number of TCs from given DCBx configuration
  3191. **/
  3192. static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
  3193. {
  3194. u8 num_tc = 0;
  3195. int i;
  3196. /* Scan the ETS Config Priority Table to find
  3197. * traffic class enabled for a given priority
  3198. * and use the traffic class index to get the
  3199. * number of traffic classes enabled
  3200. */
  3201. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  3202. if (dcbcfg->etscfg.prioritytable[i] > num_tc)
  3203. num_tc = dcbcfg->etscfg.prioritytable[i];
  3204. }
  3205. /* Traffic class index starts from zero so
  3206. * increment to return the actual count
  3207. */
  3208. return num_tc + 1;
  3209. }
  3210. /**
  3211. * i40e_dcb_get_enabled_tc - Get enabled traffic classes
  3212. * @dcbcfg: the corresponding DCBx configuration structure
  3213. *
  3214. * Query the current DCB configuration and return the number of
  3215. * traffic classes enabled from the given DCBX config
  3216. **/
  3217. static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
  3218. {
  3219. u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
  3220. u8 enabled_tc = 1;
  3221. u8 i;
  3222. for (i = 0; i < num_tc; i++)
  3223. enabled_tc |= 1 << i;
  3224. return enabled_tc;
  3225. }
  3226. /**
  3227. * i40e_pf_get_num_tc - Get enabled traffic classes for PF
  3228. * @pf: PF being queried
  3229. *
  3230. * Return number of traffic classes enabled for the given PF
  3231. **/
  3232. static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
  3233. {
  3234. struct i40e_hw *hw = &pf->hw;
  3235. u8 i, enabled_tc;
  3236. u8 num_tc = 0;
  3237. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  3238. /* If DCB is not enabled then always in single TC */
  3239. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  3240. return 1;
  3241. /* MFP mode return count of enabled TCs for this PF */
  3242. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  3243. enabled_tc = pf->hw.func_caps.enabled_tcmap;
  3244. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  3245. if (enabled_tc & (1 << i))
  3246. num_tc++;
  3247. }
  3248. return num_tc;
  3249. }
  3250. /* SFP mode will be enabled for all TCs on port */
  3251. return i40e_dcb_get_num_tc(dcbcfg);
  3252. }
  3253. /**
  3254. * i40e_pf_get_default_tc - Get bitmap for first enabled TC
  3255. * @pf: PF being queried
  3256. *
  3257. * Return a bitmap for first enabled traffic class for this PF.
  3258. **/
  3259. static u8 i40e_pf_get_default_tc(struct i40e_pf *pf)
  3260. {
  3261. u8 enabled_tc = pf->hw.func_caps.enabled_tcmap;
  3262. u8 i = 0;
  3263. if (!enabled_tc)
  3264. return 0x1; /* TC0 */
  3265. /* Find the first enabled TC */
  3266. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  3267. if (enabled_tc & (1 << i))
  3268. break;
  3269. }
  3270. return 1 << i;
  3271. }
  3272. /**
  3273. * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
  3274. * @pf: PF being queried
  3275. *
  3276. * Return a bitmap for enabled traffic classes for this PF.
  3277. **/
  3278. static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
  3279. {
  3280. /* If DCB is not enabled for this PF then just return default TC */
  3281. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  3282. return i40e_pf_get_default_tc(pf);
  3283. /* MFP mode will have enabled TCs set by FW */
  3284. if (pf->flags & I40E_FLAG_MFP_ENABLED)
  3285. return pf->hw.func_caps.enabled_tcmap;
  3286. /* SFP mode we want PF to be enabled for all TCs */
  3287. return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
  3288. }
  3289. /**
  3290. * i40e_vsi_get_bw_info - Query VSI BW Information
  3291. * @vsi: the VSI being queried
  3292. *
  3293. * Returns 0 on success, negative value on failure
  3294. **/
  3295. static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
  3296. {
  3297. struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
  3298. struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
  3299. struct i40e_pf *pf = vsi->back;
  3300. struct i40e_hw *hw = &pf->hw;
  3301. i40e_status aq_ret;
  3302. u32 tc_bw_max;
  3303. int i;
  3304. /* Get the VSI level BW configuration */
  3305. aq_ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
  3306. if (aq_ret) {
  3307. dev_info(&pf->pdev->dev,
  3308. "couldn't get pf vsi bw config, err %d, aq_err %d\n",
  3309. aq_ret, pf->hw.aq.asq_last_status);
  3310. return -EINVAL;
  3311. }
  3312. /* Get the VSI level BW configuration per TC */
  3313. aq_ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
  3314. NULL);
  3315. if (aq_ret) {
  3316. dev_info(&pf->pdev->dev,
  3317. "couldn't get pf vsi ets bw config, err %d, aq_err %d\n",
  3318. aq_ret, pf->hw.aq.asq_last_status);
  3319. return -EINVAL;
  3320. }
  3321. if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
  3322. dev_info(&pf->pdev->dev,
  3323. "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
  3324. bw_config.tc_valid_bits,
  3325. bw_ets_config.tc_valid_bits);
  3326. /* Still continuing */
  3327. }
  3328. vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
  3329. vsi->bw_max_quanta = bw_config.max_bw;
  3330. tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
  3331. (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
  3332. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  3333. vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
  3334. vsi->bw_ets_limit_credits[i] =
  3335. le16_to_cpu(bw_ets_config.credits[i]);
  3336. /* 3 bits out of 4 for each TC */
  3337. vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
  3338. }
  3339. return 0;
  3340. }
  3341. /**
  3342. * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
  3343. * @vsi: the VSI being configured
  3344. * @enabled_tc: TC bitmap
  3345. * @bw_credits: BW shared credits per TC
  3346. *
  3347. * Returns 0 on success, negative value on failure
  3348. **/
  3349. static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
  3350. u8 *bw_share)
  3351. {
  3352. struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
  3353. i40e_status aq_ret;
  3354. int i;
  3355. bw_data.tc_valid_bits = enabled_tc;
  3356. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  3357. bw_data.tc_bw_credits[i] = bw_share[i];
  3358. aq_ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data,
  3359. NULL);
  3360. if (aq_ret) {
  3361. dev_info(&vsi->back->pdev->dev,
  3362. "AQ command Config VSI BW allocation per TC failed = %d\n",
  3363. vsi->back->hw.aq.asq_last_status);
  3364. return -EINVAL;
  3365. }
  3366. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  3367. vsi->info.qs_handle[i] = bw_data.qs_handles[i];
  3368. return 0;
  3369. }
  3370. /**
  3371. * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
  3372. * @vsi: the VSI being configured
  3373. * @enabled_tc: TC map to be enabled
  3374. *
  3375. **/
  3376. static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  3377. {
  3378. struct net_device *netdev = vsi->netdev;
  3379. struct i40e_pf *pf = vsi->back;
  3380. struct i40e_hw *hw = &pf->hw;
  3381. u8 netdev_tc = 0;
  3382. int i;
  3383. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  3384. if (!netdev)
  3385. return;
  3386. if (!enabled_tc) {
  3387. netdev_reset_tc(netdev);
  3388. return;
  3389. }
  3390. /* Set up actual enabled TCs on the VSI */
  3391. if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
  3392. return;
  3393. /* set per TC queues for the VSI */
  3394. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  3395. /* Only set TC queues for enabled tcs
  3396. *
  3397. * e.g. For a VSI that has TC0 and TC3 enabled the
  3398. * enabled_tc bitmap would be 0x00001001; the driver
  3399. * will set the numtc for netdev as 2 that will be
  3400. * referenced by the netdev layer as TC 0 and 1.
  3401. */
  3402. if (vsi->tc_config.enabled_tc & (1 << i))
  3403. netdev_set_tc_queue(netdev,
  3404. vsi->tc_config.tc_info[i].netdev_tc,
  3405. vsi->tc_config.tc_info[i].qcount,
  3406. vsi->tc_config.tc_info[i].qoffset);
  3407. }
  3408. /* Assign UP2TC map for the VSI */
  3409. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  3410. /* Get the actual TC# for the UP */
  3411. u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
  3412. /* Get the mapped netdev TC# for the UP */
  3413. netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
  3414. netdev_set_prio_tc_map(netdev, i, netdev_tc);
  3415. }
  3416. }
  3417. /**
  3418. * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
  3419. * @vsi: the VSI being configured
  3420. * @ctxt: the ctxt buffer returned from AQ VSI update param command
  3421. **/
  3422. static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
  3423. struct i40e_vsi_context *ctxt)
  3424. {
  3425. /* copy just the sections touched not the entire info
  3426. * since not all sections are valid as returned by
  3427. * update vsi params
  3428. */
  3429. vsi->info.mapping_flags = ctxt->info.mapping_flags;
  3430. memcpy(&vsi->info.queue_mapping,
  3431. &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
  3432. memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
  3433. sizeof(vsi->info.tc_mapping));
  3434. }
  3435. /**
  3436. * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
  3437. * @vsi: VSI to be configured
  3438. * @enabled_tc: TC bitmap
  3439. *
  3440. * This configures a particular VSI for TCs that are mapped to the
  3441. * given TC bitmap. It uses default bandwidth share for TCs across
  3442. * VSIs to configure TC for a particular VSI.
  3443. *
  3444. * NOTE:
  3445. * It is expected that the VSI queues have been quisced before calling
  3446. * this function.
  3447. **/
  3448. static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  3449. {
  3450. u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
  3451. struct i40e_vsi_context ctxt;
  3452. int ret = 0;
  3453. int i;
  3454. /* Check if enabled_tc is same as existing or new TCs */
  3455. if (vsi->tc_config.enabled_tc == enabled_tc)
  3456. return ret;
  3457. /* Enable ETS TCs with equal BW Share for now across all VSIs */
  3458. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  3459. if (enabled_tc & (1 << i))
  3460. bw_share[i] = 1;
  3461. }
  3462. ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
  3463. if (ret) {
  3464. dev_info(&vsi->back->pdev->dev,
  3465. "Failed configuring TC map %d for VSI %d\n",
  3466. enabled_tc, vsi->seid);
  3467. goto out;
  3468. }
  3469. /* Update Queue Pairs Mapping for currently enabled UPs */
  3470. ctxt.seid = vsi->seid;
  3471. ctxt.pf_num = vsi->back->hw.pf_id;
  3472. ctxt.vf_num = 0;
  3473. ctxt.uplink_seid = vsi->uplink_seid;
  3474. memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
  3475. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  3476. /* Update the VSI after updating the VSI queue-mapping information */
  3477. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  3478. if (ret) {
  3479. dev_info(&vsi->back->pdev->dev,
  3480. "update vsi failed, aq_err=%d\n",
  3481. vsi->back->hw.aq.asq_last_status);
  3482. goto out;
  3483. }
  3484. /* update the local VSI info with updated queue map */
  3485. i40e_vsi_update_queue_map(vsi, &ctxt);
  3486. vsi->info.valid_sections = 0;
  3487. /* Update current VSI BW information */
  3488. ret = i40e_vsi_get_bw_info(vsi);
  3489. if (ret) {
  3490. dev_info(&vsi->back->pdev->dev,
  3491. "Failed updating vsi bw info, aq_err=%d\n",
  3492. vsi->back->hw.aq.asq_last_status);
  3493. goto out;
  3494. }
  3495. /* Update the netdev TC setup */
  3496. i40e_vsi_config_netdev_tc(vsi, enabled_tc);
  3497. out:
  3498. return ret;
  3499. }
  3500. /**
  3501. * i40e_veb_config_tc - Configure TCs for given VEB
  3502. * @veb: given VEB
  3503. * @enabled_tc: TC bitmap
  3504. *
  3505. * Configures given TC bitmap for VEB (switching) element
  3506. **/
  3507. int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
  3508. {
  3509. struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
  3510. struct i40e_pf *pf = veb->pf;
  3511. int ret = 0;
  3512. int i;
  3513. /* No TCs or already enabled TCs just return */
  3514. if (!enabled_tc || veb->enabled_tc == enabled_tc)
  3515. return ret;
  3516. bw_data.tc_valid_bits = enabled_tc;
  3517. /* bw_data.absolute_credits is not set (relative) */
  3518. /* Enable ETS TCs with equal BW Share for now */
  3519. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  3520. if (enabled_tc & (1 << i))
  3521. bw_data.tc_bw_share_credits[i] = 1;
  3522. }
  3523. ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
  3524. &bw_data, NULL);
  3525. if (ret) {
  3526. dev_info(&pf->pdev->dev,
  3527. "veb bw config failed, aq_err=%d\n",
  3528. pf->hw.aq.asq_last_status);
  3529. goto out;
  3530. }
  3531. /* Update the BW information */
  3532. ret = i40e_veb_get_bw_info(veb);
  3533. if (ret) {
  3534. dev_info(&pf->pdev->dev,
  3535. "Failed getting veb bw config, aq_err=%d\n",
  3536. pf->hw.aq.asq_last_status);
  3537. }
  3538. out:
  3539. return ret;
  3540. }
  3541. #ifdef CONFIG_I40E_DCB
  3542. /**
  3543. * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
  3544. * @pf: PF struct
  3545. *
  3546. * Reconfigure VEB/VSIs on a given PF; it is assumed that
  3547. * the caller would've quiesce all the VSIs before calling
  3548. * this function
  3549. **/
  3550. static void i40e_dcb_reconfigure(struct i40e_pf *pf)
  3551. {
  3552. u8 tc_map = 0;
  3553. int ret;
  3554. u8 v;
  3555. /* Enable the TCs available on PF to all VEBs */
  3556. tc_map = i40e_pf_get_tc_map(pf);
  3557. for (v = 0; v < I40E_MAX_VEB; v++) {
  3558. if (!pf->veb[v])
  3559. continue;
  3560. ret = i40e_veb_config_tc(pf->veb[v], tc_map);
  3561. if (ret) {
  3562. dev_info(&pf->pdev->dev,
  3563. "Failed configuring TC for VEB seid=%d\n",
  3564. pf->veb[v]->seid);
  3565. /* Will try to configure as many components */
  3566. }
  3567. }
  3568. /* Update each VSI */
  3569. for (v = 0; v < pf->num_alloc_vsi; v++) {
  3570. if (!pf->vsi[v])
  3571. continue;
  3572. /* - Enable all TCs for the LAN VSI
  3573. * - For all others keep them at TC0 for now
  3574. */
  3575. if (v == pf->lan_vsi)
  3576. tc_map = i40e_pf_get_tc_map(pf);
  3577. else
  3578. tc_map = i40e_pf_get_default_tc(pf);
  3579. ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
  3580. if (ret) {
  3581. dev_info(&pf->pdev->dev,
  3582. "Failed configuring TC for VSI seid=%d\n",
  3583. pf->vsi[v]->seid);
  3584. /* Will try to configure as many components */
  3585. } else {
  3586. /* Re-configure VSI vectors based on updated TC map */
  3587. i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
  3588. if (pf->vsi[v]->netdev)
  3589. i40e_dcbnl_set_all(pf->vsi[v]);
  3590. }
  3591. }
  3592. }
  3593. /**
  3594. * i40e_init_pf_dcb - Initialize DCB configuration
  3595. * @pf: PF being configured
  3596. *
  3597. * Query the current DCB configuration and cache it
  3598. * in the hardware structure
  3599. **/
  3600. static int i40e_init_pf_dcb(struct i40e_pf *pf)
  3601. {
  3602. struct i40e_hw *hw = &pf->hw;
  3603. int err = 0;
  3604. if (pf->hw.func_caps.npar_enable)
  3605. goto out;
  3606. /* Get the initial DCB configuration */
  3607. err = i40e_init_dcb(hw);
  3608. if (!err) {
  3609. /* Device/Function is not DCBX capable */
  3610. if ((!hw->func_caps.dcb) ||
  3611. (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
  3612. dev_info(&pf->pdev->dev,
  3613. "DCBX offload is not supported or is disabled for this PF.\n");
  3614. if (pf->flags & I40E_FLAG_MFP_ENABLED)
  3615. goto out;
  3616. } else {
  3617. /* When status is not DISABLED then DCBX in FW */
  3618. pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
  3619. DCB_CAP_DCBX_VER_IEEE;
  3620. pf->flags |= I40E_FLAG_DCB_CAPABLE;
  3621. /* Enable DCB tagging only when more than one TC */
  3622. if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
  3623. pf->flags |= I40E_FLAG_DCB_ENABLED;
  3624. }
  3625. } else {
  3626. dev_info(&pf->pdev->dev, "AQ Querying DCB configuration failed: %d\n",
  3627. pf->hw.aq.asq_last_status);
  3628. }
  3629. out:
  3630. return err;
  3631. }
  3632. #endif /* CONFIG_I40E_DCB */
  3633. #define SPEED_SIZE 14
  3634. #define FC_SIZE 8
  3635. /**
  3636. * i40e_print_link_message - print link up or down
  3637. * @vsi: the VSI for which link needs a message
  3638. */
  3639. static void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
  3640. {
  3641. char speed[SPEED_SIZE] = "Unknown";
  3642. char fc[FC_SIZE] = "RX/TX";
  3643. if (!isup) {
  3644. netdev_info(vsi->netdev, "NIC Link is Down\n");
  3645. return;
  3646. }
  3647. switch (vsi->back->hw.phy.link_info.link_speed) {
  3648. case I40E_LINK_SPEED_40GB:
  3649. strncpy(speed, "40 Gbps", SPEED_SIZE);
  3650. break;
  3651. case I40E_LINK_SPEED_10GB:
  3652. strncpy(speed, "10 Gbps", SPEED_SIZE);
  3653. break;
  3654. case I40E_LINK_SPEED_1GB:
  3655. strncpy(speed, "1000 Mbps", SPEED_SIZE);
  3656. break;
  3657. default:
  3658. break;
  3659. }
  3660. switch (vsi->back->hw.fc.current_mode) {
  3661. case I40E_FC_FULL:
  3662. strncpy(fc, "RX/TX", FC_SIZE);
  3663. break;
  3664. case I40E_FC_TX_PAUSE:
  3665. strncpy(fc, "TX", FC_SIZE);
  3666. break;
  3667. case I40E_FC_RX_PAUSE:
  3668. strncpy(fc, "RX", FC_SIZE);
  3669. break;
  3670. default:
  3671. strncpy(fc, "None", FC_SIZE);
  3672. break;
  3673. }
  3674. netdev_info(vsi->netdev, "NIC Link is Up %s Full Duplex, Flow Control: %s\n",
  3675. speed, fc);
  3676. }
  3677. /**
  3678. * i40e_up_complete - Finish the last steps of bringing up a connection
  3679. * @vsi: the VSI being configured
  3680. **/
  3681. static int i40e_up_complete(struct i40e_vsi *vsi)
  3682. {
  3683. struct i40e_pf *pf = vsi->back;
  3684. int err;
  3685. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  3686. i40e_vsi_configure_msix(vsi);
  3687. else
  3688. i40e_configure_msi_and_legacy(vsi);
  3689. /* start rings */
  3690. err = i40e_vsi_control_rings(vsi, true);
  3691. if (err)
  3692. return err;
  3693. clear_bit(__I40E_DOWN, &vsi->state);
  3694. i40e_napi_enable_all(vsi);
  3695. i40e_vsi_enable_irq(vsi);
  3696. if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
  3697. (vsi->netdev)) {
  3698. i40e_print_link_message(vsi, true);
  3699. netif_tx_start_all_queues(vsi->netdev);
  3700. netif_carrier_on(vsi->netdev);
  3701. } else if (vsi->netdev) {
  3702. i40e_print_link_message(vsi, false);
  3703. }
  3704. /* replay FDIR SB filters */
  3705. if (vsi->type == I40E_VSI_FDIR)
  3706. i40e_fdir_filter_restore(vsi);
  3707. i40e_service_event_schedule(pf);
  3708. return 0;
  3709. }
  3710. /**
  3711. * i40e_vsi_reinit_locked - Reset the VSI
  3712. * @vsi: the VSI being configured
  3713. *
  3714. * Rebuild the ring structs after some configuration
  3715. * has changed, e.g. MTU size.
  3716. **/
  3717. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
  3718. {
  3719. struct i40e_pf *pf = vsi->back;
  3720. WARN_ON(in_interrupt());
  3721. while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
  3722. usleep_range(1000, 2000);
  3723. i40e_down(vsi);
  3724. /* Give a VF some time to respond to the reset. The
  3725. * two second wait is based upon the watchdog cycle in
  3726. * the VF driver.
  3727. */
  3728. if (vsi->type == I40E_VSI_SRIOV)
  3729. msleep(2000);
  3730. i40e_up(vsi);
  3731. clear_bit(__I40E_CONFIG_BUSY, &pf->state);
  3732. }
  3733. /**
  3734. * i40e_up - Bring the connection back up after being down
  3735. * @vsi: the VSI being configured
  3736. **/
  3737. int i40e_up(struct i40e_vsi *vsi)
  3738. {
  3739. int err;
  3740. err = i40e_vsi_configure(vsi);
  3741. if (!err)
  3742. err = i40e_up_complete(vsi);
  3743. return err;
  3744. }
  3745. /**
  3746. * i40e_down - Shutdown the connection processing
  3747. * @vsi: the VSI being stopped
  3748. **/
  3749. void i40e_down(struct i40e_vsi *vsi)
  3750. {
  3751. int i;
  3752. /* It is assumed that the caller of this function
  3753. * sets the vsi->state __I40E_DOWN bit.
  3754. */
  3755. if (vsi->netdev) {
  3756. netif_carrier_off(vsi->netdev);
  3757. netif_tx_disable(vsi->netdev);
  3758. }
  3759. i40e_vsi_disable_irq(vsi);
  3760. i40e_vsi_control_rings(vsi, false);
  3761. i40e_napi_disable_all(vsi);
  3762. for (i = 0; i < vsi->num_queue_pairs; i++) {
  3763. i40e_clean_tx_ring(vsi->tx_rings[i]);
  3764. i40e_clean_rx_ring(vsi->rx_rings[i]);
  3765. }
  3766. }
  3767. /**
  3768. * i40e_setup_tc - configure multiple traffic classes
  3769. * @netdev: net device to configure
  3770. * @tc: number of traffic classes to enable
  3771. **/
  3772. static int i40e_setup_tc(struct net_device *netdev, u8 tc)
  3773. {
  3774. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3775. struct i40e_vsi *vsi = np->vsi;
  3776. struct i40e_pf *pf = vsi->back;
  3777. u8 enabled_tc = 0;
  3778. int ret = -EINVAL;
  3779. int i;
  3780. /* Check if DCB enabled to continue */
  3781. if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
  3782. netdev_info(netdev, "DCB is not enabled for adapter\n");
  3783. goto exit;
  3784. }
  3785. /* Check if MFP enabled */
  3786. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  3787. netdev_info(netdev, "Configuring TC not supported in MFP mode\n");
  3788. goto exit;
  3789. }
  3790. /* Check whether tc count is within enabled limit */
  3791. if (tc > i40e_pf_get_num_tc(pf)) {
  3792. netdev_info(netdev, "TC count greater than enabled on link for adapter\n");
  3793. goto exit;
  3794. }
  3795. /* Generate TC map for number of tc requested */
  3796. for (i = 0; i < tc; i++)
  3797. enabled_tc |= (1 << i);
  3798. /* Requesting same TC configuration as already enabled */
  3799. if (enabled_tc == vsi->tc_config.enabled_tc)
  3800. return 0;
  3801. /* Quiesce VSI queues */
  3802. i40e_quiesce_vsi(vsi);
  3803. /* Configure VSI for enabled TCs */
  3804. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  3805. if (ret) {
  3806. netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
  3807. vsi->seid);
  3808. goto exit;
  3809. }
  3810. /* Unquiesce VSI */
  3811. i40e_unquiesce_vsi(vsi);
  3812. exit:
  3813. return ret;
  3814. }
  3815. /**
  3816. * i40e_open - Called when a network interface is made active
  3817. * @netdev: network interface device structure
  3818. *
  3819. * The open entry point is called when a network interface is made
  3820. * active by the system (IFF_UP). At this point all resources needed
  3821. * for transmit and receive operations are allocated, the interrupt
  3822. * handler is registered with the OS, the netdev watchdog subtask is
  3823. * enabled, and the stack is notified that the interface is ready.
  3824. *
  3825. * Returns 0 on success, negative value on failure
  3826. **/
  3827. static int i40e_open(struct net_device *netdev)
  3828. {
  3829. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3830. struct i40e_vsi *vsi = np->vsi;
  3831. struct i40e_pf *pf = vsi->back;
  3832. int err;
  3833. /* disallow open during test or if eeprom is broken */
  3834. if (test_bit(__I40E_TESTING, &pf->state) ||
  3835. test_bit(__I40E_BAD_EEPROM, &pf->state))
  3836. return -EBUSY;
  3837. netif_carrier_off(netdev);
  3838. err = i40e_vsi_open(vsi);
  3839. if (err)
  3840. return err;
  3841. /* configure global TSO hardware offload settings */
  3842. wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
  3843. TCP_FLAG_FIN) >> 16);
  3844. wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
  3845. TCP_FLAG_FIN |
  3846. TCP_FLAG_CWR) >> 16);
  3847. wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
  3848. #ifdef CONFIG_I40E_VXLAN
  3849. vxlan_get_rx_port(netdev);
  3850. #endif
  3851. return 0;
  3852. }
  3853. /**
  3854. * i40e_vsi_open -
  3855. * @vsi: the VSI to open
  3856. *
  3857. * Finish initialization of the VSI.
  3858. *
  3859. * Returns 0 on success, negative value on failure
  3860. **/
  3861. int i40e_vsi_open(struct i40e_vsi *vsi)
  3862. {
  3863. struct i40e_pf *pf = vsi->back;
  3864. char int_name[IFNAMSIZ];
  3865. int err;
  3866. /* allocate descriptors */
  3867. err = i40e_vsi_setup_tx_resources(vsi);
  3868. if (err)
  3869. goto err_setup_tx;
  3870. err = i40e_vsi_setup_rx_resources(vsi);
  3871. if (err)
  3872. goto err_setup_rx;
  3873. err = i40e_vsi_configure(vsi);
  3874. if (err)
  3875. goto err_setup_rx;
  3876. if (vsi->netdev) {
  3877. snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
  3878. dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
  3879. err = i40e_vsi_request_irq(vsi, int_name);
  3880. if (err)
  3881. goto err_setup_rx;
  3882. /* Notify the stack of the actual queue counts. */
  3883. err = netif_set_real_num_tx_queues(vsi->netdev,
  3884. vsi->num_queue_pairs);
  3885. if (err)
  3886. goto err_set_queues;
  3887. err = netif_set_real_num_rx_queues(vsi->netdev,
  3888. vsi->num_queue_pairs);
  3889. if (err)
  3890. goto err_set_queues;
  3891. } else if (vsi->type == I40E_VSI_FDIR) {
  3892. snprintf(int_name, sizeof(int_name) - 1, "%s-fdir",
  3893. dev_driver_string(&pf->pdev->dev));
  3894. err = i40e_vsi_request_irq(vsi, int_name);
  3895. } else {
  3896. err = -EINVAL;
  3897. goto err_setup_rx;
  3898. }
  3899. err = i40e_up_complete(vsi);
  3900. if (err)
  3901. goto err_up_complete;
  3902. return 0;
  3903. err_up_complete:
  3904. i40e_down(vsi);
  3905. err_set_queues:
  3906. i40e_vsi_free_irq(vsi);
  3907. err_setup_rx:
  3908. i40e_vsi_free_rx_resources(vsi);
  3909. err_setup_tx:
  3910. i40e_vsi_free_tx_resources(vsi);
  3911. if (vsi == pf->vsi[pf->lan_vsi])
  3912. i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
  3913. return err;
  3914. }
  3915. /**
  3916. * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
  3917. * @pf: Pointer to pf
  3918. *
  3919. * This function destroys the hlist where all the Flow Director
  3920. * filters were saved.
  3921. **/
  3922. static void i40e_fdir_filter_exit(struct i40e_pf *pf)
  3923. {
  3924. struct i40e_fdir_filter *filter;
  3925. struct hlist_node *node2;
  3926. hlist_for_each_entry_safe(filter, node2,
  3927. &pf->fdir_filter_list, fdir_node) {
  3928. hlist_del(&filter->fdir_node);
  3929. kfree(filter);
  3930. }
  3931. pf->fdir_pf_active_filters = 0;
  3932. }
  3933. /**
  3934. * i40e_close - Disables a network interface
  3935. * @netdev: network interface device structure
  3936. *
  3937. * The close entry point is called when an interface is de-activated
  3938. * by the OS. The hardware is still under the driver's control, but
  3939. * this netdev interface is disabled.
  3940. *
  3941. * Returns 0, this is not allowed to fail
  3942. **/
  3943. static int i40e_close(struct net_device *netdev)
  3944. {
  3945. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3946. struct i40e_vsi *vsi = np->vsi;
  3947. i40e_vsi_close(vsi);
  3948. return 0;
  3949. }
  3950. /**
  3951. * i40e_do_reset - Start a PF or Core Reset sequence
  3952. * @pf: board private structure
  3953. * @reset_flags: which reset is requested
  3954. *
  3955. * The essential difference in resets is that the PF Reset
  3956. * doesn't clear the packet buffers, doesn't reset the PE
  3957. * firmware, and doesn't bother the other PFs on the chip.
  3958. **/
  3959. void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags)
  3960. {
  3961. u32 val;
  3962. WARN_ON(in_interrupt());
  3963. if (i40e_check_asq_alive(&pf->hw))
  3964. i40e_vc_notify_reset(pf);
  3965. /* do the biggest reset indicated */
  3966. if (reset_flags & (1 << __I40E_GLOBAL_RESET_REQUESTED)) {
  3967. /* Request a Global Reset
  3968. *
  3969. * This will start the chip's countdown to the actual full
  3970. * chip reset event, and a warning interrupt to be sent
  3971. * to all PFs, including the requestor. Our handler
  3972. * for the warning interrupt will deal with the shutdown
  3973. * and recovery of the switch setup.
  3974. */
  3975. dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
  3976. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  3977. val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
  3978. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  3979. } else if (reset_flags & (1 << __I40E_CORE_RESET_REQUESTED)) {
  3980. /* Request a Core Reset
  3981. *
  3982. * Same as Global Reset, except does *not* include the MAC/PHY
  3983. */
  3984. dev_dbg(&pf->pdev->dev, "CoreR requested\n");
  3985. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  3986. val |= I40E_GLGEN_RTRIG_CORER_MASK;
  3987. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  3988. i40e_flush(&pf->hw);
  3989. } else if (reset_flags & (1 << __I40E_EMP_RESET_REQUESTED)) {
  3990. /* Request a Firmware Reset
  3991. *
  3992. * Same as Global reset, plus restarting the
  3993. * embedded firmware engine.
  3994. */
  3995. /* enable EMP Reset */
  3996. val = rd32(&pf->hw, I40E_GLGEN_RSTENA_EMP);
  3997. val |= I40E_GLGEN_RSTENA_EMP_EMP_RST_ENA_MASK;
  3998. wr32(&pf->hw, I40E_GLGEN_RSTENA_EMP, val);
  3999. /* force the reset */
  4000. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  4001. val |= I40E_GLGEN_RTRIG_EMPFWR_MASK;
  4002. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  4003. i40e_flush(&pf->hw);
  4004. } else if (reset_flags & (1 << __I40E_PF_RESET_REQUESTED)) {
  4005. /* Request a PF Reset
  4006. *
  4007. * Resets only the PF-specific registers
  4008. *
  4009. * This goes directly to the tear-down and rebuild of
  4010. * the switch, since we need to do all the recovery as
  4011. * for the Core Reset.
  4012. */
  4013. dev_dbg(&pf->pdev->dev, "PFR requested\n");
  4014. i40e_handle_reset_warning(pf);
  4015. } else if (reset_flags & (1 << __I40E_REINIT_REQUESTED)) {
  4016. int v;
  4017. /* Find the VSI(s) that requested a re-init */
  4018. dev_info(&pf->pdev->dev,
  4019. "VSI reinit requested\n");
  4020. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4021. struct i40e_vsi *vsi = pf->vsi[v];
  4022. if (vsi != NULL &&
  4023. test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) {
  4024. i40e_vsi_reinit_locked(pf->vsi[v]);
  4025. clear_bit(__I40E_REINIT_REQUESTED, &vsi->state);
  4026. }
  4027. }
  4028. /* no further action needed, so return now */
  4029. return;
  4030. } else {
  4031. dev_info(&pf->pdev->dev,
  4032. "bad reset request 0x%08x\n", reset_flags);
  4033. return;
  4034. }
  4035. }
  4036. #ifdef CONFIG_I40E_DCB
  4037. /**
  4038. * i40e_dcb_need_reconfig - Check if DCB needs reconfig
  4039. * @pf: board private structure
  4040. * @old_cfg: current DCB config
  4041. * @new_cfg: new DCB config
  4042. **/
  4043. bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
  4044. struct i40e_dcbx_config *old_cfg,
  4045. struct i40e_dcbx_config *new_cfg)
  4046. {
  4047. bool need_reconfig = false;
  4048. /* Check if ETS configuration has changed */
  4049. if (memcmp(&new_cfg->etscfg,
  4050. &old_cfg->etscfg,
  4051. sizeof(new_cfg->etscfg))) {
  4052. /* If Priority Table has changed reconfig is needed */
  4053. if (memcmp(&new_cfg->etscfg.prioritytable,
  4054. &old_cfg->etscfg.prioritytable,
  4055. sizeof(new_cfg->etscfg.prioritytable))) {
  4056. need_reconfig = true;
  4057. dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
  4058. }
  4059. if (memcmp(&new_cfg->etscfg.tcbwtable,
  4060. &old_cfg->etscfg.tcbwtable,
  4061. sizeof(new_cfg->etscfg.tcbwtable)))
  4062. dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
  4063. if (memcmp(&new_cfg->etscfg.tsatable,
  4064. &old_cfg->etscfg.tsatable,
  4065. sizeof(new_cfg->etscfg.tsatable)))
  4066. dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
  4067. }
  4068. /* Check if PFC configuration has changed */
  4069. if (memcmp(&new_cfg->pfc,
  4070. &old_cfg->pfc,
  4071. sizeof(new_cfg->pfc))) {
  4072. need_reconfig = true;
  4073. dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
  4074. }
  4075. /* Check if APP Table has changed */
  4076. if (memcmp(&new_cfg->app,
  4077. &old_cfg->app,
  4078. sizeof(new_cfg->app))) {
  4079. need_reconfig = true;
  4080. dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
  4081. }
  4082. return need_reconfig;
  4083. }
  4084. /**
  4085. * i40e_handle_lldp_event - Handle LLDP Change MIB event
  4086. * @pf: board private structure
  4087. * @e: event info posted on ARQ
  4088. **/
  4089. static int i40e_handle_lldp_event(struct i40e_pf *pf,
  4090. struct i40e_arq_event_info *e)
  4091. {
  4092. struct i40e_aqc_lldp_get_mib *mib =
  4093. (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
  4094. struct i40e_hw *hw = &pf->hw;
  4095. struct i40e_dcbx_config *dcbx_cfg = &hw->local_dcbx_config;
  4096. struct i40e_dcbx_config tmp_dcbx_cfg;
  4097. bool need_reconfig = false;
  4098. int ret = 0;
  4099. u8 type;
  4100. /* Not DCB capable or capability disabled */
  4101. if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
  4102. return ret;
  4103. /* Ignore if event is not for Nearest Bridge */
  4104. type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
  4105. & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
  4106. if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
  4107. return ret;
  4108. /* Check MIB Type and return if event for Remote MIB update */
  4109. type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
  4110. if (type == I40E_AQ_LLDP_MIB_REMOTE) {
  4111. /* Update the remote cached instance and return */
  4112. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
  4113. I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
  4114. &hw->remote_dcbx_config);
  4115. goto exit;
  4116. }
  4117. /* Convert/store the DCBX data from LLDPDU temporarily */
  4118. memset(&tmp_dcbx_cfg, 0, sizeof(tmp_dcbx_cfg));
  4119. ret = i40e_lldp_to_dcb_config(e->msg_buf, &tmp_dcbx_cfg);
  4120. if (ret) {
  4121. /* Error in LLDPDU parsing return */
  4122. dev_info(&pf->pdev->dev, "Failed parsing LLDPDU from event buffer\n");
  4123. goto exit;
  4124. }
  4125. /* No change detected in DCBX configs */
  4126. if (!memcmp(&tmp_dcbx_cfg, dcbx_cfg, sizeof(tmp_dcbx_cfg))) {
  4127. dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
  4128. goto exit;
  4129. }
  4130. need_reconfig = i40e_dcb_need_reconfig(pf, dcbx_cfg, &tmp_dcbx_cfg);
  4131. i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg);
  4132. /* Overwrite the new configuration */
  4133. *dcbx_cfg = tmp_dcbx_cfg;
  4134. if (!need_reconfig)
  4135. goto exit;
  4136. /* Enable DCB tagging only when more than one TC */
  4137. if (i40e_dcb_get_num_tc(dcbx_cfg) > 1)
  4138. pf->flags |= I40E_FLAG_DCB_ENABLED;
  4139. else
  4140. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  4141. /* Reconfiguration needed quiesce all VSIs */
  4142. i40e_pf_quiesce_all_vsi(pf);
  4143. /* Changes in configuration update VEB/VSI */
  4144. i40e_dcb_reconfigure(pf);
  4145. i40e_pf_unquiesce_all_vsi(pf);
  4146. exit:
  4147. return ret;
  4148. }
  4149. #endif /* CONFIG_I40E_DCB */
  4150. /**
  4151. * i40e_do_reset_safe - Protected reset path for userland calls.
  4152. * @pf: board private structure
  4153. * @reset_flags: which reset is requested
  4154. *
  4155. **/
  4156. void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
  4157. {
  4158. rtnl_lock();
  4159. i40e_do_reset(pf, reset_flags);
  4160. rtnl_unlock();
  4161. }
  4162. /**
  4163. * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
  4164. * @pf: board private structure
  4165. * @e: event info posted on ARQ
  4166. *
  4167. * Handler for LAN Queue Overflow Event generated by the firmware for PF
  4168. * and VF queues
  4169. **/
  4170. static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
  4171. struct i40e_arq_event_info *e)
  4172. {
  4173. struct i40e_aqc_lan_overflow *data =
  4174. (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
  4175. u32 queue = le32_to_cpu(data->prtdcb_rupto);
  4176. u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
  4177. struct i40e_hw *hw = &pf->hw;
  4178. struct i40e_vf *vf;
  4179. u16 vf_id;
  4180. dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
  4181. queue, qtx_ctl);
  4182. /* Queue belongs to VF, find the VF and issue VF reset */
  4183. if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
  4184. >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
  4185. vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
  4186. >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
  4187. vf_id -= hw->func_caps.vf_base_id;
  4188. vf = &pf->vf[vf_id];
  4189. i40e_vc_notify_vf_reset(vf);
  4190. /* Allow VF to process pending reset notification */
  4191. msleep(20);
  4192. i40e_reset_vf(vf, false);
  4193. }
  4194. }
  4195. /**
  4196. * i40e_service_event_complete - Finish up the service event
  4197. * @pf: board private structure
  4198. **/
  4199. static void i40e_service_event_complete(struct i40e_pf *pf)
  4200. {
  4201. BUG_ON(!test_bit(__I40E_SERVICE_SCHED, &pf->state));
  4202. /* flush memory to make sure state is correct before next watchog */
  4203. smp_mb__before_atomic();
  4204. clear_bit(__I40E_SERVICE_SCHED, &pf->state);
  4205. }
  4206. /**
  4207. * i40e_get_current_fd_count - Get the count of FD filters programmed in the HW
  4208. * @pf: board private structure
  4209. **/
  4210. int i40e_get_current_fd_count(struct i40e_pf *pf)
  4211. {
  4212. int val, fcnt_prog;
  4213. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  4214. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
  4215. ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
  4216. I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
  4217. return fcnt_prog;
  4218. }
  4219. /**
  4220. * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
  4221. * @pf: board private structure
  4222. **/
  4223. void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
  4224. {
  4225. u32 fcnt_prog, fcnt_avail;
  4226. /* Check if, FD SB or ATR was auto disabled and if there is enough room
  4227. * to re-enable
  4228. */
  4229. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  4230. (pf->flags & I40E_FLAG_FD_SB_ENABLED))
  4231. return;
  4232. fcnt_prog = i40e_get_current_fd_count(pf);
  4233. fcnt_avail = i40e_get_fd_cnt_all(pf);
  4234. if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) {
  4235. if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
  4236. (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) {
  4237. pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
  4238. dev_info(&pf->pdev->dev, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
  4239. }
  4240. }
  4241. /* Wait for some more space to be available to turn on ATR */
  4242. if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) {
  4243. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  4244. (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) {
  4245. pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  4246. dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table now\n");
  4247. }
  4248. }
  4249. }
  4250. /**
  4251. * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
  4252. * @pf: board private structure
  4253. **/
  4254. static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
  4255. {
  4256. if (!(pf->flags & I40E_FLAG_FDIR_REQUIRES_REINIT))
  4257. return;
  4258. /* if interface is down do nothing */
  4259. if (test_bit(__I40E_DOWN, &pf->state))
  4260. return;
  4261. i40e_fdir_check_and_reenable(pf);
  4262. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  4263. (pf->flags & I40E_FLAG_FD_SB_ENABLED))
  4264. pf->flags &= ~I40E_FLAG_FDIR_REQUIRES_REINIT;
  4265. }
  4266. /**
  4267. * i40e_vsi_link_event - notify VSI of a link event
  4268. * @vsi: vsi to be notified
  4269. * @link_up: link up or down
  4270. **/
  4271. static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
  4272. {
  4273. if (!vsi)
  4274. return;
  4275. switch (vsi->type) {
  4276. case I40E_VSI_MAIN:
  4277. if (!vsi->netdev || !vsi->netdev_registered)
  4278. break;
  4279. if (link_up) {
  4280. netif_carrier_on(vsi->netdev);
  4281. netif_tx_wake_all_queues(vsi->netdev);
  4282. } else {
  4283. netif_carrier_off(vsi->netdev);
  4284. netif_tx_stop_all_queues(vsi->netdev);
  4285. }
  4286. break;
  4287. case I40E_VSI_SRIOV:
  4288. break;
  4289. case I40E_VSI_VMDQ2:
  4290. case I40E_VSI_CTRL:
  4291. case I40E_VSI_MIRROR:
  4292. default:
  4293. /* there is no notification for other VSIs */
  4294. break;
  4295. }
  4296. }
  4297. /**
  4298. * i40e_veb_link_event - notify elements on the veb of a link event
  4299. * @veb: veb to be notified
  4300. * @link_up: link up or down
  4301. **/
  4302. static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
  4303. {
  4304. struct i40e_pf *pf;
  4305. int i;
  4306. if (!veb || !veb->pf)
  4307. return;
  4308. pf = veb->pf;
  4309. /* depth first... */
  4310. for (i = 0; i < I40E_MAX_VEB; i++)
  4311. if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
  4312. i40e_veb_link_event(pf->veb[i], link_up);
  4313. /* ... now the local VSIs */
  4314. for (i = 0; i < pf->num_alloc_vsi; i++)
  4315. if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
  4316. i40e_vsi_link_event(pf->vsi[i], link_up);
  4317. }
  4318. /**
  4319. * i40e_link_event - Update netif_carrier status
  4320. * @pf: board private structure
  4321. **/
  4322. static void i40e_link_event(struct i40e_pf *pf)
  4323. {
  4324. bool new_link, old_link;
  4325. new_link = (pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP);
  4326. old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
  4327. if (new_link == old_link)
  4328. return;
  4329. if (!test_bit(__I40E_DOWN, &pf->vsi[pf->lan_vsi]->state))
  4330. i40e_print_link_message(pf->vsi[pf->lan_vsi], new_link);
  4331. /* Notify the base of the switch tree connected to
  4332. * the link. Floating VEBs are not notified.
  4333. */
  4334. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  4335. i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
  4336. else
  4337. i40e_vsi_link_event(pf->vsi[pf->lan_vsi], new_link);
  4338. if (pf->vf)
  4339. i40e_vc_notify_link_state(pf);
  4340. if (pf->flags & I40E_FLAG_PTP)
  4341. i40e_ptp_set_increment(pf);
  4342. }
  4343. /**
  4344. * i40e_check_hang_subtask - Check for hung queues and dropped interrupts
  4345. * @pf: board private structure
  4346. *
  4347. * Set the per-queue flags to request a check for stuck queues in the irq
  4348. * clean functions, then force interrupts to be sure the irq clean is called.
  4349. **/
  4350. static void i40e_check_hang_subtask(struct i40e_pf *pf)
  4351. {
  4352. int i, v;
  4353. /* If we're down or resetting, just bail */
  4354. if (test_bit(__I40E_CONFIG_BUSY, &pf->state))
  4355. return;
  4356. /* for each VSI/netdev
  4357. * for each Tx queue
  4358. * set the check flag
  4359. * for each q_vector
  4360. * force an interrupt
  4361. */
  4362. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4363. struct i40e_vsi *vsi = pf->vsi[v];
  4364. int armed = 0;
  4365. if (!pf->vsi[v] ||
  4366. test_bit(__I40E_DOWN, &vsi->state) ||
  4367. (vsi->netdev && !netif_carrier_ok(vsi->netdev)))
  4368. continue;
  4369. for (i = 0; i < vsi->num_queue_pairs; i++) {
  4370. set_check_for_tx_hang(vsi->tx_rings[i]);
  4371. if (test_bit(__I40E_HANG_CHECK_ARMED,
  4372. &vsi->tx_rings[i]->state))
  4373. armed++;
  4374. }
  4375. if (armed) {
  4376. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
  4377. wr32(&vsi->back->hw, I40E_PFINT_DYN_CTL0,
  4378. (I40E_PFINT_DYN_CTL0_INTENA_MASK |
  4379. I40E_PFINT_DYN_CTL0_SWINT_TRIG_MASK));
  4380. } else {
  4381. u16 vec = vsi->base_vector - 1;
  4382. u32 val = (I40E_PFINT_DYN_CTLN_INTENA_MASK |
  4383. I40E_PFINT_DYN_CTLN_SWINT_TRIG_MASK);
  4384. for (i = 0; i < vsi->num_q_vectors; i++, vec++)
  4385. wr32(&vsi->back->hw,
  4386. I40E_PFINT_DYN_CTLN(vec), val);
  4387. }
  4388. i40e_flush(&vsi->back->hw);
  4389. }
  4390. }
  4391. }
  4392. /**
  4393. * i40e_watchdog_subtask - Check and bring link up
  4394. * @pf: board private structure
  4395. **/
  4396. static void i40e_watchdog_subtask(struct i40e_pf *pf)
  4397. {
  4398. int i;
  4399. /* if interface is down do nothing */
  4400. if (test_bit(__I40E_DOWN, &pf->state) ||
  4401. test_bit(__I40E_CONFIG_BUSY, &pf->state))
  4402. return;
  4403. /* Update the stats for active netdevs so the network stack
  4404. * can look at updated numbers whenever it cares to
  4405. */
  4406. for (i = 0; i < pf->num_alloc_vsi; i++)
  4407. if (pf->vsi[i] && pf->vsi[i]->netdev)
  4408. i40e_update_stats(pf->vsi[i]);
  4409. /* Update the stats for the active switching components */
  4410. for (i = 0; i < I40E_MAX_VEB; i++)
  4411. if (pf->veb[i])
  4412. i40e_update_veb_stats(pf->veb[i]);
  4413. i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]);
  4414. }
  4415. /**
  4416. * i40e_reset_subtask - Set up for resetting the device and driver
  4417. * @pf: board private structure
  4418. **/
  4419. static void i40e_reset_subtask(struct i40e_pf *pf)
  4420. {
  4421. u32 reset_flags = 0;
  4422. rtnl_lock();
  4423. if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) {
  4424. reset_flags |= (1 << __I40E_REINIT_REQUESTED);
  4425. clear_bit(__I40E_REINIT_REQUESTED, &pf->state);
  4426. }
  4427. if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) {
  4428. reset_flags |= (1 << __I40E_PF_RESET_REQUESTED);
  4429. clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  4430. }
  4431. if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) {
  4432. reset_flags |= (1 << __I40E_CORE_RESET_REQUESTED);
  4433. clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
  4434. }
  4435. if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) {
  4436. reset_flags |= (1 << __I40E_GLOBAL_RESET_REQUESTED);
  4437. clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
  4438. }
  4439. /* If there's a recovery already waiting, it takes
  4440. * precedence before starting a new reset sequence.
  4441. */
  4442. if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) {
  4443. i40e_handle_reset_warning(pf);
  4444. goto unlock;
  4445. }
  4446. /* If we're already down or resetting, just bail */
  4447. if (reset_flags &&
  4448. !test_bit(__I40E_DOWN, &pf->state) &&
  4449. !test_bit(__I40E_CONFIG_BUSY, &pf->state))
  4450. i40e_do_reset(pf, reset_flags);
  4451. unlock:
  4452. rtnl_unlock();
  4453. }
  4454. /**
  4455. * i40e_handle_link_event - Handle link event
  4456. * @pf: board private structure
  4457. * @e: event info posted on ARQ
  4458. **/
  4459. static void i40e_handle_link_event(struct i40e_pf *pf,
  4460. struct i40e_arq_event_info *e)
  4461. {
  4462. struct i40e_hw *hw = &pf->hw;
  4463. struct i40e_aqc_get_link_status *status =
  4464. (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
  4465. struct i40e_link_status *hw_link_info = &hw->phy.link_info;
  4466. /* save off old link status information */
  4467. memcpy(&pf->hw.phy.link_info_old, hw_link_info,
  4468. sizeof(pf->hw.phy.link_info_old));
  4469. /* update link status */
  4470. hw_link_info->phy_type = (enum i40e_aq_phy_type)status->phy_type;
  4471. hw_link_info->link_speed = (enum i40e_aq_link_speed)status->link_speed;
  4472. hw_link_info->link_info = status->link_info;
  4473. hw_link_info->an_info = status->an_info;
  4474. hw_link_info->ext_info = status->ext_info;
  4475. hw_link_info->lse_enable =
  4476. le16_to_cpu(status->command_flags) &
  4477. I40E_AQ_LSE_ENABLE;
  4478. /* process the event */
  4479. i40e_link_event(pf);
  4480. /* Do a new status request to re-enable LSE reporting
  4481. * and load new status information into the hw struct,
  4482. * then see if the status changed while processing the
  4483. * initial event.
  4484. */
  4485. i40e_aq_get_link_info(&pf->hw, true, NULL, NULL);
  4486. i40e_link_event(pf);
  4487. }
  4488. /**
  4489. * i40e_clean_adminq_subtask - Clean the AdminQ rings
  4490. * @pf: board private structure
  4491. **/
  4492. static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
  4493. {
  4494. struct i40e_arq_event_info event;
  4495. struct i40e_hw *hw = &pf->hw;
  4496. u16 pending, i = 0;
  4497. i40e_status ret;
  4498. u16 opcode;
  4499. u32 oldval;
  4500. u32 val;
  4501. if (!test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state))
  4502. return;
  4503. /* check for error indications */
  4504. val = rd32(&pf->hw, pf->hw.aq.arq.len);
  4505. oldval = val;
  4506. if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
  4507. dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
  4508. val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
  4509. }
  4510. if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
  4511. dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
  4512. val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
  4513. }
  4514. if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
  4515. dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
  4516. val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
  4517. }
  4518. if (oldval != val)
  4519. wr32(&pf->hw, pf->hw.aq.arq.len, val);
  4520. val = rd32(&pf->hw, pf->hw.aq.asq.len);
  4521. oldval = val;
  4522. if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
  4523. dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
  4524. val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
  4525. }
  4526. if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
  4527. dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
  4528. val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
  4529. }
  4530. if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
  4531. dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
  4532. val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
  4533. }
  4534. if (oldval != val)
  4535. wr32(&pf->hw, pf->hw.aq.asq.len, val);
  4536. event.msg_size = I40E_MAX_AQ_BUF_SIZE;
  4537. event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL);
  4538. if (!event.msg_buf)
  4539. return;
  4540. do {
  4541. event.msg_size = I40E_MAX_AQ_BUF_SIZE; /* reinit each time */
  4542. ret = i40e_clean_arq_element(hw, &event, &pending);
  4543. if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK) {
  4544. dev_info(&pf->pdev->dev, "No ARQ event found\n");
  4545. break;
  4546. } else if (ret) {
  4547. dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
  4548. break;
  4549. }
  4550. opcode = le16_to_cpu(event.desc.opcode);
  4551. switch (opcode) {
  4552. case i40e_aqc_opc_get_link_status:
  4553. i40e_handle_link_event(pf, &event);
  4554. break;
  4555. case i40e_aqc_opc_send_msg_to_pf:
  4556. ret = i40e_vc_process_vf_msg(pf,
  4557. le16_to_cpu(event.desc.retval),
  4558. le32_to_cpu(event.desc.cookie_high),
  4559. le32_to_cpu(event.desc.cookie_low),
  4560. event.msg_buf,
  4561. event.msg_size);
  4562. break;
  4563. case i40e_aqc_opc_lldp_update_mib:
  4564. dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
  4565. #ifdef CONFIG_I40E_DCB
  4566. rtnl_lock();
  4567. ret = i40e_handle_lldp_event(pf, &event);
  4568. rtnl_unlock();
  4569. #endif /* CONFIG_I40E_DCB */
  4570. break;
  4571. case i40e_aqc_opc_event_lan_overflow:
  4572. dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
  4573. i40e_handle_lan_overflow_event(pf, &event);
  4574. break;
  4575. case i40e_aqc_opc_send_msg_to_peer:
  4576. dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
  4577. break;
  4578. default:
  4579. dev_info(&pf->pdev->dev,
  4580. "ARQ Error: Unknown event 0x%04x received\n",
  4581. opcode);
  4582. break;
  4583. }
  4584. } while (pending && (i++ < pf->adminq_work_limit));
  4585. clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
  4586. /* re-enable Admin queue interrupt cause */
  4587. val = rd32(hw, I40E_PFINT_ICR0_ENA);
  4588. val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  4589. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  4590. i40e_flush(hw);
  4591. kfree(event.msg_buf);
  4592. }
  4593. /**
  4594. * i40e_verify_eeprom - make sure eeprom is good to use
  4595. * @pf: board private structure
  4596. **/
  4597. static void i40e_verify_eeprom(struct i40e_pf *pf)
  4598. {
  4599. int err;
  4600. err = i40e_diag_eeprom_test(&pf->hw);
  4601. if (err) {
  4602. /* retry in case of garbage read */
  4603. err = i40e_diag_eeprom_test(&pf->hw);
  4604. if (err) {
  4605. dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
  4606. err);
  4607. set_bit(__I40E_BAD_EEPROM, &pf->state);
  4608. }
  4609. }
  4610. if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) {
  4611. dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
  4612. clear_bit(__I40E_BAD_EEPROM, &pf->state);
  4613. }
  4614. }
  4615. /**
  4616. * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
  4617. * @veb: pointer to the VEB instance
  4618. *
  4619. * This is a recursive function that first builds the attached VSIs then
  4620. * recurses in to build the next layer of VEB. We track the connections
  4621. * through our own index numbers because the seid's from the HW could
  4622. * change across the reset.
  4623. **/
  4624. static int i40e_reconstitute_veb(struct i40e_veb *veb)
  4625. {
  4626. struct i40e_vsi *ctl_vsi = NULL;
  4627. struct i40e_pf *pf = veb->pf;
  4628. int v, veb_idx;
  4629. int ret;
  4630. /* build VSI that owns this VEB, temporarily attached to base VEB */
  4631. for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
  4632. if (pf->vsi[v] &&
  4633. pf->vsi[v]->veb_idx == veb->idx &&
  4634. pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
  4635. ctl_vsi = pf->vsi[v];
  4636. break;
  4637. }
  4638. }
  4639. if (!ctl_vsi) {
  4640. dev_info(&pf->pdev->dev,
  4641. "missing owner VSI for veb_idx %d\n", veb->idx);
  4642. ret = -ENOENT;
  4643. goto end_reconstitute;
  4644. }
  4645. if (ctl_vsi != pf->vsi[pf->lan_vsi])
  4646. ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  4647. ret = i40e_add_vsi(ctl_vsi);
  4648. if (ret) {
  4649. dev_info(&pf->pdev->dev,
  4650. "rebuild of owner VSI failed: %d\n", ret);
  4651. goto end_reconstitute;
  4652. }
  4653. i40e_vsi_reset_stats(ctl_vsi);
  4654. /* create the VEB in the switch and move the VSI onto the VEB */
  4655. ret = i40e_add_veb(veb, ctl_vsi);
  4656. if (ret)
  4657. goto end_reconstitute;
  4658. /* create the remaining VSIs attached to this VEB */
  4659. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4660. if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
  4661. continue;
  4662. if (pf->vsi[v]->veb_idx == veb->idx) {
  4663. struct i40e_vsi *vsi = pf->vsi[v];
  4664. vsi->uplink_seid = veb->seid;
  4665. ret = i40e_add_vsi(vsi);
  4666. if (ret) {
  4667. dev_info(&pf->pdev->dev,
  4668. "rebuild of vsi_idx %d failed: %d\n",
  4669. v, ret);
  4670. goto end_reconstitute;
  4671. }
  4672. i40e_vsi_reset_stats(vsi);
  4673. }
  4674. }
  4675. /* create any VEBs attached to this VEB - RECURSION */
  4676. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  4677. if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
  4678. pf->veb[veb_idx]->uplink_seid = veb->seid;
  4679. ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
  4680. if (ret)
  4681. break;
  4682. }
  4683. }
  4684. end_reconstitute:
  4685. return ret;
  4686. }
  4687. /**
  4688. * i40e_get_capabilities - get info about the HW
  4689. * @pf: the PF struct
  4690. **/
  4691. static int i40e_get_capabilities(struct i40e_pf *pf)
  4692. {
  4693. struct i40e_aqc_list_capabilities_element_resp *cap_buf;
  4694. u16 data_size;
  4695. int buf_len;
  4696. int err;
  4697. buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
  4698. do {
  4699. cap_buf = kzalloc(buf_len, GFP_KERNEL);
  4700. if (!cap_buf)
  4701. return -ENOMEM;
  4702. /* this loads the data into the hw struct for us */
  4703. err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
  4704. &data_size,
  4705. i40e_aqc_opc_list_func_capabilities,
  4706. NULL);
  4707. /* data loaded, buffer no longer needed */
  4708. kfree(cap_buf);
  4709. if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
  4710. /* retry with a larger buffer */
  4711. buf_len = data_size;
  4712. } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
  4713. dev_info(&pf->pdev->dev,
  4714. "capability discovery failed: aq=%d\n",
  4715. pf->hw.aq.asq_last_status);
  4716. return -ENODEV;
  4717. }
  4718. } while (err);
  4719. if (((pf->hw.aq.fw_maj_ver == 2) && (pf->hw.aq.fw_min_ver < 22)) ||
  4720. (pf->hw.aq.fw_maj_ver < 2)) {
  4721. pf->hw.func_caps.num_msix_vectors++;
  4722. pf->hw.func_caps.num_msix_vectors_vf++;
  4723. }
  4724. if (pf->hw.debug_mask & I40E_DEBUG_USER)
  4725. dev_info(&pf->pdev->dev,
  4726. "pf=%d, num_vfs=%d, msix_pf=%d, msix_vf=%d, fd_g=%d, fd_b=%d, pf_max_q=%d num_vsi=%d\n",
  4727. pf->hw.pf_id, pf->hw.func_caps.num_vfs,
  4728. pf->hw.func_caps.num_msix_vectors,
  4729. pf->hw.func_caps.num_msix_vectors_vf,
  4730. pf->hw.func_caps.fd_filters_guaranteed,
  4731. pf->hw.func_caps.fd_filters_best_effort,
  4732. pf->hw.func_caps.num_tx_qp,
  4733. pf->hw.func_caps.num_vsis);
  4734. #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
  4735. + pf->hw.func_caps.num_vfs)
  4736. if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) {
  4737. dev_info(&pf->pdev->dev,
  4738. "got num_vsis %d, setting num_vsis to %d\n",
  4739. pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
  4740. pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
  4741. }
  4742. return 0;
  4743. }
  4744. static int i40e_vsi_clear(struct i40e_vsi *vsi);
  4745. /**
  4746. * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
  4747. * @pf: board private structure
  4748. **/
  4749. static void i40e_fdir_sb_setup(struct i40e_pf *pf)
  4750. {
  4751. struct i40e_vsi *vsi;
  4752. int i;
  4753. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  4754. return;
  4755. /* find existing VSI and see if it needs configuring */
  4756. vsi = NULL;
  4757. for (i = 0; i < pf->num_alloc_vsi; i++) {
  4758. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
  4759. vsi = pf->vsi[i];
  4760. break;
  4761. }
  4762. }
  4763. /* create a new VSI if none exists */
  4764. if (!vsi) {
  4765. vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
  4766. pf->vsi[pf->lan_vsi]->seid, 0);
  4767. if (!vsi) {
  4768. dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
  4769. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  4770. return;
  4771. }
  4772. }
  4773. i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
  4774. }
  4775. /**
  4776. * i40e_fdir_teardown - release the Flow Director resources
  4777. * @pf: board private structure
  4778. **/
  4779. static void i40e_fdir_teardown(struct i40e_pf *pf)
  4780. {
  4781. int i;
  4782. i40e_fdir_filter_exit(pf);
  4783. for (i = 0; i < pf->num_alloc_vsi; i++) {
  4784. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
  4785. i40e_vsi_release(pf->vsi[i]);
  4786. break;
  4787. }
  4788. }
  4789. }
  4790. /**
  4791. * i40e_prep_for_reset - prep for the core to reset
  4792. * @pf: board private structure
  4793. *
  4794. * Close up the VFs and other things in prep for pf Reset.
  4795. **/
  4796. static int i40e_prep_for_reset(struct i40e_pf *pf)
  4797. {
  4798. struct i40e_hw *hw = &pf->hw;
  4799. i40e_status ret = 0;
  4800. u32 v;
  4801. clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
  4802. if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
  4803. return 0;
  4804. dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
  4805. /* quiesce the VSIs and their queues that are not already DOWN */
  4806. i40e_pf_quiesce_all_vsi(pf);
  4807. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4808. if (pf->vsi[v])
  4809. pf->vsi[v]->seid = 0;
  4810. }
  4811. i40e_shutdown_adminq(&pf->hw);
  4812. /* call shutdown HMC */
  4813. if (hw->hmc.hmc_obj) {
  4814. ret = i40e_shutdown_lan_hmc(hw);
  4815. if (ret) {
  4816. dev_warn(&pf->pdev->dev,
  4817. "shutdown_lan_hmc failed: %d\n", ret);
  4818. clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state);
  4819. }
  4820. }
  4821. return ret;
  4822. }
  4823. /**
  4824. * i40e_send_version - update firmware with driver version
  4825. * @pf: PF struct
  4826. */
  4827. static void i40e_send_version(struct i40e_pf *pf)
  4828. {
  4829. struct i40e_driver_version dv;
  4830. dv.major_version = DRV_VERSION_MAJOR;
  4831. dv.minor_version = DRV_VERSION_MINOR;
  4832. dv.build_version = DRV_VERSION_BUILD;
  4833. dv.subbuild_version = 0;
  4834. strncpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string));
  4835. i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
  4836. }
  4837. /**
  4838. * i40e_reset_and_rebuild - reset and rebuild using a saved config
  4839. * @pf: board private structure
  4840. * @reinit: if the Main VSI needs to re-initialized.
  4841. **/
  4842. static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit)
  4843. {
  4844. struct i40e_hw *hw = &pf->hw;
  4845. i40e_status ret;
  4846. u32 v;
  4847. /* Now we wait for GRST to settle out.
  4848. * We don't have to delete the VEBs or VSIs from the hw switch
  4849. * because the reset will make them disappear.
  4850. */
  4851. ret = i40e_pf_reset(hw);
  4852. if (ret) {
  4853. dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
  4854. goto end_core_reset;
  4855. }
  4856. pf->pfr_count++;
  4857. if (test_bit(__I40E_DOWN, &pf->state))
  4858. goto end_core_reset;
  4859. dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
  4860. /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
  4861. ret = i40e_init_adminq(&pf->hw);
  4862. if (ret) {
  4863. dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, %d\n", ret);
  4864. goto end_core_reset;
  4865. }
  4866. /* re-verify the eeprom if we just had an EMP reset */
  4867. if (test_bit(__I40E_EMP_RESET_REQUESTED, &pf->state)) {
  4868. clear_bit(__I40E_EMP_RESET_REQUESTED, &pf->state);
  4869. i40e_verify_eeprom(pf);
  4870. }
  4871. i40e_clear_pxe_mode(hw);
  4872. ret = i40e_get_capabilities(pf);
  4873. if (ret) {
  4874. dev_info(&pf->pdev->dev, "i40e_get_capabilities failed, %d\n",
  4875. ret);
  4876. goto end_core_reset;
  4877. }
  4878. ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  4879. hw->func_caps.num_rx_qp,
  4880. pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
  4881. if (ret) {
  4882. dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
  4883. goto end_core_reset;
  4884. }
  4885. ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  4886. if (ret) {
  4887. dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
  4888. goto end_core_reset;
  4889. }
  4890. #ifdef CONFIG_I40E_DCB
  4891. ret = i40e_init_pf_dcb(pf);
  4892. if (ret) {
  4893. dev_info(&pf->pdev->dev, "init_pf_dcb failed: %d\n", ret);
  4894. goto end_core_reset;
  4895. }
  4896. #endif /* CONFIG_I40E_DCB */
  4897. /* do basic switch setup */
  4898. ret = i40e_setup_pf_switch(pf, reinit);
  4899. if (ret)
  4900. goto end_core_reset;
  4901. /* Rebuild the VSIs and VEBs that existed before reset.
  4902. * They are still in our local switch element arrays, so only
  4903. * need to rebuild the switch model in the HW.
  4904. *
  4905. * If there were VEBs but the reconstitution failed, we'll try
  4906. * try to recover minimal use by getting the basic PF VSI working.
  4907. */
  4908. if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) {
  4909. dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
  4910. /* find the one VEB connected to the MAC, and find orphans */
  4911. for (v = 0; v < I40E_MAX_VEB; v++) {
  4912. if (!pf->veb[v])
  4913. continue;
  4914. if (pf->veb[v]->uplink_seid == pf->mac_seid ||
  4915. pf->veb[v]->uplink_seid == 0) {
  4916. ret = i40e_reconstitute_veb(pf->veb[v]);
  4917. if (!ret)
  4918. continue;
  4919. /* If Main VEB failed, we're in deep doodoo,
  4920. * so give up rebuilding the switch and set up
  4921. * for minimal rebuild of PF VSI.
  4922. * If orphan failed, we'll report the error
  4923. * but try to keep going.
  4924. */
  4925. if (pf->veb[v]->uplink_seid == pf->mac_seid) {
  4926. dev_info(&pf->pdev->dev,
  4927. "rebuild of switch failed: %d, will try to set up simple PF connection\n",
  4928. ret);
  4929. pf->vsi[pf->lan_vsi]->uplink_seid
  4930. = pf->mac_seid;
  4931. break;
  4932. } else if (pf->veb[v]->uplink_seid == 0) {
  4933. dev_info(&pf->pdev->dev,
  4934. "rebuild of orphan VEB failed: %d\n",
  4935. ret);
  4936. }
  4937. }
  4938. }
  4939. }
  4940. if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) {
  4941. dev_info(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
  4942. /* no VEB, so rebuild only the Main VSI */
  4943. ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]);
  4944. if (ret) {
  4945. dev_info(&pf->pdev->dev,
  4946. "rebuild of Main VSI failed: %d\n", ret);
  4947. goto end_core_reset;
  4948. }
  4949. }
  4950. /* reinit the misc interrupt */
  4951. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  4952. ret = i40e_setup_misc_vector(pf);
  4953. /* restart the VSIs that were rebuilt and running before the reset */
  4954. i40e_pf_unquiesce_all_vsi(pf);
  4955. if (pf->num_alloc_vfs) {
  4956. for (v = 0; v < pf->num_alloc_vfs; v++)
  4957. i40e_reset_vf(&pf->vf[v], true);
  4958. }
  4959. /* tell the firmware that we're starting */
  4960. i40e_send_version(pf);
  4961. end_core_reset:
  4962. clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state);
  4963. }
  4964. /**
  4965. * i40e_handle_reset_warning - prep for the pf to reset, reset and rebuild
  4966. * @pf: board private structure
  4967. *
  4968. * Close up the VFs and other things in prep for a Core Reset,
  4969. * then get ready to rebuild the world.
  4970. **/
  4971. static void i40e_handle_reset_warning(struct i40e_pf *pf)
  4972. {
  4973. i40e_status ret;
  4974. ret = i40e_prep_for_reset(pf);
  4975. if (!ret)
  4976. i40e_reset_and_rebuild(pf, false);
  4977. }
  4978. /**
  4979. * i40e_handle_mdd_event
  4980. * @pf: pointer to the pf structure
  4981. *
  4982. * Called from the MDD irq handler to identify possibly malicious vfs
  4983. **/
  4984. static void i40e_handle_mdd_event(struct i40e_pf *pf)
  4985. {
  4986. struct i40e_hw *hw = &pf->hw;
  4987. bool mdd_detected = false;
  4988. struct i40e_vf *vf;
  4989. u32 reg;
  4990. int i;
  4991. if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state))
  4992. return;
  4993. /* find what triggered the MDD event */
  4994. reg = rd32(hw, I40E_GL_MDET_TX);
  4995. if (reg & I40E_GL_MDET_TX_VALID_MASK) {
  4996. u8 func = (reg & I40E_GL_MDET_TX_FUNCTION_MASK)
  4997. >> I40E_GL_MDET_TX_FUNCTION_SHIFT;
  4998. u8 event = (reg & I40E_GL_MDET_TX_EVENT_SHIFT)
  4999. >> I40E_GL_MDET_TX_EVENT_SHIFT;
  5000. u8 queue = (reg & I40E_GL_MDET_TX_QUEUE_MASK)
  5001. >> I40E_GL_MDET_TX_QUEUE_SHIFT;
  5002. dev_info(&pf->pdev->dev,
  5003. "Malicious Driver Detection event 0x%02x on TX queue %d of function 0x%02x\n",
  5004. event, queue, func);
  5005. wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
  5006. mdd_detected = true;
  5007. }
  5008. reg = rd32(hw, I40E_GL_MDET_RX);
  5009. if (reg & I40E_GL_MDET_RX_VALID_MASK) {
  5010. u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK)
  5011. >> I40E_GL_MDET_RX_FUNCTION_SHIFT;
  5012. u8 event = (reg & I40E_GL_MDET_RX_EVENT_SHIFT)
  5013. >> I40E_GL_MDET_RX_EVENT_SHIFT;
  5014. u8 queue = (reg & I40E_GL_MDET_RX_QUEUE_MASK)
  5015. >> I40E_GL_MDET_RX_QUEUE_SHIFT;
  5016. dev_info(&pf->pdev->dev,
  5017. "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
  5018. event, queue, func);
  5019. wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
  5020. mdd_detected = true;
  5021. }
  5022. /* see if one of the VFs needs its hand slapped */
  5023. for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
  5024. vf = &(pf->vf[i]);
  5025. reg = rd32(hw, I40E_VP_MDET_TX(i));
  5026. if (reg & I40E_VP_MDET_TX_VALID_MASK) {
  5027. wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
  5028. vf->num_mdd_events++;
  5029. dev_info(&pf->pdev->dev, "MDD TX event on VF %d\n", i);
  5030. }
  5031. reg = rd32(hw, I40E_VP_MDET_RX(i));
  5032. if (reg & I40E_VP_MDET_RX_VALID_MASK) {
  5033. wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
  5034. vf->num_mdd_events++;
  5035. dev_info(&pf->pdev->dev, "MDD RX event on VF %d\n", i);
  5036. }
  5037. if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) {
  5038. dev_info(&pf->pdev->dev,
  5039. "Too many MDD events on VF %d, disabled\n", i);
  5040. dev_info(&pf->pdev->dev,
  5041. "Use PF Control I/F to re-enable the VF\n");
  5042. set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
  5043. }
  5044. }
  5045. /* re-enable mdd interrupt cause */
  5046. clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
  5047. reg = rd32(hw, I40E_PFINT_ICR0_ENA);
  5048. reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  5049. wr32(hw, I40E_PFINT_ICR0_ENA, reg);
  5050. i40e_flush(hw);
  5051. }
  5052. #ifdef CONFIG_I40E_VXLAN
  5053. /**
  5054. * i40e_sync_vxlan_filters_subtask - Sync the VSI filter list with HW
  5055. * @pf: board private structure
  5056. **/
  5057. static void i40e_sync_vxlan_filters_subtask(struct i40e_pf *pf)
  5058. {
  5059. struct i40e_hw *hw = &pf->hw;
  5060. i40e_status ret;
  5061. u8 filter_index;
  5062. __be16 port;
  5063. int i;
  5064. if (!(pf->flags & I40E_FLAG_VXLAN_FILTER_SYNC))
  5065. return;
  5066. pf->flags &= ~I40E_FLAG_VXLAN_FILTER_SYNC;
  5067. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  5068. if (pf->pending_vxlan_bitmap & (1 << i)) {
  5069. pf->pending_vxlan_bitmap &= ~(1 << i);
  5070. port = pf->vxlan_ports[i];
  5071. ret = port ?
  5072. i40e_aq_add_udp_tunnel(hw, ntohs(port),
  5073. I40E_AQC_TUNNEL_TYPE_VXLAN,
  5074. &filter_index, NULL)
  5075. : i40e_aq_del_udp_tunnel(hw, i, NULL);
  5076. if (ret) {
  5077. dev_info(&pf->pdev->dev, "Failed to execute AQ command for %s port %d with index %d\n",
  5078. port ? "adding" : "deleting",
  5079. ntohs(port), port ? i : i);
  5080. pf->vxlan_ports[i] = 0;
  5081. } else {
  5082. dev_info(&pf->pdev->dev, "%s port %d with AQ command with index %d\n",
  5083. port ? "Added" : "Deleted",
  5084. ntohs(port), port ? i : filter_index);
  5085. }
  5086. }
  5087. }
  5088. }
  5089. #endif
  5090. /**
  5091. * i40e_service_task - Run the driver's async subtasks
  5092. * @work: pointer to work_struct containing our data
  5093. **/
  5094. static void i40e_service_task(struct work_struct *work)
  5095. {
  5096. struct i40e_pf *pf = container_of(work,
  5097. struct i40e_pf,
  5098. service_task);
  5099. unsigned long start_time = jiffies;
  5100. i40e_reset_subtask(pf);
  5101. i40e_handle_mdd_event(pf);
  5102. i40e_vc_process_vflr_event(pf);
  5103. i40e_watchdog_subtask(pf);
  5104. i40e_fdir_reinit_subtask(pf);
  5105. i40e_check_hang_subtask(pf);
  5106. i40e_sync_filters_subtask(pf);
  5107. #ifdef CONFIG_I40E_VXLAN
  5108. i40e_sync_vxlan_filters_subtask(pf);
  5109. #endif
  5110. i40e_clean_adminq_subtask(pf);
  5111. i40e_service_event_complete(pf);
  5112. /* If the tasks have taken longer than one timer cycle or there
  5113. * is more work to be done, reschedule the service task now
  5114. * rather than wait for the timer to tick again.
  5115. */
  5116. if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
  5117. test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) ||
  5118. test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) ||
  5119. test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
  5120. i40e_service_event_schedule(pf);
  5121. }
  5122. /**
  5123. * i40e_service_timer - timer callback
  5124. * @data: pointer to PF struct
  5125. **/
  5126. static void i40e_service_timer(unsigned long data)
  5127. {
  5128. struct i40e_pf *pf = (struct i40e_pf *)data;
  5129. mod_timer(&pf->service_timer,
  5130. round_jiffies(jiffies + pf->service_timer_period));
  5131. i40e_service_event_schedule(pf);
  5132. }
  5133. /**
  5134. * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
  5135. * @vsi: the VSI being configured
  5136. **/
  5137. static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
  5138. {
  5139. struct i40e_pf *pf = vsi->back;
  5140. switch (vsi->type) {
  5141. case I40E_VSI_MAIN:
  5142. vsi->alloc_queue_pairs = pf->num_lan_qps;
  5143. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  5144. I40E_REQ_DESCRIPTOR_MULTIPLE);
  5145. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  5146. vsi->num_q_vectors = pf->num_lan_msix;
  5147. else
  5148. vsi->num_q_vectors = 1;
  5149. break;
  5150. case I40E_VSI_FDIR:
  5151. vsi->alloc_queue_pairs = 1;
  5152. vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT,
  5153. I40E_REQ_DESCRIPTOR_MULTIPLE);
  5154. vsi->num_q_vectors = 1;
  5155. break;
  5156. case I40E_VSI_VMDQ2:
  5157. vsi->alloc_queue_pairs = pf->num_vmdq_qps;
  5158. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  5159. I40E_REQ_DESCRIPTOR_MULTIPLE);
  5160. vsi->num_q_vectors = pf->num_vmdq_msix;
  5161. break;
  5162. case I40E_VSI_SRIOV:
  5163. vsi->alloc_queue_pairs = pf->num_vf_qps;
  5164. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  5165. I40E_REQ_DESCRIPTOR_MULTIPLE);
  5166. break;
  5167. default:
  5168. WARN_ON(1);
  5169. return -ENODATA;
  5170. }
  5171. return 0;
  5172. }
  5173. /**
  5174. * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
  5175. * @type: VSI pointer
  5176. * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
  5177. *
  5178. * On error: returns error code (negative)
  5179. * On success: returns 0
  5180. **/
  5181. static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)
  5182. {
  5183. int size;
  5184. int ret = 0;
  5185. /* allocate memory for both Tx and Rx ring pointers */
  5186. size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2;
  5187. vsi->tx_rings = kzalloc(size, GFP_KERNEL);
  5188. if (!vsi->tx_rings)
  5189. return -ENOMEM;
  5190. vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs];
  5191. if (alloc_qvectors) {
  5192. /* allocate memory for q_vector pointers */
  5193. size = sizeof(struct i40e_q_vectors *) * vsi->num_q_vectors;
  5194. vsi->q_vectors = kzalloc(size, GFP_KERNEL);
  5195. if (!vsi->q_vectors) {
  5196. ret = -ENOMEM;
  5197. goto err_vectors;
  5198. }
  5199. }
  5200. return ret;
  5201. err_vectors:
  5202. kfree(vsi->tx_rings);
  5203. return ret;
  5204. }
  5205. /**
  5206. * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
  5207. * @pf: board private structure
  5208. * @type: type of VSI
  5209. *
  5210. * On error: returns error code (negative)
  5211. * On success: returns vsi index in PF (positive)
  5212. **/
  5213. static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
  5214. {
  5215. int ret = -ENODEV;
  5216. struct i40e_vsi *vsi;
  5217. int vsi_idx;
  5218. int i;
  5219. /* Need to protect the allocation of the VSIs at the PF level */
  5220. mutex_lock(&pf->switch_mutex);
  5221. /* VSI list may be fragmented if VSI creation/destruction has
  5222. * been happening. We can afford to do a quick scan to look
  5223. * for any free VSIs in the list.
  5224. *
  5225. * find next empty vsi slot, looping back around if necessary
  5226. */
  5227. i = pf->next_vsi;
  5228. while (i < pf->num_alloc_vsi && pf->vsi[i])
  5229. i++;
  5230. if (i >= pf->num_alloc_vsi) {
  5231. i = 0;
  5232. while (i < pf->next_vsi && pf->vsi[i])
  5233. i++;
  5234. }
  5235. if (i < pf->num_alloc_vsi && !pf->vsi[i]) {
  5236. vsi_idx = i; /* Found one! */
  5237. } else {
  5238. ret = -ENODEV;
  5239. goto unlock_pf; /* out of VSI slots! */
  5240. }
  5241. pf->next_vsi = ++i;
  5242. vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
  5243. if (!vsi) {
  5244. ret = -ENOMEM;
  5245. goto unlock_pf;
  5246. }
  5247. vsi->type = type;
  5248. vsi->back = pf;
  5249. set_bit(__I40E_DOWN, &vsi->state);
  5250. vsi->flags = 0;
  5251. vsi->idx = vsi_idx;
  5252. vsi->rx_itr_setting = pf->rx_itr_default;
  5253. vsi->tx_itr_setting = pf->tx_itr_default;
  5254. vsi->netdev_registered = false;
  5255. vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
  5256. INIT_LIST_HEAD(&vsi->mac_filter_list);
  5257. vsi->irqs_ready = false;
  5258. ret = i40e_set_num_rings_in_vsi(vsi);
  5259. if (ret)
  5260. goto err_rings;
  5261. ret = i40e_vsi_alloc_arrays(vsi, true);
  5262. if (ret)
  5263. goto err_rings;
  5264. /* Setup default MSIX irq handler for VSI */
  5265. i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
  5266. pf->vsi[vsi_idx] = vsi;
  5267. ret = vsi_idx;
  5268. goto unlock_pf;
  5269. err_rings:
  5270. pf->next_vsi = i - 1;
  5271. kfree(vsi);
  5272. unlock_pf:
  5273. mutex_unlock(&pf->switch_mutex);
  5274. return ret;
  5275. }
  5276. /**
  5277. * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
  5278. * @type: VSI pointer
  5279. * @free_qvectors: a bool to specify if q_vectors need to be freed.
  5280. *
  5281. * On error: returns error code (negative)
  5282. * On success: returns 0
  5283. **/
  5284. static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors)
  5285. {
  5286. /* free the ring and vector containers */
  5287. if (free_qvectors) {
  5288. kfree(vsi->q_vectors);
  5289. vsi->q_vectors = NULL;
  5290. }
  5291. kfree(vsi->tx_rings);
  5292. vsi->tx_rings = NULL;
  5293. vsi->rx_rings = NULL;
  5294. }
  5295. /**
  5296. * i40e_vsi_clear - Deallocate the VSI provided
  5297. * @vsi: the VSI being un-configured
  5298. **/
  5299. static int i40e_vsi_clear(struct i40e_vsi *vsi)
  5300. {
  5301. struct i40e_pf *pf;
  5302. if (!vsi)
  5303. return 0;
  5304. if (!vsi->back)
  5305. goto free_vsi;
  5306. pf = vsi->back;
  5307. mutex_lock(&pf->switch_mutex);
  5308. if (!pf->vsi[vsi->idx]) {
  5309. dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
  5310. vsi->idx, vsi->idx, vsi, vsi->type);
  5311. goto unlock_vsi;
  5312. }
  5313. if (pf->vsi[vsi->idx] != vsi) {
  5314. dev_err(&pf->pdev->dev,
  5315. "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
  5316. pf->vsi[vsi->idx]->idx,
  5317. pf->vsi[vsi->idx],
  5318. pf->vsi[vsi->idx]->type,
  5319. vsi->idx, vsi, vsi->type);
  5320. goto unlock_vsi;
  5321. }
  5322. /* updates the pf for this cleared vsi */
  5323. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  5324. i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
  5325. i40e_vsi_free_arrays(vsi, true);
  5326. pf->vsi[vsi->idx] = NULL;
  5327. if (vsi->idx < pf->next_vsi)
  5328. pf->next_vsi = vsi->idx;
  5329. unlock_vsi:
  5330. mutex_unlock(&pf->switch_mutex);
  5331. free_vsi:
  5332. kfree(vsi);
  5333. return 0;
  5334. }
  5335. /**
  5336. * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
  5337. * @vsi: the VSI being cleaned
  5338. **/
  5339. static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
  5340. {
  5341. int i;
  5342. if (vsi->tx_rings && vsi->tx_rings[0]) {
  5343. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  5344. kfree_rcu(vsi->tx_rings[i], rcu);
  5345. vsi->tx_rings[i] = NULL;
  5346. vsi->rx_rings[i] = NULL;
  5347. }
  5348. }
  5349. }
  5350. /**
  5351. * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
  5352. * @vsi: the VSI being configured
  5353. **/
  5354. static int i40e_alloc_rings(struct i40e_vsi *vsi)
  5355. {
  5356. struct i40e_ring *tx_ring, *rx_ring;
  5357. struct i40e_pf *pf = vsi->back;
  5358. int i;
  5359. /* Set basic values in the rings to be used later during open() */
  5360. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  5361. /* allocate space for both Tx and Rx in one shot */
  5362. tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL);
  5363. if (!tx_ring)
  5364. goto err_out;
  5365. tx_ring->queue_index = i;
  5366. tx_ring->reg_idx = vsi->base_queue + i;
  5367. tx_ring->ring_active = false;
  5368. tx_ring->vsi = vsi;
  5369. tx_ring->netdev = vsi->netdev;
  5370. tx_ring->dev = &pf->pdev->dev;
  5371. tx_ring->count = vsi->num_desc;
  5372. tx_ring->size = 0;
  5373. tx_ring->dcb_tc = 0;
  5374. vsi->tx_rings[i] = tx_ring;
  5375. rx_ring = &tx_ring[1];
  5376. rx_ring->queue_index = i;
  5377. rx_ring->reg_idx = vsi->base_queue + i;
  5378. rx_ring->ring_active = false;
  5379. rx_ring->vsi = vsi;
  5380. rx_ring->netdev = vsi->netdev;
  5381. rx_ring->dev = &pf->pdev->dev;
  5382. rx_ring->count = vsi->num_desc;
  5383. rx_ring->size = 0;
  5384. rx_ring->dcb_tc = 0;
  5385. if (pf->flags & I40E_FLAG_16BYTE_RX_DESC_ENABLED)
  5386. set_ring_16byte_desc_enabled(rx_ring);
  5387. else
  5388. clear_ring_16byte_desc_enabled(rx_ring);
  5389. vsi->rx_rings[i] = rx_ring;
  5390. }
  5391. return 0;
  5392. err_out:
  5393. i40e_vsi_clear_rings(vsi);
  5394. return -ENOMEM;
  5395. }
  5396. /**
  5397. * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
  5398. * @pf: board private structure
  5399. * @vectors: the number of MSI-X vectors to request
  5400. *
  5401. * Returns the number of vectors reserved, or error
  5402. **/
  5403. static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
  5404. {
  5405. vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries,
  5406. I40E_MIN_MSIX, vectors);
  5407. if (vectors < 0) {
  5408. dev_info(&pf->pdev->dev,
  5409. "MSI-X vector reservation failed: %d\n", vectors);
  5410. vectors = 0;
  5411. }
  5412. return vectors;
  5413. }
  5414. /**
  5415. * i40e_init_msix - Setup the MSIX capability
  5416. * @pf: board private structure
  5417. *
  5418. * Work with the OS to set up the MSIX vectors needed.
  5419. *
  5420. * Returns 0 on success, negative on failure
  5421. **/
  5422. static int i40e_init_msix(struct i40e_pf *pf)
  5423. {
  5424. i40e_status err = 0;
  5425. struct i40e_hw *hw = &pf->hw;
  5426. int v_budget, i;
  5427. int vec;
  5428. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  5429. return -ENODEV;
  5430. /* The number of vectors we'll request will be comprised of:
  5431. * - Add 1 for "other" cause for Admin Queue events, etc.
  5432. * - The number of LAN queue pairs
  5433. * - Queues being used for RSS.
  5434. * We don't need as many as max_rss_size vectors.
  5435. * use rss_size instead in the calculation since that
  5436. * is governed by number of cpus in the system.
  5437. * - assumes symmetric Tx/Rx pairing
  5438. * - The number of VMDq pairs
  5439. * Once we count this up, try the request.
  5440. *
  5441. * If we can't get what we want, we'll simplify to nearly nothing
  5442. * and try again. If that still fails, we punt.
  5443. */
  5444. pf->num_lan_msix = pf->num_lan_qps - (pf->rss_size_max - pf->rss_size);
  5445. pf->num_vmdq_msix = pf->num_vmdq_qps;
  5446. v_budget = 1 + pf->num_lan_msix;
  5447. v_budget += (pf->num_vmdq_vsis * pf->num_vmdq_msix);
  5448. if (pf->flags & I40E_FLAG_FD_SB_ENABLED)
  5449. v_budget++;
  5450. /* Scale down if necessary, and the rings will share vectors */
  5451. v_budget = min_t(int, v_budget, hw->func_caps.num_msix_vectors);
  5452. pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
  5453. GFP_KERNEL);
  5454. if (!pf->msix_entries)
  5455. return -ENOMEM;
  5456. for (i = 0; i < v_budget; i++)
  5457. pf->msix_entries[i].entry = i;
  5458. vec = i40e_reserve_msix_vectors(pf, v_budget);
  5459. if (vec != v_budget) {
  5460. /* If we have limited resources, we will start with no vectors
  5461. * for the special features and then allocate vectors to some
  5462. * of these features based on the policy and at the end disable
  5463. * the features that did not get any vectors.
  5464. */
  5465. pf->num_vmdq_msix = 0;
  5466. }
  5467. if (vec < I40E_MIN_MSIX) {
  5468. pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
  5469. kfree(pf->msix_entries);
  5470. pf->msix_entries = NULL;
  5471. return -ENODEV;
  5472. } else if (vec == I40E_MIN_MSIX) {
  5473. /* Adjust for minimal MSIX use */
  5474. pf->num_vmdq_vsis = 0;
  5475. pf->num_vmdq_qps = 0;
  5476. pf->num_lan_qps = 1;
  5477. pf->num_lan_msix = 1;
  5478. } else if (vec != v_budget) {
  5479. /* reserve the misc vector */
  5480. vec--;
  5481. /* Scale vector usage down */
  5482. pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
  5483. pf->num_vmdq_vsis = 1;
  5484. /* partition out the remaining vectors */
  5485. switch (vec) {
  5486. case 2:
  5487. pf->num_lan_msix = 1;
  5488. break;
  5489. case 3:
  5490. pf->num_lan_msix = 2;
  5491. break;
  5492. default:
  5493. pf->num_lan_msix = min_t(int, (vec / 2),
  5494. pf->num_lan_qps);
  5495. pf->num_vmdq_vsis = min_t(int, (vec - pf->num_lan_msix),
  5496. I40E_DEFAULT_NUM_VMDQ_VSI);
  5497. break;
  5498. }
  5499. }
  5500. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  5501. (pf->num_vmdq_msix == 0)) {
  5502. dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n");
  5503. pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
  5504. }
  5505. return err;
  5506. }
  5507. /**
  5508. * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
  5509. * @vsi: the VSI being configured
  5510. * @v_idx: index of the vector in the vsi struct
  5511. *
  5512. * We allocate one q_vector. If allocation fails we return -ENOMEM.
  5513. **/
  5514. static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx)
  5515. {
  5516. struct i40e_q_vector *q_vector;
  5517. /* allocate q_vector */
  5518. q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
  5519. if (!q_vector)
  5520. return -ENOMEM;
  5521. q_vector->vsi = vsi;
  5522. q_vector->v_idx = v_idx;
  5523. cpumask_set_cpu(v_idx, &q_vector->affinity_mask);
  5524. if (vsi->netdev)
  5525. netif_napi_add(vsi->netdev, &q_vector->napi,
  5526. i40e_napi_poll, NAPI_POLL_WEIGHT);
  5527. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  5528. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  5529. /* tie q_vector and vsi together */
  5530. vsi->q_vectors[v_idx] = q_vector;
  5531. return 0;
  5532. }
  5533. /**
  5534. * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
  5535. * @vsi: the VSI being configured
  5536. *
  5537. * We allocate one q_vector per queue interrupt. If allocation fails we
  5538. * return -ENOMEM.
  5539. **/
  5540. static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi)
  5541. {
  5542. struct i40e_pf *pf = vsi->back;
  5543. int v_idx, num_q_vectors;
  5544. int err;
  5545. /* if not MSIX, give the one vector only to the LAN VSI */
  5546. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  5547. num_q_vectors = vsi->num_q_vectors;
  5548. else if (vsi == pf->vsi[pf->lan_vsi])
  5549. num_q_vectors = 1;
  5550. else
  5551. return -EINVAL;
  5552. for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
  5553. err = i40e_vsi_alloc_q_vector(vsi, v_idx);
  5554. if (err)
  5555. goto err_out;
  5556. }
  5557. return 0;
  5558. err_out:
  5559. while (v_idx--)
  5560. i40e_free_q_vector(vsi, v_idx);
  5561. return err;
  5562. }
  5563. /**
  5564. * i40e_init_interrupt_scheme - Determine proper interrupt scheme
  5565. * @pf: board private structure to initialize
  5566. **/
  5567. static void i40e_init_interrupt_scheme(struct i40e_pf *pf)
  5568. {
  5569. int err = 0;
  5570. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  5571. err = i40e_init_msix(pf);
  5572. if (err) {
  5573. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
  5574. I40E_FLAG_RSS_ENABLED |
  5575. I40E_FLAG_DCB_CAPABLE |
  5576. I40E_FLAG_SRIOV_ENABLED |
  5577. I40E_FLAG_FD_SB_ENABLED |
  5578. I40E_FLAG_FD_ATR_ENABLED |
  5579. I40E_FLAG_VMDQ_ENABLED);
  5580. /* rework the queue expectations without MSIX */
  5581. i40e_determine_queue_usage(pf);
  5582. }
  5583. }
  5584. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  5585. (pf->flags & I40E_FLAG_MSI_ENABLED)) {
  5586. dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n");
  5587. err = pci_enable_msi(pf->pdev);
  5588. if (err) {
  5589. dev_info(&pf->pdev->dev, "MSI init failed - %d\n", err);
  5590. pf->flags &= ~I40E_FLAG_MSI_ENABLED;
  5591. }
  5592. }
  5593. if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
  5594. dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
  5595. /* track first vector for misc interrupts */
  5596. err = i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT-1);
  5597. }
  5598. /**
  5599. * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
  5600. * @pf: board private structure
  5601. *
  5602. * This sets up the handler for MSIX 0, which is used to manage the
  5603. * non-queue interrupts, e.g. AdminQ and errors. This is not used
  5604. * when in MSI or Legacy interrupt mode.
  5605. **/
  5606. static int i40e_setup_misc_vector(struct i40e_pf *pf)
  5607. {
  5608. struct i40e_hw *hw = &pf->hw;
  5609. int err = 0;
  5610. /* Only request the irq if this is the first time through, and
  5611. * not when we're rebuilding after a Reset
  5612. */
  5613. if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
  5614. err = request_irq(pf->msix_entries[0].vector,
  5615. i40e_intr, 0, pf->misc_int_name, pf);
  5616. if (err) {
  5617. dev_info(&pf->pdev->dev,
  5618. "request_irq for %s failed: %d\n",
  5619. pf->misc_int_name, err);
  5620. return -EFAULT;
  5621. }
  5622. }
  5623. i40e_enable_misc_int_causes(hw);
  5624. /* associate no queues to the misc vector */
  5625. wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
  5626. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K);
  5627. i40e_flush(hw);
  5628. i40e_irq_dynamic_enable_icr0(pf);
  5629. return err;
  5630. }
  5631. /**
  5632. * i40e_config_rss - Prepare for RSS if used
  5633. * @pf: board private structure
  5634. **/
  5635. static int i40e_config_rss(struct i40e_pf *pf)
  5636. {
  5637. /* Set of random keys generated using kernel random number generator */
  5638. static const u32 seed[I40E_PFQF_HKEY_MAX_INDEX + 1] = {0x41b01687,
  5639. 0x183cfd8c, 0xce880440, 0x580cbc3c, 0x35897377,
  5640. 0x328b25e1, 0x4fa98922, 0xb7d90c14, 0xd5bad70d,
  5641. 0xcd15a2c1, 0xe8580225, 0x4a1e9d11, 0xfe5731be};
  5642. struct i40e_hw *hw = &pf->hw;
  5643. u32 lut = 0;
  5644. int i, j;
  5645. u64 hena;
  5646. /* Fill out hash function seed */
  5647. for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
  5648. wr32(hw, I40E_PFQF_HKEY(i), seed[i]);
  5649. /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
  5650. hena = (u64)rd32(hw, I40E_PFQF_HENA(0)) |
  5651. ((u64)rd32(hw, I40E_PFQF_HENA(1)) << 32);
  5652. hena |= I40E_DEFAULT_RSS_HENA;
  5653. wr32(hw, I40E_PFQF_HENA(0), (u32)hena);
  5654. wr32(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  5655. /* Populate the LUT with max no. of queues in round robin fashion */
  5656. for (i = 0, j = 0; i < pf->hw.func_caps.rss_table_size; i++, j++) {
  5657. /* The assumption is that lan qp count will be the highest
  5658. * qp count for any PF VSI that needs RSS.
  5659. * If multiple VSIs need RSS support, all the qp counts
  5660. * for those VSIs should be a power of 2 for RSS to work.
  5661. * If LAN VSI is the only consumer for RSS then this requirement
  5662. * is not necessary.
  5663. */
  5664. if (j == pf->rss_size)
  5665. j = 0;
  5666. /* lut = 4-byte sliding window of 4 lut entries */
  5667. lut = (lut << 8) | (j &
  5668. ((0x1 << pf->hw.func_caps.rss_table_entry_width) - 1));
  5669. /* On i = 3, we have 4 entries in lut; write to the register */
  5670. if ((i & 3) == 3)
  5671. wr32(hw, I40E_PFQF_HLUT(i >> 2), lut);
  5672. }
  5673. i40e_flush(hw);
  5674. return 0;
  5675. }
  5676. /**
  5677. * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
  5678. * @pf: board private structure
  5679. * @queue_count: the requested queue count for rss.
  5680. *
  5681. * returns 0 if rss is not enabled, if enabled returns the final rss queue
  5682. * count which may be different from the requested queue count.
  5683. **/
  5684. int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
  5685. {
  5686. if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
  5687. return 0;
  5688. queue_count = min_t(int, queue_count, pf->rss_size_max);
  5689. if (queue_count != pf->rss_size) {
  5690. i40e_prep_for_reset(pf);
  5691. pf->rss_size = queue_count;
  5692. i40e_reset_and_rebuild(pf, true);
  5693. i40e_config_rss(pf);
  5694. }
  5695. dev_info(&pf->pdev->dev, "RSS count: %d\n", pf->rss_size);
  5696. return pf->rss_size;
  5697. }
  5698. /**
  5699. * i40e_sw_init - Initialize general software structures (struct i40e_pf)
  5700. * @pf: board private structure to initialize
  5701. *
  5702. * i40e_sw_init initializes the Adapter private data structure.
  5703. * Fields are initialized based on PCI device information and
  5704. * OS network device settings (MTU size).
  5705. **/
  5706. static int i40e_sw_init(struct i40e_pf *pf)
  5707. {
  5708. int err = 0;
  5709. int size;
  5710. pf->msg_enable = netif_msg_init(I40E_DEFAULT_MSG_ENABLE,
  5711. (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK));
  5712. pf->hw.debug_mask = pf->msg_enable | I40E_DEBUG_DIAG;
  5713. if (debug != -1 && debug != I40E_DEFAULT_MSG_ENABLE) {
  5714. if (I40E_DEBUG_USER & debug)
  5715. pf->hw.debug_mask = debug;
  5716. pf->msg_enable = netif_msg_init((debug & ~I40E_DEBUG_USER),
  5717. I40E_DEFAULT_MSG_ENABLE);
  5718. }
  5719. /* Set default capability flags */
  5720. pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
  5721. I40E_FLAG_MSI_ENABLED |
  5722. I40E_FLAG_MSIX_ENABLED |
  5723. I40E_FLAG_RX_1BUF_ENABLED;
  5724. /* Set default ITR */
  5725. pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF;
  5726. pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF;
  5727. /* Depending on PF configurations, it is possible that the RSS
  5728. * maximum might end up larger than the available queues
  5729. */
  5730. pf->rss_size_max = 0x1 << pf->hw.func_caps.rss_table_entry_width;
  5731. pf->rss_size_max = min_t(int, pf->rss_size_max,
  5732. pf->hw.func_caps.num_tx_qp);
  5733. if (pf->hw.func_caps.rss) {
  5734. pf->flags |= I40E_FLAG_RSS_ENABLED;
  5735. pf->rss_size = min_t(int, pf->rss_size_max, num_online_cpus());
  5736. } else {
  5737. pf->rss_size = 1;
  5738. }
  5739. /* MFP mode enabled */
  5740. if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.mfp_mode_1) {
  5741. pf->flags |= I40E_FLAG_MFP_ENABLED;
  5742. dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
  5743. }
  5744. /* FW/NVM is not yet fixed in this regard */
  5745. if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
  5746. (pf->hw.func_caps.fd_filters_best_effort > 0)) {
  5747. pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
  5748. pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
  5749. /* Setup a counter for fd_atr per pf */
  5750. pf->fd_atr_cnt_idx = I40E_FD_ATR_STAT_IDX(pf->hw.pf_id);
  5751. if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) {
  5752. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  5753. /* Setup a counter for fd_sb per pf */
  5754. pf->fd_sb_cnt_idx = I40E_FD_SB_STAT_IDX(pf->hw.pf_id);
  5755. } else {
  5756. dev_info(&pf->pdev->dev,
  5757. "Flow Director Sideband mode Disabled in MFP mode\n");
  5758. }
  5759. pf->fdir_pf_filter_count =
  5760. pf->hw.func_caps.fd_filters_guaranteed;
  5761. pf->hw.fdir_shared_filter_count =
  5762. pf->hw.func_caps.fd_filters_best_effort;
  5763. }
  5764. if (pf->hw.func_caps.vmdq) {
  5765. pf->flags |= I40E_FLAG_VMDQ_ENABLED;
  5766. pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
  5767. pf->num_vmdq_qps = I40E_DEFAULT_QUEUES_PER_VMDQ;
  5768. }
  5769. #ifdef CONFIG_PCI_IOV
  5770. if (pf->hw.func_caps.num_vfs) {
  5771. pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
  5772. pf->flags |= I40E_FLAG_SRIOV_ENABLED;
  5773. pf->num_req_vfs = min_t(int,
  5774. pf->hw.func_caps.num_vfs,
  5775. I40E_MAX_VF_COUNT);
  5776. }
  5777. #endif /* CONFIG_PCI_IOV */
  5778. pf->eeprom_version = 0xDEAD;
  5779. pf->lan_veb = I40E_NO_VEB;
  5780. pf->lan_vsi = I40E_NO_VSI;
  5781. /* set up queue assignment tracking */
  5782. size = sizeof(struct i40e_lump_tracking)
  5783. + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
  5784. pf->qp_pile = kzalloc(size, GFP_KERNEL);
  5785. if (!pf->qp_pile) {
  5786. err = -ENOMEM;
  5787. goto sw_init_done;
  5788. }
  5789. pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
  5790. pf->qp_pile->search_hint = 0;
  5791. /* set up vector assignment tracking */
  5792. size = sizeof(struct i40e_lump_tracking)
  5793. + (sizeof(u16) * pf->hw.func_caps.num_msix_vectors);
  5794. pf->irq_pile = kzalloc(size, GFP_KERNEL);
  5795. if (!pf->irq_pile) {
  5796. kfree(pf->qp_pile);
  5797. err = -ENOMEM;
  5798. goto sw_init_done;
  5799. }
  5800. pf->irq_pile->num_entries = pf->hw.func_caps.num_msix_vectors;
  5801. pf->irq_pile->search_hint = 0;
  5802. mutex_init(&pf->switch_mutex);
  5803. sw_init_done:
  5804. return err;
  5805. }
  5806. /**
  5807. * i40e_set_ntuple - set the ntuple feature flag and take action
  5808. * @pf: board private structure to initialize
  5809. * @features: the feature set that the stack is suggesting
  5810. *
  5811. * returns a bool to indicate if reset needs to happen
  5812. **/
  5813. bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
  5814. {
  5815. bool need_reset = false;
  5816. /* Check if Flow Director n-tuple support was enabled or disabled. If
  5817. * the state changed, we need to reset.
  5818. */
  5819. if (features & NETIF_F_NTUPLE) {
  5820. /* Enable filters and mark for reset */
  5821. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  5822. need_reset = true;
  5823. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  5824. } else {
  5825. /* turn off filters, mark for reset and clear SW filter list */
  5826. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  5827. need_reset = true;
  5828. i40e_fdir_filter_exit(pf);
  5829. }
  5830. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  5831. /* if ATR was disabled it can be re-enabled. */
  5832. if (!(pf->flags & I40E_FLAG_FD_ATR_ENABLED))
  5833. pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
  5834. }
  5835. return need_reset;
  5836. }
  5837. /**
  5838. * i40e_set_features - set the netdev feature flags
  5839. * @netdev: ptr to the netdev being adjusted
  5840. * @features: the feature set that the stack is suggesting
  5841. **/
  5842. static int i40e_set_features(struct net_device *netdev,
  5843. netdev_features_t features)
  5844. {
  5845. struct i40e_netdev_priv *np = netdev_priv(netdev);
  5846. struct i40e_vsi *vsi = np->vsi;
  5847. struct i40e_pf *pf = vsi->back;
  5848. bool need_reset;
  5849. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  5850. i40e_vlan_stripping_enable(vsi);
  5851. else
  5852. i40e_vlan_stripping_disable(vsi);
  5853. need_reset = i40e_set_ntuple(pf, features);
  5854. if (need_reset)
  5855. i40e_do_reset(pf, (1 << __I40E_PF_RESET_REQUESTED));
  5856. return 0;
  5857. }
  5858. #ifdef CONFIG_I40E_VXLAN
  5859. /**
  5860. * i40e_get_vxlan_port_idx - Lookup a possibly offloaded for Rx UDP port
  5861. * @pf: board private structure
  5862. * @port: The UDP port to look up
  5863. *
  5864. * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
  5865. **/
  5866. static u8 i40e_get_vxlan_port_idx(struct i40e_pf *pf, __be16 port)
  5867. {
  5868. u8 i;
  5869. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  5870. if (pf->vxlan_ports[i] == port)
  5871. return i;
  5872. }
  5873. return i;
  5874. }
  5875. /**
  5876. * i40e_add_vxlan_port - Get notifications about VXLAN ports that come up
  5877. * @netdev: This physical port's netdev
  5878. * @sa_family: Socket Family that VXLAN is notifying us about
  5879. * @port: New UDP port number that VXLAN started listening to
  5880. **/
  5881. static void i40e_add_vxlan_port(struct net_device *netdev,
  5882. sa_family_t sa_family, __be16 port)
  5883. {
  5884. struct i40e_netdev_priv *np = netdev_priv(netdev);
  5885. struct i40e_vsi *vsi = np->vsi;
  5886. struct i40e_pf *pf = vsi->back;
  5887. u8 next_idx;
  5888. u8 idx;
  5889. if (sa_family == AF_INET6)
  5890. return;
  5891. idx = i40e_get_vxlan_port_idx(pf, port);
  5892. /* Check if port already exists */
  5893. if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  5894. netdev_info(netdev, "Port %d already offloaded\n", ntohs(port));
  5895. return;
  5896. }
  5897. /* Now check if there is space to add the new port */
  5898. next_idx = i40e_get_vxlan_port_idx(pf, 0);
  5899. if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  5900. netdev_info(netdev, "Maximum number of UDP ports reached, not adding port %d\n",
  5901. ntohs(port));
  5902. return;
  5903. }
  5904. /* New port: add it and mark its index in the bitmap */
  5905. pf->vxlan_ports[next_idx] = port;
  5906. pf->pending_vxlan_bitmap |= (1 << next_idx);
  5907. pf->flags |= I40E_FLAG_VXLAN_FILTER_SYNC;
  5908. }
  5909. /**
  5910. * i40e_del_vxlan_port - Get notifications about VXLAN ports that go away
  5911. * @netdev: This physical port's netdev
  5912. * @sa_family: Socket Family that VXLAN is notifying us about
  5913. * @port: UDP port number that VXLAN stopped listening to
  5914. **/
  5915. static void i40e_del_vxlan_port(struct net_device *netdev,
  5916. sa_family_t sa_family, __be16 port)
  5917. {
  5918. struct i40e_netdev_priv *np = netdev_priv(netdev);
  5919. struct i40e_vsi *vsi = np->vsi;
  5920. struct i40e_pf *pf = vsi->back;
  5921. u8 idx;
  5922. if (sa_family == AF_INET6)
  5923. return;
  5924. idx = i40e_get_vxlan_port_idx(pf, port);
  5925. /* Check if port already exists */
  5926. if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  5927. /* if port exists, set it to 0 (mark for deletion)
  5928. * and make it pending
  5929. */
  5930. pf->vxlan_ports[idx] = 0;
  5931. pf->pending_vxlan_bitmap |= (1 << idx);
  5932. pf->flags |= I40E_FLAG_VXLAN_FILTER_SYNC;
  5933. } else {
  5934. netdev_warn(netdev, "Port %d was not found, not deleting\n",
  5935. ntohs(port));
  5936. }
  5937. }
  5938. #endif
  5939. #ifdef HAVE_FDB_OPS
  5940. #ifdef USE_CONST_DEV_UC_CHAR
  5941. static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  5942. struct net_device *dev,
  5943. const unsigned char *addr,
  5944. u16 flags)
  5945. #else
  5946. static int i40e_ndo_fdb_add(struct ndmsg *ndm,
  5947. struct net_device *dev,
  5948. unsigned char *addr,
  5949. u16 flags)
  5950. #endif
  5951. {
  5952. struct i40e_netdev_priv *np = netdev_priv(dev);
  5953. struct i40e_pf *pf = np->vsi->back;
  5954. int err = 0;
  5955. if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
  5956. return -EOPNOTSUPP;
  5957. /* Hardware does not support aging addresses so if a
  5958. * ndm_state is given only allow permanent addresses
  5959. */
  5960. if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
  5961. netdev_info(dev, "FDB only supports static addresses\n");
  5962. return -EINVAL;
  5963. }
  5964. if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
  5965. err = dev_uc_add_excl(dev, addr);
  5966. else if (is_multicast_ether_addr(addr))
  5967. err = dev_mc_add_excl(dev, addr);
  5968. else
  5969. err = -EINVAL;
  5970. /* Only return duplicate errors if NLM_F_EXCL is set */
  5971. if (err == -EEXIST && !(flags & NLM_F_EXCL))
  5972. err = 0;
  5973. return err;
  5974. }
  5975. #ifndef USE_DEFAULT_FDB_DEL_DUMP
  5976. #ifdef USE_CONST_DEV_UC_CHAR
  5977. static int i40e_ndo_fdb_del(struct ndmsg *ndm,
  5978. struct net_device *dev,
  5979. const unsigned char *addr)
  5980. #else
  5981. static int i40e_ndo_fdb_del(struct ndmsg *ndm,
  5982. struct net_device *dev,
  5983. unsigned char *addr)
  5984. #endif
  5985. {
  5986. struct i40e_netdev_priv *np = netdev_priv(dev);
  5987. struct i40e_pf *pf = np->vsi->back;
  5988. int err = -EOPNOTSUPP;
  5989. if (ndm->ndm_state & NUD_PERMANENT) {
  5990. netdev_info(dev, "FDB only supports static addresses\n");
  5991. return -EINVAL;
  5992. }
  5993. if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
  5994. if (is_unicast_ether_addr(addr))
  5995. err = dev_uc_del(dev, addr);
  5996. else if (is_multicast_ether_addr(addr))
  5997. err = dev_mc_del(dev, addr);
  5998. else
  5999. err = -EINVAL;
  6000. }
  6001. return err;
  6002. }
  6003. static int i40e_ndo_fdb_dump(struct sk_buff *skb,
  6004. struct netlink_callback *cb,
  6005. struct net_device *dev,
  6006. int idx)
  6007. {
  6008. struct i40e_netdev_priv *np = netdev_priv(dev);
  6009. struct i40e_pf *pf = np->vsi->back;
  6010. if (pf->flags & I40E_FLAG_SRIOV_ENABLED)
  6011. idx = ndo_dflt_fdb_dump(skb, cb, dev, idx);
  6012. return idx;
  6013. }
  6014. #endif /* USE_DEFAULT_FDB_DEL_DUMP */
  6015. #endif /* HAVE_FDB_OPS */
  6016. static const struct net_device_ops i40e_netdev_ops = {
  6017. .ndo_open = i40e_open,
  6018. .ndo_stop = i40e_close,
  6019. .ndo_start_xmit = i40e_lan_xmit_frame,
  6020. .ndo_get_stats64 = i40e_get_netdev_stats_struct,
  6021. .ndo_set_rx_mode = i40e_set_rx_mode,
  6022. .ndo_validate_addr = eth_validate_addr,
  6023. .ndo_set_mac_address = i40e_set_mac,
  6024. .ndo_change_mtu = i40e_change_mtu,
  6025. .ndo_do_ioctl = i40e_ioctl,
  6026. .ndo_tx_timeout = i40e_tx_timeout,
  6027. .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
  6028. .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
  6029. #ifdef CONFIG_NET_POLL_CONTROLLER
  6030. .ndo_poll_controller = i40e_netpoll,
  6031. #endif
  6032. .ndo_setup_tc = i40e_setup_tc,
  6033. .ndo_set_features = i40e_set_features,
  6034. .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
  6035. .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
  6036. .ndo_set_vf_rate = i40e_ndo_set_vf_bw,
  6037. .ndo_get_vf_config = i40e_ndo_get_vf_config,
  6038. .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
  6039. .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofck,
  6040. #ifdef CONFIG_I40E_VXLAN
  6041. .ndo_add_vxlan_port = i40e_add_vxlan_port,
  6042. .ndo_del_vxlan_port = i40e_del_vxlan_port,
  6043. #endif
  6044. #ifdef HAVE_FDB_OPS
  6045. .ndo_fdb_add = i40e_ndo_fdb_add,
  6046. #ifndef USE_DEFAULT_FDB_DEL_DUMP
  6047. .ndo_fdb_del = i40e_ndo_fdb_del,
  6048. .ndo_fdb_dump = i40e_ndo_fdb_dump,
  6049. #endif
  6050. #endif
  6051. };
  6052. /**
  6053. * i40e_config_netdev - Setup the netdev flags
  6054. * @vsi: the VSI being configured
  6055. *
  6056. * Returns 0 on success, negative value on failure
  6057. **/
  6058. static int i40e_config_netdev(struct i40e_vsi *vsi)
  6059. {
  6060. u8 brdcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
  6061. struct i40e_pf *pf = vsi->back;
  6062. struct i40e_hw *hw = &pf->hw;
  6063. struct i40e_netdev_priv *np;
  6064. struct net_device *netdev;
  6065. u8 mac_addr[ETH_ALEN];
  6066. int etherdev_size;
  6067. etherdev_size = sizeof(struct i40e_netdev_priv);
  6068. netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
  6069. if (!netdev)
  6070. return -ENOMEM;
  6071. vsi->netdev = netdev;
  6072. np = netdev_priv(netdev);
  6073. np->vsi = vsi;
  6074. netdev->hw_enc_features |= NETIF_F_IP_CSUM |
  6075. NETIF_F_GSO_UDP_TUNNEL |
  6076. NETIF_F_TSO;
  6077. netdev->features = NETIF_F_SG |
  6078. NETIF_F_IP_CSUM |
  6079. NETIF_F_SCTP_CSUM |
  6080. NETIF_F_HIGHDMA |
  6081. NETIF_F_GSO_UDP_TUNNEL |
  6082. NETIF_F_HW_VLAN_CTAG_TX |
  6083. NETIF_F_HW_VLAN_CTAG_RX |
  6084. NETIF_F_HW_VLAN_CTAG_FILTER |
  6085. NETIF_F_IPV6_CSUM |
  6086. NETIF_F_TSO |
  6087. NETIF_F_TSO_ECN |
  6088. NETIF_F_TSO6 |
  6089. NETIF_F_RXCSUM |
  6090. NETIF_F_RXHASH |
  6091. 0;
  6092. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  6093. netdev->features |= NETIF_F_NTUPLE;
  6094. /* copy netdev features into list of user selectable features */
  6095. netdev->hw_features |= netdev->features;
  6096. if (vsi->type == I40E_VSI_MAIN) {
  6097. SET_NETDEV_DEV(netdev, &pf->pdev->dev);
  6098. ether_addr_copy(mac_addr, hw->mac.perm_addr);
  6099. /* The following two steps are necessary to prevent reception
  6100. * of tagged packets - by default the NVM loads a MAC-VLAN
  6101. * filter that will accept any tagged packet. This is to
  6102. * prevent that during normal operations until a specific
  6103. * VLAN tag filter has been set.
  6104. */
  6105. i40e_rm_default_mac_filter(vsi, mac_addr);
  6106. i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, true);
  6107. } else {
  6108. /* relate the VSI_VMDQ name to the VSI_MAIN name */
  6109. snprintf(netdev->name, IFNAMSIZ, "%sv%%d",
  6110. pf->vsi[pf->lan_vsi]->netdev->name);
  6111. random_ether_addr(mac_addr);
  6112. i40e_add_filter(vsi, mac_addr, I40E_VLAN_ANY, false, false);
  6113. }
  6114. i40e_add_filter(vsi, brdcast, I40E_VLAN_ANY, false, false);
  6115. ether_addr_copy(netdev->dev_addr, mac_addr);
  6116. ether_addr_copy(netdev->perm_addr, mac_addr);
  6117. /* vlan gets same features (except vlan offload)
  6118. * after any tweaks for specific VSI types
  6119. */
  6120. netdev->vlan_features = netdev->features & ~(NETIF_F_HW_VLAN_CTAG_TX |
  6121. NETIF_F_HW_VLAN_CTAG_RX |
  6122. NETIF_F_HW_VLAN_CTAG_FILTER);
  6123. netdev->priv_flags |= IFF_UNICAST_FLT;
  6124. netdev->priv_flags |= IFF_SUPP_NOFCS;
  6125. /* Setup netdev TC information */
  6126. i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
  6127. netdev->netdev_ops = &i40e_netdev_ops;
  6128. netdev->watchdog_timeo = 5 * HZ;
  6129. i40e_set_ethtool_ops(netdev);
  6130. return 0;
  6131. }
  6132. /**
  6133. * i40e_vsi_delete - Delete a VSI from the switch
  6134. * @vsi: the VSI being removed
  6135. *
  6136. * Returns 0 on success, negative value on failure
  6137. **/
  6138. static void i40e_vsi_delete(struct i40e_vsi *vsi)
  6139. {
  6140. /* remove default VSI is not allowed */
  6141. if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
  6142. return;
  6143. i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
  6144. }
  6145. /**
  6146. * i40e_add_vsi - Add a VSI to the switch
  6147. * @vsi: the VSI being configured
  6148. *
  6149. * This initializes a VSI context depending on the VSI type to be added and
  6150. * passes it down to the add_vsi aq command.
  6151. **/
  6152. static int i40e_add_vsi(struct i40e_vsi *vsi)
  6153. {
  6154. int ret = -ENODEV;
  6155. struct i40e_mac_filter *f, *ftmp;
  6156. struct i40e_pf *pf = vsi->back;
  6157. struct i40e_hw *hw = &pf->hw;
  6158. struct i40e_vsi_context ctxt;
  6159. u8 enabled_tc = 0x1; /* TC0 enabled */
  6160. int f_count = 0;
  6161. memset(&ctxt, 0, sizeof(ctxt));
  6162. switch (vsi->type) {
  6163. case I40E_VSI_MAIN:
  6164. /* The PF's main VSI is already setup as part of the
  6165. * device initialization, so we'll not bother with
  6166. * the add_vsi call, but we will retrieve the current
  6167. * VSI context.
  6168. */
  6169. ctxt.seid = pf->main_vsi_seid;
  6170. ctxt.pf_num = pf->hw.pf_id;
  6171. ctxt.vf_num = 0;
  6172. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  6173. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  6174. if (ret) {
  6175. dev_info(&pf->pdev->dev,
  6176. "couldn't get pf vsi config, err %d, aq_err %d\n",
  6177. ret, pf->hw.aq.asq_last_status);
  6178. return -ENOENT;
  6179. }
  6180. memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
  6181. vsi->info.valid_sections = 0;
  6182. vsi->seid = ctxt.seid;
  6183. vsi->id = ctxt.vsi_number;
  6184. enabled_tc = i40e_pf_get_tc_map(pf);
  6185. /* MFP mode setup queue map and update VSI */
  6186. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  6187. memset(&ctxt, 0, sizeof(ctxt));
  6188. ctxt.seid = pf->main_vsi_seid;
  6189. ctxt.pf_num = pf->hw.pf_id;
  6190. ctxt.vf_num = 0;
  6191. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  6192. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  6193. if (ret) {
  6194. dev_info(&pf->pdev->dev,
  6195. "update vsi failed, aq_err=%d\n",
  6196. pf->hw.aq.asq_last_status);
  6197. ret = -ENOENT;
  6198. goto err;
  6199. }
  6200. /* update the local VSI info queue map */
  6201. i40e_vsi_update_queue_map(vsi, &ctxt);
  6202. vsi->info.valid_sections = 0;
  6203. } else {
  6204. /* Default/Main VSI is only enabled for TC0
  6205. * reconfigure it to enable all TCs that are
  6206. * available on the port in SFP mode.
  6207. */
  6208. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  6209. if (ret) {
  6210. dev_info(&pf->pdev->dev,
  6211. "failed to configure TCs for main VSI tc_map 0x%08x, err %d, aq_err %d\n",
  6212. enabled_tc, ret,
  6213. pf->hw.aq.asq_last_status);
  6214. ret = -ENOENT;
  6215. }
  6216. }
  6217. break;
  6218. case I40E_VSI_FDIR:
  6219. ctxt.pf_num = hw->pf_id;
  6220. ctxt.vf_num = 0;
  6221. ctxt.uplink_seid = vsi->uplink_seid;
  6222. ctxt.connection_type = 0x1; /* regular data port */
  6223. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  6224. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  6225. break;
  6226. case I40E_VSI_VMDQ2:
  6227. ctxt.pf_num = hw->pf_id;
  6228. ctxt.vf_num = 0;
  6229. ctxt.uplink_seid = vsi->uplink_seid;
  6230. ctxt.connection_type = 0x1; /* regular data port */
  6231. ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
  6232. ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  6233. /* This VSI is connected to VEB so the switch_id
  6234. * should be set to zero by default.
  6235. */
  6236. ctxt.info.switch_id = 0;
  6237. ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_LOCAL_LB);
  6238. ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  6239. /* Setup the VSI tx/rx queue map for TC0 only for now */
  6240. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  6241. break;
  6242. case I40E_VSI_SRIOV:
  6243. ctxt.pf_num = hw->pf_id;
  6244. ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
  6245. ctxt.uplink_seid = vsi->uplink_seid;
  6246. ctxt.connection_type = 0x1; /* regular data port */
  6247. ctxt.flags = I40E_AQ_VSI_TYPE_VF;
  6248. ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  6249. /* This VSI is connected to VEB so the switch_id
  6250. * should be set to zero by default.
  6251. */
  6252. ctxt.info.switch_id = cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  6253. ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  6254. ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
  6255. if (pf->vf[vsi->vf_id].spoofchk) {
  6256. ctxt.info.valid_sections |=
  6257. cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
  6258. ctxt.info.sec_flags |=
  6259. (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
  6260. I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
  6261. }
  6262. /* Setup the VSI tx/rx queue map for TC0 only for now */
  6263. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  6264. break;
  6265. default:
  6266. return -ENODEV;
  6267. }
  6268. if (vsi->type != I40E_VSI_MAIN) {
  6269. ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
  6270. if (ret) {
  6271. dev_info(&vsi->back->pdev->dev,
  6272. "add vsi failed, aq_err=%d\n",
  6273. vsi->back->hw.aq.asq_last_status);
  6274. ret = -ENOENT;
  6275. goto err;
  6276. }
  6277. memcpy(&vsi->info, &ctxt.info, sizeof(ctxt.info));
  6278. vsi->info.valid_sections = 0;
  6279. vsi->seid = ctxt.seid;
  6280. vsi->id = ctxt.vsi_number;
  6281. }
  6282. /* If macvlan filters already exist, force them to get loaded */
  6283. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list) {
  6284. f->changed = true;
  6285. f_count++;
  6286. }
  6287. if (f_count) {
  6288. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  6289. pf->flags |= I40E_FLAG_FILTER_SYNC;
  6290. }
  6291. /* Update VSI BW information */
  6292. ret = i40e_vsi_get_bw_info(vsi);
  6293. if (ret) {
  6294. dev_info(&pf->pdev->dev,
  6295. "couldn't get vsi bw info, err %d, aq_err %d\n",
  6296. ret, pf->hw.aq.asq_last_status);
  6297. /* VSI is already added so not tearing that up */
  6298. ret = 0;
  6299. }
  6300. err:
  6301. return ret;
  6302. }
  6303. /**
  6304. * i40e_vsi_release - Delete a VSI and free its resources
  6305. * @vsi: the VSI being removed
  6306. *
  6307. * Returns 0 on success or < 0 on error
  6308. **/
  6309. int i40e_vsi_release(struct i40e_vsi *vsi)
  6310. {
  6311. struct i40e_mac_filter *f, *ftmp;
  6312. struct i40e_veb *veb = NULL;
  6313. struct i40e_pf *pf;
  6314. u16 uplink_seid;
  6315. int i, n;
  6316. pf = vsi->back;
  6317. /* release of a VEB-owner or last VSI is not allowed */
  6318. if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
  6319. dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
  6320. vsi->seid, vsi->uplink_seid);
  6321. return -ENODEV;
  6322. }
  6323. if (vsi == pf->vsi[pf->lan_vsi] &&
  6324. !test_bit(__I40E_DOWN, &pf->state)) {
  6325. dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
  6326. return -ENODEV;
  6327. }
  6328. uplink_seid = vsi->uplink_seid;
  6329. if (vsi->type != I40E_VSI_SRIOV) {
  6330. if (vsi->netdev_registered) {
  6331. vsi->netdev_registered = false;
  6332. if (vsi->netdev) {
  6333. /* results in a call to i40e_close() */
  6334. unregister_netdev(vsi->netdev);
  6335. }
  6336. } else {
  6337. i40e_vsi_close(vsi);
  6338. }
  6339. i40e_vsi_disable_irq(vsi);
  6340. }
  6341. list_for_each_entry_safe(f, ftmp, &vsi->mac_filter_list, list)
  6342. i40e_del_filter(vsi, f->macaddr, f->vlan,
  6343. f->is_vf, f->is_netdev);
  6344. i40e_sync_vsi_filters(vsi);
  6345. i40e_vsi_delete(vsi);
  6346. i40e_vsi_free_q_vectors(vsi);
  6347. if (vsi->netdev) {
  6348. free_netdev(vsi->netdev);
  6349. vsi->netdev = NULL;
  6350. }
  6351. i40e_vsi_clear_rings(vsi);
  6352. i40e_vsi_clear(vsi);
  6353. /* If this was the last thing on the VEB, except for the
  6354. * controlling VSI, remove the VEB, which puts the controlling
  6355. * VSI onto the next level down in the switch.
  6356. *
  6357. * Well, okay, there's one more exception here: don't remove
  6358. * the orphan VEBs yet. We'll wait for an explicit remove request
  6359. * from up the network stack.
  6360. */
  6361. for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) {
  6362. if (pf->vsi[i] &&
  6363. pf->vsi[i]->uplink_seid == uplink_seid &&
  6364. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  6365. n++; /* count the VSIs */
  6366. }
  6367. }
  6368. for (i = 0; i < I40E_MAX_VEB; i++) {
  6369. if (!pf->veb[i])
  6370. continue;
  6371. if (pf->veb[i]->uplink_seid == uplink_seid)
  6372. n++; /* count the VEBs */
  6373. if (pf->veb[i]->seid == uplink_seid)
  6374. veb = pf->veb[i];
  6375. }
  6376. if (n == 0 && veb && veb->uplink_seid != 0)
  6377. i40e_veb_release(veb);
  6378. return 0;
  6379. }
  6380. /**
  6381. * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
  6382. * @vsi: ptr to the VSI
  6383. *
  6384. * This should only be called after i40e_vsi_mem_alloc() which allocates the
  6385. * corresponding SW VSI structure and initializes num_queue_pairs for the
  6386. * newly allocated VSI.
  6387. *
  6388. * Returns 0 on success or negative on failure
  6389. **/
  6390. static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
  6391. {
  6392. int ret = -ENOENT;
  6393. struct i40e_pf *pf = vsi->back;
  6394. if (vsi->q_vectors[0]) {
  6395. dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
  6396. vsi->seid);
  6397. return -EEXIST;
  6398. }
  6399. if (vsi->base_vector) {
  6400. dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
  6401. vsi->seid, vsi->base_vector);
  6402. return -EEXIST;
  6403. }
  6404. ret = i40e_vsi_alloc_q_vectors(vsi);
  6405. if (ret) {
  6406. dev_info(&pf->pdev->dev,
  6407. "failed to allocate %d q_vector for VSI %d, ret=%d\n",
  6408. vsi->num_q_vectors, vsi->seid, ret);
  6409. vsi->num_q_vectors = 0;
  6410. goto vector_setup_out;
  6411. }
  6412. if (vsi->num_q_vectors)
  6413. vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
  6414. vsi->num_q_vectors, vsi->idx);
  6415. if (vsi->base_vector < 0) {
  6416. dev_info(&pf->pdev->dev,
  6417. "failed to get queue tracking for VSI %d, err=%d\n",
  6418. vsi->seid, vsi->base_vector);
  6419. i40e_vsi_free_q_vectors(vsi);
  6420. ret = -ENOENT;
  6421. goto vector_setup_out;
  6422. }
  6423. vector_setup_out:
  6424. return ret;
  6425. }
  6426. /**
  6427. * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
  6428. * @vsi: pointer to the vsi.
  6429. *
  6430. * This re-allocates a vsi's queue resources.
  6431. *
  6432. * Returns pointer to the successfully allocated and configured VSI sw struct
  6433. * on success, otherwise returns NULL on failure.
  6434. **/
  6435. static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
  6436. {
  6437. struct i40e_pf *pf = vsi->back;
  6438. u8 enabled_tc;
  6439. int ret;
  6440. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  6441. i40e_vsi_clear_rings(vsi);
  6442. i40e_vsi_free_arrays(vsi, false);
  6443. i40e_set_num_rings_in_vsi(vsi);
  6444. ret = i40e_vsi_alloc_arrays(vsi, false);
  6445. if (ret)
  6446. goto err_vsi;
  6447. ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx);
  6448. if (ret < 0) {
  6449. dev_info(&pf->pdev->dev, "VSI %d get_lump failed %d\n",
  6450. vsi->seid, ret);
  6451. goto err_vsi;
  6452. }
  6453. vsi->base_queue = ret;
  6454. /* Update the FW view of the VSI. Force a reset of TC and queue
  6455. * layout configurations.
  6456. */
  6457. enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  6458. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  6459. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  6460. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  6461. /* assign it some queues */
  6462. ret = i40e_alloc_rings(vsi);
  6463. if (ret)
  6464. goto err_rings;
  6465. /* map all of the rings to the q_vectors */
  6466. i40e_vsi_map_rings_to_vectors(vsi);
  6467. return vsi;
  6468. err_rings:
  6469. i40e_vsi_free_q_vectors(vsi);
  6470. if (vsi->netdev_registered) {
  6471. vsi->netdev_registered = false;
  6472. unregister_netdev(vsi->netdev);
  6473. free_netdev(vsi->netdev);
  6474. vsi->netdev = NULL;
  6475. }
  6476. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  6477. err_vsi:
  6478. i40e_vsi_clear(vsi);
  6479. return NULL;
  6480. }
  6481. /**
  6482. * i40e_vsi_setup - Set up a VSI by a given type
  6483. * @pf: board private structure
  6484. * @type: VSI type
  6485. * @uplink_seid: the switch element to link to
  6486. * @param1: usage depends upon VSI type. For VF types, indicates VF id
  6487. *
  6488. * This allocates the sw VSI structure and its queue resources, then add a VSI
  6489. * to the identified VEB.
  6490. *
  6491. * Returns pointer to the successfully allocated and configure VSI sw struct on
  6492. * success, otherwise returns NULL on failure.
  6493. **/
  6494. struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
  6495. u16 uplink_seid, u32 param1)
  6496. {
  6497. struct i40e_vsi *vsi = NULL;
  6498. struct i40e_veb *veb = NULL;
  6499. int ret, i;
  6500. int v_idx;
  6501. /* The requested uplink_seid must be either
  6502. * - the PF's port seid
  6503. * no VEB is needed because this is the PF
  6504. * or this is a Flow Director special case VSI
  6505. * - seid of an existing VEB
  6506. * - seid of a VSI that owns an existing VEB
  6507. * - seid of a VSI that doesn't own a VEB
  6508. * a new VEB is created and the VSI becomes the owner
  6509. * - seid of the PF VSI, which is what creates the first VEB
  6510. * this is a special case of the previous
  6511. *
  6512. * Find which uplink_seid we were given and create a new VEB if needed
  6513. */
  6514. for (i = 0; i < I40E_MAX_VEB; i++) {
  6515. if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
  6516. veb = pf->veb[i];
  6517. break;
  6518. }
  6519. }
  6520. if (!veb && uplink_seid != pf->mac_seid) {
  6521. for (i = 0; i < pf->num_alloc_vsi; i++) {
  6522. if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
  6523. vsi = pf->vsi[i];
  6524. break;
  6525. }
  6526. }
  6527. if (!vsi) {
  6528. dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
  6529. uplink_seid);
  6530. return NULL;
  6531. }
  6532. if (vsi->uplink_seid == pf->mac_seid)
  6533. veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
  6534. vsi->tc_config.enabled_tc);
  6535. else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
  6536. veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
  6537. vsi->tc_config.enabled_tc);
  6538. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  6539. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  6540. veb = pf->veb[i];
  6541. }
  6542. if (!veb) {
  6543. dev_info(&pf->pdev->dev, "couldn't add VEB\n");
  6544. return NULL;
  6545. }
  6546. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  6547. uplink_seid = veb->seid;
  6548. }
  6549. /* get vsi sw struct */
  6550. v_idx = i40e_vsi_mem_alloc(pf, type);
  6551. if (v_idx < 0)
  6552. goto err_alloc;
  6553. vsi = pf->vsi[v_idx];
  6554. if (!vsi)
  6555. goto err_alloc;
  6556. vsi->type = type;
  6557. vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
  6558. if (type == I40E_VSI_MAIN)
  6559. pf->lan_vsi = v_idx;
  6560. else if (type == I40E_VSI_SRIOV)
  6561. vsi->vf_id = param1;
  6562. /* assign it some queues */
  6563. ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs,
  6564. vsi->idx);
  6565. if (ret < 0) {
  6566. dev_info(&pf->pdev->dev, "VSI %d get_lump failed %d\n",
  6567. vsi->seid, ret);
  6568. goto err_vsi;
  6569. }
  6570. vsi->base_queue = ret;
  6571. /* get a VSI from the hardware */
  6572. vsi->uplink_seid = uplink_seid;
  6573. ret = i40e_add_vsi(vsi);
  6574. if (ret)
  6575. goto err_vsi;
  6576. switch (vsi->type) {
  6577. /* setup the netdev if needed */
  6578. case I40E_VSI_MAIN:
  6579. case I40E_VSI_VMDQ2:
  6580. ret = i40e_config_netdev(vsi);
  6581. if (ret)
  6582. goto err_netdev;
  6583. ret = register_netdev(vsi->netdev);
  6584. if (ret)
  6585. goto err_netdev;
  6586. vsi->netdev_registered = true;
  6587. netif_carrier_off(vsi->netdev);
  6588. #ifdef CONFIG_I40E_DCB
  6589. /* Setup DCB netlink interface */
  6590. i40e_dcbnl_setup(vsi);
  6591. #endif /* CONFIG_I40E_DCB */
  6592. /* fall through */
  6593. case I40E_VSI_FDIR:
  6594. /* set up vectors and rings if needed */
  6595. ret = i40e_vsi_setup_vectors(vsi);
  6596. if (ret)
  6597. goto err_msix;
  6598. ret = i40e_alloc_rings(vsi);
  6599. if (ret)
  6600. goto err_rings;
  6601. /* map all of the rings to the q_vectors */
  6602. i40e_vsi_map_rings_to_vectors(vsi);
  6603. i40e_vsi_reset_stats(vsi);
  6604. break;
  6605. default:
  6606. /* no netdev or rings for the other VSI types */
  6607. break;
  6608. }
  6609. return vsi;
  6610. err_rings:
  6611. i40e_vsi_free_q_vectors(vsi);
  6612. err_msix:
  6613. if (vsi->netdev_registered) {
  6614. vsi->netdev_registered = false;
  6615. unregister_netdev(vsi->netdev);
  6616. free_netdev(vsi->netdev);
  6617. vsi->netdev = NULL;
  6618. }
  6619. err_netdev:
  6620. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  6621. err_vsi:
  6622. i40e_vsi_clear(vsi);
  6623. err_alloc:
  6624. return NULL;
  6625. }
  6626. /**
  6627. * i40e_veb_get_bw_info - Query VEB BW information
  6628. * @veb: the veb to query
  6629. *
  6630. * Query the Tx scheduler BW configuration data for given VEB
  6631. **/
  6632. static int i40e_veb_get_bw_info(struct i40e_veb *veb)
  6633. {
  6634. struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
  6635. struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
  6636. struct i40e_pf *pf = veb->pf;
  6637. struct i40e_hw *hw = &pf->hw;
  6638. u32 tc_bw_max;
  6639. int ret = 0;
  6640. int i;
  6641. ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
  6642. &bw_data, NULL);
  6643. if (ret) {
  6644. dev_info(&pf->pdev->dev,
  6645. "query veb bw config failed, aq_err=%d\n",
  6646. hw->aq.asq_last_status);
  6647. goto out;
  6648. }
  6649. ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
  6650. &ets_data, NULL);
  6651. if (ret) {
  6652. dev_info(&pf->pdev->dev,
  6653. "query veb bw ets config failed, aq_err=%d\n",
  6654. hw->aq.asq_last_status);
  6655. goto out;
  6656. }
  6657. veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
  6658. veb->bw_max_quanta = ets_data.tc_bw_max;
  6659. veb->is_abs_credits = bw_data.absolute_credits_enable;
  6660. tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
  6661. (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
  6662. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  6663. veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
  6664. veb->bw_tc_limit_credits[i] =
  6665. le16_to_cpu(bw_data.tc_bw_limits[i]);
  6666. veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
  6667. }
  6668. out:
  6669. return ret;
  6670. }
  6671. /**
  6672. * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
  6673. * @pf: board private structure
  6674. *
  6675. * On error: returns error code (negative)
  6676. * On success: returns vsi index in PF (positive)
  6677. **/
  6678. static int i40e_veb_mem_alloc(struct i40e_pf *pf)
  6679. {
  6680. int ret = -ENOENT;
  6681. struct i40e_veb *veb;
  6682. int i;
  6683. /* Need to protect the allocation of switch elements at the PF level */
  6684. mutex_lock(&pf->switch_mutex);
  6685. /* VEB list may be fragmented if VEB creation/destruction has
  6686. * been happening. We can afford to do a quick scan to look
  6687. * for any free slots in the list.
  6688. *
  6689. * find next empty veb slot, looping back around if necessary
  6690. */
  6691. i = 0;
  6692. while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
  6693. i++;
  6694. if (i >= I40E_MAX_VEB) {
  6695. ret = -ENOMEM;
  6696. goto err_alloc_veb; /* out of VEB slots! */
  6697. }
  6698. veb = kzalloc(sizeof(*veb), GFP_KERNEL);
  6699. if (!veb) {
  6700. ret = -ENOMEM;
  6701. goto err_alloc_veb;
  6702. }
  6703. veb->pf = pf;
  6704. veb->idx = i;
  6705. veb->enabled_tc = 1;
  6706. pf->veb[i] = veb;
  6707. ret = i;
  6708. err_alloc_veb:
  6709. mutex_unlock(&pf->switch_mutex);
  6710. return ret;
  6711. }
  6712. /**
  6713. * i40e_switch_branch_release - Delete a branch of the switch tree
  6714. * @branch: where to start deleting
  6715. *
  6716. * This uses recursion to find the tips of the branch to be
  6717. * removed, deleting until we get back to and can delete this VEB.
  6718. **/
  6719. static void i40e_switch_branch_release(struct i40e_veb *branch)
  6720. {
  6721. struct i40e_pf *pf = branch->pf;
  6722. u16 branch_seid = branch->seid;
  6723. u16 veb_idx = branch->idx;
  6724. int i;
  6725. /* release any VEBs on this VEB - RECURSION */
  6726. for (i = 0; i < I40E_MAX_VEB; i++) {
  6727. if (!pf->veb[i])
  6728. continue;
  6729. if (pf->veb[i]->uplink_seid == branch->seid)
  6730. i40e_switch_branch_release(pf->veb[i]);
  6731. }
  6732. /* Release the VSIs on this VEB, but not the owner VSI.
  6733. *
  6734. * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
  6735. * the VEB itself, so don't use (*branch) after this loop.
  6736. */
  6737. for (i = 0; i < pf->num_alloc_vsi; i++) {
  6738. if (!pf->vsi[i])
  6739. continue;
  6740. if (pf->vsi[i]->uplink_seid == branch_seid &&
  6741. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  6742. i40e_vsi_release(pf->vsi[i]);
  6743. }
  6744. }
  6745. /* There's one corner case where the VEB might not have been
  6746. * removed, so double check it here and remove it if needed.
  6747. * This case happens if the veb was created from the debugfs
  6748. * commands and no VSIs were added to it.
  6749. */
  6750. if (pf->veb[veb_idx])
  6751. i40e_veb_release(pf->veb[veb_idx]);
  6752. }
  6753. /**
  6754. * i40e_veb_clear - remove veb struct
  6755. * @veb: the veb to remove
  6756. **/
  6757. static void i40e_veb_clear(struct i40e_veb *veb)
  6758. {
  6759. if (!veb)
  6760. return;
  6761. if (veb->pf) {
  6762. struct i40e_pf *pf = veb->pf;
  6763. mutex_lock(&pf->switch_mutex);
  6764. if (pf->veb[veb->idx] == veb)
  6765. pf->veb[veb->idx] = NULL;
  6766. mutex_unlock(&pf->switch_mutex);
  6767. }
  6768. kfree(veb);
  6769. }
  6770. /**
  6771. * i40e_veb_release - Delete a VEB and free its resources
  6772. * @veb: the VEB being removed
  6773. **/
  6774. void i40e_veb_release(struct i40e_veb *veb)
  6775. {
  6776. struct i40e_vsi *vsi = NULL;
  6777. struct i40e_pf *pf;
  6778. int i, n = 0;
  6779. pf = veb->pf;
  6780. /* find the remaining VSI and check for extras */
  6781. for (i = 0; i < pf->num_alloc_vsi; i++) {
  6782. if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
  6783. n++;
  6784. vsi = pf->vsi[i];
  6785. }
  6786. }
  6787. if (n != 1) {
  6788. dev_info(&pf->pdev->dev,
  6789. "can't remove VEB %d with %d VSIs left\n",
  6790. veb->seid, n);
  6791. return;
  6792. }
  6793. /* move the remaining VSI to uplink veb */
  6794. vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
  6795. if (veb->uplink_seid) {
  6796. vsi->uplink_seid = veb->uplink_seid;
  6797. if (veb->uplink_seid == pf->mac_seid)
  6798. vsi->veb_idx = I40E_NO_VEB;
  6799. else
  6800. vsi->veb_idx = veb->veb_idx;
  6801. } else {
  6802. /* floating VEB */
  6803. vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  6804. vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
  6805. }
  6806. i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
  6807. i40e_veb_clear(veb);
  6808. }
  6809. /**
  6810. * i40e_add_veb - create the VEB in the switch
  6811. * @veb: the VEB to be instantiated
  6812. * @vsi: the controlling VSI
  6813. **/
  6814. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
  6815. {
  6816. bool is_default = false;
  6817. bool is_cloud = false;
  6818. int ret;
  6819. /* get a VEB from the hardware */
  6820. ret = i40e_aq_add_veb(&veb->pf->hw, veb->uplink_seid, vsi->seid,
  6821. veb->enabled_tc, is_default,
  6822. is_cloud, &veb->seid, NULL);
  6823. if (ret) {
  6824. dev_info(&veb->pf->pdev->dev,
  6825. "couldn't add VEB, err %d, aq_err %d\n",
  6826. ret, veb->pf->hw.aq.asq_last_status);
  6827. return -EPERM;
  6828. }
  6829. /* get statistics counter */
  6830. ret = i40e_aq_get_veb_parameters(&veb->pf->hw, veb->seid, NULL, NULL,
  6831. &veb->stats_idx, NULL, NULL, NULL);
  6832. if (ret) {
  6833. dev_info(&veb->pf->pdev->dev,
  6834. "couldn't get VEB statistics idx, err %d, aq_err %d\n",
  6835. ret, veb->pf->hw.aq.asq_last_status);
  6836. return -EPERM;
  6837. }
  6838. ret = i40e_veb_get_bw_info(veb);
  6839. if (ret) {
  6840. dev_info(&veb->pf->pdev->dev,
  6841. "couldn't get VEB bw info, err %d, aq_err %d\n",
  6842. ret, veb->pf->hw.aq.asq_last_status);
  6843. i40e_aq_delete_element(&veb->pf->hw, veb->seid, NULL);
  6844. return -ENOENT;
  6845. }
  6846. vsi->uplink_seid = veb->seid;
  6847. vsi->veb_idx = veb->idx;
  6848. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  6849. return 0;
  6850. }
  6851. /**
  6852. * i40e_veb_setup - Set up a VEB
  6853. * @pf: board private structure
  6854. * @flags: VEB setup flags
  6855. * @uplink_seid: the switch element to link to
  6856. * @vsi_seid: the initial VSI seid
  6857. * @enabled_tc: Enabled TC bit-map
  6858. *
  6859. * This allocates the sw VEB structure and links it into the switch
  6860. * It is possible and legal for this to be a duplicate of an already
  6861. * existing VEB. It is also possible for both uplink and vsi seids
  6862. * to be zero, in order to create a floating VEB.
  6863. *
  6864. * Returns pointer to the successfully allocated VEB sw struct on
  6865. * success, otherwise returns NULL on failure.
  6866. **/
  6867. struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
  6868. u16 uplink_seid, u16 vsi_seid,
  6869. u8 enabled_tc)
  6870. {
  6871. struct i40e_veb *veb, *uplink_veb = NULL;
  6872. int vsi_idx, veb_idx;
  6873. int ret;
  6874. /* if one seid is 0, the other must be 0 to create a floating relay */
  6875. if ((uplink_seid == 0 || vsi_seid == 0) &&
  6876. (uplink_seid + vsi_seid != 0)) {
  6877. dev_info(&pf->pdev->dev,
  6878. "one, not both seid's are 0: uplink=%d vsi=%d\n",
  6879. uplink_seid, vsi_seid);
  6880. return NULL;
  6881. }
  6882. /* make sure there is such a vsi and uplink */
  6883. for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++)
  6884. if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
  6885. break;
  6886. if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) {
  6887. dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
  6888. vsi_seid);
  6889. return NULL;
  6890. }
  6891. if (uplink_seid && uplink_seid != pf->mac_seid) {
  6892. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  6893. if (pf->veb[veb_idx] &&
  6894. pf->veb[veb_idx]->seid == uplink_seid) {
  6895. uplink_veb = pf->veb[veb_idx];
  6896. break;
  6897. }
  6898. }
  6899. if (!uplink_veb) {
  6900. dev_info(&pf->pdev->dev,
  6901. "uplink seid %d not found\n", uplink_seid);
  6902. return NULL;
  6903. }
  6904. }
  6905. /* get veb sw struct */
  6906. veb_idx = i40e_veb_mem_alloc(pf);
  6907. if (veb_idx < 0)
  6908. goto err_alloc;
  6909. veb = pf->veb[veb_idx];
  6910. veb->flags = flags;
  6911. veb->uplink_seid = uplink_seid;
  6912. veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
  6913. veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
  6914. /* create the VEB in the switch */
  6915. ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
  6916. if (ret)
  6917. goto err_veb;
  6918. if (vsi_idx == pf->lan_vsi)
  6919. pf->lan_veb = veb->idx;
  6920. return veb;
  6921. err_veb:
  6922. i40e_veb_clear(veb);
  6923. err_alloc:
  6924. return NULL;
  6925. }
  6926. /**
  6927. * i40e_setup_pf_switch_element - set pf vars based on switch type
  6928. * @pf: board private structure
  6929. * @ele: element we are building info from
  6930. * @num_reported: total number of elements
  6931. * @printconfig: should we print the contents
  6932. *
  6933. * helper function to assist in extracting a few useful SEID values.
  6934. **/
  6935. static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
  6936. struct i40e_aqc_switch_config_element_resp *ele,
  6937. u16 num_reported, bool printconfig)
  6938. {
  6939. u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
  6940. u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
  6941. u8 element_type = ele->element_type;
  6942. u16 seid = le16_to_cpu(ele->seid);
  6943. if (printconfig)
  6944. dev_info(&pf->pdev->dev,
  6945. "type=%d seid=%d uplink=%d downlink=%d\n",
  6946. element_type, seid, uplink_seid, downlink_seid);
  6947. switch (element_type) {
  6948. case I40E_SWITCH_ELEMENT_TYPE_MAC:
  6949. pf->mac_seid = seid;
  6950. break;
  6951. case I40E_SWITCH_ELEMENT_TYPE_VEB:
  6952. /* Main VEB? */
  6953. if (uplink_seid != pf->mac_seid)
  6954. break;
  6955. if (pf->lan_veb == I40E_NO_VEB) {
  6956. int v;
  6957. /* find existing or else empty VEB */
  6958. for (v = 0; v < I40E_MAX_VEB; v++) {
  6959. if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
  6960. pf->lan_veb = v;
  6961. break;
  6962. }
  6963. }
  6964. if (pf->lan_veb == I40E_NO_VEB) {
  6965. v = i40e_veb_mem_alloc(pf);
  6966. if (v < 0)
  6967. break;
  6968. pf->lan_veb = v;
  6969. }
  6970. }
  6971. pf->veb[pf->lan_veb]->seid = seid;
  6972. pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
  6973. pf->veb[pf->lan_veb]->pf = pf;
  6974. pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
  6975. break;
  6976. case I40E_SWITCH_ELEMENT_TYPE_VSI:
  6977. if (num_reported != 1)
  6978. break;
  6979. /* This is immediately after a reset so we can assume this is
  6980. * the PF's VSI
  6981. */
  6982. pf->mac_seid = uplink_seid;
  6983. pf->pf_seid = downlink_seid;
  6984. pf->main_vsi_seid = seid;
  6985. if (printconfig)
  6986. dev_info(&pf->pdev->dev,
  6987. "pf_seid=%d main_vsi_seid=%d\n",
  6988. pf->pf_seid, pf->main_vsi_seid);
  6989. break;
  6990. case I40E_SWITCH_ELEMENT_TYPE_PF:
  6991. case I40E_SWITCH_ELEMENT_TYPE_VF:
  6992. case I40E_SWITCH_ELEMENT_TYPE_EMP:
  6993. case I40E_SWITCH_ELEMENT_TYPE_BMC:
  6994. case I40E_SWITCH_ELEMENT_TYPE_PE:
  6995. case I40E_SWITCH_ELEMENT_TYPE_PA:
  6996. /* ignore these for now */
  6997. break;
  6998. default:
  6999. dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
  7000. element_type, seid);
  7001. break;
  7002. }
  7003. }
  7004. /**
  7005. * i40e_fetch_switch_configuration - Get switch config from firmware
  7006. * @pf: board private structure
  7007. * @printconfig: should we print the contents
  7008. *
  7009. * Get the current switch configuration from the device and
  7010. * extract a few useful SEID values.
  7011. **/
  7012. int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
  7013. {
  7014. struct i40e_aqc_get_switch_config_resp *sw_config;
  7015. u16 next_seid = 0;
  7016. int ret = 0;
  7017. u8 *aq_buf;
  7018. int i;
  7019. aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
  7020. if (!aq_buf)
  7021. return -ENOMEM;
  7022. sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
  7023. do {
  7024. u16 num_reported, num_total;
  7025. ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
  7026. I40E_AQ_LARGE_BUF,
  7027. &next_seid, NULL);
  7028. if (ret) {
  7029. dev_info(&pf->pdev->dev,
  7030. "get switch config failed %d aq_err=%x\n",
  7031. ret, pf->hw.aq.asq_last_status);
  7032. kfree(aq_buf);
  7033. return -ENOENT;
  7034. }
  7035. num_reported = le16_to_cpu(sw_config->header.num_reported);
  7036. num_total = le16_to_cpu(sw_config->header.num_total);
  7037. if (printconfig)
  7038. dev_info(&pf->pdev->dev,
  7039. "header: %d reported %d total\n",
  7040. num_reported, num_total);
  7041. for (i = 0; i < num_reported; i++) {
  7042. struct i40e_aqc_switch_config_element_resp *ele =
  7043. &sw_config->element[i];
  7044. i40e_setup_pf_switch_element(pf, ele, num_reported,
  7045. printconfig);
  7046. }
  7047. } while (next_seid != 0);
  7048. kfree(aq_buf);
  7049. return ret;
  7050. }
  7051. /**
  7052. * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
  7053. * @pf: board private structure
  7054. * @reinit: if the Main VSI needs to re-initialized.
  7055. *
  7056. * Returns 0 on success, negative value on failure
  7057. **/
  7058. static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
  7059. {
  7060. u32 rxfc = 0, txfc = 0, rxfc_reg;
  7061. int ret;
  7062. /* find out what's out there already */
  7063. ret = i40e_fetch_switch_configuration(pf, false);
  7064. if (ret) {
  7065. dev_info(&pf->pdev->dev,
  7066. "couldn't fetch switch config, err %d, aq_err %d\n",
  7067. ret, pf->hw.aq.asq_last_status);
  7068. return ret;
  7069. }
  7070. i40e_pf_reset_stats(pf);
  7071. /* first time setup */
  7072. if (pf->lan_vsi == I40E_NO_VSI || reinit) {
  7073. struct i40e_vsi *vsi = NULL;
  7074. u16 uplink_seid;
  7075. /* Set up the PF VSI associated with the PF's main VSI
  7076. * that is already in the HW switch
  7077. */
  7078. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  7079. uplink_seid = pf->veb[pf->lan_veb]->seid;
  7080. else
  7081. uplink_seid = pf->mac_seid;
  7082. if (pf->lan_vsi == I40E_NO_VSI)
  7083. vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
  7084. else if (reinit)
  7085. vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
  7086. if (!vsi) {
  7087. dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
  7088. i40e_fdir_teardown(pf);
  7089. return -EAGAIN;
  7090. }
  7091. } else {
  7092. /* force a reset of TC and queue layout configurations */
  7093. u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  7094. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  7095. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  7096. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  7097. }
  7098. i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
  7099. i40e_fdir_sb_setup(pf);
  7100. /* Setup static PF queue filter control settings */
  7101. ret = i40e_setup_pf_filter_control(pf);
  7102. if (ret) {
  7103. dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
  7104. ret);
  7105. /* Failure here should not stop continuing other steps */
  7106. }
  7107. /* enable RSS in the HW, even for only one queue, as the stack can use
  7108. * the hash
  7109. */
  7110. if ((pf->flags & I40E_FLAG_RSS_ENABLED))
  7111. i40e_config_rss(pf);
  7112. /* fill in link information and enable LSE reporting */
  7113. i40e_aq_get_link_info(&pf->hw, true, NULL, NULL);
  7114. i40e_link_event(pf);
  7115. /* Initialize user-specific link properties */
  7116. pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
  7117. I40E_AQ_AN_COMPLETED) ? true : false);
  7118. /* requested_mode is set in probe or by ethtool */
  7119. if (!pf->fc_autoneg_status)
  7120. goto no_autoneg;
  7121. if ((pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_TX) &&
  7122. (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_RX))
  7123. pf->hw.fc.current_mode = I40E_FC_FULL;
  7124. else if (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_TX)
  7125. pf->hw.fc.current_mode = I40E_FC_TX_PAUSE;
  7126. else if (pf->hw.phy.link_info.an_info & I40E_AQ_LINK_PAUSE_RX)
  7127. pf->hw.fc.current_mode = I40E_FC_RX_PAUSE;
  7128. else
  7129. pf->hw.fc.current_mode = I40E_FC_NONE;
  7130. /* sync the flow control settings with the auto-neg values */
  7131. switch (pf->hw.fc.current_mode) {
  7132. case I40E_FC_FULL:
  7133. txfc = 1;
  7134. rxfc = 1;
  7135. break;
  7136. case I40E_FC_TX_PAUSE:
  7137. txfc = 1;
  7138. rxfc = 0;
  7139. break;
  7140. case I40E_FC_RX_PAUSE:
  7141. txfc = 0;
  7142. rxfc = 1;
  7143. break;
  7144. case I40E_FC_NONE:
  7145. case I40E_FC_DEFAULT:
  7146. txfc = 0;
  7147. rxfc = 0;
  7148. break;
  7149. case I40E_FC_PFC:
  7150. /* TBD */
  7151. break;
  7152. /* no default case, we have to handle all possibilities here */
  7153. }
  7154. wr32(&pf->hw, I40E_PRTDCB_FCCFG, txfc << I40E_PRTDCB_FCCFG_TFCE_SHIFT);
  7155. rxfc_reg = rd32(&pf->hw, I40E_PRTDCB_MFLCN) &
  7156. ~I40E_PRTDCB_MFLCN_RFCE_MASK;
  7157. rxfc_reg |= (rxfc << I40E_PRTDCB_MFLCN_RFCE_SHIFT);
  7158. wr32(&pf->hw, I40E_PRTDCB_MFLCN, rxfc_reg);
  7159. goto fc_complete;
  7160. no_autoneg:
  7161. /* disable L2 flow control, user can turn it on if they wish */
  7162. wr32(&pf->hw, I40E_PRTDCB_FCCFG, 0);
  7163. wr32(&pf->hw, I40E_PRTDCB_MFLCN, rd32(&pf->hw, I40E_PRTDCB_MFLCN) &
  7164. ~I40E_PRTDCB_MFLCN_RFCE_MASK);
  7165. fc_complete:
  7166. i40e_ptp_init(pf);
  7167. return ret;
  7168. }
  7169. /**
  7170. * i40e_determine_queue_usage - Work out queue distribution
  7171. * @pf: board private structure
  7172. **/
  7173. static void i40e_determine_queue_usage(struct i40e_pf *pf)
  7174. {
  7175. int queues_left;
  7176. pf->num_lan_qps = 0;
  7177. /* Find the max queues to be put into basic use. We'll always be
  7178. * using TC0, whether or not DCB is running, and TC0 will get the
  7179. * big RSS set.
  7180. */
  7181. queues_left = pf->hw.func_caps.num_tx_qp;
  7182. if ((queues_left == 1) ||
  7183. !(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
  7184. /* one qp for PF, no queues for anything else */
  7185. queues_left = 0;
  7186. pf->rss_size = pf->num_lan_qps = 1;
  7187. /* make sure all the fancies are disabled */
  7188. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  7189. I40E_FLAG_FD_SB_ENABLED |
  7190. I40E_FLAG_FD_ATR_ENABLED |
  7191. I40E_FLAG_DCB_CAPABLE |
  7192. I40E_FLAG_SRIOV_ENABLED |
  7193. I40E_FLAG_VMDQ_ENABLED);
  7194. } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED |
  7195. I40E_FLAG_FD_SB_ENABLED |
  7196. I40E_FLAG_FD_ATR_ENABLED |
  7197. I40E_FLAG_DCB_CAPABLE))) {
  7198. /* one qp for PF */
  7199. pf->rss_size = pf->num_lan_qps = 1;
  7200. queues_left -= pf->num_lan_qps;
  7201. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  7202. I40E_FLAG_FD_SB_ENABLED |
  7203. I40E_FLAG_FD_ATR_ENABLED |
  7204. I40E_FLAG_DCB_ENABLED |
  7205. I40E_FLAG_VMDQ_ENABLED);
  7206. } else {
  7207. /* Not enough queues for all TCs */
  7208. if ((pf->flags & I40E_FLAG_DCB_CAPABLE) &&
  7209. (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
  7210. pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
  7211. dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
  7212. }
  7213. pf->num_lan_qps = pf->rss_size_max;
  7214. queues_left -= pf->num_lan_qps;
  7215. }
  7216. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  7217. if (queues_left > 1) {
  7218. queues_left -= 1; /* save 1 queue for FD */
  7219. } else {
  7220. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  7221. dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
  7222. }
  7223. }
  7224. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  7225. pf->num_vf_qps && pf->num_req_vfs && queues_left) {
  7226. pf->num_req_vfs = min_t(int, pf->num_req_vfs,
  7227. (queues_left / pf->num_vf_qps));
  7228. queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
  7229. }
  7230. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  7231. pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
  7232. pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
  7233. (queues_left / pf->num_vmdq_qps));
  7234. queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
  7235. }
  7236. pf->queues_left = queues_left;
  7237. }
  7238. /**
  7239. * i40e_setup_pf_filter_control - Setup PF static filter control
  7240. * @pf: PF to be setup
  7241. *
  7242. * i40e_setup_pf_filter_control sets up a pf's initial filter control
  7243. * settings. If PE/FCoE are enabled then it will also set the per PF
  7244. * based filter sizes required for them. It also enables Flow director,
  7245. * ethertype and macvlan type filter settings for the pf.
  7246. *
  7247. * Returns 0 on success, negative on failure
  7248. **/
  7249. static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
  7250. {
  7251. struct i40e_filter_control_settings *settings = &pf->filter_settings;
  7252. settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
  7253. /* Flow Director is enabled */
  7254. if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
  7255. settings->enable_fdir = true;
  7256. /* Ethtype and MACVLAN filters enabled for PF */
  7257. settings->enable_ethtype = true;
  7258. settings->enable_macvlan = true;
  7259. if (i40e_set_filter_control(&pf->hw, settings))
  7260. return -ENOENT;
  7261. return 0;
  7262. }
  7263. #define INFO_STRING_LEN 255
  7264. static void i40e_print_features(struct i40e_pf *pf)
  7265. {
  7266. struct i40e_hw *hw = &pf->hw;
  7267. char *buf, *string;
  7268. string = kzalloc(INFO_STRING_LEN, GFP_KERNEL);
  7269. if (!string) {
  7270. dev_err(&pf->pdev->dev, "Features string allocation failed\n");
  7271. return;
  7272. }
  7273. buf = string;
  7274. buf += sprintf(string, "Features: PF-id[%d] ", hw->pf_id);
  7275. #ifdef CONFIG_PCI_IOV
  7276. buf += sprintf(buf, "VFs: %d ", pf->num_req_vfs);
  7277. #endif
  7278. buf += sprintf(buf, "VSIs: %d QP: %d ", pf->hw.func_caps.num_vsis,
  7279. pf->vsi[pf->lan_vsi]->num_queue_pairs);
  7280. if (pf->flags & I40E_FLAG_RSS_ENABLED)
  7281. buf += sprintf(buf, "RSS ");
  7282. if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
  7283. buf += sprintf(buf, "FD_ATR ");
  7284. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  7285. buf += sprintf(buf, "FD_SB ");
  7286. buf += sprintf(buf, "NTUPLE ");
  7287. }
  7288. if (pf->flags & I40E_FLAG_DCB_CAPABLE)
  7289. buf += sprintf(buf, "DCB ");
  7290. if (pf->flags & I40E_FLAG_PTP)
  7291. buf += sprintf(buf, "PTP ");
  7292. BUG_ON(buf > (string + INFO_STRING_LEN));
  7293. dev_info(&pf->pdev->dev, "%s\n", string);
  7294. kfree(string);
  7295. }
  7296. /**
  7297. * i40e_probe - Device initialization routine
  7298. * @pdev: PCI device information struct
  7299. * @ent: entry in i40e_pci_tbl
  7300. *
  7301. * i40e_probe initializes a pf identified by a pci_dev structure.
  7302. * The OS initialization, configuring of the pf private structure,
  7303. * and a hardware reset occur.
  7304. *
  7305. * Returns 0 on success, negative on failure
  7306. **/
  7307. static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  7308. {
  7309. struct i40e_pf *pf;
  7310. struct i40e_hw *hw;
  7311. static u16 pfs_found;
  7312. u16 link_status;
  7313. int err = 0;
  7314. u32 len;
  7315. u32 i;
  7316. err = pci_enable_device_mem(pdev);
  7317. if (err)
  7318. return err;
  7319. /* set up for high or low dma */
  7320. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  7321. if (err) {
  7322. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  7323. if (err) {
  7324. dev_err(&pdev->dev,
  7325. "DMA configuration failed: 0x%x\n", err);
  7326. goto err_dma;
  7327. }
  7328. }
  7329. /* set up pci connections */
  7330. err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
  7331. IORESOURCE_MEM), i40e_driver_name);
  7332. if (err) {
  7333. dev_info(&pdev->dev,
  7334. "pci_request_selected_regions failed %d\n", err);
  7335. goto err_pci_reg;
  7336. }
  7337. pci_enable_pcie_error_reporting(pdev);
  7338. pci_set_master(pdev);
  7339. /* Now that we have a PCI connection, we need to do the
  7340. * low level device setup. This is primarily setting up
  7341. * the Admin Queue structures and then querying for the
  7342. * device's current profile information.
  7343. */
  7344. pf = kzalloc(sizeof(*pf), GFP_KERNEL);
  7345. if (!pf) {
  7346. err = -ENOMEM;
  7347. goto err_pf_alloc;
  7348. }
  7349. pf->next_vsi = 0;
  7350. pf->pdev = pdev;
  7351. set_bit(__I40E_DOWN, &pf->state);
  7352. hw = &pf->hw;
  7353. hw->back = pf;
  7354. hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
  7355. pci_resource_len(pdev, 0));
  7356. if (!hw->hw_addr) {
  7357. err = -EIO;
  7358. dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
  7359. (unsigned int)pci_resource_start(pdev, 0),
  7360. (unsigned int)pci_resource_len(pdev, 0), err);
  7361. goto err_ioremap;
  7362. }
  7363. hw->vendor_id = pdev->vendor;
  7364. hw->device_id = pdev->device;
  7365. pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
  7366. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  7367. hw->subsystem_device_id = pdev->subsystem_device;
  7368. hw->bus.device = PCI_SLOT(pdev->devfn);
  7369. hw->bus.func = PCI_FUNC(pdev->devfn);
  7370. pf->instance = pfs_found;
  7371. /* do a special CORER for clearing PXE mode once at init */
  7372. if (hw->revision_id == 0 &&
  7373. (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
  7374. wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
  7375. i40e_flush(hw);
  7376. msleep(200);
  7377. pf->corer_count++;
  7378. i40e_clear_pxe_mode(hw);
  7379. }
  7380. /* Reset here to make sure all is clean and to define PF 'n' */
  7381. err = i40e_pf_reset(hw);
  7382. if (err) {
  7383. dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err);
  7384. goto err_pf_reset;
  7385. }
  7386. pf->pfr_count++;
  7387. hw->aq.num_arq_entries = I40E_AQ_LEN;
  7388. hw->aq.num_asq_entries = I40E_AQ_LEN;
  7389. hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  7390. hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  7391. pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
  7392. snprintf(pf->misc_int_name, sizeof(pf->misc_int_name) - 1,
  7393. "%s-pf%d:misc",
  7394. dev_driver_string(&pf->pdev->dev), pf->hw.pf_id);
  7395. err = i40e_init_shared_code(hw);
  7396. if (err) {
  7397. dev_info(&pdev->dev, "init_shared_code failed: %d\n", err);
  7398. goto err_pf_reset;
  7399. }
  7400. /* set up a default setting for link flow control */
  7401. pf->hw.fc.requested_mode = I40E_FC_NONE;
  7402. err = i40e_init_adminq(hw);
  7403. dev_info(&pdev->dev, "%s\n", i40e_fw_version_str(hw));
  7404. if (err) {
  7405. dev_info(&pdev->dev,
  7406. "init_adminq failed: %d expecting API %02x.%02x\n",
  7407. err,
  7408. I40E_FW_API_VERSION_MAJOR, I40E_FW_API_VERSION_MINOR);
  7409. goto err_pf_reset;
  7410. }
  7411. i40e_verify_eeprom(pf);
  7412. /* Rev 0 hardware was never productized */
  7413. if (hw->revision_id < 1)
  7414. dev_warn(&pdev->dev, "This device is a pre-production adapter/LOM. Please be aware there may be issues with your hardware. If you are experiencing problems please contact your Intel or hardware representative who provided you with this hardware.\n");
  7415. i40e_clear_pxe_mode(hw);
  7416. err = i40e_get_capabilities(pf);
  7417. if (err)
  7418. goto err_adminq_setup;
  7419. err = i40e_sw_init(pf);
  7420. if (err) {
  7421. dev_info(&pdev->dev, "sw_init failed: %d\n", err);
  7422. goto err_sw_init;
  7423. }
  7424. err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  7425. hw->func_caps.num_rx_qp,
  7426. pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
  7427. if (err) {
  7428. dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
  7429. goto err_init_lan_hmc;
  7430. }
  7431. err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  7432. if (err) {
  7433. dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
  7434. err = -ENOENT;
  7435. goto err_configure_lan_hmc;
  7436. }
  7437. i40e_get_mac_addr(hw, hw->mac.addr);
  7438. if (!is_valid_ether_addr(hw->mac.addr)) {
  7439. dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
  7440. err = -EIO;
  7441. goto err_mac_addr;
  7442. }
  7443. dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
  7444. ether_addr_copy(hw->mac.perm_addr, hw->mac.addr);
  7445. pci_set_drvdata(pdev, pf);
  7446. pci_save_state(pdev);
  7447. #ifdef CONFIG_I40E_DCB
  7448. err = i40e_init_pf_dcb(pf);
  7449. if (err) {
  7450. dev_info(&pdev->dev, "init_pf_dcb failed: %d\n", err);
  7451. pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
  7452. /* Continue without DCB enabled */
  7453. }
  7454. #endif /* CONFIG_I40E_DCB */
  7455. /* set up periodic task facility */
  7456. setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf);
  7457. pf->service_timer_period = HZ;
  7458. INIT_WORK(&pf->service_task, i40e_service_task);
  7459. clear_bit(__I40E_SERVICE_SCHED, &pf->state);
  7460. pf->flags |= I40E_FLAG_NEED_LINK_UPDATE;
  7461. pf->link_check_timeout = jiffies;
  7462. /* WoL defaults to disabled */
  7463. pf->wol_en = false;
  7464. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  7465. /* set up the main switch operations */
  7466. i40e_determine_queue_usage(pf);
  7467. i40e_init_interrupt_scheme(pf);
  7468. /* The number of VSIs reported by the FW is the minimum guaranteed
  7469. * to us; HW supports far more and we share the remaining pool with
  7470. * the other PFs. We allocate space for more than the guarantee with
  7471. * the understanding that we might not get them all later.
  7472. */
  7473. if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
  7474. pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
  7475. else
  7476. pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
  7477. /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
  7478. len = sizeof(struct i40e_vsi *) * pf->num_alloc_vsi;
  7479. pf->vsi = kzalloc(len, GFP_KERNEL);
  7480. if (!pf->vsi) {
  7481. err = -ENOMEM;
  7482. goto err_switch_setup;
  7483. }
  7484. err = i40e_setup_pf_switch(pf, false);
  7485. if (err) {
  7486. dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
  7487. goto err_vsis;
  7488. }
  7489. /* if FDIR VSI was set up, start it now */
  7490. for (i = 0; i < pf->num_alloc_vsi; i++) {
  7491. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
  7492. i40e_vsi_open(pf->vsi[i]);
  7493. break;
  7494. }
  7495. }
  7496. /* The main driver is (mostly) up and happy. We need to set this state
  7497. * before setting up the misc vector or we get a race and the vector
  7498. * ends up disabled forever.
  7499. */
  7500. clear_bit(__I40E_DOWN, &pf->state);
  7501. /* In case of MSIX we are going to setup the misc vector right here
  7502. * to handle admin queue events etc. In case of legacy and MSI
  7503. * the misc functionality and queue processing is combined in
  7504. * the same vector and that gets setup at open.
  7505. */
  7506. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  7507. err = i40e_setup_misc_vector(pf);
  7508. if (err) {
  7509. dev_info(&pdev->dev,
  7510. "setup of misc vector failed: %d\n", err);
  7511. goto err_vsis;
  7512. }
  7513. }
  7514. #ifdef CONFIG_PCI_IOV
  7515. /* prep for VF support */
  7516. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  7517. (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  7518. !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
  7519. u32 val;
  7520. /* disable link interrupts for VFs */
  7521. val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
  7522. val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
  7523. wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
  7524. i40e_flush(hw);
  7525. if (pci_num_vf(pdev)) {
  7526. dev_info(&pdev->dev,
  7527. "Active VFs found, allocating resources.\n");
  7528. err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
  7529. if (err)
  7530. dev_info(&pdev->dev,
  7531. "Error %d allocating resources for existing VFs\n",
  7532. err);
  7533. }
  7534. }
  7535. #endif /* CONFIG_PCI_IOV */
  7536. pfs_found++;
  7537. i40e_dbg_pf_init(pf);
  7538. /* tell the firmware that we're starting */
  7539. i40e_send_version(pf);
  7540. /* since everything's happy, start the service_task timer */
  7541. mod_timer(&pf->service_timer,
  7542. round_jiffies(jiffies + pf->service_timer_period));
  7543. /* Get the negotiated link width and speed from PCI config space */
  7544. pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA, &link_status);
  7545. i40e_set_pci_config_data(hw, link_status);
  7546. dev_info(&pdev->dev, "PCI-Express: %s %s\n",
  7547. (hw->bus.speed == i40e_bus_speed_8000 ? "Speed 8.0GT/s" :
  7548. hw->bus.speed == i40e_bus_speed_5000 ? "Speed 5.0GT/s" :
  7549. hw->bus.speed == i40e_bus_speed_2500 ? "Speed 2.5GT/s" :
  7550. "Unknown"),
  7551. (hw->bus.width == i40e_bus_width_pcie_x8 ? "Width x8" :
  7552. hw->bus.width == i40e_bus_width_pcie_x4 ? "Width x4" :
  7553. hw->bus.width == i40e_bus_width_pcie_x2 ? "Width x2" :
  7554. hw->bus.width == i40e_bus_width_pcie_x1 ? "Width x1" :
  7555. "Unknown"));
  7556. if (hw->bus.width < i40e_bus_width_pcie_x8 ||
  7557. hw->bus.speed < i40e_bus_speed_8000) {
  7558. dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
  7559. dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
  7560. }
  7561. /* print a string summarizing features */
  7562. i40e_print_features(pf);
  7563. return 0;
  7564. /* Unwind what we've done if something failed in the setup */
  7565. err_vsis:
  7566. set_bit(__I40E_DOWN, &pf->state);
  7567. i40e_clear_interrupt_scheme(pf);
  7568. kfree(pf->vsi);
  7569. err_switch_setup:
  7570. i40e_reset_interrupt_capability(pf);
  7571. del_timer_sync(&pf->service_timer);
  7572. err_mac_addr:
  7573. err_configure_lan_hmc:
  7574. (void)i40e_shutdown_lan_hmc(hw);
  7575. err_init_lan_hmc:
  7576. kfree(pf->qp_pile);
  7577. kfree(pf->irq_pile);
  7578. err_sw_init:
  7579. err_adminq_setup:
  7580. (void)i40e_shutdown_adminq(hw);
  7581. err_pf_reset:
  7582. iounmap(hw->hw_addr);
  7583. err_ioremap:
  7584. kfree(pf);
  7585. err_pf_alloc:
  7586. pci_disable_pcie_error_reporting(pdev);
  7587. pci_release_selected_regions(pdev,
  7588. pci_select_bars(pdev, IORESOURCE_MEM));
  7589. err_pci_reg:
  7590. err_dma:
  7591. pci_disable_device(pdev);
  7592. return err;
  7593. }
  7594. /**
  7595. * i40e_remove - Device removal routine
  7596. * @pdev: PCI device information struct
  7597. *
  7598. * i40e_remove is called by the PCI subsystem to alert the driver
  7599. * that is should release a PCI device. This could be caused by a
  7600. * Hot-Plug event, or because the driver is going to be removed from
  7601. * memory.
  7602. **/
  7603. static void i40e_remove(struct pci_dev *pdev)
  7604. {
  7605. struct i40e_pf *pf = pci_get_drvdata(pdev);
  7606. i40e_status ret_code;
  7607. u32 reg;
  7608. int i;
  7609. i40e_dbg_pf_exit(pf);
  7610. i40e_ptp_stop(pf);
  7611. /* no more scheduling of any task */
  7612. set_bit(__I40E_DOWN, &pf->state);
  7613. del_timer_sync(&pf->service_timer);
  7614. cancel_work_sync(&pf->service_task);
  7615. if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
  7616. i40e_free_vfs(pf);
  7617. pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
  7618. }
  7619. i40e_fdir_teardown(pf);
  7620. /* If there is a switch structure or any orphans, remove them.
  7621. * This will leave only the PF's VSI remaining.
  7622. */
  7623. for (i = 0; i < I40E_MAX_VEB; i++) {
  7624. if (!pf->veb[i])
  7625. continue;
  7626. if (pf->veb[i]->uplink_seid == pf->mac_seid ||
  7627. pf->veb[i]->uplink_seid == 0)
  7628. i40e_switch_branch_release(pf->veb[i]);
  7629. }
  7630. /* Now we can shutdown the PF's VSI, just before we kill
  7631. * adminq and hmc.
  7632. */
  7633. if (pf->vsi[pf->lan_vsi])
  7634. i40e_vsi_release(pf->vsi[pf->lan_vsi]);
  7635. i40e_stop_misc_vector(pf);
  7636. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  7637. synchronize_irq(pf->msix_entries[0].vector);
  7638. free_irq(pf->msix_entries[0].vector, pf);
  7639. }
  7640. /* shutdown and destroy the HMC */
  7641. if (pf->hw.hmc.hmc_obj) {
  7642. ret_code = i40e_shutdown_lan_hmc(&pf->hw);
  7643. if (ret_code)
  7644. dev_warn(&pdev->dev,
  7645. "Failed to destroy the HMC resources: %d\n",
  7646. ret_code);
  7647. }
  7648. /* shutdown the adminq */
  7649. ret_code = i40e_shutdown_adminq(&pf->hw);
  7650. if (ret_code)
  7651. dev_warn(&pdev->dev,
  7652. "Failed to destroy the Admin Queue resources: %d\n",
  7653. ret_code);
  7654. /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
  7655. i40e_clear_interrupt_scheme(pf);
  7656. for (i = 0; i < pf->num_alloc_vsi; i++) {
  7657. if (pf->vsi[i]) {
  7658. i40e_vsi_clear_rings(pf->vsi[i]);
  7659. i40e_vsi_clear(pf->vsi[i]);
  7660. pf->vsi[i] = NULL;
  7661. }
  7662. }
  7663. for (i = 0; i < I40E_MAX_VEB; i++) {
  7664. kfree(pf->veb[i]);
  7665. pf->veb[i] = NULL;
  7666. }
  7667. kfree(pf->qp_pile);
  7668. kfree(pf->irq_pile);
  7669. kfree(pf->vsi);
  7670. /* force a PF reset to clean anything leftover */
  7671. reg = rd32(&pf->hw, I40E_PFGEN_CTRL);
  7672. wr32(&pf->hw, I40E_PFGEN_CTRL, (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
  7673. i40e_flush(&pf->hw);
  7674. iounmap(pf->hw.hw_addr);
  7675. kfree(pf);
  7676. pci_release_selected_regions(pdev,
  7677. pci_select_bars(pdev, IORESOURCE_MEM));
  7678. pci_disable_pcie_error_reporting(pdev);
  7679. pci_disable_device(pdev);
  7680. }
  7681. /**
  7682. * i40e_pci_error_detected - warning that something funky happened in PCI land
  7683. * @pdev: PCI device information struct
  7684. *
  7685. * Called to warn that something happened and the error handling steps
  7686. * are in progress. Allows the driver to quiesce things, be ready for
  7687. * remediation.
  7688. **/
  7689. static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
  7690. enum pci_channel_state error)
  7691. {
  7692. struct i40e_pf *pf = pci_get_drvdata(pdev);
  7693. dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
  7694. /* shutdown all operations */
  7695. if (!test_bit(__I40E_SUSPENDED, &pf->state)) {
  7696. rtnl_lock();
  7697. i40e_prep_for_reset(pf);
  7698. rtnl_unlock();
  7699. }
  7700. /* Request a slot reset */
  7701. return PCI_ERS_RESULT_NEED_RESET;
  7702. }
  7703. /**
  7704. * i40e_pci_error_slot_reset - a PCI slot reset just happened
  7705. * @pdev: PCI device information struct
  7706. *
  7707. * Called to find if the driver can work with the device now that
  7708. * the pci slot has been reset. If a basic connection seems good
  7709. * (registers are readable and have sane content) then return a
  7710. * happy little PCI_ERS_RESULT_xxx.
  7711. **/
  7712. static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
  7713. {
  7714. struct i40e_pf *pf = pci_get_drvdata(pdev);
  7715. pci_ers_result_t result;
  7716. int err;
  7717. u32 reg;
  7718. dev_info(&pdev->dev, "%s\n", __func__);
  7719. if (pci_enable_device_mem(pdev)) {
  7720. dev_info(&pdev->dev,
  7721. "Cannot re-enable PCI device after reset.\n");
  7722. result = PCI_ERS_RESULT_DISCONNECT;
  7723. } else {
  7724. pci_set_master(pdev);
  7725. pci_restore_state(pdev);
  7726. pci_save_state(pdev);
  7727. pci_wake_from_d3(pdev, false);
  7728. reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  7729. if (reg == 0)
  7730. result = PCI_ERS_RESULT_RECOVERED;
  7731. else
  7732. result = PCI_ERS_RESULT_DISCONNECT;
  7733. }
  7734. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  7735. if (err) {
  7736. dev_info(&pdev->dev,
  7737. "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
  7738. err);
  7739. /* non-fatal, continue */
  7740. }
  7741. return result;
  7742. }
  7743. /**
  7744. * i40e_pci_error_resume - restart operations after PCI error recovery
  7745. * @pdev: PCI device information struct
  7746. *
  7747. * Called to allow the driver to bring things back up after PCI error
  7748. * and/or reset recovery has finished.
  7749. **/
  7750. static void i40e_pci_error_resume(struct pci_dev *pdev)
  7751. {
  7752. struct i40e_pf *pf = pci_get_drvdata(pdev);
  7753. dev_info(&pdev->dev, "%s\n", __func__);
  7754. if (test_bit(__I40E_SUSPENDED, &pf->state))
  7755. return;
  7756. rtnl_lock();
  7757. i40e_handle_reset_warning(pf);
  7758. rtnl_lock();
  7759. }
  7760. /**
  7761. * i40e_shutdown - PCI callback for shutting down
  7762. * @pdev: PCI device information struct
  7763. **/
  7764. static void i40e_shutdown(struct pci_dev *pdev)
  7765. {
  7766. struct i40e_pf *pf = pci_get_drvdata(pdev);
  7767. struct i40e_hw *hw = &pf->hw;
  7768. set_bit(__I40E_SUSPENDED, &pf->state);
  7769. set_bit(__I40E_DOWN, &pf->state);
  7770. rtnl_lock();
  7771. i40e_prep_for_reset(pf);
  7772. rtnl_unlock();
  7773. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  7774. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  7775. if (system_state == SYSTEM_POWER_OFF) {
  7776. pci_wake_from_d3(pdev, pf->wol_en);
  7777. pci_set_power_state(pdev, PCI_D3hot);
  7778. }
  7779. }
  7780. #ifdef CONFIG_PM
  7781. /**
  7782. * i40e_suspend - PCI callback for moving to D3
  7783. * @pdev: PCI device information struct
  7784. **/
  7785. static int i40e_suspend(struct pci_dev *pdev, pm_message_t state)
  7786. {
  7787. struct i40e_pf *pf = pci_get_drvdata(pdev);
  7788. struct i40e_hw *hw = &pf->hw;
  7789. set_bit(__I40E_SUSPENDED, &pf->state);
  7790. set_bit(__I40E_DOWN, &pf->state);
  7791. rtnl_lock();
  7792. i40e_prep_for_reset(pf);
  7793. rtnl_unlock();
  7794. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  7795. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  7796. pci_wake_from_d3(pdev, pf->wol_en);
  7797. pci_set_power_state(pdev, PCI_D3hot);
  7798. return 0;
  7799. }
  7800. /**
  7801. * i40e_resume - PCI callback for waking up from D3
  7802. * @pdev: PCI device information struct
  7803. **/
  7804. static int i40e_resume(struct pci_dev *pdev)
  7805. {
  7806. struct i40e_pf *pf = pci_get_drvdata(pdev);
  7807. u32 err;
  7808. pci_set_power_state(pdev, PCI_D0);
  7809. pci_restore_state(pdev);
  7810. /* pci_restore_state() clears dev->state_saves, so
  7811. * call pci_save_state() again to restore it.
  7812. */
  7813. pci_save_state(pdev);
  7814. err = pci_enable_device_mem(pdev);
  7815. if (err) {
  7816. dev_err(&pdev->dev,
  7817. "%s: Cannot enable PCI device from suspend\n",
  7818. __func__);
  7819. return err;
  7820. }
  7821. pci_set_master(pdev);
  7822. /* no wakeup events while running */
  7823. pci_wake_from_d3(pdev, false);
  7824. /* handling the reset will rebuild the device state */
  7825. if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) {
  7826. clear_bit(__I40E_DOWN, &pf->state);
  7827. rtnl_lock();
  7828. i40e_reset_and_rebuild(pf, false);
  7829. rtnl_unlock();
  7830. }
  7831. return 0;
  7832. }
  7833. #endif
  7834. static const struct pci_error_handlers i40e_err_handler = {
  7835. .error_detected = i40e_pci_error_detected,
  7836. .slot_reset = i40e_pci_error_slot_reset,
  7837. .resume = i40e_pci_error_resume,
  7838. };
  7839. static struct pci_driver i40e_driver = {
  7840. .name = i40e_driver_name,
  7841. .id_table = i40e_pci_tbl,
  7842. .probe = i40e_probe,
  7843. .remove = i40e_remove,
  7844. #ifdef CONFIG_PM
  7845. .suspend = i40e_suspend,
  7846. .resume = i40e_resume,
  7847. #endif
  7848. .shutdown = i40e_shutdown,
  7849. .err_handler = &i40e_err_handler,
  7850. .sriov_configure = i40e_pci_sriov_configure,
  7851. };
  7852. /**
  7853. * i40e_init_module - Driver registration routine
  7854. *
  7855. * i40e_init_module is the first routine called when the driver is
  7856. * loaded. All it does is register with the PCI subsystem.
  7857. **/
  7858. static int __init i40e_init_module(void)
  7859. {
  7860. pr_info("%s: %s - version %s\n", i40e_driver_name,
  7861. i40e_driver_string, i40e_driver_version_str);
  7862. pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
  7863. i40e_dbg_init();
  7864. return pci_register_driver(&i40e_driver);
  7865. }
  7866. module_init(i40e_init_module);
  7867. /**
  7868. * i40e_exit_module - Driver exit cleanup routine
  7869. *
  7870. * i40e_exit_module is called just before the driver is removed
  7871. * from memory.
  7872. **/
  7873. static void __exit i40e_exit_module(void)
  7874. {
  7875. pci_unregister_driver(&i40e_driver);
  7876. i40e_dbg_exit();
  7877. }
  7878. module_exit(i40e_exit_module);