i40e_main.c 290 KB

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