i40e_main.c 315 KB

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