i40e_main.c 290 KB

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