i40e_main.c 319 KB

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