i40e_main.c 317 KB

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