i40e_main.c 318 KB

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