i40e_main.c 265 KB

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