i40e_main.c 289 KB

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