i40e_main.c 318 KB

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