i40e_main.c 279 KB

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