i40e_main.c 325 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2016 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. * Contact Information:
  22. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. ******************************************************************************/
  26. #include <linux/etherdevice.h>
  27. #include <linux/of_net.h>
  28. #include <linux/pci.h>
  29. /* Local includes */
  30. #include "i40e.h"
  31. #include "i40e_diag.h"
  32. #include <net/udp_tunnel.h>
  33. const char i40e_driver_name[] = "i40e";
  34. static const char i40e_driver_string[] =
  35. "Intel(R) Ethernet Connection XL710 Network Driver";
  36. #define DRV_KERN "-k"
  37. #define DRV_VERSION_MAJOR 1
  38. #define DRV_VERSION_MINOR 6
  39. #define DRV_VERSION_BUILD 27
  40. #define DRV_VERSION __stringify(DRV_VERSION_MAJOR) "." \
  41. __stringify(DRV_VERSION_MINOR) "." \
  42. __stringify(DRV_VERSION_BUILD) DRV_KERN
  43. const char i40e_driver_version_str[] = DRV_VERSION;
  44. static const char i40e_copyright[] = "Copyright (c) 2013 - 2014 Intel Corporation.";
  45. /* a bit of forward declarations */
  46. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi);
  47. static void i40e_handle_reset_warning(struct i40e_pf *pf);
  48. static int i40e_add_vsi(struct i40e_vsi *vsi);
  49. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi);
  50. static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit);
  51. static int i40e_setup_misc_vector(struct i40e_pf *pf);
  52. static void i40e_determine_queue_usage(struct i40e_pf *pf);
  53. static int i40e_setup_pf_filter_control(struct i40e_pf *pf);
  54. static void i40e_fdir_sb_setup(struct i40e_pf *pf);
  55. static int i40e_veb_get_bw_info(struct i40e_veb *veb);
  56. /* i40e_pci_tbl - PCI Device ID Table
  57. *
  58. * Last entry must be all 0s
  59. *
  60. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  61. * Class, Class Mask, private data (not used) }
  62. */
  63. static const struct pci_device_id i40e_pci_tbl[] = {
  64. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_XL710), 0},
  65. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QEMU), 0},
  66. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_B), 0},
  67. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_C), 0},
  68. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_A), 0},
  69. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_B), 0},
  70. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_C), 0},
  71. {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T), 0},
  72. {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T4), 0},
  73. {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
  74. {PCI_VDEVICE(INTEL, I40E_DEV_ID_KX_X722), 0},
  75. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0},
  76. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0},
  77. {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0},
  78. {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0},
  79. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_I_X722), 0},
  80. {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
  81. {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0},
  82. {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_B), 0},
  83. {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_SFP28), 0},
  84. /* required last entry */
  85. {0, }
  86. };
  87. MODULE_DEVICE_TABLE(pci, i40e_pci_tbl);
  88. #define I40E_MAX_VF_COUNT 128
  89. static int debug = -1;
  90. module_param(debug, uint, 0);
  91. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all), Debug mask (0x8XXXXXXX)");
  92. MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
  93. MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
  94. MODULE_LICENSE("GPL");
  95. MODULE_VERSION(DRV_VERSION);
  96. static struct workqueue_struct *i40e_wq;
  97. /**
  98. * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
  99. * @hw: pointer to the HW structure
  100. * @mem: ptr to mem struct to fill out
  101. * @size: size of memory requested
  102. * @alignment: what to align the allocation to
  103. **/
  104. int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
  105. u64 size, u32 alignment)
  106. {
  107. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  108. mem->size = ALIGN(size, alignment);
  109. mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size,
  110. &mem->pa, GFP_KERNEL);
  111. if (!mem->va)
  112. return -ENOMEM;
  113. return 0;
  114. }
  115. /**
  116. * i40e_free_dma_mem_d - OS specific memory free for shared code
  117. * @hw: pointer to the HW structure
  118. * @mem: ptr to mem struct to free
  119. **/
  120. int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
  121. {
  122. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  123. dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa);
  124. mem->va = NULL;
  125. mem->pa = 0;
  126. mem->size = 0;
  127. return 0;
  128. }
  129. /**
  130. * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
  131. * @hw: pointer to the HW structure
  132. * @mem: ptr to mem struct to fill out
  133. * @size: size of memory requested
  134. **/
  135. int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem,
  136. u32 size)
  137. {
  138. mem->size = size;
  139. mem->va = kzalloc(size, GFP_KERNEL);
  140. if (!mem->va)
  141. return -ENOMEM;
  142. return 0;
  143. }
  144. /**
  145. * i40e_free_virt_mem_d - OS specific memory free for shared code
  146. * @hw: pointer to the HW structure
  147. * @mem: ptr to mem struct to free
  148. **/
  149. int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem)
  150. {
  151. /* it's ok to kfree a NULL pointer */
  152. kfree(mem->va);
  153. mem->va = NULL;
  154. mem->size = 0;
  155. return 0;
  156. }
  157. /**
  158. * i40e_get_lump - find a lump of free generic resource
  159. * @pf: board private structure
  160. * @pile: the pile of resource to search
  161. * @needed: the number of items needed
  162. * @id: an owner id to stick on the items assigned
  163. *
  164. * Returns the base item index of the lump, or negative for error
  165. *
  166. * The search_hint trick and lack of advanced fit-finding only work
  167. * because we're highly likely to have all the same size lump requests.
  168. * Linear search time and any fragmentation should be minimal.
  169. **/
  170. static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile,
  171. u16 needed, u16 id)
  172. {
  173. int ret = -ENOMEM;
  174. int i, j;
  175. if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) {
  176. dev_info(&pf->pdev->dev,
  177. "param err: pile=%p needed=%d id=0x%04x\n",
  178. pile, needed, id);
  179. return -EINVAL;
  180. }
  181. /* start the linear search with an imperfect hint */
  182. i = pile->search_hint;
  183. while (i < pile->num_entries) {
  184. /* skip already allocated entries */
  185. if (pile->list[i] & I40E_PILE_VALID_BIT) {
  186. i++;
  187. continue;
  188. }
  189. /* do we have enough in this lump? */
  190. for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) {
  191. if (pile->list[i+j] & I40E_PILE_VALID_BIT)
  192. break;
  193. }
  194. if (j == needed) {
  195. /* there was enough, so assign it to the requestor */
  196. for (j = 0; j < needed; j++)
  197. pile->list[i+j] = id | I40E_PILE_VALID_BIT;
  198. ret = i;
  199. pile->search_hint = i + j;
  200. break;
  201. }
  202. /* not enough, so skip over it and continue looking */
  203. i += j;
  204. }
  205. return ret;
  206. }
  207. /**
  208. * i40e_put_lump - return a lump of generic resource
  209. * @pile: the pile of resource to search
  210. * @index: the base item index
  211. * @id: the owner id of the items assigned
  212. *
  213. * Returns the count of items in the lump
  214. **/
  215. static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id)
  216. {
  217. int valid_id = (id | I40E_PILE_VALID_BIT);
  218. int count = 0;
  219. int i;
  220. if (!pile || index >= pile->num_entries)
  221. return -EINVAL;
  222. for (i = index;
  223. i < pile->num_entries && pile->list[i] == valid_id;
  224. i++) {
  225. pile->list[i] = 0;
  226. count++;
  227. }
  228. if (count && index < pile->search_hint)
  229. pile->search_hint = index;
  230. return count;
  231. }
  232. /**
  233. * i40e_find_vsi_from_id - searches for the vsi with the given id
  234. * @pf - the pf structure to search for the vsi
  235. * @id - id of the vsi it is searching for
  236. **/
  237. struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id)
  238. {
  239. int i;
  240. for (i = 0; i < pf->num_alloc_vsi; i++)
  241. if (pf->vsi[i] && (pf->vsi[i]->id == id))
  242. return pf->vsi[i];
  243. return NULL;
  244. }
  245. /**
  246. * i40e_service_event_schedule - Schedule the service task to wake up
  247. * @pf: board private structure
  248. *
  249. * If not already scheduled, this puts the task into the work queue
  250. **/
  251. void i40e_service_event_schedule(struct i40e_pf *pf)
  252. {
  253. if (!test_bit(__I40E_DOWN, &pf->state) &&
  254. !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
  255. queue_work(i40e_wq, &pf->service_task);
  256. }
  257. /**
  258. * i40e_tx_timeout - Respond to a Tx Hang
  259. * @netdev: network interface device structure
  260. *
  261. * If any port has noticed a Tx timeout, it is likely that the whole
  262. * device is munged, not just the one netdev port, so go for the full
  263. * reset.
  264. **/
  265. #ifdef I40E_FCOE
  266. void i40e_tx_timeout(struct net_device *netdev)
  267. #else
  268. static void i40e_tx_timeout(struct net_device *netdev)
  269. #endif
  270. {
  271. struct i40e_netdev_priv *np = netdev_priv(netdev);
  272. struct i40e_vsi *vsi = np->vsi;
  273. struct i40e_pf *pf = vsi->back;
  274. struct i40e_ring *tx_ring = NULL;
  275. unsigned int i, hung_queue = 0;
  276. u32 head, val;
  277. pf->tx_timeout_count++;
  278. /* find the stopped queue the same way the stack does */
  279. for (i = 0; i < netdev->num_tx_queues; i++) {
  280. struct netdev_queue *q;
  281. unsigned long trans_start;
  282. q = netdev_get_tx_queue(netdev, i);
  283. trans_start = q->trans_start;
  284. if (netif_xmit_stopped(q) &&
  285. time_after(jiffies,
  286. (trans_start + netdev->watchdog_timeo))) {
  287. hung_queue = i;
  288. break;
  289. }
  290. }
  291. if (i == netdev->num_tx_queues) {
  292. netdev_info(netdev, "tx_timeout: no netdev hung queue found\n");
  293. } else {
  294. /* now that we have an index, find the tx_ring struct */
  295. for (i = 0; i < vsi->num_queue_pairs; i++) {
  296. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
  297. if (hung_queue ==
  298. vsi->tx_rings[i]->queue_index) {
  299. tx_ring = vsi->tx_rings[i];
  300. break;
  301. }
  302. }
  303. }
  304. }
  305. if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20)))
  306. pf->tx_timeout_recovery_level = 1; /* reset after some time */
  307. else if (time_before(jiffies,
  308. (pf->tx_timeout_last_recovery + netdev->watchdog_timeo)))
  309. return; /* don't do any new action before the next timeout */
  310. if (tx_ring) {
  311. head = i40e_get_head(tx_ring);
  312. /* Read interrupt register */
  313. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  314. val = rd32(&pf->hw,
  315. I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
  316. tx_ring->vsi->base_vector - 1));
  317. else
  318. val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
  319. netdev_info(netdev, "tx_timeout: VSI_seid: %d, Q %d, NTC: 0x%x, HWB: 0x%x, NTU: 0x%x, TAIL: 0x%x, INT: 0x%x\n",
  320. vsi->seid, hung_queue, tx_ring->next_to_clean,
  321. head, tx_ring->next_to_use,
  322. readl(tx_ring->tail), val);
  323. }
  324. pf->tx_timeout_last_recovery = jiffies;
  325. netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n",
  326. pf->tx_timeout_recovery_level, hung_queue);
  327. switch (pf->tx_timeout_recovery_level) {
  328. case 1:
  329. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  330. break;
  331. case 2:
  332. set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
  333. break;
  334. case 3:
  335. set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
  336. break;
  337. default:
  338. netdev_err(netdev, "tx_timeout recovery unsuccessful\n");
  339. break;
  340. }
  341. i40e_service_event_schedule(pf);
  342. pf->tx_timeout_recovery_level++;
  343. }
  344. /**
  345. * i40e_get_vsi_stats_struct - Get System Network Statistics
  346. * @vsi: the VSI we care about
  347. *
  348. * Returns the address of the device statistics structure.
  349. * The statistics are actually updated from the service task.
  350. **/
  351. struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi)
  352. {
  353. return &vsi->net_stats;
  354. }
  355. /**
  356. * i40e_get_netdev_stats_struct - Get statistics for netdev interface
  357. * @netdev: network interface device structure
  358. *
  359. * Returns the address of the device statistics structure.
  360. * The statistics are actually updated from the service task.
  361. **/
  362. #ifndef I40E_FCOE
  363. static
  364. #endif
  365. void i40e_get_netdev_stats_struct(struct net_device *netdev,
  366. struct rtnl_link_stats64 *stats)
  367. {
  368. struct i40e_netdev_priv *np = netdev_priv(netdev);
  369. struct i40e_ring *tx_ring, *rx_ring;
  370. struct i40e_vsi *vsi = np->vsi;
  371. struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi);
  372. int i;
  373. if (test_bit(__I40E_DOWN, &vsi->state))
  374. return;
  375. if (!vsi->tx_rings)
  376. return;
  377. rcu_read_lock();
  378. for (i = 0; i < vsi->num_queue_pairs; i++) {
  379. u64 bytes, packets;
  380. unsigned int start;
  381. tx_ring = ACCESS_ONCE(vsi->tx_rings[i]);
  382. if (!tx_ring)
  383. continue;
  384. do {
  385. start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
  386. packets = tx_ring->stats.packets;
  387. bytes = tx_ring->stats.bytes;
  388. } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
  389. stats->tx_packets += packets;
  390. stats->tx_bytes += bytes;
  391. rx_ring = &tx_ring[1];
  392. do {
  393. start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
  394. packets = rx_ring->stats.packets;
  395. bytes = rx_ring->stats.bytes;
  396. } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
  397. stats->rx_packets += packets;
  398. stats->rx_bytes += bytes;
  399. }
  400. rcu_read_unlock();
  401. /* following stats updated by i40e_watchdog_subtask() */
  402. stats->multicast = vsi_stats->multicast;
  403. stats->tx_errors = vsi_stats->tx_errors;
  404. stats->tx_dropped = vsi_stats->tx_dropped;
  405. stats->rx_errors = vsi_stats->rx_errors;
  406. stats->rx_dropped = vsi_stats->rx_dropped;
  407. stats->rx_crc_errors = vsi_stats->rx_crc_errors;
  408. stats->rx_length_errors = vsi_stats->rx_length_errors;
  409. }
  410. /**
  411. * i40e_vsi_reset_stats - Resets all stats of the given vsi
  412. * @vsi: the VSI to have its stats reset
  413. **/
  414. void i40e_vsi_reset_stats(struct i40e_vsi *vsi)
  415. {
  416. struct rtnl_link_stats64 *ns;
  417. int i;
  418. if (!vsi)
  419. return;
  420. ns = i40e_get_vsi_stats_struct(vsi);
  421. memset(ns, 0, sizeof(*ns));
  422. memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets));
  423. memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats));
  424. memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets));
  425. if (vsi->rx_rings && vsi->rx_rings[0]) {
  426. for (i = 0; i < vsi->num_queue_pairs; i++) {
  427. memset(&vsi->rx_rings[i]->stats, 0,
  428. sizeof(vsi->rx_rings[i]->stats));
  429. memset(&vsi->rx_rings[i]->rx_stats, 0,
  430. sizeof(vsi->rx_rings[i]->rx_stats));
  431. memset(&vsi->tx_rings[i]->stats, 0,
  432. sizeof(vsi->tx_rings[i]->stats));
  433. memset(&vsi->tx_rings[i]->tx_stats, 0,
  434. sizeof(vsi->tx_rings[i]->tx_stats));
  435. }
  436. }
  437. vsi->stat_offsets_loaded = false;
  438. }
  439. /**
  440. * i40e_pf_reset_stats - Reset all of the stats for the given PF
  441. * @pf: the PF to be reset
  442. **/
  443. void i40e_pf_reset_stats(struct i40e_pf *pf)
  444. {
  445. int i;
  446. memset(&pf->stats, 0, sizeof(pf->stats));
  447. memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets));
  448. pf->stat_offsets_loaded = false;
  449. for (i = 0; i < I40E_MAX_VEB; i++) {
  450. if (pf->veb[i]) {
  451. memset(&pf->veb[i]->stats, 0,
  452. sizeof(pf->veb[i]->stats));
  453. memset(&pf->veb[i]->stats_offsets, 0,
  454. sizeof(pf->veb[i]->stats_offsets));
  455. pf->veb[i]->stat_offsets_loaded = false;
  456. }
  457. }
  458. pf->hw_csum_rx_error = 0;
  459. }
  460. /**
  461. * i40e_stat_update48 - read and update a 48 bit stat from the chip
  462. * @hw: ptr to the hardware info
  463. * @hireg: the high 32 bit reg to read
  464. * @loreg: the low 32 bit reg to read
  465. * @offset_loaded: has the initial offset been loaded yet
  466. * @offset: ptr to current offset value
  467. * @stat: ptr to the stat
  468. *
  469. * Since the device stats are not reset at PFReset, they likely will not
  470. * be zeroed when the driver starts. We'll save the first values read
  471. * and use them as offsets to be subtracted from the raw values in order
  472. * to report stats that count from zero. In the process, we also manage
  473. * the potential roll-over.
  474. **/
  475. static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg,
  476. bool offset_loaded, u64 *offset, u64 *stat)
  477. {
  478. u64 new_data;
  479. if (hw->device_id == I40E_DEV_ID_QEMU) {
  480. new_data = rd32(hw, loreg);
  481. new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
  482. } else {
  483. new_data = rd64(hw, loreg);
  484. }
  485. if (!offset_loaded)
  486. *offset = new_data;
  487. if (likely(new_data >= *offset))
  488. *stat = new_data - *offset;
  489. else
  490. *stat = (new_data + BIT_ULL(48)) - *offset;
  491. *stat &= 0xFFFFFFFFFFFFULL;
  492. }
  493. /**
  494. * i40e_stat_update32 - read and update a 32 bit stat from the chip
  495. * @hw: ptr to the hardware info
  496. * @reg: the hw reg to read
  497. * @offset_loaded: has the initial offset been loaded yet
  498. * @offset: ptr to current offset value
  499. * @stat: ptr to the stat
  500. **/
  501. static void i40e_stat_update32(struct i40e_hw *hw, u32 reg,
  502. bool offset_loaded, u64 *offset, u64 *stat)
  503. {
  504. u32 new_data;
  505. new_data = rd32(hw, reg);
  506. if (!offset_loaded)
  507. *offset = new_data;
  508. if (likely(new_data >= *offset))
  509. *stat = (u32)(new_data - *offset);
  510. else
  511. *stat = (u32)((new_data + BIT_ULL(32)) - *offset);
  512. }
  513. /**
  514. * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
  515. * @vsi: the VSI to be updated
  516. **/
  517. void i40e_update_eth_stats(struct i40e_vsi *vsi)
  518. {
  519. int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx);
  520. struct i40e_pf *pf = vsi->back;
  521. struct i40e_hw *hw = &pf->hw;
  522. struct i40e_eth_stats *oes;
  523. struct i40e_eth_stats *es; /* device's eth stats */
  524. es = &vsi->eth_stats;
  525. oes = &vsi->eth_stats_offsets;
  526. /* Gather up the stats that the hw collects */
  527. i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
  528. vsi->stat_offsets_loaded,
  529. &oes->tx_errors, &es->tx_errors);
  530. i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx),
  531. vsi->stat_offsets_loaded,
  532. &oes->rx_discards, &es->rx_discards);
  533. i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx),
  534. vsi->stat_offsets_loaded,
  535. &oes->rx_unknown_protocol, &es->rx_unknown_protocol);
  536. i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
  537. vsi->stat_offsets_loaded,
  538. &oes->tx_errors, &es->tx_errors);
  539. i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx),
  540. I40E_GLV_GORCL(stat_idx),
  541. vsi->stat_offsets_loaded,
  542. &oes->rx_bytes, &es->rx_bytes);
  543. i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx),
  544. I40E_GLV_UPRCL(stat_idx),
  545. vsi->stat_offsets_loaded,
  546. &oes->rx_unicast, &es->rx_unicast);
  547. i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx),
  548. I40E_GLV_MPRCL(stat_idx),
  549. vsi->stat_offsets_loaded,
  550. &oes->rx_multicast, &es->rx_multicast);
  551. i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx),
  552. I40E_GLV_BPRCL(stat_idx),
  553. vsi->stat_offsets_loaded,
  554. &oes->rx_broadcast, &es->rx_broadcast);
  555. i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx),
  556. I40E_GLV_GOTCL(stat_idx),
  557. vsi->stat_offsets_loaded,
  558. &oes->tx_bytes, &es->tx_bytes);
  559. i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx),
  560. I40E_GLV_UPTCL(stat_idx),
  561. vsi->stat_offsets_loaded,
  562. &oes->tx_unicast, &es->tx_unicast);
  563. i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx),
  564. I40E_GLV_MPTCL(stat_idx),
  565. vsi->stat_offsets_loaded,
  566. &oes->tx_multicast, &es->tx_multicast);
  567. i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx),
  568. I40E_GLV_BPTCL(stat_idx),
  569. vsi->stat_offsets_loaded,
  570. &oes->tx_broadcast, &es->tx_broadcast);
  571. vsi->stat_offsets_loaded = true;
  572. }
  573. /**
  574. * i40e_update_veb_stats - Update Switch component statistics
  575. * @veb: the VEB being updated
  576. **/
  577. static void i40e_update_veb_stats(struct i40e_veb *veb)
  578. {
  579. struct i40e_pf *pf = veb->pf;
  580. struct i40e_hw *hw = &pf->hw;
  581. struct i40e_eth_stats *oes;
  582. struct i40e_eth_stats *es; /* device's eth stats */
  583. struct i40e_veb_tc_stats *veb_oes;
  584. struct i40e_veb_tc_stats *veb_es;
  585. int i, idx = 0;
  586. idx = veb->stats_idx;
  587. es = &veb->stats;
  588. oes = &veb->stats_offsets;
  589. veb_es = &veb->tc_stats;
  590. veb_oes = &veb->tc_stats_offsets;
  591. /* Gather up the stats that the hw collects */
  592. i40e_stat_update32(hw, I40E_GLSW_TDPC(idx),
  593. veb->stat_offsets_loaded,
  594. &oes->tx_discards, &es->tx_discards);
  595. if (hw->revision_id > 0)
  596. i40e_stat_update32(hw, I40E_GLSW_RUPP(idx),
  597. veb->stat_offsets_loaded,
  598. &oes->rx_unknown_protocol,
  599. &es->rx_unknown_protocol);
  600. i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx),
  601. veb->stat_offsets_loaded,
  602. &oes->rx_bytes, &es->rx_bytes);
  603. i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx),
  604. veb->stat_offsets_loaded,
  605. &oes->rx_unicast, &es->rx_unicast);
  606. i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx),
  607. veb->stat_offsets_loaded,
  608. &oes->rx_multicast, &es->rx_multicast);
  609. i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx),
  610. veb->stat_offsets_loaded,
  611. &oes->rx_broadcast, &es->rx_broadcast);
  612. i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx),
  613. veb->stat_offsets_loaded,
  614. &oes->tx_bytes, &es->tx_bytes);
  615. i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx),
  616. veb->stat_offsets_loaded,
  617. &oes->tx_unicast, &es->tx_unicast);
  618. i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx),
  619. veb->stat_offsets_loaded,
  620. &oes->tx_multicast, &es->tx_multicast);
  621. i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx),
  622. veb->stat_offsets_loaded,
  623. &oes->tx_broadcast, &es->tx_broadcast);
  624. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  625. i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx),
  626. I40E_GLVEBTC_RPCL(i, idx),
  627. veb->stat_offsets_loaded,
  628. &veb_oes->tc_rx_packets[i],
  629. &veb_es->tc_rx_packets[i]);
  630. i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx),
  631. I40E_GLVEBTC_RBCL(i, idx),
  632. veb->stat_offsets_loaded,
  633. &veb_oes->tc_rx_bytes[i],
  634. &veb_es->tc_rx_bytes[i]);
  635. i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx),
  636. I40E_GLVEBTC_TPCL(i, idx),
  637. veb->stat_offsets_loaded,
  638. &veb_oes->tc_tx_packets[i],
  639. &veb_es->tc_tx_packets[i]);
  640. i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx),
  641. I40E_GLVEBTC_TBCL(i, idx),
  642. veb->stat_offsets_loaded,
  643. &veb_oes->tc_tx_bytes[i],
  644. &veb_es->tc_tx_bytes[i]);
  645. }
  646. veb->stat_offsets_loaded = true;
  647. }
  648. #ifdef I40E_FCOE
  649. /**
  650. * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters.
  651. * @vsi: the VSI that is capable of doing FCoE
  652. **/
  653. static void i40e_update_fcoe_stats(struct i40e_vsi *vsi)
  654. {
  655. struct i40e_pf *pf = vsi->back;
  656. struct i40e_hw *hw = &pf->hw;
  657. struct i40e_fcoe_stats *ofs;
  658. struct i40e_fcoe_stats *fs; /* device's eth stats */
  659. int idx;
  660. if (vsi->type != I40E_VSI_FCOE)
  661. return;
  662. idx = hw->pf_id + I40E_FCOE_PF_STAT_OFFSET;
  663. fs = &vsi->fcoe_stats;
  664. ofs = &vsi->fcoe_stats_offsets;
  665. i40e_stat_update32(hw, I40E_GL_FCOEPRC(idx),
  666. vsi->fcoe_stat_offsets_loaded,
  667. &ofs->rx_fcoe_packets, &fs->rx_fcoe_packets);
  668. i40e_stat_update48(hw, I40E_GL_FCOEDWRCH(idx), I40E_GL_FCOEDWRCL(idx),
  669. vsi->fcoe_stat_offsets_loaded,
  670. &ofs->rx_fcoe_dwords, &fs->rx_fcoe_dwords);
  671. i40e_stat_update32(hw, I40E_GL_FCOERPDC(idx),
  672. vsi->fcoe_stat_offsets_loaded,
  673. &ofs->rx_fcoe_dropped, &fs->rx_fcoe_dropped);
  674. i40e_stat_update32(hw, I40E_GL_FCOEPTC(idx),
  675. vsi->fcoe_stat_offsets_loaded,
  676. &ofs->tx_fcoe_packets, &fs->tx_fcoe_packets);
  677. i40e_stat_update48(hw, I40E_GL_FCOEDWTCH(idx), I40E_GL_FCOEDWTCL(idx),
  678. vsi->fcoe_stat_offsets_loaded,
  679. &ofs->tx_fcoe_dwords, &fs->tx_fcoe_dwords);
  680. i40e_stat_update32(hw, I40E_GL_FCOECRC(idx),
  681. vsi->fcoe_stat_offsets_loaded,
  682. &ofs->fcoe_bad_fccrc, &fs->fcoe_bad_fccrc);
  683. i40e_stat_update32(hw, I40E_GL_FCOELAST(idx),
  684. vsi->fcoe_stat_offsets_loaded,
  685. &ofs->fcoe_last_error, &fs->fcoe_last_error);
  686. i40e_stat_update32(hw, I40E_GL_FCOEDDPC(idx),
  687. vsi->fcoe_stat_offsets_loaded,
  688. &ofs->fcoe_ddp_count, &fs->fcoe_ddp_count);
  689. vsi->fcoe_stat_offsets_loaded = true;
  690. }
  691. #endif
  692. /**
  693. * i40e_update_vsi_stats - Update the vsi statistics counters.
  694. * @vsi: the VSI to be updated
  695. *
  696. * There are a few instances where we store the same stat in a
  697. * couple of different structs. This is partly because we have
  698. * the netdev stats that need to be filled out, which is slightly
  699. * different from the "eth_stats" defined by the chip and used in
  700. * VF communications. We sort it out here.
  701. **/
  702. static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
  703. {
  704. struct i40e_pf *pf = vsi->back;
  705. struct rtnl_link_stats64 *ons;
  706. struct rtnl_link_stats64 *ns; /* netdev stats */
  707. struct i40e_eth_stats *oes;
  708. struct i40e_eth_stats *es; /* device's eth stats */
  709. u32 tx_restart, tx_busy;
  710. u64 tx_lost_interrupt;
  711. struct i40e_ring *p;
  712. u32 rx_page, rx_buf;
  713. u64 bytes, packets;
  714. unsigned int start;
  715. u64 tx_linearize;
  716. u64 tx_force_wb;
  717. u64 rx_p, rx_b;
  718. u64 tx_p, tx_b;
  719. u16 q;
  720. if (test_bit(__I40E_DOWN, &vsi->state) ||
  721. test_bit(__I40E_CONFIG_BUSY, &pf->state))
  722. return;
  723. ns = i40e_get_vsi_stats_struct(vsi);
  724. ons = &vsi->net_stats_offsets;
  725. es = &vsi->eth_stats;
  726. oes = &vsi->eth_stats_offsets;
  727. /* Gather up the netdev and vsi stats that the driver collects
  728. * on the fly during packet processing
  729. */
  730. rx_b = rx_p = 0;
  731. tx_b = tx_p = 0;
  732. tx_restart = tx_busy = tx_linearize = tx_force_wb = 0;
  733. tx_lost_interrupt = 0;
  734. rx_page = 0;
  735. rx_buf = 0;
  736. rcu_read_lock();
  737. for (q = 0; q < vsi->num_queue_pairs; q++) {
  738. /* locate Tx ring */
  739. p = ACCESS_ONCE(vsi->tx_rings[q]);
  740. do {
  741. start = u64_stats_fetch_begin_irq(&p->syncp);
  742. packets = p->stats.packets;
  743. bytes = p->stats.bytes;
  744. } while (u64_stats_fetch_retry_irq(&p->syncp, start));
  745. tx_b += bytes;
  746. tx_p += packets;
  747. tx_restart += p->tx_stats.restart_queue;
  748. tx_busy += p->tx_stats.tx_busy;
  749. tx_linearize += p->tx_stats.tx_linearize;
  750. tx_force_wb += p->tx_stats.tx_force_wb;
  751. tx_lost_interrupt += p->tx_stats.tx_lost_interrupt;
  752. /* Rx queue is part of the same block as Tx queue */
  753. p = &p[1];
  754. do {
  755. start = u64_stats_fetch_begin_irq(&p->syncp);
  756. packets = p->stats.packets;
  757. bytes = p->stats.bytes;
  758. } while (u64_stats_fetch_retry_irq(&p->syncp, start));
  759. rx_b += bytes;
  760. rx_p += packets;
  761. rx_buf += p->rx_stats.alloc_buff_failed;
  762. rx_page += p->rx_stats.alloc_page_failed;
  763. }
  764. rcu_read_unlock();
  765. vsi->tx_restart = tx_restart;
  766. vsi->tx_busy = tx_busy;
  767. vsi->tx_linearize = tx_linearize;
  768. vsi->tx_force_wb = tx_force_wb;
  769. vsi->tx_lost_interrupt = tx_lost_interrupt;
  770. vsi->rx_page_failed = rx_page;
  771. vsi->rx_buf_failed = rx_buf;
  772. ns->rx_packets = rx_p;
  773. ns->rx_bytes = rx_b;
  774. ns->tx_packets = tx_p;
  775. ns->tx_bytes = tx_b;
  776. /* update netdev stats from eth stats */
  777. i40e_update_eth_stats(vsi);
  778. ons->tx_errors = oes->tx_errors;
  779. ns->tx_errors = es->tx_errors;
  780. ons->multicast = oes->rx_multicast;
  781. ns->multicast = es->rx_multicast;
  782. ons->rx_dropped = oes->rx_discards;
  783. ns->rx_dropped = es->rx_discards;
  784. ons->tx_dropped = oes->tx_discards;
  785. ns->tx_dropped = es->tx_discards;
  786. /* pull in a couple PF stats if this is the main vsi */
  787. if (vsi == pf->vsi[pf->lan_vsi]) {
  788. ns->rx_crc_errors = pf->stats.crc_errors;
  789. ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes;
  790. ns->rx_length_errors = pf->stats.rx_length_errors;
  791. }
  792. }
  793. /**
  794. * i40e_update_pf_stats - Update the PF statistics counters.
  795. * @pf: the PF to be updated
  796. **/
  797. static void i40e_update_pf_stats(struct i40e_pf *pf)
  798. {
  799. struct i40e_hw_port_stats *osd = &pf->stats_offsets;
  800. struct i40e_hw_port_stats *nsd = &pf->stats;
  801. struct i40e_hw *hw = &pf->hw;
  802. u32 val;
  803. int i;
  804. i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port),
  805. I40E_GLPRT_GORCL(hw->port),
  806. pf->stat_offsets_loaded,
  807. &osd->eth.rx_bytes, &nsd->eth.rx_bytes);
  808. i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port),
  809. I40E_GLPRT_GOTCL(hw->port),
  810. pf->stat_offsets_loaded,
  811. &osd->eth.tx_bytes, &nsd->eth.tx_bytes);
  812. i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port),
  813. pf->stat_offsets_loaded,
  814. &osd->eth.rx_discards,
  815. &nsd->eth.rx_discards);
  816. i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port),
  817. I40E_GLPRT_UPRCL(hw->port),
  818. pf->stat_offsets_loaded,
  819. &osd->eth.rx_unicast,
  820. &nsd->eth.rx_unicast);
  821. i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port),
  822. I40E_GLPRT_MPRCL(hw->port),
  823. pf->stat_offsets_loaded,
  824. &osd->eth.rx_multicast,
  825. &nsd->eth.rx_multicast);
  826. i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port),
  827. I40E_GLPRT_BPRCL(hw->port),
  828. pf->stat_offsets_loaded,
  829. &osd->eth.rx_broadcast,
  830. &nsd->eth.rx_broadcast);
  831. i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port),
  832. I40E_GLPRT_UPTCL(hw->port),
  833. pf->stat_offsets_loaded,
  834. &osd->eth.tx_unicast,
  835. &nsd->eth.tx_unicast);
  836. i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port),
  837. I40E_GLPRT_MPTCL(hw->port),
  838. pf->stat_offsets_loaded,
  839. &osd->eth.tx_multicast,
  840. &nsd->eth.tx_multicast);
  841. i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port),
  842. I40E_GLPRT_BPTCL(hw->port),
  843. pf->stat_offsets_loaded,
  844. &osd->eth.tx_broadcast,
  845. &nsd->eth.tx_broadcast);
  846. i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port),
  847. pf->stat_offsets_loaded,
  848. &osd->tx_dropped_link_down,
  849. &nsd->tx_dropped_link_down);
  850. i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port),
  851. pf->stat_offsets_loaded,
  852. &osd->crc_errors, &nsd->crc_errors);
  853. i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port),
  854. pf->stat_offsets_loaded,
  855. &osd->illegal_bytes, &nsd->illegal_bytes);
  856. i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port),
  857. pf->stat_offsets_loaded,
  858. &osd->mac_local_faults,
  859. &nsd->mac_local_faults);
  860. i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port),
  861. pf->stat_offsets_loaded,
  862. &osd->mac_remote_faults,
  863. &nsd->mac_remote_faults);
  864. i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port),
  865. pf->stat_offsets_loaded,
  866. &osd->rx_length_errors,
  867. &nsd->rx_length_errors);
  868. i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port),
  869. pf->stat_offsets_loaded,
  870. &osd->link_xon_rx, &nsd->link_xon_rx);
  871. i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port),
  872. pf->stat_offsets_loaded,
  873. &osd->link_xon_tx, &nsd->link_xon_tx);
  874. i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
  875. pf->stat_offsets_loaded,
  876. &osd->link_xoff_rx, &nsd->link_xoff_rx);
  877. i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
  878. pf->stat_offsets_loaded,
  879. &osd->link_xoff_tx, &nsd->link_xoff_tx);
  880. for (i = 0; i < 8; i++) {
  881. i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
  882. pf->stat_offsets_loaded,
  883. &osd->priority_xoff_rx[i],
  884. &nsd->priority_xoff_rx[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,
  973. I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(pf->hw.pf_id)),
  974. pf->stat_offsets_loaded,
  975. &osd->fd_atr_match, &nsd->fd_atr_match);
  976. i40e_stat_update32(hw,
  977. I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(pf->hw.pf_id)),
  978. pf->stat_offsets_loaded,
  979. &osd->fd_sb_match, &nsd->fd_sb_match);
  980. i40e_stat_update32(hw,
  981. I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)),
  982. pf->stat_offsets_loaded,
  983. &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match);
  984. val = rd32(hw, I40E_PRTPM_EEE_STAT);
  985. nsd->tx_lpi_status =
  986. (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >>
  987. I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT;
  988. nsd->rx_lpi_status =
  989. (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >>
  990. I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT;
  991. i40e_stat_update32(hw, I40E_PRTPM_TLPIC,
  992. pf->stat_offsets_loaded,
  993. &osd->tx_lpi_count, &nsd->tx_lpi_count);
  994. i40e_stat_update32(hw, I40E_PRTPM_RLPIC,
  995. pf->stat_offsets_loaded,
  996. &osd->rx_lpi_count, &nsd->rx_lpi_count);
  997. if (pf->flags & I40E_FLAG_FD_SB_ENABLED &&
  998. !(pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED))
  999. nsd->fd_sb_status = true;
  1000. else
  1001. nsd->fd_sb_status = false;
  1002. if (pf->flags & I40E_FLAG_FD_ATR_ENABLED &&
  1003. !(pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED))
  1004. nsd->fd_atr_status = true;
  1005. else
  1006. nsd->fd_atr_status = false;
  1007. pf->stat_offsets_loaded = true;
  1008. }
  1009. /**
  1010. * i40e_update_stats - Update the various statistics counters.
  1011. * @vsi: the VSI to be updated
  1012. *
  1013. * Update the various stats for this VSI and its related entities.
  1014. **/
  1015. void i40e_update_stats(struct i40e_vsi *vsi)
  1016. {
  1017. struct i40e_pf *pf = vsi->back;
  1018. if (vsi == pf->vsi[pf->lan_vsi])
  1019. i40e_update_pf_stats(pf);
  1020. i40e_update_vsi_stats(vsi);
  1021. #ifdef I40E_FCOE
  1022. i40e_update_fcoe_stats(vsi);
  1023. #endif
  1024. }
  1025. /**
  1026. * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
  1027. * @vsi: the VSI to be searched
  1028. * @macaddr: the MAC address
  1029. * @vlan: the vlan
  1030. *
  1031. * Returns ptr to the filter object or NULL
  1032. **/
  1033. static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi,
  1034. const u8 *macaddr, s16 vlan)
  1035. {
  1036. struct i40e_mac_filter *f;
  1037. u64 key;
  1038. if (!vsi || !macaddr)
  1039. return NULL;
  1040. key = i40e_addr_to_hkey(macaddr);
  1041. hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) {
  1042. if ((ether_addr_equal(macaddr, f->macaddr)) &&
  1043. (vlan == f->vlan))
  1044. return f;
  1045. }
  1046. return NULL;
  1047. }
  1048. /**
  1049. * i40e_find_mac - Find a mac addr in the macvlan filters list
  1050. * @vsi: the VSI to be searched
  1051. * @macaddr: the MAC address we are searching for
  1052. *
  1053. * Returns the first filter with the provided MAC address or NULL if
  1054. * MAC address was not found
  1055. **/
  1056. struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, const u8 *macaddr)
  1057. {
  1058. struct i40e_mac_filter *f;
  1059. u64 key;
  1060. if (!vsi || !macaddr)
  1061. return NULL;
  1062. key = i40e_addr_to_hkey(macaddr);
  1063. hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) {
  1064. if ((ether_addr_equal(macaddr, f->macaddr)))
  1065. return f;
  1066. }
  1067. return NULL;
  1068. }
  1069. /**
  1070. * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
  1071. * @vsi: the VSI to be searched
  1072. *
  1073. * Returns true if VSI is in vlan mode or false otherwise
  1074. **/
  1075. bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi)
  1076. {
  1077. /* If we have a PVID, always operate in VLAN mode */
  1078. if (vsi->info.pvid)
  1079. return true;
  1080. /* We need to operate in VLAN mode whenever we have any filters with
  1081. * a VLAN other than I40E_VLAN_ALL. We could check the table each
  1082. * time, incurring search cost repeatedly. However, we can notice two
  1083. * things:
  1084. *
  1085. * 1) the only place where we can gain a VLAN filter is in
  1086. * i40e_add_filter.
  1087. *
  1088. * 2) the only place where filters are actually removed is in
  1089. * i40e_sync_filters_subtask.
  1090. *
  1091. * Thus, we can simply use a boolean value, has_vlan_filters which we
  1092. * will set to true when we add a VLAN filter in i40e_add_filter. Then
  1093. * we have to perform the full search after deleting filters in
  1094. * i40e_sync_filters_subtask, but we already have to search
  1095. * filters here and can perform the check at the same time. This
  1096. * results in avoiding embedding a loop for VLAN mode inside another
  1097. * loop over all the filters, and should maintain correctness as noted
  1098. * above.
  1099. */
  1100. return vsi->has_vlan_filter;
  1101. }
  1102. /**
  1103. * i40e_correct_mac_vlan_filters - Correct non-VLAN filters if necessary
  1104. * @vsi: the VSI to configure
  1105. * @tmp_add_list: list of filters ready to be added
  1106. * @tmp_del_list: list of filters ready to be deleted
  1107. * @vlan_filters: the number of active VLAN filters
  1108. *
  1109. * Update VLAN=0 and VLAN=-1 (I40E_VLAN_ANY) filters properly so that they
  1110. * behave as expected. If we have any active VLAN filters remaining or about
  1111. * to be added then we need to update non-VLAN filters to be marked as VLAN=0
  1112. * so that they only match against untagged traffic. If we no longer have any
  1113. * active VLAN filters, we need to make all non-VLAN filters marked as VLAN=-1
  1114. * so that they match against both tagged and untagged traffic. In this way,
  1115. * we ensure that we correctly receive the desired traffic. This ensures that
  1116. * when we have an active VLAN we will receive only untagged traffic and
  1117. * traffic matching active VLANs. If we have no active VLANs then we will
  1118. * operate in non-VLAN mode and receive all traffic, tagged or untagged.
  1119. *
  1120. * Finally, in a similar fashion, this function also corrects filters when
  1121. * there is an active PVID assigned to this VSI.
  1122. *
  1123. * In case of memory allocation failure return -ENOMEM. Otherwise, return 0.
  1124. *
  1125. * This function is only expected to be called from within
  1126. * i40e_sync_vsi_filters.
  1127. *
  1128. * NOTE: This function expects to be called while under the
  1129. * mac_filter_hash_lock
  1130. */
  1131. static int i40e_correct_mac_vlan_filters(struct i40e_vsi *vsi,
  1132. struct hlist_head *tmp_add_list,
  1133. struct hlist_head *tmp_del_list,
  1134. int vlan_filters)
  1135. {
  1136. struct i40e_mac_filter *f, *add_head;
  1137. struct hlist_node *h;
  1138. int bkt, new_vlan;
  1139. /* To determine if a particular filter needs to be replaced we
  1140. * have the three following conditions:
  1141. *
  1142. * a) if we have a PVID assigned, then all filters which are
  1143. * not marked as VLAN=PVID must be replaced with filters that
  1144. * are.
  1145. * b) otherwise, if we have any active VLANS, all filters
  1146. * which are marked as VLAN=-1 must be replaced with
  1147. * filters marked as VLAN=0
  1148. * c) finally, if we do not have any active VLANS, all filters
  1149. * which are marked as VLAN=0 must be replaced with filters
  1150. * marked as VLAN=-1
  1151. */
  1152. /* Update the filters about to be added in place */
  1153. hlist_for_each_entry(f, tmp_add_list, hlist) {
  1154. if (vsi->info.pvid && f->vlan != vsi->info.pvid)
  1155. f->vlan = vsi->info.pvid;
  1156. else if (vlan_filters && f->vlan == I40E_VLAN_ANY)
  1157. f->vlan = 0;
  1158. else if (!vlan_filters && f->vlan == 0)
  1159. f->vlan = I40E_VLAN_ANY;
  1160. }
  1161. /* Update the remaining active filters */
  1162. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1163. /* Combine the checks for whether a filter needs to be changed
  1164. * and then determine the new VLAN inside the if block, in
  1165. * order to avoid duplicating code for adding the new filter
  1166. * then deleting the old filter.
  1167. */
  1168. if ((vsi->info.pvid && f->vlan != vsi->info.pvid) ||
  1169. (vlan_filters && f->vlan == I40E_VLAN_ANY) ||
  1170. (!vlan_filters && f->vlan == 0)) {
  1171. /* Determine the new vlan we will be adding */
  1172. if (vsi->info.pvid)
  1173. new_vlan = vsi->info.pvid;
  1174. else if (vlan_filters)
  1175. new_vlan = 0;
  1176. else
  1177. new_vlan = I40E_VLAN_ANY;
  1178. /* Create the new filter */
  1179. add_head = i40e_add_filter(vsi, f->macaddr, new_vlan);
  1180. if (!add_head)
  1181. return -ENOMEM;
  1182. /* Put the replacement filter into the add list */
  1183. hash_del(&add_head->hlist);
  1184. hlist_add_head(&add_head->hlist, tmp_add_list);
  1185. /* Put the original filter into the delete list */
  1186. f->state = I40E_FILTER_REMOVE;
  1187. hash_del(&f->hlist);
  1188. hlist_add_head(&f->hlist, tmp_del_list);
  1189. }
  1190. }
  1191. vsi->has_vlan_filter = !!vlan_filters;
  1192. return 0;
  1193. }
  1194. /**
  1195. * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
  1196. * @vsi: the PF Main VSI - inappropriate for any other VSI
  1197. * @macaddr: the MAC address
  1198. *
  1199. * Remove whatever filter the firmware set up so the driver can manage
  1200. * its own filtering intelligently.
  1201. **/
  1202. static void i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr)
  1203. {
  1204. struct i40e_aqc_remove_macvlan_element_data element;
  1205. struct i40e_pf *pf = vsi->back;
  1206. /* Only appropriate for the PF main VSI */
  1207. if (vsi->type != I40E_VSI_MAIN)
  1208. return;
  1209. memset(&element, 0, sizeof(element));
  1210. ether_addr_copy(element.mac_addr, macaddr);
  1211. element.vlan_tag = 0;
  1212. /* Ignore error returns, some firmware does it this way... */
  1213. element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  1214. i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
  1215. memset(&element, 0, sizeof(element));
  1216. ether_addr_copy(element.mac_addr, macaddr);
  1217. element.vlan_tag = 0;
  1218. /* ...and some firmware does it this way. */
  1219. element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
  1220. I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
  1221. i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
  1222. }
  1223. /**
  1224. * i40e_add_filter - Add a mac/vlan filter to the VSI
  1225. * @vsi: the VSI to be searched
  1226. * @macaddr: the MAC address
  1227. * @vlan: the vlan
  1228. *
  1229. * Returns ptr to the filter object or NULL when no memory available.
  1230. *
  1231. * NOTE: This function is expected to be called with mac_filter_hash_lock
  1232. * being held.
  1233. **/
  1234. struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi,
  1235. const u8 *macaddr, s16 vlan)
  1236. {
  1237. struct i40e_mac_filter *f;
  1238. u64 key;
  1239. if (!vsi || !macaddr)
  1240. return NULL;
  1241. f = i40e_find_filter(vsi, macaddr, vlan);
  1242. if (!f) {
  1243. f = kzalloc(sizeof(*f), GFP_ATOMIC);
  1244. if (!f)
  1245. return NULL;
  1246. /* Update the boolean indicating if we need to function in
  1247. * VLAN mode.
  1248. */
  1249. if (vlan >= 0)
  1250. vsi->has_vlan_filter = true;
  1251. ether_addr_copy(f->macaddr, macaddr);
  1252. f->vlan = vlan;
  1253. /* If we're in overflow promisc mode, set the state directly
  1254. * to failed, so we don't bother to try sending the filter
  1255. * to the hardware.
  1256. */
  1257. if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state))
  1258. f->state = I40E_FILTER_FAILED;
  1259. else
  1260. f->state = I40E_FILTER_NEW;
  1261. INIT_HLIST_NODE(&f->hlist);
  1262. key = i40e_addr_to_hkey(macaddr);
  1263. hash_add(vsi->mac_filter_hash, &f->hlist, key);
  1264. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1265. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1266. }
  1267. /* If we're asked to add a filter that has been marked for removal, it
  1268. * is safe to simply restore it to active state. __i40e_del_filter
  1269. * will have simply deleted any filters which were previously marked
  1270. * NEW or FAILED, so if it is currently marked REMOVE it must have
  1271. * previously been ACTIVE. Since we haven't yet run the sync filters
  1272. * task, just restore this filter to the ACTIVE state so that the
  1273. * sync task leaves it in place
  1274. */
  1275. if (f->state == I40E_FILTER_REMOVE)
  1276. f->state = I40E_FILTER_ACTIVE;
  1277. return f;
  1278. }
  1279. /**
  1280. * __i40e_del_filter - Remove a specific filter from the VSI
  1281. * @vsi: VSI to remove from
  1282. * @f: the filter to remove from the list
  1283. *
  1284. * This function should be called instead of i40e_del_filter only if you know
  1285. * the exact filter you will remove already, such as via i40e_find_filter or
  1286. * i40e_find_mac.
  1287. *
  1288. * NOTE: This function is expected to be called with mac_filter_hash_lock
  1289. * being held.
  1290. * ANOTHER NOTE: This function MUST be called from within the context of
  1291. * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
  1292. * instead of list_for_each_entry().
  1293. **/
  1294. void __i40e_del_filter(struct i40e_vsi *vsi, struct i40e_mac_filter *f)
  1295. {
  1296. if (!f)
  1297. return;
  1298. if ((f->state == I40E_FILTER_FAILED) ||
  1299. (f->state == I40E_FILTER_NEW)) {
  1300. /* this one never got added by the FW. Just remove it,
  1301. * no need to sync anything.
  1302. */
  1303. hash_del(&f->hlist);
  1304. kfree(f);
  1305. } else {
  1306. f->state = I40E_FILTER_REMOVE;
  1307. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1308. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1309. }
  1310. }
  1311. /**
  1312. * i40e_del_filter - Remove a MAC/VLAN filter from the VSI
  1313. * @vsi: the VSI to be searched
  1314. * @macaddr: the MAC address
  1315. * @vlan: the VLAN
  1316. *
  1317. * NOTE: This function is expected to be called with mac_filter_hash_lock
  1318. * being held.
  1319. * ANOTHER NOTE: This function MUST be called from within the context of
  1320. * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
  1321. * instead of list_for_each_entry().
  1322. **/
  1323. void i40e_del_filter(struct i40e_vsi *vsi, const u8 *macaddr, s16 vlan)
  1324. {
  1325. struct i40e_mac_filter *f;
  1326. if (!vsi || !macaddr)
  1327. return;
  1328. f = i40e_find_filter(vsi, macaddr, vlan);
  1329. __i40e_del_filter(vsi, f);
  1330. }
  1331. /**
  1332. * i40e_add_mac_filter - Add a MAC filter for all active VLANs
  1333. * @vsi: the VSI to be searched
  1334. * @macaddr: the mac address to be filtered
  1335. *
  1336. * If we're not in VLAN mode, just add the filter to I40E_VLAN_ANY. Otherwise,
  1337. * go through all the macvlan filters and add a macvlan filter for each
  1338. * unique vlan that already exists. If a PVID has been assigned, instead only
  1339. * add the macaddr to that VLAN.
  1340. *
  1341. * Returns last filter added on success, else NULL
  1342. **/
  1343. struct i40e_mac_filter *i40e_add_mac_filter(struct i40e_vsi *vsi,
  1344. const u8 *macaddr)
  1345. {
  1346. struct i40e_mac_filter *f, *add = NULL;
  1347. struct hlist_node *h;
  1348. int bkt;
  1349. if (vsi->info.pvid)
  1350. return i40e_add_filter(vsi, macaddr,
  1351. le16_to_cpu(vsi->info.pvid));
  1352. if (!i40e_is_vsi_in_vlan(vsi))
  1353. return i40e_add_filter(vsi, macaddr, I40E_VLAN_ANY);
  1354. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1355. if (f->state == I40E_FILTER_REMOVE)
  1356. continue;
  1357. add = i40e_add_filter(vsi, macaddr, f->vlan);
  1358. if (!add)
  1359. return NULL;
  1360. }
  1361. return add;
  1362. }
  1363. /**
  1364. * i40e_del_mac_filter - Remove a MAC filter from all VLANs
  1365. * @vsi: the VSI to be searched
  1366. * @macaddr: the mac address to be removed
  1367. *
  1368. * Removes a given MAC address from a VSI regardless of what VLAN it has been
  1369. * associated with.
  1370. *
  1371. * Returns 0 for success, or error
  1372. **/
  1373. int i40e_del_mac_filter(struct i40e_vsi *vsi, const u8 *macaddr)
  1374. {
  1375. struct i40e_mac_filter *f;
  1376. struct hlist_node *h;
  1377. bool found = false;
  1378. int bkt;
  1379. WARN(!spin_is_locked(&vsi->mac_filter_hash_lock),
  1380. "Missing mac_filter_hash_lock\n");
  1381. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1382. if (ether_addr_equal(macaddr, f->macaddr)) {
  1383. __i40e_del_filter(vsi, f);
  1384. found = true;
  1385. }
  1386. }
  1387. if (found)
  1388. return 0;
  1389. else
  1390. return -ENOENT;
  1391. }
  1392. /**
  1393. * i40e_set_mac - NDO callback to set mac address
  1394. * @netdev: network interface device structure
  1395. * @p: pointer to an address structure
  1396. *
  1397. * Returns 0 on success, negative on failure
  1398. **/
  1399. #ifdef I40E_FCOE
  1400. int i40e_set_mac(struct net_device *netdev, void *p)
  1401. #else
  1402. static int i40e_set_mac(struct net_device *netdev, void *p)
  1403. #endif
  1404. {
  1405. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1406. struct i40e_vsi *vsi = np->vsi;
  1407. struct i40e_pf *pf = vsi->back;
  1408. struct i40e_hw *hw = &pf->hw;
  1409. struct sockaddr *addr = p;
  1410. if (!is_valid_ether_addr(addr->sa_data))
  1411. return -EADDRNOTAVAIL;
  1412. if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) {
  1413. netdev_info(netdev, "already using mac address %pM\n",
  1414. addr->sa_data);
  1415. return 0;
  1416. }
  1417. if (test_bit(__I40E_DOWN, &vsi->back->state) ||
  1418. test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
  1419. return -EADDRNOTAVAIL;
  1420. if (ether_addr_equal(hw->mac.addr, addr->sa_data))
  1421. netdev_info(netdev, "returning to hw mac address %pM\n",
  1422. hw->mac.addr);
  1423. else
  1424. netdev_info(netdev, "set new mac address %pM\n", addr->sa_data);
  1425. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1426. i40e_del_mac_filter(vsi, netdev->dev_addr);
  1427. i40e_add_mac_filter(vsi, addr->sa_data);
  1428. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1429. ether_addr_copy(netdev->dev_addr, addr->sa_data);
  1430. if (vsi->type == I40E_VSI_MAIN) {
  1431. i40e_status ret;
  1432. ret = i40e_aq_mac_address_write(&vsi->back->hw,
  1433. I40E_AQC_WRITE_TYPE_LAA_WOL,
  1434. addr->sa_data, NULL);
  1435. if (ret)
  1436. netdev_info(netdev, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n",
  1437. i40e_stat_str(hw, ret),
  1438. i40e_aq_str(hw, hw->aq.asq_last_status));
  1439. }
  1440. /* schedule our worker thread which will take care of
  1441. * applying the new filter changes
  1442. */
  1443. i40e_service_event_schedule(vsi->back);
  1444. return 0;
  1445. }
  1446. /**
  1447. * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
  1448. * @vsi: the VSI being setup
  1449. * @ctxt: VSI context structure
  1450. * @enabled_tc: Enabled TCs bitmap
  1451. * @is_add: True if called before Add VSI
  1452. *
  1453. * Setup VSI queue mapping for enabled traffic classes.
  1454. **/
  1455. #ifdef I40E_FCOE
  1456. void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
  1457. struct i40e_vsi_context *ctxt,
  1458. u8 enabled_tc,
  1459. bool is_add)
  1460. #else
  1461. static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
  1462. struct i40e_vsi_context *ctxt,
  1463. u8 enabled_tc,
  1464. bool is_add)
  1465. #endif
  1466. {
  1467. struct i40e_pf *pf = vsi->back;
  1468. u16 sections = 0;
  1469. u8 netdev_tc = 0;
  1470. u16 numtc = 0;
  1471. u16 qcount;
  1472. u8 offset;
  1473. u16 qmap;
  1474. int i;
  1475. u16 num_tc_qps = 0;
  1476. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  1477. offset = 0;
  1478. if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  1479. /* Find numtc from enabled TC bitmap */
  1480. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1481. if (enabled_tc & BIT(i)) /* TC is enabled */
  1482. numtc++;
  1483. }
  1484. if (!numtc) {
  1485. dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n");
  1486. numtc = 1;
  1487. }
  1488. } else {
  1489. /* At least TC0 is enabled in case of non-DCB case */
  1490. numtc = 1;
  1491. }
  1492. vsi->tc_config.numtc = numtc;
  1493. vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
  1494. /* Number of queues per enabled TC */
  1495. qcount = vsi->alloc_queue_pairs;
  1496. num_tc_qps = qcount / numtc;
  1497. num_tc_qps = min_t(int, num_tc_qps, i40e_pf_get_max_q_per_tc(pf));
  1498. /* Setup queue offset/count for all TCs for given VSI */
  1499. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1500. /* See if the given TC is enabled for the given VSI */
  1501. if (vsi->tc_config.enabled_tc & BIT(i)) {
  1502. /* TC is enabled */
  1503. int pow, num_qps;
  1504. switch (vsi->type) {
  1505. case I40E_VSI_MAIN:
  1506. qcount = min_t(int, pf->alloc_rss_size,
  1507. num_tc_qps);
  1508. break;
  1509. #ifdef I40E_FCOE
  1510. case I40E_VSI_FCOE:
  1511. qcount = num_tc_qps;
  1512. break;
  1513. #endif
  1514. case I40E_VSI_FDIR:
  1515. case I40E_VSI_SRIOV:
  1516. case I40E_VSI_VMDQ2:
  1517. default:
  1518. qcount = num_tc_qps;
  1519. WARN_ON(i != 0);
  1520. break;
  1521. }
  1522. vsi->tc_config.tc_info[i].qoffset = offset;
  1523. vsi->tc_config.tc_info[i].qcount = qcount;
  1524. /* find the next higher power-of-2 of num queue pairs */
  1525. num_qps = qcount;
  1526. pow = 0;
  1527. while (num_qps && (BIT_ULL(pow) < qcount)) {
  1528. pow++;
  1529. num_qps >>= 1;
  1530. }
  1531. vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
  1532. qmap =
  1533. (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  1534. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  1535. offset += qcount;
  1536. } else {
  1537. /* TC is not enabled so set the offset to
  1538. * default queue and allocate one queue
  1539. * for the given TC.
  1540. */
  1541. vsi->tc_config.tc_info[i].qoffset = 0;
  1542. vsi->tc_config.tc_info[i].qcount = 1;
  1543. vsi->tc_config.tc_info[i].netdev_tc = 0;
  1544. qmap = 0;
  1545. }
  1546. ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
  1547. }
  1548. /* Set actual Tx/Rx queue pairs */
  1549. vsi->num_queue_pairs = offset;
  1550. if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) {
  1551. if (vsi->req_queue_pairs > 0)
  1552. vsi->num_queue_pairs = vsi->req_queue_pairs;
  1553. else if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  1554. vsi->num_queue_pairs = pf->num_lan_msix;
  1555. }
  1556. /* Scheduler section valid can only be set for ADD VSI */
  1557. if (is_add) {
  1558. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  1559. ctxt->info.up_enable_bits = enabled_tc;
  1560. }
  1561. if (vsi->type == I40E_VSI_SRIOV) {
  1562. ctxt->info.mapping_flags |=
  1563. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
  1564. for (i = 0; i < vsi->num_queue_pairs; i++)
  1565. ctxt->info.queue_mapping[i] =
  1566. cpu_to_le16(vsi->base_queue + i);
  1567. } else {
  1568. ctxt->info.mapping_flags |=
  1569. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  1570. ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
  1571. }
  1572. ctxt->info.valid_sections |= cpu_to_le16(sections);
  1573. }
  1574. /**
  1575. * i40e_addr_sync - Callback for dev_(mc|uc)_sync to add address
  1576. * @netdev: the netdevice
  1577. * @addr: address to add
  1578. *
  1579. * Called by __dev_(mc|uc)_sync when an address needs to be added. We call
  1580. * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
  1581. */
  1582. static int i40e_addr_sync(struct net_device *netdev, const u8 *addr)
  1583. {
  1584. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1585. struct i40e_vsi *vsi = np->vsi;
  1586. if (i40e_add_mac_filter(vsi, addr))
  1587. return 0;
  1588. else
  1589. return -ENOMEM;
  1590. }
  1591. /**
  1592. * i40e_addr_unsync - Callback for dev_(mc|uc)_sync to remove address
  1593. * @netdev: the netdevice
  1594. * @addr: address to add
  1595. *
  1596. * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call
  1597. * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
  1598. */
  1599. static int i40e_addr_unsync(struct net_device *netdev, const u8 *addr)
  1600. {
  1601. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1602. struct i40e_vsi *vsi = np->vsi;
  1603. i40e_del_mac_filter(vsi, addr);
  1604. return 0;
  1605. }
  1606. /**
  1607. * i40e_set_rx_mode - NDO callback to set the netdev filters
  1608. * @netdev: network interface device structure
  1609. **/
  1610. #ifdef I40E_FCOE
  1611. void i40e_set_rx_mode(struct net_device *netdev)
  1612. #else
  1613. static void i40e_set_rx_mode(struct net_device *netdev)
  1614. #endif
  1615. {
  1616. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1617. struct i40e_vsi *vsi = np->vsi;
  1618. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1619. __dev_uc_sync(netdev, i40e_addr_sync, i40e_addr_unsync);
  1620. __dev_mc_sync(netdev, i40e_addr_sync, i40e_addr_unsync);
  1621. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1622. /* check for other flag changes */
  1623. if (vsi->current_netdev_flags != vsi->netdev->flags) {
  1624. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1625. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1626. }
  1627. /* schedule our worker thread which will take care of
  1628. * applying the new filter changes
  1629. */
  1630. i40e_service_event_schedule(vsi->back);
  1631. }
  1632. /**
  1633. * i40e_undo_filter_entries - Undo the changes made to MAC filter entries
  1634. * @vsi: Pointer to VSI struct
  1635. * @from: Pointer to list which contains MAC filter entries - changes to
  1636. * those entries needs to be undone.
  1637. *
  1638. * MAC filter entries from list were slated to be sent to firmware, either for
  1639. * addition or deletion.
  1640. **/
  1641. static void i40e_undo_filter_entries(struct i40e_vsi *vsi,
  1642. struct hlist_head *from)
  1643. {
  1644. struct i40e_mac_filter *f;
  1645. struct hlist_node *h;
  1646. hlist_for_each_entry_safe(f, h, from, hlist) {
  1647. u64 key = i40e_addr_to_hkey(f->macaddr);
  1648. /* Move the element back into MAC filter list*/
  1649. hlist_del(&f->hlist);
  1650. hash_add(vsi->mac_filter_hash, &f->hlist, key);
  1651. }
  1652. }
  1653. /**
  1654. * i40e_update_filter_state - Update filter state based on return data
  1655. * from firmware
  1656. * @count: Number of filters added
  1657. * @add_list: return data from fw
  1658. * @head: pointer to first filter in current batch
  1659. *
  1660. * MAC filter entries from list were slated to be added to device. Returns
  1661. * number of successful filters. Note that 0 does NOT mean success!
  1662. **/
  1663. static int
  1664. i40e_update_filter_state(int count,
  1665. struct i40e_aqc_add_macvlan_element_data *add_list,
  1666. struct i40e_mac_filter *add_head)
  1667. {
  1668. int retval = 0;
  1669. int i;
  1670. for (i = 0; i < count; i++) {
  1671. /* Always check status of each filter. We don't need to check
  1672. * the firmware return status because we pre-set the filter
  1673. * status to I40E_AQC_MM_ERR_NO_RES when sending the filter
  1674. * request to the adminq. Thus, if it no longer matches then
  1675. * we know the filter is active.
  1676. */
  1677. if (add_list[i].match_method == I40E_AQC_MM_ERR_NO_RES) {
  1678. add_head->state = I40E_FILTER_FAILED;
  1679. } else {
  1680. add_head->state = I40E_FILTER_ACTIVE;
  1681. retval++;
  1682. }
  1683. add_head = hlist_entry(add_head->hlist.next,
  1684. typeof(struct i40e_mac_filter),
  1685. hlist);
  1686. }
  1687. return retval;
  1688. }
  1689. /**
  1690. * i40e_aqc_del_filters - Request firmware to delete a set of filters
  1691. * @vsi: ptr to the VSI
  1692. * @vsi_name: name to display in messages
  1693. * @list: the list of filters to send to firmware
  1694. * @num_del: the number of filters to delete
  1695. * @retval: Set to -EIO on failure to delete
  1696. *
  1697. * Send a request to firmware via AdminQ to delete a set of filters. Uses
  1698. * *retval instead of a return value so that success does not force ret_val to
  1699. * be set to 0. This ensures that a sequence of calls to this function
  1700. * preserve the previous value of *retval on successful delete.
  1701. */
  1702. static
  1703. void i40e_aqc_del_filters(struct i40e_vsi *vsi, const char *vsi_name,
  1704. struct i40e_aqc_remove_macvlan_element_data *list,
  1705. int num_del, int *retval)
  1706. {
  1707. struct i40e_hw *hw = &vsi->back->hw;
  1708. i40e_status aq_ret;
  1709. int aq_err;
  1710. aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, list, num_del, NULL);
  1711. aq_err = hw->aq.asq_last_status;
  1712. /* Explicitly ignore and do not report when firmware returns ENOENT */
  1713. if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) {
  1714. *retval = -EIO;
  1715. dev_info(&vsi->back->pdev->dev,
  1716. "ignoring delete macvlan error on %s, err %s, aq_err %s\n",
  1717. vsi_name, i40e_stat_str(hw, aq_ret),
  1718. i40e_aq_str(hw, aq_err));
  1719. }
  1720. }
  1721. /**
  1722. * i40e_aqc_add_filters - Request firmware to add a set of filters
  1723. * @vsi: ptr to the VSI
  1724. * @vsi_name: name to display in messages
  1725. * @list: the list of filters to send to firmware
  1726. * @add_head: Position in the add hlist
  1727. * @num_add: the number of filters to add
  1728. * @promisc_change: set to true on exit if promiscuous mode was forced on
  1729. *
  1730. * Send a request to firmware via AdminQ to add a chunk of filters. Will set
  1731. * promisc_changed to true if the firmware has run out of space for more
  1732. * filters.
  1733. */
  1734. static
  1735. void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name,
  1736. struct i40e_aqc_add_macvlan_element_data *list,
  1737. struct i40e_mac_filter *add_head,
  1738. int num_add, bool *promisc_changed)
  1739. {
  1740. struct i40e_hw *hw = &vsi->back->hw;
  1741. int aq_err, fcnt;
  1742. i40e_aq_add_macvlan(hw, vsi->seid, list, num_add, NULL);
  1743. aq_err = hw->aq.asq_last_status;
  1744. fcnt = i40e_update_filter_state(num_add, list, add_head);
  1745. if (fcnt != num_add) {
  1746. *promisc_changed = true;
  1747. set_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state);
  1748. dev_warn(&vsi->back->pdev->dev,
  1749. "Error %s adding RX filters on %s, promiscuous mode forced on\n",
  1750. i40e_aq_str(hw, aq_err),
  1751. vsi_name);
  1752. }
  1753. }
  1754. /**
  1755. * i40e_aqc_broadcast_filter - Set promiscuous broadcast flags
  1756. * @vsi: pointer to the VSI
  1757. * @f: filter data
  1758. *
  1759. * This function sets or clears the promiscuous broadcast flags for VLAN
  1760. * filters in order to properly receive broadcast frames. Assumes that only
  1761. * broadcast filters are passed.
  1762. **/
  1763. static
  1764. void i40e_aqc_broadcast_filter(struct i40e_vsi *vsi, const char *vsi_name,
  1765. struct i40e_mac_filter *f)
  1766. {
  1767. bool enable = f->state == I40E_FILTER_NEW;
  1768. struct i40e_hw *hw = &vsi->back->hw;
  1769. i40e_status aq_ret;
  1770. if (f->vlan == I40E_VLAN_ANY) {
  1771. aq_ret = i40e_aq_set_vsi_broadcast(hw,
  1772. vsi->seid,
  1773. enable,
  1774. NULL);
  1775. } else {
  1776. aq_ret = i40e_aq_set_vsi_bc_promisc_on_vlan(hw,
  1777. vsi->seid,
  1778. enable,
  1779. f->vlan,
  1780. NULL);
  1781. }
  1782. if (aq_ret) {
  1783. dev_warn(&vsi->back->pdev->dev,
  1784. "Error %s setting broadcast promiscuous mode on %s\n",
  1785. i40e_aq_str(hw, hw->aq.asq_last_status),
  1786. vsi_name);
  1787. f->state = I40E_FILTER_FAILED;
  1788. } else if (enable) {
  1789. f->state = I40E_FILTER_ACTIVE;
  1790. }
  1791. }
  1792. /**
  1793. * i40e_sync_vsi_filters - Update the VSI filter list to the HW
  1794. * @vsi: ptr to the VSI
  1795. *
  1796. * Push any outstanding VSI filter changes through the AdminQ.
  1797. *
  1798. * Returns 0 or error value
  1799. **/
  1800. int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
  1801. {
  1802. struct hlist_head tmp_add_list, tmp_del_list;
  1803. struct i40e_mac_filter *f, *add_head = NULL;
  1804. struct i40e_hw *hw = &vsi->back->hw;
  1805. unsigned int failed_filters = 0;
  1806. unsigned int vlan_filters = 0;
  1807. bool promisc_changed = false;
  1808. char vsi_name[16] = "PF";
  1809. int filter_list_len = 0;
  1810. i40e_status aq_ret = 0;
  1811. u32 changed_flags = 0;
  1812. struct hlist_node *h;
  1813. struct i40e_pf *pf;
  1814. int num_add = 0;
  1815. int num_del = 0;
  1816. int retval = 0;
  1817. u16 cmd_flags;
  1818. int list_size;
  1819. int bkt;
  1820. /* empty array typed pointers, kcalloc later */
  1821. struct i40e_aqc_add_macvlan_element_data *add_list;
  1822. struct i40e_aqc_remove_macvlan_element_data *del_list;
  1823. while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state))
  1824. usleep_range(1000, 2000);
  1825. pf = vsi->back;
  1826. if (vsi->netdev) {
  1827. changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
  1828. vsi->current_netdev_flags = vsi->netdev->flags;
  1829. }
  1830. INIT_HLIST_HEAD(&tmp_add_list);
  1831. INIT_HLIST_HEAD(&tmp_del_list);
  1832. if (vsi->type == I40E_VSI_SRIOV)
  1833. snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id);
  1834. else if (vsi->type != I40E_VSI_MAIN)
  1835. snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid);
  1836. if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
  1837. vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
  1838. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1839. /* Create a list of filters to delete. */
  1840. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1841. if (f->state == I40E_FILTER_REMOVE) {
  1842. /* Move the element into temporary del_list */
  1843. hash_del(&f->hlist);
  1844. hlist_add_head(&f->hlist, &tmp_del_list);
  1845. /* Avoid counting removed filters */
  1846. continue;
  1847. }
  1848. if (f->state == I40E_FILTER_NEW) {
  1849. hash_del(&f->hlist);
  1850. hlist_add_head(&f->hlist, &tmp_add_list);
  1851. }
  1852. /* Count the number of active (current and new) VLAN
  1853. * filters we have now. Does not count filters which
  1854. * are marked for deletion.
  1855. */
  1856. if (f->vlan > 0)
  1857. vlan_filters++;
  1858. }
  1859. retval = i40e_correct_mac_vlan_filters(vsi,
  1860. &tmp_add_list,
  1861. &tmp_del_list,
  1862. vlan_filters);
  1863. if (retval)
  1864. goto err_no_memory_locked;
  1865. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1866. }
  1867. /* Now process 'del_list' outside the lock */
  1868. if (!hlist_empty(&tmp_del_list)) {
  1869. filter_list_len = hw->aq.asq_buf_size /
  1870. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  1871. list_size = filter_list_len *
  1872. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  1873. del_list = kzalloc(list_size, GFP_ATOMIC);
  1874. if (!del_list)
  1875. goto err_no_memory;
  1876. hlist_for_each_entry_safe(f, h, &tmp_del_list, hlist) {
  1877. cmd_flags = 0;
  1878. /* handle broadcast filters by updating the broadcast
  1879. * promiscuous flag instead of deleting a MAC filter.
  1880. */
  1881. if (is_broadcast_ether_addr(f->macaddr)) {
  1882. i40e_aqc_broadcast_filter(vsi, vsi_name, f);
  1883. hlist_del(&f->hlist);
  1884. kfree(f);
  1885. continue;
  1886. }
  1887. /* add to delete list */
  1888. ether_addr_copy(del_list[num_del].mac_addr, f->macaddr);
  1889. if (f->vlan == I40E_VLAN_ANY) {
  1890. del_list[num_del].vlan_tag = 0;
  1891. cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
  1892. } else {
  1893. del_list[num_del].vlan_tag =
  1894. cpu_to_le16((u16)(f->vlan));
  1895. }
  1896. cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  1897. del_list[num_del].flags = cmd_flags;
  1898. num_del++;
  1899. /* flush a full buffer */
  1900. if (num_del == filter_list_len) {
  1901. i40e_aqc_del_filters(vsi, vsi_name, del_list,
  1902. num_del, &retval);
  1903. memset(del_list, 0, list_size);
  1904. num_del = 0;
  1905. }
  1906. /* Release memory for MAC filter entries which were
  1907. * synced up with HW.
  1908. */
  1909. hlist_del(&f->hlist);
  1910. kfree(f);
  1911. }
  1912. if (num_del) {
  1913. i40e_aqc_del_filters(vsi, vsi_name, del_list,
  1914. num_del, &retval);
  1915. }
  1916. kfree(del_list);
  1917. del_list = NULL;
  1918. }
  1919. if (!hlist_empty(&tmp_add_list)) {
  1920. /* Do all the adds now. */
  1921. filter_list_len = hw->aq.asq_buf_size /
  1922. sizeof(struct i40e_aqc_add_macvlan_element_data);
  1923. list_size = filter_list_len *
  1924. sizeof(struct i40e_aqc_add_macvlan_element_data);
  1925. add_list = kzalloc(list_size, GFP_ATOMIC);
  1926. if (!add_list)
  1927. goto err_no_memory;
  1928. num_add = 0;
  1929. hlist_for_each_entry_safe(f, h, &tmp_add_list, hlist) {
  1930. if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  1931. &vsi->state)) {
  1932. f->state = I40E_FILTER_FAILED;
  1933. continue;
  1934. }
  1935. /* handle broadcast filters by updating the broadcast
  1936. * promiscuous flag instead of adding a MAC filter.
  1937. */
  1938. if (is_broadcast_ether_addr(f->macaddr)) {
  1939. u64 key = i40e_addr_to_hkey(f->macaddr);
  1940. i40e_aqc_broadcast_filter(vsi, vsi_name, f);
  1941. hlist_del(&f->hlist);
  1942. hash_add(vsi->mac_filter_hash, &f->hlist, key);
  1943. continue;
  1944. }
  1945. /* add to add array */
  1946. if (num_add == 0)
  1947. add_head = f;
  1948. cmd_flags = 0;
  1949. ether_addr_copy(add_list[num_add].mac_addr, f->macaddr);
  1950. if (f->vlan == I40E_VLAN_ANY) {
  1951. add_list[num_add].vlan_tag = 0;
  1952. cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
  1953. } else {
  1954. add_list[num_add].vlan_tag =
  1955. cpu_to_le16((u16)(f->vlan));
  1956. }
  1957. add_list[num_add].queue_number = 0;
  1958. /* set invalid match method for later detection */
  1959. add_list[num_add].match_method = I40E_AQC_MM_ERR_NO_RES;
  1960. cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
  1961. add_list[num_add].flags = cpu_to_le16(cmd_flags);
  1962. num_add++;
  1963. /* flush a full buffer */
  1964. if (num_add == filter_list_len) {
  1965. i40e_aqc_add_filters(vsi, vsi_name, add_list,
  1966. add_head, num_add,
  1967. &promisc_changed);
  1968. memset(add_list, 0, list_size);
  1969. num_add = 0;
  1970. }
  1971. }
  1972. if (num_add) {
  1973. i40e_aqc_add_filters(vsi, vsi_name, add_list, add_head,
  1974. num_add, &promisc_changed);
  1975. }
  1976. /* Now move all of the filters from the temp add list back to
  1977. * the VSI's list.
  1978. */
  1979. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1980. hlist_for_each_entry_safe(f, h, &tmp_add_list, hlist) {
  1981. u64 key = i40e_addr_to_hkey(f->macaddr);
  1982. hlist_del(&f->hlist);
  1983. hash_add(vsi->mac_filter_hash, &f->hlist, key);
  1984. }
  1985. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1986. kfree(add_list);
  1987. add_list = NULL;
  1988. }
  1989. /* Determine the number of active and failed filters. */
  1990. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1991. vsi->active_filters = 0;
  1992. hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
  1993. if (f->state == I40E_FILTER_ACTIVE)
  1994. vsi->active_filters++;
  1995. else if (f->state == I40E_FILTER_FAILED)
  1996. failed_filters++;
  1997. }
  1998. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1999. /* If promiscuous mode has changed, we need to calculate a new
  2000. * threshold for when we are safe to exit
  2001. */
  2002. if (promisc_changed)
  2003. vsi->promisc_threshold = (vsi->active_filters * 3) / 4;
  2004. /* Check if we are able to exit overflow promiscuous mode. We can
  2005. * safely exit if we didn't just enter, we no longer have any failed
  2006. * filters, and we have reduced filters below the threshold value.
  2007. */
  2008. if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state) &&
  2009. !promisc_changed && !failed_filters &&
  2010. (vsi->active_filters < vsi->promisc_threshold)) {
  2011. dev_info(&pf->pdev->dev,
  2012. "filter logjam cleared on %s, leaving overflow promiscuous mode\n",
  2013. vsi_name);
  2014. clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state);
  2015. promisc_changed = true;
  2016. vsi->promisc_threshold = 0;
  2017. }
  2018. /* if the VF is not trusted do not do promisc */
  2019. if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) {
  2020. clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state);
  2021. goto out;
  2022. }
  2023. /* check for changes in promiscuous modes */
  2024. if (changed_flags & IFF_ALLMULTI) {
  2025. bool cur_multipromisc;
  2026. cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
  2027. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
  2028. vsi->seid,
  2029. cur_multipromisc,
  2030. NULL);
  2031. if (aq_ret) {
  2032. retval = i40e_aq_rc_to_posix(aq_ret,
  2033. hw->aq.asq_last_status);
  2034. dev_info(&pf->pdev->dev,
  2035. "set multi promisc failed on %s, err %s aq_err %s\n",
  2036. vsi_name,
  2037. i40e_stat_str(hw, aq_ret),
  2038. i40e_aq_str(hw, hw->aq.asq_last_status));
  2039. }
  2040. }
  2041. if ((changed_flags & IFF_PROMISC) ||
  2042. (promisc_changed &&
  2043. test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state))) {
  2044. bool cur_promisc;
  2045. cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
  2046. test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  2047. &vsi->state));
  2048. if ((vsi->type == I40E_VSI_MAIN) &&
  2049. (pf->lan_veb != I40E_NO_VEB) &&
  2050. !(pf->flags & I40E_FLAG_MFP_ENABLED)) {
  2051. /* set defport ON for Main VSI instead of true promisc
  2052. * this way we will get all unicast/multicast and VLAN
  2053. * promisc behavior but will not get VF or VMDq traffic
  2054. * replicated on the Main VSI.
  2055. */
  2056. if (pf->cur_promisc != cur_promisc) {
  2057. pf->cur_promisc = cur_promisc;
  2058. if (cur_promisc)
  2059. aq_ret =
  2060. i40e_aq_set_default_vsi(hw,
  2061. vsi->seid,
  2062. NULL);
  2063. else
  2064. aq_ret =
  2065. i40e_aq_clear_default_vsi(hw,
  2066. vsi->seid,
  2067. NULL);
  2068. if (aq_ret) {
  2069. retval = i40e_aq_rc_to_posix(aq_ret,
  2070. hw->aq.asq_last_status);
  2071. dev_info(&pf->pdev->dev,
  2072. "Set default VSI failed on %s, err %s, aq_err %s\n",
  2073. vsi_name,
  2074. i40e_stat_str(hw, aq_ret),
  2075. i40e_aq_str(hw,
  2076. hw->aq.asq_last_status));
  2077. }
  2078. }
  2079. } else {
  2080. aq_ret = i40e_aq_set_vsi_unicast_promiscuous(
  2081. hw,
  2082. vsi->seid,
  2083. cur_promisc, NULL,
  2084. true);
  2085. if (aq_ret) {
  2086. retval =
  2087. i40e_aq_rc_to_posix(aq_ret,
  2088. hw->aq.asq_last_status);
  2089. dev_info(&pf->pdev->dev,
  2090. "set unicast promisc failed on %s, err %s, aq_err %s\n",
  2091. vsi_name,
  2092. i40e_stat_str(hw, aq_ret),
  2093. i40e_aq_str(hw,
  2094. hw->aq.asq_last_status));
  2095. }
  2096. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(
  2097. hw,
  2098. vsi->seid,
  2099. cur_promisc, NULL);
  2100. if (aq_ret) {
  2101. retval =
  2102. i40e_aq_rc_to_posix(aq_ret,
  2103. hw->aq.asq_last_status);
  2104. dev_info(&pf->pdev->dev,
  2105. "set multicast promisc failed on %s, err %s, aq_err %s\n",
  2106. vsi_name,
  2107. i40e_stat_str(hw, aq_ret),
  2108. i40e_aq_str(hw,
  2109. hw->aq.asq_last_status));
  2110. }
  2111. }
  2112. aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw,
  2113. vsi->seid,
  2114. cur_promisc, NULL);
  2115. if (aq_ret) {
  2116. retval = i40e_aq_rc_to_posix(aq_ret,
  2117. pf->hw.aq.asq_last_status);
  2118. dev_info(&pf->pdev->dev,
  2119. "set brdcast promisc failed, err %s, aq_err %s\n",
  2120. i40e_stat_str(hw, aq_ret),
  2121. i40e_aq_str(hw,
  2122. hw->aq.asq_last_status));
  2123. }
  2124. }
  2125. out:
  2126. /* if something went wrong then set the changed flag so we try again */
  2127. if (retval)
  2128. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  2129. clear_bit(__I40E_CONFIG_BUSY, &vsi->state);
  2130. return retval;
  2131. err_no_memory:
  2132. /* Restore elements on the temporary add and delete lists */
  2133. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2134. err_no_memory_locked:
  2135. i40e_undo_filter_entries(vsi, &tmp_del_list);
  2136. i40e_undo_filter_entries(vsi, &tmp_add_list);
  2137. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2138. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  2139. clear_bit(__I40E_CONFIG_BUSY, &vsi->state);
  2140. return -ENOMEM;
  2141. }
  2142. /**
  2143. * i40e_sync_filters_subtask - Sync the VSI filter list with HW
  2144. * @pf: board private structure
  2145. **/
  2146. static void i40e_sync_filters_subtask(struct i40e_pf *pf)
  2147. {
  2148. int v;
  2149. if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC))
  2150. return;
  2151. pf->flags &= ~I40E_FLAG_FILTER_SYNC;
  2152. for (v = 0; v < pf->num_alloc_vsi; v++) {
  2153. if (pf->vsi[v] &&
  2154. (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) {
  2155. int ret = i40e_sync_vsi_filters(pf->vsi[v]);
  2156. if (ret) {
  2157. /* come back and try again later */
  2158. pf->flags |= I40E_FLAG_FILTER_SYNC;
  2159. break;
  2160. }
  2161. }
  2162. }
  2163. }
  2164. /**
  2165. * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
  2166. * @netdev: network interface device structure
  2167. * @new_mtu: new value for maximum frame size
  2168. *
  2169. * Returns 0 on success, negative on failure
  2170. **/
  2171. static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
  2172. {
  2173. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2174. struct i40e_vsi *vsi = np->vsi;
  2175. netdev_info(netdev, "changing MTU from %d to %d\n",
  2176. netdev->mtu, new_mtu);
  2177. netdev->mtu = new_mtu;
  2178. if (netif_running(netdev))
  2179. i40e_vsi_reinit_locked(vsi);
  2180. i40e_notify_client_of_l2_param_changes(vsi);
  2181. return 0;
  2182. }
  2183. /**
  2184. * i40e_ioctl - Access the hwtstamp interface
  2185. * @netdev: network interface device structure
  2186. * @ifr: interface request data
  2187. * @cmd: ioctl command
  2188. **/
  2189. int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  2190. {
  2191. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2192. struct i40e_pf *pf = np->vsi->back;
  2193. switch (cmd) {
  2194. case SIOCGHWTSTAMP:
  2195. return i40e_ptp_get_ts_config(pf, ifr);
  2196. case SIOCSHWTSTAMP:
  2197. return i40e_ptp_set_ts_config(pf, ifr);
  2198. default:
  2199. return -EOPNOTSUPP;
  2200. }
  2201. }
  2202. /**
  2203. * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
  2204. * @vsi: the vsi being adjusted
  2205. **/
  2206. void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
  2207. {
  2208. struct i40e_vsi_context ctxt;
  2209. i40e_status ret;
  2210. if ((vsi->info.valid_sections &
  2211. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  2212. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
  2213. return; /* already enabled */
  2214. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2215. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  2216. I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
  2217. ctxt.seid = vsi->seid;
  2218. ctxt.info = vsi->info;
  2219. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2220. if (ret) {
  2221. dev_info(&vsi->back->pdev->dev,
  2222. "update vlan stripping failed, err %s aq_err %s\n",
  2223. i40e_stat_str(&vsi->back->hw, ret),
  2224. i40e_aq_str(&vsi->back->hw,
  2225. vsi->back->hw.aq.asq_last_status));
  2226. }
  2227. }
  2228. /**
  2229. * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
  2230. * @vsi: the vsi being adjusted
  2231. **/
  2232. void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
  2233. {
  2234. struct i40e_vsi_context ctxt;
  2235. i40e_status ret;
  2236. if ((vsi->info.valid_sections &
  2237. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  2238. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
  2239. I40E_AQ_VSI_PVLAN_EMOD_MASK))
  2240. return; /* already disabled */
  2241. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2242. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  2243. I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
  2244. ctxt.seid = vsi->seid;
  2245. ctxt.info = vsi->info;
  2246. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2247. if (ret) {
  2248. dev_info(&vsi->back->pdev->dev,
  2249. "update vlan stripping failed, err %s aq_err %s\n",
  2250. i40e_stat_str(&vsi->back->hw, ret),
  2251. i40e_aq_str(&vsi->back->hw,
  2252. vsi->back->hw.aq.asq_last_status));
  2253. }
  2254. }
  2255. /**
  2256. * i40e_vlan_rx_register - Setup or shutdown vlan offload
  2257. * @netdev: network interface to be adjusted
  2258. * @features: netdev features to test if VLAN offload is enabled or not
  2259. **/
  2260. static void i40e_vlan_rx_register(struct net_device *netdev, u32 features)
  2261. {
  2262. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2263. struct i40e_vsi *vsi = np->vsi;
  2264. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  2265. i40e_vlan_stripping_enable(vsi);
  2266. else
  2267. i40e_vlan_stripping_disable(vsi);
  2268. }
  2269. /**
  2270. * i40e_add_vlan_all_mac - Add a MAC/VLAN filter for each existing MAC address
  2271. * @vsi: the vsi being configured
  2272. * @vid: vlan id to be added (0 = untagged only , -1 = any)
  2273. *
  2274. * This is a helper function for adding a new MAC/VLAN filter with the
  2275. * specified VLAN for each existing MAC address already in the hash table.
  2276. * This function does *not* perform any accounting to update filters based on
  2277. * VLAN mode.
  2278. *
  2279. * NOTE: this function expects to be called while under the
  2280. * mac_filter_hash_lock
  2281. **/
  2282. int i40e_add_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
  2283. {
  2284. struct i40e_mac_filter *f, *add_f;
  2285. struct hlist_node *h;
  2286. int bkt;
  2287. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  2288. if (f->state == I40E_FILTER_REMOVE)
  2289. continue;
  2290. add_f = i40e_add_filter(vsi, f->macaddr, vid);
  2291. if (!add_f) {
  2292. dev_info(&vsi->back->pdev->dev,
  2293. "Could not add vlan filter %d for %pM\n",
  2294. vid, f->macaddr);
  2295. return -ENOMEM;
  2296. }
  2297. }
  2298. return 0;
  2299. }
  2300. /**
  2301. * i40e_vsi_add_vlan - Add VSI membership for given VLAN
  2302. * @vsi: the VSI being configured
  2303. * @vid: VLAN id to be added
  2304. **/
  2305. int i40e_vsi_add_vlan(struct i40e_vsi *vsi, u16 vid)
  2306. {
  2307. int err;
  2308. if (!vid || vsi->info.pvid)
  2309. return -EINVAL;
  2310. /* Locked once because all functions invoked below iterates list*/
  2311. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2312. err = i40e_add_vlan_all_mac(vsi, vid);
  2313. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2314. if (err)
  2315. return err;
  2316. /* schedule our worker thread which will take care of
  2317. * applying the new filter changes
  2318. */
  2319. i40e_service_event_schedule(vsi->back);
  2320. return 0;
  2321. }
  2322. /**
  2323. * i40e_rm_vlan_all_mac - Remove MAC/VLAN pair for all MAC with the given VLAN
  2324. * @vsi: the vsi being configured
  2325. * @vid: vlan id to be removed (0 = untagged only , -1 = any)
  2326. *
  2327. * This function should be used to remove all VLAN filters which match the
  2328. * given VID. It does not schedule the service event and does not take the
  2329. * mac_filter_hash_lock so it may be combined with other operations under
  2330. * a single invocation of the mac_filter_hash_lock.
  2331. *
  2332. * NOTE: this function expects to be called while under the
  2333. * mac_filter_hash_lock
  2334. */
  2335. void i40e_rm_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
  2336. {
  2337. struct i40e_mac_filter *f;
  2338. struct hlist_node *h;
  2339. int bkt;
  2340. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  2341. if (f->vlan == vid)
  2342. __i40e_del_filter(vsi, f);
  2343. }
  2344. }
  2345. /**
  2346. * i40e_vsi_kill_vlan - Remove VSI membership for given VLAN
  2347. * @vsi: the VSI being configured
  2348. * @vid: VLAN id to be removed
  2349. **/
  2350. void i40e_vsi_kill_vlan(struct i40e_vsi *vsi, u16 vid)
  2351. {
  2352. if (!vid || vsi->info.pvid)
  2353. return;
  2354. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2355. i40e_rm_vlan_all_mac(vsi, vid);
  2356. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2357. /* schedule our worker thread which will take care of
  2358. * applying the new filter changes
  2359. */
  2360. i40e_service_event_schedule(vsi->back);
  2361. }
  2362. /**
  2363. * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
  2364. * @netdev: network interface to be adjusted
  2365. * @vid: vlan id to be added
  2366. *
  2367. * net_device_ops implementation for adding vlan ids
  2368. **/
  2369. #ifdef I40E_FCOE
  2370. int i40e_vlan_rx_add_vid(struct net_device *netdev,
  2371. __always_unused __be16 proto, u16 vid)
  2372. #else
  2373. static int i40e_vlan_rx_add_vid(struct net_device *netdev,
  2374. __always_unused __be16 proto, u16 vid)
  2375. #endif
  2376. {
  2377. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2378. struct i40e_vsi *vsi = np->vsi;
  2379. int ret = 0;
  2380. if (vid >= VLAN_N_VID)
  2381. return -EINVAL;
  2382. /* If the network stack called us with vid = 0 then
  2383. * it is asking to receive priority tagged packets with
  2384. * vlan id 0. Our HW receives them by default when configured
  2385. * to receive untagged packets so there is no need to add an
  2386. * extra filter for vlan 0 tagged packets.
  2387. */
  2388. if (vid)
  2389. ret = i40e_vsi_add_vlan(vsi, vid);
  2390. if (!ret)
  2391. set_bit(vid, vsi->active_vlans);
  2392. return ret;
  2393. }
  2394. /**
  2395. * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
  2396. * @netdev: network interface to be adjusted
  2397. * @vid: vlan id to be removed
  2398. *
  2399. * net_device_ops implementation for removing vlan ids
  2400. **/
  2401. #ifdef I40E_FCOE
  2402. int i40e_vlan_rx_kill_vid(struct net_device *netdev,
  2403. __always_unused __be16 proto, u16 vid)
  2404. #else
  2405. static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
  2406. __always_unused __be16 proto, u16 vid)
  2407. #endif
  2408. {
  2409. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2410. struct i40e_vsi *vsi = np->vsi;
  2411. /* return code is ignored as there is nothing a user
  2412. * can do about failure to remove and a log message was
  2413. * already printed from the other function
  2414. */
  2415. i40e_vsi_kill_vlan(vsi, vid);
  2416. clear_bit(vid, vsi->active_vlans);
  2417. return 0;
  2418. }
  2419. /**
  2420. * i40e_macaddr_init - explicitly write the mac address filters
  2421. *
  2422. * @vsi: pointer to the vsi
  2423. * @macaddr: the MAC address
  2424. *
  2425. * This is needed when the macaddr has been obtained by other
  2426. * means than the default, e.g., from Open Firmware or IDPROM.
  2427. * Returns 0 on success, negative on failure
  2428. **/
  2429. static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr)
  2430. {
  2431. int ret;
  2432. struct i40e_aqc_add_macvlan_element_data element;
  2433. ret = i40e_aq_mac_address_write(&vsi->back->hw,
  2434. I40E_AQC_WRITE_TYPE_LAA_WOL,
  2435. macaddr, NULL);
  2436. if (ret) {
  2437. dev_info(&vsi->back->pdev->dev,
  2438. "Addr change for VSI failed: %d\n", ret);
  2439. return -EADDRNOTAVAIL;
  2440. }
  2441. memset(&element, 0, sizeof(element));
  2442. ether_addr_copy(element.mac_addr, macaddr);
  2443. element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH);
  2444. ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL);
  2445. if (ret) {
  2446. dev_info(&vsi->back->pdev->dev,
  2447. "add filter failed err %s aq_err %s\n",
  2448. i40e_stat_str(&vsi->back->hw, ret),
  2449. i40e_aq_str(&vsi->back->hw,
  2450. vsi->back->hw.aq.asq_last_status));
  2451. }
  2452. return ret;
  2453. }
  2454. /**
  2455. * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
  2456. * @vsi: the vsi being brought back up
  2457. **/
  2458. static void i40e_restore_vlan(struct i40e_vsi *vsi)
  2459. {
  2460. u16 vid;
  2461. if (!vsi->netdev)
  2462. return;
  2463. i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features);
  2464. for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
  2465. i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q),
  2466. vid);
  2467. }
  2468. /**
  2469. * i40e_vsi_add_pvid - Add pvid for the VSI
  2470. * @vsi: the vsi being adjusted
  2471. * @vid: the vlan id to set as a PVID
  2472. **/
  2473. int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
  2474. {
  2475. struct i40e_vsi_context ctxt;
  2476. i40e_status ret;
  2477. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2478. vsi->info.pvid = cpu_to_le16(vid);
  2479. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
  2480. I40E_AQ_VSI_PVLAN_INSERT_PVID |
  2481. I40E_AQ_VSI_PVLAN_EMOD_STR;
  2482. ctxt.seid = vsi->seid;
  2483. ctxt.info = vsi->info;
  2484. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2485. if (ret) {
  2486. dev_info(&vsi->back->pdev->dev,
  2487. "add pvid failed, err %s aq_err %s\n",
  2488. i40e_stat_str(&vsi->back->hw, ret),
  2489. i40e_aq_str(&vsi->back->hw,
  2490. vsi->back->hw.aq.asq_last_status));
  2491. return -ENOENT;
  2492. }
  2493. return 0;
  2494. }
  2495. /**
  2496. * i40e_vsi_remove_pvid - Remove the pvid from the VSI
  2497. * @vsi: the vsi being adjusted
  2498. *
  2499. * Just use the vlan_rx_register() service to put it back to normal
  2500. **/
  2501. void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
  2502. {
  2503. i40e_vlan_stripping_disable(vsi);
  2504. vsi->info.pvid = 0;
  2505. }
  2506. /**
  2507. * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
  2508. * @vsi: ptr to the VSI
  2509. *
  2510. * If this function returns with an error, then it's possible one or
  2511. * more of the rings is populated (while the rest are not). It is the
  2512. * callers duty to clean those orphaned rings.
  2513. *
  2514. * Return 0 on success, negative on failure
  2515. **/
  2516. static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
  2517. {
  2518. int i, err = 0;
  2519. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2520. err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
  2521. return err;
  2522. }
  2523. /**
  2524. * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
  2525. * @vsi: ptr to the VSI
  2526. *
  2527. * Free VSI's transmit software resources
  2528. **/
  2529. static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
  2530. {
  2531. int i;
  2532. if (!vsi->tx_rings)
  2533. return;
  2534. for (i = 0; i < vsi->num_queue_pairs; i++)
  2535. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
  2536. i40e_free_tx_resources(vsi->tx_rings[i]);
  2537. }
  2538. /**
  2539. * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
  2540. * @vsi: ptr to the VSI
  2541. *
  2542. * If this function returns with an error, then it's possible one or
  2543. * more of the rings is populated (while the rest are not). It is the
  2544. * callers duty to clean those orphaned rings.
  2545. *
  2546. * Return 0 on success, negative on failure
  2547. **/
  2548. static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
  2549. {
  2550. int i, err = 0;
  2551. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2552. err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
  2553. #ifdef I40E_FCOE
  2554. i40e_fcoe_setup_ddp_resources(vsi);
  2555. #endif
  2556. return err;
  2557. }
  2558. /**
  2559. * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
  2560. * @vsi: ptr to the VSI
  2561. *
  2562. * Free all receive software resources
  2563. **/
  2564. static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
  2565. {
  2566. int i;
  2567. if (!vsi->rx_rings)
  2568. return;
  2569. for (i = 0; i < vsi->num_queue_pairs; i++)
  2570. if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
  2571. i40e_free_rx_resources(vsi->rx_rings[i]);
  2572. #ifdef I40E_FCOE
  2573. i40e_fcoe_free_ddp_resources(vsi);
  2574. #endif
  2575. }
  2576. /**
  2577. * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
  2578. * @ring: The Tx ring to configure
  2579. *
  2580. * This enables/disables XPS for a given Tx descriptor ring
  2581. * based on the TCs enabled for the VSI that ring belongs to.
  2582. **/
  2583. static void i40e_config_xps_tx_ring(struct i40e_ring *ring)
  2584. {
  2585. struct i40e_vsi *vsi = ring->vsi;
  2586. cpumask_var_t mask;
  2587. if (!ring->q_vector || !ring->netdev)
  2588. return;
  2589. /* Single TC mode enable XPS */
  2590. if (vsi->tc_config.numtc <= 1) {
  2591. if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state))
  2592. netif_set_xps_queue(ring->netdev,
  2593. &ring->q_vector->affinity_mask,
  2594. ring->queue_index);
  2595. } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) {
  2596. /* Disable XPS to allow selection based on TC */
  2597. bitmap_zero(cpumask_bits(mask), nr_cpumask_bits);
  2598. netif_set_xps_queue(ring->netdev, mask, ring->queue_index);
  2599. free_cpumask_var(mask);
  2600. }
  2601. /* schedule our worker thread which will take care of
  2602. * applying the new filter changes
  2603. */
  2604. i40e_service_event_schedule(vsi->back);
  2605. }
  2606. /**
  2607. * i40e_configure_tx_ring - Configure a transmit ring context and rest
  2608. * @ring: The Tx ring to configure
  2609. *
  2610. * Configure the Tx descriptor ring in the HMC context.
  2611. **/
  2612. static int i40e_configure_tx_ring(struct i40e_ring *ring)
  2613. {
  2614. struct i40e_vsi *vsi = ring->vsi;
  2615. u16 pf_q = vsi->base_queue + ring->queue_index;
  2616. struct i40e_hw *hw = &vsi->back->hw;
  2617. struct i40e_hmc_obj_txq tx_ctx;
  2618. i40e_status err = 0;
  2619. u32 qtx_ctl = 0;
  2620. /* some ATR related tx ring init */
  2621. if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
  2622. ring->atr_sample_rate = vsi->back->atr_sample_rate;
  2623. ring->atr_count = 0;
  2624. } else {
  2625. ring->atr_sample_rate = 0;
  2626. }
  2627. /* configure XPS */
  2628. i40e_config_xps_tx_ring(ring);
  2629. /* clear the context structure first */
  2630. memset(&tx_ctx, 0, sizeof(tx_ctx));
  2631. tx_ctx.new_context = 1;
  2632. tx_ctx.base = (ring->dma / 128);
  2633. tx_ctx.qlen = ring->count;
  2634. tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
  2635. I40E_FLAG_FD_ATR_ENABLED));
  2636. #ifdef I40E_FCOE
  2637. tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
  2638. #endif
  2639. tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
  2640. /* FDIR VSI tx ring can still use RS bit and writebacks */
  2641. if (vsi->type != I40E_VSI_FDIR)
  2642. tx_ctx.head_wb_ena = 1;
  2643. tx_ctx.head_wb_addr = ring->dma +
  2644. (ring->count * sizeof(struct i40e_tx_desc));
  2645. /* As part of VSI creation/update, FW allocates certain
  2646. * Tx arbitration queue sets for each TC enabled for
  2647. * the VSI. The FW returns the handles to these queue
  2648. * sets as part of the response buffer to Add VSI,
  2649. * Update VSI, etc. AQ commands. It is expected that
  2650. * these queue set handles be associated with the Tx
  2651. * queues by the driver as part of the TX queue context
  2652. * initialization. This has to be done regardless of
  2653. * DCB as by default everything is mapped to TC0.
  2654. */
  2655. tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
  2656. tx_ctx.rdylist_act = 0;
  2657. /* clear the context in the HMC */
  2658. err = i40e_clear_lan_tx_queue_context(hw, pf_q);
  2659. if (err) {
  2660. dev_info(&vsi->back->pdev->dev,
  2661. "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
  2662. ring->queue_index, pf_q, err);
  2663. return -ENOMEM;
  2664. }
  2665. /* set the context in the HMC */
  2666. err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
  2667. if (err) {
  2668. dev_info(&vsi->back->pdev->dev,
  2669. "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
  2670. ring->queue_index, pf_q, err);
  2671. return -ENOMEM;
  2672. }
  2673. /* Now associate this queue with this PCI function */
  2674. if (vsi->type == I40E_VSI_VMDQ2) {
  2675. qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
  2676. qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) &
  2677. I40E_QTX_CTL_VFVM_INDX_MASK;
  2678. } else {
  2679. qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
  2680. }
  2681. qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
  2682. I40E_QTX_CTL_PF_INDX_MASK);
  2683. wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
  2684. i40e_flush(hw);
  2685. /* cache tail off for easier writes later */
  2686. ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
  2687. return 0;
  2688. }
  2689. /**
  2690. * i40e_configure_rx_ring - Configure a receive ring context
  2691. * @ring: The Rx ring to configure
  2692. *
  2693. * Configure the Rx descriptor ring in the HMC context.
  2694. **/
  2695. static int i40e_configure_rx_ring(struct i40e_ring *ring)
  2696. {
  2697. struct i40e_vsi *vsi = ring->vsi;
  2698. u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
  2699. u16 pf_q = vsi->base_queue + ring->queue_index;
  2700. struct i40e_hw *hw = &vsi->back->hw;
  2701. struct i40e_hmc_obj_rxq rx_ctx;
  2702. i40e_status err = 0;
  2703. ring->state = 0;
  2704. /* clear the context structure first */
  2705. memset(&rx_ctx, 0, sizeof(rx_ctx));
  2706. ring->rx_buf_len = vsi->rx_buf_len;
  2707. rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT;
  2708. rx_ctx.base = (ring->dma / 128);
  2709. rx_ctx.qlen = ring->count;
  2710. /* use 32 byte descriptors */
  2711. rx_ctx.dsize = 1;
  2712. /* descriptor type is always zero
  2713. * rx_ctx.dtype = 0;
  2714. */
  2715. rx_ctx.hsplit_0 = 0;
  2716. rx_ctx.rxmax = min_t(u16, vsi->max_frame, chain_len * ring->rx_buf_len);
  2717. if (hw->revision_id == 0)
  2718. rx_ctx.lrxqthresh = 0;
  2719. else
  2720. rx_ctx.lrxqthresh = 2;
  2721. rx_ctx.crcstrip = 1;
  2722. rx_ctx.l2tsel = 1;
  2723. /* this controls whether VLAN is stripped from inner headers */
  2724. rx_ctx.showiv = 0;
  2725. #ifdef I40E_FCOE
  2726. rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
  2727. #endif
  2728. /* set the prefena field to 1 because the manual says to */
  2729. rx_ctx.prefena = 1;
  2730. /* clear the context in the HMC */
  2731. err = i40e_clear_lan_rx_queue_context(hw, pf_q);
  2732. if (err) {
  2733. dev_info(&vsi->back->pdev->dev,
  2734. "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2735. ring->queue_index, pf_q, err);
  2736. return -ENOMEM;
  2737. }
  2738. /* set the context in the HMC */
  2739. err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
  2740. if (err) {
  2741. dev_info(&vsi->back->pdev->dev,
  2742. "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2743. ring->queue_index, pf_q, err);
  2744. return -ENOMEM;
  2745. }
  2746. /* cache tail for quicker writes, and clear the reg before use */
  2747. ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
  2748. writel(0, ring->tail);
  2749. i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring));
  2750. return 0;
  2751. }
  2752. /**
  2753. * i40e_vsi_configure_tx - Configure the VSI for Tx
  2754. * @vsi: VSI structure describing this set of rings and resources
  2755. *
  2756. * Configure the Tx VSI for operation.
  2757. **/
  2758. static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
  2759. {
  2760. int err = 0;
  2761. u16 i;
  2762. for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
  2763. err = i40e_configure_tx_ring(vsi->tx_rings[i]);
  2764. return err;
  2765. }
  2766. /**
  2767. * i40e_vsi_configure_rx - Configure the VSI for Rx
  2768. * @vsi: the VSI being configured
  2769. *
  2770. * Configure the Rx VSI for operation.
  2771. **/
  2772. static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
  2773. {
  2774. int err = 0;
  2775. u16 i;
  2776. if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN))
  2777. vsi->max_frame = vsi->netdev->mtu + ETH_HLEN
  2778. + ETH_FCS_LEN + VLAN_HLEN;
  2779. else
  2780. vsi->max_frame = I40E_RXBUFFER_2048;
  2781. vsi->rx_buf_len = I40E_RXBUFFER_2048;
  2782. #ifdef I40E_FCOE
  2783. /* setup rx buffer for FCoE */
  2784. if ((vsi->type == I40E_VSI_FCOE) &&
  2785. (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) {
  2786. vsi->rx_buf_len = I40E_RXBUFFER_3072;
  2787. vsi->max_frame = I40E_RXBUFFER_3072;
  2788. }
  2789. #endif /* I40E_FCOE */
  2790. /* round up for the chip's needs */
  2791. vsi->rx_buf_len = ALIGN(vsi->rx_buf_len,
  2792. BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
  2793. /* set up individual rings */
  2794. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2795. err = i40e_configure_rx_ring(vsi->rx_rings[i]);
  2796. return err;
  2797. }
  2798. /**
  2799. * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
  2800. * @vsi: ptr to the VSI
  2801. **/
  2802. static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
  2803. {
  2804. struct i40e_ring *tx_ring, *rx_ring;
  2805. u16 qoffset, qcount;
  2806. int i, n;
  2807. if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  2808. /* Reset the TC information */
  2809. for (i = 0; i < vsi->num_queue_pairs; i++) {
  2810. rx_ring = vsi->rx_rings[i];
  2811. tx_ring = vsi->tx_rings[i];
  2812. rx_ring->dcb_tc = 0;
  2813. tx_ring->dcb_tc = 0;
  2814. }
  2815. }
  2816. for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
  2817. if (!(vsi->tc_config.enabled_tc & BIT_ULL(n)))
  2818. continue;
  2819. qoffset = vsi->tc_config.tc_info[n].qoffset;
  2820. qcount = vsi->tc_config.tc_info[n].qcount;
  2821. for (i = qoffset; i < (qoffset + qcount); i++) {
  2822. rx_ring = vsi->rx_rings[i];
  2823. tx_ring = vsi->tx_rings[i];
  2824. rx_ring->dcb_tc = n;
  2825. tx_ring->dcb_tc = n;
  2826. }
  2827. }
  2828. }
  2829. /**
  2830. * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
  2831. * @vsi: ptr to the VSI
  2832. **/
  2833. static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
  2834. {
  2835. struct i40e_pf *pf = vsi->back;
  2836. int err;
  2837. if (vsi->netdev)
  2838. i40e_set_rx_mode(vsi->netdev);
  2839. if (!!(pf->flags & I40E_FLAG_PF_MAC)) {
  2840. err = i40e_macaddr_init(vsi, pf->hw.mac.addr);
  2841. if (err) {
  2842. dev_warn(&pf->pdev->dev,
  2843. "could not set up macaddr; err %d\n", err);
  2844. }
  2845. }
  2846. }
  2847. /**
  2848. * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
  2849. * @vsi: Pointer to the targeted VSI
  2850. *
  2851. * This function replays the hlist on the hw where all the SB Flow Director
  2852. * filters were saved.
  2853. **/
  2854. static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
  2855. {
  2856. struct i40e_fdir_filter *filter;
  2857. struct i40e_pf *pf = vsi->back;
  2858. struct hlist_node *node;
  2859. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  2860. return;
  2861. hlist_for_each_entry_safe(filter, node,
  2862. &pf->fdir_filter_list, fdir_node) {
  2863. i40e_add_del_fdir(vsi, filter, true);
  2864. }
  2865. }
  2866. /**
  2867. * i40e_vsi_configure - Set up the VSI for action
  2868. * @vsi: the VSI being configured
  2869. **/
  2870. static int i40e_vsi_configure(struct i40e_vsi *vsi)
  2871. {
  2872. int err;
  2873. i40e_set_vsi_rx_mode(vsi);
  2874. i40e_restore_vlan(vsi);
  2875. i40e_vsi_config_dcb_rings(vsi);
  2876. err = i40e_vsi_configure_tx(vsi);
  2877. if (!err)
  2878. err = i40e_vsi_configure_rx(vsi);
  2879. return err;
  2880. }
  2881. /**
  2882. * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
  2883. * @vsi: the VSI being configured
  2884. **/
  2885. static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
  2886. {
  2887. struct i40e_pf *pf = vsi->back;
  2888. struct i40e_hw *hw = &pf->hw;
  2889. u16 vector;
  2890. int i, q;
  2891. u32 qp;
  2892. /* The interrupt indexing is offset by 1 in the PFINT_ITRn
  2893. * and PFINT_LNKLSTn registers, e.g.:
  2894. * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
  2895. */
  2896. qp = vsi->base_queue;
  2897. vector = vsi->base_vector;
  2898. for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
  2899. struct i40e_q_vector *q_vector = vsi->q_vectors[i];
  2900. q_vector->itr_countdown = ITR_COUNTDOWN_START;
  2901. q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[i]->rx_itr_setting);
  2902. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  2903. wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
  2904. q_vector->rx.itr);
  2905. q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[i]->tx_itr_setting);
  2906. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  2907. wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
  2908. q_vector->tx.itr);
  2909. wr32(hw, I40E_PFINT_RATEN(vector - 1),
  2910. i40e_intrl_usec_to_reg(vsi->int_rate_limit));
  2911. /* Linked list for the queuepairs assigned to this vector */
  2912. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
  2913. for (q = 0; q < q_vector->num_ringpairs; q++) {
  2914. u32 val;
  2915. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  2916. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  2917. (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
  2918. (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
  2919. (I40E_QUEUE_TYPE_TX
  2920. << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
  2921. wr32(hw, I40E_QINT_RQCTL(qp), val);
  2922. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  2923. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  2924. (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
  2925. ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)|
  2926. (I40E_QUEUE_TYPE_RX
  2927. << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  2928. /* Terminate the linked list */
  2929. if (q == (q_vector->num_ringpairs - 1))
  2930. val |= (I40E_QUEUE_END_OF_LIST
  2931. << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  2932. wr32(hw, I40E_QINT_TQCTL(qp), val);
  2933. qp++;
  2934. }
  2935. }
  2936. i40e_flush(hw);
  2937. }
  2938. /**
  2939. * i40e_enable_misc_int_causes - enable the non-queue interrupts
  2940. * @hw: ptr to the hardware info
  2941. **/
  2942. static void i40e_enable_misc_int_causes(struct i40e_pf *pf)
  2943. {
  2944. struct i40e_hw *hw = &pf->hw;
  2945. u32 val;
  2946. /* clear things first */
  2947. wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
  2948. rd32(hw, I40E_PFINT_ICR0); /* read to clear */
  2949. val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
  2950. I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
  2951. I40E_PFINT_ICR0_ENA_GRST_MASK |
  2952. I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
  2953. I40E_PFINT_ICR0_ENA_GPIO_MASK |
  2954. I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
  2955. I40E_PFINT_ICR0_ENA_VFLR_MASK |
  2956. I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  2957. if (pf->flags & I40E_FLAG_IWARP_ENABLED)
  2958. val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  2959. if (pf->flags & I40E_FLAG_PTP)
  2960. val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  2961. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  2962. /* SW_ITR_IDX = 0, but don't change INTENA */
  2963. wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
  2964. I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
  2965. /* OTHER_ITR_IDX = 0 */
  2966. wr32(hw, I40E_PFINT_STAT_CTL0, 0);
  2967. }
  2968. /**
  2969. * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
  2970. * @vsi: the VSI being configured
  2971. **/
  2972. static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
  2973. {
  2974. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  2975. struct i40e_pf *pf = vsi->back;
  2976. struct i40e_hw *hw = &pf->hw;
  2977. u32 val;
  2978. /* set the ITR configuration */
  2979. q_vector->itr_countdown = ITR_COUNTDOWN_START;
  2980. q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[0]->rx_itr_setting);
  2981. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  2982. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr);
  2983. q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[0]->tx_itr_setting);
  2984. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  2985. wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr);
  2986. i40e_enable_misc_int_causes(pf);
  2987. /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
  2988. wr32(hw, I40E_PFINT_LNKLST0, 0);
  2989. /* Associate the queue pair to the vector and enable the queue int */
  2990. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  2991. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  2992. (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  2993. wr32(hw, I40E_QINT_RQCTL(0), val);
  2994. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  2995. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  2996. (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  2997. wr32(hw, I40E_QINT_TQCTL(0), val);
  2998. i40e_flush(hw);
  2999. }
  3000. /**
  3001. * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
  3002. * @pf: board private structure
  3003. **/
  3004. void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
  3005. {
  3006. struct i40e_hw *hw = &pf->hw;
  3007. wr32(hw, I40E_PFINT_DYN_CTL0,
  3008. I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
  3009. i40e_flush(hw);
  3010. }
  3011. /**
  3012. * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
  3013. * @pf: board private structure
  3014. * @clearpba: true when all pending interrupt events should be cleared
  3015. **/
  3016. void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba)
  3017. {
  3018. struct i40e_hw *hw = &pf->hw;
  3019. u32 val;
  3020. val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
  3021. (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) |
  3022. (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
  3023. wr32(hw, I40E_PFINT_DYN_CTL0, val);
  3024. i40e_flush(hw);
  3025. }
  3026. /**
  3027. * i40e_msix_clean_rings - MSIX mode Interrupt Handler
  3028. * @irq: interrupt number
  3029. * @data: pointer to a q_vector
  3030. **/
  3031. static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
  3032. {
  3033. struct i40e_q_vector *q_vector = data;
  3034. if (!q_vector->tx.ring && !q_vector->rx.ring)
  3035. return IRQ_HANDLED;
  3036. napi_schedule_irqoff(&q_vector->napi);
  3037. return IRQ_HANDLED;
  3038. }
  3039. /**
  3040. * i40e_irq_affinity_notify - Callback for affinity changes
  3041. * @notify: context as to what irq was changed
  3042. * @mask: the new affinity mask
  3043. *
  3044. * This is a callback function used by the irq_set_affinity_notifier function
  3045. * so that we may register to receive changes to the irq affinity masks.
  3046. **/
  3047. static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify,
  3048. const cpumask_t *mask)
  3049. {
  3050. struct i40e_q_vector *q_vector =
  3051. container_of(notify, struct i40e_q_vector, affinity_notify);
  3052. q_vector->affinity_mask = *mask;
  3053. }
  3054. /**
  3055. * i40e_irq_affinity_release - Callback for affinity notifier release
  3056. * @ref: internal core kernel usage
  3057. *
  3058. * This is a callback function used by the irq_set_affinity_notifier function
  3059. * to inform the current notification subscriber that they will no longer
  3060. * receive notifications.
  3061. **/
  3062. static void i40e_irq_affinity_release(struct kref *ref) {}
  3063. /**
  3064. * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
  3065. * @vsi: the VSI being configured
  3066. * @basename: name for the vector
  3067. *
  3068. * Allocates MSI-X vectors and requests interrupts from the kernel.
  3069. **/
  3070. static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
  3071. {
  3072. int q_vectors = vsi->num_q_vectors;
  3073. struct i40e_pf *pf = vsi->back;
  3074. int base = vsi->base_vector;
  3075. int rx_int_idx = 0;
  3076. int tx_int_idx = 0;
  3077. int vector, err;
  3078. int irq_num;
  3079. for (vector = 0; vector < q_vectors; vector++) {
  3080. struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
  3081. irq_num = pf->msix_entries[base + vector].vector;
  3082. if (q_vector->tx.ring && q_vector->rx.ring) {
  3083. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3084. "%s-%s-%d", basename, "TxRx", rx_int_idx++);
  3085. tx_int_idx++;
  3086. } else if (q_vector->rx.ring) {
  3087. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3088. "%s-%s-%d", basename, "rx", rx_int_idx++);
  3089. } else if (q_vector->tx.ring) {
  3090. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3091. "%s-%s-%d", basename, "tx", tx_int_idx++);
  3092. } else {
  3093. /* skip this unused q_vector */
  3094. continue;
  3095. }
  3096. err = request_irq(irq_num,
  3097. vsi->irq_handler,
  3098. 0,
  3099. q_vector->name,
  3100. q_vector);
  3101. if (err) {
  3102. dev_info(&pf->pdev->dev,
  3103. "MSIX request_irq failed, error: %d\n", err);
  3104. goto free_queue_irqs;
  3105. }
  3106. /* register for affinity change notifications */
  3107. q_vector->affinity_notify.notify = i40e_irq_affinity_notify;
  3108. q_vector->affinity_notify.release = i40e_irq_affinity_release;
  3109. irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
  3110. /* assign the mask for this irq */
  3111. irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
  3112. }
  3113. vsi->irqs_ready = true;
  3114. return 0;
  3115. free_queue_irqs:
  3116. while (vector) {
  3117. vector--;
  3118. irq_num = pf->msix_entries[base + vector].vector;
  3119. irq_set_affinity_notifier(irq_num, NULL);
  3120. irq_set_affinity_hint(irq_num, NULL);
  3121. free_irq(irq_num, &vsi->q_vectors[vector]);
  3122. }
  3123. return err;
  3124. }
  3125. /**
  3126. * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
  3127. * @vsi: the VSI being un-configured
  3128. **/
  3129. static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
  3130. {
  3131. struct i40e_pf *pf = vsi->back;
  3132. struct i40e_hw *hw = &pf->hw;
  3133. int base = vsi->base_vector;
  3134. int i;
  3135. for (i = 0; i < vsi->num_queue_pairs; i++) {
  3136. wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0);
  3137. wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0);
  3138. }
  3139. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3140. for (i = vsi->base_vector;
  3141. i < (vsi->num_q_vectors + vsi->base_vector); i++)
  3142. wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
  3143. i40e_flush(hw);
  3144. for (i = 0; i < vsi->num_q_vectors; i++)
  3145. synchronize_irq(pf->msix_entries[i + base].vector);
  3146. } else {
  3147. /* Legacy and MSI mode - this stops all interrupt handling */
  3148. wr32(hw, I40E_PFINT_ICR0_ENA, 0);
  3149. wr32(hw, I40E_PFINT_DYN_CTL0, 0);
  3150. i40e_flush(hw);
  3151. synchronize_irq(pf->pdev->irq);
  3152. }
  3153. }
  3154. /**
  3155. * i40e_vsi_enable_irq - Enable IRQ for the given VSI
  3156. * @vsi: the VSI being configured
  3157. **/
  3158. static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
  3159. {
  3160. struct i40e_pf *pf = vsi->back;
  3161. int i;
  3162. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3163. for (i = 0; i < vsi->num_q_vectors; i++)
  3164. i40e_irq_dynamic_enable(vsi, i);
  3165. } else {
  3166. i40e_irq_dynamic_enable_icr0(pf, true);
  3167. }
  3168. i40e_flush(&pf->hw);
  3169. return 0;
  3170. }
  3171. /**
  3172. * i40e_stop_misc_vector - Stop the vector that handles non-queue events
  3173. * @pf: board private structure
  3174. **/
  3175. static void i40e_stop_misc_vector(struct i40e_pf *pf)
  3176. {
  3177. /* Disable ICR 0 */
  3178. wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
  3179. i40e_flush(&pf->hw);
  3180. }
  3181. /**
  3182. * i40e_intr - MSI/Legacy and non-queue interrupt handler
  3183. * @irq: interrupt number
  3184. * @data: pointer to a q_vector
  3185. *
  3186. * This is the handler used for all MSI/Legacy interrupts, and deals
  3187. * with both queue and non-queue interrupts. This is also used in
  3188. * MSIX mode to handle the non-queue interrupts.
  3189. **/
  3190. static irqreturn_t i40e_intr(int irq, void *data)
  3191. {
  3192. struct i40e_pf *pf = (struct i40e_pf *)data;
  3193. struct i40e_hw *hw = &pf->hw;
  3194. irqreturn_t ret = IRQ_NONE;
  3195. u32 icr0, icr0_remaining;
  3196. u32 val, ena_mask;
  3197. icr0 = rd32(hw, I40E_PFINT_ICR0);
  3198. ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
  3199. /* if sharing a legacy IRQ, we might get called w/o an intr pending */
  3200. if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
  3201. goto enable_intr;
  3202. /* if interrupt but no bits showing, must be SWINT */
  3203. if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
  3204. (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
  3205. pf->sw_int_count++;
  3206. if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
  3207. (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) {
  3208. ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  3209. icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  3210. dev_dbg(&pf->pdev->dev, "cleared PE_CRITERR\n");
  3211. }
  3212. /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
  3213. if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
  3214. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  3215. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  3216. /* We do not have a way to disarm Queue causes while leaving
  3217. * interrupt enabled for all other causes, ideally
  3218. * interrupt should be disabled while we are in NAPI but
  3219. * this is not a performance path and napi_schedule()
  3220. * can deal with rescheduling.
  3221. */
  3222. if (!test_bit(__I40E_DOWN, &pf->state))
  3223. napi_schedule_irqoff(&q_vector->napi);
  3224. }
  3225. if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
  3226. ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  3227. set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
  3228. i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n");
  3229. }
  3230. if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
  3231. ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  3232. set_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
  3233. }
  3234. if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
  3235. ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
  3236. set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
  3237. }
  3238. if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
  3239. if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
  3240. set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
  3241. ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
  3242. val = rd32(hw, I40E_GLGEN_RSTAT);
  3243. val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
  3244. >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
  3245. if (val == I40E_RESET_CORER) {
  3246. pf->corer_count++;
  3247. } else if (val == I40E_RESET_GLOBR) {
  3248. pf->globr_count++;
  3249. } else if (val == I40E_RESET_EMPR) {
  3250. pf->empr_count++;
  3251. set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state);
  3252. }
  3253. }
  3254. if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
  3255. icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
  3256. dev_info(&pf->pdev->dev, "HMC error interrupt\n");
  3257. dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n",
  3258. rd32(hw, I40E_PFHMC_ERRORINFO),
  3259. rd32(hw, I40E_PFHMC_ERRORDATA));
  3260. }
  3261. if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
  3262. u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
  3263. if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
  3264. icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  3265. i40e_ptp_tx_hwtstamp(pf);
  3266. }
  3267. }
  3268. /* If a critical error is pending we have no choice but to reset the
  3269. * device.
  3270. * Report and mask out any remaining unexpected interrupts.
  3271. */
  3272. icr0_remaining = icr0 & ena_mask;
  3273. if (icr0_remaining) {
  3274. dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
  3275. icr0_remaining);
  3276. if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
  3277. (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
  3278. (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
  3279. dev_info(&pf->pdev->dev, "device will be reset\n");
  3280. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  3281. i40e_service_event_schedule(pf);
  3282. }
  3283. ena_mask &= ~icr0_remaining;
  3284. }
  3285. ret = IRQ_HANDLED;
  3286. enable_intr:
  3287. /* re-enable interrupt causes */
  3288. wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
  3289. if (!test_bit(__I40E_DOWN, &pf->state)) {
  3290. i40e_service_event_schedule(pf);
  3291. i40e_irq_dynamic_enable_icr0(pf, false);
  3292. }
  3293. return ret;
  3294. }
  3295. /**
  3296. * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
  3297. * @tx_ring: tx ring to clean
  3298. * @budget: how many cleans we're allowed
  3299. *
  3300. * Returns true if there's any budget left (e.g. the clean is finished)
  3301. **/
  3302. static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
  3303. {
  3304. struct i40e_vsi *vsi = tx_ring->vsi;
  3305. u16 i = tx_ring->next_to_clean;
  3306. struct i40e_tx_buffer *tx_buf;
  3307. struct i40e_tx_desc *tx_desc;
  3308. tx_buf = &tx_ring->tx_bi[i];
  3309. tx_desc = I40E_TX_DESC(tx_ring, i);
  3310. i -= tx_ring->count;
  3311. do {
  3312. struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
  3313. /* if next_to_watch is not set then there is no work pending */
  3314. if (!eop_desc)
  3315. break;
  3316. /* prevent any other reads prior to eop_desc */
  3317. read_barrier_depends();
  3318. /* if the descriptor isn't done, no work yet to do */
  3319. if (!(eop_desc->cmd_type_offset_bsz &
  3320. cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
  3321. break;
  3322. /* clear next_to_watch to prevent false hangs */
  3323. tx_buf->next_to_watch = NULL;
  3324. tx_desc->buffer_addr = 0;
  3325. tx_desc->cmd_type_offset_bsz = 0;
  3326. /* move past filter desc */
  3327. tx_buf++;
  3328. tx_desc++;
  3329. i++;
  3330. if (unlikely(!i)) {
  3331. i -= tx_ring->count;
  3332. tx_buf = tx_ring->tx_bi;
  3333. tx_desc = I40E_TX_DESC(tx_ring, 0);
  3334. }
  3335. /* unmap skb header data */
  3336. dma_unmap_single(tx_ring->dev,
  3337. dma_unmap_addr(tx_buf, dma),
  3338. dma_unmap_len(tx_buf, len),
  3339. DMA_TO_DEVICE);
  3340. if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB)
  3341. kfree(tx_buf->raw_buf);
  3342. tx_buf->raw_buf = NULL;
  3343. tx_buf->tx_flags = 0;
  3344. tx_buf->next_to_watch = NULL;
  3345. dma_unmap_len_set(tx_buf, len, 0);
  3346. tx_desc->buffer_addr = 0;
  3347. tx_desc->cmd_type_offset_bsz = 0;
  3348. /* move us past the eop_desc for start of next FD desc */
  3349. tx_buf++;
  3350. tx_desc++;
  3351. i++;
  3352. if (unlikely(!i)) {
  3353. i -= tx_ring->count;
  3354. tx_buf = tx_ring->tx_bi;
  3355. tx_desc = I40E_TX_DESC(tx_ring, 0);
  3356. }
  3357. /* update budget accounting */
  3358. budget--;
  3359. } while (likely(budget));
  3360. i += tx_ring->count;
  3361. tx_ring->next_to_clean = i;
  3362. if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED)
  3363. i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx);
  3364. return budget > 0;
  3365. }
  3366. /**
  3367. * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
  3368. * @irq: interrupt number
  3369. * @data: pointer to a q_vector
  3370. **/
  3371. static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
  3372. {
  3373. struct i40e_q_vector *q_vector = data;
  3374. struct i40e_vsi *vsi;
  3375. if (!q_vector->tx.ring)
  3376. return IRQ_HANDLED;
  3377. vsi = q_vector->tx.ring->vsi;
  3378. i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
  3379. return IRQ_HANDLED;
  3380. }
  3381. /**
  3382. * i40e_map_vector_to_qp - Assigns the queue pair to the vector
  3383. * @vsi: the VSI being configured
  3384. * @v_idx: vector index
  3385. * @qp_idx: queue pair index
  3386. **/
  3387. static void i40e_map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
  3388. {
  3389. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  3390. struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
  3391. struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
  3392. tx_ring->q_vector = q_vector;
  3393. tx_ring->next = q_vector->tx.ring;
  3394. q_vector->tx.ring = tx_ring;
  3395. q_vector->tx.count++;
  3396. rx_ring->q_vector = q_vector;
  3397. rx_ring->next = q_vector->rx.ring;
  3398. q_vector->rx.ring = rx_ring;
  3399. q_vector->rx.count++;
  3400. }
  3401. /**
  3402. * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
  3403. * @vsi: the VSI being configured
  3404. *
  3405. * This function maps descriptor rings to the queue-specific vectors
  3406. * we were allotted through the MSI-X enabling code. Ideally, we'd have
  3407. * one vector per queue pair, but on a constrained vector budget, we
  3408. * group the queue pairs as "efficiently" as possible.
  3409. **/
  3410. static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
  3411. {
  3412. int qp_remaining = vsi->num_queue_pairs;
  3413. int q_vectors = vsi->num_q_vectors;
  3414. int num_ringpairs;
  3415. int v_start = 0;
  3416. int qp_idx = 0;
  3417. /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
  3418. * group them so there are multiple queues per vector.
  3419. * It is also important to go through all the vectors available to be
  3420. * sure that if we don't use all the vectors, that the remaining vectors
  3421. * are cleared. This is especially important when decreasing the
  3422. * number of queues in use.
  3423. */
  3424. for (; v_start < q_vectors; v_start++) {
  3425. struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
  3426. num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
  3427. q_vector->num_ringpairs = num_ringpairs;
  3428. q_vector->rx.count = 0;
  3429. q_vector->tx.count = 0;
  3430. q_vector->rx.ring = NULL;
  3431. q_vector->tx.ring = NULL;
  3432. while (num_ringpairs--) {
  3433. i40e_map_vector_to_qp(vsi, v_start, qp_idx);
  3434. qp_idx++;
  3435. qp_remaining--;
  3436. }
  3437. }
  3438. }
  3439. /**
  3440. * i40e_vsi_request_irq - Request IRQ from the OS
  3441. * @vsi: the VSI being configured
  3442. * @basename: name for the vector
  3443. **/
  3444. static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
  3445. {
  3446. struct i40e_pf *pf = vsi->back;
  3447. int err;
  3448. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  3449. err = i40e_vsi_request_irq_msix(vsi, basename);
  3450. else if (pf->flags & I40E_FLAG_MSI_ENABLED)
  3451. err = request_irq(pf->pdev->irq, i40e_intr, 0,
  3452. pf->int_name, pf);
  3453. else
  3454. err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
  3455. pf->int_name, pf);
  3456. if (err)
  3457. dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
  3458. return err;
  3459. }
  3460. #ifdef CONFIG_NET_POLL_CONTROLLER
  3461. /**
  3462. * i40e_netpoll - A Polling 'interrupt' handler
  3463. * @netdev: network interface device structure
  3464. *
  3465. * This is used by netconsole to send skbs without having to re-enable
  3466. * interrupts. It's not called while the normal interrupt routine is executing.
  3467. **/
  3468. #ifdef I40E_FCOE
  3469. void i40e_netpoll(struct net_device *netdev)
  3470. #else
  3471. static void i40e_netpoll(struct net_device *netdev)
  3472. #endif
  3473. {
  3474. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3475. struct i40e_vsi *vsi = np->vsi;
  3476. struct i40e_pf *pf = vsi->back;
  3477. int i;
  3478. /* if interface is down do nothing */
  3479. if (test_bit(__I40E_DOWN, &vsi->state))
  3480. return;
  3481. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3482. for (i = 0; i < vsi->num_q_vectors; i++)
  3483. i40e_msix_clean_rings(0, vsi->q_vectors[i]);
  3484. } else {
  3485. i40e_intr(pf->pdev->irq, netdev);
  3486. }
  3487. }
  3488. #endif
  3489. /**
  3490. * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
  3491. * @pf: the PF being configured
  3492. * @pf_q: the PF queue
  3493. * @enable: enable or disable state of the queue
  3494. *
  3495. * This routine will wait for the given Tx queue of the PF to reach the
  3496. * enabled or disabled state.
  3497. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  3498. * multiple retries; else will return 0 in case of success.
  3499. **/
  3500. static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable)
  3501. {
  3502. int i;
  3503. u32 tx_reg;
  3504. for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
  3505. tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q));
  3506. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  3507. break;
  3508. usleep_range(10, 20);
  3509. }
  3510. if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
  3511. return -ETIMEDOUT;
  3512. return 0;
  3513. }
  3514. /**
  3515. * i40e_vsi_control_tx - Start or stop a VSI's rings
  3516. * @vsi: the VSI being configured
  3517. * @enable: start or stop the rings
  3518. **/
  3519. static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
  3520. {
  3521. struct i40e_pf *pf = vsi->back;
  3522. struct i40e_hw *hw = &pf->hw;
  3523. int i, j, pf_q, ret = 0;
  3524. u32 tx_reg;
  3525. pf_q = vsi->base_queue;
  3526. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3527. /* warn the TX unit of coming changes */
  3528. i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
  3529. if (!enable)
  3530. usleep_range(10, 20);
  3531. for (j = 0; j < 50; j++) {
  3532. tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
  3533. if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
  3534. ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
  3535. break;
  3536. usleep_range(1000, 2000);
  3537. }
  3538. /* Skip if the queue is already in the requested state */
  3539. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  3540. continue;
  3541. /* turn on/off the queue */
  3542. if (enable) {
  3543. wr32(hw, I40E_QTX_HEAD(pf_q), 0);
  3544. tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
  3545. } else {
  3546. tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
  3547. }
  3548. wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
  3549. /* No waiting for the Tx queue to disable */
  3550. if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state))
  3551. continue;
  3552. /* wait for the change to finish */
  3553. ret = i40e_pf_txq_wait(pf, pf_q, enable);
  3554. if (ret) {
  3555. dev_info(&pf->pdev->dev,
  3556. "VSI seid %d Tx ring %d %sable timeout\n",
  3557. vsi->seid, pf_q, (enable ? "en" : "dis"));
  3558. break;
  3559. }
  3560. }
  3561. if (hw->revision_id == 0)
  3562. mdelay(50);
  3563. return ret;
  3564. }
  3565. /**
  3566. * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
  3567. * @pf: the PF being configured
  3568. * @pf_q: the PF queue
  3569. * @enable: enable or disable state of the queue
  3570. *
  3571. * This routine will wait for the given Rx queue of the PF to reach the
  3572. * enabled or disabled state.
  3573. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  3574. * multiple retries; else will return 0 in case of success.
  3575. **/
  3576. static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable)
  3577. {
  3578. int i;
  3579. u32 rx_reg;
  3580. for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
  3581. rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q));
  3582. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  3583. break;
  3584. usleep_range(10, 20);
  3585. }
  3586. if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
  3587. return -ETIMEDOUT;
  3588. return 0;
  3589. }
  3590. /**
  3591. * i40e_vsi_control_rx - Start or stop a VSI's rings
  3592. * @vsi: the VSI being configured
  3593. * @enable: start or stop the rings
  3594. **/
  3595. static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
  3596. {
  3597. struct i40e_pf *pf = vsi->back;
  3598. struct i40e_hw *hw = &pf->hw;
  3599. int i, j, pf_q, ret = 0;
  3600. u32 rx_reg;
  3601. pf_q = vsi->base_queue;
  3602. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3603. for (j = 0; j < 50; j++) {
  3604. rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
  3605. if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
  3606. ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
  3607. break;
  3608. usleep_range(1000, 2000);
  3609. }
  3610. /* Skip if the queue is already in the requested state */
  3611. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  3612. continue;
  3613. /* turn on/off the queue */
  3614. if (enable)
  3615. rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
  3616. else
  3617. rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
  3618. wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
  3619. /* No waiting for the Tx queue to disable */
  3620. if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state))
  3621. continue;
  3622. /* wait for the change to finish */
  3623. ret = i40e_pf_rxq_wait(pf, pf_q, enable);
  3624. if (ret) {
  3625. dev_info(&pf->pdev->dev,
  3626. "VSI seid %d Rx ring %d %sable timeout\n",
  3627. vsi->seid, pf_q, (enable ? "en" : "dis"));
  3628. break;
  3629. }
  3630. }
  3631. return ret;
  3632. }
  3633. /**
  3634. * i40e_vsi_start_rings - Start a VSI's rings
  3635. * @vsi: the VSI being configured
  3636. **/
  3637. int i40e_vsi_start_rings(struct i40e_vsi *vsi)
  3638. {
  3639. int ret = 0;
  3640. /* do rx first for enable and last for disable */
  3641. ret = i40e_vsi_control_rx(vsi, true);
  3642. if (ret)
  3643. return ret;
  3644. ret = i40e_vsi_control_tx(vsi, true);
  3645. return ret;
  3646. }
  3647. /**
  3648. * i40e_vsi_stop_rings - Stop a VSI's rings
  3649. * @vsi: the VSI being configured
  3650. **/
  3651. void i40e_vsi_stop_rings(struct i40e_vsi *vsi)
  3652. {
  3653. /* do rx first for enable and last for disable
  3654. * Ignore return value, we need to shutdown whatever we can
  3655. */
  3656. i40e_vsi_control_tx(vsi, false);
  3657. i40e_vsi_control_rx(vsi, false);
  3658. }
  3659. /**
  3660. * i40e_vsi_free_irq - Free the irq association with the OS
  3661. * @vsi: the VSI being configured
  3662. **/
  3663. static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
  3664. {
  3665. struct i40e_pf *pf = vsi->back;
  3666. struct i40e_hw *hw = &pf->hw;
  3667. int base = vsi->base_vector;
  3668. u32 val, qp;
  3669. int i;
  3670. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3671. if (!vsi->q_vectors)
  3672. return;
  3673. if (!vsi->irqs_ready)
  3674. return;
  3675. vsi->irqs_ready = false;
  3676. for (i = 0; i < vsi->num_q_vectors; i++) {
  3677. int irq_num;
  3678. u16 vector;
  3679. vector = i + base;
  3680. irq_num = pf->msix_entries[vector].vector;
  3681. /* free only the irqs that were actually requested */
  3682. if (!vsi->q_vectors[i] ||
  3683. !vsi->q_vectors[i]->num_ringpairs)
  3684. continue;
  3685. /* clear the affinity notifier in the IRQ descriptor */
  3686. irq_set_affinity_notifier(irq_num, NULL);
  3687. /* clear the affinity_mask in the IRQ descriptor */
  3688. irq_set_affinity_hint(irq_num, NULL);
  3689. synchronize_irq(irq_num);
  3690. free_irq(irq_num, vsi->q_vectors[i]);
  3691. /* Tear down the interrupt queue link list
  3692. *
  3693. * We know that they come in pairs and always
  3694. * the Rx first, then the Tx. To clear the
  3695. * link list, stick the EOL value into the
  3696. * next_q field of the registers.
  3697. */
  3698. val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
  3699. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  3700. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3701. val |= I40E_QUEUE_END_OF_LIST
  3702. << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3703. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
  3704. while (qp != I40E_QUEUE_END_OF_LIST) {
  3705. u32 next;
  3706. val = rd32(hw, I40E_QINT_RQCTL(qp));
  3707. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  3708. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  3709. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3710. I40E_QINT_RQCTL_INTEVENT_MASK);
  3711. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  3712. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  3713. wr32(hw, I40E_QINT_RQCTL(qp), val);
  3714. val = rd32(hw, I40E_QINT_TQCTL(qp));
  3715. next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
  3716. >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
  3717. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  3718. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  3719. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3720. I40E_QINT_TQCTL_INTEVENT_MASK);
  3721. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  3722. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  3723. wr32(hw, I40E_QINT_TQCTL(qp), val);
  3724. qp = next;
  3725. }
  3726. }
  3727. } else {
  3728. free_irq(pf->pdev->irq, pf);
  3729. val = rd32(hw, I40E_PFINT_LNKLST0);
  3730. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  3731. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3732. val |= I40E_QUEUE_END_OF_LIST
  3733. << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
  3734. wr32(hw, I40E_PFINT_LNKLST0, val);
  3735. val = rd32(hw, I40E_QINT_RQCTL(qp));
  3736. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  3737. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  3738. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3739. I40E_QINT_RQCTL_INTEVENT_MASK);
  3740. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  3741. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  3742. wr32(hw, I40E_QINT_RQCTL(qp), val);
  3743. val = rd32(hw, I40E_QINT_TQCTL(qp));
  3744. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  3745. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  3746. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3747. I40E_QINT_TQCTL_INTEVENT_MASK);
  3748. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  3749. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  3750. wr32(hw, I40E_QINT_TQCTL(qp), val);
  3751. }
  3752. }
  3753. /**
  3754. * i40e_free_q_vector - Free memory allocated for specific interrupt vector
  3755. * @vsi: the VSI being configured
  3756. * @v_idx: Index of vector to be freed
  3757. *
  3758. * This function frees the memory allocated to the q_vector. In addition if
  3759. * NAPI is enabled it will delete any references to the NAPI struct prior
  3760. * to freeing the q_vector.
  3761. **/
  3762. static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
  3763. {
  3764. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  3765. struct i40e_ring *ring;
  3766. if (!q_vector)
  3767. return;
  3768. /* disassociate q_vector from rings */
  3769. i40e_for_each_ring(ring, q_vector->tx)
  3770. ring->q_vector = NULL;
  3771. i40e_for_each_ring(ring, q_vector->rx)
  3772. ring->q_vector = NULL;
  3773. /* only VSI w/ an associated netdev is set up w/ NAPI */
  3774. if (vsi->netdev)
  3775. netif_napi_del(&q_vector->napi);
  3776. vsi->q_vectors[v_idx] = NULL;
  3777. kfree_rcu(q_vector, rcu);
  3778. }
  3779. /**
  3780. * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
  3781. * @vsi: the VSI being un-configured
  3782. *
  3783. * This frees the memory allocated to the q_vectors and
  3784. * deletes references to the NAPI struct.
  3785. **/
  3786. static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
  3787. {
  3788. int v_idx;
  3789. for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
  3790. i40e_free_q_vector(vsi, v_idx);
  3791. }
  3792. /**
  3793. * i40e_reset_interrupt_capability - Disable interrupt setup in OS
  3794. * @pf: board private structure
  3795. **/
  3796. static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
  3797. {
  3798. /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
  3799. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3800. pci_disable_msix(pf->pdev);
  3801. kfree(pf->msix_entries);
  3802. pf->msix_entries = NULL;
  3803. kfree(pf->irq_pile);
  3804. pf->irq_pile = NULL;
  3805. } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
  3806. pci_disable_msi(pf->pdev);
  3807. }
  3808. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
  3809. }
  3810. /**
  3811. * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
  3812. * @pf: board private structure
  3813. *
  3814. * We go through and clear interrupt specific resources and reset the structure
  3815. * to pre-load conditions
  3816. **/
  3817. static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
  3818. {
  3819. int i;
  3820. i40e_stop_misc_vector(pf);
  3821. if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) {
  3822. synchronize_irq(pf->msix_entries[0].vector);
  3823. free_irq(pf->msix_entries[0].vector, pf);
  3824. }
  3825. i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector,
  3826. I40E_IWARP_IRQ_PILE_ID);
  3827. i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
  3828. for (i = 0; i < pf->num_alloc_vsi; i++)
  3829. if (pf->vsi[i])
  3830. i40e_vsi_free_q_vectors(pf->vsi[i]);
  3831. i40e_reset_interrupt_capability(pf);
  3832. }
  3833. /**
  3834. * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
  3835. * @vsi: the VSI being configured
  3836. **/
  3837. static void i40e_napi_enable_all(struct i40e_vsi *vsi)
  3838. {
  3839. int q_idx;
  3840. if (!vsi->netdev)
  3841. return;
  3842. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
  3843. napi_enable(&vsi->q_vectors[q_idx]->napi);
  3844. }
  3845. /**
  3846. * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
  3847. * @vsi: the VSI being configured
  3848. **/
  3849. static void i40e_napi_disable_all(struct i40e_vsi *vsi)
  3850. {
  3851. int q_idx;
  3852. if (!vsi->netdev)
  3853. return;
  3854. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
  3855. napi_disable(&vsi->q_vectors[q_idx]->napi);
  3856. }
  3857. /**
  3858. * i40e_vsi_close - Shut down a VSI
  3859. * @vsi: the vsi to be quelled
  3860. **/
  3861. static void i40e_vsi_close(struct i40e_vsi *vsi)
  3862. {
  3863. bool reset = false;
  3864. if (!test_and_set_bit(__I40E_DOWN, &vsi->state))
  3865. i40e_down(vsi);
  3866. i40e_vsi_free_irq(vsi);
  3867. i40e_vsi_free_tx_resources(vsi);
  3868. i40e_vsi_free_rx_resources(vsi);
  3869. vsi->current_netdev_flags = 0;
  3870. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
  3871. reset = true;
  3872. i40e_notify_client_of_netdev_close(vsi, reset);
  3873. }
  3874. /**
  3875. * i40e_quiesce_vsi - Pause a given VSI
  3876. * @vsi: the VSI being paused
  3877. **/
  3878. static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
  3879. {
  3880. if (test_bit(__I40E_DOWN, &vsi->state))
  3881. return;
  3882. /* No need to disable FCoE VSI when Tx suspended */
  3883. if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) &&
  3884. vsi->type == I40E_VSI_FCOE) {
  3885. dev_dbg(&vsi->back->pdev->dev,
  3886. "VSI seid %d skipping FCoE VSI disable\n", vsi->seid);
  3887. return;
  3888. }
  3889. set_bit(__I40E_NEEDS_RESTART, &vsi->state);
  3890. if (vsi->netdev && netif_running(vsi->netdev))
  3891. vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
  3892. else
  3893. i40e_vsi_close(vsi);
  3894. }
  3895. /**
  3896. * i40e_unquiesce_vsi - Resume a given VSI
  3897. * @vsi: the VSI being resumed
  3898. **/
  3899. static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
  3900. {
  3901. if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state))
  3902. return;
  3903. clear_bit(__I40E_NEEDS_RESTART, &vsi->state);
  3904. if (vsi->netdev && netif_running(vsi->netdev))
  3905. vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
  3906. else
  3907. i40e_vsi_open(vsi); /* this clears the DOWN bit */
  3908. }
  3909. /**
  3910. * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
  3911. * @pf: the PF
  3912. **/
  3913. static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
  3914. {
  3915. int v;
  3916. for (v = 0; v < pf->num_alloc_vsi; v++) {
  3917. if (pf->vsi[v])
  3918. i40e_quiesce_vsi(pf->vsi[v]);
  3919. }
  3920. }
  3921. /**
  3922. * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
  3923. * @pf: the PF
  3924. **/
  3925. static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
  3926. {
  3927. int v;
  3928. for (v = 0; v < pf->num_alloc_vsi; v++) {
  3929. if (pf->vsi[v])
  3930. i40e_unquiesce_vsi(pf->vsi[v]);
  3931. }
  3932. }
  3933. #ifdef CONFIG_I40E_DCB
  3934. /**
  3935. * i40e_vsi_wait_queues_disabled - Wait for VSI's queues to be disabled
  3936. * @vsi: the VSI being configured
  3937. *
  3938. * This function waits for the given VSI's queues to be disabled.
  3939. **/
  3940. static int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi)
  3941. {
  3942. struct i40e_pf *pf = vsi->back;
  3943. int i, pf_q, ret;
  3944. pf_q = vsi->base_queue;
  3945. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3946. /* Check and wait for the disable status of the queue */
  3947. ret = i40e_pf_txq_wait(pf, pf_q, false);
  3948. if (ret) {
  3949. dev_info(&pf->pdev->dev,
  3950. "VSI seid %d Tx ring %d disable timeout\n",
  3951. vsi->seid, pf_q);
  3952. return ret;
  3953. }
  3954. }
  3955. pf_q = vsi->base_queue;
  3956. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3957. /* Check and wait for the disable status of the queue */
  3958. ret = i40e_pf_rxq_wait(pf, pf_q, false);
  3959. if (ret) {
  3960. dev_info(&pf->pdev->dev,
  3961. "VSI seid %d Rx ring %d disable timeout\n",
  3962. vsi->seid, pf_q);
  3963. return ret;
  3964. }
  3965. }
  3966. return 0;
  3967. }
  3968. /**
  3969. * i40e_pf_wait_queues_disabled - Wait for all queues of PF VSIs to be disabled
  3970. * @pf: the PF
  3971. *
  3972. * This function waits for the queues to be in disabled state for all the
  3973. * VSIs that are managed by this PF.
  3974. **/
  3975. static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf)
  3976. {
  3977. int v, ret = 0;
  3978. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  3979. /* No need to wait for FCoE VSI queues */
  3980. if (pf->vsi[v] && pf->vsi[v]->type != I40E_VSI_FCOE) {
  3981. ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]);
  3982. if (ret)
  3983. break;
  3984. }
  3985. }
  3986. return ret;
  3987. }
  3988. #endif
  3989. /**
  3990. * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue
  3991. * @q_idx: TX queue number
  3992. * @vsi: Pointer to VSI struct
  3993. *
  3994. * This function checks specified queue for given VSI. Detects hung condition.
  3995. * Sets hung bit since it is two step process. Before next run of service task
  3996. * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not,
  3997. * hung condition remain unchanged and during subsequent run, this function
  3998. * issues SW interrupt to recover from hung condition.
  3999. **/
  4000. static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi)
  4001. {
  4002. struct i40e_ring *tx_ring = NULL;
  4003. struct i40e_pf *pf;
  4004. u32 head, val, tx_pending_hw;
  4005. int i;
  4006. pf = vsi->back;
  4007. /* now that we have an index, find the tx_ring struct */
  4008. for (i = 0; i < vsi->num_queue_pairs; i++) {
  4009. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
  4010. if (q_idx == vsi->tx_rings[i]->queue_index) {
  4011. tx_ring = vsi->tx_rings[i];
  4012. break;
  4013. }
  4014. }
  4015. }
  4016. if (!tx_ring)
  4017. return;
  4018. /* Read interrupt register */
  4019. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  4020. val = rd32(&pf->hw,
  4021. I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
  4022. tx_ring->vsi->base_vector - 1));
  4023. else
  4024. val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
  4025. head = i40e_get_head(tx_ring);
  4026. tx_pending_hw = i40e_get_tx_pending(tx_ring, false);
  4027. /* HW is done executing descriptors, updated HEAD write back,
  4028. * but SW hasn't processed those descriptors. If interrupt is
  4029. * not generated from this point ON, it could result into
  4030. * dev_watchdog detecting timeout on those netdev_queue,
  4031. * hence proactively trigger SW interrupt.
  4032. */
  4033. if (tx_pending_hw && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) {
  4034. /* NAPI Poll didn't run and clear since it was set */
  4035. if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT,
  4036. &tx_ring->q_vector->hung_detected)) {
  4037. netdev_info(vsi->netdev, "VSI_seid %d, Hung TX queue %d, tx_pending_hw: %d, NTC:0x%x, HWB: 0x%x, NTU: 0x%x, TAIL: 0x%x\n",
  4038. vsi->seid, q_idx, tx_pending_hw,
  4039. tx_ring->next_to_clean, head,
  4040. tx_ring->next_to_use,
  4041. readl(tx_ring->tail));
  4042. netdev_info(vsi->netdev, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n",
  4043. vsi->seid, q_idx, val);
  4044. i40e_force_wb(vsi, tx_ring->q_vector);
  4045. } else {
  4046. /* First Chance - detected possible hung */
  4047. set_bit(I40E_Q_VECTOR_HUNG_DETECT,
  4048. &tx_ring->q_vector->hung_detected);
  4049. }
  4050. }
  4051. /* This is the case where we have interrupts missing,
  4052. * so the tx_pending in HW will most likely be 0, but we
  4053. * will have tx_pending in SW since the WB happened but the
  4054. * interrupt got lost.
  4055. */
  4056. if ((!tx_pending_hw) && i40e_get_tx_pending(tx_ring, true) &&
  4057. (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) {
  4058. if (napi_reschedule(&tx_ring->q_vector->napi))
  4059. tx_ring->tx_stats.tx_lost_interrupt++;
  4060. }
  4061. }
  4062. /**
  4063. * i40e_detect_recover_hung - Function to detect and recover hung_queues
  4064. * @pf: pointer to PF struct
  4065. *
  4066. * LAN VSI has netdev and netdev has TX queues. This function is to check
  4067. * each of those TX queues if they are hung, trigger recovery by issuing
  4068. * SW interrupt.
  4069. **/
  4070. static void i40e_detect_recover_hung(struct i40e_pf *pf)
  4071. {
  4072. struct net_device *netdev;
  4073. struct i40e_vsi *vsi;
  4074. int i;
  4075. /* Only for LAN VSI */
  4076. vsi = pf->vsi[pf->lan_vsi];
  4077. if (!vsi)
  4078. return;
  4079. /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */
  4080. if (test_bit(__I40E_DOWN, &vsi->back->state) ||
  4081. test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
  4082. return;
  4083. /* Make sure type is MAIN VSI */
  4084. if (vsi->type != I40E_VSI_MAIN)
  4085. return;
  4086. netdev = vsi->netdev;
  4087. if (!netdev)
  4088. return;
  4089. /* Bail out if netif_carrier is not OK */
  4090. if (!netif_carrier_ok(netdev))
  4091. return;
  4092. /* Go thru' TX queues for netdev */
  4093. for (i = 0; i < netdev->num_tx_queues; i++) {
  4094. struct netdev_queue *q;
  4095. q = netdev_get_tx_queue(netdev, i);
  4096. if (q)
  4097. i40e_detect_recover_hung_queue(i, vsi);
  4098. }
  4099. }
  4100. /**
  4101. * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
  4102. * @pf: pointer to PF
  4103. *
  4104. * Get TC map for ISCSI PF type that will include iSCSI TC
  4105. * and LAN TC.
  4106. **/
  4107. static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf)
  4108. {
  4109. struct i40e_dcb_app_priority_table app;
  4110. struct i40e_hw *hw = &pf->hw;
  4111. u8 enabled_tc = 1; /* TC0 is always enabled */
  4112. u8 tc, i;
  4113. /* Get the iSCSI APP TLV */
  4114. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4115. for (i = 0; i < dcbcfg->numapps; i++) {
  4116. app = dcbcfg->app[i];
  4117. if (app.selector == I40E_APP_SEL_TCPIP &&
  4118. app.protocolid == I40E_APP_PROTOID_ISCSI) {
  4119. tc = dcbcfg->etscfg.prioritytable[app.priority];
  4120. enabled_tc |= BIT(tc);
  4121. break;
  4122. }
  4123. }
  4124. return enabled_tc;
  4125. }
  4126. /**
  4127. * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
  4128. * @dcbcfg: the corresponding DCBx configuration structure
  4129. *
  4130. * Return the number of TCs from given DCBx configuration
  4131. **/
  4132. static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
  4133. {
  4134. int i, tc_unused = 0;
  4135. u8 num_tc = 0;
  4136. u8 ret = 0;
  4137. /* Scan the ETS Config Priority Table to find
  4138. * traffic class enabled for a given priority
  4139. * and create a bitmask of enabled TCs
  4140. */
  4141. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
  4142. num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]);
  4143. /* Now scan the bitmask to check for
  4144. * contiguous TCs starting with TC0
  4145. */
  4146. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4147. if (num_tc & BIT(i)) {
  4148. if (!tc_unused) {
  4149. ret++;
  4150. } else {
  4151. pr_err("Non-contiguous TC - Disabling DCB\n");
  4152. return 1;
  4153. }
  4154. } else {
  4155. tc_unused = 1;
  4156. }
  4157. }
  4158. /* There is always at least TC0 */
  4159. if (!ret)
  4160. ret = 1;
  4161. return ret;
  4162. }
  4163. /**
  4164. * i40e_dcb_get_enabled_tc - Get enabled traffic classes
  4165. * @dcbcfg: the corresponding DCBx configuration structure
  4166. *
  4167. * Query the current DCB configuration and return the number of
  4168. * traffic classes enabled from the given DCBX config
  4169. **/
  4170. static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
  4171. {
  4172. u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
  4173. u8 enabled_tc = 1;
  4174. u8 i;
  4175. for (i = 0; i < num_tc; i++)
  4176. enabled_tc |= BIT(i);
  4177. return enabled_tc;
  4178. }
  4179. /**
  4180. * i40e_pf_get_num_tc - Get enabled traffic classes for PF
  4181. * @pf: PF being queried
  4182. *
  4183. * Return number of traffic classes enabled for the given PF
  4184. **/
  4185. static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
  4186. {
  4187. struct i40e_hw *hw = &pf->hw;
  4188. u8 i, enabled_tc = 1;
  4189. u8 num_tc = 0;
  4190. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4191. /* If DCB is not enabled then always in single TC */
  4192. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  4193. return 1;
  4194. /* SFP mode will be enabled for all TCs on port */
  4195. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  4196. return i40e_dcb_get_num_tc(dcbcfg);
  4197. /* MFP mode return count of enabled TCs for this PF */
  4198. if (pf->hw.func_caps.iscsi)
  4199. enabled_tc = i40e_get_iscsi_tc_map(pf);
  4200. else
  4201. return 1; /* Only TC0 */
  4202. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4203. if (enabled_tc & BIT(i))
  4204. num_tc++;
  4205. }
  4206. return num_tc;
  4207. }
  4208. /**
  4209. * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
  4210. * @pf: PF being queried
  4211. *
  4212. * Return a bitmap for enabled traffic classes for this PF.
  4213. **/
  4214. static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
  4215. {
  4216. /* If DCB is not enabled for this PF then just return default TC */
  4217. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  4218. return I40E_DEFAULT_TRAFFIC_CLASS;
  4219. /* SFP mode we want PF to be enabled for all TCs */
  4220. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  4221. return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
  4222. /* MFP enabled and iSCSI PF type */
  4223. if (pf->hw.func_caps.iscsi)
  4224. return i40e_get_iscsi_tc_map(pf);
  4225. else
  4226. return I40E_DEFAULT_TRAFFIC_CLASS;
  4227. }
  4228. /**
  4229. * i40e_vsi_get_bw_info - Query VSI BW Information
  4230. * @vsi: the VSI being queried
  4231. *
  4232. * Returns 0 on success, negative value on failure
  4233. **/
  4234. static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
  4235. {
  4236. struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
  4237. struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
  4238. struct i40e_pf *pf = vsi->back;
  4239. struct i40e_hw *hw = &pf->hw;
  4240. i40e_status ret;
  4241. u32 tc_bw_max;
  4242. int i;
  4243. /* Get the VSI level BW configuration */
  4244. ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
  4245. if (ret) {
  4246. dev_info(&pf->pdev->dev,
  4247. "couldn't get PF vsi bw config, err %s aq_err %s\n",
  4248. i40e_stat_str(&pf->hw, ret),
  4249. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4250. return -EINVAL;
  4251. }
  4252. /* Get the VSI level BW configuration per TC */
  4253. ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
  4254. NULL);
  4255. if (ret) {
  4256. dev_info(&pf->pdev->dev,
  4257. "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
  4258. i40e_stat_str(&pf->hw, ret),
  4259. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4260. return -EINVAL;
  4261. }
  4262. if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
  4263. dev_info(&pf->pdev->dev,
  4264. "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
  4265. bw_config.tc_valid_bits,
  4266. bw_ets_config.tc_valid_bits);
  4267. /* Still continuing */
  4268. }
  4269. vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
  4270. vsi->bw_max_quanta = bw_config.max_bw;
  4271. tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
  4272. (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
  4273. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4274. vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
  4275. vsi->bw_ets_limit_credits[i] =
  4276. le16_to_cpu(bw_ets_config.credits[i]);
  4277. /* 3 bits out of 4 for each TC */
  4278. vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
  4279. }
  4280. return 0;
  4281. }
  4282. /**
  4283. * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
  4284. * @vsi: the VSI being configured
  4285. * @enabled_tc: TC bitmap
  4286. * @bw_credits: BW shared credits per TC
  4287. *
  4288. * Returns 0 on success, negative value on failure
  4289. **/
  4290. static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
  4291. u8 *bw_share)
  4292. {
  4293. struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
  4294. i40e_status ret;
  4295. int i;
  4296. bw_data.tc_valid_bits = enabled_tc;
  4297. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  4298. bw_data.tc_bw_credits[i] = bw_share[i];
  4299. ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data,
  4300. NULL);
  4301. if (ret) {
  4302. dev_info(&vsi->back->pdev->dev,
  4303. "AQ command Config VSI BW allocation per TC failed = %d\n",
  4304. vsi->back->hw.aq.asq_last_status);
  4305. return -EINVAL;
  4306. }
  4307. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  4308. vsi->info.qs_handle[i] = bw_data.qs_handles[i];
  4309. return 0;
  4310. }
  4311. /**
  4312. * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
  4313. * @vsi: the VSI being configured
  4314. * @enabled_tc: TC map to be enabled
  4315. *
  4316. **/
  4317. static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  4318. {
  4319. struct net_device *netdev = vsi->netdev;
  4320. struct i40e_pf *pf = vsi->back;
  4321. struct i40e_hw *hw = &pf->hw;
  4322. u8 netdev_tc = 0;
  4323. int i;
  4324. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4325. if (!netdev)
  4326. return;
  4327. if (!enabled_tc) {
  4328. netdev_reset_tc(netdev);
  4329. return;
  4330. }
  4331. /* Set up actual enabled TCs on the VSI */
  4332. if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
  4333. return;
  4334. /* set per TC queues for the VSI */
  4335. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4336. /* Only set TC queues for enabled tcs
  4337. *
  4338. * e.g. For a VSI that has TC0 and TC3 enabled the
  4339. * enabled_tc bitmap would be 0x00001001; the driver
  4340. * will set the numtc for netdev as 2 that will be
  4341. * referenced by the netdev layer as TC 0 and 1.
  4342. */
  4343. if (vsi->tc_config.enabled_tc & BIT(i))
  4344. netdev_set_tc_queue(netdev,
  4345. vsi->tc_config.tc_info[i].netdev_tc,
  4346. vsi->tc_config.tc_info[i].qcount,
  4347. vsi->tc_config.tc_info[i].qoffset);
  4348. }
  4349. /* Assign UP2TC map for the VSI */
  4350. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  4351. /* Get the actual TC# for the UP */
  4352. u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
  4353. /* Get the mapped netdev TC# for the UP */
  4354. netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
  4355. netdev_set_prio_tc_map(netdev, i, netdev_tc);
  4356. }
  4357. }
  4358. /**
  4359. * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
  4360. * @vsi: the VSI being configured
  4361. * @ctxt: the ctxt buffer returned from AQ VSI update param command
  4362. **/
  4363. static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
  4364. struct i40e_vsi_context *ctxt)
  4365. {
  4366. /* copy just the sections touched not the entire info
  4367. * since not all sections are valid as returned by
  4368. * update vsi params
  4369. */
  4370. vsi->info.mapping_flags = ctxt->info.mapping_flags;
  4371. memcpy(&vsi->info.queue_mapping,
  4372. &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
  4373. memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
  4374. sizeof(vsi->info.tc_mapping));
  4375. }
  4376. /**
  4377. * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
  4378. * @vsi: VSI to be configured
  4379. * @enabled_tc: TC bitmap
  4380. *
  4381. * This configures a particular VSI for TCs that are mapped to the
  4382. * given TC bitmap. It uses default bandwidth share for TCs across
  4383. * VSIs to configure TC for a particular VSI.
  4384. *
  4385. * NOTE:
  4386. * It is expected that the VSI queues have been quisced before calling
  4387. * this function.
  4388. **/
  4389. static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  4390. {
  4391. u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
  4392. struct i40e_vsi_context ctxt;
  4393. int ret = 0;
  4394. int i;
  4395. /* Check if enabled_tc is same as existing or new TCs */
  4396. if (vsi->tc_config.enabled_tc == enabled_tc)
  4397. return ret;
  4398. /* Enable ETS TCs with equal BW Share for now across all VSIs */
  4399. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4400. if (enabled_tc & BIT(i))
  4401. bw_share[i] = 1;
  4402. }
  4403. ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
  4404. if (ret) {
  4405. dev_info(&vsi->back->pdev->dev,
  4406. "Failed configuring TC map %d for VSI %d\n",
  4407. enabled_tc, vsi->seid);
  4408. goto out;
  4409. }
  4410. /* Update Queue Pairs Mapping for currently enabled UPs */
  4411. ctxt.seid = vsi->seid;
  4412. ctxt.pf_num = vsi->back->hw.pf_id;
  4413. ctxt.vf_num = 0;
  4414. ctxt.uplink_seid = vsi->uplink_seid;
  4415. ctxt.info = vsi->info;
  4416. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  4417. if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
  4418. ctxt.info.valid_sections |=
  4419. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  4420. ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
  4421. }
  4422. /* Update the VSI after updating the VSI queue-mapping information */
  4423. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  4424. if (ret) {
  4425. dev_info(&vsi->back->pdev->dev,
  4426. "Update vsi tc config failed, err %s aq_err %s\n",
  4427. i40e_stat_str(&vsi->back->hw, ret),
  4428. i40e_aq_str(&vsi->back->hw,
  4429. vsi->back->hw.aq.asq_last_status));
  4430. goto out;
  4431. }
  4432. /* update the local VSI info with updated queue map */
  4433. i40e_vsi_update_queue_map(vsi, &ctxt);
  4434. vsi->info.valid_sections = 0;
  4435. /* Update current VSI BW information */
  4436. ret = i40e_vsi_get_bw_info(vsi);
  4437. if (ret) {
  4438. dev_info(&vsi->back->pdev->dev,
  4439. "Failed updating vsi bw info, err %s aq_err %s\n",
  4440. i40e_stat_str(&vsi->back->hw, ret),
  4441. i40e_aq_str(&vsi->back->hw,
  4442. vsi->back->hw.aq.asq_last_status));
  4443. goto out;
  4444. }
  4445. /* Update the netdev TC setup */
  4446. i40e_vsi_config_netdev_tc(vsi, enabled_tc);
  4447. out:
  4448. return ret;
  4449. }
  4450. /**
  4451. * i40e_veb_config_tc - Configure TCs for given VEB
  4452. * @veb: given VEB
  4453. * @enabled_tc: TC bitmap
  4454. *
  4455. * Configures given TC bitmap for VEB (switching) element
  4456. **/
  4457. int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
  4458. {
  4459. struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
  4460. struct i40e_pf *pf = veb->pf;
  4461. int ret = 0;
  4462. int i;
  4463. /* No TCs or already enabled TCs just return */
  4464. if (!enabled_tc || veb->enabled_tc == enabled_tc)
  4465. return ret;
  4466. bw_data.tc_valid_bits = enabled_tc;
  4467. /* bw_data.absolute_credits is not set (relative) */
  4468. /* Enable ETS TCs with equal BW Share for now */
  4469. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4470. if (enabled_tc & BIT(i))
  4471. bw_data.tc_bw_share_credits[i] = 1;
  4472. }
  4473. ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
  4474. &bw_data, NULL);
  4475. if (ret) {
  4476. dev_info(&pf->pdev->dev,
  4477. "VEB bw config failed, err %s aq_err %s\n",
  4478. i40e_stat_str(&pf->hw, ret),
  4479. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4480. goto out;
  4481. }
  4482. /* Update the BW information */
  4483. ret = i40e_veb_get_bw_info(veb);
  4484. if (ret) {
  4485. dev_info(&pf->pdev->dev,
  4486. "Failed getting veb bw config, err %s aq_err %s\n",
  4487. i40e_stat_str(&pf->hw, ret),
  4488. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4489. }
  4490. out:
  4491. return ret;
  4492. }
  4493. #ifdef CONFIG_I40E_DCB
  4494. /**
  4495. * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
  4496. * @pf: PF struct
  4497. *
  4498. * Reconfigure VEB/VSIs on a given PF; it is assumed that
  4499. * the caller would've quiesce all the VSIs before calling
  4500. * this function
  4501. **/
  4502. static void i40e_dcb_reconfigure(struct i40e_pf *pf)
  4503. {
  4504. u8 tc_map = 0;
  4505. int ret;
  4506. u8 v;
  4507. /* Enable the TCs available on PF to all VEBs */
  4508. tc_map = i40e_pf_get_tc_map(pf);
  4509. for (v = 0; v < I40E_MAX_VEB; v++) {
  4510. if (!pf->veb[v])
  4511. continue;
  4512. ret = i40e_veb_config_tc(pf->veb[v], tc_map);
  4513. if (ret) {
  4514. dev_info(&pf->pdev->dev,
  4515. "Failed configuring TC for VEB seid=%d\n",
  4516. pf->veb[v]->seid);
  4517. /* Will try to configure as many components */
  4518. }
  4519. }
  4520. /* Update each VSI */
  4521. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4522. if (!pf->vsi[v])
  4523. continue;
  4524. /* - Enable all TCs for the LAN VSI
  4525. #ifdef I40E_FCOE
  4526. * - For FCoE VSI only enable the TC configured
  4527. * as per the APP TLV
  4528. #endif
  4529. * - For all others keep them at TC0 for now
  4530. */
  4531. if (v == pf->lan_vsi)
  4532. tc_map = i40e_pf_get_tc_map(pf);
  4533. else
  4534. tc_map = I40E_DEFAULT_TRAFFIC_CLASS;
  4535. #ifdef I40E_FCOE
  4536. if (pf->vsi[v]->type == I40E_VSI_FCOE)
  4537. tc_map = i40e_get_fcoe_tc_map(pf);
  4538. #endif /* #ifdef I40E_FCOE */
  4539. ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
  4540. if (ret) {
  4541. dev_info(&pf->pdev->dev,
  4542. "Failed configuring TC for VSI seid=%d\n",
  4543. pf->vsi[v]->seid);
  4544. /* Will try to configure as many components */
  4545. } else {
  4546. /* Re-configure VSI vectors based on updated TC map */
  4547. i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
  4548. if (pf->vsi[v]->netdev)
  4549. i40e_dcbnl_set_all(pf->vsi[v]);
  4550. }
  4551. }
  4552. }
  4553. /**
  4554. * i40e_resume_port_tx - Resume port Tx
  4555. * @pf: PF struct
  4556. *
  4557. * Resume a port's Tx and issue a PF reset in case of failure to
  4558. * resume.
  4559. **/
  4560. static int i40e_resume_port_tx(struct i40e_pf *pf)
  4561. {
  4562. struct i40e_hw *hw = &pf->hw;
  4563. int ret;
  4564. ret = i40e_aq_resume_port_tx(hw, NULL);
  4565. if (ret) {
  4566. dev_info(&pf->pdev->dev,
  4567. "Resume Port Tx failed, err %s aq_err %s\n",
  4568. i40e_stat_str(&pf->hw, ret),
  4569. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4570. /* Schedule PF reset to recover */
  4571. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  4572. i40e_service_event_schedule(pf);
  4573. }
  4574. return ret;
  4575. }
  4576. /**
  4577. * i40e_init_pf_dcb - Initialize DCB configuration
  4578. * @pf: PF being configured
  4579. *
  4580. * Query the current DCB configuration and cache it
  4581. * in the hardware structure
  4582. **/
  4583. static int i40e_init_pf_dcb(struct i40e_pf *pf)
  4584. {
  4585. struct i40e_hw *hw = &pf->hw;
  4586. int err = 0;
  4587. /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */
  4588. if (pf->flags & I40E_FLAG_NO_DCB_SUPPORT)
  4589. goto out;
  4590. /* Get the initial DCB configuration */
  4591. err = i40e_init_dcb(hw);
  4592. if (!err) {
  4593. /* Device/Function is not DCBX capable */
  4594. if ((!hw->func_caps.dcb) ||
  4595. (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
  4596. dev_info(&pf->pdev->dev,
  4597. "DCBX offload is not supported or is disabled for this PF.\n");
  4598. if (pf->flags & I40E_FLAG_MFP_ENABLED)
  4599. goto out;
  4600. } else {
  4601. /* When status is not DISABLED then DCBX in FW */
  4602. pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
  4603. DCB_CAP_DCBX_VER_IEEE;
  4604. pf->flags |= I40E_FLAG_DCB_CAPABLE;
  4605. /* Enable DCB tagging only when more than one TC
  4606. * or explicitly disable if only one TC
  4607. */
  4608. if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
  4609. pf->flags |= I40E_FLAG_DCB_ENABLED;
  4610. else
  4611. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  4612. dev_dbg(&pf->pdev->dev,
  4613. "DCBX offload is supported for this PF.\n");
  4614. }
  4615. } else {
  4616. dev_info(&pf->pdev->dev,
  4617. "Query for DCB configuration failed, err %s aq_err %s\n",
  4618. i40e_stat_str(&pf->hw, err),
  4619. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4620. }
  4621. out:
  4622. return err;
  4623. }
  4624. #endif /* CONFIG_I40E_DCB */
  4625. #define SPEED_SIZE 14
  4626. #define FC_SIZE 8
  4627. /**
  4628. * i40e_print_link_message - print link up or down
  4629. * @vsi: the VSI for which link needs a message
  4630. */
  4631. void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
  4632. {
  4633. enum i40e_aq_link_speed new_speed;
  4634. char *speed = "Unknown";
  4635. char *fc = "Unknown";
  4636. new_speed = vsi->back->hw.phy.link_info.link_speed;
  4637. if ((vsi->current_isup == isup) && (vsi->current_speed == new_speed))
  4638. return;
  4639. vsi->current_isup = isup;
  4640. vsi->current_speed = new_speed;
  4641. if (!isup) {
  4642. netdev_info(vsi->netdev, "NIC Link is Down\n");
  4643. return;
  4644. }
  4645. /* Warn user if link speed on NPAR enabled partition is not at
  4646. * least 10GB
  4647. */
  4648. if (vsi->back->hw.func_caps.npar_enable &&
  4649. (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB ||
  4650. vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB))
  4651. netdev_warn(vsi->netdev,
  4652. "The partition detected link speed that is less than 10Gbps\n");
  4653. switch (vsi->back->hw.phy.link_info.link_speed) {
  4654. case I40E_LINK_SPEED_40GB:
  4655. speed = "40 G";
  4656. break;
  4657. case I40E_LINK_SPEED_20GB:
  4658. speed = "20 G";
  4659. break;
  4660. case I40E_LINK_SPEED_25GB:
  4661. speed = "25 G";
  4662. break;
  4663. case I40E_LINK_SPEED_10GB:
  4664. speed = "10 G";
  4665. break;
  4666. case I40E_LINK_SPEED_1GB:
  4667. speed = "1000 M";
  4668. break;
  4669. case I40E_LINK_SPEED_100MB:
  4670. speed = "100 M";
  4671. break;
  4672. default:
  4673. break;
  4674. }
  4675. switch (vsi->back->hw.fc.current_mode) {
  4676. case I40E_FC_FULL:
  4677. fc = "RX/TX";
  4678. break;
  4679. case I40E_FC_TX_PAUSE:
  4680. fc = "TX";
  4681. break;
  4682. case I40E_FC_RX_PAUSE:
  4683. fc = "RX";
  4684. break;
  4685. default:
  4686. fc = "None";
  4687. break;
  4688. }
  4689. netdev_info(vsi->netdev, "NIC Link is Up %sbps Full Duplex, Flow Control: %s\n",
  4690. speed, fc);
  4691. }
  4692. /**
  4693. * i40e_up_complete - Finish the last steps of bringing up a connection
  4694. * @vsi: the VSI being configured
  4695. **/
  4696. static int i40e_up_complete(struct i40e_vsi *vsi)
  4697. {
  4698. struct i40e_pf *pf = vsi->back;
  4699. int err;
  4700. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  4701. i40e_vsi_configure_msix(vsi);
  4702. else
  4703. i40e_configure_msi_and_legacy(vsi);
  4704. /* start rings */
  4705. err = i40e_vsi_start_rings(vsi);
  4706. if (err)
  4707. return err;
  4708. clear_bit(__I40E_DOWN, &vsi->state);
  4709. i40e_napi_enable_all(vsi);
  4710. i40e_vsi_enable_irq(vsi);
  4711. if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
  4712. (vsi->netdev)) {
  4713. i40e_print_link_message(vsi, true);
  4714. netif_tx_start_all_queues(vsi->netdev);
  4715. netif_carrier_on(vsi->netdev);
  4716. } else if (vsi->netdev) {
  4717. i40e_print_link_message(vsi, false);
  4718. /* need to check for qualified module here*/
  4719. if ((pf->hw.phy.link_info.link_info &
  4720. I40E_AQ_MEDIA_AVAILABLE) &&
  4721. (!(pf->hw.phy.link_info.an_info &
  4722. I40E_AQ_QUALIFIED_MODULE)))
  4723. netdev_err(vsi->netdev,
  4724. "the driver failed to link because an unqualified module was detected.");
  4725. }
  4726. /* replay FDIR SB filters */
  4727. if (vsi->type == I40E_VSI_FDIR) {
  4728. /* reset fd counters */
  4729. pf->fd_add_err = pf->fd_atr_cnt = 0;
  4730. if (pf->fd_tcp_rule > 0) {
  4731. pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
  4732. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  4733. dev_info(&pf->pdev->dev, "Forcing ATR off, sideband rules for TCP/IPv4 exist\n");
  4734. pf->fd_tcp_rule = 0;
  4735. }
  4736. i40e_fdir_filter_restore(vsi);
  4737. }
  4738. /* On the next run of the service_task, notify any clients of the new
  4739. * opened netdev
  4740. */
  4741. pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  4742. i40e_service_event_schedule(pf);
  4743. return 0;
  4744. }
  4745. /**
  4746. * i40e_vsi_reinit_locked - Reset the VSI
  4747. * @vsi: the VSI being configured
  4748. *
  4749. * Rebuild the ring structs after some configuration
  4750. * has changed, e.g. MTU size.
  4751. **/
  4752. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
  4753. {
  4754. struct i40e_pf *pf = vsi->back;
  4755. WARN_ON(in_interrupt());
  4756. while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
  4757. usleep_range(1000, 2000);
  4758. i40e_down(vsi);
  4759. i40e_up(vsi);
  4760. clear_bit(__I40E_CONFIG_BUSY, &pf->state);
  4761. }
  4762. /**
  4763. * i40e_up - Bring the connection back up after being down
  4764. * @vsi: the VSI being configured
  4765. **/
  4766. int i40e_up(struct i40e_vsi *vsi)
  4767. {
  4768. int err;
  4769. err = i40e_vsi_configure(vsi);
  4770. if (!err)
  4771. err = i40e_up_complete(vsi);
  4772. return err;
  4773. }
  4774. /**
  4775. * i40e_down - Shutdown the connection processing
  4776. * @vsi: the VSI being stopped
  4777. **/
  4778. void i40e_down(struct i40e_vsi *vsi)
  4779. {
  4780. int i;
  4781. /* It is assumed that the caller of this function
  4782. * sets the vsi->state __I40E_DOWN bit.
  4783. */
  4784. if (vsi->netdev) {
  4785. netif_carrier_off(vsi->netdev);
  4786. netif_tx_disable(vsi->netdev);
  4787. }
  4788. i40e_vsi_disable_irq(vsi);
  4789. i40e_vsi_stop_rings(vsi);
  4790. i40e_napi_disable_all(vsi);
  4791. for (i = 0; i < vsi->num_queue_pairs; i++) {
  4792. i40e_clean_tx_ring(vsi->tx_rings[i]);
  4793. i40e_clean_rx_ring(vsi->rx_rings[i]);
  4794. }
  4795. i40e_notify_client_of_netdev_close(vsi, false);
  4796. }
  4797. /**
  4798. * i40e_setup_tc - configure multiple traffic classes
  4799. * @netdev: net device to configure
  4800. * @tc: number of traffic classes to enable
  4801. **/
  4802. static int i40e_setup_tc(struct net_device *netdev, u8 tc)
  4803. {
  4804. struct i40e_netdev_priv *np = netdev_priv(netdev);
  4805. struct i40e_vsi *vsi = np->vsi;
  4806. struct i40e_pf *pf = vsi->back;
  4807. u8 enabled_tc = 0;
  4808. int ret = -EINVAL;
  4809. int i;
  4810. /* Check if DCB enabled to continue */
  4811. if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
  4812. netdev_info(netdev, "DCB is not enabled for adapter\n");
  4813. goto exit;
  4814. }
  4815. /* Check if MFP enabled */
  4816. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  4817. netdev_info(netdev, "Configuring TC not supported in MFP mode\n");
  4818. goto exit;
  4819. }
  4820. /* Check whether tc count is within enabled limit */
  4821. if (tc > i40e_pf_get_num_tc(pf)) {
  4822. netdev_info(netdev, "TC count greater than enabled on link for adapter\n");
  4823. goto exit;
  4824. }
  4825. /* Generate TC map for number of tc requested */
  4826. for (i = 0; i < tc; i++)
  4827. enabled_tc |= BIT(i);
  4828. /* Requesting same TC configuration as already enabled */
  4829. if (enabled_tc == vsi->tc_config.enabled_tc)
  4830. return 0;
  4831. /* Quiesce VSI queues */
  4832. i40e_quiesce_vsi(vsi);
  4833. /* Configure VSI for enabled TCs */
  4834. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  4835. if (ret) {
  4836. netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
  4837. vsi->seid);
  4838. goto exit;
  4839. }
  4840. /* Unquiesce VSI */
  4841. i40e_unquiesce_vsi(vsi);
  4842. exit:
  4843. return ret;
  4844. }
  4845. #ifdef I40E_FCOE
  4846. int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto,
  4847. struct tc_to_netdev *tc)
  4848. #else
  4849. static int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto,
  4850. struct tc_to_netdev *tc)
  4851. #endif
  4852. {
  4853. if (handle != TC_H_ROOT || tc->type != TC_SETUP_MQPRIO)
  4854. return -EINVAL;
  4855. return i40e_setup_tc(netdev, tc->tc);
  4856. }
  4857. /**
  4858. * i40e_open - Called when a network interface is made active
  4859. * @netdev: network interface device structure
  4860. *
  4861. * The open entry point is called when a network interface is made
  4862. * active by the system (IFF_UP). At this point all resources needed
  4863. * for transmit and receive operations are allocated, the interrupt
  4864. * handler is registered with the OS, the netdev watchdog subtask is
  4865. * enabled, and the stack is notified that the interface is ready.
  4866. *
  4867. * Returns 0 on success, negative value on failure
  4868. **/
  4869. int i40e_open(struct net_device *netdev)
  4870. {
  4871. struct i40e_netdev_priv *np = netdev_priv(netdev);
  4872. struct i40e_vsi *vsi = np->vsi;
  4873. struct i40e_pf *pf = vsi->back;
  4874. int err;
  4875. /* disallow open during test or if eeprom is broken */
  4876. if (test_bit(__I40E_TESTING, &pf->state) ||
  4877. test_bit(__I40E_BAD_EEPROM, &pf->state))
  4878. return -EBUSY;
  4879. netif_carrier_off(netdev);
  4880. err = i40e_vsi_open(vsi);
  4881. if (err)
  4882. return err;
  4883. /* configure global TSO hardware offload settings */
  4884. wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
  4885. TCP_FLAG_FIN) >> 16);
  4886. wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
  4887. TCP_FLAG_FIN |
  4888. TCP_FLAG_CWR) >> 16);
  4889. wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
  4890. udp_tunnel_get_rx_info(netdev);
  4891. return 0;
  4892. }
  4893. /**
  4894. * i40e_vsi_open -
  4895. * @vsi: the VSI to open
  4896. *
  4897. * Finish initialization of the VSI.
  4898. *
  4899. * Returns 0 on success, negative value on failure
  4900. **/
  4901. int i40e_vsi_open(struct i40e_vsi *vsi)
  4902. {
  4903. struct i40e_pf *pf = vsi->back;
  4904. char int_name[I40E_INT_NAME_STR_LEN];
  4905. int err;
  4906. /* allocate descriptors */
  4907. err = i40e_vsi_setup_tx_resources(vsi);
  4908. if (err)
  4909. goto err_setup_tx;
  4910. err = i40e_vsi_setup_rx_resources(vsi);
  4911. if (err)
  4912. goto err_setup_rx;
  4913. err = i40e_vsi_configure(vsi);
  4914. if (err)
  4915. goto err_setup_rx;
  4916. if (vsi->netdev) {
  4917. snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
  4918. dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
  4919. err = i40e_vsi_request_irq(vsi, int_name);
  4920. if (err)
  4921. goto err_setup_rx;
  4922. /* Notify the stack of the actual queue counts. */
  4923. err = netif_set_real_num_tx_queues(vsi->netdev,
  4924. vsi->num_queue_pairs);
  4925. if (err)
  4926. goto err_set_queues;
  4927. err = netif_set_real_num_rx_queues(vsi->netdev,
  4928. vsi->num_queue_pairs);
  4929. if (err)
  4930. goto err_set_queues;
  4931. } else if (vsi->type == I40E_VSI_FDIR) {
  4932. snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir",
  4933. dev_driver_string(&pf->pdev->dev),
  4934. dev_name(&pf->pdev->dev));
  4935. err = i40e_vsi_request_irq(vsi, int_name);
  4936. } else {
  4937. err = -EINVAL;
  4938. goto err_setup_rx;
  4939. }
  4940. err = i40e_up_complete(vsi);
  4941. if (err)
  4942. goto err_up_complete;
  4943. return 0;
  4944. err_up_complete:
  4945. i40e_down(vsi);
  4946. err_set_queues:
  4947. i40e_vsi_free_irq(vsi);
  4948. err_setup_rx:
  4949. i40e_vsi_free_rx_resources(vsi);
  4950. err_setup_tx:
  4951. i40e_vsi_free_tx_resources(vsi);
  4952. if (vsi == pf->vsi[pf->lan_vsi])
  4953. i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
  4954. return err;
  4955. }
  4956. /**
  4957. * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
  4958. * @pf: Pointer to PF
  4959. *
  4960. * This function destroys the hlist where all the Flow Director
  4961. * filters were saved.
  4962. **/
  4963. static void i40e_fdir_filter_exit(struct i40e_pf *pf)
  4964. {
  4965. struct i40e_fdir_filter *filter;
  4966. struct hlist_node *node2;
  4967. hlist_for_each_entry_safe(filter, node2,
  4968. &pf->fdir_filter_list, fdir_node) {
  4969. hlist_del(&filter->fdir_node);
  4970. kfree(filter);
  4971. }
  4972. pf->fdir_pf_active_filters = 0;
  4973. }
  4974. /**
  4975. * i40e_close - Disables a network interface
  4976. * @netdev: network interface device structure
  4977. *
  4978. * The close entry point is called when an interface is de-activated
  4979. * by the OS. The hardware is still under the driver's control, but
  4980. * this netdev interface is disabled.
  4981. *
  4982. * Returns 0, this is not allowed to fail
  4983. **/
  4984. int i40e_close(struct net_device *netdev)
  4985. {
  4986. struct i40e_netdev_priv *np = netdev_priv(netdev);
  4987. struct i40e_vsi *vsi = np->vsi;
  4988. i40e_vsi_close(vsi);
  4989. return 0;
  4990. }
  4991. /**
  4992. * i40e_do_reset - Start a PF or Core Reset sequence
  4993. * @pf: board private structure
  4994. * @reset_flags: which reset is requested
  4995. *
  4996. * The essential difference in resets is that the PF Reset
  4997. * doesn't clear the packet buffers, doesn't reset the PE
  4998. * firmware, and doesn't bother the other PFs on the chip.
  4999. **/
  5000. void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags)
  5001. {
  5002. u32 val;
  5003. WARN_ON(in_interrupt());
  5004. /* do the biggest reset indicated */
  5005. if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) {
  5006. /* Request a Global Reset
  5007. *
  5008. * This will start the chip's countdown to the actual full
  5009. * chip reset event, and a warning interrupt to be sent
  5010. * to all PFs, including the requestor. Our handler
  5011. * for the warning interrupt will deal with the shutdown
  5012. * and recovery of the switch setup.
  5013. */
  5014. dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
  5015. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  5016. val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
  5017. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  5018. } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) {
  5019. /* Request a Core Reset
  5020. *
  5021. * Same as Global Reset, except does *not* include the MAC/PHY
  5022. */
  5023. dev_dbg(&pf->pdev->dev, "CoreR requested\n");
  5024. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  5025. val |= I40E_GLGEN_RTRIG_CORER_MASK;
  5026. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  5027. i40e_flush(&pf->hw);
  5028. } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) {
  5029. /* Request a PF Reset
  5030. *
  5031. * Resets only the PF-specific registers
  5032. *
  5033. * This goes directly to the tear-down and rebuild of
  5034. * the switch, since we need to do all the recovery as
  5035. * for the Core Reset.
  5036. */
  5037. dev_dbg(&pf->pdev->dev, "PFR requested\n");
  5038. i40e_handle_reset_warning(pf);
  5039. } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) {
  5040. int v;
  5041. /* Find the VSI(s) that requested a re-init */
  5042. dev_info(&pf->pdev->dev,
  5043. "VSI reinit requested\n");
  5044. for (v = 0; v < pf->num_alloc_vsi; v++) {
  5045. struct i40e_vsi *vsi = pf->vsi[v];
  5046. if (vsi != NULL &&
  5047. test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) {
  5048. i40e_vsi_reinit_locked(pf->vsi[v]);
  5049. clear_bit(__I40E_REINIT_REQUESTED, &vsi->state);
  5050. }
  5051. }
  5052. } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) {
  5053. int v;
  5054. /* Find the VSI(s) that needs to be brought down */
  5055. dev_info(&pf->pdev->dev, "VSI down requested\n");
  5056. for (v = 0; v < pf->num_alloc_vsi; v++) {
  5057. struct i40e_vsi *vsi = pf->vsi[v];
  5058. if (vsi != NULL &&
  5059. test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) {
  5060. set_bit(__I40E_DOWN, &vsi->state);
  5061. i40e_down(vsi);
  5062. clear_bit(__I40E_DOWN_REQUESTED, &vsi->state);
  5063. }
  5064. }
  5065. } else {
  5066. dev_info(&pf->pdev->dev,
  5067. "bad reset request 0x%08x\n", reset_flags);
  5068. }
  5069. }
  5070. #ifdef CONFIG_I40E_DCB
  5071. /**
  5072. * i40e_dcb_need_reconfig - Check if DCB needs reconfig
  5073. * @pf: board private structure
  5074. * @old_cfg: current DCB config
  5075. * @new_cfg: new DCB config
  5076. **/
  5077. bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
  5078. struct i40e_dcbx_config *old_cfg,
  5079. struct i40e_dcbx_config *new_cfg)
  5080. {
  5081. bool need_reconfig = false;
  5082. /* Check if ETS configuration has changed */
  5083. if (memcmp(&new_cfg->etscfg,
  5084. &old_cfg->etscfg,
  5085. sizeof(new_cfg->etscfg))) {
  5086. /* If Priority Table has changed reconfig is needed */
  5087. if (memcmp(&new_cfg->etscfg.prioritytable,
  5088. &old_cfg->etscfg.prioritytable,
  5089. sizeof(new_cfg->etscfg.prioritytable))) {
  5090. need_reconfig = true;
  5091. dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
  5092. }
  5093. if (memcmp(&new_cfg->etscfg.tcbwtable,
  5094. &old_cfg->etscfg.tcbwtable,
  5095. sizeof(new_cfg->etscfg.tcbwtable)))
  5096. dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
  5097. if (memcmp(&new_cfg->etscfg.tsatable,
  5098. &old_cfg->etscfg.tsatable,
  5099. sizeof(new_cfg->etscfg.tsatable)))
  5100. dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
  5101. }
  5102. /* Check if PFC configuration has changed */
  5103. if (memcmp(&new_cfg->pfc,
  5104. &old_cfg->pfc,
  5105. sizeof(new_cfg->pfc))) {
  5106. need_reconfig = true;
  5107. dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
  5108. }
  5109. /* Check if APP Table has changed */
  5110. if (memcmp(&new_cfg->app,
  5111. &old_cfg->app,
  5112. sizeof(new_cfg->app))) {
  5113. need_reconfig = true;
  5114. dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
  5115. }
  5116. dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig);
  5117. return need_reconfig;
  5118. }
  5119. /**
  5120. * i40e_handle_lldp_event - Handle LLDP Change MIB event
  5121. * @pf: board private structure
  5122. * @e: event info posted on ARQ
  5123. **/
  5124. static int i40e_handle_lldp_event(struct i40e_pf *pf,
  5125. struct i40e_arq_event_info *e)
  5126. {
  5127. struct i40e_aqc_lldp_get_mib *mib =
  5128. (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
  5129. struct i40e_hw *hw = &pf->hw;
  5130. struct i40e_dcbx_config tmp_dcbx_cfg;
  5131. bool need_reconfig = false;
  5132. int ret = 0;
  5133. u8 type;
  5134. /* Not DCB capable or capability disabled */
  5135. if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
  5136. return ret;
  5137. /* Ignore if event is not for Nearest Bridge */
  5138. type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
  5139. & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
  5140. dev_dbg(&pf->pdev->dev, "LLDP event mib bridge type 0x%x\n", type);
  5141. if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
  5142. return ret;
  5143. /* Check MIB Type and return if event for Remote MIB update */
  5144. type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
  5145. dev_dbg(&pf->pdev->dev,
  5146. "LLDP event mib type %s\n", type ? "remote" : "local");
  5147. if (type == I40E_AQ_LLDP_MIB_REMOTE) {
  5148. /* Update the remote cached instance and return */
  5149. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
  5150. I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
  5151. &hw->remote_dcbx_config);
  5152. goto exit;
  5153. }
  5154. /* Store the old configuration */
  5155. tmp_dcbx_cfg = hw->local_dcbx_config;
  5156. /* Reset the old DCBx configuration data */
  5157. memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config));
  5158. /* Get updated DCBX data from firmware */
  5159. ret = i40e_get_dcb_config(&pf->hw);
  5160. if (ret) {
  5161. dev_info(&pf->pdev->dev,
  5162. "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
  5163. i40e_stat_str(&pf->hw, ret),
  5164. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5165. goto exit;
  5166. }
  5167. /* No change detected in DCBX configs */
  5168. if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config,
  5169. sizeof(tmp_dcbx_cfg))) {
  5170. dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
  5171. goto exit;
  5172. }
  5173. need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg,
  5174. &hw->local_dcbx_config);
  5175. i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config);
  5176. if (!need_reconfig)
  5177. goto exit;
  5178. /* Enable DCB tagging only when more than one TC */
  5179. if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
  5180. pf->flags |= I40E_FLAG_DCB_ENABLED;
  5181. else
  5182. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  5183. set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state);
  5184. /* Reconfiguration needed quiesce all VSIs */
  5185. i40e_pf_quiesce_all_vsi(pf);
  5186. /* Changes in configuration update VEB/VSI */
  5187. i40e_dcb_reconfigure(pf);
  5188. ret = i40e_resume_port_tx(pf);
  5189. clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state);
  5190. /* In case of error no point in resuming VSIs */
  5191. if (ret)
  5192. goto exit;
  5193. /* Wait for the PF's queues to be disabled */
  5194. ret = i40e_pf_wait_queues_disabled(pf);
  5195. if (ret) {
  5196. /* Schedule PF reset to recover */
  5197. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  5198. i40e_service_event_schedule(pf);
  5199. } else {
  5200. i40e_pf_unquiesce_all_vsi(pf);
  5201. /* Notify the client for the DCB changes */
  5202. i40e_notify_client_of_l2_param_changes(pf->vsi[pf->lan_vsi]);
  5203. }
  5204. exit:
  5205. return ret;
  5206. }
  5207. #endif /* CONFIG_I40E_DCB */
  5208. /**
  5209. * i40e_do_reset_safe - Protected reset path for userland calls.
  5210. * @pf: board private structure
  5211. * @reset_flags: which reset is requested
  5212. *
  5213. **/
  5214. void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
  5215. {
  5216. rtnl_lock();
  5217. i40e_do_reset(pf, reset_flags);
  5218. rtnl_unlock();
  5219. }
  5220. /**
  5221. * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
  5222. * @pf: board private structure
  5223. * @e: event info posted on ARQ
  5224. *
  5225. * Handler for LAN Queue Overflow Event generated by the firmware for PF
  5226. * and VF queues
  5227. **/
  5228. static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
  5229. struct i40e_arq_event_info *e)
  5230. {
  5231. struct i40e_aqc_lan_overflow *data =
  5232. (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
  5233. u32 queue = le32_to_cpu(data->prtdcb_rupto);
  5234. u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
  5235. struct i40e_hw *hw = &pf->hw;
  5236. struct i40e_vf *vf;
  5237. u16 vf_id;
  5238. dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
  5239. queue, qtx_ctl);
  5240. /* Queue belongs to VF, find the VF and issue VF reset */
  5241. if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
  5242. >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
  5243. vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
  5244. >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
  5245. vf_id -= hw->func_caps.vf_base_id;
  5246. vf = &pf->vf[vf_id];
  5247. i40e_vc_notify_vf_reset(vf);
  5248. /* Allow VF to process pending reset notification */
  5249. msleep(20);
  5250. i40e_reset_vf(vf, false);
  5251. }
  5252. }
  5253. /**
  5254. * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
  5255. * @pf: board private structure
  5256. **/
  5257. u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf)
  5258. {
  5259. u32 val, fcnt_prog;
  5260. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  5261. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK);
  5262. return fcnt_prog;
  5263. }
  5264. /**
  5265. * i40e_get_current_fd_count - Get total FD filters programmed for this PF
  5266. * @pf: board private structure
  5267. **/
  5268. u32 i40e_get_current_fd_count(struct i40e_pf *pf)
  5269. {
  5270. u32 val, fcnt_prog;
  5271. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  5272. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
  5273. ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
  5274. I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
  5275. return fcnt_prog;
  5276. }
  5277. /**
  5278. * i40e_get_global_fd_count - Get total FD filters programmed on device
  5279. * @pf: board private structure
  5280. **/
  5281. u32 i40e_get_global_fd_count(struct i40e_pf *pf)
  5282. {
  5283. u32 val, fcnt_prog;
  5284. val = rd32(&pf->hw, I40E_GLQF_FDCNT_0);
  5285. fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) +
  5286. ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >>
  5287. I40E_GLQF_FDCNT_0_BESTCNT_SHIFT);
  5288. return fcnt_prog;
  5289. }
  5290. /**
  5291. * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
  5292. * @pf: board private structure
  5293. **/
  5294. void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
  5295. {
  5296. struct i40e_fdir_filter *filter;
  5297. u32 fcnt_prog, fcnt_avail;
  5298. struct hlist_node *node;
  5299. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  5300. return;
  5301. /* Check if, FD SB or ATR was auto disabled and if there is enough room
  5302. * to re-enable
  5303. */
  5304. fcnt_prog = i40e_get_global_fd_count(pf);
  5305. fcnt_avail = pf->fdir_pf_filter_count;
  5306. if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) ||
  5307. (pf->fd_add_err == 0) ||
  5308. (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) {
  5309. if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
  5310. (pf->auto_disable_flags & I40E_FLAG_FD_SB_ENABLED)) {
  5311. pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
  5312. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  5313. dev_info(&pf->pdev->dev, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
  5314. }
  5315. }
  5316. /* Wait for some more space to be available to turn on ATR. We also
  5317. * must check that no existing ntuple rules for TCP are in effect
  5318. */
  5319. if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) {
  5320. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  5321. (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED) &&
  5322. (pf->fd_tcp_rule == 0)) {
  5323. pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  5324. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  5325. dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table and there are no conflicting ntuple rules\n");
  5326. }
  5327. }
  5328. /* if hw had a problem adding a filter, delete it */
  5329. if (pf->fd_inv > 0) {
  5330. hlist_for_each_entry_safe(filter, node,
  5331. &pf->fdir_filter_list, fdir_node) {
  5332. if (filter->fd_id == pf->fd_inv) {
  5333. hlist_del(&filter->fdir_node);
  5334. kfree(filter);
  5335. pf->fdir_pf_active_filters--;
  5336. }
  5337. }
  5338. }
  5339. }
  5340. #define I40E_MIN_FD_FLUSH_INTERVAL 10
  5341. #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
  5342. /**
  5343. * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
  5344. * @pf: board private structure
  5345. **/
  5346. static void i40e_fdir_flush_and_replay(struct i40e_pf *pf)
  5347. {
  5348. unsigned long min_flush_time;
  5349. int flush_wait_retry = 50;
  5350. bool disable_atr = false;
  5351. int fd_room;
  5352. int reg;
  5353. if (!time_after(jiffies, pf->fd_flush_timestamp +
  5354. (I40E_MIN_FD_FLUSH_INTERVAL * HZ)))
  5355. return;
  5356. /* If the flush is happening too quick and we have mostly SB rules we
  5357. * should not re-enable ATR for some time.
  5358. */
  5359. min_flush_time = pf->fd_flush_timestamp +
  5360. (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ);
  5361. fd_room = pf->fdir_pf_filter_count - pf->fdir_pf_active_filters;
  5362. if (!(time_after(jiffies, min_flush_time)) &&
  5363. (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) {
  5364. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  5365. dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n");
  5366. disable_atr = true;
  5367. }
  5368. pf->fd_flush_timestamp = jiffies;
  5369. pf->auto_disable_flags |= I40E_FLAG_FD_ATR_ENABLED;
  5370. /* flush all filters */
  5371. wr32(&pf->hw, I40E_PFQF_CTL_1,
  5372. I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
  5373. i40e_flush(&pf->hw);
  5374. pf->fd_flush_cnt++;
  5375. pf->fd_add_err = 0;
  5376. do {
  5377. /* Check FD flush status every 5-6msec */
  5378. usleep_range(5000, 6000);
  5379. reg = rd32(&pf->hw, I40E_PFQF_CTL_1);
  5380. if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
  5381. break;
  5382. } while (flush_wait_retry--);
  5383. if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) {
  5384. dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n");
  5385. } else {
  5386. /* replay sideband filters */
  5387. i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]);
  5388. if (!disable_atr)
  5389. pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  5390. clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state);
  5391. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  5392. dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n");
  5393. }
  5394. }
  5395. /**
  5396. * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
  5397. * @pf: board private structure
  5398. **/
  5399. u32 i40e_get_current_atr_cnt(struct i40e_pf *pf)
  5400. {
  5401. return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters;
  5402. }
  5403. /* We can see up to 256 filter programming desc in transit if the filters are
  5404. * being applied really fast; before we see the first
  5405. * filter miss error on Rx queue 0. Accumulating enough error messages before
  5406. * reacting will make sure we don't cause flush too often.
  5407. */
  5408. #define I40E_MAX_FD_PROGRAM_ERROR 256
  5409. /**
  5410. * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
  5411. * @pf: board private structure
  5412. **/
  5413. static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
  5414. {
  5415. /* if interface is down do nothing */
  5416. if (test_bit(__I40E_DOWN, &pf->state))
  5417. return;
  5418. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  5419. i40e_fdir_flush_and_replay(pf);
  5420. i40e_fdir_check_and_reenable(pf);
  5421. }
  5422. /**
  5423. * i40e_vsi_link_event - notify VSI of a link event
  5424. * @vsi: vsi to be notified
  5425. * @link_up: link up or down
  5426. **/
  5427. static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
  5428. {
  5429. if (!vsi || test_bit(__I40E_DOWN, &vsi->state))
  5430. return;
  5431. switch (vsi->type) {
  5432. case I40E_VSI_MAIN:
  5433. #ifdef I40E_FCOE
  5434. case I40E_VSI_FCOE:
  5435. #endif
  5436. if (!vsi->netdev || !vsi->netdev_registered)
  5437. break;
  5438. if (link_up) {
  5439. netif_carrier_on(vsi->netdev);
  5440. netif_tx_wake_all_queues(vsi->netdev);
  5441. } else {
  5442. netif_carrier_off(vsi->netdev);
  5443. netif_tx_stop_all_queues(vsi->netdev);
  5444. }
  5445. break;
  5446. case I40E_VSI_SRIOV:
  5447. case I40E_VSI_VMDQ2:
  5448. case I40E_VSI_CTRL:
  5449. case I40E_VSI_IWARP:
  5450. case I40E_VSI_MIRROR:
  5451. default:
  5452. /* there is no notification for other VSIs */
  5453. break;
  5454. }
  5455. }
  5456. /**
  5457. * i40e_veb_link_event - notify elements on the veb of a link event
  5458. * @veb: veb to be notified
  5459. * @link_up: link up or down
  5460. **/
  5461. static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
  5462. {
  5463. struct i40e_pf *pf;
  5464. int i;
  5465. if (!veb || !veb->pf)
  5466. return;
  5467. pf = veb->pf;
  5468. /* depth first... */
  5469. for (i = 0; i < I40E_MAX_VEB; i++)
  5470. if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
  5471. i40e_veb_link_event(pf->veb[i], link_up);
  5472. /* ... now the local VSIs */
  5473. for (i = 0; i < pf->num_alloc_vsi; i++)
  5474. if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
  5475. i40e_vsi_link_event(pf->vsi[i], link_up);
  5476. }
  5477. /**
  5478. * i40e_link_event - Update netif_carrier status
  5479. * @pf: board private structure
  5480. **/
  5481. static void i40e_link_event(struct i40e_pf *pf)
  5482. {
  5483. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  5484. u8 new_link_speed, old_link_speed;
  5485. i40e_status status;
  5486. bool new_link, old_link;
  5487. /* save off old link status information */
  5488. pf->hw.phy.link_info_old = pf->hw.phy.link_info;
  5489. /* set this to force the get_link_status call to refresh state */
  5490. pf->hw.phy.get_link_info = true;
  5491. old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
  5492. status = i40e_get_link_status(&pf->hw, &new_link);
  5493. if (status) {
  5494. dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n",
  5495. status);
  5496. return;
  5497. }
  5498. old_link_speed = pf->hw.phy.link_info_old.link_speed;
  5499. new_link_speed = pf->hw.phy.link_info.link_speed;
  5500. if (new_link == old_link &&
  5501. new_link_speed == old_link_speed &&
  5502. (test_bit(__I40E_DOWN, &vsi->state) ||
  5503. new_link == netif_carrier_ok(vsi->netdev)))
  5504. return;
  5505. if (!test_bit(__I40E_DOWN, &vsi->state))
  5506. i40e_print_link_message(vsi, new_link);
  5507. /* Notify the base of the switch tree connected to
  5508. * the link. Floating VEBs are not notified.
  5509. */
  5510. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  5511. i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
  5512. else
  5513. i40e_vsi_link_event(vsi, new_link);
  5514. if (pf->vf)
  5515. i40e_vc_notify_link_state(pf);
  5516. if (pf->flags & I40E_FLAG_PTP)
  5517. i40e_ptp_set_increment(pf);
  5518. }
  5519. /**
  5520. * i40e_watchdog_subtask - periodic checks not using event driven response
  5521. * @pf: board private structure
  5522. **/
  5523. static void i40e_watchdog_subtask(struct i40e_pf *pf)
  5524. {
  5525. int i;
  5526. /* if interface is down do nothing */
  5527. if (test_bit(__I40E_DOWN, &pf->state) ||
  5528. test_bit(__I40E_CONFIG_BUSY, &pf->state))
  5529. return;
  5530. /* make sure we don't do these things too often */
  5531. if (time_before(jiffies, (pf->service_timer_previous +
  5532. pf->service_timer_period)))
  5533. return;
  5534. pf->service_timer_previous = jiffies;
  5535. if (pf->flags & I40E_FLAG_LINK_POLLING_ENABLED)
  5536. i40e_link_event(pf);
  5537. /* Update the stats for active netdevs so the network stack
  5538. * can look at updated numbers whenever it cares to
  5539. */
  5540. for (i = 0; i < pf->num_alloc_vsi; i++)
  5541. if (pf->vsi[i] && pf->vsi[i]->netdev)
  5542. i40e_update_stats(pf->vsi[i]);
  5543. if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) {
  5544. /* Update the stats for the active switching components */
  5545. for (i = 0; i < I40E_MAX_VEB; i++)
  5546. if (pf->veb[i])
  5547. i40e_update_veb_stats(pf->veb[i]);
  5548. }
  5549. i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]);
  5550. }
  5551. /**
  5552. * i40e_reset_subtask - Set up for resetting the device and driver
  5553. * @pf: board private structure
  5554. **/
  5555. static void i40e_reset_subtask(struct i40e_pf *pf)
  5556. {
  5557. u32 reset_flags = 0;
  5558. rtnl_lock();
  5559. if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) {
  5560. reset_flags |= BIT(__I40E_REINIT_REQUESTED);
  5561. clear_bit(__I40E_REINIT_REQUESTED, &pf->state);
  5562. }
  5563. if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) {
  5564. reset_flags |= BIT(__I40E_PF_RESET_REQUESTED);
  5565. clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  5566. }
  5567. if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) {
  5568. reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED);
  5569. clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
  5570. }
  5571. if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) {
  5572. reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED);
  5573. clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
  5574. }
  5575. if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) {
  5576. reset_flags |= BIT(__I40E_DOWN_REQUESTED);
  5577. clear_bit(__I40E_DOWN_REQUESTED, &pf->state);
  5578. }
  5579. /* If there's a recovery already waiting, it takes
  5580. * precedence before starting a new reset sequence.
  5581. */
  5582. if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) {
  5583. i40e_handle_reset_warning(pf);
  5584. goto unlock;
  5585. }
  5586. /* If we're already down or resetting, just bail */
  5587. if (reset_flags &&
  5588. !test_bit(__I40E_DOWN, &pf->state) &&
  5589. !test_bit(__I40E_CONFIG_BUSY, &pf->state))
  5590. i40e_do_reset(pf, reset_flags);
  5591. unlock:
  5592. rtnl_unlock();
  5593. }
  5594. /**
  5595. * i40e_handle_link_event - Handle link event
  5596. * @pf: board private structure
  5597. * @e: event info posted on ARQ
  5598. **/
  5599. static void i40e_handle_link_event(struct i40e_pf *pf,
  5600. struct i40e_arq_event_info *e)
  5601. {
  5602. struct i40e_aqc_get_link_status *status =
  5603. (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
  5604. /* Do a new status request to re-enable LSE reporting
  5605. * and load new status information into the hw struct
  5606. * This completely ignores any state information
  5607. * in the ARQ event info, instead choosing to always
  5608. * issue the AQ update link status command.
  5609. */
  5610. i40e_link_event(pf);
  5611. /* check for unqualified module, if link is down */
  5612. if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) &&
  5613. (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) &&
  5614. (!(status->link_info & I40E_AQ_LINK_UP)))
  5615. dev_err(&pf->pdev->dev,
  5616. "The driver failed to link because an unqualified module was detected.\n");
  5617. }
  5618. /**
  5619. * i40e_clean_adminq_subtask - Clean the AdminQ rings
  5620. * @pf: board private structure
  5621. **/
  5622. static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
  5623. {
  5624. struct i40e_arq_event_info event;
  5625. struct i40e_hw *hw = &pf->hw;
  5626. u16 pending, i = 0;
  5627. i40e_status ret;
  5628. u16 opcode;
  5629. u32 oldval;
  5630. u32 val;
  5631. /* Do not run clean AQ when PF reset fails */
  5632. if (test_bit(__I40E_RESET_FAILED, &pf->state))
  5633. return;
  5634. /* check for error indications */
  5635. val = rd32(&pf->hw, pf->hw.aq.arq.len);
  5636. oldval = val;
  5637. if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
  5638. if (hw->debug_mask & I40E_DEBUG_AQ)
  5639. dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
  5640. val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
  5641. }
  5642. if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
  5643. if (hw->debug_mask & I40E_DEBUG_AQ)
  5644. dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
  5645. val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
  5646. pf->arq_overflows++;
  5647. }
  5648. if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
  5649. if (hw->debug_mask & I40E_DEBUG_AQ)
  5650. dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
  5651. val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
  5652. }
  5653. if (oldval != val)
  5654. wr32(&pf->hw, pf->hw.aq.arq.len, val);
  5655. val = rd32(&pf->hw, pf->hw.aq.asq.len);
  5656. oldval = val;
  5657. if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
  5658. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  5659. dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
  5660. val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
  5661. }
  5662. if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
  5663. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  5664. dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
  5665. val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
  5666. }
  5667. if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
  5668. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  5669. dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
  5670. val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
  5671. }
  5672. if (oldval != val)
  5673. wr32(&pf->hw, pf->hw.aq.asq.len, val);
  5674. event.buf_len = I40E_MAX_AQ_BUF_SIZE;
  5675. event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
  5676. if (!event.msg_buf)
  5677. return;
  5678. do {
  5679. ret = i40e_clean_arq_element(hw, &event, &pending);
  5680. if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
  5681. break;
  5682. else if (ret) {
  5683. dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
  5684. break;
  5685. }
  5686. opcode = le16_to_cpu(event.desc.opcode);
  5687. switch (opcode) {
  5688. case i40e_aqc_opc_get_link_status:
  5689. i40e_handle_link_event(pf, &event);
  5690. break;
  5691. case i40e_aqc_opc_send_msg_to_pf:
  5692. ret = i40e_vc_process_vf_msg(pf,
  5693. le16_to_cpu(event.desc.retval),
  5694. le32_to_cpu(event.desc.cookie_high),
  5695. le32_to_cpu(event.desc.cookie_low),
  5696. event.msg_buf,
  5697. event.msg_len);
  5698. break;
  5699. case i40e_aqc_opc_lldp_update_mib:
  5700. dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
  5701. #ifdef CONFIG_I40E_DCB
  5702. rtnl_lock();
  5703. ret = i40e_handle_lldp_event(pf, &event);
  5704. rtnl_unlock();
  5705. #endif /* CONFIG_I40E_DCB */
  5706. break;
  5707. case i40e_aqc_opc_event_lan_overflow:
  5708. dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
  5709. i40e_handle_lan_overflow_event(pf, &event);
  5710. break;
  5711. case i40e_aqc_opc_send_msg_to_peer:
  5712. dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
  5713. break;
  5714. case i40e_aqc_opc_nvm_erase:
  5715. case i40e_aqc_opc_nvm_update:
  5716. case i40e_aqc_opc_oem_post_update:
  5717. i40e_debug(&pf->hw, I40E_DEBUG_NVM,
  5718. "ARQ NVM operation 0x%04x completed\n",
  5719. opcode);
  5720. break;
  5721. default:
  5722. dev_info(&pf->pdev->dev,
  5723. "ARQ: Unknown event 0x%04x ignored\n",
  5724. opcode);
  5725. break;
  5726. }
  5727. } while (pending && (i++ < pf->adminq_work_limit));
  5728. clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
  5729. /* re-enable Admin queue interrupt cause */
  5730. val = rd32(hw, I40E_PFINT_ICR0_ENA);
  5731. val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  5732. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  5733. i40e_flush(hw);
  5734. kfree(event.msg_buf);
  5735. }
  5736. /**
  5737. * i40e_verify_eeprom - make sure eeprom is good to use
  5738. * @pf: board private structure
  5739. **/
  5740. static void i40e_verify_eeprom(struct i40e_pf *pf)
  5741. {
  5742. int err;
  5743. err = i40e_diag_eeprom_test(&pf->hw);
  5744. if (err) {
  5745. /* retry in case of garbage read */
  5746. err = i40e_diag_eeprom_test(&pf->hw);
  5747. if (err) {
  5748. dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
  5749. err);
  5750. set_bit(__I40E_BAD_EEPROM, &pf->state);
  5751. }
  5752. }
  5753. if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) {
  5754. dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
  5755. clear_bit(__I40E_BAD_EEPROM, &pf->state);
  5756. }
  5757. }
  5758. /**
  5759. * i40e_enable_pf_switch_lb
  5760. * @pf: pointer to the PF structure
  5761. *
  5762. * enable switch loop back or die - no point in a return value
  5763. **/
  5764. static void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
  5765. {
  5766. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  5767. struct i40e_vsi_context ctxt;
  5768. int ret;
  5769. ctxt.seid = pf->main_vsi_seid;
  5770. ctxt.pf_num = pf->hw.pf_id;
  5771. ctxt.vf_num = 0;
  5772. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  5773. if (ret) {
  5774. dev_info(&pf->pdev->dev,
  5775. "couldn't get PF vsi config, err %s aq_err %s\n",
  5776. i40e_stat_str(&pf->hw, ret),
  5777. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5778. return;
  5779. }
  5780. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  5781. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  5782. ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  5783. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  5784. if (ret) {
  5785. dev_info(&pf->pdev->dev,
  5786. "update vsi switch failed, err %s aq_err %s\n",
  5787. i40e_stat_str(&pf->hw, ret),
  5788. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5789. }
  5790. }
  5791. /**
  5792. * i40e_disable_pf_switch_lb
  5793. * @pf: pointer to the PF structure
  5794. *
  5795. * disable switch loop back or die - no point in a return value
  5796. **/
  5797. static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
  5798. {
  5799. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  5800. struct i40e_vsi_context ctxt;
  5801. int ret;
  5802. ctxt.seid = pf->main_vsi_seid;
  5803. ctxt.pf_num = pf->hw.pf_id;
  5804. ctxt.vf_num = 0;
  5805. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  5806. if (ret) {
  5807. dev_info(&pf->pdev->dev,
  5808. "couldn't get PF vsi config, err %s aq_err %s\n",
  5809. i40e_stat_str(&pf->hw, ret),
  5810. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5811. return;
  5812. }
  5813. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  5814. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  5815. ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  5816. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  5817. if (ret) {
  5818. dev_info(&pf->pdev->dev,
  5819. "update vsi switch failed, err %s aq_err %s\n",
  5820. i40e_stat_str(&pf->hw, ret),
  5821. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5822. }
  5823. }
  5824. /**
  5825. * i40e_config_bridge_mode - Configure the HW bridge mode
  5826. * @veb: pointer to the bridge instance
  5827. *
  5828. * Configure the loop back mode for the LAN VSI that is downlink to the
  5829. * specified HW bridge instance. It is expected this function is called
  5830. * when a new HW bridge is instantiated.
  5831. **/
  5832. static void i40e_config_bridge_mode(struct i40e_veb *veb)
  5833. {
  5834. struct i40e_pf *pf = veb->pf;
  5835. if (pf->hw.debug_mask & I40E_DEBUG_LAN)
  5836. dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n",
  5837. veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
  5838. if (veb->bridge_mode & BRIDGE_MODE_VEPA)
  5839. i40e_disable_pf_switch_lb(pf);
  5840. else
  5841. i40e_enable_pf_switch_lb(pf);
  5842. }
  5843. /**
  5844. * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
  5845. * @veb: pointer to the VEB instance
  5846. *
  5847. * This is a recursive function that first builds the attached VSIs then
  5848. * recurses in to build the next layer of VEB. We track the connections
  5849. * through our own index numbers because the seid's from the HW could
  5850. * change across the reset.
  5851. **/
  5852. static int i40e_reconstitute_veb(struct i40e_veb *veb)
  5853. {
  5854. struct i40e_vsi *ctl_vsi = NULL;
  5855. struct i40e_pf *pf = veb->pf;
  5856. int v, veb_idx;
  5857. int ret;
  5858. /* build VSI that owns this VEB, temporarily attached to base VEB */
  5859. for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
  5860. if (pf->vsi[v] &&
  5861. pf->vsi[v]->veb_idx == veb->idx &&
  5862. pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
  5863. ctl_vsi = pf->vsi[v];
  5864. break;
  5865. }
  5866. }
  5867. if (!ctl_vsi) {
  5868. dev_info(&pf->pdev->dev,
  5869. "missing owner VSI for veb_idx %d\n", veb->idx);
  5870. ret = -ENOENT;
  5871. goto end_reconstitute;
  5872. }
  5873. if (ctl_vsi != pf->vsi[pf->lan_vsi])
  5874. ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  5875. ret = i40e_add_vsi(ctl_vsi);
  5876. if (ret) {
  5877. dev_info(&pf->pdev->dev,
  5878. "rebuild of veb_idx %d owner VSI failed: %d\n",
  5879. veb->idx, ret);
  5880. goto end_reconstitute;
  5881. }
  5882. i40e_vsi_reset_stats(ctl_vsi);
  5883. /* create the VEB in the switch and move the VSI onto the VEB */
  5884. ret = i40e_add_veb(veb, ctl_vsi);
  5885. if (ret)
  5886. goto end_reconstitute;
  5887. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
  5888. veb->bridge_mode = BRIDGE_MODE_VEB;
  5889. else
  5890. veb->bridge_mode = BRIDGE_MODE_VEPA;
  5891. i40e_config_bridge_mode(veb);
  5892. /* create the remaining VSIs attached to this VEB */
  5893. for (v = 0; v < pf->num_alloc_vsi; v++) {
  5894. if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
  5895. continue;
  5896. if (pf->vsi[v]->veb_idx == veb->idx) {
  5897. struct i40e_vsi *vsi = pf->vsi[v];
  5898. vsi->uplink_seid = veb->seid;
  5899. ret = i40e_add_vsi(vsi);
  5900. if (ret) {
  5901. dev_info(&pf->pdev->dev,
  5902. "rebuild of vsi_idx %d failed: %d\n",
  5903. v, ret);
  5904. goto end_reconstitute;
  5905. }
  5906. i40e_vsi_reset_stats(vsi);
  5907. }
  5908. }
  5909. /* create any VEBs attached to this VEB - RECURSION */
  5910. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  5911. if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
  5912. pf->veb[veb_idx]->uplink_seid = veb->seid;
  5913. ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
  5914. if (ret)
  5915. break;
  5916. }
  5917. }
  5918. end_reconstitute:
  5919. return ret;
  5920. }
  5921. /**
  5922. * i40e_get_capabilities - get info about the HW
  5923. * @pf: the PF struct
  5924. **/
  5925. static int i40e_get_capabilities(struct i40e_pf *pf)
  5926. {
  5927. struct i40e_aqc_list_capabilities_element_resp *cap_buf;
  5928. u16 data_size;
  5929. int buf_len;
  5930. int err;
  5931. buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
  5932. do {
  5933. cap_buf = kzalloc(buf_len, GFP_KERNEL);
  5934. if (!cap_buf)
  5935. return -ENOMEM;
  5936. /* this loads the data into the hw struct for us */
  5937. err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
  5938. &data_size,
  5939. i40e_aqc_opc_list_func_capabilities,
  5940. NULL);
  5941. /* data loaded, buffer no longer needed */
  5942. kfree(cap_buf);
  5943. if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
  5944. /* retry with a larger buffer */
  5945. buf_len = data_size;
  5946. } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
  5947. dev_info(&pf->pdev->dev,
  5948. "capability discovery failed, err %s aq_err %s\n",
  5949. i40e_stat_str(&pf->hw, err),
  5950. i40e_aq_str(&pf->hw,
  5951. pf->hw.aq.asq_last_status));
  5952. return -ENODEV;
  5953. }
  5954. } while (err);
  5955. if (pf->hw.debug_mask & I40E_DEBUG_USER)
  5956. dev_info(&pf->pdev->dev,
  5957. "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",
  5958. pf->hw.pf_id, pf->hw.func_caps.num_vfs,
  5959. pf->hw.func_caps.num_msix_vectors,
  5960. pf->hw.func_caps.num_msix_vectors_vf,
  5961. pf->hw.func_caps.fd_filters_guaranteed,
  5962. pf->hw.func_caps.fd_filters_best_effort,
  5963. pf->hw.func_caps.num_tx_qp,
  5964. pf->hw.func_caps.num_vsis);
  5965. #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
  5966. + pf->hw.func_caps.num_vfs)
  5967. if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) {
  5968. dev_info(&pf->pdev->dev,
  5969. "got num_vsis %d, setting num_vsis to %d\n",
  5970. pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
  5971. pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
  5972. }
  5973. return 0;
  5974. }
  5975. static int i40e_vsi_clear(struct i40e_vsi *vsi);
  5976. /**
  5977. * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
  5978. * @pf: board private structure
  5979. **/
  5980. static void i40e_fdir_sb_setup(struct i40e_pf *pf)
  5981. {
  5982. struct i40e_vsi *vsi;
  5983. /* quick workaround for an NVM issue that leaves a critical register
  5984. * uninitialized
  5985. */
  5986. if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) {
  5987. static const u32 hkey[] = {
  5988. 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
  5989. 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
  5990. 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
  5991. 0x95b3a76d};
  5992. int i;
  5993. for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++)
  5994. wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]);
  5995. }
  5996. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  5997. return;
  5998. /* find existing VSI and see if it needs configuring */
  5999. vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
  6000. /* create a new VSI if none exists */
  6001. if (!vsi) {
  6002. vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
  6003. pf->vsi[pf->lan_vsi]->seid, 0);
  6004. if (!vsi) {
  6005. dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
  6006. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  6007. return;
  6008. }
  6009. }
  6010. i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
  6011. }
  6012. /**
  6013. * i40e_fdir_teardown - release the Flow Director resources
  6014. * @pf: board private structure
  6015. **/
  6016. static void i40e_fdir_teardown(struct i40e_pf *pf)
  6017. {
  6018. struct i40e_vsi *vsi;
  6019. i40e_fdir_filter_exit(pf);
  6020. vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
  6021. if (vsi)
  6022. i40e_vsi_release(vsi);
  6023. }
  6024. /**
  6025. * i40e_prep_for_reset - prep for the core to reset
  6026. * @pf: board private structure
  6027. *
  6028. * Close up the VFs and other things in prep for PF Reset.
  6029. **/
  6030. static void i40e_prep_for_reset(struct i40e_pf *pf)
  6031. {
  6032. struct i40e_hw *hw = &pf->hw;
  6033. i40e_status ret = 0;
  6034. u32 v;
  6035. clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
  6036. if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
  6037. return;
  6038. if (i40e_check_asq_alive(&pf->hw))
  6039. i40e_vc_notify_reset(pf);
  6040. dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
  6041. /* quiesce the VSIs and their queues that are not already DOWN */
  6042. i40e_pf_quiesce_all_vsi(pf);
  6043. for (v = 0; v < pf->num_alloc_vsi; v++) {
  6044. if (pf->vsi[v])
  6045. pf->vsi[v]->seid = 0;
  6046. }
  6047. i40e_shutdown_adminq(&pf->hw);
  6048. /* call shutdown HMC */
  6049. if (hw->hmc.hmc_obj) {
  6050. ret = i40e_shutdown_lan_hmc(hw);
  6051. if (ret)
  6052. dev_warn(&pf->pdev->dev,
  6053. "shutdown_lan_hmc failed: %d\n", ret);
  6054. }
  6055. }
  6056. /**
  6057. * i40e_send_version - update firmware with driver version
  6058. * @pf: PF struct
  6059. */
  6060. static void i40e_send_version(struct i40e_pf *pf)
  6061. {
  6062. struct i40e_driver_version dv;
  6063. dv.major_version = DRV_VERSION_MAJOR;
  6064. dv.minor_version = DRV_VERSION_MINOR;
  6065. dv.build_version = DRV_VERSION_BUILD;
  6066. dv.subbuild_version = 0;
  6067. strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string));
  6068. i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
  6069. }
  6070. /**
  6071. * i40e_reset_and_rebuild - reset and rebuild using a saved config
  6072. * @pf: board private structure
  6073. * @reinit: if the Main VSI needs to re-initialized.
  6074. **/
  6075. static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit)
  6076. {
  6077. struct i40e_hw *hw = &pf->hw;
  6078. u8 set_fc_aq_fail = 0;
  6079. i40e_status ret;
  6080. u32 val;
  6081. u32 v;
  6082. /* Now we wait for GRST to settle out.
  6083. * We don't have to delete the VEBs or VSIs from the hw switch
  6084. * because the reset will make them disappear.
  6085. */
  6086. ret = i40e_pf_reset(hw);
  6087. if (ret) {
  6088. dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
  6089. set_bit(__I40E_RESET_FAILED, &pf->state);
  6090. goto clear_recovery;
  6091. }
  6092. pf->pfr_count++;
  6093. if (test_bit(__I40E_DOWN, &pf->state))
  6094. goto clear_recovery;
  6095. dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
  6096. /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
  6097. ret = i40e_init_adminq(&pf->hw);
  6098. if (ret) {
  6099. dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n",
  6100. i40e_stat_str(&pf->hw, ret),
  6101. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  6102. goto clear_recovery;
  6103. }
  6104. /* re-verify the eeprom if we just had an EMP reset */
  6105. if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state))
  6106. i40e_verify_eeprom(pf);
  6107. i40e_clear_pxe_mode(hw);
  6108. ret = i40e_get_capabilities(pf);
  6109. if (ret)
  6110. goto end_core_reset;
  6111. ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  6112. hw->func_caps.num_rx_qp,
  6113. pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
  6114. if (ret) {
  6115. dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
  6116. goto end_core_reset;
  6117. }
  6118. ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  6119. if (ret) {
  6120. dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
  6121. goto end_core_reset;
  6122. }
  6123. #ifdef CONFIG_I40E_DCB
  6124. ret = i40e_init_pf_dcb(pf);
  6125. if (ret) {
  6126. dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret);
  6127. pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
  6128. /* Continue without DCB enabled */
  6129. }
  6130. #endif /* CONFIG_I40E_DCB */
  6131. #ifdef I40E_FCOE
  6132. i40e_init_pf_fcoe(pf);
  6133. #endif
  6134. /* do basic switch setup */
  6135. ret = i40e_setup_pf_switch(pf, reinit);
  6136. if (ret)
  6137. goto end_core_reset;
  6138. /* The driver only wants link up/down and module qualification
  6139. * reports from firmware. Note the negative logic.
  6140. */
  6141. ret = i40e_aq_set_phy_int_mask(&pf->hw,
  6142. ~(I40E_AQ_EVENT_LINK_UPDOWN |
  6143. I40E_AQ_EVENT_MEDIA_NA |
  6144. I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
  6145. if (ret)
  6146. dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
  6147. i40e_stat_str(&pf->hw, ret),
  6148. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  6149. /* make sure our flow control settings are restored */
  6150. ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true);
  6151. if (ret)
  6152. dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n",
  6153. i40e_stat_str(&pf->hw, ret),
  6154. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  6155. /* Rebuild the VSIs and VEBs that existed before reset.
  6156. * They are still in our local switch element arrays, so only
  6157. * need to rebuild the switch model in the HW.
  6158. *
  6159. * If there were VEBs but the reconstitution failed, we'll try
  6160. * try to recover minimal use by getting the basic PF VSI working.
  6161. */
  6162. if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) {
  6163. dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
  6164. /* find the one VEB connected to the MAC, and find orphans */
  6165. for (v = 0; v < I40E_MAX_VEB; v++) {
  6166. if (!pf->veb[v])
  6167. continue;
  6168. if (pf->veb[v]->uplink_seid == pf->mac_seid ||
  6169. pf->veb[v]->uplink_seid == 0) {
  6170. ret = i40e_reconstitute_veb(pf->veb[v]);
  6171. if (!ret)
  6172. continue;
  6173. /* If Main VEB failed, we're in deep doodoo,
  6174. * so give up rebuilding the switch and set up
  6175. * for minimal rebuild of PF VSI.
  6176. * If orphan failed, we'll report the error
  6177. * but try to keep going.
  6178. */
  6179. if (pf->veb[v]->uplink_seid == pf->mac_seid) {
  6180. dev_info(&pf->pdev->dev,
  6181. "rebuild of switch failed: %d, will try to set up simple PF connection\n",
  6182. ret);
  6183. pf->vsi[pf->lan_vsi]->uplink_seid
  6184. = pf->mac_seid;
  6185. break;
  6186. } else if (pf->veb[v]->uplink_seid == 0) {
  6187. dev_info(&pf->pdev->dev,
  6188. "rebuild of orphan VEB failed: %d\n",
  6189. ret);
  6190. }
  6191. }
  6192. }
  6193. }
  6194. if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) {
  6195. dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
  6196. /* no VEB, so rebuild only the Main VSI */
  6197. ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]);
  6198. if (ret) {
  6199. dev_info(&pf->pdev->dev,
  6200. "rebuild of Main VSI failed: %d\n", ret);
  6201. goto end_core_reset;
  6202. }
  6203. }
  6204. /* Reconfigure hardware for allowing smaller MSS in the case
  6205. * of TSO, so that we avoid the MDD being fired and causing
  6206. * a reset in the case of small MSS+TSO.
  6207. */
  6208. #define I40E_REG_MSS 0x000E64DC
  6209. #define I40E_REG_MSS_MIN_MASK 0x3FF0000
  6210. #define I40E_64BYTE_MSS 0x400000
  6211. val = rd32(hw, I40E_REG_MSS);
  6212. if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
  6213. val &= ~I40E_REG_MSS_MIN_MASK;
  6214. val |= I40E_64BYTE_MSS;
  6215. wr32(hw, I40E_REG_MSS, val);
  6216. }
  6217. if (pf->flags & I40E_FLAG_RESTART_AUTONEG) {
  6218. msleep(75);
  6219. ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
  6220. if (ret)
  6221. dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
  6222. i40e_stat_str(&pf->hw, ret),
  6223. i40e_aq_str(&pf->hw,
  6224. pf->hw.aq.asq_last_status));
  6225. }
  6226. /* reinit the misc interrupt */
  6227. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  6228. ret = i40e_setup_misc_vector(pf);
  6229. /* Add a filter to drop all Flow control frames from any VSI from being
  6230. * transmitted. By doing so we stop a malicious VF from sending out
  6231. * PAUSE or PFC frames and potentially controlling traffic for other
  6232. * PF/VF VSIs.
  6233. * The FW can still send Flow control frames if enabled.
  6234. */
  6235. i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
  6236. pf->main_vsi_seid);
  6237. /* restart the VSIs that were rebuilt and running before the reset */
  6238. i40e_pf_unquiesce_all_vsi(pf);
  6239. if (pf->num_alloc_vfs) {
  6240. for (v = 0; v < pf->num_alloc_vfs; v++)
  6241. i40e_reset_vf(&pf->vf[v], true);
  6242. }
  6243. /* tell the firmware that we're starting */
  6244. i40e_send_version(pf);
  6245. end_core_reset:
  6246. clear_bit(__I40E_RESET_FAILED, &pf->state);
  6247. clear_recovery:
  6248. clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state);
  6249. }
  6250. /**
  6251. * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
  6252. * @pf: board private structure
  6253. *
  6254. * Close up the VFs and other things in prep for a Core Reset,
  6255. * then get ready to rebuild the world.
  6256. **/
  6257. static void i40e_handle_reset_warning(struct i40e_pf *pf)
  6258. {
  6259. i40e_prep_for_reset(pf);
  6260. i40e_reset_and_rebuild(pf, false);
  6261. }
  6262. /**
  6263. * i40e_handle_mdd_event
  6264. * @pf: pointer to the PF structure
  6265. *
  6266. * Called from the MDD irq handler to identify possibly malicious vfs
  6267. **/
  6268. static void i40e_handle_mdd_event(struct i40e_pf *pf)
  6269. {
  6270. struct i40e_hw *hw = &pf->hw;
  6271. bool mdd_detected = false;
  6272. bool pf_mdd_detected = false;
  6273. struct i40e_vf *vf;
  6274. u32 reg;
  6275. int i;
  6276. if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state))
  6277. return;
  6278. /* find what triggered the MDD event */
  6279. reg = rd32(hw, I40E_GL_MDET_TX);
  6280. if (reg & I40E_GL_MDET_TX_VALID_MASK) {
  6281. u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
  6282. I40E_GL_MDET_TX_PF_NUM_SHIFT;
  6283. u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
  6284. I40E_GL_MDET_TX_VF_NUM_SHIFT;
  6285. u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
  6286. I40E_GL_MDET_TX_EVENT_SHIFT;
  6287. u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
  6288. I40E_GL_MDET_TX_QUEUE_SHIFT) -
  6289. pf->hw.func_caps.base_queue;
  6290. if (netif_msg_tx_err(pf))
  6291. dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on TX queue %d PF number 0x%02x VF number 0x%02x\n",
  6292. event, queue, pf_num, vf_num);
  6293. wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
  6294. mdd_detected = true;
  6295. }
  6296. reg = rd32(hw, I40E_GL_MDET_RX);
  6297. if (reg & I40E_GL_MDET_RX_VALID_MASK) {
  6298. u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
  6299. I40E_GL_MDET_RX_FUNCTION_SHIFT;
  6300. u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
  6301. I40E_GL_MDET_RX_EVENT_SHIFT;
  6302. u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
  6303. I40E_GL_MDET_RX_QUEUE_SHIFT) -
  6304. pf->hw.func_caps.base_queue;
  6305. if (netif_msg_rx_err(pf))
  6306. dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
  6307. event, queue, func);
  6308. wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
  6309. mdd_detected = true;
  6310. }
  6311. if (mdd_detected) {
  6312. reg = rd32(hw, I40E_PF_MDET_TX);
  6313. if (reg & I40E_PF_MDET_TX_VALID_MASK) {
  6314. wr32(hw, I40E_PF_MDET_TX, 0xFFFF);
  6315. dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
  6316. pf_mdd_detected = true;
  6317. }
  6318. reg = rd32(hw, I40E_PF_MDET_RX);
  6319. if (reg & I40E_PF_MDET_RX_VALID_MASK) {
  6320. wr32(hw, I40E_PF_MDET_RX, 0xFFFF);
  6321. dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
  6322. pf_mdd_detected = true;
  6323. }
  6324. /* Queue belongs to the PF, initiate a reset */
  6325. if (pf_mdd_detected) {
  6326. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  6327. i40e_service_event_schedule(pf);
  6328. }
  6329. }
  6330. /* see if one of the VFs needs its hand slapped */
  6331. for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
  6332. vf = &(pf->vf[i]);
  6333. reg = rd32(hw, I40E_VP_MDET_TX(i));
  6334. if (reg & I40E_VP_MDET_TX_VALID_MASK) {
  6335. wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
  6336. vf->num_mdd_events++;
  6337. dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
  6338. i);
  6339. }
  6340. reg = rd32(hw, I40E_VP_MDET_RX(i));
  6341. if (reg & I40E_VP_MDET_RX_VALID_MASK) {
  6342. wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
  6343. vf->num_mdd_events++;
  6344. dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
  6345. i);
  6346. }
  6347. if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) {
  6348. dev_info(&pf->pdev->dev,
  6349. "Too many MDD events on VF %d, disabled\n", i);
  6350. dev_info(&pf->pdev->dev,
  6351. "Use PF Control I/F to re-enable the VF\n");
  6352. set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
  6353. }
  6354. }
  6355. /* re-enable mdd interrupt cause */
  6356. clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
  6357. reg = rd32(hw, I40E_PFINT_ICR0_ENA);
  6358. reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  6359. wr32(hw, I40E_PFINT_ICR0_ENA, reg);
  6360. i40e_flush(hw);
  6361. }
  6362. /**
  6363. * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW
  6364. * @pf: board private structure
  6365. **/
  6366. static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf)
  6367. {
  6368. struct i40e_hw *hw = &pf->hw;
  6369. i40e_status ret;
  6370. __be16 port;
  6371. int i;
  6372. if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC))
  6373. return;
  6374. pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC;
  6375. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  6376. if (pf->pending_udp_bitmap & BIT_ULL(i)) {
  6377. pf->pending_udp_bitmap &= ~BIT_ULL(i);
  6378. port = pf->udp_ports[i].index;
  6379. if (port)
  6380. ret = i40e_aq_add_udp_tunnel(hw, port,
  6381. pf->udp_ports[i].type,
  6382. NULL, NULL);
  6383. else
  6384. ret = i40e_aq_del_udp_tunnel(hw, i, NULL);
  6385. if (ret) {
  6386. dev_dbg(&pf->pdev->dev,
  6387. "%s %s port %d, index %d failed, err %s aq_err %s\n",
  6388. pf->udp_ports[i].type ? "vxlan" : "geneve",
  6389. port ? "add" : "delete",
  6390. ntohs(port), i,
  6391. i40e_stat_str(&pf->hw, ret),
  6392. i40e_aq_str(&pf->hw,
  6393. pf->hw.aq.asq_last_status));
  6394. pf->udp_ports[i].index = 0;
  6395. }
  6396. }
  6397. }
  6398. }
  6399. /**
  6400. * i40e_service_task - Run the driver's async subtasks
  6401. * @work: pointer to work_struct containing our data
  6402. **/
  6403. static void i40e_service_task(struct work_struct *work)
  6404. {
  6405. struct i40e_pf *pf = container_of(work,
  6406. struct i40e_pf,
  6407. service_task);
  6408. unsigned long start_time = jiffies;
  6409. /* don't bother with service tasks if a reset is in progress */
  6410. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
  6411. return;
  6412. }
  6413. if (test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state))
  6414. return;
  6415. i40e_detect_recover_hung(pf);
  6416. i40e_sync_filters_subtask(pf);
  6417. i40e_reset_subtask(pf);
  6418. i40e_handle_mdd_event(pf);
  6419. i40e_vc_process_vflr_event(pf);
  6420. i40e_watchdog_subtask(pf);
  6421. i40e_fdir_reinit_subtask(pf);
  6422. i40e_client_subtask(pf);
  6423. i40e_sync_filters_subtask(pf);
  6424. i40e_sync_udp_filters_subtask(pf);
  6425. i40e_clean_adminq_subtask(pf);
  6426. /* flush memory to make sure state is correct before next watchdog */
  6427. smp_mb__before_atomic();
  6428. clear_bit(__I40E_SERVICE_SCHED, &pf->state);
  6429. /* If the tasks have taken longer than one timer cycle or there
  6430. * is more work to be done, reschedule the service task now
  6431. * rather than wait for the timer to tick again.
  6432. */
  6433. if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
  6434. test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) ||
  6435. test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) ||
  6436. test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
  6437. i40e_service_event_schedule(pf);
  6438. }
  6439. /**
  6440. * i40e_service_timer - timer callback
  6441. * @data: pointer to PF struct
  6442. **/
  6443. static void i40e_service_timer(unsigned long data)
  6444. {
  6445. struct i40e_pf *pf = (struct i40e_pf *)data;
  6446. mod_timer(&pf->service_timer,
  6447. round_jiffies(jiffies + pf->service_timer_period));
  6448. i40e_service_event_schedule(pf);
  6449. }
  6450. /**
  6451. * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
  6452. * @vsi: the VSI being configured
  6453. **/
  6454. static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
  6455. {
  6456. struct i40e_pf *pf = vsi->back;
  6457. switch (vsi->type) {
  6458. case I40E_VSI_MAIN:
  6459. vsi->alloc_queue_pairs = pf->num_lan_qps;
  6460. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  6461. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6462. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  6463. vsi->num_q_vectors = pf->num_lan_msix;
  6464. else
  6465. vsi->num_q_vectors = 1;
  6466. break;
  6467. case I40E_VSI_FDIR:
  6468. vsi->alloc_queue_pairs = 1;
  6469. vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT,
  6470. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6471. vsi->num_q_vectors = pf->num_fdsb_msix;
  6472. break;
  6473. case I40E_VSI_VMDQ2:
  6474. vsi->alloc_queue_pairs = pf->num_vmdq_qps;
  6475. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  6476. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6477. vsi->num_q_vectors = pf->num_vmdq_msix;
  6478. break;
  6479. case I40E_VSI_SRIOV:
  6480. vsi->alloc_queue_pairs = pf->num_vf_qps;
  6481. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  6482. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6483. break;
  6484. #ifdef I40E_FCOE
  6485. case I40E_VSI_FCOE:
  6486. vsi->alloc_queue_pairs = pf->num_fcoe_qps;
  6487. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  6488. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6489. vsi->num_q_vectors = pf->num_fcoe_msix;
  6490. break;
  6491. #endif /* I40E_FCOE */
  6492. default:
  6493. WARN_ON(1);
  6494. return -ENODATA;
  6495. }
  6496. return 0;
  6497. }
  6498. /**
  6499. * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
  6500. * @type: VSI pointer
  6501. * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
  6502. *
  6503. * On error: returns error code (negative)
  6504. * On success: returns 0
  6505. **/
  6506. static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)
  6507. {
  6508. int size;
  6509. int ret = 0;
  6510. /* allocate memory for both Tx and Rx ring pointers */
  6511. size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2;
  6512. vsi->tx_rings = kzalloc(size, GFP_KERNEL);
  6513. if (!vsi->tx_rings)
  6514. return -ENOMEM;
  6515. vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs];
  6516. if (alloc_qvectors) {
  6517. /* allocate memory for q_vector pointers */
  6518. size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors;
  6519. vsi->q_vectors = kzalloc(size, GFP_KERNEL);
  6520. if (!vsi->q_vectors) {
  6521. ret = -ENOMEM;
  6522. goto err_vectors;
  6523. }
  6524. }
  6525. return ret;
  6526. err_vectors:
  6527. kfree(vsi->tx_rings);
  6528. return ret;
  6529. }
  6530. /**
  6531. * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
  6532. * @pf: board private structure
  6533. * @type: type of VSI
  6534. *
  6535. * On error: returns error code (negative)
  6536. * On success: returns vsi index in PF (positive)
  6537. **/
  6538. static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
  6539. {
  6540. int ret = -ENODEV;
  6541. struct i40e_vsi *vsi;
  6542. int vsi_idx;
  6543. int i;
  6544. /* Need to protect the allocation of the VSIs at the PF level */
  6545. mutex_lock(&pf->switch_mutex);
  6546. /* VSI list may be fragmented if VSI creation/destruction has
  6547. * been happening. We can afford to do a quick scan to look
  6548. * for any free VSIs in the list.
  6549. *
  6550. * find next empty vsi slot, looping back around if necessary
  6551. */
  6552. i = pf->next_vsi;
  6553. while (i < pf->num_alloc_vsi && pf->vsi[i])
  6554. i++;
  6555. if (i >= pf->num_alloc_vsi) {
  6556. i = 0;
  6557. while (i < pf->next_vsi && pf->vsi[i])
  6558. i++;
  6559. }
  6560. if (i < pf->num_alloc_vsi && !pf->vsi[i]) {
  6561. vsi_idx = i; /* Found one! */
  6562. } else {
  6563. ret = -ENODEV;
  6564. goto unlock_pf; /* out of VSI slots! */
  6565. }
  6566. pf->next_vsi = ++i;
  6567. vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
  6568. if (!vsi) {
  6569. ret = -ENOMEM;
  6570. goto unlock_pf;
  6571. }
  6572. vsi->type = type;
  6573. vsi->back = pf;
  6574. set_bit(__I40E_DOWN, &vsi->state);
  6575. vsi->flags = 0;
  6576. vsi->idx = vsi_idx;
  6577. vsi->int_rate_limit = 0;
  6578. vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ?
  6579. pf->rss_table_size : 64;
  6580. vsi->netdev_registered = false;
  6581. vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
  6582. hash_init(vsi->mac_filter_hash);
  6583. vsi->irqs_ready = false;
  6584. ret = i40e_set_num_rings_in_vsi(vsi);
  6585. if (ret)
  6586. goto err_rings;
  6587. ret = i40e_vsi_alloc_arrays(vsi, true);
  6588. if (ret)
  6589. goto err_rings;
  6590. /* Setup default MSIX irq handler for VSI */
  6591. i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
  6592. /* Initialize VSI lock */
  6593. spin_lock_init(&vsi->mac_filter_hash_lock);
  6594. pf->vsi[vsi_idx] = vsi;
  6595. ret = vsi_idx;
  6596. goto unlock_pf;
  6597. err_rings:
  6598. pf->next_vsi = i - 1;
  6599. kfree(vsi);
  6600. unlock_pf:
  6601. mutex_unlock(&pf->switch_mutex);
  6602. return ret;
  6603. }
  6604. /**
  6605. * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
  6606. * @type: VSI pointer
  6607. * @free_qvectors: a bool to specify if q_vectors need to be freed.
  6608. *
  6609. * On error: returns error code (negative)
  6610. * On success: returns 0
  6611. **/
  6612. static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors)
  6613. {
  6614. /* free the ring and vector containers */
  6615. if (free_qvectors) {
  6616. kfree(vsi->q_vectors);
  6617. vsi->q_vectors = NULL;
  6618. }
  6619. kfree(vsi->tx_rings);
  6620. vsi->tx_rings = NULL;
  6621. vsi->rx_rings = NULL;
  6622. }
  6623. /**
  6624. * i40e_clear_rss_config_user - clear the user configured RSS hash keys
  6625. * and lookup table
  6626. * @vsi: Pointer to VSI structure
  6627. */
  6628. static void i40e_clear_rss_config_user(struct i40e_vsi *vsi)
  6629. {
  6630. if (!vsi)
  6631. return;
  6632. kfree(vsi->rss_hkey_user);
  6633. vsi->rss_hkey_user = NULL;
  6634. kfree(vsi->rss_lut_user);
  6635. vsi->rss_lut_user = NULL;
  6636. }
  6637. /**
  6638. * i40e_vsi_clear - Deallocate the VSI provided
  6639. * @vsi: the VSI being un-configured
  6640. **/
  6641. static int i40e_vsi_clear(struct i40e_vsi *vsi)
  6642. {
  6643. struct i40e_pf *pf;
  6644. if (!vsi)
  6645. return 0;
  6646. if (!vsi->back)
  6647. goto free_vsi;
  6648. pf = vsi->back;
  6649. mutex_lock(&pf->switch_mutex);
  6650. if (!pf->vsi[vsi->idx]) {
  6651. dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
  6652. vsi->idx, vsi->idx, vsi, vsi->type);
  6653. goto unlock_vsi;
  6654. }
  6655. if (pf->vsi[vsi->idx] != vsi) {
  6656. dev_err(&pf->pdev->dev,
  6657. "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
  6658. pf->vsi[vsi->idx]->idx,
  6659. pf->vsi[vsi->idx],
  6660. pf->vsi[vsi->idx]->type,
  6661. vsi->idx, vsi, vsi->type);
  6662. goto unlock_vsi;
  6663. }
  6664. /* updates the PF for this cleared vsi */
  6665. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  6666. i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
  6667. i40e_vsi_free_arrays(vsi, true);
  6668. i40e_clear_rss_config_user(vsi);
  6669. pf->vsi[vsi->idx] = NULL;
  6670. if (vsi->idx < pf->next_vsi)
  6671. pf->next_vsi = vsi->idx;
  6672. unlock_vsi:
  6673. mutex_unlock(&pf->switch_mutex);
  6674. free_vsi:
  6675. kfree(vsi);
  6676. return 0;
  6677. }
  6678. /**
  6679. * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
  6680. * @vsi: the VSI being cleaned
  6681. **/
  6682. static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
  6683. {
  6684. int i;
  6685. if (vsi->tx_rings && vsi->tx_rings[0]) {
  6686. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  6687. kfree_rcu(vsi->tx_rings[i], rcu);
  6688. vsi->tx_rings[i] = NULL;
  6689. vsi->rx_rings[i] = NULL;
  6690. }
  6691. }
  6692. }
  6693. /**
  6694. * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
  6695. * @vsi: the VSI being configured
  6696. **/
  6697. static int i40e_alloc_rings(struct i40e_vsi *vsi)
  6698. {
  6699. struct i40e_ring *tx_ring, *rx_ring;
  6700. struct i40e_pf *pf = vsi->back;
  6701. int i;
  6702. /* Set basic values in the rings to be used later during open() */
  6703. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  6704. /* allocate space for both Tx and Rx in one shot */
  6705. tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL);
  6706. if (!tx_ring)
  6707. goto err_out;
  6708. tx_ring->queue_index = i;
  6709. tx_ring->reg_idx = vsi->base_queue + i;
  6710. tx_ring->ring_active = false;
  6711. tx_ring->vsi = vsi;
  6712. tx_ring->netdev = vsi->netdev;
  6713. tx_ring->dev = &pf->pdev->dev;
  6714. tx_ring->count = vsi->num_desc;
  6715. tx_ring->size = 0;
  6716. tx_ring->dcb_tc = 0;
  6717. if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE)
  6718. tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
  6719. tx_ring->tx_itr_setting = pf->tx_itr_default;
  6720. vsi->tx_rings[i] = tx_ring;
  6721. rx_ring = &tx_ring[1];
  6722. rx_ring->queue_index = i;
  6723. rx_ring->reg_idx = vsi->base_queue + i;
  6724. rx_ring->ring_active = false;
  6725. rx_ring->vsi = vsi;
  6726. rx_ring->netdev = vsi->netdev;
  6727. rx_ring->dev = &pf->pdev->dev;
  6728. rx_ring->count = vsi->num_desc;
  6729. rx_ring->size = 0;
  6730. rx_ring->dcb_tc = 0;
  6731. rx_ring->rx_itr_setting = pf->rx_itr_default;
  6732. vsi->rx_rings[i] = rx_ring;
  6733. }
  6734. return 0;
  6735. err_out:
  6736. i40e_vsi_clear_rings(vsi);
  6737. return -ENOMEM;
  6738. }
  6739. /**
  6740. * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
  6741. * @pf: board private structure
  6742. * @vectors: the number of MSI-X vectors to request
  6743. *
  6744. * Returns the number of vectors reserved, or error
  6745. **/
  6746. static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
  6747. {
  6748. vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries,
  6749. I40E_MIN_MSIX, vectors);
  6750. if (vectors < 0) {
  6751. dev_info(&pf->pdev->dev,
  6752. "MSI-X vector reservation failed: %d\n", vectors);
  6753. vectors = 0;
  6754. }
  6755. return vectors;
  6756. }
  6757. /**
  6758. * i40e_init_msix - Setup the MSIX capability
  6759. * @pf: board private structure
  6760. *
  6761. * Work with the OS to set up the MSIX vectors needed.
  6762. *
  6763. * Returns the number of vectors reserved or negative on failure
  6764. **/
  6765. static int i40e_init_msix(struct i40e_pf *pf)
  6766. {
  6767. struct i40e_hw *hw = &pf->hw;
  6768. int vectors_left;
  6769. int v_budget, i;
  6770. int v_actual;
  6771. int iwarp_requested = 0;
  6772. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  6773. return -ENODEV;
  6774. /* The number of vectors we'll request will be comprised of:
  6775. * - Add 1 for "other" cause for Admin Queue events, etc.
  6776. * - The number of LAN queue pairs
  6777. * - Queues being used for RSS.
  6778. * We don't need as many as max_rss_size vectors.
  6779. * use rss_size instead in the calculation since that
  6780. * is governed by number of cpus in the system.
  6781. * - assumes symmetric Tx/Rx pairing
  6782. * - The number of VMDq pairs
  6783. * - The CPU count within the NUMA node if iWARP is enabled
  6784. #ifdef I40E_FCOE
  6785. * - The number of FCOE qps.
  6786. #endif
  6787. * Once we count this up, try the request.
  6788. *
  6789. * If we can't get what we want, we'll simplify to nearly nothing
  6790. * and try again. If that still fails, we punt.
  6791. */
  6792. vectors_left = hw->func_caps.num_msix_vectors;
  6793. v_budget = 0;
  6794. /* reserve one vector for miscellaneous handler */
  6795. if (vectors_left) {
  6796. v_budget++;
  6797. vectors_left--;
  6798. }
  6799. /* reserve vectors for the main PF traffic queues */
  6800. pf->num_lan_msix = min_t(int, num_online_cpus(), vectors_left);
  6801. vectors_left -= pf->num_lan_msix;
  6802. v_budget += pf->num_lan_msix;
  6803. /* reserve one vector for sideband flow director */
  6804. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  6805. if (vectors_left) {
  6806. pf->num_fdsb_msix = 1;
  6807. v_budget++;
  6808. vectors_left--;
  6809. } else {
  6810. pf->num_fdsb_msix = 0;
  6811. }
  6812. }
  6813. #ifdef I40E_FCOE
  6814. /* can we reserve enough for FCoE? */
  6815. if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
  6816. if (!vectors_left)
  6817. pf->num_fcoe_msix = 0;
  6818. else if (vectors_left >= pf->num_fcoe_qps)
  6819. pf->num_fcoe_msix = pf->num_fcoe_qps;
  6820. else
  6821. pf->num_fcoe_msix = 1;
  6822. v_budget += pf->num_fcoe_msix;
  6823. vectors_left -= pf->num_fcoe_msix;
  6824. }
  6825. #endif
  6826. /* can we reserve enough for iWARP? */
  6827. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  6828. iwarp_requested = pf->num_iwarp_msix;
  6829. if (!vectors_left)
  6830. pf->num_iwarp_msix = 0;
  6831. else if (vectors_left < pf->num_iwarp_msix)
  6832. pf->num_iwarp_msix = 1;
  6833. v_budget += pf->num_iwarp_msix;
  6834. vectors_left -= pf->num_iwarp_msix;
  6835. }
  6836. /* any vectors left over go for VMDq support */
  6837. if (pf->flags & I40E_FLAG_VMDQ_ENABLED) {
  6838. int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps;
  6839. int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted);
  6840. if (!vectors_left) {
  6841. pf->num_vmdq_msix = 0;
  6842. pf->num_vmdq_qps = 0;
  6843. } else {
  6844. /* if we're short on vectors for what's desired, we limit
  6845. * the queues per vmdq. If this is still more than are
  6846. * available, the user will need to change the number of
  6847. * queues/vectors used by the PF later with the ethtool
  6848. * channels command
  6849. */
  6850. if (vmdq_vecs < vmdq_vecs_wanted)
  6851. pf->num_vmdq_qps = 1;
  6852. pf->num_vmdq_msix = pf->num_vmdq_qps;
  6853. v_budget += vmdq_vecs;
  6854. vectors_left -= vmdq_vecs;
  6855. }
  6856. }
  6857. pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
  6858. GFP_KERNEL);
  6859. if (!pf->msix_entries)
  6860. return -ENOMEM;
  6861. for (i = 0; i < v_budget; i++)
  6862. pf->msix_entries[i].entry = i;
  6863. v_actual = i40e_reserve_msix_vectors(pf, v_budget);
  6864. if (v_actual < I40E_MIN_MSIX) {
  6865. pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
  6866. kfree(pf->msix_entries);
  6867. pf->msix_entries = NULL;
  6868. pci_disable_msix(pf->pdev);
  6869. return -ENODEV;
  6870. } else if (v_actual == I40E_MIN_MSIX) {
  6871. /* Adjust for minimal MSIX use */
  6872. pf->num_vmdq_vsis = 0;
  6873. pf->num_vmdq_qps = 0;
  6874. pf->num_lan_qps = 1;
  6875. pf->num_lan_msix = 1;
  6876. } else if (!vectors_left) {
  6877. /* If we have limited resources, we will start with no vectors
  6878. * for the special features and then allocate vectors to some
  6879. * of these features based on the policy and at the end disable
  6880. * the features that did not get any vectors.
  6881. */
  6882. int vec;
  6883. dev_info(&pf->pdev->dev,
  6884. "MSI-X vector limit reached, attempting to redistribute vectors\n");
  6885. /* reserve the misc vector */
  6886. vec = v_actual - 1;
  6887. /* Scale vector usage down */
  6888. pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
  6889. pf->num_vmdq_vsis = 1;
  6890. pf->num_vmdq_qps = 1;
  6891. #ifdef I40E_FCOE
  6892. pf->num_fcoe_qps = 0;
  6893. pf->num_fcoe_msix = 0;
  6894. #endif
  6895. /* partition out the remaining vectors */
  6896. switch (vec) {
  6897. case 2:
  6898. pf->num_lan_msix = 1;
  6899. break;
  6900. case 3:
  6901. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  6902. pf->num_lan_msix = 1;
  6903. pf->num_iwarp_msix = 1;
  6904. } else {
  6905. pf->num_lan_msix = 2;
  6906. }
  6907. #ifdef I40E_FCOE
  6908. /* give one vector to FCoE */
  6909. if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
  6910. pf->num_lan_msix = 1;
  6911. pf->num_fcoe_msix = 1;
  6912. }
  6913. #endif
  6914. break;
  6915. default:
  6916. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  6917. pf->num_iwarp_msix = min_t(int, (vec / 3),
  6918. iwarp_requested);
  6919. pf->num_vmdq_vsis = min_t(int, (vec / 3),
  6920. I40E_DEFAULT_NUM_VMDQ_VSI);
  6921. } else {
  6922. pf->num_vmdq_vsis = min_t(int, (vec / 2),
  6923. I40E_DEFAULT_NUM_VMDQ_VSI);
  6924. }
  6925. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  6926. pf->num_fdsb_msix = 1;
  6927. vec--;
  6928. }
  6929. pf->num_lan_msix = min_t(int,
  6930. (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)),
  6931. pf->num_lan_msix);
  6932. pf->num_lan_qps = pf->num_lan_msix;
  6933. #ifdef I40E_FCOE
  6934. /* give one vector to FCoE */
  6935. if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
  6936. pf->num_fcoe_msix = 1;
  6937. vec--;
  6938. }
  6939. #endif
  6940. break;
  6941. }
  6942. }
  6943. if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
  6944. (pf->num_fdsb_msix == 0)) {
  6945. dev_info(&pf->pdev->dev, "Sideband Flowdir disabled, not enough MSI-X vectors\n");
  6946. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  6947. }
  6948. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  6949. (pf->num_vmdq_msix == 0)) {
  6950. dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n");
  6951. pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
  6952. }
  6953. if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
  6954. (pf->num_iwarp_msix == 0)) {
  6955. dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n");
  6956. pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
  6957. }
  6958. #ifdef I40E_FCOE
  6959. if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) {
  6960. dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n");
  6961. pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
  6962. }
  6963. #endif
  6964. i40e_debug(&pf->hw, I40E_DEBUG_INIT,
  6965. "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n",
  6966. pf->num_lan_msix,
  6967. pf->num_vmdq_msix * pf->num_vmdq_vsis,
  6968. pf->num_fdsb_msix,
  6969. pf->num_iwarp_msix);
  6970. return v_actual;
  6971. }
  6972. /**
  6973. * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
  6974. * @vsi: the VSI being configured
  6975. * @v_idx: index of the vector in the vsi struct
  6976. * @cpu: cpu to be used on affinity_mask
  6977. *
  6978. * We allocate one q_vector. If allocation fails we return -ENOMEM.
  6979. **/
  6980. static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx, int cpu)
  6981. {
  6982. struct i40e_q_vector *q_vector;
  6983. /* allocate q_vector */
  6984. q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
  6985. if (!q_vector)
  6986. return -ENOMEM;
  6987. q_vector->vsi = vsi;
  6988. q_vector->v_idx = v_idx;
  6989. cpumask_set_cpu(cpu, &q_vector->affinity_mask);
  6990. if (vsi->netdev)
  6991. netif_napi_add(vsi->netdev, &q_vector->napi,
  6992. i40e_napi_poll, NAPI_POLL_WEIGHT);
  6993. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  6994. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  6995. /* tie q_vector and vsi together */
  6996. vsi->q_vectors[v_idx] = q_vector;
  6997. return 0;
  6998. }
  6999. /**
  7000. * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
  7001. * @vsi: the VSI being configured
  7002. *
  7003. * We allocate one q_vector per queue interrupt. If allocation fails we
  7004. * return -ENOMEM.
  7005. **/
  7006. static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi)
  7007. {
  7008. struct i40e_pf *pf = vsi->back;
  7009. int err, v_idx, num_q_vectors, current_cpu;
  7010. /* if not MSIX, give the one vector only to the LAN VSI */
  7011. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  7012. num_q_vectors = vsi->num_q_vectors;
  7013. else if (vsi == pf->vsi[pf->lan_vsi])
  7014. num_q_vectors = 1;
  7015. else
  7016. return -EINVAL;
  7017. current_cpu = cpumask_first(cpu_online_mask);
  7018. for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
  7019. err = i40e_vsi_alloc_q_vector(vsi, v_idx, current_cpu);
  7020. if (err)
  7021. goto err_out;
  7022. current_cpu = cpumask_next(current_cpu, cpu_online_mask);
  7023. if (unlikely(current_cpu >= nr_cpu_ids))
  7024. current_cpu = cpumask_first(cpu_online_mask);
  7025. }
  7026. return 0;
  7027. err_out:
  7028. while (v_idx--)
  7029. i40e_free_q_vector(vsi, v_idx);
  7030. return err;
  7031. }
  7032. /**
  7033. * i40e_init_interrupt_scheme - Determine proper interrupt scheme
  7034. * @pf: board private structure to initialize
  7035. **/
  7036. static int i40e_init_interrupt_scheme(struct i40e_pf *pf)
  7037. {
  7038. int vectors = 0;
  7039. ssize_t size;
  7040. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  7041. vectors = i40e_init_msix(pf);
  7042. if (vectors < 0) {
  7043. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
  7044. I40E_FLAG_IWARP_ENABLED |
  7045. #ifdef I40E_FCOE
  7046. I40E_FLAG_FCOE_ENABLED |
  7047. #endif
  7048. I40E_FLAG_RSS_ENABLED |
  7049. I40E_FLAG_DCB_CAPABLE |
  7050. I40E_FLAG_DCB_ENABLED |
  7051. I40E_FLAG_SRIOV_ENABLED |
  7052. I40E_FLAG_FD_SB_ENABLED |
  7053. I40E_FLAG_FD_ATR_ENABLED |
  7054. I40E_FLAG_VMDQ_ENABLED);
  7055. /* rework the queue expectations without MSIX */
  7056. i40e_determine_queue_usage(pf);
  7057. }
  7058. }
  7059. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  7060. (pf->flags & I40E_FLAG_MSI_ENABLED)) {
  7061. dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n");
  7062. vectors = pci_enable_msi(pf->pdev);
  7063. if (vectors < 0) {
  7064. dev_info(&pf->pdev->dev, "MSI init failed - %d\n",
  7065. vectors);
  7066. pf->flags &= ~I40E_FLAG_MSI_ENABLED;
  7067. }
  7068. vectors = 1; /* one MSI or Legacy vector */
  7069. }
  7070. if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
  7071. dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
  7072. /* set up vector assignment tracking */
  7073. size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors);
  7074. pf->irq_pile = kzalloc(size, GFP_KERNEL);
  7075. if (!pf->irq_pile) {
  7076. dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n");
  7077. return -ENOMEM;
  7078. }
  7079. pf->irq_pile->num_entries = vectors;
  7080. pf->irq_pile->search_hint = 0;
  7081. /* track first vector for misc interrupts, ignore return */
  7082. (void)i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT - 1);
  7083. return 0;
  7084. }
  7085. /**
  7086. * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
  7087. * @pf: board private structure
  7088. *
  7089. * This sets up the handler for MSIX 0, which is used to manage the
  7090. * non-queue interrupts, e.g. AdminQ and errors. This is not used
  7091. * when in MSI or Legacy interrupt mode.
  7092. **/
  7093. static int i40e_setup_misc_vector(struct i40e_pf *pf)
  7094. {
  7095. struct i40e_hw *hw = &pf->hw;
  7096. int err = 0;
  7097. /* Only request the irq if this is the first time through, and
  7098. * not when we're rebuilding after a Reset
  7099. */
  7100. if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
  7101. err = request_irq(pf->msix_entries[0].vector,
  7102. i40e_intr, 0, pf->int_name, pf);
  7103. if (err) {
  7104. dev_info(&pf->pdev->dev,
  7105. "request_irq for %s failed: %d\n",
  7106. pf->int_name, err);
  7107. return -EFAULT;
  7108. }
  7109. }
  7110. i40e_enable_misc_int_causes(pf);
  7111. /* associate no queues to the misc vector */
  7112. wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
  7113. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K);
  7114. i40e_flush(hw);
  7115. i40e_irq_dynamic_enable_icr0(pf, true);
  7116. return err;
  7117. }
  7118. /**
  7119. * i40e_config_rss_aq - Prepare for RSS using AQ commands
  7120. * @vsi: vsi structure
  7121. * @seed: RSS hash seed
  7122. **/
  7123. static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
  7124. u8 *lut, u16 lut_size)
  7125. {
  7126. struct i40e_pf *pf = vsi->back;
  7127. struct i40e_hw *hw = &pf->hw;
  7128. int ret = 0;
  7129. if (seed) {
  7130. struct i40e_aqc_get_set_rss_key_data *seed_dw =
  7131. (struct i40e_aqc_get_set_rss_key_data *)seed;
  7132. ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw);
  7133. if (ret) {
  7134. dev_info(&pf->pdev->dev,
  7135. "Cannot set RSS key, err %s aq_err %s\n",
  7136. i40e_stat_str(hw, ret),
  7137. i40e_aq_str(hw, hw->aq.asq_last_status));
  7138. return ret;
  7139. }
  7140. }
  7141. if (lut) {
  7142. bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
  7143. ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
  7144. if (ret) {
  7145. dev_info(&pf->pdev->dev,
  7146. "Cannot set RSS lut, err %s aq_err %s\n",
  7147. i40e_stat_str(hw, ret),
  7148. i40e_aq_str(hw, hw->aq.asq_last_status));
  7149. return ret;
  7150. }
  7151. }
  7152. return ret;
  7153. }
  7154. /**
  7155. * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands
  7156. * @vsi: Pointer to vsi structure
  7157. * @seed: Buffter to store the hash keys
  7158. * @lut: Buffer to store the lookup table entries
  7159. * @lut_size: Size of buffer to store the lookup table entries
  7160. *
  7161. * Return 0 on success, negative on failure
  7162. */
  7163. static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
  7164. u8 *lut, u16 lut_size)
  7165. {
  7166. struct i40e_pf *pf = vsi->back;
  7167. struct i40e_hw *hw = &pf->hw;
  7168. int ret = 0;
  7169. if (seed) {
  7170. ret = i40e_aq_get_rss_key(hw, vsi->id,
  7171. (struct i40e_aqc_get_set_rss_key_data *)seed);
  7172. if (ret) {
  7173. dev_info(&pf->pdev->dev,
  7174. "Cannot get RSS key, err %s aq_err %s\n",
  7175. i40e_stat_str(&pf->hw, ret),
  7176. i40e_aq_str(&pf->hw,
  7177. pf->hw.aq.asq_last_status));
  7178. return ret;
  7179. }
  7180. }
  7181. if (lut) {
  7182. bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
  7183. ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
  7184. if (ret) {
  7185. dev_info(&pf->pdev->dev,
  7186. "Cannot get RSS lut, err %s aq_err %s\n",
  7187. i40e_stat_str(&pf->hw, ret),
  7188. i40e_aq_str(&pf->hw,
  7189. pf->hw.aq.asq_last_status));
  7190. return ret;
  7191. }
  7192. }
  7193. return ret;
  7194. }
  7195. /**
  7196. * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
  7197. * @vsi: VSI structure
  7198. **/
  7199. static int i40e_vsi_config_rss(struct i40e_vsi *vsi)
  7200. {
  7201. u8 seed[I40E_HKEY_ARRAY_SIZE];
  7202. struct i40e_pf *pf = vsi->back;
  7203. u8 *lut;
  7204. int ret;
  7205. if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE))
  7206. return 0;
  7207. if (!vsi->rss_size)
  7208. vsi->rss_size = min_t(int, pf->alloc_rss_size,
  7209. vsi->num_queue_pairs);
  7210. if (!vsi->rss_size)
  7211. return -EINVAL;
  7212. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  7213. if (!lut)
  7214. return -ENOMEM;
  7215. /* Use the user configured hash keys and lookup table if there is one,
  7216. * otherwise use default
  7217. */
  7218. if (vsi->rss_lut_user)
  7219. memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
  7220. else
  7221. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
  7222. if (vsi->rss_hkey_user)
  7223. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  7224. else
  7225. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  7226. ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size);
  7227. kfree(lut);
  7228. return ret;
  7229. }
  7230. /**
  7231. * i40e_config_rss_reg - Configure RSS keys and lut by writing registers
  7232. * @vsi: Pointer to vsi structure
  7233. * @seed: RSS hash seed
  7234. * @lut: Lookup table
  7235. * @lut_size: Lookup table size
  7236. *
  7237. * Returns 0 on success, negative on failure
  7238. **/
  7239. static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
  7240. const u8 *lut, u16 lut_size)
  7241. {
  7242. struct i40e_pf *pf = vsi->back;
  7243. struct i40e_hw *hw = &pf->hw;
  7244. u16 vf_id = vsi->vf_id;
  7245. u8 i;
  7246. /* Fill out hash function seed */
  7247. if (seed) {
  7248. u32 *seed_dw = (u32 *)seed;
  7249. if (vsi->type == I40E_VSI_MAIN) {
  7250. for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
  7251. i40e_write_rx_ctl(hw, I40E_PFQF_HKEY(i),
  7252. seed_dw[i]);
  7253. } else if (vsi->type == I40E_VSI_SRIOV) {
  7254. for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++)
  7255. i40e_write_rx_ctl(hw,
  7256. I40E_VFQF_HKEY1(i, vf_id),
  7257. seed_dw[i]);
  7258. } else {
  7259. dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n");
  7260. }
  7261. }
  7262. if (lut) {
  7263. u32 *lut_dw = (u32 *)lut;
  7264. if (vsi->type == I40E_VSI_MAIN) {
  7265. if (lut_size != I40E_HLUT_ARRAY_SIZE)
  7266. return -EINVAL;
  7267. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  7268. wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]);
  7269. } else if (vsi->type == I40E_VSI_SRIOV) {
  7270. if (lut_size != I40E_VF_HLUT_ARRAY_SIZE)
  7271. return -EINVAL;
  7272. for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
  7273. i40e_write_rx_ctl(hw,
  7274. I40E_VFQF_HLUT1(i, vf_id),
  7275. lut_dw[i]);
  7276. } else {
  7277. dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
  7278. }
  7279. }
  7280. i40e_flush(hw);
  7281. return 0;
  7282. }
  7283. /**
  7284. * i40e_get_rss_reg - Get the RSS keys and lut by reading registers
  7285. * @vsi: Pointer to VSI structure
  7286. * @seed: Buffer to store the keys
  7287. * @lut: Buffer to store the lookup table entries
  7288. * @lut_size: Size of buffer to store the lookup table entries
  7289. *
  7290. * Returns 0 on success, negative on failure
  7291. */
  7292. static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed,
  7293. u8 *lut, u16 lut_size)
  7294. {
  7295. struct i40e_pf *pf = vsi->back;
  7296. struct i40e_hw *hw = &pf->hw;
  7297. u16 i;
  7298. if (seed) {
  7299. u32 *seed_dw = (u32 *)seed;
  7300. for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
  7301. seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i));
  7302. }
  7303. if (lut) {
  7304. u32 *lut_dw = (u32 *)lut;
  7305. if (lut_size != I40E_HLUT_ARRAY_SIZE)
  7306. return -EINVAL;
  7307. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  7308. lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i));
  7309. }
  7310. return 0;
  7311. }
  7312. /**
  7313. * i40e_config_rss - Configure RSS keys and lut
  7314. * @vsi: Pointer to VSI structure
  7315. * @seed: RSS hash seed
  7316. * @lut: Lookup table
  7317. * @lut_size: Lookup table size
  7318. *
  7319. * Returns 0 on success, negative on failure
  7320. */
  7321. int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
  7322. {
  7323. struct i40e_pf *pf = vsi->back;
  7324. if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
  7325. return i40e_config_rss_aq(vsi, seed, lut, lut_size);
  7326. else
  7327. return i40e_config_rss_reg(vsi, seed, lut, lut_size);
  7328. }
  7329. /**
  7330. * i40e_get_rss - Get RSS keys and lut
  7331. * @vsi: Pointer to VSI structure
  7332. * @seed: Buffer to store the keys
  7333. * @lut: Buffer to store the lookup table entries
  7334. * lut_size: Size of buffer to store the lookup table entries
  7335. *
  7336. * Returns 0 on success, negative on failure
  7337. */
  7338. int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
  7339. {
  7340. struct i40e_pf *pf = vsi->back;
  7341. if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
  7342. return i40e_get_rss_aq(vsi, seed, lut, lut_size);
  7343. else
  7344. return i40e_get_rss_reg(vsi, seed, lut, lut_size);
  7345. }
  7346. /**
  7347. * i40e_fill_rss_lut - Fill the RSS lookup table with default values
  7348. * @pf: Pointer to board private structure
  7349. * @lut: Lookup table
  7350. * @rss_table_size: Lookup table size
  7351. * @rss_size: Range of queue number for hashing
  7352. */
  7353. void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
  7354. u16 rss_table_size, u16 rss_size)
  7355. {
  7356. u16 i;
  7357. for (i = 0; i < rss_table_size; i++)
  7358. lut[i] = i % rss_size;
  7359. }
  7360. /**
  7361. * i40e_pf_config_rss - Prepare for RSS if used
  7362. * @pf: board private structure
  7363. **/
  7364. static int i40e_pf_config_rss(struct i40e_pf *pf)
  7365. {
  7366. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7367. u8 seed[I40E_HKEY_ARRAY_SIZE];
  7368. u8 *lut;
  7369. struct i40e_hw *hw = &pf->hw;
  7370. u32 reg_val;
  7371. u64 hena;
  7372. int ret;
  7373. /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
  7374. hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
  7375. ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
  7376. hena |= i40e_pf_get_default_rss_hena(pf);
  7377. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
  7378. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  7379. /* Determine the RSS table size based on the hardware capabilities */
  7380. reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
  7381. reg_val = (pf->rss_table_size == 512) ?
  7382. (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) :
  7383. (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512);
  7384. i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val);
  7385. /* Determine the RSS size of the VSI */
  7386. if (!vsi->rss_size)
  7387. vsi->rss_size = min_t(int, pf->alloc_rss_size,
  7388. vsi->num_queue_pairs);
  7389. if (!vsi->rss_size)
  7390. return -EINVAL;
  7391. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  7392. if (!lut)
  7393. return -ENOMEM;
  7394. /* Use user configured lut if there is one, otherwise use default */
  7395. if (vsi->rss_lut_user)
  7396. memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
  7397. else
  7398. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
  7399. /* Use user configured hash key if there is one, otherwise
  7400. * use default.
  7401. */
  7402. if (vsi->rss_hkey_user)
  7403. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  7404. else
  7405. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  7406. ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
  7407. kfree(lut);
  7408. return ret;
  7409. }
  7410. /**
  7411. * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
  7412. * @pf: board private structure
  7413. * @queue_count: the requested queue count for rss.
  7414. *
  7415. * returns 0 if rss is not enabled, if enabled returns the final rss queue
  7416. * count which may be different from the requested queue count.
  7417. **/
  7418. int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
  7419. {
  7420. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7421. int new_rss_size;
  7422. if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
  7423. return 0;
  7424. new_rss_size = min_t(int, queue_count, pf->rss_size_max);
  7425. if (queue_count != vsi->num_queue_pairs) {
  7426. vsi->req_queue_pairs = queue_count;
  7427. i40e_prep_for_reset(pf);
  7428. pf->alloc_rss_size = new_rss_size;
  7429. i40e_reset_and_rebuild(pf, true);
  7430. /* Discard the user configured hash keys and lut, if less
  7431. * queues are enabled.
  7432. */
  7433. if (queue_count < vsi->rss_size) {
  7434. i40e_clear_rss_config_user(vsi);
  7435. dev_dbg(&pf->pdev->dev,
  7436. "discard user configured hash keys and lut\n");
  7437. }
  7438. /* Reset vsi->rss_size, as number of enabled queues changed */
  7439. vsi->rss_size = min_t(int, pf->alloc_rss_size,
  7440. vsi->num_queue_pairs);
  7441. i40e_pf_config_rss(pf);
  7442. }
  7443. dev_info(&pf->pdev->dev, "User requested queue count/HW max RSS count: %d/%d\n",
  7444. vsi->req_queue_pairs, pf->rss_size_max);
  7445. return pf->alloc_rss_size;
  7446. }
  7447. /**
  7448. * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition
  7449. * @pf: board private structure
  7450. **/
  7451. i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf)
  7452. {
  7453. i40e_status status;
  7454. bool min_valid, max_valid;
  7455. u32 max_bw, min_bw;
  7456. status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw,
  7457. &min_valid, &max_valid);
  7458. if (!status) {
  7459. if (min_valid)
  7460. pf->npar_min_bw = min_bw;
  7461. if (max_valid)
  7462. pf->npar_max_bw = max_bw;
  7463. }
  7464. return status;
  7465. }
  7466. /**
  7467. * i40e_set_npar_bw_setting - Set BW settings for this PF partition
  7468. * @pf: board private structure
  7469. **/
  7470. i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf)
  7471. {
  7472. struct i40e_aqc_configure_partition_bw_data bw_data;
  7473. i40e_status status;
  7474. /* Set the valid bit for this PF */
  7475. bw_data.pf_valid_bits = cpu_to_le16(BIT(pf->hw.pf_id));
  7476. bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK;
  7477. bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK;
  7478. /* Set the new bandwidths */
  7479. status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL);
  7480. return status;
  7481. }
  7482. /**
  7483. * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition
  7484. * @pf: board private structure
  7485. **/
  7486. i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf)
  7487. {
  7488. /* Commit temporary BW setting to permanent NVM image */
  7489. enum i40e_admin_queue_err last_aq_status;
  7490. i40e_status ret;
  7491. u16 nvm_word;
  7492. if (pf->hw.partition_id != 1) {
  7493. dev_info(&pf->pdev->dev,
  7494. "Commit BW only works on partition 1! This is partition %d",
  7495. pf->hw.partition_id);
  7496. ret = I40E_NOT_SUPPORTED;
  7497. goto bw_commit_out;
  7498. }
  7499. /* Acquire NVM for read access */
  7500. ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
  7501. last_aq_status = pf->hw.aq.asq_last_status;
  7502. if (ret) {
  7503. dev_info(&pf->pdev->dev,
  7504. "Cannot acquire NVM for read access, err %s aq_err %s\n",
  7505. i40e_stat_str(&pf->hw, ret),
  7506. i40e_aq_str(&pf->hw, last_aq_status));
  7507. goto bw_commit_out;
  7508. }
  7509. /* Read word 0x10 of NVM - SW compatibility word 1 */
  7510. ret = i40e_aq_read_nvm(&pf->hw,
  7511. I40E_SR_NVM_CONTROL_WORD,
  7512. 0x10, sizeof(nvm_word), &nvm_word,
  7513. false, NULL);
  7514. /* Save off last admin queue command status before releasing
  7515. * the NVM
  7516. */
  7517. last_aq_status = pf->hw.aq.asq_last_status;
  7518. i40e_release_nvm(&pf->hw);
  7519. if (ret) {
  7520. dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n",
  7521. i40e_stat_str(&pf->hw, ret),
  7522. i40e_aq_str(&pf->hw, last_aq_status));
  7523. goto bw_commit_out;
  7524. }
  7525. /* Wait a bit for NVM release to complete */
  7526. msleep(50);
  7527. /* Acquire NVM for write access */
  7528. ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE);
  7529. last_aq_status = pf->hw.aq.asq_last_status;
  7530. if (ret) {
  7531. dev_info(&pf->pdev->dev,
  7532. "Cannot acquire NVM for write access, err %s aq_err %s\n",
  7533. i40e_stat_str(&pf->hw, ret),
  7534. i40e_aq_str(&pf->hw, last_aq_status));
  7535. goto bw_commit_out;
  7536. }
  7537. /* Write it back out unchanged to initiate update NVM,
  7538. * which will force a write of the shadow (alt) RAM to
  7539. * the NVM - thus storing the bandwidth values permanently.
  7540. */
  7541. ret = i40e_aq_update_nvm(&pf->hw,
  7542. I40E_SR_NVM_CONTROL_WORD,
  7543. 0x10, sizeof(nvm_word),
  7544. &nvm_word, true, NULL);
  7545. /* Save off last admin queue command status before releasing
  7546. * the NVM
  7547. */
  7548. last_aq_status = pf->hw.aq.asq_last_status;
  7549. i40e_release_nvm(&pf->hw);
  7550. if (ret)
  7551. dev_info(&pf->pdev->dev,
  7552. "BW settings NOT SAVED, err %s aq_err %s\n",
  7553. i40e_stat_str(&pf->hw, ret),
  7554. i40e_aq_str(&pf->hw, last_aq_status));
  7555. bw_commit_out:
  7556. return ret;
  7557. }
  7558. /**
  7559. * i40e_sw_init - Initialize general software structures (struct i40e_pf)
  7560. * @pf: board private structure to initialize
  7561. *
  7562. * i40e_sw_init initializes the Adapter private data structure.
  7563. * Fields are initialized based on PCI device information and
  7564. * OS network device settings (MTU size).
  7565. **/
  7566. static int i40e_sw_init(struct i40e_pf *pf)
  7567. {
  7568. int err = 0;
  7569. int size;
  7570. /* Set default capability flags */
  7571. pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
  7572. I40E_FLAG_MSI_ENABLED |
  7573. I40E_FLAG_MSIX_ENABLED;
  7574. /* Set default ITR */
  7575. pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF;
  7576. pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF;
  7577. /* Depending on PF configurations, it is possible that the RSS
  7578. * maximum might end up larger than the available queues
  7579. */
  7580. pf->rss_size_max = BIT(pf->hw.func_caps.rss_table_entry_width);
  7581. pf->alloc_rss_size = 1;
  7582. pf->rss_table_size = pf->hw.func_caps.rss_table_size;
  7583. pf->rss_size_max = min_t(int, pf->rss_size_max,
  7584. pf->hw.func_caps.num_tx_qp);
  7585. if (pf->hw.func_caps.rss) {
  7586. pf->flags |= I40E_FLAG_RSS_ENABLED;
  7587. pf->alloc_rss_size = min_t(int, pf->rss_size_max,
  7588. num_online_cpus());
  7589. }
  7590. /* MFP mode enabled */
  7591. if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.flex10_enable) {
  7592. pf->flags |= I40E_FLAG_MFP_ENABLED;
  7593. dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
  7594. if (i40e_get_npar_bw_setting(pf))
  7595. dev_warn(&pf->pdev->dev,
  7596. "Could not get NPAR bw settings\n");
  7597. else
  7598. dev_info(&pf->pdev->dev,
  7599. "Min BW = %8.8x, Max BW = %8.8x\n",
  7600. pf->npar_min_bw, pf->npar_max_bw);
  7601. }
  7602. /* FW/NVM is not yet fixed in this regard */
  7603. if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
  7604. (pf->hw.func_caps.fd_filters_best_effort > 0)) {
  7605. pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
  7606. pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
  7607. if (pf->flags & I40E_FLAG_MFP_ENABLED &&
  7608. pf->hw.num_partitions > 1)
  7609. dev_info(&pf->pdev->dev,
  7610. "Flow Director Sideband mode Disabled in MFP mode\n");
  7611. else
  7612. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  7613. pf->fdir_pf_filter_count =
  7614. pf->hw.func_caps.fd_filters_guaranteed;
  7615. pf->hw.fdir_shared_filter_count =
  7616. pf->hw.func_caps.fd_filters_best_effort;
  7617. }
  7618. if ((pf->hw.mac.type == I40E_MAC_XL710) &&
  7619. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) ||
  7620. (pf->hw.aq.fw_maj_ver < 4))) {
  7621. pf->flags |= I40E_FLAG_RESTART_AUTONEG;
  7622. /* No DCB support for FW < v4.33 */
  7623. pf->flags |= I40E_FLAG_NO_DCB_SUPPORT;
  7624. }
  7625. /* Disable FW LLDP if FW < v4.3 */
  7626. if ((pf->hw.mac.type == I40E_MAC_XL710) &&
  7627. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) ||
  7628. (pf->hw.aq.fw_maj_ver < 4)))
  7629. pf->flags |= I40E_FLAG_STOP_FW_LLDP;
  7630. /* Use the FW Set LLDP MIB API if FW > v4.40 */
  7631. if ((pf->hw.mac.type == I40E_MAC_XL710) &&
  7632. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) ||
  7633. (pf->hw.aq.fw_maj_ver >= 5)))
  7634. pf->flags |= I40E_FLAG_USE_SET_LLDP_MIB;
  7635. if (pf->hw.func_caps.vmdq) {
  7636. pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
  7637. pf->flags |= I40E_FLAG_VMDQ_ENABLED;
  7638. pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf);
  7639. }
  7640. if (pf->hw.func_caps.iwarp) {
  7641. pf->flags |= I40E_FLAG_IWARP_ENABLED;
  7642. /* IWARP needs one extra vector for CQP just like MISC.*/
  7643. pf->num_iwarp_msix = (int)num_online_cpus() + 1;
  7644. }
  7645. #ifdef I40E_FCOE
  7646. i40e_init_pf_fcoe(pf);
  7647. #endif /* I40E_FCOE */
  7648. #ifdef CONFIG_PCI_IOV
  7649. if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) {
  7650. pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
  7651. pf->flags |= I40E_FLAG_SRIOV_ENABLED;
  7652. pf->num_req_vfs = min_t(int,
  7653. pf->hw.func_caps.num_vfs,
  7654. I40E_MAX_VF_COUNT);
  7655. }
  7656. #endif /* CONFIG_PCI_IOV */
  7657. if (pf->hw.mac.type == I40E_MAC_X722) {
  7658. pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE |
  7659. I40E_FLAG_128_QP_RSS_CAPABLE |
  7660. I40E_FLAG_HW_ATR_EVICT_CAPABLE |
  7661. I40E_FLAG_OUTER_UDP_CSUM_CAPABLE |
  7662. I40E_FLAG_WB_ON_ITR_CAPABLE |
  7663. I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE |
  7664. I40E_FLAG_NO_PCI_LINK_CHECK |
  7665. I40E_FLAG_USE_SET_LLDP_MIB |
  7666. I40E_FLAG_GENEVE_OFFLOAD_CAPABLE |
  7667. I40E_FLAG_PTP_L4_CAPABLE;
  7668. } else if ((pf->hw.aq.api_maj_ver > 1) ||
  7669. ((pf->hw.aq.api_maj_ver == 1) &&
  7670. (pf->hw.aq.api_min_ver > 4))) {
  7671. /* Supported in FW API version higher than 1.4 */
  7672. pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE;
  7673. pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE;
  7674. } else {
  7675. pf->auto_disable_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE;
  7676. }
  7677. pf->eeprom_version = 0xDEAD;
  7678. pf->lan_veb = I40E_NO_VEB;
  7679. pf->lan_vsi = I40E_NO_VSI;
  7680. /* By default FW has this off for performance reasons */
  7681. pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
  7682. /* set up queue assignment tracking */
  7683. size = sizeof(struct i40e_lump_tracking)
  7684. + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
  7685. pf->qp_pile = kzalloc(size, GFP_KERNEL);
  7686. if (!pf->qp_pile) {
  7687. err = -ENOMEM;
  7688. goto sw_init_done;
  7689. }
  7690. pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
  7691. pf->qp_pile->search_hint = 0;
  7692. pf->tx_timeout_recovery_level = 1;
  7693. mutex_init(&pf->switch_mutex);
  7694. /* If NPAR is enabled nudge the Tx scheduler */
  7695. if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf)))
  7696. i40e_set_npar_bw_setting(pf);
  7697. sw_init_done:
  7698. return err;
  7699. }
  7700. /**
  7701. * i40e_set_ntuple - set the ntuple feature flag and take action
  7702. * @pf: board private structure to initialize
  7703. * @features: the feature set that the stack is suggesting
  7704. *
  7705. * returns a bool to indicate if reset needs to happen
  7706. **/
  7707. bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
  7708. {
  7709. bool need_reset = false;
  7710. /* Check if Flow Director n-tuple support was enabled or disabled. If
  7711. * the state changed, we need to reset.
  7712. */
  7713. if (features & NETIF_F_NTUPLE) {
  7714. /* Enable filters and mark for reset */
  7715. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  7716. need_reset = true;
  7717. /* enable FD_SB only if there is MSI-X vector */
  7718. if (pf->num_fdsb_msix > 0)
  7719. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  7720. } else {
  7721. /* turn off filters, mark for reset and clear SW filter list */
  7722. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  7723. need_reset = true;
  7724. i40e_fdir_filter_exit(pf);
  7725. }
  7726. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  7727. pf->auto_disable_flags &= ~I40E_FLAG_FD_SB_ENABLED;
  7728. /* reset fd counters */
  7729. pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0;
  7730. pf->fdir_pf_active_filters = 0;
  7731. /* if ATR was auto disabled it can be re-enabled. */
  7732. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  7733. (pf->auto_disable_flags & I40E_FLAG_FD_ATR_ENABLED)) {
  7734. pf->auto_disable_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  7735. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  7736. dev_info(&pf->pdev->dev, "ATR re-enabled.\n");
  7737. }
  7738. }
  7739. return need_reset;
  7740. }
  7741. /**
  7742. * i40e_clear_rss_lut - clear the rx hash lookup table
  7743. * @vsi: the VSI being configured
  7744. **/
  7745. static void i40e_clear_rss_lut(struct i40e_vsi *vsi)
  7746. {
  7747. struct i40e_pf *pf = vsi->back;
  7748. struct i40e_hw *hw = &pf->hw;
  7749. u16 vf_id = vsi->vf_id;
  7750. u8 i;
  7751. if (vsi->type == I40E_VSI_MAIN) {
  7752. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  7753. wr32(hw, I40E_PFQF_HLUT(i), 0);
  7754. } else if (vsi->type == I40E_VSI_SRIOV) {
  7755. for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
  7756. i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0);
  7757. } else {
  7758. dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
  7759. }
  7760. }
  7761. /**
  7762. * i40e_set_features - set the netdev feature flags
  7763. * @netdev: ptr to the netdev being adjusted
  7764. * @features: the feature set that the stack is suggesting
  7765. **/
  7766. static int i40e_set_features(struct net_device *netdev,
  7767. netdev_features_t features)
  7768. {
  7769. struct i40e_netdev_priv *np = netdev_priv(netdev);
  7770. struct i40e_vsi *vsi = np->vsi;
  7771. struct i40e_pf *pf = vsi->back;
  7772. bool need_reset;
  7773. if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
  7774. i40e_pf_config_rss(pf);
  7775. else if (!(features & NETIF_F_RXHASH) &&
  7776. netdev->features & NETIF_F_RXHASH)
  7777. i40e_clear_rss_lut(vsi);
  7778. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  7779. i40e_vlan_stripping_enable(vsi);
  7780. else
  7781. i40e_vlan_stripping_disable(vsi);
  7782. need_reset = i40e_set_ntuple(pf, features);
  7783. if (need_reset)
  7784. i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
  7785. return 0;
  7786. }
  7787. /**
  7788. * i40e_get_udp_port_idx - Lookup a possibly offloaded for Rx UDP port
  7789. * @pf: board private structure
  7790. * @port: The UDP port to look up
  7791. *
  7792. * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
  7793. **/
  7794. static u8 i40e_get_udp_port_idx(struct i40e_pf *pf, __be16 port)
  7795. {
  7796. u8 i;
  7797. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  7798. if (pf->udp_ports[i].index == port)
  7799. return i;
  7800. }
  7801. return i;
  7802. }
  7803. /**
  7804. * i40e_udp_tunnel_add - Get notifications about UDP tunnel ports that come up
  7805. * @netdev: This physical port's netdev
  7806. * @ti: Tunnel endpoint information
  7807. **/
  7808. static void i40e_udp_tunnel_add(struct net_device *netdev,
  7809. struct udp_tunnel_info *ti)
  7810. {
  7811. struct i40e_netdev_priv *np = netdev_priv(netdev);
  7812. struct i40e_vsi *vsi = np->vsi;
  7813. struct i40e_pf *pf = vsi->back;
  7814. __be16 port = ti->port;
  7815. u8 next_idx;
  7816. u8 idx;
  7817. idx = i40e_get_udp_port_idx(pf, port);
  7818. /* Check if port already exists */
  7819. if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  7820. netdev_info(netdev, "port %d already offloaded\n",
  7821. ntohs(port));
  7822. return;
  7823. }
  7824. /* Now check if there is space to add the new port */
  7825. next_idx = i40e_get_udp_port_idx(pf, 0);
  7826. if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  7827. netdev_info(netdev, "maximum number of offloaded UDP ports reached, not adding port %d\n",
  7828. ntohs(port));
  7829. return;
  7830. }
  7831. switch (ti->type) {
  7832. case UDP_TUNNEL_TYPE_VXLAN:
  7833. pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN;
  7834. break;
  7835. case UDP_TUNNEL_TYPE_GENEVE:
  7836. if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE))
  7837. return;
  7838. pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE;
  7839. break;
  7840. default:
  7841. return;
  7842. }
  7843. /* New port: add it and mark its index in the bitmap */
  7844. pf->udp_ports[next_idx].index = port;
  7845. pf->pending_udp_bitmap |= BIT_ULL(next_idx);
  7846. pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
  7847. }
  7848. /**
  7849. * i40e_udp_tunnel_del - Get notifications about UDP tunnel ports that go away
  7850. * @netdev: This physical port's netdev
  7851. * @ti: Tunnel endpoint information
  7852. **/
  7853. static void i40e_udp_tunnel_del(struct net_device *netdev,
  7854. struct udp_tunnel_info *ti)
  7855. {
  7856. struct i40e_netdev_priv *np = netdev_priv(netdev);
  7857. struct i40e_vsi *vsi = np->vsi;
  7858. struct i40e_pf *pf = vsi->back;
  7859. __be16 port = ti->port;
  7860. u8 idx;
  7861. idx = i40e_get_udp_port_idx(pf, port);
  7862. /* Check if port already exists */
  7863. if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS)
  7864. goto not_found;
  7865. switch (ti->type) {
  7866. case UDP_TUNNEL_TYPE_VXLAN:
  7867. if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN)
  7868. goto not_found;
  7869. break;
  7870. case UDP_TUNNEL_TYPE_GENEVE:
  7871. if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE)
  7872. goto not_found;
  7873. break;
  7874. default:
  7875. goto not_found;
  7876. }
  7877. /* if port exists, set it to 0 (mark for deletion)
  7878. * and make it pending
  7879. */
  7880. pf->udp_ports[idx].index = 0;
  7881. pf->pending_udp_bitmap |= BIT_ULL(idx);
  7882. pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
  7883. return;
  7884. not_found:
  7885. netdev_warn(netdev, "UDP port %d was not found, not deleting\n",
  7886. ntohs(port));
  7887. }
  7888. static int i40e_get_phys_port_id(struct net_device *netdev,
  7889. struct netdev_phys_item_id *ppid)
  7890. {
  7891. struct i40e_netdev_priv *np = netdev_priv(netdev);
  7892. struct i40e_pf *pf = np->vsi->back;
  7893. struct i40e_hw *hw = &pf->hw;
  7894. if (!(pf->flags & I40E_FLAG_PORT_ID_VALID))
  7895. return -EOPNOTSUPP;
  7896. ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id));
  7897. memcpy(ppid->id, hw->mac.port_addr, ppid->id_len);
  7898. return 0;
  7899. }
  7900. /**
  7901. * i40e_ndo_fdb_add - add an entry to the hardware database
  7902. * @ndm: the input from the stack
  7903. * @tb: pointer to array of nladdr (unused)
  7904. * @dev: the net device pointer
  7905. * @addr: the MAC address entry being added
  7906. * @flags: instructions from stack about fdb operation
  7907. */
  7908. static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  7909. struct net_device *dev,
  7910. const unsigned char *addr, u16 vid,
  7911. u16 flags)
  7912. {
  7913. struct i40e_netdev_priv *np = netdev_priv(dev);
  7914. struct i40e_pf *pf = np->vsi->back;
  7915. int err = 0;
  7916. if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
  7917. return -EOPNOTSUPP;
  7918. if (vid) {
  7919. pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name);
  7920. return -EINVAL;
  7921. }
  7922. /* Hardware does not support aging addresses so if a
  7923. * ndm_state is given only allow permanent addresses
  7924. */
  7925. if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
  7926. netdev_info(dev, "FDB only supports static addresses\n");
  7927. return -EINVAL;
  7928. }
  7929. if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
  7930. err = dev_uc_add_excl(dev, addr);
  7931. else if (is_multicast_ether_addr(addr))
  7932. err = dev_mc_add_excl(dev, addr);
  7933. else
  7934. err = -EINVAL;
  7935. /* Only return duplicate errors if NLM_F_EXCL is set */
  7936. if (err == -EEXIST && !(flags & NLM_F_EXCL))
  7937. err = 0;
  7938. return err;
  7939. }
  7940. /**
  7941. * i40e_ndo_bridge_setlink - Set the hardware bridge mode
  7942. * @dev: the netdev being configured
  7943. * @nlh: RTNL message
  7944. *
  7945. * Inserts a new hardware bridge if not already created and
  7946. * enables the bridging mode requested (VEB or VEPA). If the
  7947. * hardware bridge has already been inserted and the request
  7948. * is to change the mode then that requires a PF reset to
  7949. * allow rebuild of the components with required hardware
  7950. * bridge mode enabled.
  7951. **/
  7952. static int i40e_ndo_bridge_setlink(struct net_device *dev,
  7953. struct nlmsghdr *nlh,
  7954. u16 flags)
  7955. {
  7956. struct i40e_netdev_priv *np = netdev_priv(dev);
  7957. struct i40e_vsi *vsi = np->vsi;
  7958. struct i40e_pf *pf = vsi->back;
  7959. struct i40e_veb *veb = NULL;
  7960. struct nlattr *attr, *br_spec;
  7961. int i, rem;
  7962. /* Only for PF VSI for now */
  7963. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
  7964. return -EOPNOTSUPP;
  7965. /* Find the HW bridge for PF VSI */
  7966. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  7967. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  7968. veb = pf->veb[i];
  7969. }
  7970. br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
  7971. nla_for_each_nested(attr, br_spec, rem) {
  7972. __u16 mode;
  7973. if (nla_type(attr) != IFLA_BRIDGE_MODE)
  7974. continue;
  7975. mode = nla_get_u16(attr);
  7976. if ((mode != BRIDGE_MODE_VEPA) &&
  7977. (mode != BRIDGE_MODE_VEB))
  7978. return -EINVAL;
  7979. /* Insert a new HW bridge */
  7980. if (!veb) {
  7981. veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
  7982. vsi->tc_config.enabled_tc);
  7983. if (veb) {
  7984. veb->bridge_mode = mode;
  7985. i40e_config_bridge_mode(veb);
  7986. } else {
  7987. /* No Bridge HW offload available */
  7988. return -ENOENT;
  7989. }
  7990. break;
  7991. } else if (mode != veb->bridge_mode) {
  7992. /* Existing HW bridge but different mode needs reset */
  7993. veb->bridge_mode = mode;
  7994. /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
  7995. if (mode == BRIDGE_MODE_VEB)
  7996. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  7997. else
  7998. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  7999. i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
  8000. break;
  8001. }
  8002. }
  8003. return 0;
  8004. }
  8005. /**
  8006. * i40e_ndo_bridge_getlink - Get the hardware bridge mode
  8007. * @skb: skb buff
  8008. * @pid: process id
  8009. * @seq: RTNL message seq #
  8010. * @dev: the netdev being configured
  8011. * @filter_mask: unused
  8012. * @nlflags: netlink flags passed in
  8013. *
  8014. * Return the mode in which the hardware bridge is operating in
  8015. * i.e VEB or VEPA.
  8016. **/
  8017. static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
  8018. struct net_device *dev,
  8019. u32 __always_unused filter_mask,
  8020. int nlflags)
  8021. {
  8022. struct i40e_netdev_priv *np = netdev_priv(dev);
  8023. struct i40e_vsi *vsi = np->vsi;
  8024. struct i40e_pf *pf = vsi->back;
  8025. struct i40e_veb *veb = NULL;
  8026. int i;
  8027. /* Only for PF VSI for now */
  8028. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
  8029. return -EOPNOTSUPP;
  8030. /* Find the HW bridge for the PF VSI */
  8031. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  8032. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  8033. veb = pf->veb[i];
  8034. }
  8035. if (!veb)
  8036. return 0;
  8037. return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode,
  8038. 0, 0, nlflags, filter_mask, NULL);
  8039. }
  8040. /**
  8041. * i40e_features_check - Validate encapsulated packet conforms to limits
  8042. * @skb: skb buff
  8043. * @dev: This physical port's netdev
  8044. * @features: Offload features that the stack believes apply
  8045. **/
  8046. static netdev_features_t i40e_features_check(struct sk_buff *skb,
  8047. struct net_device *dev,
  8048. netdev_features_t features)
  8049. {
  8050. size_t len;
  8051. /* No point in doing any of this if neither checksum nor GSO are
  8052. * being requested for this frame. We can rule out both by just
  8053. * checking for CHECKSUM_PARTIAL
  8054. */
  8055. if (skb->ip_summed != CHECKSUM_PARTIAL)
  8056. return features;
  8057. /* We cannot support GSO if the MSS is going to be less than
  8058. * 64 bytes. If it is then we need to drop support for GSO.
  8059. */
  8060. if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
  8061. features &= ~NETIF_F_GSO_MASK;
  8062. /* MACLEN can support at most 63 words */
  8063. len = skb_network_header(skb) - skb->data;
  8064. if (len & ~(63 * 2))
  8065. goto out_err;
  8066. /* IPLEN and EIPLEN can support at most 127 dwords */
  8067. len = skb_transport_header(skb) - skb_network_header(skb);
  8068. if (len & ~(127 * 4))
  8069. goto out_err;
  8070. if (skb->encapsulation) {
  8071. /* L4TUNLEN can support 127 words */
  8072. len = skb_inner_network_header(skb) - skb_transport_header(skb);
  8073. if (len & ~(127 * 2))
  8074. goto out_err;
  8075. /* IPLEN can support at most 127 dwords */
  8076. len = skb_inner_transport_header(skb) -
  8077. skb_inner_network_header(skb);
  8078. if (len & ~(127 * 4))
  8079. goto out_err;
  8080. }
  8081. /* No need to validate L4LEN as TCP is the only protocol with a
  8082. * a flexible value and we support all possible values supported
  8083. * by TCP, which is at most 15 dwords
  8084. */
  8085. return features;
  8086. out_err:
  8087. return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
  8088. }
  8089. static const struct net_device_ops i40e_netdev_ops = {
  8090. .ndo_open = i40e_open,
  8091. .ndo_stop = i40e_close,
  8092. .ndo_start_xmit = i40e_lan_xmit_frame,
  8093. .ndo_get_stats64 = i40e_get_netdev_stats_struct,
  8094. .ndo_set_rx_mode = i40e_set_rx_mode,
  8095. .ndo_validate_addr = eth_validate_addr,
  8096. .ndo_set_mac_address = i40e_set_mac,
  8097. .ndo_change_mtu = i40e_change_mtu,
  8098. .ndo_do_ioctl = i40e_ioctl,
  8099. .ndo_tx_timeout = i40e_tx_timeout,
  8100. .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
  8101. .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
  8102. #ifdef CONFIG_NET_POLL_CONTROLLER
  8103. .ndo_poll_controller = i40e_netpoll,
  8104. #endif
  8105. .ndo_setup_tc = __i40e_setup_tc,
  8106. #ifdef I40E_FCOE
  8107. .ndo_fcoe_enable = i40e_fcoe_enable,
  8108. .ndo_fcoe_disable = i40e_fcoe_disable,
  8109. #endif
  8110. .ndo_set_features = i40e_set_features,
  8111. .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
  8112. .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
  8113. .ndo_set_vf_rate = i40e_ndo_set_vf_bw,
  8114. .ndo_get_vf_config = i40e_ndo_get_vf_config,
  8115. .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
  8116. .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk,
  8117. .ndo_set_vf_trust = i40e_ndo_set_vf_trust,
  8118. .ndo_udp_tunnel_add = i40e_udp_tunnel_add,
  8119. .ndo_udp_tunnel_del = i40e_udp_tunnel_del,
  8120. .ndo_get_phys_port_id = i40e_get_phys_port_id,
  8121. .ndo_fdb_add = i40e_ndo_fdb_add,
  8122. .ndo_features_check = i40e_features_check,
  8123. .ndo_bridge_getlink = i40e_ndo_bridge_getlink,
  8124. .ndo_bridge_setlink = i40e_ndo_bridge_setlink,
  8125. };
  8126. /**
  8127. * i40e_config_netdev - Setup the netdev flags
  8128. * @vsi: the VSI being configured
  8129. *
  8130. * Returns 0 on success, negative value on failure
  8131. **/
  8132. static int i40e_config_netdev(struct i40e_vsi *vsi)
  8133. {
  8134. struct i40e_pf *pf = vsi->back;
  8135. struct i40e_hw *hw = &pf->hw;
  8136. struct i40e_netdev_priv *np;
  8137. struct net_device *netdev;
  8138. u8 broadcast[ETH_ALEN];
  8139. u8 mac_addr[ETH_ALEN];
  8140. int etherdev_size;
  8141. etherdev_size = sizeof(struct i40e_netdev_priv);
  8142. netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
  8143. if (!netdev)
  8144. return -ENOMEM;
  8145. vsi->netdev = netdev;
  8146. np = netdev_priv(netdev);
  8147. np->vsi = vsi;
  8148. netdev->hw_enc_features |= NETIF_F_SG |
  8149. NETIF_F_IP_CSUM |
  8150. NETIF_F_IPV6_CSUM |
  8151. NETIF_F_HIGHDMA |
  8152. NETIF_F_SOFT_FEATURES |
  8153. NETIF_F_TSO |
  8154. NETIF_F_TSO_ECN |
  8155. NETIF_F_TSO6 |
  8156. NETIF_F_GSO_GRE |
  8157. NETIF_F_GSO_GRE_CSUM |
  8158. NETIF_F_GSO_IPXIP4 |
  8159. NETIF_F_GSO_IPXIP6 |
  8160. NETIF_F_GSO_UDP_TUNNEL |
  8161. NETIF_F_GSO_UDP_TUNNEL_CSUM |
  8162. NETIF_F_GSO_PARTIAL |
  8163. NETIF_F_SCTP_CRC |
  8164. NETIF_F_RXHASH |
  8165. NETIF_F_RXCSUM |
  8166. 0;
  8167. if (!(pf->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE))
  8168. netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM;
  8169. netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM;
  8170. /* record features VLANs can make use of */
  8171. netdev->vlan_features |= netdev->hw_enc_features |
  8172. NETIF_F_TSO_MANGLEID;
  8173. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  8174. netdev->hw_features |= NETIF_F_NTUPLE;
  8175. netdev->hw_features |= netdev->hw_enc_features |
  8176. NETIF_F_HW_VLAN_CTAG_TX |
  8177. NETIF_F_HW_VLAN_CTAG_RX;
  8178. netdev->features |= netdev->hw_features | NETIF_F_HW_VLAN_CTAG_FILTER;
  8179. netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID;
  8180. if (vsi->type == I40E_VSI_MAIN) {
  8181. SET_NETDEV_DEV(netdev, &pf->pdev->dev);
  8182. ether_addr_copy(mac_addr, hw->mac.perm_addr);
  8183. /* The following steps are necessary to prevent reception
  8184. * of tagged packets - some older NVM configurations load a
  8185. * default a MAC-VLAN filter that accepts any tagged packet
  8186. * which must be replaced by a normal filter.
  8187. */
  8188. i40e_rm_default_mac_filter(vsi, mac_addr);
  8189. spin_lock_bh(&vsi->mac_filter_hash_lock);
  8190. i40e_add_mac_filter(vsi, mac_addr);
  8191. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  8192. } else {
  8193. /* relate the VSI_VMDQ name to the VSI_MAIN name */
  8194. snprintf(netdev->name, IFNAMSIZ, "%sv%%d",
  8195. pf->vsi[pf->lan_vsi]->netdev->name);
  8196. random_ether_addr(mac_addr);
  8197. spin_lock_bh(&vsi->mac_filter_hash_lock);
  8198. i40e_add_mac_filter(vsi, mac_addr);
  8199. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  8200. }
  8201. /* Add the broadcast filter so that we initially will receive
  8202. * broadcast packets. Note that when a new VLAN is first added the
  8203. * driver will convert all filters marked I40E_VLAN_ANY into VLAN
  8204. * specific filters as part of transitioning into "vlan" operation.
  8205. * When more VLANs are added, the driver will copy each existing MAC
  8206. * filter and add it for the new VLAN.
  8207. *
  8208. * Broadcast filters are handled specially by
  8209. * i40e_sync_filters_subtask, as the driver must to set the broadcast
  8210. * promiscuous bit instead of adding this directly as a MAC/VLAN
  8211. * filter. The subtask will update the correct broadcast promiscuous
  8212. * bits as VLANs become active or inactive.
  8213. */
  8214. eth_broadcast_addr(broadcast);
  8215. spin_lock_bh(&vsi->mac_filter_hash_lock);
  8216. i40e_add_mac_filter(vsi, broadcast);
  8217. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  8218. ether_addr_copy(netdev->dev_addr, mac_addr);
  8219. ether_addr_copy(netdev->perm_addr, mac_addr);
  8220. netdev->priv_flags |= IFF_UNICAST_FLT;
  8221. netdev->priv_flags |= IFF_SUPP_NOFCS;
  8222. /* Setup netdev TC information */
  8223. i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
  8224. netdev->netdev_ops = &i40e_netdev_ops;
  8225. netdev->watchdog_timeo = 5 * HZ;
  8226. i40e_set_ethtool_ops(netdev);
  8227. #ifdef I40E_FCOE
  8228. i40e_fcoe_config_netdev(netdev, vsi);
  8229. #endif
  8230. /* MTU range: 68 - 9706 */
  8231. netdev->min_mtu = ETH_MIN_MTU;
  8232. netdev->max_mtu = I40E_MAX_RXBUFFER -
  8233. (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN);
  8234. return 0;
  8235. }
  8236. /**
  8237. * i40e_vsi_delete - Delete a VSI from the switch
  8238. * @vsi: the VSI being removed
  8239. *
  8240. * Returns 0 on success, negative value on failure
  8241. **/
  8242. static void i40e_vsi_delete(struct i40e_vsi *vsi)
  8243. {
  8244. /* remove default VSI is not allowed */
  8245. if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
  8246. return;
  8247. i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
  8248. }
  8249. /**
  8250. * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
  8251. * @vsi: the VSI being queried
  8252. *
  8253. * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
  8254. **/
  8255. int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi)
  8256. {
  8257. struct i40e_veb *veb;
  8258. struct i40e_pf *pf = vsi->back;
  8259. /* Uplink is not a bridge so default to VEB */
  8260. if (vsi->veb_idx == I40E_NO_VEB)
  8261. return 1;
  8262. veb = pf->veb[vsi->veb_idx];
  8263. if (!veb) {
  8264. dev_info(&pf->pdev->dev,
  8265. "There is no veb associated with the bridge\n");
  8266. return -ENOENT;
  8267. }
  8268. /* Uplink is a bridge in VEPA mode */
  8269. if (veb->bridge_mode & BRIDGE_MODE_VEPA) {
  8270. return 0;
  8271. } else {
  8272. /* Uplink is a bridge in VEB mode */
  8273. return 1;
  8274. }
  8275. /* VEPA is now default bridge, so return 0 */
  8276. return 0;
  8277. }
  8278. /**
  8279. * i40e_add_vsi - Add a VSI to the switch
  8280. * @vsi: the VSI being configured
  8281. *
  8282. * This initializes a VSI context depending on the VSI type to be added and
  8283. * passes it down to the add_vsi aq command.
  8284. **/
  8285. static int i40e_add_vsi(struct i40e_vsi *vsi)
  8286. {
  8287. int ret = -ENODEV;
  8288. struct i40e_pf *pf = vsi->back;
  8289. struct i40e_hw *hw = &pf->hw;
  8290. struct i40e_vsi_context ctxt;
  8291. struct i40e_mac_filter *f;
  8292. struct hlist_node *h;
  8293. int bkt;
  8294. u8 enabled_tc = 0x1; /* TC0 enabled */
  8295. int f_count = 0;
  8296. memset(&ctxt, 0, sizeof(ctxt));
  8297. switch (vsi->type) {
  8298. case I40E_VSI_MAIN:
  8299. /* The PF's main VSI is already setup as part of the
  8300. * device initialization, so we'll not bother with
  8301. * the add_vsi call, but we will retrieve the current
  8302. * VSI context.
  8303. */
  8304. ctxt.seid = pf->main_vsi_seid;
  8305. ctxt.pf_num = pf->hw.pf_id;
  8306. ctxt.vf_num = 0;
  8307. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  8308. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  8309. if (ret) {
  8310. dev_info(&pf->pdev->dev,
  8311. "couldn't get PF vsi config, err %s aq_err %s\n",
  8312. i40e_stat_str(&pf->hw, ret),
  8313. i40e_aq_str(&pf->hw,
  8314. pf->hw.aq.asq_last_status));
  8315. return -ENOENT;
  8316. }
  8317. vsi->info = ctxt.info;
  8318. vsi->info.valid_sections = 0;
  8319. vsi->seid = ctxt.seid;
  8320. vsi->id = ctxt.vsi_number;
  8321. enabled_tc = i40e_pf_get_tc_map(pf);
  8322. /* MFP mode setup queue map and update VSI */
  8323. if ((pf->flags & I40E_FLAG_MFP_ENABLED) &&
  8324. !(pf->hw.func_caps.iscsi)) { /* NIC type PF */
  8325. memset(&ctxt, 0, sizeof(ctxt));
  8326. ctxt.seid = pf->main_vsi_seid;
  8327. ctxt.pf_num = pf->hw.pf_id;
  8328. ctxt.vf_num = 0;
  8329. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  8330. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  8331. if (ret) {
  8332. dev_info(&pf->pdev->dev,
  8333. "update vsi failed, err %s aq_err %s\n",
  8334. i40e_stat_str(&pf->hw, ret),
  8335. i40e_aq_str(&pf->hw,
  8336. pf->hw.aq.asq_last_status));
  8337. ret = -ENOENT;
  8338. goto err;
  8339. }
  8340. /* update the local VSI info queue map */
  8341. i40e_vsi_update_queue_map(vsi, &ctxt);
  8342. vsi->info.valid_sections = 0;
  8343. } else {
  8344. /* Default/Main VSI is only enabled for TC0
  8345. * reconfigure it to enable all TCs that are
  8346. * available on the port in SFP mode.
  8347. * For MFP case the iSCSI PF would use this
  8348. * flow to enable LAN+iSCSI TC.
  8349. */
  8350. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  8351. if (ret) {
  8352. dev_info(&pf->pdev->dev,
  8353. "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
  8354. enabled_tc,
  8355. i40e_stat_str(&pf->hw, ret),
  8356. i40e_aq_str(&pf->hw,
  8357. pf->hw.aq.asq_last_status));
  8358. ret = -ENOENT;
  8359. }
  8360. }
  8361. break;
  8362. case I40E_VSI_FDIR:
  8363. ctxt.pf_num = hw->pf_id;
  8364. ctxt.vf_num = 0;
  8365. ctxt.uplink_seid = vsi->uplink_seid;
  8366. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  8367. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  8368. if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) &&
  8369. (i40e_is_vsi_uplink_mode_veb(vsi))) {
  8370. ctxt.info.valid_sections |=
  8371. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  8372. ctxt.info.switch_id =
  8373. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  8374. }
  8375. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  8376. break;
  8377. case I40E_VSI_VMDQ2:
  8378. ctxt.pf_num = hw->pf_id;
  8379. ctxt.vf_num = 0;
  8380. ctxt.uplink_seid = vsi->uplink_seid;
  8381. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  8382. ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
  8383. /* This VSI is connected to VEB so the switch_id
  8384. * should be set to zero by default.
  8385. */
  8386. if (i40e_is_vsi_uplink_mode_veb(vsi)) {
  8387. ctxt.info.valid_sections |=
  8388. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  8389. ctxt.info.switch_id =
  8390. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  8391. }
  8392. /* Setup the VSI tx/rx queue map for TC0 only for now */
  8393. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  8394. break;
  8395. case I40E_VSI_SRIOV:
  8396. ctxt.pf_num = hw->pf_id;
  8397. ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
  8398. ctxt.uplink_seid = vsi->uplink_seid;
  8399. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  8400. ctxt.flags = I40E_AQ_VSI_TYPE_VF;
  8401. /* This VSI is connected to VEB so the switch_id
  8402. * should be set to zero by default.
  8403. */
  8404. if (i40e_is_vsi_uplink_mode_veb(vsi)) {
  8405. ctxt.info.valid_sections |=
  8406. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  8407. ctxt.info.switch_id =
  8408. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  8409. }
  8410. if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
  8411. ctxt.info.valid_sections |=
  8412. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  8413. ctxt.info.queueing_opt_flags |=
  8414. (I40E_AQ_VSI_QUE_OPT_TCP_ENA |
  8415. I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI);
  8416. }
  8417. ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  8418. ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
  8419. if (pf->vf[vsi->vf_id].spoofchk) {
  8420. ctxt.info.valid_sections |=
  8421. cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
  8422. ctxt.info.sec_flags |=
  8423. (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
  8424. I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
  8425. }
  8426. /* Setup the VSI tx/rx queue map for TC0 only for now */
  8427. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  8428. break;
  8429. #ifdef I40E_FCOE
  8430. case I40E_VSI_FCOE:
  8431. ret = i40e_fcoe_vsi_init(vsi, &ctxt);
  8432. if (ret) {
  8433. dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n");
  8434. return ret;
  8435. }
  8436. break;
  8437. #endif /* I40E_FCOE */
  8438. case I40E_VSI_IWARP:
  8439. /* send down message to iWARP */
  8440. break;
  8441. default:
  8442. return -ENODEV;
  8443. }
  8444. if (vsi->type != I40E_VSI_MAIN) {
  8445. ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
  8446. if (ret) {
  8447. dev_info(&vsi->back->pdev->dev,
  8448. "add vsi failed, err %s aq_err %s\n",
  8449. i40e_stat_str(&pf->hw, ret),
  8450. i40e_aq_str(&pf->hw,
  8451. pf->hw.aq.asq_last_status));
  8452. ret = -ENOENT;
  8453. goto err;
  8454. }
  8455. vsi->info = ctxt.info;
  8456. vsi->info.valid_sections = 0;
  8457. vsi->seid = ctxt.seid;
  8458. vsi->id = ctxt.vsi_number;
  8459. }
  8460. vsi->active_filters = 0;
  8461. clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state);
  8462. spin_lock_bh(&vsi->mac_filter_hash_lock);
  8463. /* If macvlan filters already exist, force them to get loaded */
  8464. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  8465. f->state = I40E_FILTER_NEW;
  8466. f_count++;
  8467. }
  8468. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  8469. if (f_count) {
  8470. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  8471. pf->flags |= I40E_FLAG_FILTER_SYNC;
  8472. }
  8473. /* Update VSI BW information */
  8474. ret = i40e_vsi_get_bw_info(vsi);
  8475. if (ret) {
  8476. dev_info(&pf->pdev->dev,
  8477. "couldn't get vsi bw info, err %s aq_err %s\n",
  8478. i40e_stat_str(&pf->hw, ret),
  8479. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8480. /* VSI is already added so not tearing that up */
  8481. ret = 0;
  8482. }
  8483. err:
  8484. return ret;
  8485. }
  8486. /**
  8487. * i40e_vsi_release - Delete a VSI and free its resources
  8488. * @vsi: the VSI being removed
  8489. *
  8490. * Returns 0 on success or < 0 on error
  8491. **/
  8492. int i40e_vsi_release(struct i40e_vsi *vsi)
  8493. {
  8494. struct i40e_mac_filter *f;
  8495. struct hlist_node *h;
  8496. struct i40e_veb *veb = NULL;
  8497. struct i40e_pf *pf;
  8498. u16 uplink_seid;
  8499. int i, n, bkt;
  8500. pf = vsi->back;
  8501. /* release of a VEB-owner or last VSI is not allowed */
  8502. if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
  8503. dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
  8504. vsi->seid, vsi->uplink_seid);
  8505. return -ENODEV;
  8506. }
  8507. if (vsi == pf->vsi[pf->lan_vsi] &&
  8508. !test_bit(__I40E_DOWN, &pf->state)) {
  8509. dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
  8510. return -ENODEV;
  8511. }
  8512. uplink_seid = vsi->uplink_seid;
  8513. if (vsi->type != I40E_VSI_SRIOV) {
  8514. if (vsi->netdev_registered) {
  8515. vsi->netdev_registered = false;
  8516. if (vsi->netdev) {
  8517. /* results in a call to i40e_close() */
  8518. unregister_netdev(vsi->netdev);
  8519. }
  8520. } else {
  8521. i40e_vsi_close(vsi);
  8522. }
  8523. i40e_vsi_disable_irq(vsi);
  8524. }
  8525. spin_lock_bh(&vsi->mac_filter_hash_lock);
  8526. /* clear the sync flag on all filters */
  8527. if (vsi->netdev) {
  8528. __dev_uc_unsync(vsi->netdev, NULL);
  8529. __dev_mc_unsync(vsi->netdev, NULL);
  8530. }
  8531. /* make sure any remaining filters are marked for deletion */
  8532. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist)
  8533. __i40e_del_filter(vsi, f);
  8534. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  8535. i40e_sync_vsi_filters(vsi);
  8536. i40e_vsi_delete(vsi);
  8537. i40e_vsi_free_q_vectors(vsi);
  8538. if (vsi->netdev) {
  8539. free_netdev(vsi->netdev);
  8540. vsi->netdev = NULL;
  8541. }
  8542. i40e_vsi_clear_rings(vsi);
  8543. i40e_vsi_clear(vsi);
  8544. /* If this was the last thing on the VEB, except for the
  8545. * controlling VSI, remove the VEB, which puts the controlling
  8546. * VSI onto the next level down in the switch.
  8547. *
  8548. * Well, okay, there's one more exception here: don't remove
  8549. * the orphan VEBs yet. We'll wait for an explicit remove request
  8550. * from up the network stack.
  8551. */
  8552. for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) {
  8553. if (pf->vsi[i] &&
  8554. pf->vsi[i]->uplink_seid == uplink_seid &&
  8555. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  8556. n++; /* count the VSIs */
  8557. }
  8558. }
  8559. for (i = 0; i < I40E_MAX_VEB; i++) {
  8560. if (!pf->veb[i])
  8561. continue;
  8562. if (pf->veb[i]->uplink_seid == uplink_seid)
  8563. n++; /* count the VEBs */
  8564. if (pf->veb[i]->seid == uplink_seid)
  8565. veb = pf->veb[i];
  8566. }
  8567. if (n == 0 && veb && veb->uplink_seid != 0)
  8568. i40e_veb_release(veb);
  8569. return 0;
  8570. }
  8571. /**
  8572. * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
  8573. * @vsi: ptr to the VSI
  8574. *
  8575. * This should only be called after i40e_vsi_mem_alloc() which allocates the
  8576. * corresponding SW VSI structure and initializes num_queue_pairs for the
  8577. * newly allocated VSI.
  8578. *
  8579. * Returns 0 on success or negative on failure
  8580. **/
  8581. static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
  8582. {
  8583. int ret = -ENOENT;
  8584. struct i40e_pf *pf = vsi->back;
  8585. if (vsi->q_vectors[0]) {
  8586. dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
  8587. vsi->seid);
  8588. return -EEXIST;
  8589. }
  8590. if (vsi->base_vector) {
  8591. dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
  8592. vsi->seid, vsi->base_vector);
  8593. return -EEXIST;
  8594. }
  8595. ret = i40e_vsi_alloc_q_vectors(vsi);
  8596. if (ret) {
  8597. dev_info(&pf->pdev->dev,
  8598. "failed to allocate %d q_vector for VSI %d, ret=%d\n",
  8599. vsi->num_q_vectors, vsi->seid, ret);
  8600. vsi->num_q_vectors = 0;
  8601. goto vector_setup_out;
  8602. }
  8603. /* In Legacy mode, we do not have to get any other vector since we
  8604. * piggyback on the misc/ICR0 for queue interrupts.
  8605. */
  8606. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  8607. return ret;
  8608. if (vsi->num_q_vectors)
  8609. vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
  8610. vsi->num_q_vectors, vsi->idx);
  8611. if (vsi->base_vector < 0) {
  8612. dev_info(&pf->pdev->dev,
  8613. "failed to get tracking for %d vectors for VSI %d, err=%d\n",
  8614. vsi->num_q_vectors, vsi->seid, vsi->base_vector);
  8615. i40e_vsi_free_q_vectors(vsi);
  8616. ret = -ENOENT;
  8617. goto vector_setup_out;
  8618. }
  8619. vector_setup_out:
  8620. return ret;
  8621. }
  8622. /**
  8623. * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
  8624. * @vsi: pointer to the vsi.
  8625. *
  8626. * This re-allocates a vsi's queue resources.
  8627. *
  8628. * Returns pointer to the successfully allocated and configured VSI sw struct
  8629. * on success, otherwise returns NULL on failure.
  8630. **/
  8631. static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
  8632. {
  8633. struct i40e_pf *pf;
  8634. u8 enabled_tc;
  8635. int ret;
  8636. if (!vsi)
  8637. return NULL;
  8638. pf = vsi->back;
  8639. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  8640. i40e_vsi_clear_rings(vsi);
  8641. i40e_vsi_free_arrays(vsi, false);
  8642. i40e_set_num_rings_in_vsi(vsi);
  8643. ret = i40e_vsi_alloc_arrays(vsi, false);
  8644. if (ret)
  8645. goto err_vsi;
  8646. ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx);
  8647. if (ret < 0) {
  8648. dev_info(&pf->pdev->dev,
  8649. "failed to get tracking for %d queues for VSI %d err %d\n",
  8650. vsi->alloc_queue_pairs, vsi->seid, ret);
  8651. goto err_vsi;
  8652. }
  8653. vsi->base_queue = ret;
  8654. /* Update the FW view of the VSI. Force a reset of TC and queue
  8655. * layout configurations.
  8656. */
  8657. enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  8658. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  8659. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  8660. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  8661. if (vsi->type == I40E_VSI_MAIN)
  8662. i40e_rm_default_mac_filter(vsi, pf->hw.mac.perm_addr);
  8663. /* assign it some queues */
  8664. ret = i40e_alloc_rings(vsi);
  8665. if (ret)
  8666. goto err_rings;
  8667. /* map all of the rings to the q_vectors */
  8668. i40e_vsi_map_rings_to_vectors(vsi);
  8669. return vsi;
  8670. err_rings:
  8671. i40e_vsi_free_q_vectors(vsi);
  8672. if (vsi->netdev_registered) {
  8673. vsi->netdev_registered = false;
  8674. unregister_netdev(vsi->netdev);
  8675. free_netdev(vsi->netdev);
  8676. vsi->netdev = NULL;
  8677. }
  8678. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  8679. err_vsi:
  8680. i40e_vsi_clear(vsi);
  8681. return NULL;
  8682. }
  8683. /**
  8684. * i40e_vsi_setup - Set up a VSI by a given type
  8685. * @pf: board private structure
  8686. * @type: VSI type
  8687. * @uplink_seid: the switch element to link to
  8688. * @param1: usage depends upon VSI type. For VF types, indicates VF id
  8689. *
  8690. * This allocates the sw VSI structure and its queue resources, then add a VSI
  8691. * to the identified VEB.
  8692. *
  8693. * Returns pointer to the successfully allocated and configure VSI sw struct on
  8694. * success, otherwise returns NULL on failure.
  8695. **/
  8696. struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
  8697. u16 uplink_seid, u32 param1)
  8698. {
  8699. struct i40e_vsi *vsi = NULL;
  8700. struct i40e_veb *veb = NULL;
  8701. int ret, i;
  8702. int v_idx;
  8703. /* The requested uplink_seid must be either
  8704. * - the PF's port seid
  8705. * no VEB is needed because this is the PF
  8706. * or this is a Flow Director special case VSI
  8707. * - seid of an existing VEB
  8708. * - seid of a VSI that owns an existing VEB
  8709. * - seid of a VSI that doesn't own a VEB
  8710. * a new VEB is created and the VSI becomes the owner
  8711. * - seid of the PF VSI, which is what creates the first VEB
  8712. * this is a special case of the previous
  8713. *
  8714. * Find which uplink_seid we were given and create a new VEB if needed
  8715. */
  8716. for (i = 0; i < I40E_MAX_VEB; i++) {
  8717. if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
  8718. veb = pf->veb[i];
  8719. break;
  8720. }
  8721. }
  8722. if (!veb && uplink_seid != pf->mac_seid) {
  8723. for (i = 0; i < pf->num_alloc_vsi; i++) {
  8724. if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
  8725. vsi = pf->vsi[i];
  8726. break;
  8727. }
  8728. }
  8729. if (!vsi) {
  8730. dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
  8731. uplink_seid);
  8732. return NULL;
  8733. }
  8734. if (vsi->uplink_seid == pf->mac_seid)
  8735. veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
  8736. vsi->tc_config.enabled_tc);
  8737. else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
  8738. veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
  8739. vsi->tc_config.enabled_tc);
  8740. if (veb) {
  8741. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) {
  8742. dev_info(&vsi->back->pdev->dev,
  8743. "New VSI creation error, uplink seid of LAN VSI expected.\n");
  8744. return NULL;
  8745. }
  8746. /* We come up by default in VEPA mode if SRIOV is not
  8747. * already enabled, in which case we can't force VEPA
  8748. * mode.
  8749. */
  8750. if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
  8751. veb->bridge_mode = BRIDGE_MODE_VEPA;
  8752. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  8753. }
  8754. i40e_config_bridge_mode(veb);
  8755. }
  8756. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  8757. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  8758. veb = pf->veb[i];
  8759. }
  8760. if (!veb) {
  8761. dev_info(&pf->pdev->dev, "couldn't add VEB\n");
  8762. return NULL;
  8763. }
  8764. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  8765. uplink_seid = veb->seid;
  8766. }
  8767. /* get vsi sw struct */
  8768. v_idx = i40e_vsi_mem_alloc(pf, type);
  8769. if (v_idx < 0)
  8770. goto err_alloc;
  8771. vsi = pf->vsi[v_idx];
  8772. if (!vsi)
  8773. goto err_alloc;
  8774. vsi->type = type;
  8775. vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
  8776. if (type == I40E_VSI_MAIN)
  8777. pf->lan_vsi = v_idx;
  8778. else if (type == I40E_VSI_SRIOV)
  8779. vsi->vf_id = param1;
  8780. /* assign it some queues */
  8781. ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs,
  8782. vsi->idx);
  8783. if (ret < 0) {
  8784. dev_info(&pf->pdev->dev,
  8785. "failed to get tracking for %d queues for VSI %d err=%d\n",
  8786. vsi->alloc_queue_pairs, vsi->seid, ret);
  8787. goto err_vsi;
  8788. }
  8789. vsi->base_queue = ret;
  8790. /* get a VSI from the hardware */
  8791. vsi->uplink_seid = uplink_seid;
  8792. ret = i40e_add_vsi(vsi);
  8793. if (ret)
  8794. goto err_vsi;
  8795. switch (vsi->type) {
  8796. /* setup the netdev if needed */
  8797. case I40E_VSI_MAIN:
  8798. /* Apply relevant filters if a platform-specific mac
  8799. * address was selected.
  8800. */
  8801. if (!!(pf->flags & I40E_FLAG_PF_MAC)) {
  8802. ret = i40e_macaddr_init(vsi, pf->hw.mac.addr);
  8803. if (ret) {
  8804. dev_warn(&pf->pdev->dev,
  8805. "could not set up macaddr; err %d\n",
  8806. ret);
  8807. }
  8808. }
  8809. case I40E_VSI_VMDQ2:
  8810. case I40E_VSI_FCOE:
  8811. ret = i40e_config_netdev(vsi);
  8812. if (ret)
  8813. goto err_netdev;
  8814. ret = register_netdev(vsi->netdev);
  8815. if (ret)
  8816. goto err_netdev;
  8817. vsi->netdev_registered = true;
  8818. netif_carrier_off(vsi->netdev);
  8819. #ifdef CONFIG_I40E_DCB
  8820. /* Setup DCB netlink interface */
  8821. i40e_dcbnl_setup(vsi);
  8822. #endif /* CONFIG_I40E_DCB */
  8823. /* fall through */
  8824. case I40E_VSI_FDIR:
  8825. /* set up vectors and rings if needed */
  8826. ret = i40e_vsi_setup_vectors(vsi);
  8827. if (ret)
  8828. goto err_msix;
  8829. ret = i40e_alloc_rings(vsi);
  8830. if (ret)
  8831. goto err_rings;
  8832. /* map all of the rings to the q_vectors */
  8833. i40e_vsi_map_rings_to_vectors(vsi);
  8834. i40e_vsi_reset_stats(vsi);
  8835. break;
  8836. default:
  8837. /* no netdev or rings for the other VSI types */
  8838. break;
  8839. }
  8840. if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) &&
  8841. (vsi->type == I40E_VSI_VMDQ2)) {
  8842. ret = i40e_vsi_config_rss(vsi);
  8843. }
  8844. return vsi;
  8845. err_rings:
  8846. i40e_vsi_free_q_vectors(vsi);
  8847. err_msix:
  8848. if (vsi->netdev_registered) {
  8849. vsi->netdev_registered = false;
  8850. unregister_netdev(vsi->netdev);
  8851. free_netdev(vsi->netdev);
  8852. vsi->netdev = NULL;
  8853. }
  8854. err_netdev:
  8855. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  8856. err_vsi:
  8857. i40e_vsi_clear(vsi);
  8858. err_alloc:
  8859. return NULL;
  8860. }
  8861. /**
  8862. * i40e_veb_get_bw_info - Query VEB BW information
  8863. * @veb: the veb to query
  8864. *
  8865. * Query the Tx scheduler BW configuration data for given VEB
  8866. **/
  8867. static int i40e_veb_get_bw_info(struct i40e_veb *veb)
  8868. {
  8869. struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
  8870. struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
  8871. struct i40e_pf *pf = veb->pf;
  8872. struct i40e_hw *hw = &pf->hw;
  8873. u32 tc_bw_max;
  8874. int ret = 0;
  8875. int i;
  8876. ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
  8877. &bw_data, NULL);
  8878. if (ret) {
  8879. dev_info(&pf->pdev->dev,
  8880. "query veb bw config failed, err %s aq_err %s\n",
  8881. i40e_stat_str(&pf->hw, ret),
  8882. i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
  8883. goto out;
  8884. }
  8885. ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
  8886. &ets_data, NULL);
  8887. if (ret) {
  8888. dev_info(&pf->pdev->dev,
  8889. "query veb bw ets config failed, err %s aq_err %s\n",
  8890. i40e_stat_str(&pf->hw, ret),
  8891. i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
  8892. goto out;
  8893. }
  8894. veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
  8895. veb->bw_max_quanta = ets_data.tc_bw_max;
  8896. veb->is_abs_credits = bw_data.absolute_credits_enable;
  8897. veb->enabled_tc = ets_data.tc_valid_bits;
  8898. tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
  8899. (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
  8900. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  8901. veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
  8902. veb->bw_tc_limit_credits[i] =
  8903. le16_to_cpu(bw_data.tc_bw_limits[i]);
  8904. veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
  8905. }
  8906. out:
  8907. return ret;
  8908. }
  8909. /**
  8910. * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
  8911. * @pf: board private structure
  8912. *
  8913. * On error: returns error code (negative)
  8914. * On success: returns vsi index in PF (positive)
  8915. **/
  8916. static int i40e_veb_mem_alloc(struct i40e_pf *pf)
  8917. {
  8918. int ret = -ENOENT;
  8919. struct i40e_veb *veb;
  8920. int i;
  8921. /* Need to protect the allocation of switch elements at the PF level */
  8922. mutex_lock(&pf->switch_mutex);
  8923. /* VEB list may be fragmented if VEB creation/destruction has
  8924. * been happening. We can afford to do a quick scan to look
  8925. * for any free slots in the list.
  8926. *
  8927. * find next empty veb slot, looping back around if necessary
  8928. */
  8929. i = 0;
  8930. while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
  8931. i++;
  8932. if (i >= I40E_MAX_VEB) {
  8933. ret = -ENOMEM;
  8934. goto err_alloc_veb; /* out of VEB slots! */
  8935. }
  8936. veb = kzalloc(sizeof(*veb), GFP_KERNEL);
  8937. if (!veb) {
  8938. ret = -ENOMEM;
  8939. goto err_alloc_veb;
  8940. }
  8941. veb->pf = pf;
  8942. veb->idx = i;
  8943. veb->enabled_tc = 1;
  8944. pf->veb[i] = veb;
  8945. ret = i;
  8946. err_alloc_veb:
  8947. mutex_unlock(&pf->switch_mutex);
  8948. return ret;
  8949. }
  8950. /**
  8951. * i40e_switch_branch_release - Delete a branch of the switch tree
  8952. * @branch: where to start deleting
  8953. *
  8954. * This uses recursion to find the tips of the branch to be
  8955. * removed, deleting until we get back to and can delete this VEB.
  8956. **/
  8957. static void i40e_switch_branch_release(struct i40e_veb *branch)
  8958. {
  8959. struct i40e_pf *pf = branch->pf;
  8960. u16 branch_seid = branch->seid;
  8961. u16 veb_idx = branch->idx;
  8962. int i;
  8963. /* release any VEBs on this VEB - RECURSION */
  8964. for (i = 0; i < I40E_MAX_VEB; i++) {
  8965. if (!pf->veb[i])
  8966. continue;
  8967. if (pf->veb[i]->uplink_seid == branch->seid)
  8968. i40e_switch_branch_release(pf->veb[i]);
  8969. }
  8970. /* Release the VSIs on this VEB, but not the owner VSI.
  8971. *
  8972. * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
  8973. * the VEB itself, so don't use (*branch) after this loop.
  8974. */
  8975. for (i = 0; i < pf->num_alloc_vsi; i++) {
  8976. if (!pf->vsi[i])
  8977. continue;
  8978. if (pf->vsi[i]->uplink_seid == branch_seid &&
  8979. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  8980. i40e_vsi_release(pf->vsi[i]);
  8981. }
  8982. }
  8983. /* There's one corner case where the VEB might not have been
  8984. * removed, so double check it here and remove it if needed.
  8985. * This case happens if the veb was created from the debugfs
  8986. * commands and no VSIs were added to it.
  8987. */
  8988. if (pf->veb[veb_idx])
  8989. i40e_veb_release(pf->veb[veb_idx]);
  8990. }
  8991. /**
  8992. * i40e_veb_clear - remove veb struct
  8993. * @veb: the veb to remove
  8994. **/
  8995. static void i40e_veb_clear(struct i40e_veb *veb)
  8996. {
  8997. if (!veb)
  8998. return;
  8999. if (veb->pf) {
  9000. struct i40e_pf *pf = veb->pf;
  9001. mutex_lock(&pf->switch_mutex);
  9002. if (pf->veb[veb->idx] == veb)
  9003. pf->veb[veb->idx] = NULL;
  9004. mutex_unlock(&pf->switch_mutex);
  9005. }
  9006. kfree(veb);
  9007. }
  9008. /**
  9009. * i40e_veb_release - Delete a VEB and free its resources
  9010. * @veb: the VEB being removed
  9011. **/
  9012. void i40e_veb_release(struct i40e_veb *veb)
  9013. {
  9014. struct i40e_vsi *vsi = NULL;
  9015. struct i40e_pf *pf;
  9016. int i, n = 0;
  9017. pf = veb->pf;
  9018. /* find the remaining VSI and check for extras */
  9019. for (i = 0; i < pf->num_alloc_vsi; i++) {
  9020. if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
  9021. n++;
  9022. vsi = pf->vsi[i];
  9023. }
  9024. }
  9025. if (n != 1) {
  9026. dev_info(&pf->pdev->dev,
  9027. "can't remove VEB %d with %d VSIs left\n",
  9028. veb->seid, n);
  9029. return;
  9030. }
  9031. /* move the remaining VSI to uplink veb */
  9032. vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
  9033. if (veb->uplink_seid) {
  9034. vsi->uplink_seid = veb->uplink_seid;
  9035. if (veb->uplink_seid == pf->mac_seid)
  9036. vsi->veb_idx = I40E_NO_VEB;
  9037. else
  9038. vsi->veb_idx = veb->veb_idx;
  9039. } else {
  9040. /* floating VEB */
  9041. vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  9042. vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
  9043. }
  9044. i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
  9045. i40e_veb_clear(veb);
  9046. }
  9047. /**
  9048. * i40e_add_veb - create the VEB in the switch
  9049. * @veb: the VEB to be instantiated
  9050. * @vsi: the controlling VSI
  9051. **/
  9052. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
  9053. {
  9054. struct i40e_pf *pf = veb->pf;
  9055. bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED);
  9056. int ret;
  9057. ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid,
  9058. veb->enabled_tc, false,
  9059. &veb->seid, enable_stats, NULL);
  9060. /* get a VEB from the hardware */
  9061. if (ret) {
  9062. dev_info(&pf->pdev->dev,
  9063. "couldn't add VEB, err %s aq_err %s\n",
  9064. i40e_stat_str(&pf->hw, ret),
  9065. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  9066. return -EPERM;
  9067. }
  9068. /* get statistics counter */
  9069. ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL,
  9070. &veb->stats_idx, NULL, NULL, NULL);
  9071. if (ret) {
  9072. dev_info(&pf->pdev->dev,
  9073. "couldn't get VEB statistics idx, err %s aq_err %s\n",
  9074. i40e_stat_str(&pf->hw, ret),
  9075. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  9076. return -EPERM;
  9077. }
  9078. ret = i40e_veb_get_bw_info(veb);
  9079. if (ret) {
  9080. dev_info(&pf->pdev->dev,
  9081. "couldn't get VEB bw info, err %s aq_err %s\n",
  9082. i40e_stat_str(&pf->hw, ret),
  9083. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  9084. i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
  9085. return -ENOENT;
  9086. }
  9087. vsi->uplink_seid = veb->seid;
  9088. vsi->veb_idx = veb->idx;
  9089. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  9090. return 0;
  9091. }
  9092. /**
  9093. * i40e_veb_setup - Set up a VEB
  9094. * @pf: board private structure
  9095. * @flags: VEB setup flags
  9096. * @uplink_seid: the switch element to link to
  9097. * @vsi_seid: the initial VSI seid
  9098. * @enabled_tc: Enabled TC bit-map
  9099. *
  9100. * This allocates the sw VEB structure and links it into the switch
  9101. * It is possible and legal for this to be a duplicate of an already
  9102. * existing VEB. It is also possible for both uplink and vsi seids
  9103. * to be zero, in order to create a floating VEB.
  9104. *
  9105. * Returns pointer to the successfully allocated VEB sw struct on
  9106. * success, otherwise returns NULL on failure.
  9107. **/
  9108. struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
  9109. u16 uplink_seid, u16 vsi_seid,
  9110. u8 enabled_tc)
  9111. {
  9112. struct i40e_veb *veb, *uplink_veb = NULL;
  9113. int vsi_idx, veb_idx;
  9114. int ret;
  9115. /* if one seid is 0, the other must be 0 to create a floating relay */
  9116. if ((uplink_seid == 0 || vsi_seid == 0) &&
  9117. (uplink_seid + vsi_seid != 0)) {
  9118. dev_info(&pf->pdev->dev,
  9119. "one, not both seid's are 0: uplink=%d vsi=%d\n",
  9120. uplink_seid, vsi_seid);
  9121. return NULL;
  9122. }
  9123. /* make sure there is such a vsi and uplink */
  9124. for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++)
  9125. if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
  9126. break;
  9127. if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) {
  9128. dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
  9129. vsi_seid);
  9130. return NULL;
  9131. }
  9132. if (uplink_seid && uplink_seid != pf->mac_seid) {
  9133. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  9134. if (pf->veb[veb_idx] &&
  9135. pf->veb[veb_idx]->seid == uplink_seid) {
  9136. uplink_veb = pf->veb[veb_idx];
  9137. break;
  9138. }
  9139. }
  9140. if (!uplink_veb) {
  9141. dev_info(&pf->pdev->dev,
  9142. "uplink seid %d not found\n", uplink_seid);
  9143. return NULL;
  9144. }
  9145. }
  9146. /* get veb sw struct */
  9147. veb_idx = i40e_veb_mem_alloc(pf);
  9148. if (veb_idx < 0)
  9149. goto err_alloc;
  9150. veb = pf->veb[veb_idx];
  9151. veb->flags = flags;
  9152. veb->uplink_seid = uplink_seid;
  9153. veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
  9154. veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
  9155. /* create the VEB in the switch */
  9156. ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
  9157. if (ret)
  9158. goto err_veb;
  9159. if (vsi_idx == pf->lan_vsi)
  9160. pf->lan_veb = veb->idx;
  9161. return veb;
  9162. err_veb:
  9163. i40e_veb_clear(veb);
  9164. err_alloc:
  9165. return NULL;
  9166. }
  9167. /**
  9168. * i40e_setup_pf_switch_element - set PF vars based on switch type
  9169. * @pf: board private structure
  9170. * @ele: element we are building info from
  9171. * @num_reported: total number of elements
  9172. * @printconfig: should we print the contents
  9173. *
  9174. * helper function to assist in extracting a few useful SEID values.
  9175. **/
  9176. static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
  9177. struct i40e_aqc_switch_config_element_resp *ele,
  9178. u16 num_reported, bool printconfig)
  9179. {
  9180. u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
  9181. u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
  9182. u8 element_type = ele->element_type;
  9183. u16 seid = le16_to_cpu(ele->seid);
  9184. if (printconfig)
  9185. dev_info(&pf->pdev->dev,
  9186. "type=%d seid=%d uplink=%d downlink=%d\n",
  9187. element_type, seid, uplink_seid, downlink_seid);
  9188. switch (element_type) {
  9189. case I40E_SWITCH_ELEMENT_TYPE_MAC:
  9190. pf->mac_seid = seid;
  9191. break;
  9192. case I40E_SWITCH_ELEMENT_TYPE_VEB:
  9193. /* Main VEB? */
  9194. if (uplink_seid != pf->mac_seid)
  9195. break;
  9196. if (pf->lan_veb == I40E_NO_VEB) {
  9197. int v;
  9198. /* find existing or else empty VEB */
  9199. for (v = 0; v < I40E_MAX_VEB; v++) {
  9200. if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
  9201. pf->lan_veb = v;
  9202. break;
  9203. }
  9204. }
  9205. if (pf->lan_veb == I40E_NO_VEB) {
  9206. v = i40e_veb_mem_alloc(pf);
  9207. if (v < 0)
  9208. break;
  9209. pf->lan_veb = v;
  9210. }
  9211. }
  9212. pf->veb[pf->lan_veb]->seid = seid;
  9213. pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
  9214. pf->veb[pf->lan_veb]->pf = pf;
  9215. pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
  9216. break;
  9217. case I40E_SWITCH_ELEMENT_TYPE_VSI:
  9218. if (num_reported != 1)
  9219. break;
  9220. /* This is immediately after a reset so we can assume this is
  9221. * the PF's VSI
  9222. */
  9223. pf->mac_seid = uplink_seid;
  9224. pf->pf_seid = downlink_seid;
  9225. pf->main_vsi_seid = seid;
  9226. if (printconfig)
  9227. dev_info(&pf->pdev->dev,
  9228. "pf_seid=%d main_vsi_seid=%d\n",
  9229. pf->pf_seid, pf->main_vsi_seid);
  9230. break;
  9231. case I40E_SWITCH_ELEMENT_TYPE_PF:
  9232. case I40E_SWITCH_ELEMENT_TYPE_VF:
  9233. case I40E_SWITCH_ELEMENT_TYPE_EMP:
  9234. case I40E_SWITCH_ELEMENT_TYPE_BMC:
  9235. case I40E_SWITCH_ELEMENT_TYPE_PE:
  9236. case I40E_SWITCH_ELEMENT_TYPE_PA:
  9237. /* ignore these for now */
  9238. break;
  9239. default:
  9240. dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
  9241. element_type, seid);
  9242. break;
  9243. }
  9244. }
  9245. /**
  9246. * i40e_fetch_switch_configuration - Get switch config from firmware
  9247. * @pf: board private structure
  9248. * @printconfig: should we print the contents
  9249. *
  9250. * Get the current switch configuration from the device and
  9251. * extract a few useful SEID values.
  9252. **/
  9253. int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
  9254. {
  9255. struct i40e_aqc_get_switch_config_resp *sw_config;
  9256. u16 next_seid = 0;
  9257. int ret = 0;
  9258. u8 *aq_buf;
  9259. int i;
  9260. aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
  9261. if (!aq_buf)
  9262. return -ENOMEM;
  9263. sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
  9264. do {
  9265. u16 num_reported, num_total;
  9266. ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
  9267. I40E_AQ_LARGE_BUF,
  9268. &next_seid, NULL);
  9269. if (ret) {
  9270. dev_info(&pf->pdev->dev,
  9271. "get switch config failed err %s aq_err %s\n",
  9272. i40e_stat_str(&pf->hw, ret),
  9273. i40e_aq_str(&pf->hw,
  9274. pf->hw.aq.asq_last_status));
  9275. kfree(aq_buf);
  9276. return -ENOENT;
  9277. }
  9278. num_reported = le16_to_cpu(sw_config->header.num_reported);
  9279. num_total = le16_to_cpu(sw_config->header.num_total);
  9280. if (printconfig)
  9281. dev_info(&pf->pdev->dev,
  9282. "header: %d reported %d total\n",
  9283. num_reported, num_total);
  9284. for (i = 0; i < num_reported; i++) {
  9285. struct i40e_aqc_switch_config_element_resp *ele =
  9286. &sw_config->element[i];
  9287. i40e_setup_pf_switch_element(pf, ele, num_reported,
  9288. printconfig);
  9289. }
  9290. } while (next_seid != 0);
  9291. kfree(aq_buf);
  9292. return ret;
  9293. }
  9294. /**
  9295. * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
  9296. * @pf: board private structure
  9297. * @reinit: if the Main VSI needs to re-initialized.
  9298. *
  9299. * Returns 0 on success, negative value on failure
  9300. **/
  9301. static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
  9302. {
  9303. u16 flags = 0;
  9304. int ret;
  9305. /* find out what's out there already */
  9306. ret = i40e_fetch_switch_configuration(pf, false);
  9307. if (ret) {
  9308. dev_info(&pf->pdev->dev,
  9309. "couldn't fetch switch config, err %s aq_err %s\n",
  9310. i40e_stat_str(&pf->hw, ret),
  9311. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  9312. return ret;
  9313. }
  9314. i40e_pf_reset_stats(pf);
  9315. /* set the switch config bit for the whole device to
  9316. * support limited promisc or true promisc
  9317. * when user requests promisc. The default is limited
  9318. * promisc.
  9319. */
  9320. if ((pf->hw.pf_id == 0) &&
  9321. !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
  9322. flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  9323. if (pf->hw.pf_id == 0) {
  9324. u16 valid_flags;
  9325. valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  9326. ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags,
  9327. NULL);
  9328. if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
  9329. dev_info(&pf->pdev->dev,
  9330. "couldn't set switch config bits, err %s aq_err %s\n",
  9331. i40e_stat_str(&pf->hw, ret),
  9332. i40e_aq_str(&pf->hw,
  9333. pf->hw.aq.asq_last_status));
  9334. /* not a fatal problem, just keep going */
  9335. }
  9336. }
  9337. /* first time setup */
  9338. if (pf->lan_vsi == I40E_NO_VSI || reinit) {
  9339. struct i40e_vsi *vsi = NULL;
  9340. u16 uplink_seid;
  9341. /* Set up the PF VSI associated with the PF's main VSI
  9342. * that is already in the HW switch
  9343. */
  9344. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  9345. uplink_seid = pf->veb[pf->lan_veb]->seid;
  9346. else
  9347. uplink_seid = pf->mac_seid;
  9348. if (pf->lan_vsi == I40E_NO_VSI)
  9349. vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
  9350. else if (reinit)
  9351. vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
  9352. if (!vsi) {
  9353. dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
  9354. i40e_fdir_teardown(pf);
  9355. return -EAGAIN;
  9356. }
  9357. } else {
  9358. /* force a reset of TC and queue layout configurations */
  9359. u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  9360. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  9361. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  9362. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  9363. }
  9364. i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
  9365. i40e_fdir_sb_setup(pf);
  9366. /* Setup static PF queue filter control settings */
  9367. ret = i40e_setup_pf_filter_control(pf);
  9368. if (ret) {
  9369. dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
  9370. ret);
  9371. /* Failure here should not stop continuing other steps */
  9372. }
  9373. /* enable RSS in the HW, even for only one queue, as the stack can use
  9374. * the hash
  9375. */
  9376. if ((pf->flags & I40E_FLAG_RSS_ENABLED))
  9377. i40e_pf_config_rss(pf);
  9378. /* fill in link information and enable LSE reporting */
  9379. i40e_update_link_info(&pf->hw);
  9380. i40e_link_event(pf);
  9381. /* Initialize user-specific link properties */
  9382. pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
  9383. I40E_AQ_AN_COMPLETED) ? true : false);
  9384. i40e_ptp_init(pf);
  9385. return ret;
  9386. }
  9387. /**
  9388. * i40e_determine_queue_usage - Work out queue distribution
  9389. * @pf: board private structure
  9390. **/
  9391. static void i40e_determine_queue_usage(struct i40e_pf *pf)
  9392. {
  9393. int queues_left;
  9394. pf->num_lan_qps = 0;
  9395. #ifdef I40E_FCOE
  9396. pf->num_fcoe_qps = 0;
  9397. #endif
  9398. /* Find the max queues to be put into basic use. We'll always be
  9399. * using TC0, whether or not DCB is running, and TC0 will get the
  9400. * big RSS set.
  9401. */
  9402. queues_left = pf->hw.func_caps.num_tx_qp;
  9403. if ((queues_left == 1) ||
  9404. !(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
  9405. /* one qp for PF, no queues for anything else */
  9406. queues_left = 0;
  9407. pf->alloc_rss_size = pf->num_lan_qps = 1;
  9408. /* make sure all the fancies are disabled */
  9409. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  9410. I40E_FLAG_IWARP_ENABLED |
  9411. #ifdef I40E_FCOE
  9412. I40E_FLAG_FCOE_ENABLED |
  9413. #endif
  9414. I40E_FLAG_FD_SB_ENABLED |
  9415. I40E_FLAG_FD_ATR_ENABLED |
  9416. I40E_FLAG_DCB_CAPABLE |
  9417. I40E_FLAG_DCB_ENABLED |
  9418. I40E_FLAG_SRIOV_ENABLED |
  9419. I40E_FLAG_VMDQ_ENABLED);
  9420. } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED |
  9421. I40E_FLAG_FD_SB_ENABLED |
  9422. I40E_FLAG_FD_ATR_ENABLED |
  9423. I40E_FLAG_DCB_CAPABLE))) {
  9424. /* one qp for PF */
  9425. pf->alloc_rss_size = pf->num_lan_qps = 1;
  9426. queues_left -= pf->num_lan_qps;
  9427. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  9428. I40E_FLAG_IWARP_ENABLED |
  9429. #ifdef I40E_FCOE
  9430. I40E_FLAG_FCOE_ENABLED |
  9431. #endif
  9432. I40E_FLAG_FD_SB_ENABLED |
  9433. I40E_FLAG_FD_ATR_ENABLED |
  9434. I40E_FLAG_DCB_ENABLED |
  9435. I40E_FLAG_VMDQ_ENABLED);
  9436. } else {
  9437. /* Not enough queues for all TCs */
  9438. if ((pf->flags & I40E_FLAG_DCB_CAPABLE) &&
  9439. (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
  9440. pf->flags &= ~(I40E_FLAG_DCB_CAPABLE |
  9441. I40E_FLAG_DCB_ENABLED);
  9442. dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
  9443. }
  9444. pf->num_lan_qps = max_t(int, pf->rss_size_max,
  9445. num_online_cpus());
  9446. pf->num_lan_qps = min_t(int, pf->num_lan_qps,
  9447. pf->hw.func_caps.num_tx_qp);
  9448. queues_left -= pf->num_lan_qps;
  9449. }
  9450. #ifdef I40E_FCOE
  9451. if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
  9452. if (I40E_DEFAULT_FCOE <= queues_left) {
  9453. pf->num_fcoe_qps = I40E_DEFAULT_FCOE;
  9454. } else if (I40E_MINIMUM_FCOE <= queues_left) {
  9455. pf->num_fcoe_qps = I40E_MINIMUM_FCOE;
  9456. } else {
  9457. pf->num_fcoe_qps = 0;
  9458. pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
  9459. dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n");
  9460. }
  9461. queues_left -= pf->num_fcoe_qps;
  9462. }
  9463. #endif
  9464. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  9465. if (queues_left > 1) {
  9466. queues_left -= 1; /* save 1 queue for FD */
  9467. } else {
  9468. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  9469. dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
  9470. }
  9471. }
  9472. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  9473. pf->num_vf_qps && pf->num_req_vfs && queues_left) {
  9474. pf->num_req_vfs = min_t(int, pf->num_req_vfs,
  9475. (queues_left / pf->num_vf_qps));
  9476. queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
  9477. }
  9478. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  9479. pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
  9480. pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
  9481. (queues_left / pf->num_vmdq_qps));
  9482. queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
  9483. }
  9484. pf->queues_left = queues_left;
  9485. dev_dbg(&pf->pdev->dev,
  9486. "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
  9487. pf->hw.func_caps.num_tx_qp,
  9488. !!(pf->flags & I40E_FLAG_FD_SB_ENABLED),
  9489. pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs,
  9490. pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps,
  9491. queues_left);
  9492. #ifdef I40E_FCOE
  9493. dev_dbg(&pf->pdev->dev, "fcoe queues = %d\n", pf->num_fcoe_qps);
  9494. #endif
  9495. }
  9496. /**
  9497. * i40e_setup_pf_filter_control - Setup PF static filter control
  9498. * @pf: PF to be setup
  9499. *
  9500. * i40e_setup_pf_filter_control sets up a PF's initial filter control
  9501. * settings. If PE/FCoE are enabled then it will also set the per PF
  9502. * based filter sizes required for them. It also enables Flow director,
  9503. * ethertype and macvlan type filter settings for the pf.
  9504. *
  9505. * Returns 0 on success, negative on failure
  9506. **/
  9507. static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
  9508. {
  9509. struct i40e_filter_control_settings *settings = &pf->filter_settings;
  9510. settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
  9511. /* Flow Director is enabled */
  9512. if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
  9513. settings->enable_fdir = true;
  9514. /* Ethtype and MACVLAN filters enabled for PF */
  9515. settings->enable_ethtype = true;
  9516. settings->enable_macvlan = true;
  9517. if (i40e_set_filter_control(&pf->hw, settings))
  9518. return -ENOENT;
  9519. return 0;
  9520. }
  9521. #define INFO_STRING_LEN 255
  9522. #define REMAIN(__x) (INFO_STRING_LEN - (__x))
  9523. static void i40e_print_features(struct i40e_pf *pf)
  9524. {
  9525. struct i40e_hw *hw = &pf->hw;
  9526. char *buf;
  9527. int i;
  9528. buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL);
  9529. if (!buf)
  9530. return;
  9531. i = snprintf(buf, INFO_STRING_LEN, "Features: PF-id[%d]", hw->pf_id);
  9532. #ifdef CONFIG_PCI_IOV
  9533. i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs);
  9534. #endif
  9535. i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d",
  9536. pf->hw.func_caps.num_vsis,
  9537. pf->vsi[pf->lan_vsi]->num_queue_pairs);
  9538. if (pf->flags & I40E_FLAG_RSS_ENABLED)
  9539. i += snprintf(&buf[i], REMAIN(i), " RSS");
  9540. if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
  9541. i += snprintf(&buf[i], REMAIN(i), " FD_ATR");
  9542. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  9543. i += snprintf(&buf[i], REMAIN(i), " FD_SB");
  9544. i += snprintf(&buf[i], REMAIN(i), " NTUPLE");
  9545. }
  9546. if (pf->flags & I40E_FLAG_DCB_CAPABLE)
  9547. i += snprintf(&buf[i], REMAIN(i), " DCB");
  9548. i += snprintf(&buf[i], REMAIN(i), " VxLAN");
  9549. i += snprintf(&buf[i], REMAIN(i), " Geneve");
  9550. if (pf->flags & I40E_FLAG_PTP)
  9551. i += snprintf(&buf[i], REMAIN(i), " PTP");
  9552. #ifdef I40E_FCOE
  9553. if (pf->flags & I40E_FLAG_FCOE_ENABLED)
  9554. i += snprintf(&buf[i], REMAIN(i), " FCOE");
  9555. #endif
  9556. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
  9557. i += snprintf(&buf[i], REMAIN(i), " VEB");
  9558. else
  9559. i += snprintf(&buf[i], REMAIN(i), " VEPA");
  9560. dev_info(&pf->pdev->dev, "%s\n", buf);
  9561. kfree(buf);
  9562. WARN_ON(i > INFO_STRING_LEN);
  9563. }
  9564. /**
  9565. * i40e_get_platform_mac_addr - get platform-specific MAC address
  9566. *
  9567. * @pdev: PCI device information struct
  9568. * @pf: board private structure
  9569. *
  9570. * Look up the MAC address in Open Firmware on systems that support it,
  9571. * and use IDPROM on SPARC if no OF address is found. On return, the
  9572. * I40E_FLAG_PF_MAC will be wset in pf->flags if a platform-specific value
  9573. * has been selected.
  9574. **/
  9575. static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf)
  9576. {
  9577. pf->flags &= ~I40E_FLAG_PF_MAC;
  9578. if (!eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr))
  9579. pf->flags |= I40E_FLAG_PF_MAC;
  9580. }
  9581. /**
  9582. * i40e_probe - Device initialization routine
  9583. * @pdev: PCI device information struct
  9584. * @ent: entry in i40e_pci_tbl
  9585. *
  9586. * i40e_probe initializes a PF identified by a pci_dev structure.
  9587. * The OS initialization, configuring of the PF private structure,
  9588. * and a hardware reset occur.
  9589. *
  9590. * Returns 0 on success, negative on failure
  9591. **/
  9592. static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  9593. {
  9594. struct i40e_aq_get_phy_abilities_resp abilities;
  9595. struct i40e_pf *pf;
  9596. struct i40e_hw *hw;
  9597. static u16 pfs_found;
  9598. u16 wol_nvm_bits;
  9599. u16 link_status;
  9600. int err;
  9601. u32 val;
  9602. u32 i;
  9603. u8 set_fc_aq_fail;
  9604. err = pci_enable_device_mem(pdev);
  9605. if (err)
  9606. return err;
  9607. /* set up for high or low dma */
  9608. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  9609. if (err) {
  9610. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  9611. if (err) {
  9612. dev_err(&pdev->dev,
  9613. "DMA configuration failed: 0x%x\n", err);
  9614. goto err_dma;
  9615. }
  9616. }
  9617. /* set up pci connections */
  9618. err = pci_request_mem_regions(pdev, i40e_driver_name);
  9619. if (err) {
  9620. dev_info(&pdev->dev,
  9621. "pci_request_selected_regions failed %d\n", err);
  9622. goto err_pci_reg;
  9623. }
  9624. pci_enable_pcie_error_reporting(pdev);
  9625. pci_set_master(pdev);
  9626. /* Now that we have a PCI connection, we need to do the
  9627. * low level device setup. This is primarily setting up
  9628. * the Admin Queue structures and then querying for the
  9629. * device's current profile information.
  9630. */
  9631. pf = kzalloc(sizeof(*pf), GFP_KERNEL);
  9632. if (!pf) {
  9633. err = -ENOMEM;
  9634. goto err_pf_alloc;
  9635. }
  9636. pf->next_vsi = 0;
  9637. pf->pdev = pdev;
  9638. set_bit(__I40E_DOWN, &pf->state);
  9639. hw = &pf->hw;
  9640. hw->back = pf;
  9641. pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0),
  9642. I40E_MAX_CSR_SPACE);
  9643. hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len);
  9644. if (!hw->hw_addr) {
  9645. err = -EIO;
  9646. dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
  9647. (unsigned int)pci_resource_start(pdev, 0),
  9648. pf->ioremap_len, err);
  9649. goto err_ioremap;
  9650. }
  9651. hw->vendor_id = pdev->vendor;
  9652. hw->device_id = pdev->device;
  9653. pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
  9654. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  9655. hw->subsystem_device_id = pdev->subsystem_device;
  9656. hw->bus.device = PCI_SLOT(pdev->devfn);
  9657. hw->bus.func = PCI_FUNC(pdev->devfn);
  9658. pf->instance = pfs_found;
  9659. /* set up the locks for the AQ, do this only once in probe
  9660. * and destroy them only once in remove
  9661. */
  9662. mutex_init(&hw->aq.asq_mutex);
  9663. mutex_init(&hw->aq.arq_mutex);
  9664. pf->msg_enable = netif_msg_init(debug,
  9665. NETIF_MSG_DRV |
  9666. NETIF_MSG_PROBE |
  9667. NETIF_MSG_LINK);
  9668. if (debug < -1)
  9669. pf->hw.debug_mask = debug;
  9670. /* do a special CORER for clearing PXE mode once at init */
  9671. if (hw->revision_id == 0 &&
  9672. (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
  9673. wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
  9674. i40e_flush(hw);
  9675. msleep(200);
  9676. pf->corer_count++;
  9677. i40e_clear_pxe_mode(hw);
  9678. }
  9679. /* Reset here to make sure all is clean and to define PF 'n' */
  9680. i40e_clear_hw(hw);
  9681. err = i40e_pf_reset(hw);
  9682. if (err) {
  9683. dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err);
  9684. goto err_pf_reset;
  9685. }
  9686. pf->pfr_count++;
  9687. hw->aq.num_arq_entries = I40E_AQ_LEN;
  9688. hw->aq.num_asq_entries = I40E_AQ_LEN;
  9689. hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  9690. hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  9691. pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
  9692. snprintf(pf->int_name, sizeof(pf->int_name) - 1,
  9693. "%s-%s:misc",
  9694. dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev));
  9695. err = i40e_init_shared_code(hw);
  9696. if (err) {
  9697. dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n",
  9698. err);
  9699. goto err_pf_reset;
  9700. }
  9701. /* set up a default setting for link flow control */
  9702. pf->hw.fc.requested_mode = I40E_FC_NONE;
  9703. err = i40e_init_adminq(hw);
  9704. if (err) {
  9705. if (err == I40E_ERR_FIRMWARE_API_VERSION)
  9706. dev_info(&pdev->dev,
  9707. "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");
  9708. else
  9709. dev_info(&pdev->dev,
  9710. "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n");
  9711. goto err_pf_reset;
  9712. }
  9713. /* provide nvm, fw, api versions */
  9714. dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n",
  9715. hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build,
  9716. hw->aq.api_maj_ver, hw->aq.api_min_ver,
  9717. i40e_nvm_version_str(hw));
  9718. if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
  9719. hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR)
  9720. dev_info(&pdev->dev,
  9721. "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");
  9722. else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR ||
  9723. hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1))
  9724. dev_info(&pdev->dev,
  9725. "The driver for the device detected an older version of the NVM image than expected. Please update the NVM image.\n");
  9726. i40e_verify_eeprom(pf);
  9727. /* Rev 0 hardware was never productized */
  9728. if (hw->revision_id < 1)
  9729. 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");
  9730. i40e_clear_pxe_mode(hw);
  9731. err = i40e_get_capabilities(pf);
  9732. if (err)
  9733. goto err_adminq_setup;
  9734. err = i40e_sw_init(pf);
  9735. if (err) {
  9736. dev_info(&pdev->dev, "sw_init failed: %d\n", err);
  9737. goto err_sw_init;
  9738. }
  9739. err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  9740. hw->func_caps.num_rx_qp,
  9741. pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
  9742. if (err) {
  9743. dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
  9744. goto err_init_lan_hmc;
  9745. }
  9746. err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  9747. if (err) {
  9748. dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
  9749. err = -ENOENT;
  9750. goto err_configure_lan_hmc;
  9751. }
  9752. /* Disable LLDP for NICs that have firmware versions lower than v4.3.
  9753. * Ignore error return codes because if it was already disabled via
  9754. * hardware settings this will fail
  9755. */
  9756. if (pf->flags & I40E_FLAG_STOP_FW_LLDP) {
  9757. dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n");
  9758. i40e_aq_stop_lldp(hw, true, NULL);
  9759. }
  9760. i40e_get_mac_addr(hw, hw->mac.addr);
  9761. /* allow a platform config to override the HW addr */
  9762. i40e_get_platform_mac_addr(pdev, pf);
  9763. if (!is_valid_ether_addr(hw->mac.addr)) {
  9764. dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
  9765. err = -EIO;
  9766. goto err_mac_addr;
  9767. }
  9768. dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
  9769. ether_addr_copy(hw->mac.perm_addr, hw->mac.addr);
  9770. i40e_get_port_mac_addr(hw, hw->mac.port_addr);
  9771. if (is_valid_ether_addr(hw->mac.port_addr))
  9772. pf->flags |= I40E_FLAG_PORT_ID_VALID;
  9773. #ifdef I40E_FCOE
  9774. err = i40e_get_san_mac_addr(hw, hw->mac.san_addr);
  9775. if (err)
  9776. dev_info(&pdev->dev,
  9777. "(non-fatal) SAN MAC retrieval failed: %d\n", err);
  9778. if (!is_valid_ether_addr(hw->mac.san_addr)) {
  9779. dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n",
  9780. hw->mac.san_addr);
  9781. ether_addr_copy(hw->mac.san_addr, hw->mac.addr);
  9782. }
  9783. dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr);
  9784. #endif /* I40E_FCOE */
  9785. pci_set_drvdata(pdev, pf);
  9786. pci_save_state(pdev);
  9787. #ifdef CONFIG_I40E_DCB
  9788. err = i40e_init_pf_dcb(pf);
  9789. if (err) {
  9790. dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err);
  9791. pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | I40E_FLAG_DCB_ENABLED);
  9792. /* Continue without DCB enabled */
  9793. }
  9794. #endif /* CONFIG_I40E_DCB */
  9795. /* set up periodic task facility */
  9796. setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf);
  9797. pf->service_timer_period = HZ;
  9798. INIT_WORK(&pf->service_task, i40e_service_task);
  9799. clear_bit(__I40E_SERVICE_SCHED, &pf->state);
  9800. pf->flags |= I40E_FLAG_NEED_LINK_UPDATE;
  9801. /* NVM bit on means WoL disabled for the port */
  9802. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  9803. if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1)
  9804. pf->wol_en = false;
  9805. else
  9806. pf->wol_en = true;
  9807. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  9808. /* set up the main switch operations */
  9809. i40e_determine_queue_usage(pf);
  9810. err = i40e_init_interrupt_scheme(pf);
  9811. if (err)
  9812. goto err_switch_setup;
  9813. /* The number of VSIs reported by the FW is the minimum guaranteed
  9814. * to us; HW supports far more and we share the remaining pool with
  9815. * the other PFs. We allocate space for more than the guarantee with
  9816. * the understanding that we might not get them all later.
  9817. */
  9818. if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
  9819. pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
  9820. else
  9821. pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
  9822. /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
  9823. pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *),
  9824. GFP_KERNEL);
  9825. if (!pf->vsi) {
  9826. err = -ENOMEM;
  9827. goto err_switch_setup;
  9828. }
  9829. #ifdef CONFIG_PCI_IOV
  9830. /* prep for VF support */
  9831. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  9832. (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  9833. !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
  9834. if (pci_num_vf(pdev))
  9835. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  9836. }
  9837. #endif
  9838. err = i40e_setup_pf_switch(pf, false);
  9839. if (err) {
  9840. dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
  9841. goto err_vsis;
  9842. }
  9843. /* Make sure flow control is set according to current settings */
  9844. err = i40e_set_fc(hw, &set_fc_aq_fail, true);
  9845. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET)
  9846. dev_dbg(&pf->pdev->dev,
  9847. "Set fc with err %s aq_err %s on get_phy_cap\n",
  9848. i40e_stat_str(hw, err),
  9849. i40e_aq_str(hw, hw->aq.asq_last_status));
  9850. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET)
  9851. dev_dbg(&pf->pdev->dev,
  9852. "Set fc with err %s aq_err %s on set_phy_config\n",
  9853. i40e_stat_str(hw, err),
  9854. i40e_aq_str(hw, hw->aq.asq_last_status));
  9855. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE)
  9856. dev_dbg(&pf->pdev->dev,
  9857. "Set fc with err %s aq_err %s on get_link_info\n",
  9858. i40e_stat_str(hw, err),
  9859. i40e_aq_str(hw, hw->aq.asq_last_status));
  9860. /* if FDIR VSI was set up, start it now */
  9861. for (i = 0; i < pf->num_alloc_vsi; i++) {
  9862. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
  9863. i40e_vsi_open(pf->vsi[i]);
  9864. break;
  9865. }
  9866. }
  9867. /* The driver only wants link up/down and module qualification
  9868. * reports from firmware. Note the negative logic.
  9869. */
  9870. err = i40e_aq_set_phy_int_mask(&pf->hw,
  9871. ~(I40E_AQ_EVENT_LINK_UPDOWN |
  9872. I40E_AQ_EVENT_MEDIA_NA |
  9873. I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
  9874. if (err)
  9875. dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
  9876. i40e_stat_str(&pf->hw, err),
  9877. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  9878. /* Reconfigure hardware for allowing smaller MSS in the case
  9879. * of TSO, so that we avoid the MDD being fired and causing
  9880. * a reset in the case of small MSS+TSO.
  9881. */
  9882. val = rd32(hw, I40E_REG_MSS);
  9883. if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
  9884. val &= ~I40E_REG_MSS_MIN_MASK;
  9885. val |= I40E_64BYTE_MSS;
  9886. wr32(hw, I40E_REG_MSS, val);
  9887. }
  9888. if (pf->flags & I40E_FLAG_RESTART_AUTONEG) {
  9889. msleep(75);
  9890. err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
  9891. if (err)
  9892. dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
  9893. i40e_stat_str(&pf->hw, err),
  9894. i40e_aq_str(&pf->hw,
  9895. pf->hw.aq.asq_last_status));
  9896. }
  9897. /* The main driver is (mostly) up and happy. We need to set this state
  9898. * before setting up the misc vector or we get a race and the vector
  9899. * ends up disabled forever.
  9900. */
  9901. clear_bit(__I40E_DOWN, &pf->state);
  9902. /* In case of MSIX we are going to setup the misc vector right here
  9903. * to handle admin queue events etc. In case of legacy and MSI
  9904. * the misc functionality and queue processing is combined in
  9905. * the same vector and that gets setup at open.
  9906. */
  9907. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  9908. err = i40e_setup_misc_vector(pf);
  9909. if (err) {
  9910. dev_info(&pdev->dev,
  9911. "setup of misc vector failed: %d\n", err);
  9912. goto err_vsis;
  9913. }
  9914. }
  9915. #ifdef CONFIG_PCI_IOV
  9916. /* prep for VF support */
  9917. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  9918. (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  9919. !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
  9920. /* disable link interrupts for VFs */
  9921. val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
  9922. val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
  9923. wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
  9924. i40e_flush(hw);
  9925. if (pci_num_vf(pdev)) {
  9926. dev_info(&pdev->dev,
  9927. "Active VFs found, allocating resources.\n");
  9928. err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
  9929. if (err)
  9930. dev_info(&pdev->dev,
  9931. "Error %d allocating resources for existing VFs\n",
  9932. err);
  9933. }
  9934. }
  9935. #endif /* CONFIG_PCI_IOV */
  9936. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  9937. pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile,
  9938. pf->num_iwarp_msix,
  9939. I40E_IWARP_IRQ_PILE_ID);
  9940. if (pf->iwarp_base_vector < 0) {
  9941. dev_info(&pdev->dev,
  9942. "failed to get tracking for %d vectors for IWARP err=%d\n",
  9943. pf->num_iwarp_msix, pf->iwarp_base_vector);
  9944. pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
  9945. }
  9946. }
  9947. i40e_dbg_pf_init(pf);
  9948. /* tell the firmware that we're starting */
  9949. i40e_send_version(pf);
  9950. /* since everything's happy, start the service_task timer */
  9951. mod_timer(&pf->service_timer,
  9952. round_jiffies(jiffies + pf->service_timer_period));
  9953. /* add this PF to client device list and launch a client service task */
  9954. err = i40e_lan_add_device(pf);
  9955. if (err)
  9956. dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n",
  9957. err);
  9958. #ifdef I40E_FCOE
  9959. /* create FCoE interface */
  9960. i40e_fcoe_vsi_setup(pf);
  9961. #endif
  9962. #define PCI_SPEED_SIZE 8
  9963. #define PCI_WIDTH_SIZE 8
  9964. /* Devices on the IOSF bus do not have this information
  9965. * and will report PCI Gen 1 x 1 by default so don't bother
  9966. * checking them.
  9967. */
  9968. if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) {
  9969. char speed[PCI_SPEED_SIZE] = "Unknown";
  9970. char width[PCI_WIDTH_SIZE] = "Unknown";
  9971. /* Get the negotiated link width and speed from PCI config
  9972. * space
  9973. */
  9974. pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA,
  9975. &link_status);
  9976. i40e_set_pci_config_data(hw, link_status);
  9977. switch (hw->bus.speed) {
  9978. case i40e_bus_speed_8000:
  9979. strncpy(speed, "8.0", PCI_SPEED_SIZE); break;
  9980. case i40e_bus_speed_5000:
  9981. strncpy(speed, "5.0", PCI_SPEED_SIZE); break;
  9982. case i40e_bus_speed_2500:
  9983. strncpy(speed, "2.5", PCI_SPEED_SIZE); break;
  9984. default:
  9985. break;
  9986. }
  9987. switch (hw->bus.width) {
  9988. case i40e_bus_width_pcie_x8:
  9989. strncpy(width, "8", PCI_WIDTH_SIZE); break;
  9990. case i40e_bus_width_pcie_x4:
  9991. strncpy(width, "4", PCI_WIDTH_SIZE); break;
  9992. case i40e_bus_width_pcie_x2:
  9993. strncpy(width, "2", PCI_WIDTH_SIZE); break;
  9994. case i40e_bus_width_pcie_x1:
  9995. strncpy(width, "1", PCI_WIDTH_SIZE); break;
  9996. default:
  9997. break;
  9998. }
  9999. dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n",
  10000. speed, width);
  10001. if (hw->bus.width < i40e_bus_width_pcie_x8 ||
  10002. hw->bus.speed < i40e_bus_speed_8000) {
  10003. dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
  10004. dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
  10005. }
  10006. }
  10007. /* get the requested speeds from the fw */
  10008. err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL);
  10009. if (err)
  10010. dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n",
  10011. i40e_stat_str(&pf->hw, err),
  10012. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  10013. pf->hw.phy.link_info.requested_speeds = abilities.link_speed;
  10014. /* get the supported phy types from the fw */
  10015. err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL);
  10016. if (err)
  10017. dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n",
  10018. i40e_stat_str(&pf->hw, err),
  10019. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  10020. /* Add a filter to drop all Flow control frames from any VSI from being
  10021. * transmitted. By doing so we stop a malicious VF from sending out
  10022. * PAUSE or PFC frames and potentially controlling traffic for other
  10023. * PF/VF VSIs.
  10024. * The FW can still send Flow control frames if enabled.
  10025. */
  10026. i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
  10027. pf->main_vsi_seid);
  10028. if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) ||
  10029. (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4))
  10030. pf->flags |= I40E_FLAG_PHY_CONTROLS_LEDS;
  10031. if (pf->hw.device_id == I40E_DEV_ID_SFP_I_X722)
  10032. pf->flags |= I40E_FLAG_HAVE_CRT_RETIMER;
  10033. /* print a string summarizing features */
  10034. i40e_print_features(pf);
  10035. return 0;
  10036. /* Unwind what we've done if something failed in the setup */
  10037. err_vsis:
  10038. set_bit(__I40E_DOWN, &pf->state);
  10039. i40e_clear_interrupt_scheme(pf);
  10040. kfree(pf->vsi);
  10041. err_switch_setup:
  10042. i40e_reset_interrupt_capability(pf);
  10043. del_timer_sync(&pf->service_timer);
  10044. err_mac_addr:
  10045. err_configure_lan_hmc:
  10046. (void)i40e_shutdown_lan_hmc(hw);
  10047. err_init_lan_hmc:
  10048. kfree(pf->qp_pile);
  10049. err_sw_init:
  10050. err_adminq_setup:
  10051. err_pf_reset:
  10052. iounmap(hw->hw_addr);
  10053. err_ioremap:
  10054. kfree(pf);
  10055. err_pf_alloc:
  10056. pci_disable_pcie_error_reporting(pdev);
  10057. pci_release_mem_regions(pdev);
  10058. err_pci_reg:
  10059. err_dma:
  10060. pci_disable_device(pdev);
  10061. return err;
  10062. }
  10063. /**
  10064. * i40e_remove - Device removal routine
  10065. * @pdev: PCI device information struct
  10066. *
  10067. * i40e_remove is called by the PCI subsystem to alert the driver
  10068. * that is should release a PCI device. This could be caused by a
  10069. * Hot-Plug event, or because the driver is going to be removed from
  10070. * memory.
  10071. **/
  10072. static void i40e_remove(struct pci_dev *pdev)
  10073. {
  10074. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10075. struct i40e_hw *hw = &pf->hw;
  10076. i40e_status ret_code;
  10077. int i;
  10078. i40e_dbg_pf_exit(pf);
  10079. i40e_ptp_stop(pf);
  10080. /* Disable RSS in hw */
  10081. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
  10082. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
  10083. /* no more scheduling of any task */
  10084. set_bit(__I40E_SUSPENDED, &pf->state);
  10085. set_bit(__I40E_DOWN, &pf->state);
  10086. if (pf->service_timer.data)
  10087. del_timer_sync(&pf->service_timer);
  10088. if (pf->service_task.func)
  10089. cancel_work_sync(&pf->service_task);
  10090. if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
  10091. i40e_free_vfs(pf);
  10092. pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
  10093. }
  10094. i40e_fdir_teardown(pf);
  10095. /* If there is a switch structure or any orphans, remove them.
  10096. * This will leave only the PF's VSI remaining.
  10097. */
  10098. for (i = 0; i < I40E_MAX_VEB; i++) {
  10099. if (!pf->veb[i])
  10100. continue;
  10101. if (pf->veb[i]->uplink_seid == pf->mac_seid ||
  10102. pf->veb[i]->uplink_seid == 0)
  10103. i40e_switch_branch_release(pf->veb[i]);
  10104. }
  10105. /* Now we can shutdown the PF's VSI, just before we kill
  10106. * adminq and hmc.
  10107. */
  10108. if (pf->vsi[pf->lan_vsi])
  10109. i40e_vsi_release(pf->vsi[pf->lan_vsi]);
  10110. /* remove attached clients */
  10111. ret_code = i40e_lan_del_device(pf);
  10112. if (ret_code) {
  10113. dev_warn(&pdev->dev, "Failed to delete client device: %d\n",
  10114. ret_code);
  10115. }
  10116. /* shutdown and destroy the HMC */
  10117. if (hw->hmc.hmc_obj) {
  10118. ret_code = i40e_shutdown_lan_hmc(hw);
  10119. if (ret_code)
  10120. dev_warn(&pdev->dev,
  10121. "Failed to destroy the HMC resources: %d\n",
  10122. ret_code);
  10123. }
  10124. /* shutdown the adminq */
  10125. i40e_shutdown_adminq(hw);
  10126. /* destroy the locks only once, here */
  10127. mutex_destroy(&hw->aq.arq_mutex);
  10128. mutex_destroy(&hw->aq.asq_mutex);
  10129. /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
  10130. i40e_clear_interrupt_scheme(pf);
  10131. for (i = 0; i < pf->num_alloc_vsi; i++) {
  10132. if (pf->vsi[i]) {
  10133. i40e_vsi_clear_rings(pf->vsi[i]);
  10134. i40e_vsi_clear(pf->vsi[i]);
  10135. pf->vsi[i] = NULL;
  10136. }
  10137. }
  10138. for (i = 0; i < I40E_MAX_VEB; i++) {
  10139. kfree(pf->veb[i]);
  10140. pf->veb[i] = NULL;
  10141. }
  10142. kfree(pf->qp_pile);
  10143. kfree(pf->vsi);
  10144. iounmap(hw->hw_addr);
  10145. kfree(pf);
  10146. pci_release_mem_regions(pdev);
  10147. pci_disable_pcie_error_reporting(pdev);
  10148. pci_disable_device(pdev);
  10149. }
  10150. /**
  10151. * i40e_pci_error_detected - warning that something funky happened in PCI land
  10152. * @pdev: PCI device information struct
  10153. *
  10154. * Called to warn that something happened and the error handling steps
  10155. * are in progress. Allows the driver to quiesce things, be ready for
  10156. * remediation.
  10157. **/
  10158. static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
  10159. enum pci_channel_state error)
  10160. {
  10161. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10162. dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
  10163. if (!pf) {
  10164. dev_info(&pdev->dev,
  10165. "Cannot recover - error happened during device probe\n");
  10166. return PCI_ERS_RESULT_DISCONNECT;
  10167. }
  10168. /* shutdown all operations */
  10169. if (!test_bit(__I40E_SUSPENDED, &pf->state)) {
  10170. rtnl_lock();
  10171. i40e_prep_for_reset(pf);
  10172. rtnl_unlock();
  10173. }
  10174. /* Request a slot reset */
  10175. return PCI_ERS_RESULT_NEED_RESET;
  10176. }
  10177. /**
  10178. * i40e_pci_error_slot_reset - a PCI slot reset just happened
  10179. * @pdev: PCI device information struct
  10180. *
  10181. * Called to find if the driver can work with the device now that
  10182. * the pci slot has been reset. If a basic connection seems good
  10183. * (registers are readable and have sane content) then return a
  10184. * happy little PCI_ERS_RESULT_xxx.
  10185. **/
  10186. static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
  10187. {
  10188. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10189. pci_ers_result_t result;
  10190. int err;
  10191. u32 reg;
  10192. dev_dbg(&pdev->dev, "%s\n", __func__);
  10193. if (pci_enable_device_mem(pdev)) {
  10194. dev_info(&pdev->dev,
  10195. "Cannot re-enable PCI device after reset.\n");
  10196. result = PCI_ERS_RESULT_DISCONNECT;
  10197. } else {
  10198. pci_set_master(pdev);
  10199. pci_restore_state(pdev);
  10200. pci_save_state(pdev);
  10201. pci_wake_from_d3(pdev, false);
  10202. reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  10203. if (reg == 0)
  10204. result = PCI_ERS_RESULT_RECOVERED;
  10205. else
  10206. result = PCI_ERS_RESULT_DISCONNECT;
  10207. }
  10208. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  10209. if (err) {
  10210. dev_info(&pdev->dev,
  10211. "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
  10212. err);
  10213. /* non-fatal, continue */
  10214. }
  10215. return result;
  10216. }
  10217. /**
  10218. * i40e_pci_error_resume - restart operations after PCI error recovery
  10219. * @pdev: PCI device information struct
  10220. *
  10221. * Called to allow the driver to bring things back up after PCI error
  10222. * and/or reset recovery has finished.
  10223. **/
  10224. static void i40e_pci_error_resume(struct pci_dev *pdev)
  10225. {
  10226. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10227. dev_dbg(&pdev->dev, "%s\n", __func__);
  10228. if (test_bit(__I40E_SUSPENDED, &pf->state))
  10229. return;
  10230. rtnl_lock();
  10231. i40e_handle_reset_warning(pf);
  10232. rtnl_unlock();
  10233. }
  10234. /**
  10235. * i40e_shutdown - PCI callback for shutting down
  10236. * @pdev: PCI device information struct
  10237. **/
  10238. static void i40e_shutdown(struct pci_dev *pdev)
  10239. {
  10240. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10241. struct i40e_hw *hw = &pf->hw;
  10242. set_bit(__I40E_SUSPENDED, &pf->state);
  10243. set_bit(__I40E_DOWN, &pf->state);
  10244. rtnl_lock();
  10245. i40e_prep_for_reset(pf);
  10246. rtnl_unlock();
  10247. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  10248. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  10249. del_timer_sync(&pf->service_timer);
  10250. cancel_work_sync(&pf->service_task);
  10251. i40e_fdir_teardown(pf);
  10252. rtnl_lock();
  10253. i40e_prep_for_reset(pf);
  10254. rtnl_unlock();
  10255. wr32(hw, I40E_PFPM_APM,
  10256. (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  10257. wr32(hw, I40E_PFPM_WUFC,
  10258. (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  10259. i40e_clear_interrupt_scheme(pf);
  10260. if (system_state == SYSTEM_POWER_OFF) {
  10261. pci_wake_from_d3(pdev, pf->wol_en);
  10262. pci_set_power_state(pdev, PCI_D3hot);
  10263. }
  10264. }
  10265. #ifdef CONFIG_PM
  10266. /**
  10267. * i40e_suspend - PCI callback for moving to D3
  10268. * @pdev: PCI device information struct
  10269. **/
  10270. static int i40e_suspend(struct pci_dev *pdev, pm_message_t state)
  10271. {
  10272. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10273. struct i40e_hw *hw = &pf->hw;
  10274. int retval = 0;
  10275. set_bit(__I40E_SUSPENDED, &pf->state);
  10276. set_bit(__I40E_DOWN, &pf->state);
  10277. rtnl_lock();
  10278. i40e_prep_for_reset(pf);
  10279. rtnl_unlock();
  10280. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  10281. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  10282. i40e_stop_misc_vector(pf);
  10283. retval = pci_save_state(pdev);
  10284. if (retval)
  10285. return retval;
  10286. pci_wake_from_d3(pdev, pf->wol_en);
  10287. pci_set_power_state(pdev, PCI_D3hot);
  10288. return retval;
  10289. }
  10290. /**
  10291. * i40e_resume - PCI callback for waking up from D3
  10292. * @pdev: PCI device information struct
  10293. **/
  10294. static int i40e_resume(struct pci_dev *pdev)
  10295. {
  10296. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10297. u32 err;
  10298. pci_set_power_state(pdev, PCI_D0);
  10299. pci_restore_state(pdev);
  10300. /* pci_restore_state() clears dev->state_saves, so
  10301. * call pci_save_state() again to restore it.
  10302. */
  10303. pci_save_state(pdev);
  10304. err = pci_enable_device_mem(pdev);
  10305. if (err) {
  10306. dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
  10307. return err;
  10308. }
  10309. pci_set_master(pdev);
  10310. /* no wakeup events while running */
  10311. pci_wake_from_d3(pdev, false);
  10312. /* handling the reset will rebuild the device state */
  10313. if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) {
  10314. clear_bit(__I40E_DOWN, &pf->state);
  10315. rtnl_lock();
  10316. i40e_reset_and_rebuild(pf, false);
  10317. rtnl_unlock();
  10318. }
  10319. return 0;
  10320. }
  10321. #endif
  10322. static const struct pci_error_handlers i40e_err_handler = {
  10323. .error_detected = i40e_pci_error_detected,
  10324. .slot_reset = i40e_pci_error_slot_reset,
  10325. .resume = i40e_pci_error_resume,
  10326. };
  10327. static struct pci_driver i40e_driver = {
  10328. .name = i40e_driver_name,
  10329. .id_table = i40e_pci_tbl,
  10330. .probe = i40e_probe,
  10331. .remove = i40e_remove,
  10332. #ifdef CONFIG_PM
  10333. .suspend = i40e_suspend,
  10334. .resume = i40e_resume,
  10335. #endif
  10336. .shutdown = i40e_shutdown,
  10337. .err_handler = &i40e_err_handler,
  10338. .sriov_configure = i40e_pci_sriov_configure,
  10339. };
  10340. /**
  10341. * i40e_init_module - Driver registration routine
  10342. *
  10343. * i40e_init_module is the first routine called when the driver is
  10344. * loaded. All it does is register with the PCI subsystem.
  10345. **/
  10346. static int __init i40e_init_module(void)
  10347. {
  10348. pr_info("%s: %s - version %s\n", i40e_driver_name,
  10349. i40e_driver_string, i40e_driver_version_str);
  10350. pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
  10351. /* we will see if single thread per module is enough for now,
  10352. * it can't be any worse than using the system workqueue which
  10353. * was already single threaded
  10354. */
  10355. i40e_wq = alloc_workqueue("%s", WQ_UNBOUND | WQ_MEM_RECLAIM, 1,
  10356. i40e_driver_name);
  10357. if (!i40e_wq) {
  10358. pr_err("%s: Failed to create workqueue\n", i40e_driver_name);
  10359. return -ENOMEM;
  10360. }
  10361. i40e_dbg_init();
  10362. return pci_register_driver(&i40e_driver);
  10363. }
  10364. module_init(i40e_init_module);
  10365. /**
  10366. * i40e_exit_module - Driver exit cleanup routine
  10367. *
  10368. * i40e_exit_module is called just before the driver is removed
  10369. * from memory.
  10370. **/
  10371. static void __exit i40e_exit_module(void)
  10372. {
  10373. pci_unregister_driver(&i40e_driver);
  10374. destroy_workqueue(i40e_wq);
  10375. i40e_dbg_exit();
  10376. }
  10377. module_exit(i40e_exit_module);