i40e_main.c 299 KB

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