i40e_main.c 260 KB

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