i40e_main.c 311 KB

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