i40e_main.c 304 KB

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