i40e_main.c 331 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010
  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 2
  38. #define DRV_VERSION_MINOR 1
  39. #define DRV_VERSION_BUILD 7
  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_KX_X722), 0},
  74. {PCI_VDEVICE(INTEL, I40E_DEV_ID_QSFP_X722), 0},
  75. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_X722), 0},
  76. {PCI_VDEVICE(INTEL, I40E_DEV_ID_1G_BASE_T_X722), 0},
  77. {PCI_VDEVICE(INTEL, I40E_DEV_ID_10G_BASE_T_X722), 0},
  78. {PCI_VDEVICE(INTEL, I40E_DEV_ID_SFP_I_X722), 0},
  79. {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2), 0},
  80. {PCI_VDEVICE(INTEL, I40E_DEV_ID_20G_KR2_A), 0},
  81. {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_B), 0},
  82. {PCI_VDEVICE(INTEL, I40E_DEV_ID_25G_SFP28), 0},
  83. /* required last entry */
  84. {0, }
  85. };
  86. MODULE_DEVICE_TABLE(pci, i40e_pci_tbl);
  87. #define I40E_MAX_VF_COUNT 128
  88. static int debug = -1;
  89. module_param(debug, uint, 0);
  90. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all), Debug mask (0x8XXXXXXX)");
  91. MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
  92. MODULE_DESCRIPTION("Intel(R) Ethernet Connection XL710 Network Driver");
  93. MODULE_LICENSE("GPL");
  94. MODULE_VERSION(DRV_VERSION);
  95. static struct workqueue_struct *i40e_wq;
  96. /**
  97. * i40e_allocate_dma_mem_d - OS specific memory alloc for shared code
  98. * @hw: pointer to the HW structure
  99. * @mem: ptr to mem struct to fill out
  100. * @size: size of memory requested
  101. * @alignment: what to align the allocation to
  102. **/
  103. int i40e_allocate_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem,
  104. u64 size, u32 alignment)
  105. {
  106. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  107. mem->size = ALIGN(size, alignment);
  108. mem->va = dma_zalloc_coherent(&pf->pdev->dev, mem->size,
  109. &mem->pa, GFP_KERNEL);
  110. if (!mem->va)
  111. return -ENOMEM;
  112. return 0;
  113. }
  114. /**
  115. * i40e_free_dma_mem_d - OS specific memory free for shared code
  116. * @hw: pointer to the HW structure
  117. * @mem: ptr to mem struct to free
  118. **/
  119. int i40e_free_dma_mem_d(struct i40e_hw *hw, struct i40e_dma_mem *mem)
  120. {
  121. struct i40e_pf *pf = (struct i40e_pf *)hw->back;
  122. dma_free_coherent(&pf->pdev->dev, mem->size, mem->va, mem->pa);
  123. mem->va = NULL;
  124. mem->pa = 0;
  125. mem->size = 0;
  126. return 0;
  127. }
  128. /**
  129. * i40e_allocate_virt_mem_d - OS specific memory alloc for shared code
  130. * @hw: pointer to the HW structure
  131. * @mem: ptr to mem struct to fill out
  132. * @size: size of memory requested
  133. **/
  134. int i40e_allocate_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem,
  135. u32 size)
  136. {
  137. mem->size = size;
  138. mem->va = kzalloc(size, GFP_KERNEL);
  139. if (!mem->va)
  140. return -ENOMEM;
  141. return 0;
  142. }
  143. /**
  144. * i40e_free_virt_mem_d - OS specific memory free for shared code
  145. * @hw: pointer to the HW structure
  146. * @mem: ptr to mem struct to free
  147. **/
  148. int i40e_free_virt_mem_d(struct i40e_hw *hw, struct i40e_virt_mem *mem)
  149. {
  150. /* it's ok to kfree a NULL pointer */
  151. kfree(mem->va);
  152. mem->va = NULL;
  153. mem->size = 0;
  154. return 0;
  155. }
  156. /**
  157. * i40e_get_lump - find a lump of free generic resource
  158. * @pf: board private structure
  159. * @pile: the pile of resource to search
  160. * @needed: the number of items needed
  161. * @id: an owner id to stick on the items assigned
  162. *
  163. * Returns the base item index of the lump, or negative for error
  164. *
  165. * The search_hint trick and lack of advanced fit-finding only work
  166. * because we're highly likely to have all the same size lump requests.
  167. * Linear search time and any fragmentation should be minimal.
  168. **/
  169. static int i40e_get_lump(struct i40e_pf *pf, struct i40e_lump_tracking *pile,
  170. u16 needed, u16 id)
  171. {
  172. int ret = -ENOMEM;
  173. int i, j;
  174. if (!pile || needed == 0 || id >= I40E_PILE_VALID_BIT) {
  175. dev_info(&pf->pdev->dev,
  176. "param err: pile=%p needed=%d id=0x%04x\n",
  177. pile, needed, id);
  178. return -EINVAL;
  179. }
  180. /* start the linear search with an imperfect hint */
  181. i = pile->search_hint;
  182. while (i < pile->num_entries) {
  183. /* skip already allocated entries */
  184. if (pile->list[i] & I40E_PILE_VALID_BIT) {
  185. i++;
  186. continue;
  187. }
  188. /* do we have enough in this lump? */
  189. for (j = 0; (j < needed) && ((i+j) < pile->num_entries); j++) {
  190. if (pile->list[i+j] & I40E_PILE_VALID_BIT)
  191. break;
  192. }
  193. if (j == needed) {
  194. /* there was enough, so assign it to the requestor */
  195. for (j = 0; j < needed; j++)
  196. pile->list[i+j] = id | I40E_PILE_VALID_BIT;
  197. ret = i;
  198. pile->search_hint = i + j;
  199. break;
  200. }
  201. /* not enough, so skip over it and continue looking */
  202. i += j;
  203. }
  204. return ret;
  205. }
  206. /**
  207. * i40e_put_lump - return a lump of generic resource
  208. * @pile: the pile of resource to search
  209. * @index: the base item index
  210. * @id: the owner id of the items assigned
  211. *
  212. * Returns the count of items in the lump
  213. **/
  214. static int i40e_put_lump(struct i40e_lump_tracking *pile, u16 index, u16 id)
  215. {
  216. int valid_id = (id | I40E_PILE_VALID_BIT);
  217. int count = 0;
  218. int i;
  219. if (!pile || index >= pile->num_entries)
  220. return -EINVAL;
  221. for (i = index;
  222. i < pile->num_entries && pile->list[i] == valid_id;
  223. i++) {
  224. pile->list[i] = 0;
  225. count++;
  226. }
  227. if (count && index < pile->search_hint)
  228. pile->search_hint = index;
  229. return count;
  230. }
  231. /**
  232. * i40e_find_vsi_from_id - searches for the vsi with the given id
  233. * @pf - the pf structure to search for the vsi
  234. * @id - id of the vsi it is searching for
  235. **/
  236. struct i40e_vsi *i40e_find_vsi_from_id(struct i40e_pf *pf, u16 id)
  237. {
  238. int i;
  239. for (i = 0; i < pf->num_alloc_vsi; i++)
  240. if (pf->vsi[i] && (pf->vsi[i]->id == id))
  241. return pf->vsi[i];
  242. return NULL;
  243. }
  244. /**
  245. * i40e_service_event_schedule - Schedule the service task to wake up
  246. * @pf: board private structure
  247. *
  248. * If not already scheduled, this puts the task into the work queue
  249. **/
  250. void i40e_service_event_schedule(struct i40e_pf *pf)
  251. {
  252. if (!test_bit(__I40E_DOWN, &pf->state) &&
  253. !test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
  254. queue_work(i40e_wq, &pf->service_task);
  255. }
  256. /**
  257. * i40e_tx_timeout - Respond to a Tx Hang
  258. * @netdev: network interface device structure
  259. *
  260. * If any port has noticed a Tx timeout, it is likely that the whole
  261. * device is munged, not just the one netdev port, so go for the full
  262. * reset.
  263. **/
  264. #ifdef I40E_FCOE
  265. void i40e_tx_timeout(struct net_device *netdev)
  266. #else
  267. static void i40e_tx_timeout(struct net_device *netdev)
  268. #endif
  269. {
  270. struct i40e_netdev_priv *np = netdev_priv(netdev);
  271. struct i40e_vsi *vsi = np->vsi;
  272. struct i40e_pf *pf = vsi->back;
  273. struct i40e_ring *tx_ring = NULL;
  274. unsigned int i, hung_queue = 0;
  275. u32 head, val;
  276. pf->tx_timeout_count++;
  277. /* find the stopped queue the same way the stack does */
  278. for (i = 0; i < netdev->num_tx_queues; i++) {
  279. struct netdev_queue *q;
  280. unsigned long trans_start;
  281. q = netdev_get_tx_queue(netdev, i);
  282. trans_start = q->trans_start;
  283. if (netif_xmit_stopped(q) &&
  284. time_after(jiffies,
  285. (trans_start + netdev->watchdog_timeo))) {
  286. hung_queue = i;
  287. break;
  288. }
  289. }
  290. if (i == netdev->num_tx_queues) {
  291. netdev_info(netdev, "tx_timeout: no netdev hung queue found\n");
  292. } else {
  293. /* now that we have an index, find the tx_ring struct */
  294. for (i = 0; i < vsi->num_queue_pairs; i++) {
  295. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
  296. if (hung_queue ==
  297. vsi->tx_rings[i]->queue_index) {
  298. tx_ring = vsi->tx_rings[i];
  299. break;
  300. }
  301. }
  302. }
  303. }
  304. if (time_after(jiffies, (pf->tx_timeout_last_recovery + HZ*20)))
  305. pf->tx_timeout_recovery_level = 1; /* reset after some time */
  306. else if (time_before(jiffies,
  307. (pf->tx_timeout_last_recovery + netdev->watchdog_timeo)))
  308. return; /* don't do any new action before the next timeout */
  309. if (tx_ring) {
  310. head = i40e_get_head(tx_ring);
  311. /* Read interrupt register */
  312. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  313. val = rd32(&pf->hw,
  314. I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
  315. tx_ring->vsi->base_vector - 1));
  316. else
  317. val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
  318. 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",
  319. vsi->seid, hung_queue, tx_ring->next_to_clean,
  320. head, tx_ring->next_to_use,
  321. readl(tx_ring->tail), val);
  322. }
  323. pf->tx_timeout_last_recovery = jiffies;
  324. netdev_info(netdev, "tx_timeout recovery level %d, hung_queue %d\n",
  325. pf->tx_timeout_recovery_level, hung_queue);
  326. switch (pf->tx_timeout_recovery_level) {
  327. case 1:
  328. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  329. break;
  330. case 2:
  331. set_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
  332. break;
  333. case 3:
  334. set_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
  335. break;
  336. default:
  337. netdev_err(netdev, "tx_timeout recovery unsuccessful\n");
  338. break;
  339. }
  340. i40e_service_event_schedule(pf);
  341. pf->tx_timeout_recovery_level++;
  342. }
  343. /**
  344. * i40e_get_vsi_stats_struct - Get System Network Statistics
  345. * @vsi: the VSI we care about
  346. *
  347. * Returns the address of the device statistics structure.
  348. * The statistics are actually updated from the service task.
  349. **/
  350. struct rtnl_link_stats64 *i40e_get_vsi_stats_struct(struct i40e_vsi *vsi)
  351. {
  352. return &vsi->net_stats;
  353. }
  354. /**
  355. * i40e_get_netdev_stats_struct - Get statistics for netdev interface
  356. * @netdev: network interface device structure
  357. *
  358. * Returns the address of the device statistics structure.
  359. * The statistics are actually updated from the service task.
  360. **/
  361. #ifndef I40E_FCOE
  362. static
  363. #endif
  364. void i40e_get_netdev_stats_struct(struct net_device *netdev,
  365. struct rtnl_link_stats64 *stats)
  366. {
  367. struct i40e_netdev_priv *np = netdev_priv(netdev);
  368. struct i40e_ring *tx_ring, *rx_ring;
  369. struct i40e_vsi *vsi = np->vsi;
  370. struct rtnl_link_stats64 *vsi_stats = i40e_get_vsi_stats_struct(vsi);
  371. int i;
  372. if (test_bit(__I40E_DOWN, &vsi->state))
  373. return;
  374. if (!vsi->tx_rings)
  375. return;
  376. rcu_read_lock();
  377. for (i = 0; i < vsi->num_queue_pairs; i++) {
  378. u64 bytes, packets;
  379. unsigned int start;
  380. tx_ring = ACCESS_ONCE(vsi->tx_rings[i]);
  381. if (!tx_ring)
  382. continue;
  383. do {
  384. start = u64_stats_fetch_begin_irq(&tx_ring->syncp);
  385. packets = tx_ring->stats.packets;
  386. bytes = tx_ring->stats.bytes;
  387. } while (u64_stats_fetch_retry_irq(&tx_ring->syncp, start));
  388. stats->tx_packets += packets;
  389. stats->tx_bytes += bytes;
  390. rx_ring = &tx_ring[1];
  391. do {
  392. start = u64_stats_fetch_begin_irq(&rx_ring->syncp);
  393. packets = rx_ring->stats.packets;
  394. bytes = rx_ring->stats.bytes;
  395. } while (u64_stats_fetch_retry_irq(&rx_ring->syncp, start));
  396. stats->rx_packets += packets;
  397. stats->rx_bytes += bytes;
  398. }
  399. rcu_read_unlock();
  400. /* following stats updated by i40e_watchdog_subtask() */
  401. stats->multicast = vsi_stats->multicast;
  402. stats->tx_errors = vsi_stats->tx_errors;
  403. stats->tx_dropped = vsi_stats->tx_dropped;
  404. stats->rx_errors = vsi_stats->rx_errors;
  405. stats->rx_dropped = vsi_stats->rx_dropped;
  406. stats->rx_crc_errors = vsi_stats->rx_crc_errors;
  407. stats->rx_length_errors = vsi_stats->rx_length_errors;
  408. }
  409. /**
  410. * i40e_vsi_reset_stats - Resets all stats of the given vsi
  411. * @vsi: the VSI to have its stats reset
  412. **/
  413. void i40e_vsi_reset_stats(struct i40e_vsi *vsi)
  414. {
  415. struct rtnl_link_stats64 *ns;
  416. int i;
  417. if (!vsi)
  418. return;
  419. ns = i40e_get_vsi_stats_struct(vsi);
  420. memset(ns, 0, sizeof(*ns));
  421. memset(&vsi->net_stats_offsets, 0, sizeof(vsi->net_stats_offsets));
  422. memset(&vsi->eth_stats, 0, sizeof(vsi->eth_stats));
  423. memset(&vsi->eth_stats_offsets, 0, sizeof(vsi->eth_stats_offsets));
  424. if (vsi->rx_rings && vsi->rx_rings[0]) {
  425. for (i = 0; i < vsi->num_queue_pairs; i++) {
  426. memset(&vsi->rx_rings[i]->stats, 0,
  427. sizeof(vsi->rx_rings[i]->stats));
  428. memset(&vsi->rx_rings[i]->rx_stats, 0,
  429. sizeof(vsi->rx_rings[i]->rx_stats));
  430. memset(&vsi->tx_rings[i]->stats, 0,
  431. sizeof(vsi->tx_rings[i]->stats));
  432. memset(&vsi->tx_rings[i]->tx_stats, 0,
  433. sizeof(vsi->tx_rings[i]->tx_stats));
  434. }
  435. }
  436. vsi->stat_offsets_loaded = false;
  437. }
  438. /**
  439. * i40e_pf_reset_stats - Reset all of the stats for the given PF
  440. * @pf: the PF to be reset
  441. **/
  442. void i40e_pf_reset_stats(struct i40e_pf *pf)
  443. {
  444. int i;
  445. memset(&pf->stats, 0, sizeof(pf->stats));
  446. memset(&pf->stats_offsets, 0, sizeof(pf->stats_offsets));
  447. pf->stat_offsets_loaded = false;
  448. for (i = 0; i < I40E_MAX_VEB; i++) {
  449. if (pf->veb[i]) {
  450. memset(&pf->veb[i]->stats, 0,
  451. sizeof(pf->veb[i]->stats));
  452. memset(&pf->veb[i]->stats_offsets, 0,
  453. sizeof(pf->veb[i]->stats_offsets));
  454. pf->veb[i]->stat_offsets_loaded = false;
  455. }
  456. }
  457. pf->hw_csum_rx_error = 0;
  458. }
  459. /**
  460. * i40e_stat_update48 - read and update a 48 bit stat from the chip
  461. * @hw: ptr to the hardware info
  462. * @hireg: the high 32 bit reg to read
  463. * @loreg: the low 32 bit reg to read
  464. * @offset_loaded: has the initial offset been loaded yet
  465. * @offset: ptr to current offset value
  466. * @stat: ptr to the stat
  467. *
  468. * Since the device stats are not reset at PFReset, they likely will not
  469. * be zeroed when the driver starts. We'll save the first values read
  470. * and use them as offsets to be subtracted from the raw values in order
  471. * to report stats that count from zero. In the process, we also manage
  472. * the potential roll-over.
  473. **/
  474. static void i40e_stat_update48(struct i40e_hw *hw, u32 hireg, u32 loreg,
  475. bool offset_loaded, u64 *offset, u64 *stat)
  476. {
  477. u64 new_data;
  478. if (hw->device_id == I40E_DEV_ID_QEMU) {
  479. new_data = rd32(hw, loreg);
  480. new_data |= ((u64)(rd32(hw, hireg) & 0xFFFF)) << 32;
  481. } else {
  482. new_data = rd64(hw, loreg);
  483. }
  484. if (!offset_loaded)
  485. *offset = new_data;
  486. if (likely(new_data >= *offset))
  487. *stat = new_data - *offset;
  488. else
  489. *stat = (new_data + BIT_ULL(48)) - *offset;
  490. *stat &= 0xFFFFFFFFFFFFULL;
  491. }
  492. /**
  493. * i40e_stat_update32 - read and update a 32 bit stat from the chip
  494. * @hw: ptr to the hardware info
  495. * @reg: the hw reg to read
  496. * @offset_loaded: has the initial offset been loaded yet
  497. * @offset: ptr to current offset value
  498. * @stat: ptr to the stat
  499. **/
  500. static void i40e_stat_update32(struct i40e_hw *hw, u32 reg,
  501. bool offset_loaded, u64 *offset, u64 *stat)
  502. {
  503. u32 new_data;
  504. new_data = rd32(hw, reg);
  505. if (!offset_loaded)
  506. *offset = new_data;
  507. if (likely(new_data >= *offset))
  508. *stat = (u32)(new_data - *offset);
  509. else
  510. *stat = (u32)((new_data + BIT_ULL(32)) - *offset);
  511. }
  512. /**
  513. * i40e_update_eth_stats - Update VSI-specific ethernet statistics counters.
  514. * @vsi: the VSI to be updated
  515. **/
  516. void i40e_update_eth_stats(struct i40e_vsi *vsi)
  517. {
  518. int stat_idx = le16_to_cpu(vsi->info.stat_counter_idx);
  519. struct i40e_pf *pf = vsi->back;
  520. struct i40e_hw *hw = &pf->hw;
  521. struct i40e_eth_stats *oes;
  522. struct i40e_eth_stats *es; /* device's eth stats */
  523. es = &vsi->eth_stats;
  524. oes = &vsi->eth_stats_offsets;
  525. /* Gather up the stats that the hw collects */
  526. i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
  527. vsi->stat_offsets_loaded,
  528. &oes->tx_errors, &es->tx_errors);
  529. i40e_stat_update32(hw, I40E_GLV_RDPC(stat_idx),
  530. vsi->stat_offsets_loaded,
  531. &oes->rx_discards, &es->rx_discards);
  532. i40e_stat_update32(hw, I40E_GLV_RUPP(stat_idx),
  533. vsi->stat_offsets_loaded,
  534. &oes->rx_unknown_protocol, &es->rx_unknown_protocol);
  535. i40e_stat_update32(hw, I40E_GLV_TEPC(stat_idx),
  536. vsi->stat_offsets_loaded,
  537. &oes->tx_errors, &es->tx_errors);
  538. i40e_stat_update48(hw, I40E_GLV_GORCH(stat_idx),
  539. I40E_GLV_GORCL(stat_idx),
  540. vsi->stat_offsets_loaded,
  541. &oes->rx_bytes, &es->rx_bytes);
  542. i40e_stat_update48(hw, I40E_GLV_UPRCH(stat_idx),
  543. I40E_GLV_UPRCL(stat_idx),
  544. vsi->stat_offsets_loaded,
  545. &oes->rx_unicast, &es->rx_unicast);
  546. i40e_stat_update48(hw, I40E_GLV_MPRCH(stat_idx),
  547. I40E_GLV_MPRCL(stat_idx),
  548. vsi->stat_offsets_loaded,
  549. &oes->rx_multicast, &es->rx_multicast);
  550. i40e_stat_update48(hw, I40E_GLV_BPRCH(stat_idx),
  551. I40E_GLV_BPRCL(stat_idx),
  552. vsi->stat_offsets_loaded,
  553. &oes->rx_broadcast, &es->rx_broadcast);
  554. i40e_stat_update48(hw, I40E_GLV_GOTCH(stat_idx),
  555. I40E_GLV_GOTCL(stat_idx),
  556. vsi->stat_offsets_loaded,
  557. &oes->tx_bytes, &es->tx_bytes);
  558. i40e_stat_update48(hw, I40E_GLV_UPTCH(stat_idx),
  559. I40E_GLV_UPTCL(stat_idx),
  560. vsi->stat_offsets_loaded,
  561. &oes->tx_unicast, &es->tx_unicast);
  562. i40e_stat_update48(hw, I40E_GLV_MPTCH(stat_idx),
  563. I40E_GLV_MPTCL(stat_idx),
  564. vsi->stat_offsets_loaded,
  565. &oes->tx_multicast, &es->tx_multicast);
  566. i40e_stat_update48(hw, I40E_GLV_BPTCH(stat_idx),
  567. I40E_GLV_BPTCL(stat_idx),
  568. vsi->stat_offsets_loaded,
  569. &oes->tx_broadcast, &es->tx_broadcast);
  570. vsi->stat_offsets_loaded = true;
  571. }
  572. /**
  573. * i40e_update_veb_stats - Update Switch component statistics
  574. * @veb: the VEB being updated
  575. **/
  576. static void i40e_update_veb_stats(struct i40e_veb *veb)
  577. {
  578. struct i40e_pf *pf = veb->pf;
  579. struct i40e_hw *hw = &pf->hw;
  580. struct i40e_eth_stats *oes;
  581. struct i40e_eth_stats *es; /* device's eth stats */
  582. struct i40e_veb_tc_stats *veb_oes;
  583. struct i40e_veb_tc_stats *veb_es;
  584. int i, idx = 0;
  585. idx = veb->stats_idx;
  586. es = &veb->stats;
  587. oes = &veb->stats_offsets;
  588. veb_es = &veb->tc_stats;
  589. veb_oes = &veb->tc_stats_offsets;
  590. /* Gather up the stats that the hw collects */
  591. i40e_stat_update32(hw, I40E_GLSW_TDPC(idx),
  592. veb->stat_offsets_loaded,
  593. &oes->tx_discards, &es->tx_discards);
  594. if (hw->revision_id > 0)
  595. i40e_stat_update32(hw, I40E_GLSW_RUPP(idx),
  596. veb->stat_offsets_loaded,
  597. &oes->rx_unknown_protocol,
  598. &es->rx_unknown_protocol);
  599. i40e_stat_update48(hw, I40E_GLSW_GORCH(idx), I40E_GLSW_GORCL(idx),
  600. veb->stat_offsets_loaded,
  601. &oes->rx_bytes, &es->rx_bytes);
  602. i40e_stat_update48(hw, I40E_GLSW_UPRCH(idx), I40E_GLSW_UPRCL(idx),
  603. veb->stat_offsets_loaded,
  604. &oes->rx_unicast, &es->rx_unicast);
  605. i40e_stat_update48(hw, I40E_GLSW_MPRCH(idx), I40E_GLSW_MPRCL(idx),
  606. veb->stat_offsets_loaded,
  607. &oes->rx_multicast, &es->rx_multicast);
  608. i40e_stat_update48(hw, I40E_GLSW_BPRCH(idx), I40E_GLSW_BPRCL(idx),
  609. veb->stat_offsets_loaded,
  610. &oes->rx_broadcast, &es->rx_broadcast);
  611. i40e_stat_update48(hw, I40E_GLSW_GOTCH(idx), I40E_GLSW_GOTCL(idx),
  612. veb->stat_offsets_loaded,
  613. &oes->tx_bytes, &es->tx_bytes);
  614. i40e_stat_update48(hw, I40E_GLSW_UPTCH(idx), I40E_GLSW_UPTCL(idx),
  615. veb->stat_offsets_loaded,
  616. &oes->tx_unicast, &es->tx_unicast);
  617. i40e_stat_update48(hw, I40E_GLSW_MPTCH(idx), I40E_GLSW_MPTCL(idx),
  618. veb->stat_offsets_loaded,
  619. &oes->tx_multicast, &es->tx_multicast);
  620. i40e_stat_update48(hw, I40E_GLSW_BPTCH(idx), I40E_GLSW_BPTCL(idx),
  621. veb->stat_offsets_loaded,
  622. &oes->tx_broadcast, &es->tx_broadcast);
  623. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  624. i40e_stat_update48(hw, I40E_GLVEBTC_RPCH(i, idx),
  625. I40E_GLVEBTC_RPCL(i, idx),
  626. veb->stat_offsets_loaded,
  627. &veb_oes->tc_rx_packets[i],
  628. &veb_es->tc_rx_packets[i]);
  629. i40e_stat_update48(hw, I40E_GLVEBTC_RBCH(i, idx),
  630. I40E_GLVEBTC_RBCL(i, idx),
  631. veb->stat_offsets_loaded,
  632. &veb_oes->tc_rx_bytes[i],
  633. &veb_es->tc_rx_bytes[i]);
  634. i40e_stat_update48(hw, I40E_GLVEBTC_TPCH(i, idx),
  635. I40E_GLVEBTC_TPCL(i, idx),
  636. veb->stat_offsets_loaded,
  637. &veb_oes->tc_tx_packets[i],
  638. &veb_es->tc_tx_packets[i]);
  639. i40e_stat_update48(hw, I40E_GLVEBTC_TBCH(i, idx),
  640. I40E_GLVEBTC_TBCL(i, idx),
  641. veb->stat_offsets_loaded,
  642. &veb_oes->tc_tx_bytes[i],
  643. &veb_es->tc_tx_bytes[i]);
  644. }
  645. veb->stat_offsets_loaded = true;
  646. }
  647. #ifdef I40E_FCOE
  648. /**
  649. * i40e_update_fcoe_stats - Update FCoE-specific ethernet statistics counters.
  650. * @vsi: the VSI that is capable of doing FCoE
  651. **/
  652. static void i40e_update_fcoe_stats(struct i40e_vsi *vsi)
  653. {
  654. struct i40e_pf *pf = vsi->back;
  655. struct i40e_hw *hw = &pf->hw;
  656. struct i40e_fcoe_stats *ofs;
  657. struct i40e_fcoe_stats *fs; /* device's eth stats */
  658. int idx;
  659. if (vsi->type != I40E_VSI_FCOE)
  660. return;
  661. idx = hw->pf_id + I40E_FCOE_PF_STAT_OFFSET;
  662. fs = &vsi->fcoe_stats;
  663. ofs = &vsi->fcoe_stats_offsets;
  664. i40e_stat_update32(hw, I40E_GL_FCOEPRC(idx),
  665. vsi->fcoe_stat_offsets_loaded,
  666. &ofs->rx_fcoe_packets, &fs->rx_fcoe_packets);
  667. i40e_stat_update48(hw, I40E_GL_FCOEDWRCH(idx), I40E_GL_FCOEDWRCL(idx),
  668. vsi->fcoe_stat_offsets_loaded,
  669. &ofs->rx_fcoe_dwords, &fs->rx_fcoe_dwords);
  670. i40e_stat_update32(hw, I40E_GL_FCOERPDC(idx),
  671. vsi->fcoe_stat_offsets_loaded,
  672. &ofs->rx_fcoe_dropped, &fs->rx_fcoe_dropped);
  673. i40e_stat_update32(hw, I40E_GL_FCOEPTC(idx),
  674. vsi->fcoe_stat_offsets_loaded,
  675. &ofs->tx_fcoe_packets, &fs->tx_fcoe_packets);
  676. i40e_stat_update48(hw, I40E_GL_FCOEDWTCH(idx), I40E_GL_FCOEDWTCL(idx),
  677. vsi->fcoe_stat_offsets_loaded,
  678. &ofs->tx_fcoe_dwords, &fs->tx_fcoe_dwords);
  679. i40e_stat_update32(hw, I40E_GL_FCOECRC(idx),
  680. vsi->fcoe_stat_offsets_loaded,
  681. &ofs->fcoe_bad_fccrc, &fs->fcoe_bad_fccrc);
  682. i40e_stat_update32(hw, I40E_GL_FCOELAST(idx),
  683. vsi->fcoe_stat_offsets_loaded,
  684. &ofs->fcoe_last_error, &fs->fcoe_last_error);
  685. i40e_stat_update32(hw, I40E_GL_FCOEDDPC(idx),
  686. vsi->fcoe_stat_offsets_loaded,
  687. &ofs->fcoe_ddp_count, &fs->fcoe_ddp_count);
  688. vsi->fcoe_stat_offsets_loaded = true;
  689. }
  690. #endif
  691. /**
  692. * i40e_update_vsi_stats - Update the vsi statistics counters.
  693. * @vsi: the VSI to be updated
  694. *
  695. * There are a few instances where we store the same stat in a
  696. * couple of different structs. This is partly because we have
  697. * the netdev stats that need to be filled out, which is slightly
  698. * different from the "eth_stats" defined by the chip and used in
  699. * VF communications. We sort it out here.
  700. **/
  701. static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
  702. {
  703. struct i40e_pf *pf = vsi->back;
  704. struct rtnl_link_stats64 *ons;
  705. struct rtnl_link_stats64 *ns; /* netdev stats */
  706. struct i40e_eth_stats *oes;
  707. struct i40e_eth_stats *es; /* device's eth stats */
  708. u32 tx_restart, tx_busy;
  709. u64 tx_lost_interrupt;
  710. struct i40e_ring *p;
  711. u32 rx_page, rx_buf;
  712. u64 bytes, packets;
  713. unsigned int start;
  714. u64 tx_linearize;
  715. u64 tx_force_wb;
  716. u64 rx_p, rx_b;
  717. u64 tx_p, tx_b;
  718. u16 q;
  719. if (test_bit(__I40E_DOWN, &vsi->state) ||
  720. test_bit(__I40E_CONFIG_BUSY, &pf->state))
  721. return;
  722. ns = i40e_get_vsi_stats_struct(vsi);
  723. ons = &vsi->net_stats_offsets;
  724. es = &vsi->eth_stats;
  725. oes = &vsi->eth_stats_offsets;
  726. /* Gather up the netdev and vsi stats that the driver collects
  727. * on the fly during packet processing
  728. */
  729. rx_b = rx_p = 0;
  730. tx_b = tx_p = 0;
  731. tx_restart = tx_busy = tx_linearize = tx_force_wb = 0;
  732. tx_lost_interrupt = 0;
  733. rx_page = 0;
  734. rx_buf = 0;
  735. rcu_read_lock();
  736. for (q = 0; q < vsi->num_queue_pairs; q++) {
  737. /* locate Tx ring */
  738. p = ACCESS_ONCE(vsi->tx_rings[q]);
  739. do {
  740. start = u64_stats_fetch_begin_irq(&p->syncp);
  741. packets = p->stats.packets;
  742. bytes = p->stats.bytes;
  743. } while (u64_stats_fetch_retry_irq(&p->syncp, start));
  744. tx_b += bytes;
  745. tx_p += packets;
  746. tx_restart += p->tx_stats.restart_queue;
  747. tx_busy += p->tx_stats.tx_busy;
  748. tx_linearize += p->tx_stats.tx_linearize;
  749. tx_force_wb += p->tx_stats.tx_force_wb;
  750. tx_lost_interrupt += p->tx_stats.tx_lost_interrupt;
  751. /* Rx queue is part of the same block as Tx queue */
  752. p = &p[1];
  753. do {
  754. start = u64_stats_fetch_begin_irq(&p->syncp);
  755. packets = p->stats.packets;
  756. bytes = p->stats.bytes;
  757. } while (u64_stats_fetch_retry_irq(&p->syncp, start));
  758. rx_b += bytes;
  759. rx_p += packets;
  760. rx_buf += p->rx_stats.alloc_buff_failed;
  761. rx_page += p->rx_stats.alloc_page_failed;
  762. }
  763. rcu_read_unlock();
  764. vsi->tx_restart = tx_restart;
  765. vsi->tx_busy = tx_busy;
  766. vsi->tx_linearize = tx_linearize;
  767. vsi->tx_force_wb = tx_force_wb;
  768. vsi->tx_lost_interrupt = tx_lost_interrupt;
  769. vsi->rx_page_failed = rx_page;
  770. vsi->rx_buf_failed = rx_buf;
  771. ns->rx_packets = rx_p;
  772. ns->rx_bytes = rx_b;
  773. ns->tx_packets = tx_p;
  774. ns->tx_bytes = tx_b;
  775. /* update netdev stats from eth stats */
  776. i40e_update_eth_stats(vsi);
  777. ons->tx_errors = oes->tx_errors;
  778. ns->tx_errors = es->tx_errors;
  779. ons->multicast = oes->rx_multicast;
  780. ns->multicast = es->rx_multicast;
  781. ons->rx_dropped = oes->rx_discards;
  782. ns->rx_dropped = es->rx_discards;
  783. ons->tx_dropped = oes->tx_discards;
  784. ns->tx_dropped = es->tx_discards;
  785. /* pull in a couple PF stats if this is the main vsi */
  786. if (vsi == pf->vsi[pf->lan_vsi]) {
  787. ns->rx_crc_errors = pf->stats.crc_errors;
  788. ns->rx_errors = pf->stats.crc_errors + pf->stats.illegal_bytes;
  789. ns->rx_length_errors = pf->stats.rx_length_errors;
  790. }
  791. }
  792. /**
  793. * i40e_update_pf_stats - Update the PF statistics counters.
  794. * @pf: the PF to be updated
  795. **/
  796. static void i40e_update_pf_stats(struct i40e_pf *pf)
  797. {
  798. struct i40e_hw_port_stats *osd = &pf->stats_offsets;
  799. struct i40e_hw_port_stats *nsd = &pf->stats;
  800. struct i40e_hw *hw = &pf->hw;
  801. u32 val;
  802. int i;
  803. i40e_stat_update48(hw, I40E_GLPRT_GORCH(hw->port),
  804. I40E_GLPRT_GORCL(hw->port),
  805. pf->stat_offsets_loaded,
  806. &osd->eth.rx_bytes, &nsd->eth.rx_bytes);
  807. i40e_stat_update48(hw, I40E_GLPRT_GOTCH(hw->port),
  808. I40E_GLPRT_GOTCL(hw->port),
  809. pf->stat_offsets_loaded,
  810. &osd->eth.tx_bytes, &nsd->eth.tx_bytes);
  811. i40e_stat_update32(hw, I40E_GLPRT_RDPC(hw->port),
  812. pf->stat_offsets_loaded,
  813. &osd->eth.rx_discards,
  814. &nsd->eth.rx_discards);
  815. i40e_stat_update48(hw, I40E_GLPRT_UPRCH(hw->port),
  816. I40E_GLPRT_UPRCL(hw->port),
  817. pf->stat_offsets_loaded,
  818. &osd->eth.rx_unicast,
  819. &nsd->eth.rx_unicast);
  820. i40e_stat_update48(hw, I40E_GLPRT_MPRCH(hw->port),
  821. I40E_GLPRT_MPRCL(hw->port),
  822. pf->stat_offsets_loaded,
  823. &osd->eth.rx_multicast,
  824. &nsd->eth.rx_multicast);
  825. i40e_stat_update48(hw, I40E_GLPRT_BPRCH(hw->port),
  826. I40E_GLPRT_BPRCL(hw->port),
  827. pf->stat_offsets_loaded,
  828. &osd->eth.rx_broadcast,
  829. &nsd->eth.rx_broadcast);
  830. i40e_stat_update48(hw, I40E_GLPRT_UPTCH(hw->port),
  831. I40E_GLPRT_UPTCL(hw->port),
  832. pf->stat_offsets_loaded,
  833. &osd->eth.tx_unicast,
  834. &nsd->eth.tx_unicast);
  835. i40e_stat_update48(hw, I40E_GLPRT_MPTCH(hw->port),
  836. I40E_GLPRT_MPTCL(hw->port),
  837. pf->stat_offsets_loaded,
  838. &osd->eth.tx_multicast,
  839. &nsd->eth.tx_multicast);
  840. i40e_stat_update48(hw, I40E_GLPRT_BPTCH(hw->port),
  841. I40E_GLPRT_BPTCL(hw->port),
  842. pf->stat_offsets_loaded,
  843. &osd->eth.tx_broadcast,
  844. &nsd->eth.tx_broadcast);
  845. i40e_stat_update32(hw, I40E_GLPRT_TDOLD(hw->port),
  846. pf->stat_offsets_loaded,
  847. &osd->tx_dropped_link_down,
  848. &nsd->tx_dropped_link_down);
  849. i40e_stat_update32(hw, I40E_GLPRT_CRCERRS(hw->port),
  850. pf->stat_offsets_loaded,
  851. &osd->crc_errors, &nsd->crc_errors);
  852. i40e_stat_update32(hw, I40E_GLPRT_ILLERRC(hw->port),
  853. pf->stat_offsets_loaded,
  854. &osd->illegal_bytes, &nsd->illegal_bytes);
  855. i40e_stat_update32(hw, I40E_GLPRT_MLFC(hw->port),
  856. pf->stat_offsets_loaded,
  857. &osd->mac_local_faults,
  858. &nsd->mac_local_faults);
  859. i40e_stat_update32(hw, I40E_GLPRT_MRFC(hw->port),
  860. pf->stat_offsets_loaded,
  861. &osd->mac_remote_faults,
  862. &nsd->mac_remote_faults);
  863. i40e_stat_update32(hw, I40E_GLPRT_RLEC(hw->port),
  864. pf->stat_offsets_loaded,
  865. &osd->rx_length_errors,
  866. &nsd->rx_length_errors);
  867. i40e_stat_update32(hw, I40E_GLPRT_LXONRXC(hw->port),
  868. pf->stat_offsets_loaded,
  869. &osd->link_xon_rx, &nsd->link_xon_rx);
  870. i40e_stat_update32(hw, I40E_GLPRT_LXONTXC(hw->port),
  871. pf->stat_offsets_loaded,
  872. &osd->link_xon_tx, &nsd->link_xon_tx);
  873. i40e_stat_update32(hw, I40E_GLPRT_LXOFFRXC(hw->port),
  874. pf->stat_offsets_loaded,
  875. &osd->link_xoff_rx, &nsd->link_xoff_rx);
  876. i40e_stat_update32(hw, I40E_GLPRT_LXOFFTXC(hw->port),
  877. pf->stat_offsets_loaded,
  878. &osd->link_xoff_tx, &nsd->link_xoff_tx);
  879. for (i = 0; i < 8; i++) {
  880. i40e_stat_update32(hw, I40E_GLPRT_PXOFFRXC(hw->port, i),
  881. pf->stat_offsets_loaded,
  882. &osd->priority_xoff_rx[i],
  883. &nsd->priority_xoff_rx[i]);
  884. i40e_stat_update32(hw, I40E_GLPRT_PXONRXC(hw->port, i),
  885. pf->stat_offsets_loaded,
  886. &osd->priority_xon_rx[i],
  887. &nsd->priority_xon_rx[i]);
  888. i40e_stat_update32(hw, I40E_GLPRT_PXONTXC(hw->port, i),
  889. pf->stat_offsets_loaded,
  890. &osd->priority_xon_tx[i],
  891. &nsd->priority_xon_tx[i]);
  892. i40e_stat_update32(hw, I40E_GLPRT_PXOFFTXC(hw->port, i),
  893. pf->stat_offsets_loaded,
  894. &osd->priority_xoff_tx[i],
  895. &nsd->priority_xoff_tx[i]);
  896. i40e_stat_update32(hw,
  897. I40E_GLPRT_RXON2OFFCNT(hw->port, i),
  898. pf->stat_offsets_loaded,
  899. &osd->priority_xon_2_xoff[i],
  900. &nsd->priority_xon_2_xoff[i]);
  901. }
  902. i40e_stat_update48(hw, I40E_GLPRT_PRC64H(hw->port),
  903. I40E_GLPRT_PRC64L(hw->port),
  904. pf->stat_offsets_loaded,
  905. &osd->rx_size_64, &nsd->rx_size_64);
  906. i40e_stat_update48(hw, I40E_GLPRT_PRC127H(hw->port),
  907. I40E_GLPRT_PRC127L(hw->port),
  908. pf->stat_offsets_loaded,
  909. &osd->rx_size_127, &nsd->rx_size_127);
  910. i40e_stat_update48(hw, I40E_GLPRT_PRC255H(hw->port),
  911. I40E_GLPRT_PRC255L(hw->port),
  912. pf->stat_offsets_loaded,
  913. &osd->rx_size_255, &nsd->rx_size_255);
  914. i40e_stat_update48(hw, I40E_GLPRT_PRC511H(hw->port),
  915. I40E_GLPRT_PRC511L(hw->port),
  916. pf->stat_offsets_loaded,
  917. &osd->rx_size_511, &nsd->rx_size_511);
  918. i40e_stat_update48(hw, I40E_GLPRT_PRC1023H(hw->port),
  919. I40E_GLPRT_PRC1023L(hw->port),
  920. pf->stat_offsets_loaded,
  921. &osd->rx_size_1023, &nsd->rx_size_1023);
  922. i40e_stat_update48(hw, I40E_GLPRT_PRC1522H(hw->port),
  923. I40E_GLPRT_PRC1522L(hw->port),
  924. pf->stat_offsets_loaded,
  925. &osd->rx_size_1522, &nsd->rx_size_1522);
  926. i40e_stat_update48(hw, I40E_GLPRT_PRC9522H(hw->port),
  927. I40E_GLPRT_PRC9522L(hw->port),
  928. pf->stat_offsets_loaded,
  929. &osd->rx_size_big, &nsd->rx_size_big);
  930. i40e_stat_update48(hw, I40E_GLPRT_PTC64H(hw->port),
  931. I40E_GLPRT_PTC64L(hw->port),
  932. pf->stat_offsets_loaded,
  933. &osd->tx_size_64, &nsd->tx_size_64);
  934. i40e_stat_update48(hw, I40E_GLPRT_PTC127H(hw->port),
  935. I40E_GLPRT_PTC127L(hw->port),
  936. pf->stat_offsets_loaded,
  937. &osd->tx_size_127, &nsd->tx_size_127);
  938. i40e_stat_update48(hw, I40E_GLPRT_PTC255H(hw->port),
  939. I40E_GLPRT_PTC255L(hw->port),
  940. pf->stat_offsets_loaded,
  941. &osd->tx_size_255, &nsd->tx_size_255);
  942. i40e_stat_update48(hw, I40E_GLPRT_PTC511H(hw->port),
  943. I40E_GLPRT_PTC511L(hw->port),
  944. pf->stat_offsets_loaded,
  945. &osd->tx_size_511, &nsd->tx_size_511);
  946. i40e_stat_update48(hw, I40E_GLPRT_PTC1023H(hw->port),
  947. I40E_GLPRT_PTC1023L(hw->port),
  948. pf->stat_offsets_loaded,
  949. &osd->tx_size_1023, &nsd->tx_size_1023);
  950. i40e_stat_update48(hw, I40E_GLPRT_PTC1522H(hw->port),
  951. I40E_GLPRT_PTC1522L(hw->port),
  952. pf->stat_offsets_loaded,
  953. &osd->tx_size_1522, &nsd->tx_size_1522);
  954. i40e_stat_update48(hw, I40E_GLPRT_PTC9522H(hw->port),
  955. I40E_GLPRT_PTC9522L(hw->port),
  956. pf->stat_offsets_loaded,
  957. &osd->tx_size_big, &nsd->tx_size_big);
  958. i40e_stat_update32(hw, I40E_GLPRT_RUC(hw->port),
  959. pf->stat_offsets_loaded,
  960. &osd->rx_undersize, &nsd->rx_undersize);
  961. i40e_stat_update32(hw, I40E_GLPRT_RFC(hw->port),
  962. pf->stat_offsets_loaded,
  963. &osd->rx_fragments, &nsd->rx_fragments);
  964. i40e_stat_update32(hw, I40E_GLPRT_ROC(hw->port),
  965. pf->stat_offsets_loaded,
  966. &osd->rx_oversize, &nsd->rx_oversize);
  967. i40e_stat_update32(hw, I40E_GLPRT_RJC(hw->port),
  968. pf->stat_offsets_loaded,
  969. &osd->rx_jabber, &nsd->rx_jabber);
  970. /* FDIR stats */
  971. i40e_stat_update32(hw,
  972. I40E_GLQF_PCNT(I40E_FD_ATR_STAT_IDX(pf->hw.pf_id)),
  973. pf->stat_offsets_loaded,
  974. &osd->fd_atr_match, &nsd->fd_atr_match);
  975. i40e_stat_update32(hw,
  976. I40E_GLQF_PCNT(I40E_FD_SB_STAT_IDX(pf->hw.pf_id)),
  977. pf->stat_offsets_loaded,
  978. &osd->fd_sb_match, &nsd->fd_sb_match);
  979. i40e_stat_update32(hw,
  980. I40E_GLQF_PCNT(I40E_FD_ATR_TUNNEL_STAT_IDX(pf->hw.pf_id)),
  981. pf->stat_offsets_loaded,
  982. &osd->fd_atr_tunnel_match, &nsd->fd_atr_tunnel_match);
  983. val = rd32(hw, I40E_PRTPM_EEE_STAT);
  984. nsd->tx_lpi_status =
  985. (val & I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_MASK) >>
  986. I40E_PRTPM_EEE_STAT_TX_LPI_STATUS_SHIFT;
  987. nsd->rx_lpi_status =
  988. (val & I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_MASK) >>
  989. I40E_PRTPM_EEE_STAT_RX_LPI_STATUS_SHIFT;
  990. i40e_stat_update32(hw, I40E_PRTPM_TLPIC,
  991. pf->stat_offsets_loaded,
  992. &osd->tx_lpi_count, &nsd->tx_lpi_count);
  993. i40e_stat_update32(hw, I40E_PRTPM_RLPIC,
  994. pf->stat_offsets_loaded,
  995. &osd->rx_lpi_count, &nsd->rx_lpi_count);
  996. if (pf->flags & I40E_FLAG_FD_SB_ENABLED &&
  997. !(pf->hw_disabled_flags & I40E_FLAG_FD_SB_ENABLED))
  998. nsd->fd_sb_status = true;
  999. else
  1000. nsd->fd_sb_status = false;
  1001. if (pf->flags & I40E_FLAG_FD_ATR_ENABLED &&
  1002. !(pf->hw_disabled_flags & I40E_FLAG_FD_ATR_ENABLED))
  1003. nsd->fd_atr_status = true;
  1004. else
  1005. nsd->fd_atr_status = false;
  1006. pf->stat_offsets_loaded = true;
  1007. }
  1008. /**
  1009. * i40e_update_stats - Update the various statistics counters.
  1010. * @vsi: the VSI to be updated
  1011. *
  1012. * Update the various stats for this VSI and its related entities.
  1013. **/
  1014. void i40e_update_stats(struct i40e_vsi *vsi)
  1015. {
  1016. struct i40e_pf *pf = vsi->back;
  1017. if (vsi == pf->vsi[pf->lan_vsi])
  1018. i40e_update_pf_stats(pf);
  1019. i40e_update_vsi_stats(vsi);
  1020. #ifdef I40E_FCOE
  1021. i40e_update_fcoe_stats(vsi);
  1022. #endif
  1023. }
  1024. /**
  1025. * i40e_find_filter - Search VSI filter list for specific mac/vlan filter
  1026. * @vsi: the VSI to be searched
  1027. * @macaddr: the MAC address
  1028. * @vlan: the vlan
  1029. *
  1030. * Returns ptr to the filter object or NULL
  1031. **/
  1032. static struct i40e_mac_filter *i40e_find_filter(struct i40e_vsi *vsi,
  1033. const u8 *macaddr, s16 vlan)
  1034. {
  1035. struct i40e_mac_filter *f;
  1036. u64 key;
  1037. if (!vsi || !macaddr)
  1038. return NULL;
  1039. key = i40e_addr_to_hkey(macaddr);
  1040. hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) {
  1041. if ((ether_addr_equal(macaddr, f->macaddr)) &&
  1042. (vlan == f->vlan))
  1043. return f;
  1044. }
  1045. return NULL;
  1046. }
  1047. /**
  1048. * i40e_find_mac - Find a mac addr in the macvlan filters list
  1049. * @vsi: the VSI to be searched
  1050. * @macaddr: the MAC address we are searching for
  1051. *
  1052. * Returns the first filter with the provided MAC address or NULL if
  1053. * MAC address was not found
  1054. **/
  1055. struct i40e_mac_filter *i40e_find_mac(struct i40e_vsi *vsi, const u8 *macaddr)
  1056. {
  1057. struct i40e_mac_filter *f;
  1058. u64 key;
  1059. if (!vsi || !macaddr)
  1060. return NULL;
  1061. key = i40e_addr_to_hkey(macaddr);
  1062. hash_for_each_possible(vsi->mac_filter_hash, f, hlist, key) {
  1063. if ((ether_addr_equal(macaddr, f->macaddr)))
  1064. return f;
  1065. }
  1066. return NULL;
  1067. }
  1068. /**
  1069. * i40e_is_vsi_in_vlan - Check if VSI is in vlan mode
  1070. * @vsi: the VSI to be searched
  1071. *
  1072. * Returns true if VSI is in vlan mode or false otherwise
  1073. **/
  1074. bool i40e_is_vsi_in_vlan(struct i40e_vsi *vsi)
  1075. {
  1076. /* If we have a PVID, always operate in VLAN mode */
  1077. if (vsi->info.pvid)
  1078. return true;
  1079. /* We need to operate in VLAN mode whenever we have any filters with
  1080. * a VLAN other than I40E_VLAN_ALL. We could check the table each
  1081. * time, incurring search cost repeatedly. However, we can notice two
  1082. * things:
  1083. *
  1084. * 1) the only place where we can gain a VLAN filter is in
  1085. * i40e_add_filter.
  1086. *
  1087. * 2) the only place where filters are actually removed is in
  1088. * i40e_sync_filters_subtask.
  1089. *
  1090. * Thus, we can simply use a boolean value, has_vlan_filters which we
  1091. * will set to true when we add a VLAN filter in i40e_add_filter. Then
  1092. * we have to perform the full search after deleting filters in
  1093. * i40e_sync_filters_subtask, but we already have to search
  1094. * filters here and can perform the check at the same time. This
  1095. * results in avoiding embedding a loop for VLAN mode inside another
  1096. * loop over all the filters, and should maintain correctness as noted
  1097. * above.
  1098. */
  1099. return vsi->has_vlan_filter;
  1100. }
  1101. /**
  1102. * i40e_correct_mac_vlan_filters - Correct non-VLAN filters if necessary
  1103. * @vsi: the VSI to configure
  1104. * @tmp_add_list: list of filters ready to be added
  1105. * @tmp_del_list: list of filters ready to be deleted
  1106. * @vlan_filters: the number of active VLAN filters
  1107. *
  1108. * Update VLAN=0 and VLAN=-1 (I40E_VLAN_ANY) filters properly so that they
  1109. * behave as expected. If we have any active VLAN filters remaining or about
  1110. * to be added then we need to update non-VLAN filters to be marked as VLAN=0
  1111. * so that they only match against untagged traffic. If we no longer have any
  1112. * active VLAN filters, we need to make all non-VLAN filters marked as VLAN=-1
  1113. * so that they match against both tagged and untagged traffic. In this way,
  1114. * we ensure that we correctly receive the desired traffic. This ensures that
  1115. * when we have an active VLAN we will receive only untagged traffic and
  1116. * traffic matching active VLANs. If we have no active VLANs then we will
  1117. * operate in non-VLAN mode and receive all traffic, tagged or untagged.
  1118. *
  1119. * Finally, in a similar fashion, this function also corrects filters when
  1120. * there is an active PVID assigned to this VSI.
  1121. *
  1122. * In case of memory allocation failure return -ENOMEM. Otherwise, return 0.
  1123. *
  1124. * This function is only expected to be called from within
  1125. * i40e_sync_vsi_filters.
  1126. *
  1127. * NOTE: This function expects to be called while under the
  1128. * mac_filter_hash_lock
  1129. */
  1130. static int i40e_correct_mac_vlan_filters(struct i40e_vsi *vsi,
  1131. struct hlist_head *tmp_add_list,
  1132. struct hlist_head *tmp_del_list,
  1133. int vlan_filters)
  1134. {
  1135. s16 pvid = le16_to_cpu(vsi->info.pvid);
  1136. struct i40e_mac_filter *f, *add_head;
  1137. struct i40e_new_mac_filter *new;
  1138. struct hlist_node *h;
  1139. int bkt, new_vlan;
  1140. /* To determine if a particular filter needs to be replaced we
  1141. * have the three following conditions:
  1142. *
  1143. * a) if we have a PVID assigned, then all filters which are
  1144. * not marked as VLAN=PVID must be replaced with filters that
  1145. * are.
  1146. * b) otherwise, if we have any active VLANS, all filters
  1147. * which are marked as VLAN=-1 must be replaced with
  1148. * filters marked as VLAN=0
  1149. * c) finally, if we do not have any active VLANS, all filters
  1150. * which are marked as VLAN=0 must be replaced with filters
  1151. * marked as VLAN=-1
  1152. */
  1153. /* Update the filters about to be added in place */
  1154. hlist_for_each_entry(new, tmp_add_list, hlist) {
  1155. if (pvid && new->f->vlan != pvid)
  1156. new->f->vlan = pvid;
  1157. else if (vlan_filters && new->f->vlan == I40E_VLAN_ANY)
  1158. new->f->vlan = 0;
  1159. else if (!vlan_filters && new->f->vlan == 0)
  1160. new->f->vlan = I40E_VLAN_ANY;
  1161. }
  1162. /* Update the remaining active filters */
  1163. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1164. /* Combine the checks for whether a filter needs to be changed
  1165. * and then determine the new VLAN inside the if block, in
  1166. * order to avoid duplicating code for adding the new filter
  1167. * then deleting the old filter.
  1168. */
  1169. if ((pvid && f->vlan != pvid) ||
  1170. (vlan_filters && f->vlan == I40E_VLAN_ANY) ||
  1171. (!vlan_filters && f->vlan == 0)) {
  1172. /* Determine the new vlan we will be adding */
  1173. if (pvid)
  1174. new_vlan = pvid;
  1175. else if (vlan_filters)
  1176. new_vlan = 0;
  1177. else
  1178. new_vlan = I40E_VLAN_ANY;
  1179. /* Create the new filter */
  1180. add_head = i40e_add_filter(vsi, f->macaddr, new_vlan);
  1181. if (!add_head)
  1182. return -ENOMEM;
  1183. /* Create a temporary i40e_new_mac_filter */
  1184. new = kzalloc(sizeof(*new), GFP_ATOMIC);
  1185. if (!new)
  1186. return -ENOMEM;
  1187. new->f = add_head;
  1188. new->state = add_head->state;
  1189. /* Add the new filter to the tmp list */
  1190. hlist_add_head(&new->hlist, tmp_add_list);
  1191. /* Put the original filter into the delete list */
  1192. f->state = I40E_FILTER_REMOVE;
  1193. hash_del(&f->hlist);
  1194. hlist_add_head(&f->hlist, tmp_del_list);
  1195. }
  1196. }
  1197. vsi->has_vlan_filter = !!vlan_filters;
  1198. return 0;
  1199. }
  1200. /**
  1201. * i40e_rm_default_mac_filter - Remove the default MAC filter set by NVM
  1202. * @vsi: the PF Main VSI - inappropriate for any other VSI
  1203. * @macaddr: the MAC address
  1204. *
  1205. * Remove whatever filter the firmware set up so the driver can manage
  1206. * its own filtering intelligently.
  1207. **/
  1208. static void i40e_rm_default_mac_filter(struct i40e_vsi *vsi, u8 *macaddr)
  1209. {
  1210. struct i40e_aqc_remove_macvlan_element_data element;
  1211. struct i40e_pf *pf = vsi->back;
  1212. /* Only appropriate for the PF main VSI */
  1213. if (vsi->type != I40E_VSI_MAIN)
  1214. return;
  1215. memset(&element, 0, sizeof(element));
  1216. ether_addr_copy(element.mac_addr, macaddr);
  1217. element.vlan_tag = 0;
  1218. /* Ignore error returns, some firmware does it this way... */
  1219. element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  1220. i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
  1221. memset(&element, 0, sizeof(element));
  1222. ether_addr_copy(element.mac_addr, macaddr);
  1223. element.vlan_tag = 0;
  1224. /* ...and some firmware does it this way. */
  1225. element.flags = I40E_AQC_MACVLAN_DEL_PERFECT_MATCH |
  1226. I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
  1227. i40e_aq_remove_macvlan(&pf->hw, vsi->seid, &element, 1, NULL);
  1228. }
  1229. /**
  1230. * i40e_add_filter - Add a mac/vlan filter to the VSI
  1231. * @vsi: the VSI to be searched
  1232. * @macaddr: the MAC address
  1233. * @vlan: the vlan
  1234. *
  1235. * Returns ptr to the filter object or NULL when no memory available.
  1236. *
  1237. * NOTE: This function is expected to be called with mac_filter_hash_lock
  1238. * being held.
  1239. **/
  1240. struct i40e_mac_filter *i40e_add_filter(struct i40e_vsi *vsi,
  1241. const u8 *macaddr, s16 vlan)
  1242. {
  1243. struct i40e_mac_filter *f;
  1244. u64 key;
  1245. if (!vsi || !macaddr)
  1246. return NULL;
  1247. f = i40e_find_filter(vsi, macaddr, vlan);
  1248. if (!f) {
  1249. f = kzalloc(sizeof(*f), GFP_ATOMIC);
  1250. if (!f)
  1251. return NULL;
  1252. /* Update the boolean indicating if we need to function in
  1253. * VLAN mode.
  1254. */
  1255. if (vlan >= 0)
  1256. vsi->has_vlan_filter = true;
  1257. ether_addr_copy(f->macaddr, macaddr);
  1258. f->vlan = vlan;
  1259. /* If we're in overflow promisc mode, set the state directly
  1260. * to failed, so we don't bother to try sending the filter
  1261. * to the hardware.
  1262. */
  1263. if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state))
  1264. f->state = I40E_FILTER_FAILED;
  1265. else
  1266. f->state = I40E_FILTER_NEW;
  1267. INIT_HLIST_NODE(&f->hlist);
  1268. key = i40e_addr_to_hkey(macaddr);
  1269. hash_add(vsi->mac_filter_hash, &f->hlist, key);
  1270. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1271. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1272. }
  1273. /* If we're asked to add a filter that has been marked for removal, it
  1274. * is safe to simply restore it to active state. __i40e_del_filter
  1275. * will have simply deleted any filters which were previously marked
  1276. * NEW or FAILED, so if it is currently marked REMOVE it must have
  1277. * previously been ACTIVE. Since we haven't yet run the sync filters
  1278. * task, just restore this filter to the ACTIVE state so that the
  1279. * sync task leaves it in place
  1280. */
  1281. if (f->state == I40E_FILTER_REMOVE)
  1282. f->state = I40E_FILTER_ACTIVE;
  1283. return f;
  1284. }
  1285. /**
  1286. * __i40e_del_filter - Remove a specific filter from the VSI
  1287. * @vsi: VSI to remove from
  1288. * @f: the filter to remove from the list
  1289. *
  1290. * This function should be called instead of i40e_del_filter only if you know
  1291. * the exact filter you will remove already, such as via i40e_find_filter or
  1292. * i40e_find_mac.
  1293. *
  1294. * NOTE: This function is expected to be called with mac_filter_hash_lock
  1295. * being held.
  1296. * ANOTHER NOTE: This function MUST be called from within the context of
  1297. * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
  1298. * instead of list_for_each_entry().
  1299. **/
  1300. void __i40e_del_filter(struct i40e_vsi *vsi, struct i40e_mac_filter *f)
  1301. {
  1302. if (!f)
  1303. return;
  1304. /* If the filter was never added to firmware then we can just delete it
  1305. * directly and we don't want to set the status to remove or else an
  1306. * admin queue command will unnecessarily fire.
  1307. */
  1308. if ((f->state == I40E_FILTER_FAILED) ||
  1309. (f->state == I40E_FILTER_NEW)) {
  1310. hash_del(&f->hlist);
  1311. kfree(f);
  1312. } else {
  1313. f->state = I40E_FILTER_REMOVE;
  1314. }
  1315. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1316. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1317. }
  1318. /**
  1319. * i40e_del_filter - Remove a MAC/VLAN filter from the VSI
  1320. * @vsi: the VSI to be searched
  1321. * @macaddr: the MAC address
  1322. * @vlan: the VLAN
  1323. *
  1324. * NOTE: This function is expected to be called with mac_filter_hash_lock
  1325. * being held.
  1326. * ANOTHER NOTE: This function MUST be called from within the context of
  1327. * the "safe" variants of any list iterators, e.g. list_for_each_entry_safe()
  1328. * instead of list_for_each_entry().
  1329. **/
  1330. void i40e_del_filter(struct i40e_vsi *vsi, const u8 *macaddr, s16 vlan)
  1331. {
  1332. struct i40e_mac_filter *f;
  1333. if (!vsi || !macaddr)
  1334. return;
  1335. f = i40e_find_filter(vsi, macaddr, vlan);
  1336. __i40e_del_filter(vsi, f);
  1337. }
  1338. /**
  1339. * i40e_add_mac_filter - Add a MAC filter for all active VLANs
  1340. * @vsi: the VSI to be searched
  1341. * @macaddr: the mac address to be filtered
  1342. *
  1343. * If we're not in VLAN mode, just add the filter to I40E_VLAN_ANY. Otherwise,
  1344. * go through all the macvlan filters and add a macvlan filter for each
  1345. * unique vlan that already exists. If a PVID has been assigned, instead only
  1346. * add the macaddr to that VLAN.
  1347. *
  1348. * Returns last filter added on success, else NULL
  1349. **/
  1350. struct i40e_mac_filter *i40e_add_mac_filter(struct i40e_vsi *vsi,
  1351. const u8 *macaddr)
  1352. {
  1353. struct i40e_mac_filter *f, *add = NULL;
  1354. struct hlist_node *h;
  1355. int bkt;
  1356. if (vsi->info.pvid)
  1357. return i40e_add_filter(vsi, macaddr,
  1358. le16_to_cpu(vsi->info.pvid));
  1359. if (!i40e_is_vsi_in_vlan(vsi))
  1360. return i40e_add_filter(vsi, macaddr, I40E_VLAN_ANY);
  1361. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1362. if (f->state == I40E_FILTER_REMOVE)
  1363. continue;
  1364. add = i40e_add_filter(vsi, macaddr, f->vlan);
  1365. if (!add)
  1366. return NULL;
  1367. }
  1368. return add;
  1369. }
  1370. /**
  1371. * i40e_del_mac_filter - Remove a MAC filter from all VLANs
  1372. * @vsi: the VSI to be searched
  1373. * @macaddr: the mac address to be removed
  1374. *
  1375. * Removes a given MAC address from a VSI regardless of what VLAN it has been
  1376. * associated with.
  1377. *
  1378. * Returns 0 for success, or error
  1379. **/
  1380. int i40e_del_mac_filter(struct i40e_vsi *vsi, const u8 *macaddr)
  1381. {
  1382. struct i40e_mac_filter *f;
  1383. struct hlist_node *h;
  1384. bool found = false;
  1385. int bkt;
  1386. WARN(!spin_is_locked(&vsi->mac_filter_hash_lock),
  1387. "Missing mac_filter_hash_lock\n");
  1388. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1389. if (ether_addr_equal(macaddr, f->macaddr)) {
  1390. __i40e_del_filter(vsi, f);
  1391. found = true;
  1392. }
  1393. }
  1394. if (found)
  1395. return 0;
  1396. else
  1397. return -ENOENT;
  1398. }
  1399. /**
  1400. * i40e_set_mac - NDO callback to set mac address
  1401. * @netdev: network interface device structure
  1402. * @p: pointer to an address structure
  1403. *
  1404. * Returns 0 on success, negative on failure
  1405. **/
  1406. #ifdef I40E_FCOE
  1407. int i40e_set_mac(struct net_device *netdev, void *p)
  1408. #else
  1409. static int i40e_set_mac(struct net_device *netdev, void *p)
  1410. #endif
  1411. {
  1412. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1413. struct i40e_vsi *vsi = np->vsi;
  1414. struct i40e_pf *pf = vsi->back;
  1415. struct i40e_hw *hw = &pf->hw;
  1416. struct sockaddr *addr = p;
  1417. if (!is_valid_ether_addr(addr->sa_data))
  1418. return -EADDRNOTAVAIL;
  1419. if (ether_addr_equal(netdev->dev_addr, addr->sa_data)) {
  1420. netdev_info(netdev, "already using mac address %pM\n",
  1421. addr->sa_data);
  1422. return 0;
  1423. }
  1424. if (test_bit(__I40E_DOWN, &vsi->back->state) ||
  1425. test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
  1426. return -EADDRNOTAVAIL;
  1427. if (ether_addr_equal(hw->mac.addr, addr->sa_data))
  1428. netdev_info(netdev, "returning to hw mac address %pM\n",
  1429. hw->mac.addr);
  1430. else
  1431. netdev_info(netdev, "set new mac address %pM\n", addr->sa_data);
  1432. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1433. i40e_del_mac_filter(vsi, netdev->dev_addr);
  1434. i40e_add_mac_filter(vsi, addr->sa_data);
  1435. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1436. ether_addr_copy(netdev->dev_addr, addr->sa_data);
  1437. if (vsi->type == I40E_VSI_MAIN) {
  1438. i40e_status ret;
  1439. ret = i40e_aq_mac_address_write(&vsi->back->hw,
  1440. I40E_AQC_WRITE_TYPE_LAA_WOL,
  1441. addr->sa_data, NULL);
  1442. if (ret)
  1443. netdev_info(netdev, "Ignoring error from firmware on LAA update, status %s, AQ ret %s\n",
  1444. i40e_stat_str(hw, ret),
  1445. i40e_aq_str(hw, hw->aq.asq_last_status));
  1446. }
  1447. /* schedule our worker thread which will take care of
  1448. * applying the new filter changes
  1449. */
  1450. i40e_service_event_schedule(vsi->back);
  1451. return 0;
  1452. }
  1453. /**
  1454. * i40e_vsi_setup_queue_map - Setup a VSI queue map based on enabled_tc
  1455. * @vsi: the VSI being setup
  1456. * @ctxt: VSI context structure
  1457. * @enabled_tc: Enabled TCs bitmap
  1458. * @is_add: True if called before Add VSI
  1459. *
  1460. * Setup VSI queue mapping for enabled traffic classes.
  1461. **/
  1462. #ifdef I40E_FCOE
  1463. void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
  1464. struct i40e_vsi_context *ctxt,
  1465. u8 enabled_tc,
  1466. bool is_add)
  1467. #else
  1468. static void i40e_vsi_setup_queue_map(struct i40e_vsi *vsi,
  1469. struct i40e_vsi_context *ctxt,
  1470. u8 enabled_tc,
  1471. bool is_add)
  1472. #endif
  1473. {
  1474. struct i40e_pf *pf = vsi->back;
  1475. u16 sections = 0;
  1476. u8 netdev_tc = 0;
  1477. u16 numtc = 0;
  1478. u16 qcount;
  1479. u8 offset;
  1480. u16 qmap;
  1481. int i;
  1482. u16 num_tc_qps = 0;
  1483. sections = I40E_AQ_VSI_PROP_QUEUE_MAP_VALID;
  1484. offset = 0;
  1485. if (enabled_tc && (vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  1486. /* Find numtc from enabled TC bitmap */
  1487. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1488. if (enabled_tc & BIT(i)) /* TC is enabled */
  1489. numtc++;
  1490. }
  1491. if (!numtc) {
  1492. dev_warn(&pf->pdev->dev, "DCB is enabled but no TC enabled, forcing TC0\n");
  1493. numtc = 1;
  1494. }
  1495. } else {
  1496. /* At least TC0 is enabled in case of non-DCB case */
  1497. numtc = 1;
  1498. }
  1499. vsi->tc_config.numtc = numtc;
  1500. vsi->tc_config.enabled_tc = enabled_tc ? enabled_tc : 1;
  1501. /* Number of queues per enabled TC */
  1502. qcount = vsi->alloc_queue_pairs;
  1503. num_tc_qps = qcount / numtc;
  1504. num_tc_qps = min_t(int, num_tc_qps, i40e_pf_get_max_q_per_tc(pf));
  1505. /* Setup queue offset/count for all TCs for given VSI */
  1506. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  1507. /* See if the given TC is enabled for the given VSI */
  1508. if (vsi->tc_config.enabled_tc & BIT(i)) {
  1509. /* TC is enabled */
  1510. int pow, num_qps;
  1511. switch (vsi->type) {
  1512. case I40E_VSI_MAIN:
  1513. qcount = min_t(int, pf->alloc_rss_size,
  1514. num_tc_qps);
  1515. break;
  1516. #ifdef I40E_FCOE
  1517. case I40E_VSI_FCOE:
  1518. qcount = num_tc_qps;
  1519. break;
  1520. #endif
  1521. case I40E_VSI_FDIR:
  1522. case I40E_VSI_SRIOV:
  1523. case I40E_VSI_VMDQ2:
  1524. default:
  1525. qcount = num_tc_qps;
  1526. WARN_ON(i != 0);
  1527. break;
  1528. }
  1529. vsi->tc_config.tc_info[i].qoffset = offset;
  1530. vsi->tc_config.tc_info[i].qcount = qcount;
  1531. /* find the next higher power-of-2 of num queue pairs */
  1532. num_qps = qcount;
  1533. pow = 0;
  1534. while (num_qps && (BIT_ULL(pow) < qcount)) {
  1535. pow++;
  1536. num_qps >>= 1;
  1537. }
  1538. vsi->tc_config.tc_info[i].netdev_tc = netdev_tc++;
  1539. qmap =
  1540. (offset << I40E_AQ_VSI_TC_QUE_OFFSET_SHIFT) |
  1541. (pow << I40E_AQ_VSI_TC_QUE_NUMBER_SHIFT);
  1542. offset += qcount;
  1543. } else {
  1544. /* TC is not enabled so set the offset to
  1545. * default queue and allocate one queue
  1546. * for the given TC.
  1547. */
  1548. vsi->tc_config.tc_info[i].qoffset = 0;
  1549. vsi->tc_config.tc_info[i].qcount = 1;
  1550. vsi->tc_config.tc_info[i].netdev_tc = 0;
  1551. qmap = 0;
  1552. }
  1553. ctxt->info.tc_mapping[i] = cpu_to_le16(qmap);
  1554. }
  1555. /* Set actual Tx/Rx queue pairs */
  1556. vsi->num_queue_pairs = offset;
  1557. if ((vsi->type == I40E_VSI_MAIN) && (numtc == 1)) {
  1558. if (vsi->req_queue_pairs > 0)
  1559. vsi->num_queue_pairs = vsi->req_queue_pairs;
  1560. else if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  1561. vsi->num_queue_pairs = pf->num_lan_msix;
  1562. }
  1563. /* Scheduler section valid can only be set for ADD VSI */
  1564. if (is_add) {
  1565. sections |= I40E_AQ_VSI_PROP_SCHED_VALID;
  1566. ctxt->info.up_enable_bits = enabled_tc;
  1567. }
  1568. if (vsi->type == I40E_VSI_SRIOV) {
  1569. ctxt->info.mapping_flags |=
  1570. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_NONCONTIG);
  1571. for (i = 0; i < vsi->num_queue_pairs; i++)
  1572. ctxt->info.queue_mapping[i] =
  1573. cpu_to_le16(vsi->base_queue + i);
  1574. } else {
  1575. ctxt->info.mapping_flags |=
  1576. cpu_to_le16(I40E_AQ_VSI_QUE_MAP_CONTIG);
  1577. ctxt->info.queue_mapping[0] = cpu_to_le16(vsi->base_queue);
  1578. }
  1579. ctxt->info.valid_sections |= cpu_to_le16(sections);
  1580. }
  1581. /**
  1582. * i40e_addr_sync - Callback for dev_(mc|uc)_sync to add address
  1583. * @netdev: the netdevice
  1584. * @addr: address to add
  1585. *
  1586. * Called by __dev_(mc|uc)_sync when an address needs to be added. We call
  1587. * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
  1588. */
  1589. static int i40e_addr_sync(struct net_device *netdev, const u8 *addr)
  1590. {
  1591. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1592. struct i40e_vsi *vsi = np->vsi;
  1593. if (i40e_add_mac_filter(vsi, addr))
  1594. return 0;
  1595. else
  1596. return -ENOMEM;
  1597. }
  1598. /**
  1599. * i40e_addr_unsync - Callback for dev_(mc|uc)_sync to remove address
  1600. * @netdev: the netdevice
  1601. * @addr: address to add
  1602. *
  1603. * Called by __dev_(mc|uc)_sync when an address needs to be removed. We call
  1604. * __dev_(uc|mc)_sync from .set_rx_mode and guarantee to hold the hash lock.
  1605. */
  1606. static int i40e_addr_unsync(struct net_device *netdev, const u8 *addr)
  1607. {
  1608. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1609. struct i40e_vsi *vsi = np->vsi;
  1610. i40e_del_mac_filter(vsi, addr);
  1611. return 0;
  1612. }
  1613. /**
  1614. * i40e_set_rx_mode - NDO callback to set the netdev filters
  1615. * @netdev: network interface device structure
  1616. **/
  1617. #ifdef I40E_FCOE
  1618. void i40e_set_rx_mode(struct net_device *netdev)
  1619. #else
  1620. static void i40e_set_rx_mode(struct net_device *netdev)
  1621. #endif
  1622. {
  1623. struct i40e_netdev_priv *np = netdev_priv(netdev);
  1624. struct i40e_vsi *vsi = np->vsi;
  1625. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1626. __dev_uc_sync(netdev, i40e_addr_sync, i40e_addr_unsync);
  1627. __dev_mc_sync(netdev, i40e_addr_sync, i40e_addr_unsync);
  1628. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1629. /* check for other flag changes */
  1630. if (vsi->current_netdev_flags != vsi->netdev->flags) {
  1631. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  1632. vsi->back->flags |= I40E_FLAG_FILTER_SYNC;
  1633. }
  1634. /* schedule our worker thread which will take care of
  1635. * applying the new filter changes
  1636. */
  1637. i40e_service_event_schedule(vsi->back);
  1638. }
  1639. /**
  1640. * i40e_undo_del_filter_entries - Undo the changes made to MAC filter entries
  1641. * @vsi: Pointer to VSI struct
  1642. * @from: Pointer to list which contains MAC filter entries - changes to
  1643. * those entries needs to be undone.
  1644. *
  1645. * MAC filter entries from this list were slated for deletion.
  1646. **/
  1647. static void i40e_undo_del_filter_entries(struct i40e_vsi *vsi,
  1648. struct hlist_head *from)
  1649. {
  1650. struct i40e_mac_filter *f;
  1651. struct hlist_node *h;
  1652. hlist_for_each_entry_safe(f, h, from, hlist) {
  1653. u64 key = i40e_addr_to_hkey(f->macaddr);
  1654. /* Move the element back into MAC filter list*/
  1655. hlist_del(&f->hlist);
  1656. hash_add(vsi->mac_filter_hash, &f->hlist, key);
  1657. }
  1658. }
  1659. /**
  1660. * i40e_undo_add_filter_entries - Undo the changes made to MAC filter entries
  1661. * @vsi: Pointer to vsi struct
  1662. * @from: Pointer to list which contains MAC filter entries - changes to
  1663. * those entries needs to be undone.
  1664. *
  1665. * MAC filter entries from this list were slated for addition.
  1666. **/
  1667. static void i40e_undo_add_filter_entries(struct i40e_vsi *vsi,
  1668. struct hlist_head *from)
  1669. {
  1670. struct i40e_new_mac_filter *new;
  1671. struct hlist_node *h;
  1672. hlist_for_each_entry_safe(new, h, from, hlist) {
  1673. /* We can simply free the wrapper structure */
  1674. hlist_del(&new->hlist);
  1675. kfree(new);
  1676. }
  1677. }
  1678. /**
  1679. * i40e_next_entry - Get the next non-broadcast filter from a list
  1680. * @next: pointer to filter in list
  1681. *
  1682. * Returns the next non-broadcast filter in the list. Required so that we
  1683. * ignore broadcast filters within the list, since these are not handled via
  1684. * the normal firmware update path.
  1685. */
  1686. static
  1687. struct i40e_new_mac_filter *i40e_next_filter(struct i40e_new_mac_filter *next)
  1688. {
  1689. while (next) {
  1690. next = hlist_entry(next->hlist.next,
  1691. typeof(struct i40e_new_mac_filter),
  1692. hlist);
  1693. /* keep going if we found a broadcast filter */
  1694. if (next && is_broadcast_ether_addr(next->f->macaddr))
  1695. continue;
  1696. break;
  1697. }
  1698. return next;
  1699. }
  1700. /**
  1701. * i40e_update_filter_state - Update filter state based on return data
  1702. * from firmware
  1703. * @count: Number of filters added
  1704. * @add_list: return data from fw
  1705. * @head: pointer to first filter in current batch
  1706. *
  1707. * MAC filter entries from list were slated to be added to device. Returns
  1708. * number of successful filters. Note that 0 does NOT mean success!
  1709. **/
  1710. static int
  1711. i40e_update_filter_state(int count,
  1712. struct i40e_aqc_add_macvlan_element_data *add_list,
  1713. struct i40e_new_mac_filter *add_head)
  1714. {
  1715. int retval = 0;
  1716. int i;
  1717. for (i = 0; i < count; i++) {
  1718. /* Always check status of each filter. We don't need to check
  1719. * the firmware return status because we pre-set the filter
  1720. * status to I40E_AQC_MM_ERR_NO_RES when sending the filter
  1721. * request to the adminq. Thus, if it no longer matches then
  1722. * we know the filter is active.
  1723. */
  1724. if (add_list[i].match_method == I40E_AQC_MM_ERR_NO_RES) {
  1725. add_head->state = I40E_FILTER_FAILED;
  1726. } else {
  1727. add_head->state = I40E_FILTER_ACTIVE;
  1728. retval++;
  1729. }
  1730. add_head = i40e_next_filter(add_head);
  1731. if (!add_head)
  1732. break;
  1733. }
  1734. return retval;
  1735. }
  1736. /**
  1737. * i40e_aqc_del_filters - Request firmware to delete a set of filters
  1738. * @vsi: ptr to the VSI
  1739. * @vsi_name: name to display in messages
  1740. * @list: the list of filters to send to firmware
  1741. * @num_del: the number of filters to delete
  1742. * @retval: Set to -EIO on failure to delete
  1743. *
  1744. * Send a request to firmware via AdminQ to delete a set of filters. Uses
  1745. * *retval instead of a return value so that success does not force ret_val to
  1746. * be set to 0. This ensures that a sequence of calls to this function
  1747. * preserve the previous value of *retval on successful delete.
  1748. */
  1749. static
  1750. void i40e_aqc_del_filters(struct i40e_vsi *vsi, const char *vsi_name,
  1751. struct i40e_aqc_remove_macvlan_element_data *list,
  1752. int num_del, int *retval)
  1753. {
  1754. struct i40e_hw *hw = &vsi->back->hw;
  1755. i40e_status aq_ret;
  1756. int aq_err;
  1757. aq_ret = i40e_aq_remove_macvlan(hw, vsi->seid, list, num_del, NULL);
  1758. aq_err = hw->aq.asq_last_status;
  1759. /* Explicitly ignore and do not report when firmware returns ENOENT */
  1760. if (aq_ret && !(aq_err == I40E_AQ_RC_ENOENT)) {
  1761. *retval = -EIO;
  1762. dev_info(&vsi->back->pdev->dev,
  1763. "ignoring delete macvlan error on %s, err %s, aq_err %s\n",
  1764. vsi_name, i40e_stat_str(hw, aq_ret),
  1765. i40e_aq_str(hw, aq_err));
  1766. }
  1767. }
  1768. /**
  1769. * i40e_aqc_add_filters - Request firmware to add a set of filters
  1770. * @vsi: ptr to the VSI
  1771. * @vsi_name: name to display in messages
  1772. * @list: the list of filters to send to firmware
  1773. * @add_head: Position in the add hlist
  1774. * @num_add: the number of filters to add
  1775. * @promisc_change: set to true on exit if promiscuous mode was forced on
  1776. *
  1777. * Send a request to firmware via AdminQ to add a chunk of filters. Will set
  1778. * promisc_changed to true if the firmware has run out of space for more
  1779. * filters.
  1780. */
  1781. static
  1782. void i40e_aqc_add_filters(struct i40e_vsi *vsi, const char *vsi_name,
  1783. struct i40e_aqc_add_macvlan_element_data *list,
  1784. struct i40e_new_mac_filter *add_head,
  1785. int num_add, bool *promisc_changed)
  1786. {
  1787. struct i40e_hw *hw = &vsi->back->hw;
  1788. int aq_err, fcnt;
  1789. i40e_aq_add_macvlan(hw, vsi->seid, list, num_add, NULL);
  1790. aq_err = hw->aq.asq_last_status;
  1791. fcnt = i40e_update_filter_state(num_add, list, add_head);
  1792. if (fcnt != num_add) {
  1793. *promisc_changed = true;
  1794. set_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state);
  1795. dev_warn(&vsi->back->pdev->dev,
  1796. "Error %s adding RX filters on %s, promiscuous mode forced on\n",
  1797. i40e_aq_str(hw, aq_err),
  1798. vsi_name);
  1799. }
  1800. }
  1801. /**
  1802. * i40e_aqc_broadcast_filter - Set promiscuous broadcast flags
  1803. * @vsi: pointer to the VSI
  1804. * @f: filter data
  1805. *
  1806. * This function sets or clears the promiscuous broadcast flags for VLAN
  1807. * filters in order to properly receive broadcast frames. Assumes that only
  1808. * broadcast filters are passed.
  1809. *
  1810. * Returns status indicating success or failure;
  1811. **/
  1812. static i40e_status
  1813. i40e_aqc_broadcast_filter(struct i40e_vsi *vsi, const char *vsi_name,
  1814. struct i40e_mac_filter *f)
  1815. {
  1816. bool enable = f->state == I40E_FILTER_NEW;
  1817. struct i40e_hw *hw = &vsi->back->hw;
  1818. i40e_status aq_ret;
  1819. if (f->vlan == I40E_VLAN_ANY) {
  1820. aq_ret = i40e_aq_set_vsi_broadcast(hw,
  1821. vsi->seid,
  1822. enable,
  1823. NULL);
  1824. } else {
  1825. aq_ret = i40e_aq_set_vsi_bc_promisc_on_vlan(hw,
  1826. vsi->seid,
  1827. enable,
  1828. f->vlan,
  1829. NULL);
  1830. }
  1831. if (aq_ret)
  1832. dev_warn(&vsi->back->pdev->dev,
  1833. "Error %s setting broadcast promiscuous mode on %s\n",
  1834. i40e_aq_str(hw, hw->aq.asq_last_status),
  1835. vsi_name);
  1836. return aq_ret;
  1837. }
  1838. /**
  1839. * i40e_sync_vsi_filters - Update the VSI filter list to the HW
  1840. * @vsi: ptr to the VSI
  1841. *
  1842. * Push any outstanding VSI filter changes through the AdminQ.
  1843. *
  1844. * Returns 0 or error value
  1845. **/
  1846. int i40e_sync_vsi_filters(struct i40e_vsi *vsi)
  1847. {
  1848. struct hlist_head tmp_add_list, tmp_del_list;
  1849. struct i40e_mac_filter *f;
  1850. struct i40e_new_mac_filter *new, *add_head = NULL;
  1851. struct i40e_hw *hw = &vsi->back->hw;
  1852. unsigned int failed_filters = 0;
  1853. unsigned int vlan_filters = 0;
  1854. bool promisc_changed = false;
  1855. char vsi_name[16] = "PF";
  1856. int filter_list_len = 0;
  1857. i40e_status aq_ret = 0;
  1858. u32 changed_flags = 0;
  1859. struct hlist_node *h;
  1860. struct i40e_pf *pf;
  1861. int num_add = 0;
  1862. int num_del = 0;
  1863. int retval = 0;
  1864. u16 cmd_flags;
  1865. int list_size;
  1866. int bkt;
  1867. /* empty array typed pointers, kcalloc later */
  1868. struct i40e_aqc_add_macvlan_element_data *add_list;
  1869. struct i40e_aqc_remove_macvlan_element_data *del_list;
  1870. while (test_and_set_bit(__I40E_CONFIG_BUSY, &vsi->state))
  1871. usleep_range(1000, 2000);
  1872. pf = vsi->back;
  1873. if (vsi->netdev) {
  1874. changed_flags = vsi->current_netdev_flags ^ vsi->netdev->flags;
  1875. vsi->current_netdev_flags = vsi->netdev->flags;
  1876. }
  1877. INIT_HLIST_HEAD(&tmp_add_list);
  1878. INIT_HLIST_HEAD(&tmp_del_list);
  1879. if (vsi->type == I40E_VSI_SRIOV)
  1880. snprintf(vsi_name, sizeof(vsi_name) - 1, "VF %d", vsi->vf_id);
  1881. else if (vsi->type != I40E_VSI_MAIN)
  1882. snprintf(vsi_name, sizeof(vsi_name) - 1, "vsi %d", vsi->seid);
  1883. if (vsi->flags & I40E_VSI_FLAG_FILTER_CHANGED) {
  1884. vsi->flags &= ~I40E_VSI_FLAG_FILTER_CHANGED;
  1885. spin_lock_bh(&vsi->mac_filter_hash_lock);
  1886. /* Create a list of filters to delete. */
  1887. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  1888. if (f->state == I40E_FILTER_REMOVE) {
  1889. /* Move the element into temporary del_list */
  1890. hash_del(&f->hlist);
  1891. hlist_add_head(&f->hlist, &tmp_del_list);
  1892. /* Avoid counting removed filters */
  1893. continue;
  1894. }
  1895. if (f->state == I40E_FILTER_NEW) {
  1896. /* Create a temporary i40e_new_mac_filter */
  1897. new = kzalloc(sizeof(*new), GFP_ATOMIC);
  1898. if (!new)
  1899. goto err_no_memory_locked;
  1900. /* Store pointer to the real filter */
  1901. new->f = f;
  1902. new->state = f->state;
  1903. /* Add it to the hash list */
  1904. hlist_add_head(&new->hlist, &tmp_add_list);
  1905. }
  1906. /* Count the number of active (current and new) VLAN
  1907. * filters we have now. Does not count filters which
  1908. * are marked for deletion.
  1909. */
  1910. if (f->vlan > 0)
  1911. vlan_filters++;
  1912. }
  1913. retval = i40e_correct_mac_vlan_filters(vsi,
  1914. &tmp_add_list,
  1915. &tmp_del_list,
  1916. vlan_filters);
  1917. if (retval)
  1918. goto err_no_memory_locked;
  1919. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  1920. }
  1921. /* Now process 'del_list' outside the lock */
  1922. if (!hlist_empty(&tmp_del_list)) {
  1923. filter_list_len = hw->aq.asq_buf_size /
  1924. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  1925. list_size = filter_list_len *
  1926. sizeof(struct i40e_aqc_remove_macvlan_element_data);
  1927. del_list = kzalloc(list_size, GFP_ATOMIC);
  1928. if (!del_list)
  1929. goto err_no_memory;
  1930. hlist_for_each_entry_safe(f, h, &tmp_del_list, hlist) {
  1931. cmd_flags = 0;
  1932. /* handle broadcast filters by updating the broadcast
  1933. * promiscuous flag and release filter list.
  1934. */
  1935. if (is_broadcast_ether_addr(f->macaddr)) {
  1936. i40e_aqc_broadcast_filter(vsi, vsi_name, f);
  1937. hlist_del(&f->hlist);
  1938. kfree(f);
  1939. continue;
  1940. }
  1941. /* add to delete list */
  1942. ether_addr_copy(del_list[num_del].mac_addr, f->macaddr);
  1943. if (f->vlan == I40E_VLAN_ANY) {
  1944. del_list[num_del].vlan_tag = 0;
  1945. cmd_flags |= I40E_AQC_MACVLAN_DEL_IGNORE_VLAN;
  1946. } else {
  1947. del_list[num_del].vlan_tag =
  1948. cpu_to_le16((u16)(f->vlan));
  1949. }
  1950. cmd_flags |= I40E_AQC_MACVLAN_DEL_PERFECT_MATCH;
  1951. del_list[num_del].flags = cmd_flags;
  1952. num_del++;
  1953. /* flush a full buffer */
  1954. if (num_del == filter_list_len) {
  1955. i40e_aqc_del_filters(vsi, vsi_name, del_list,
  1956. num_del, &retval);
  1957. memset(del_list, 0, list_size);
  1958. num_del = 0;
  1959. }
  1960. /* Release memory for MAC filter entries which were
  1961. * synced up with HW.
  1962. */
  1963. hlist_del(&f->hlist);
  1964. kfree(f);
  1965. }
  1966. if (num_del) {
  1967. i40e_aqc_del_filters(vsi, vsi_name, del_list,
  1968. num_del, &retval);
  1969. }
  1970. kfree(del_list);
  1971. del_list = NULL;
  1972. }
  1973. if (!hlist_empty(&tmp_add_list)) {
  1974. /* Do all the adds now. */
  1975. filter_list_len = hw->aq.asq_buf_size /
  1976. sizeof(struct i40e_aqc_add_macvlan_element_data);
  1977. list_size = filter_list_len *
  1978. sizeof(struct i40e_aqc_add_macvlan_element_data);
  1979. add_list = kzalloc(list_size, GFP_ATOMIC);
  1980. if (!add_list)
  1981. goto err_no_memory;
  1982. num_add = 0;
  1983. hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) {
  1984. if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  1985. &vsi->state)) {
  1986. new->state = I40E_FILTER_FAILED;
  1987. continue;
  1988. }
  1989. /* handle broadcast filters by updating the broadcast
  1990. * promiscuous flag instead of adding a MAC filter.
  1991. */
  1992. if (is_broadcast_ether_addr(new->f->macaddr)) {
  1993. if (i40e_aqc_broadcast_filter(vsi, vsi_name,
  1994. new->f))
  1995. new->state = I40E_FILTER_FAILED;
  1996. else
  1997. new->state = I40E_FILTER_ACTIVE;
  1998. continue;
  1999. }
  2000. /* add to add array */
  2001. if (num_add == 0)
  2002. add_head = new;
  2003. cmd_flags = 0;
  2004. ether_addr_copy(add_list[num_add].mac_addr,
  2005. new->f->macaddr);
  2006. if (new->f->vlan == I40E_VLAN_ANY) {
  2007. add_list[num_add].vlan_tag = 0;
  2008. cmd_flags |= I40E_AQC_MACVLAN_ADD_IGNORE_VLAN;
  2009. } else {
  2010. add_list[num_add].vlan_tag =
  2011. cpu_to_le16((u16)(new->f->vlan));
  2012. }
  2013. add_list[num_add].queue_number = 0;
  2014. /* set invalid match method for later detection */
  2015. add_list[num_add].match_method = I40E_AQC_MM_ERR_NO_RES;
  2016. cmd_flags |= I40E_AQC_MACVLAN_ADD_PERFECT_MATCH;
  2017. add_list[num_add].flags = cpu_to_le16(cmd_flags);
  2018. num_add++;
  2019. /* flush a full buffer */
  2020. if (num_add == filter_list_len) {
  2021. i40e_aqc_add_filters(vsi, vsi_name, add_list,
  2022. add_head, num_add,
  2023. &promisc_changed);
  2024. memset(add_list, 0, list_size);
  2025. num_add = 0;
  2026. }
  2027. }
  2028. if (num_add) {
  2029. i40e_aqc_add_filters(vsi, vsi_name, add_list, add_head,
  2030. num_add, &promisc_changed);
  2031. }
  2032. /* Now move all of the filters from the temp add list back to
  2033. * the VSI's list.
  2034. */
  2035. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2036. hlist_for_each_entry_safe(new, h, &tmp_add_list, hlist) {
  2037. /* Only update the state if we're still NEW */
  2038. if (new->f->state == I40E_FILTER_NEW)
  2039. new->f->state = new->state;
  2040. hlist_del(&new->hlist);
  2041. kfree(new);
  2042. }
  2043. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2044. kfree(add_list);
  2045. add_list = NULL;
  2046. }
  2047. /* Determine the number of active and failed filters. */
  2048. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2049. vsi->active_filters = 0;
  2050. hash_for_each(vsi->mac_filter_hash, bkt, f, hlist) {
  2051. if (f->state == I40E_FILTER_ACTIVE)
  2052. vsi->active_filters++;
  2053. else if (f->state == I40E_FILTER_FAILED)
  2054. failed_filters++;
  2055. }
  2056. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2057. /* If promiscuous mode has changed, we need to calculate a new
  2058. * threshold for when we are safe to exit
  2059. */
  2060. if (promisc_changed)
  2061. vsi->promisc_threshold = (vsi->active_filters * 3) / 4;
  2062. /* Check if we are able to exit overflow promiscuous mode. We can
  2063. * safely exit if we didn't just enter, we no longer have any failed
  2064. * filters, and we have reduced filters below the threshold value.
  2065. */
  2066. if (test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state) &&
  2067. !promisc_changed && !failed_filters &&
  2068. (vsi->active_filters < vsi->promisc_threshold)) {
  2069. dev_info(&pf->pdev->dev,
  2070. "filter logjam cleared on %s, leaving overflow promiscuous mode\n",
  2071. vsi_name);
  2072. clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state);
  2073. promisc_changed = true;
  2074. vsi->promisc_threshold = 0;
  2075. }
  2076. /* if the VF is not trusted do not do promisc */
  2077. if ((vsi->type == I40E_VSI_SRIOV) && !pf->vf[vsi->vf_id].trusted) {
  2078. clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state);
  2079. goto out;
  2080. }
  2081. /* check for changes in promiscuous modes */
  2082. if (changed_flags & IFF_ALLMULTI) {
  2083. bool cur_multipromisc;
  2084. cur_multipromisc = !!(vsi->current_netdev_flags & IFF_ALLMULTI);
  2085. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(&vsi->back->hw,
  2086. vsi->seid,
  2087. cur_multipromisc,
  2088. NULL);
  2089. if (aq_ret) {
  2090. retval = i40e_aq_rc_to_posix(aq_ret,
  2091. hw->aq.asq_last_status);
  2092. dev_info(&pf->pdev->dev,
  2093. "set multi promisc failed on %s, err %s aq_err %s\n",
  2094. vsi_name,
  2095. i40e_stat_str(hw, aq_ret),
  2096. i40e_aq_str(hw, hw->aq.asq_last_status));
  2097. }
  2098. }
  2099. if ((changed_flags & IFF_PROMISC) ||
  2100. (promisc_changed &&
  2101. test_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state))) {
  2102. bool cur_promisc;
  2103. cur_promisc = (!!(vsi->current_netdev_flags & IFF_PROMISC) ||
  2104. test_bit(__I40E_FILTER_OVERFLOW_PROMISC,
  2105. &vsi->state));
  2106. if ((vsi->type == I40E_VSI_MAIN) &&
  2107. (pf->lan_veb != I40E_NO_VEB) &&
  2108. !(pf->flags & I40E_FLAG_MFP_ENABLED)) {
  2109. /* set defport ON for Main VSI instead of true promisc
  2110. * this way we will get all unicast/multicast and VLAN
  2111. * promisc behavior but will not get VF or VMDq traffic
  2112. * replicated on the Main VSI.
  2113. */
  2114. if (pf->cur_promisc != cur_promisc) {
  2115. pf->cur_promisc = cur_promisc;
  2116. if (cur_promisc)
  2117. aq_ret =
  2118. i40e_aq_set_default_vsi(hw,
  2119. vsi->seid,
  2120. NULL);
  2121. else
  2122. aq_ret =
  2123. i40e_aq_clear_default_vsi(hw,
  2124. vsi->seid,
  2125. NULL);
  2126. if (aq_ret) {
  2127. retval = i40e_aq_rc_to_posix(aq_ret,
  2128. hw->aq.asq_last_status);
  2129. dev_info(&pf->pdev->dev,
  2130. "Set default VSI failed on %s, err %s, aq_err %s\n",
  2131. vsi_name,
  2132. i40e_stat_str(hw, aq_ret),
  2133. i40e_aq_str(hw,
  2134. hw->aq.asq_last_status));
  2135. }
  2136. }
  2137. } else {
  2138. aq_ret = i40e_aq_set_vsi_unicast_promiscuous(
  2139. hw,
  2140. vsi->seid,
  2141. cur_promisc, NULL,
  2142. true);
  2143. if (aq_ret) {
  2144. retval =
  2145. i40e_aq_rc_to_posix(aq_ret,
  2146. hw->aq.asq_last_status);
  2147. dev_info(&pf->pdev->dev,
  2148. "set unicast promisc failed on %s, err %s, aq_err %s\n",
  2149. vsi_name,
  2150. i40e_stat_str(hw, aq_ret),
  2151. i40e_aq_str(hw,
  2152. hw->aq.asq_last_status));
  2153. }
  2154. aq_ret = i40e_aq_set_vsi_multicast_promiscuous(
  2155. hw,
  2156. vsi->seid,
  2157. cur_promisc, NULL);
  2158. if (aq_ret) {
  2159. retval =
  2160. i40e_aq_rc_to_posix(aq_ret,
  2161. hw->aq.asq_last_status);
  2162. dev_info(&pf->pdev->dev,
  2163. "set multicast promisc failed on %s, err %s, aq_err %s\n",
  2164. vsi_name,
  2165. i40e_stat_str(hw, aq_ret),
  2166. i40e_aq_str(hw,
  2167. hw->aq.asq_last_status));
  2168. }
  2169. }
  2170. aq_ret = i40e_aq_set_vsi_broadcast(&vsi->back->hw,
  2171. vsi->seid,
  2172. cur_promisc, NULL);
  2173. if (aq_ret) {
  2174. retval = i40e_aq_rc_to_posix(aq_ret,
  2175. pf->hw.aq.asq_last_status);
  2176. dev_info(&pf->pdev->dev,
  2177. "set brdcast promisc failed, err %s, aq_err %s\n",
  2178. i40e_stat_str(hw, aq_ret),
  2179. i40e_aq_str(hw,
  2180. hw->aq.asq_last_status));
  2181. }
  2182. }
  2183. out:
  2184. /* if something went wrong then set the changed flag so we try again */
  2185. if (retval)
  2186. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  2187. clear_bit(__I40E_CONFIG_BUSY, &vsi->state);
  2188. return retval;
  2189. err_no_memory:
  2190. /* Restore elements on the temporary add and delete lists */
  2191. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2192. err_no_memory_locked:
  2193. i40e_undo_del_filter_entries(vsi, &tmp_del_list);
  2194. i40e_undo_add_filter_entries(vsi, &tmp_add_list);
  2195. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2196. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  2197. clear_bit(__I40E_CONFIG_BUSY, &vsi->state);
  2198. return -ENOMEM;
  2199. }
  2200. /**
  2201. * i40e_sync_filters_subtask - Sync the VSI filter list with HW
  2202. * @pf: board private structure
  2203. **/
  2204. static void i40e_sync_filters_subtask(struct i40e_pf *pf)
  2205. {
  2206. int v;
  2207. if (!pf || !(pf->flags & I40E_FLAG_FILTER_SYNC))
  2208. return;
  2209. pf->flags &= ~I40E_FLAG_FILTER_SYNC;
  2210. for (v = 0; v < pf->num_alloc_vsi; v++) {
  2211. if (pf->vsi[v] &&
  2212. (pf->vsi[v]->flags & I40E_VSI_FLAG_FILTER_CHANGED)) {
  2213. int ret = i40e_sync_vsi_filters(pf->vsi[v]);
  2214. if (ret) {
  2215. /* come back and try again later */
  2216. pf->flags |= I40E_FLAG_FILTER_SYNC;
  2217. break;
  2218. }
  2219. }
  2220. }
  2221. }
  2222. /**
  2223. * i40e_change_mtu - NDO callback to change the Maximum Transfer Unit
  2224. * @netdev: network interface device structure
  2225. * @new_mtu: new value for maximum frame size
  2226. *
  2227. * Returns 0 on success, negative on failure
  2228. **/
  2229. static int i40e_change_mtu(struct net_device *netdev, int new_mtu)
  2230. {
  2231. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2232. struct i40e_vsi *vsi = np->vsi;
  2233. struct i40e_pf *pf = vsi->back;
  2234. netdev_info(netdev, "changing MTU from %d to %d\n",
  2235. netdev->mtu, new_mtu);
  2236. netdev->mtu = new_mtu;
  2237. if (netif_running(netdev))
  2238. i40e_vsi_reinit_locked(vsi);
  2239. pf->flags |= (I40E_FLAG_SERVICE_CLIENT_REQUESTED |
  2240. I40E_FLAG_CLIENT_L2_CHANGE);
  2241. return 0;
  2242. }
  2243. /**
  2244. * i40e_ioctl - Access the hwtstamp interface
  2245. * @netdev: network interface device structure
  2246. * @ifr: interface request data
  2247. * @cmd: ioctl command
  2248. **/
  2249. int i40e_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  2250. {
  2251. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2252. struct i40e_pf *pf = np->vsi->back;
  2253. switch (cmd) {
  2254. case SIOCGHWTSTAMP:
  2255. return i40e_ptp_get_ts_config(pf, ifr);
  2256. case SIOCSHWTSTAMP:
  2257. return i40e_ptp_set_ts_config(pf, ifr);
  2258. default:
  2259. return -EOPNOTSUPP;
  2260. }
  2261. }
  2262. /**
  2263. * i40e_vlan_stripping_enable - Turn on vlan stripping for the VSI
  2264. * @vsi: the vsi being adjusted
  2265. **/
  2266. void i40e_vlan_stripping_enable(struct i40e_vsi *vsi)
  2267. {
  2268. struct i40e_vsi_context ctxt;
  2269. i40e_status ret;
  2270. if ((vsi->info.valid_sections &
  2271. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  2272. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_MODE_MASK) == 0))
  2273. return; /* already enabled */
  2274. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2275. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  2276. I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH;
  2277. ctxt.seid = vsi->seid;
  2278. ctxt.info = vsi->info;
  2279. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2280. if (ret) {
  2281. dev_info(&vsi->back->pdev->dev,
  2282. "update vlan stripping failed, err %s aq_err %s\n",
  2283. i40e_stat_str(&vsi->back->hw, ret),
  2284. i40e_aq_str(&vsi->back->hw,
  2285. vsi->back->hw.aq.asq_last_status));
  2286. }
  2287. }
  2288. /**
  2289. * i40e_vlan_stripping_disable - Turn off vlan stripping for the VSI
  2290. * @vsi: the vsi being adjusted
  2291. **/
  2292. void i40e_vlan_stripping_disable(struct i40e_vsi *vsi)
  2293. {
  2294. struct i40e_vsi_context ctxt;
  2295. i40e_status ret;
  2296. if ((vsi->info.valid_sections &
  2297. cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID)) &&
  2298. ((vsi->info.port_vlan_flags & I40E_AQ_VSI_PVLAN_EMOD_MASK) ==
  2299. I40E_AQ_VSI_PVLAN_EMOD_MASK))
  2300. return; /* already disabled */
  2301. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2302. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_ALL |
  2303. I40E_AQ_VSI_PVLAN_EMOD_NOTHING;
  2304. ctxt.seid = vsi->seid;
  2305. ctxt.info = vsi->info;
  2306. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2307. if (ret) {
  2308. dev_info(&vsi->back->pdev->dev,
  2309. "update vlan stripping failed, err %s aq_err %s\n",
  2310. i40e_stat_str(&vsi->back->hw, ret),
  2311. i40e_aq_str(&vsi->back->hw,
  2312. vsi->back->hw.aq.asq_last_status));
  2313. }
  2314. }
  2315. /**
  2316. * i40e_vlan_rx_register - Setup or shutdown vlan offload
  2317. * @netdev: network interface to be adjusted
  2318. * @features: netdev features to test if VLAN offload is enabled or not
  2319. **/
  2320. static void i40e_vlan_rx_register(struct net_device *netdev, u32 features)
  2321. {
  2322. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2323. struct i40e_vsi *vsi = np->vsi;
  2324. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  2325. i40e_vlan_stripping_enable(vsi);
  2326. else
  2327. i40e_vlan_stripping_disable(vsi);
  2328. }
  2329. /**
  2330. * i40e_add_vlan_all_mac - Add a MAC/VLAN filter for each existing MAC address
  2331. * @vsi: the vsi being configured
  2332. * @vid: vlan id to be added (0 = untagged only , -1 = any)
  2333. *
  2334. * This is a helper function for adding a new MAC/VLAN filter with the
  2335. * specified VLAN for each existing MAC address already in the hash table.
  2336. * This function does *not* perform any accounting to update filters based on
  2337. * VLAN mode.
  2338. *
  2339. * NOTE: this function expects to be called while under the
  2340. * mac_filter_hash_lock
  2341. **/
  2342. int i40e_add_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
  2343. {
  2344. struct i40e_mac_filter *f, *add_f;
  2345. struct hlist_node *h;
  2346. int bkt;
  2347. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  2348. if (f->state == I40E_FILTER_REMOVE)
  2349. continue;
  2350. add_f = i40e_add_filter(vsi, f->macaddr, vid);
  2351. if (!add_f) {
  2352. dev_info(&vsi->back->pdev->dev,
  2353. "Could not add vlan filter %d for %pM\n",
  2354. vid, f->macaddr);
  2355. return -ENOMEM;
  2356. }
  2357. }
  2358. return 0;
  2359. }
  2360. /**
  2361. * i40e_vsi_add_vlan - Add VSI membership for given VLAN
  2362. * @vsi: the VSI being configured
  2363. * @vid: VLAN id to be added
  2364. **/
  2365. int i40e_vsi_add_vlan(struct i40e_vsi *vsi, u16 vid)
  2366. {
  2367. int err;
  2368. if (!vid || vsi->info.pvid)
  2369. return -EINVAL;
  2370. /* Locked once because all functions invoked below iterates list*/
  2371. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2372. err = i40e_add_vlan_all_mac(vsi, vid);
  2373. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2374. if (err)
  2375. return err;
  2376. /* schedule our worker thread which will take care of
  2377. * applying the new filter changes
  2378. */
  2379. i40e_service_event_schedule(vsi->back);
  2380. return 0;
  2381. }
  2382. /**
  2383. * i40e_rm_vlan_all_mac - Remove MAC/VLAN pair for all MAC with the given VLAN
  2384. * @vsi: the vsi being configured
  2385. * @vid: vlan id to be removed (0 = untagged only , -1 = any)
  2386. *
  2387. * This function should be used to remove all VLAN filters which match the
  2388. * given VID. It does not schedule the service event and does not take the
  2389. * mac_filter_hash_lock so it may be combined with other operations under
  2390. * a single invocation of the mac_filter_hash_lock.
  2391. *
  2392. * NOTE: this function expects to be called while under the
  2393. * mac_filter_hash_lock
  2394. */
  2395. void i40e_rm_vlan_all_mac(struct i40e_vsi *vsi, s16 vid)
  2396. {
  2397. struct i40e_mac_filter *f;
  2398. struct hlist_node *h;
  2399. int bkt;
  2400. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  2401. if (f->vlan == vid)
  2402. __i40e_del_filter(vsi, f);
  2403. }
  2404. }
  2405. /**
  2406. * i40e_vsi_kill_vlan - Remove VSI membership for given VLAN
  2407. * @vsi: the VSI being configured
  2408. * @vid: VLAN id to be removed
  2409. **/
  2410. void i40e_vsi_kill_vlan(struct i40e_vsi *vsi, u16 vid)
  2411. {
  2412. if (!vid || vsi->info.pvid)
  2413. return;
  2414. spin_lock_bh(&vsi->mac_filter_hash_lock);
  2415. i40e_rm_vlan_all_mac(vsi, vid);
  2416. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  2417. /* schedule our worker thread which will take care of
  2418. * applying the new filter changes
  2419. */
  2420. i40e_service_event_schedule(vsi->back);
  2421. }
  2422. /**
  2423. * i40e_vlan_rx_add_vid - Add a vlan id filter to HW offload
  2424. * @netdev: network interface to be adjusted
  2425. * @vid: vlan id to be added
  2426. *
  2427. * net_device_ops implementation for adding vlan ids
  2428. **/
  2429. #ifdef I40E_FCOE
  2430. int i40e_vlan_rx_add_vid(struct net_device *netdev,
  2431. __always_unused __be16 proto, u16 vid)
  2432. #else
  2433. static int i40e_vlan_rx_add_vid(struct net_device *netdev,
  2434. __always_unused __be16 proto, u16 vid)
  2435. #endif
  2436. {
  2437. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2438. struct i40e_vsi *vsi = np->vsi;
  2439. int ret = 0;
  2440. if (vid >= VLAN_N_VID)
  2441. return -EINVAL;
  2442. /* If the network stack called us with vid = 0 then
  2443. * it is asking to receive priority tagged packets with
  2444. * vlan id 0. Our HW receives them by default when configured
  2445. * to receive untagged packets so there is no need to add an
  2446. * extra filter for vlan 0 tagged packets.
  2447. */
  2448. if (vid)
  2449. ret = i40e_vsi_add_vlan(vsi, vid);
  2450. if (!ret)
  2451. set_bit(vid, vsi->active_vlans);
  2452. return ret;
  2453. }
  2454. /**
  2455. * i40e_vlan_rx_kill_vid - Remove a vlan id filter from HW offload
  2456. * @netdev: network interface to be adjusted
  2457. * @vid: vlan id to be removed
  2458. *
  2459. * net_device_ops implementation for removing vlan ids
  2460. **/
  2461. #ifdef I40E_FCOE
  2462. int i40e_vlan_rx_kill_vid(struct net_device *netdev,
  2463. __always_unused __be16 proto, u16 vid)
  2464. #else
  2465. static int i40e_vlan_rx_kill_vid(struct net_device *netdev,
  2466. __always_unused __be16 proto, u16 vid)
  2467. #endif
  2468. {
  2469. struct i40e_netdev_priv *np = netdev_priv(netdev);
  2470. struct i40e_vsi *vsi = np->vsi;
  2471. /* return code is ignored as there is nothing a user
  2472. * can do about failure to remove and a log message was
  2473. * already printed from the other function
  2474. */
  2475. i40e_vsi_kill_vlan(vsi, vid);
  2476. clear_bit(vid, vsi->active_vlans);
  2477. return 0;
  2478. }
  2479. /**
  2480. * i40e_macaddr_init - explicitly write the mac address filters
  2481. *
  2482. * @vsi: pointer to the vsi
  2483. * @macaddr: the MAC address
  2484. *
  2485. * This is needed when the macaddr has been obtained by other
  2486. * means than the default, e.g., from Open Firmware or IDPROM.
  2487. * Returns 0 on success, negative on failure
  2488. **/
  2489. static int i40e_macaddr_init(struct i40e_vsi *vsi, u8 *macaddr)
  2490. {
  2491. int ret;
  2492. struct i40e_aqc_add_macvlan_element_data element;
  2493. ret = i40e_aq_mac_address_write(&vsi->back->hw,
  2494. I40E_AQC_WRITE_TYPE_LAA_WOL,
  2495. macaddr, NULL);
  2496. if (ret) {
  2497. dev_info(&vsi->back->pdev->dev,
  2498. "Addr change for VSI failed: %d\n", ret);
  2499. return -EADDRNOTAVAIL;
  2500. }
  2501. memset(&element, 0, sizeof(element));
  2502. ether_addr_copy(element.mac_addr, macaddr);
  2503. element.flags = cpu_to_le16(I40E_AQC_MACVLAN_ADD_PERFECT_MATCH);
  2504. ret = i40e_aq_add_macvlan(&vsi->back->hw, vsi->seid, &element, 1, NULL);
  2505. if (ret) {
  2506. dev_info(&vsi->back->pdev->dev,
  2507. "add filter failed err %s aq_err %s\n",
  2508. i40e_stat_str(&vsi->back->hw, ret),
  2509. i40e_aq_str(&vsi->back->hw,
  2510. vsi->back->hw.aq.asq_last_status));
  2511. }
  2512. return ret;
  2513. }
  2514. /**
  2515. * i40e_restore_vlan - Reinstate vlans when vsi/netdev comes back up
  2516. * @vsi: the vsi being brought back up
  2517. **/
  2518. static void i40e_restore_vlan(struct i40e_vsi *vsi)
  2519. {
  2520. u16 vid;
  2521. if (!vsi->netdev)
  2522. return;
  2523. i40e_vlan_rx_register(vsi->netdev, vsi->netdev->features);
  2524. for_each_set_bit(vid, vsi->active_vlans, VLAN_N_VID)
  2525. i40e_vlan_rx_add_vid(vsi->netdev, htons(ETH_P_8021Q),
  2526. vid);
  2527. }
  2528. /**
  2529. * i40e_vsi_add_pvid - Add pvid for the VSI
  2530. * @vsi: the vsi being adjusted
  2531. * @vid: the vlan id to set as a PVID
  2532. **/
  2533. int i40e_vsi_add_pvid(struct i40e_vsi *vsi, u16 vid)
  2534. {
  2535. struct i40e_vsi_context ctxt;
  2536. i40e_status ret;
  2537. vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  2538. vsi->info.pvid = cpu_to_le16(vid);
  2539. vsi->info.port_vlan_flags = I40E_AQ_VSI_PVLAN_MODE_TAGGED |
  2540. I40E_AQ_VSI_PVLAN_INSERT_PVID |
  2541. I40E_AQ_VSI_PVLAN_EMOD_STR;
  2542. ctxt.seid = vsi->seid;
  2543. ctxt.info = vsi->info;
  2544. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  2545. if (ret) {
  2546. dev_info(&vsi->back->pdev->dev,
  2547. "add pvid failed, err %s aq_err %s\n",
  2548. i40e_stat_str(&vsi->back->hw, ret),
  2549. i40e_aq_str(&vsi->back->hw,
  2550. vsi->back->hw.aq.asq_last_status));
  2551. return -ENOENT;
  2552. }
  2553. return 0;
  2554. }
  2555. /**
  2556. * i40e_vsi_remove_pvid - Remove the pvid from the VSI
  2557. * @vsi: the vsi being adjusted
  2558. *
  2559. * Just use the vlan_rx_register() service to put it back to normal
  2560. **/
  2561. void i40e_vsi_remove_pvid(struct i40e_vsi *vsi)
  2562. {
  2563. i40e_vlan_stripping_disable(vsi);
  2564. vsi->info.pvid = 0;
  2565. }
  2566. /**
  2567. * i40e_vsi_setup_tx_resources - Allocate VSI Tx queue resources
  2568. * @vsi: ptr to the VSI
  2569. *
  2570. * If this function returns with an error, then it's possible one or
  2571. * more of the rings is populated (while the rest are not). It is the
  2572. * callers duty to clean those orphaned rings.
  2573. *
  2574. * Return 0 on success, negative on failure
  2575. **/
  2576. static int i40e_vsi_setup_tx_resources(struct i40e_vsi *vsi)
  2577. {
  2578. int i, err = 0;
  2579. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2580. err = i40e_setup_tx_descriptors(vsi->tx_rings[i]);
  2581. return err;
  2582. }
  2583. /**
  2584. * i40e_vsi_free_tx_resources - Free Tx resources for VSI queues
  2585. * @vsi: ptr to the VSI
  2586. *
  2587. * Free VSI's transmit software resources
  2588. **/
  2589. static void i40e_vsi_free_tx_resources(struct i40e_vsi *vsi)
  2590. {
  2591. int i;
  2592. if (!vsi->tx_rings)
  2593. return;
  2594. for (i = 0; i < vsi->num_queue_pairs; i++)
  2595. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc)
  2596. i40e_free_tx_resources(vsi->tx_rings[i]);
  2597. }
  2598. /**
  2599. * i40e_vsi_setup_rx_resources - Allocate VSI queues Rx resources
  2600. * @vsi: ptr to the VSI
  2601. *
  2602. * If this function returns with an error, then it's possible one or
  2603. * more of the rings is populated (while the rest are not). It is the
  2604. * callers duty to clean those orphaned rings.
  2605. *
  2606. * Return 0 on success, negative on failure
  2607. **/
  2608. static int i40e_vsi_setup_rx_resources(struct i40e_vsi *vsi)
  2609. {
  2610. int i, err = 0;
  2611. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2612. err = i40e_setup_rx_descriptors(vsi->rx_rings[i]);
  2613. #ifdef I40E_FCOE
  2614. i40e_fcoe_setup_ddp_resources(vsi);
  2615. #endif
  2616. return err;
  2617. }
  2618. /**
  2619. * i40e_vsi_free_rx_resources - Free Rx Resources for VSI queues
  2620. * @vsi: ptr to the VSI
  2621. *
  2622. * Free all receive software resources
  2623. **/
  2624. static void i40e_vsi_free_rx_resources(struct i40e_vsi *vsi)
  2625. {
  2626. int i;
  2627. if (!vsi->rx_rings)
  2628. return;
  2629. for (i = 0; i < vsi->num_queue_pairs; i++)
  2630. if (vsi->rx_rings[i] && vsi->rx_rings[i]->desc)
  2631. i40e_free_rx_resources(vsi->rx_rings[i]);
  2632. #ifdef I40E_FCOE
  2633. i40e_fcoe_free_ddp_resources(vsi);
  2634. #endif
  2635. }
  2636. /**
  2637. * i40e_config_xps_tx_ring - Configure XPS for a Tx ring
  2638. * @ring: The Tx ring to configure
  2639. *
  2640. * This enables/disables XPS for a given Tx descriptor ring
  2641. * based on the TCs enabled for the VSI that ring belongs to.
  2642. **/
  2643. static void i40e_config_xps_tx_ring(struct i40e_ring *ring)
  2644. {
  2645. struct i40e_vsi *vsi = ring->vsi;
  2646. cpumask_var_t mask;
  2647. if (!ring->q_vector || !ring->netdev)
  2648. return;
  2649. /* Single TC mode enable XPS */
  2650. if (vsi->tc_config.numtc <= 1) {
  2651. if (!test_and_set_bit(__I40E_TX_XPS_INIT_DONE, &ring->state))
  2652. netif_set_xps_queue(ring->netdev,
  2653. &ring->q_vector->affinity_mask,
  2654. ring->queue_index);
  2655. } else if (alloc_cpumask_var(&mask, GFP_KERNEL)) {
  2656. /* Disable XPS to allow selection based on TC */
  2657. bitmap_zero(cpumask_bits(mask), nr_cpumask_bits);
  2658. netif_set_xps_queue(ring->netdev, mask, ring->queue_index);
  2659. free_cpumask_var(mask);
  2660. }
  2661. /* schedule our worker thread which will take care of
  2662. * applying the new filter changes
  2663. */
  2664. i40e_service_event_schedule(vsi->back);
  2665. }
  2666. /**
  2667. * i40e_configure_tx_ring - Configure a transmit ring context and rest
  2668. * @ring: The Tx ring to configure
  2669. *
  2670. * Configure the Tx descriptor ring in the HMC context.
  2671. **/
  2672. static int i40e_configure_tx_ring(struct i40e_ring *ring)
  2673. {
  2674. struct i40e_vsi *vsi = ring->vsi;
  2675. u16 pf_q = vsi->base_queue + ring->queue_index;
  2676. struct i40e_hw *hw = &vsi->back->hw;
  2677. struct i40e_hmc_obj_txq tx_ctx;
  2678. i40e_status err = 0;
  2679. u32 qtx_ctl = 0;
  2680. /* some ATR related tx ring init */
  2681. if (vsi->back->flags & I40E_FLAG_FD_ATR_ENABLED) {
  2682. ring->atr_sample_rate = vsi->back->atr_sample_rate;
  2683. ring->atr_count = 0;
  2684. } else {
  2685. ring->atr_sample_rate = 0;
  2686. }
  2687. /* configure XPS */
  2688. i40e_config_xps_tx_ring(ring);
  2689. /* clear the context structure first */
  2690. memset(&tx_ctx, 0, sizeof(tx_ctx));
  2691. tx_ctx.new_context = 1;
  2692. tx_ctx.base = (ring->dma / 128);
  2693. tx_ctx.qlen = ring->count;
  2694. tx_ctx.fd_ena = !!(vsi->back->flags & (I40E_FLAG_FD_SB_ENABLED |
  2695. I40E_FLAG_FD_ATR_ENABLED));
  2696. #ifdef I40E_FCOE
  2697. tx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
  2698. #endif
  2699. tx_ctx.timesync_ena = !!(vsi->back->flags & I40E_FLAG_PTP);
  2700. /* FDIR VSI tx ring can still use RS bit and writebacks */
  2701. if (vsi->type != I40E_VSI_FDIR)
  2702. tx_ctx.head_wb_ena = 1;
  2703. tx_ctx.head_wb_addr = ring->dma +
  2704. (ring->count * sizeof(struct i40e_tx_desc));
  2705. /* As part of VSI creation/update, FW allocates certain
  2706. * Tx arbitration queue sets for each TC enabled for
  2707. * the VSI. The FW returns the handles to these queue
  2708. * sets as part of the response buffer to Add VSI,
  2709. * Update VSI, etc. AQ commands. It is expected that
  2710. * these queue set handles be associated with the Tx
  2711. * queues by the driver as part of the TX queue context
  2712. * initialization. This has to be done regardless of
  2713. * DCB as by default everything is mapped to TC0.
  2714. */
  2715. tx_ctx.rdylist = le16_to_cpu(vsi->info.qs_handle[ring->dcb_tc]);
  2716. tx_ctx.rdylist_act = 0;
  2717. /* clear the context in the HMC */
  2718. err = i40e_clear_lan_tx_queue_context(hw, pf_q);
  2719. if (err) {
  2720. dev_info(&vsi->back->pdev->dev,
  2721. "Failed to clear LAN Tx queue context on Tx ring %d (pf_q %d), error: %d\n",
  2722. ring->queue_index, pf_q, err);
  2723. return -ENOMEM;
  2724. }
  2725. /* set the context in the HMC */
  2726. err = i40e_set_lan_tx_queue_context(hw, pf_q, &tx_ctx);
  2727. if (err) {
  2728. dev_info(&vsi->back->pdev->dev,
  2729. "Failed to set LAN Tx queue context on Tx ring %d (pf_q %d, error: %d\n",
  2730. ring->queue_index, pf_q, err);
  2731. return -ENOMEM;
  2732. }
  2733. /* Now associate this queue with this PCI function */
  2734. if (vsi->type == I40E_VSI_VMDQ2) {
  2735. qtx_ctl = I40E_QTX_CTL_VM_QUEUE;
  2736. qtx_ctl |= ((vsi->id) << I40E_QTX_CTL_VFVM_INDX_SHIFT) &
  2737. I40E_QTX_CTL_VFVM_INDX_MASK;
  2738. } else {
  2739. qtx_ctl = I40E_QTX_CTL_PF_QUEUE;
  2740. }
  2741. qtx_ctl |= ((hw->pf_id << I40E_QTX_CTL_PF_INDX_SHIFT) &
  2742. I40E_QTX_CTL_PF_INDX_MASK);
  2743. wr32(hw, I40E_QTX_CTL(pf_q), qtx_ctl);
  2744. i40e_flush(hw);
  2745. /* cache tail off for easier writes later */
  2746. ring->tail = hw->hw_addr + I40E_QTX_TAIL(pf_q);
  2747. return 0;
  2748. }
  2749. /**
  2750. * i40e_configure_rx_ring - Configure a receive ring context
  2751. * @ring: The Rx ring to configure
  2752. *
  2753. * Configure the Rx descriptor ring in the HMC context.
  2754. **/
  2755. static int i40e_configure_rx_ring(struct i40e_ring *ring)
  2756. {
  2757. struct i40e_vsi *vsi = ring->vsi;
  2758. u32 chain_len = vsi->back->hw.func_caps.rx_buf_chain_len;
  2759. u16 pf_q = vsi->base_queue + ring->queue_index;
  2760. struct i40e_hw *hw = &vsi->back->hw;
  2761. struct i40e_hmc_obj_rxq rx_ctx;
  2762. i40e_status err = 0;
  2763. ring->state = 0;
  2764. /* clear the context structure first */
  2765. memset(&rx_ctx, 0, sizeof(rx_ctx));
  2766. ring->rx_buf_len = vsi->rx_buf_len;
  2767. rx_ctx.dbuff = ring->rx_buf_len >> I40E_RXQ_CTX_DBUFF_SHIFT;
  2768. rx_ctx.base = (ring->dma / 128);
  2769. rx_ctx.qlen = ring->count;
  2770. /* use 32 byte descriptors */
  2771. rx_ctx.dsize = 1;
  2772. /* descriptor type is always zero
  2773. * rx_ctx.dtype = 0;
  2774. */
  2775. rx_ctx.hsplit_0 = 0;
  2776. rx_ctx.rxmax = min_t(u16, vsi->max_frame, chain_len * ring->rx_buf_len);
  2777. if (hw->revision_id == 0)
  2778. rx_ctx.lrxqthresh = 0;
  2779. else
  2780. rx_ctx.lrxqthresh = 2;
  2781. rx_ctx.crcstrip = 1;
  2782. rx_ctx.l2tsel = 1;
  2783. /* this controls whether VLAN is stripped from inner headers */
  2784. rx_ctx.showiv = 0;
  2785. #ifdef I40E_FCOE
  2786. rx_ctx.fc_ena = (vsi->type == I40E_VSI_FCOE);
  2787. #endif
  2788. /* set the prefena field to 1 because the manual says to */
  2789. rx_ctx.prefena = 1;
  2790. /* clear the context in the HMC */
  2791. err = i40e_clear_lan_rx_queue_context(hw, pf_q);
  2792. if (err) {
  2793. dev_info(&vsi->back->pdev->dev,
  2794. "Failed to clear LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2795. ring->queue_index, pf_q, err);
  2796. return -ENOMEM;
  2797. }
  2798. /* set the context in the HMC */
  2799. err = i40e_set_lan_rx_queue_context(hw, pf_q, &rx_ctx);
  2800. if (err) {
  2801. dev_info(&vsi->back->pdev->dev,
  2802. "Failed to set LAN Rx queue context on Rx ring %d (pf_q %d), error: %d\n",
  2803. ring->queue_index, pf_q, err);
  2804. return -ENOMEM;
  2805. }
  2806. /* cache tail for quicker writes, and clear the reg before use */
  2807. ring->tail = hw->hw_addr + I40E_QRX_TAIL(pf_q);
  2808. writel(0, ring->tail);
  2809. i40e_alloc_rx_buffers(ring, I40E_DESC_UNUSED(ring));
  2810. return 0;
  2811. }
  2812. /**
  2813. * i40e_vsi_configure_tx - Configure the VSI for Tx
  2814. * @vsi: VSI structure describing this set of rings and resources
  2815. *
  2816. * Configure the Tx VSI for operation.
  2817. **/
  2818. static int i40e_vsi_configure_tx(struct i40e_vsi *vsi)
  2819. {
  2820. int err = 0;
  2821. u16 i;
  2822. for (i = 0; (i < vsi->num_queue_pairs) && !err; i++)
  2823. err = i40e_configure_tx_ring(vsi->tx_rings[i]);
  2824. return err;
  2825. }
  2826. /**
  2827. * i40e_vsi_configure_rx - Configure the VSI for Rx
  2828. * @vsi: the VSI being configured
  2829. *
  2830. * Configure the Rx VSI for operation.
  2831. **/
  2832. static int i40e_vsi_configure_rx(struct i40e_vsi *vsi)
  2833. {
  2834. int err = 0;
  2835. u16 i;
  2836. if (vsi->netdev && (vsi->netdev->mtu > ETH_DATA_LEN))
  2837. vsi->max_frame = vsi->netdev->mtu + ETH_HLEN
  2838. + ETH_FCS_LEN + VLAN_HLEN;
  2839. else
  2840. vsi->max_frame = I40E_RXBUFFER_2048;
  2841. vsi->rx_buf_len = I40E_RXBUFFER_2048;
  2842. #ifdef I40E_FCOE
  2843. /* setup rx buffer for FCoE */
  2844. if ((vsi->type == I40E_VSI_FCOE) &&
  2845. (vsi->back->flags & I40E_FLAG_FCOE_ENABLED)) {
  2846. vsi->rx_buf_len = I40E_RXBUFFER_3072;
  2847. vsi->max_frame = I40E_RXBUFFER_3072;
  2848. }
  2849. #endif /* I40E_FCOE */
  2850. /* round up for the chip's needs */
  2851. vsi->rx_buf_len = ALIGN(vsi->rx_buf_len,
  2852. BIT_ULL(I40E_RXQ_CTX_DBUFF_SHIFT));
  2853. /* set up individual rings */
  2854. for (i = 0; i < vsi->num_queue_pairs && !err; i++)
  2855. err = i40e_configure_rx_ring(vsi->rx_rings[i]);
  2856. return err;
  2857. }
  2858. /**
  2859. * i40e_vsi_config_dcb_rings - Update rings to reflect DCB TC
  2860. * @vsi: ptr to the VSI
  2861. **/
  2862. static void i40e_vsi_config_dcb_rings(struct i40e_vsi *vsi)
  2863. {
  2864. struct i40e_ring *tx_ring, *rx_ring;
  2865. u16 qoffset, qcount;
  2866. int i, n;
  2867. if (!(vsi->back->flags & I40E_FLAG_DCB_ENABLED)) {
  2868. /* Reset the TC information */
  2869. for (i = 0; i < vsi->num_queue_pairs; i++) {
  2870. rx_ring = vsi->rx_rings[i];
  2871. tx_ring = vsi->tx_rings[i];
  2872. rx_ring->dcb_tc = 0;
  2873. tx_ring->dcb_tc = 0;
  2874. }
  2875. }
  2876. for (n = 0; n < I40E_MAX_TRAFFIC_CLASS; n++) {
  2877. if (!(vsi->tc_config.enabled_tc & BIT_ULL(n)))
  2878. continue;
  2879. qoffset = vsi->tc_config.tc_info[n].qoffset;
  2880. qcount = vsi->tc_config.tc_info[n].qcount;
  2881. for (i = qoffset; i < (qoffset + qcount); i++) {
  2882. rx_ring = vsi->rx_rings[i];
  2883. tx_ring = vsi->tx_rings[i];
  2884. rx_ring->dcb_tc = n;
  2885. tx_ring->dcb_tc = n;
  2886. }
  2887. }
  2888. }
  2889. /**
  2890. * i40e_set_vsi_rx_mode - Call set_rx_mode on a VSI
  2891. * @vsi: ptr to the VSI
  2892. **/
  2893. static void i40e_set_vsi_rx_mode(struct i40e_vsi *vsi)
  2894. {
  2895. struct i40e_pf *pf = vsi->back;
  2896. int err;
  2897. if (vsi->netdev)
  2898. i40e_set_rx_mode(vsi->netdev);
  2899. if (!!(pf->flags & I40E_FLAG_PF_MAC)) {
  2900. err = i40e_macaddr_init(vsi, pf->hw.mac.addr);
  2901. if (err) {
  2902. dev_warn(&pf->pdev->dev,
  2903. "could not set up macaddr; err %d\n", err);
  2904. }
  2905. }
  2906. }
  2907. /**
  2908. * i40e_fdir_filter_restore - Restore the Sideband Flow Director filters
  2909. * @vsi: Pointer to the targeted VSI
  2910. *
  2911. * This function replays the hlist on the hw where all the SB Flow Director
  2912. * filters were saved.
  2913. **/
  2914. static void i40e_fdir_filter_restore(struct i40e_vsi *vsi)
  2915. {
  2916. struct i40e_fdir_filter *filter;
  2917. struct i40e_pf *pf = vsi->back;
  2918. struct hlist_node *node;
  2919. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  2920. return;
  2921. hlist_for_each_entry_safe(filter, node,
  2922. &pf->fdir_filter_list, fdir_node) {
  2923. i40e_add_del_fdir(vsi, filter, true);
  2924. }
  2925. }
  2926. /**
  2927. * i40e_vsi_configure - Set up the VSI for action
  2928. * @vsi: the VSI being configured
  2929. **/
  2930. static int i40e_vsi_configure(struct i40e_vsi *vsi)
  2931. {
  2932. int err;
  2933. i40e_set_vsi_rx_mode(vsi);
  2934. i40e_restore_vlan(vsi);
  2935. i40e_vsi_config_dcb_rings(vsi);
  2936. err = i40e_vsi_configure_tx(vsi);
  2937. if (!err)
  2938. err = i40e_vsi_configure_rx(vsi);
  2939. return err;
  2940. }
  2941. /**
  2942. * i40e_vsi_configure_msix - MSIX mode Interrupt Config in the HW
  2943. * @vsi: the VSI being configured
  2944. **/
  2945. static void i40e_vsi_configure_msix(struct i40e_vsi *vsi)
  2946. {
  2947. struct i40e_pf *pf = vsi->back;
  2948. struct i40e_hw *hw = &pf->hw;
  2949. u16 vector;
  2950. int i, q;
  2951. u32 qp;
  2952. /* The interrupt indexing is offset by 1 in the PFINT_ITRn
  2953. * and PFINT_LNKLSTn registers, e.g.:
  2954. * PFINT_ITRn[0..n-1] gets msix-1..msix-n (qpair interrupts)
  2955. */
  2956. qp = vsi->base_queue;
  2957. vector = vsi->base_vector;
  2958. for (i = 0; i < vsi->num_q_vectors; i++, vector++) {
  2959. struct i40e_q_vector *q_vector = vsi->q_vectors[i];
  2960. q_vector->itr_countdown = ITR_COUNTDOWN_START;
  2961. q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[i]->rx_itr_setting);
  2962. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  2963. wr32(hw, I40E_PFINT_ITRN(I40E_RX_ITR, vector - 1),
  2964. q_vector->rx.itr);
  2965. q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[i]->tx_itr_setting);
  2966. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  2967. wr32(hw, I40E_PFINT_ITRN(I40E_TX_ITR, vector - 1),
  2968. q_vector->tx.itr);
  2969. wr32(hw, I40E_PFINT_RATEN(vector - 1),
  2970. i40e_intrl_usec_to_reg(vsi->int_rate_limit));
  2971. /* Linked list for the queuepairs assigned to this vector */
  2972. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), qp);
  2973. for (q = 0; q < q_vector->num_ringpairs; q++) {
  2974. u32 val;
  2975. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  2976. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  2977. (vector << I40E_QINT_RQCTL_MSIX_INDX_SHIFT) |
  2978. (qp << I40E_QINT_RQCTL_NEXTQ_INDX_SHIFT)|
  2979. (I40E_QUEUE_TYPE_TX
  2980. << I40E_QINT_RQCTL_NEXTQ_TYPE_SHIFT);
  2981. wr32(hw, I40E_QINT_RQCTL(qp), val);
  2982. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  2983. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  2984. (vector << I40E_QINT_TQCTL_MSIX_INDX_SHIFT) |
  2985. ((qp+1) << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT)|
  2986. (I40E_QUEUE_TYPE_RX
  2987. << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  2988. /* Terminate the linked list */
  2989. if (q == (q_vector->num_ringpairs - 1))
  2990. val |= (I40E_QUEUE_END_OF_LIST
  2991. << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  2992. wr32(hw, I40E_QINT_TQCTL(qp), val);
  2993. qp++;
  2994. }
  2995. }
  2996. i40e_flush(hw);
  2997. }
  2998. /**
  2999. * i40e_enable_misc_int_causes - enable the non-queue interrupts
  3000. * @hw: ptr to the hardware info
  3001. **/
  3002. static void i40e_enable_misc_int_causes(struct i40e_pf *pf)
  3003. {
  3004. struct i40e_hw *hw = &pf->hw;
  3005. u32 val;
  3006. /* clear things first */
  3007. wr32(hw, I40E_PFINT_ICR0_ENA, 0); /* disable all */
  3008. rd32(hw, I40E_PFINT_ICR0); /* read to clear */
  3009. val = I40E_PFINT_ICR0_ENA_ECC_ERR_MASK |
  3010. I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK |
  3011. I40E_PFINT_ICR0_ENA_GRST_MASK |
  3012. I40E_PFINT_ICR0_ENA_PCI_EXCEPTION_MASK |
  3013. I40E_PFINT_ICR0_ENA_GPIO_MASK |
  3014. I40E_PFINT_ICR0_ENA_HMC_ERR_MASK |
  3015. I40E_PFINT_ICR0_ENA_VFLR_MASK |
  3016. I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  3017. if (pf->flags & I40E_FLAG_IWARP_ENABLED)
  3018. val |= I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  3019. if (pf->flags & I40E_FLAG_PTP)
  3020. val |= I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  3021. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  3022. /* SW_ITR_IDX = 0, but don't change INTENA */
  3023. wr32(hw, I40E_PFINT_DYN_CTL0, I40E_PFINT_DYN_CTL0_SW_ITR_INDX_MASK |
  3024. I40E_PFINT_DYN_CTL0_INTENA_MSK_MASK);
  3025. /* OTHER_ITR_IDX = 0 */
  3026. wr32(hw, I40E_PFINT_STAT_CTL0, 0);
  3027. }
  3028. /**
  3029. * i40e_configure_msi_and_legacy - Legacy mode interrupt config in the HW
  3030. * @vsi: the VSI being configured
  3031. **/
  3032. static void i40e_configure_msi_and_legacy(struct i40e_vsi *vsi)
  3033. {
  3034. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  3035. struct i40e_pf *pf = vsi->back;
  3036. struct i40e_hw *hw = &pf->hw;
  3037. u32 val;
  3038. /* set the ITR configuration */
  3039. q_vector->itr_countdown = ITR_COUNTDOWN_START;
  3040. q_vector->rx.itr = ITR_TO_REG(vsi->rx_rings[0]->rx_itr_setting);
  3041. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  3042. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), q_vector->rx.itr);
  3043. q_vector->tx.itr = ITR_TO_REG(vsi->tx_rings[0]->tx_itr_setting);
  3044. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  3045. wr32(hw, I40E_PFINT_ITR0(I40E_TX_ITR), q_vector->tx.itr);
  3046. i40e_enable_misc_int_causes(pf);
  3047. /* FIRSTQ_INDX = 0, FIRSTQ_TYPE = 0 (rx) */
  3048. wr32(hw, I40E_PFINT_LNKLST0, 0);
  3049. /* Associate the queue pair to the vector and enable the queue int */
  3050. val = I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3051. (I40E_RX_ITR << I40E_QINT_RQCTL_ITR_INDX_SHIFT) |
  3052. (I40E_QUEUE_TYPE_TX << I40E_QINT_TQCTL_NEXTQ_TYPE_SHIFT);
  3053. wr32(hw, I40E_QINT_RQCTL(0), val);
  3054. val = I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3055. (I40E_TX_ITR << I40E_QINT_TQCTL_ITR_INDX_SHIFT) |
  3056. (I40E_QUEUE_END_OF_LIST << I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT);
  3057. wr32(hw, I40E_QINT_TQCTL(0), val);
  3058. i40e_flush(hw);
  3059. }
  3060. /**
  3061. * i40e_irq_dynamic_disable_icr0 - Disable default interrupt generation for icr0
  3062. * @pf: board private structure
  3063. **/
  3064. void i40e_irq_dynamic_disable_icr0(struct i40e_pf *pf)
  3065. {
  3066. struct i40e_hw *hw = &pf->hw;
  3067. wr32(hw, I40E_PFINT_DYN_CTL0,
  3068. I40E_ITR_NONE << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT);
  3069. i40e_flush(hw);
  3070. }
  3071. /**
  3072. * i40e_irq_dynamic_enable_icr0 - Enable default interrupt generation for icr0
  3073. * @pf: board private structure
  3074. * @clearpba: true when all pending interrupt events should be cleared
  3075. **/
  3076. void i40e_irq_dynamic_enable_icr0(struct i40e_pf *pf, bool clearpba)
  3077. {
  3078. struct i40e_hw *hw = &pf->hw;
  3079. u32 val;
  3080. val = I40E_PFINT_DYN_CTL0_INTENA_MASK |
  3081. (clearpba ? I40E_PFINT_DYN_CTL0_CLEARPBA_MASK : 0) |
  3082. (I40E_ITR_NONE << I40E_PFINT_DYN_CTL0_ITR_INDX_SHIFT);
  3083. wr32(hw, I40E_PFINT_DYN_CTL0, val);
  3084. i40e_flush(hw);
  3085. }
  3086. /**
  3087. * i40e_msix_clean_rings - MSIX mode Interrupt Handler
  3088. * @irq: interrupt number
  3089. * @data: pointer to a q_vector
  3090. **/
  3091. static irqreturn_t i40e_msix_clean_rings(int irq, void *data)
  3092. {
  3093. struct i40e_q_vector *q_vector = data;
  3094. if (!q_vector->tx.ring && !q_vector->rx.ring)
  3095. return IRQ_HANDLED;
  3096. napi_schedule_irqoff(&q_vector->napi);
  3097. return IRQ_HANDLED;
  3098. }
  3099. /**
  3100. * i40e_irq_affinity_notify - Callback for affinity changes
  3101. * @notify: context as to what irq was changed
  3102. * @mask: the new affinity mask
  3103. *
  3104. * This is a callback function used by the irq_set_affinity_notifier function
  3105. * so that we may register to receive changes to the irq affinity masks.
  3106. **/
  3107. static void i40e_irq_affinity_notify(struct irq_affinity_notify *notify,
  3108. const cpumask_t *mask)
  3109. {
  3110. struct i40e_q_vector *q_vector =
  3111. container_of(notify, struct i40e_q_vector, affinity_notify);
  3112. q_vector->affinity_mask = *mask;
  3113. }
  3114. /**
  3115. * i40e_irq_affinity_release - Callback for affinity notifier release
  3116. * @ref: internal core kernel usage
  3117. *
  3118. * This is a callback function used by the irq_set_affinity_notifier function
  3119. * to inform the current notification subscriber that they will no longer
  3120. * receive notifications.
  3121. **/
  3122. static void i40e_irq_affinity_release(struct kref *ref) {}
  3123. /**
  3124. * i40e_vsi_request_irq_msix - Initialize MSI-X interrupts
  3125. * @vsi: the VSI being configured
  3126. * @basename: name for the vector
  3127. *
  3128. * Allocates MSI-X vectors and requests interrupts from the kernel.
  3129. **/
  3130. static int i40e_vsi_request_irq_msix(struct i40e_vsi *vsi, char *basename)
  3131. {
  3132. int q_vectors = vsi->num_q_vectors;
  3133. struct i40e_pf *pf = vsi->back;
  3134. int base = vsi->base_vector;
  3135. int rx_int_idx = 0;
  3136. int tx_int_idx = 0;
  3137. int vector, err;
  3138. int irq_num;
  3139. for (vector = 0; vector < q_vectors; vector++) {
  3140. struct i40e_q_vector *q_vector = vsi->q_vectors[vector];
  3141. irq_num = pf->msix_entries[base + vector].vector;
  3142. if (q_vector->tx.ring && q_vector->rx.ring) {
  3143. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3144. "%s-%s-%d", basename, "TxRx", rx_int_idx++);
  3145. tx_int_idx++;
  3146. } else if (q_vector->rx.ring) {
  3147. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3148. "%s-%s-%d", basename, "rx", rx_int_idx++);
  3149. } else if (q_vector->tx.ring) {
  3150. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  3151. "%s-%s-%d", basename, "tx", tx_int_idx++);
  3152. } else {
  3153. /* skip this unused q_vector */
  3154. continue;
  3155. }
  3156. err = request_irq(irq_num,
  3157. vsi->irq_handler,
  3158. 0,
  3159. q_vector->name,
  3160. q_vector);
  3161. if (err) {
  3162. dev_info(&pf->pdev->dev,
  3163. "MSIX request_irq failed, error: %d\n", err);
  3164. goto free_queue_irqs;
  3165. }
  3166. /* register for affinity change notifications */
  3167. q_vector->affinity_notify.notify = i40e_irq_affinity_notify;
  3168. q_vector->affinity_notify.release = i40e_irq_affinity_release;
  3169. irq_set_affinity_notifier(irq_num, &q_vector->affinity_notify);
  3170. /* assign the mask for this irq */
  3171. irq_set_affinity_hint(irq_num, &q_vector->affinity_mask);
  3172. }
  3173. vsi->irqs_ready = true;
  3174. return 0;
  3175. free_queue_irqs:
  3176. while (vector) {
  3177. vector--;
  3178. irq_num = pf->msix_entries[base + vector].vector;
  3179. irq_set_affinity_notifier(irq_num, NULL);
  3180. irq_set_affinity_hint(irq_num, NULL);
  3181. free_irq(irq_num, &vsi->q_vectors[vector]);
  3182. }
  3183. return err;
  3184. }
  3185. /**
  3186. * i40e_vsi_disable_irq - Mask off queue interrupt generation on the VSI
  3187. * @vsi: the VSI being un-configured
  3188. **/
  3189. static void i40e_vsi_disable_irq(struct i40e_vsi *vsi)
  3190. {
  3191. struct i40e_pf *pf = vsi->back;
  3192. struct i40e_hw *hw = &pf->hw;
  3193. int base = vsi->base_vector;
  3194. int i;
  3195. for (i = 0; i < vsi->num_queue_pairs; i++) {
  3196. wr32(hw, I40E_QINT_TQCTL(vsi->tx_rings[i]->reg_idx), 0);
  3197. wr32(hw, I40E_QINT_RQCTL(vsi->rx_rings[i]->reg_idx), 0);
  3198. }
  3199. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3200. for (i = vsi->base_vector;
  3201. i < (vsi->num_q_vectors + vsi->base_vector); i++)
  3202. wr32(hw, I40E_PFINT_DYN_CTLN(i - 1), 0);
  3203. i40e_flush(hw);
  3204. for (i = 0; i < vsi->num_q_vectors; i++)
  3205. synchronize_irq(pf->msix_entries[i + base].vector);
  3206. } else {
  3207. /* Legacy and MSI mode - this stops all interrupt handling */
  3208. wr32(hw, I40E_PFINT_ICR0_ENA, 0);
  3209. wr32(hw, I40E_PFINT_DYN_CTL0, 0);
  3210. i40e_flush(hw);
  3211. synchronize_irq(pf->pdev->irq);
  3212. }
  3213. }
  3214. /**
  3215. * i40e_vsi_enable_irq - Enable IRQ for the given VSI
  3216. * @vsi: the VSI being configured
  3217. **/
  3218. static int i40e_vsi_enable_irq(struct i40e_vsi *vsi)
  3219. {
  3220. struct i40e_pf *pf = vsi->back;
  3221. int i;
  3222. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3223. for (i = 0; i < vsi->num_q_vectors; i++)
  3224. i40e_irq_dynamic_enable(vsi, i);
  3225. } else {
  3226. i40e_irq_dynamic_enable_icr0(pf, true);
  3227. }
  3228. i40e_flush(&pf->hw);
  3229. return 0;
  3230. }
  3231. /**
  3232. * i40e_stop_misc_vector - Stop the vector that handles non-queue events
  3233. * @pf: board private structure
  3234. **/
  3235. static void i40e_stop_misc_vector(struct i40e_pf *pf)
  3236. {
  3237. /* Disable ICR 0 */
  3238. wr32(&pf->hw, I40E_PFINT_ICR0_ENA, 0);
  3239. i40e_flush(&pf->hw);
  3240. }
  3241. /**
  3242. * i40e_intr - MSI/Legacy and non-queue interrupt handler
  3243. * @irq: interrupt number
  3244. * @data: pointer to a q_vector
  3245. *
  3246. * This is the handler used for all MSI/Legacy interrupts, and deals
  3247. * with both queue and non-queue interrupts. This is also used in
  3248. * MSIX mode to handle the non-queue interrupts.
  3249. **/
  3250. static irqreturn_t i40e_intr(int irq, void *data)
  3251. {
  3252. struct i40e_pf *pf = (struct i40e_pf *)data;
  3253. struct i40e_hw *hw = &pf->hw;
  3254. irqreturn_t ret = IRQ_NONE;
  3255. u32 icr0, icr0_remaining;
  3256. u32 val, ena_mask;
  3257. icr0 = rd32(hw, I40E_PFINT_ICR0);
  3258. ena_mask = rd32(hw, I40E_PFINT_ICR0_ENA);
  3259. /* if sharing a legacy IRQ, we might get called w/o an intr pending */
  3260. if ((icr0 & I40E_PFINT_ICR0_INTEVENT_MASK) == 0)
  3261. goto enable_intr;
  3262. /* if interrupt but no bits showing, must be SWINT */
  3263. if (((icr0 & ~I40E_PFINT_ICR0_INTEVENT_MASK) == 0) ||
  3264. (icr0 & I40E_PFINT_ICR0_SWINT_MASK))
  3265. pf->sw_int_count++;
  3266. if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
  3267. (ena_mask & I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK)) {
  3268. ena_mask &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  3269. icr0 &= ~I40E_PFINT_ICR0_ENA_PE_CRITERR_MASK;
  3270. dev_dbg(&pf->pdev->dev, "cleared PE_CRITERR\n");
  3271. }
  3272. /* only q0 is used in MSI/Legacy mode, and none are used in MSIX */
  3273. if (icr0 & I40E_PFINT_ICR0_QUEUE_0_MASK) {
  3274. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  3275. struct i40e_q_vector *q_vector = vsi->q_vectors[0];
  3276. /* We do not have a way to disarm Queue causes while leaving
  3277. * interrupt enabled for all other causes, ideally
  3278. * interrupt should be disabled while we are in NAPI but
  3279. * this is not a performance path and napi_schedule()
  3280. * can deal with rescheduling.
  3281. */
  3282. if (!test_bit(__I40E_DOWN, &pf->state))
  3283. napi_schedule_irqoff(&q_vector->napi);
  3284. }
  3285. if (icr0 & I40E_PFINT_ICR0_ADMINQ_MASK) {
  3286. ena_mask &= ~I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  3287. set_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
  3288. i40e_debug(&pf->hw, I40E_DEBUG_NVM, "AdminQ event\n");
  3289. }
  3290. if (icr0 & I40E_PFINT_ICR0_MAL_DETECT_MASK) {
  3291. ena_mask &= ~I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  3292. set_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
  3293. }
  3294. if (icr0 & I40E_PFINT_ICR0_VFLR_MASK) {
  3295. ena_mask &= ~I40E_PFINT_ICR0_ENA_VFLR_MASK;
  3296. set_bit(__I40E_VFLR_EVENT_PENDING, &pf->state);
  3297. }
  3298. if (icr0 & I40E_PFINT_ICR0_GRST_MASK) {
  3299. if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
  3300. set_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
  3301. ena_mask &= ~I40E_PFINT_ICR0_ENA_GRST_MASK;
  3302. val = rd32(hw, I40E_GLGEN_RSTAT);
  3303. val = (val & I40E_GLGEN_RSTAT_RESET_TYPE_MASK)
  3304. >> I40E_GLGEN_RSTAT_RESET_TYPE_SHIFT;
  3305. if (val == I40E_RESET_CORER) {
  3306. pf->corer_count++;
  3307. } else if (val == I40E_RESET_GLOBR) {
  3308. pf->globr_count++;
  3309. } else if (val == I40E_RESET_EMPR) {
  3310. pf->empr_count++;
  3311. set_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state);
  3312. }
  3313. }
  3314. if (icr0 & I40E_PFINT_ICR0_HMC_ERR_MASK) {
  3315. icr0 &= ~I40E_PFINT_ICR0_HMC_ERR_MASK;
  3316. dev_info(&pf->pdev->dev, "HMC error interrupt\n");
  3317. dev_info(&pf->pdev->dev, "HMC error info 0x%x, HMC error data 0x%x\n",
  3318. rd32(hw, I40E_PFHMC_ERRORINFO),
  3319. rd32(hw, I40E_PFHMC_ERRORDATA));
  3320. }
  3321. if (icr0 & I40E_PFINT_ICR0_TIMESYNC_MASK) {
  3322. u32 prttsyn_stat = rd32(hw, I40E_PRTTSYN_STAT_0);
  3323. if (prttsyn_stat & I40E_PRTTSYN_STAT_0_TXTIME_MASK) {
  3324. icr0 &= ~I40E_PFINT_ICR0_ENA_TIMESYNC_MASK;
  3325. i40e_ptp_tx_hwtstamp(pf);
  3326. }
  3327. }
  3328. /* If a critical error is pending we have no choice but to reset the
  3329. * device.
  3330. * Report and mask out any remaining unexpected interrupts.
  3331. */
  3332. icr0_remaining = icr0 & ena_mask;
  3333. if (icr0_remaining) {
  3334. dev_info(&pf->pdev->dev, "unhandled interrupt icr0=0x%08x\n",
  3335. icr0_remaining);
  3336. if ((icr0_remaining & I40E_PFINT_ICR0_PE_CRITERR_MASK) ||
  3337. (icr0_remaining & I40E_PFINT_ICR0_PCI_EXCEPTION_MASK) ||
  3338. (icr0_remaining & I40E_PFINT_ICR0_ECC_ERR_MASK)) {
  3339. dev_info(&pf->pdev->dev, "device will be reset\n");
  3340. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  3341. i40e_service_event_schedule(pf);
  3342. }
  3343. ena_mask &= ~icr0_remaining;
  3344. }
  3345. ret = IRQ_HANDLED;
  3346. enable_intr:
  3347. /* re-enable interrupt causes */
  3348. wr32(hw, I40E_PFINT_ICR0_ENA, ena_mask);
  3349. if (!test_bit(__I40E_DOWN, &pf->state)) {
  3350. i40e_service_event_schedule(pf);
  3351. i40e_irq_dynamic_enable_icr0(pf, false);
  3352. }
  3353. return ret;
  3354. }
  3355. /**
  3356. * i40e_clean_fdir_tx_irq - Reclaim resources after transmit completes
  3357. * @tx_ring: tx ring to clean
  3358. * @budget: how many cleans we're allowed
  3359. *
  3360. * Returns true if there's any budget left (e.g. the clean is finished)
  3361. **/
  3362. static bool i40e_clean_fdir_tx_irq(struct i40e_ring *tx_ring, int budget)
  3363. {
  3364. struct i40e_vsi *vsi = tx_ring->vsi;
  3365. u16 i = tx_ring->next_to_clean;
  3366. struct i40e_tx_buffer *tx_buf;
  3367. struct i40e_tx_desc *tx_desc;
  3368. tx_buf = &tx_ring->tx_bi[i];
  3369. tx_desc = I40E_TX_DESC(tx_ring, i);
  3370. i -= tx_ring->count;
  3371. do {
  3372. struct i40e_tx_desc *eop_desc = tx_buf->next_to_watch;
  3373. /* if next_to_watch is not set then there is no work pending */
  3374. if (!eop_desc)
  3375. break;
  3376. /* prevent any other reads prior to eop_desc */
  3377. read_barrier_depends();
  3378. /* if the descriptor isn't done, no work yet to do */
  3379. if (!(eop_desc->cmd_type_offset_bsz &
  3380. cpu_to_le64(I40E_TX_DESC_DTYPE_DESC_DONE)))
  3381. break;
  3382. /* clear next_to_watch to prevent false hangs */
  3383. tx_buf->next_to_watch = NULL;
  3384. tx_desc->buffer_addr = 0;
  3385. tx_desc->cmd_type_offset_bsz = 0;
  3386. /* move past filter desc */
  3387. tx_buf++;
  3388. tx_desc++;
  3389. i++;
  3390. if (unlikely(!i)) {
  3391. i -= tx_ring->count;
  3392. tx_buf = tx_ring->tx_bi;
  3393. tx_desc = I40E_TX_DESC(tx_ring, 0);
  3394. }
  3395. /* unmap skb header data */
  3396. dma_unmap_single(tx_ring->dev,
  3397. dma_unmap_addr(tx_buf, dma),
  3398. dma_unmap_len(tx_buf, len),
  3399. DMA_TO_DEVICE);
  3400. if (tx_buf->tx_flags & I40E_TX_FLAGS_FD_SB)
  3401. kfree(tx_buf->raw_buf);
  3402. tx_buf->raw_buf = NULL;
  3403. tx_buf->tx_flags = 0;
  3404. tx_buf->next_to_watch = NULL;
  3405. dma_unmap_len_set(tx_buf, len, 0);
  3406. tx_desc->buffer_addr = 0;
  3407. tx_desc->cmd_type_offset_bsz = 0;
  3408. /* move us past the eop_desc for start of next FD desc */
  3409. tx_buf++;
  3410. tx_desc++;
  3411. i++;
  3412. if (unlikely(!i)) {
  3413. i -= tx_ring->count;
  3414. tx_buf = tx_ring->tx_bi;
  3415. tx_desc = I40E_TX_DESC(tx_ring, 0);
  3416. }
  3417. /* update budget accounting */
  3418. budget--;
  3419. } while (likely(budget));
  3420. i += tx_ring->count;
  3421. tx_ring->next_to_clean = i;
  3422. if (vsi->back->flags & I40E_FLAG_MSIX_ENABLED)
  3423. i40e_irq_dynamic_enable(vsi, tx_ring->q_vector->v_idx);
  3424. return budget > 0;
  3425. }
  3426. /**
  3427. * i40e_fdir_clean_ring - Interrupt Handler for FDIR SB ring
  3428. * @irq: interrupt number
  3429. * @data: pointer to a q_vector
  3430. **/
  3431. static irqreturn_t i40e_fdir_clean_ring(int irq, void *data)
  3432. {
  3433. struct i40e_q_vector *q_vector = data;
  3434. struct i40e_vsi *vsi;
  3435. if (!q_vector->tx.ring)
  3436. return IRQ_HANDLED;
  3437. vsi = q_vector->tx.ring->vsi;
  3438. i40e_clean_fdir_tx_irq(q_vector->tx.ring, vsi->work_limit);
  3439. return IRQ_HANDLED;
  3440. }
  3441. /**
  3442. * i40e_map_vector_to_qp - Assigns the queue pair to the vector
  3443. * @vsi: the VSI being configured
  3444. * @v_idx: vector index
  3445. * @qp_idx: queue pair index
  3446. **/
  3447. static void i40e_map_vector_to_qp(struct i40e_vsi *vsi, int v_idx, int qp_idx)
  3448. {
  3449. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  3450. struct i40e_ring *tx_ring = vsi->tx_rings[qp_idx];
  3451. struct i40e_ring *rx_ring = vsi->rx_rings[qp_idx];
  3452. tx_ring->q_vector = q_vector;
  3453. tx_ring->next = q_vector->tx.ring;
  3454. q_vector->tx.ring = tx_ring;
  3455. q_vector->tx.count++;
  3456. rx_ring->q_vector = q_vector;
  3457. rx_ring->next = q_vector->rx.ring;
  3458. q_vector->rx.ring = rx_ring;
  3459. q_vector->rx.count++;
  3460. }
  3461. /**
  3462. * i40e_vsi_map_rings_to_vectors - Maps descriptor rings to vectors
  3463. * @vsi: the VSI being configured
  3464. *
  3465. * This function maps descriptor rings to the queue-specific vectors
  3466. * we were allotted through the MSI-X enabling code. Ideally, we'd have
  3467. * one vector per queue pair, but on a constrained vector budget, we
  3468. * group the queue pairs as "efficiently" as possible.
  3469. **/
  3470. static void i40e_vsi_map_rings_to_vectors(struct i40e_vsi *vsi)
  3471. {
  3472. int qp_remaining = vsi->num_queue_pairs;
  3473. int q_vectors = vsi->num_q_vectors;
  3474. int num_ringpairs;
  3475. int v_start = 0;
  3476. int qp_idx = 0;
  3477. /* If we don't have enough vectors for a 1-to-1 mapping, we'll have to
  3478. * group them so there are multiple queues per vector.
  3479. * It is also important to go through all the vectors available to be
  3480. * sure that if we don't use all the vectors, that the remaining vectors
  3481. * are cleared. This is especially important when decreasing the
  3482. * number of queues in use.
  3483. */
  3484. for (; v_start < q_vectors; v_start++) {
  3485. struct i40e_q_vector *q_vector = vsi->q_vectors[v_start];
  3486. num_ringpairs = DIV_ROUND_UP(qp_remaining, q_vectors - v_start);
  3487. q_vector->num_ringpairs = num_ringpairs;
  3488. q_vector->rx.count = 0;
  3489. q_vector->tx.count = 0;
  3490. q_vector->rx.ring = NULL;
  3491. q_vector->tx.ring = NULL;
  3492. while (num_ringpairs--) {
  3493. i40e_map_vector_to_qp(vsi, v_start, qp_idx);
  3494. qp_idx++;
  3495. qp_remaining--;
  3496. }
  3497. }
  3498. }
  3499. /**
  3500. * i40e_vsi_request_irq - Request IRQ from the OS
  3501. * @vsi: the VSI being configured
  3502. * @basename: name for the vector
  3503. **/
  3504. static int i40e_vsi_request_irq(struct i40e_vsi *vsi, char *basename)
  3505. {
  3506. struct i40e_pf *pf = vsi->back;
  3507. int err;
  3508. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  3509. err = i40e_vsi_request_irq_msix(vsi, basename);
  3510. else if (pf->flags & I40E_FLAG_MSI_ENABLED)
  3511. err = request_irq(pf->pdev->irq, i40e_intr, 0,
  3512. pf->int_name, pf);
  3513. else
  3514. err = request_irq(pf->pdev->irq, i40e_intr, IRQF_SHARED,
  3515. pf->int_name, pf);
  3516. if (err)
  3517. dev_info(&pf->pdev->dev, "request_irq failed, Error %d\n", err);
  3518. return err;
  3519. }
  3520. #ifdef CONFIG_NET_POLL_CONTROLLER
  3521. /**
  3522. * i40e_netpoll - A Polling 'interrupt' handler
  3523. * @netdev: network interface device structure
  3524. *
  3525. * This is used by netconsole to send skbs without having to re-enable
  3526. * interrupts. It's not called while the normal interrupt routine is executing.
  3527. **/
  3528. #ifdef I40E_FCOE
  3529. void i40e_netpoll(struct net_device *netdev)
  3530. #else
  3531. static void i40e_netpoll(struct net_device *netdev)
  3532. #endif
  3533. {
  3534. struct i40e_netdev_priv *np = netdev_priv(netdev);
  3535. struct i40e_vsi *vsi = np->vsi;
  3536. struct i40e_pf *pf = vsi->back;
  3537. int i;
  3538. /* if interface is down do nothing */
  3539. if (test_bit(__I40E_DOWN, &vsi->state))
  3540. return;
  3541. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3542. for (i = 0; i < vsi->num_q_vectors; i++)
  3543. i40e_msix_clean_rings(0, vsi->q_vectors[i]);
  3544. } else {
  3545. i40e_intr(pf->pdev->irq, netdev);
  3546. }
  3547. }
  3548. #endif
  3549. /**
  3550. * i40e_pf_txq_wait - Wait for a PF's Tx queue to be enabled or disabled
  3551. * @pf: the PF being configured
  3552. * @pf_q: the PF queue
  3553. * @enable: enable or disable state of the queue
  3554. *
  3555. * This routine will wait for the given Tx queue of the PF to reach the
  3556. * enabled or disabled state.
  3557. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  3558. * multiple retries; else will return 0 in case of success.
  3559. **/
  3560. static int i40e_pf_txq_wait(struct i40e_pf *pf, int pf_q, bool enable)
  3561. {
  3562. int i;
  3563. u32 tx_reg;
  3564. for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
  3565. tx_reg = rd32(&pf->hw, I40E_QTX_ENA(pf_q));
  3566. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  3567. break;
  3568. usleep_range(10, 20);
  3569. }
  3570. if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
  3571. return -ETIMEDOUT;
  3572. return 0;
  3573. }
  3574. /**
  3575. * i40e_vsi_control_tx - Start or stop a VSI's rings
  3576. * @vsi: the VSI being configured
  3577. * @enable: start or stop the rings
  3578. **/
  3579. static int i40e_vsi_control_tx(struct i40e_vsi *vsi, bool enable)
  3580. {
  3581. struct i40e_pf *pf = vsi->back;
  3582. struct i40e_hw *hw = &pf->hw;
  3583. int i, j, pf_q, ret = 0;
  3584. u32 tx_reg;
  3585. pf_q = vsi->base_queue;
  3586. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3587. /* warn the TX unit of coming changes */
  3588. i40e_pre_tx_queue_cfg(&pf->hw, pf_q, enable);
  3589. if (!enable)
  3590. usleep_range(10, 20);
  3591. for (j = 0; j < 50; j++) {
  3592. tx_reg = rd32(hw, I40E_QTX_ENA(pf_q));
  3593. if (((tx_reg >> I40E_QTX_ENA_QENA_REQ_SHIFT) & 1) ==
  3594. ((tx_reg >> I40E_QTX_ENA_QENA_STAT_SHIFT) & 1))
  3595. break;
  3596. usleep_range(1000, 2000);
  3597. }
  3598. /* Skip if the queue is already in the requested state */
  3599. if (enable == !!(tx_reg & I40E_QTX_ENA_QENA_STAT_MASK))
  3600. continue;
  3601. /* turn on/off the queue */
  3602. if (enable) {
  3603. wr32(hw, I40E_QTX_HEAD(pf_q), 0);
  3604. tx_reg |= I40E_QTX_ENA_QENA_REQ_MASK;
  3605. } else {
  3606. tx_reg &= ~I40E_QTX_ENA_QENA_REQ_MASK;
  3607. }
  3608. wr32(hw, I40E_QTX_ENA(pf_q), tx_reg);
  3609. /* No waiting for the Tx queue to disable */
  3610. if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state))
  3611. continue;
  3612. /* wait for the change to finish */
  3613. ret = i40e_pf_txq_wait(pf, pf_q, enable);
  3614. if (ret) {
  3615. dev_info(&pf->pdev->dev,
  3616. "VSI seid %d Tx ring %d %sable timeout\n",
  3617. vsi->seid, pf_q, (enable ? "en" : "dis"));
  3618. break;
  3619. }
  3620. }
  3621. if (hw->revision_id == 0)
  3622. mdelay(50);
  3623. return ret;
  3624. }
  3625. /**
  3626. * i40e_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
  3627. * @pf: the PF being configured
  3628. * @pf_q: the PF queue
  3629. * @enable: enable or disable state of the queue
  3630. *
  3631. * This routine will wait for the given Rx queue of the PF to reach the
  3632. * enabled or disabled state.
  3633. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  3634. * multiple retries; else will return 0 in case of success.
  3635. **/
  3636. static int i40e_pf_rxq_wait(struct i40e_pf *pf, int pf_q, bool enable)
  3637. {
  3638. int i;
  3639. u32 rx_reg;
  3640. for (i = 0; i < I40E_QUEUE_WAIT_RETRY_LIMIT; i++) {
  3641. rx_reg = rd32(&pf->hw, I40E_QRX_ENA(pf_q));
  3642. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  3643. break;
  3644. usleep_range(10, 20);
  3645. }
  3646. if (i >= I40E_QUEUE_WAIT_RETRY_LIMIT)
  3647. return -ETIMEDOUT;
  3648. return 0;
  3649. }
  3650. /**
  3651. * i40e_vsi_control_rx - Start or stop a VSI's rings
  3652. * @vsi: the VSI being configured
  3653. * @enable: start or stop the rings
  3654. **/
  3655. static int i40e_vsi_control_rx(struct i40e_vsi *vsi, bool enable)
  3656. {
  3657. struct i40e_pf *pf = vsi->back;
  3658. struct i40e_hw *hw = &pf->hw;
  3659. int i, j, pf_q, ret = 0;
  3660. u32 rx_reg;
  3661. pf_q = vsi->base_queue;
  3662. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  3663. for (j = 0; j < 50; j++) {
  3664. rx_reg = rd32(hw, I40E_QRX_ENA(pf_q));
  3665. if (((rx_reg >> I40E_QRX_ENA_QENA_REQ_SHIFT) & 1) ==
  3666. ((rx_reg >> I40E_QRX_ENA_QENA_STAT_SHIFT) & 1))
  3667. break;
  3668. usleep_range(1000, 2000);
  3669. }
  3670. /* Skip if the queue is already in the requested state */
  3671. if (enable == !!(rx_reg & I40E_QRX_ENA_QENA_STAT_MASK))
  3672. continue;
  3673. /* turn on/off the queue */
  3674. if (enable)
  3675. rx_reg |= I40E_QRX_ENA_QENA_REQ_MASK;
  3676. else
  3677. rx_reg &= ~I40E_QRX_ENA_QENA_REQ_MASK;
  3678. wr32(hw, I40E_QRX_ENA(pf_q), rx_reg);
  3679. /* No waiting for the Tx queue to disable */
  3680. if (!enable && test_bit(__I40E_PORT_TX_SUSPENDED, &pf->state))
  3681. continue;
  3682. /* wait for the change to finish */
  3683. ret = i40e_pf_rxq_wait(pf, pf_q, enable);
  3684. if (ret) {
  3685. dev_info(&pf->pdev->dev,
  3686. "VSI seid %d Rx ring %d %sable timeout\n",
  3687. vsi->seid, pf_q, (enable ? "en" : "dis"));
  3688. break;
  3689. }
  3690. }
  3691. return ret;
  3692. }
  3693. /**
  3694. * i40e_vsi_start_rings - Start a VSI's rings
  3695. * @vsi: the VSI being configured
  3696. **/
  3697. int i40e_vsi_start_rings(struct i40e_vsi *vsi)
  3698. {
  3699. int ret = 0;
  3700. /* do rx first for enable and last for disable */
  3701. ret = i40e_vsi_control_rx(vsi, true);
  3702. if (ret)
  3703. return ret;
  3704. ret = i40e_vsi_control_tx(vsi, true);
  3705. return ret;
  3706. }
  3707. /**
  3708. * i40e_vsi_stop_rings - Stop a VSI's rings
  3709. * @vsi: the VSI being configured
  3710. **/
  3711. void i40e_vsi_stop_rings(struct i40e_vsi *vsi)
  3712. {
  3713. /* do rx first for enable and last for disable
  3714. * Ignore return value, we need to shutdown whatever we can
  3715. */
  3716. i40e_vsi_control_tx(vsi, false);
  3717. i40e_vsi_control_rx(vsi, false);
  3718. }
  3719. /**
  3720. * i40e_vsi_free_irq - Free the irq association with the OS
  3721. * @vsi: the VSI being configured
  3722. **/
  3723. static void i40e_vsi_free_irq(struct i40e_vsi *vsi)
  3724. {
  3725. struct i40e_pf *pf = vsi->back;
  3726. struct i40e_hw *hw = &pf->hw;
  3727. int base = vsi->base_vector;
  3728. u32 val, qp;
  3729. int i;
  3730. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3731. if (!vsi->q_vectors)
  3732. return;
  3733. if (!vsi->irqs_ready)
  3734. return;
  3735. vsi->irqs_ready = false;
  3736. for (i = 0; i < vsi->num_q_vectors; i++) {
  3737. int irq_num;
  3738. u16 vector;
  3739. vector = i + base;
  3740. irq_num = pf->msix_entries[vector].vector;
  3741. /* free only the irqs that were actually requested */
  3742. if (!vsi->q_vectors[i] ||
  3743. !vsi->q_vectors[i]->num_ringpairs)
  3744. continue;
  3745. /* clear the affinity notifier in the IRQ descriptor */
  3746. irq_set_affinity_notifier(irq_num, NULL);
  3747. /* clear the affinity_mask in the IRQ descriptor */
  3748. irq_set_affinity_hint(irq_num, NULL);
  3749. synchronize_irq(irq_num);
  3750. free_irq(irq_num, vsi->q_vectors[i]);
  3751. /* Tear down the interrupt queue link list
  3752. *
  3753. * We know that they come in pairs and always
  3754. * the Rx first, then the Tx. To clear the
  3755. * link list, stick the EOL value into the
  3756. * next_q field of the registers.
  3757. */
  3758. val = rd32(hw, I40E_PFINT_LNKLSTN(vector - 1));
  3759. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  3760. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3761. val |= I40E_QUEUE_END_OF_LIST
  3762. << I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3763. wr32(hw, I40E_PFINT_LNKLSTN(vector - 1), val);
  3764. while (qp != I40E_QUEUE_END_OF_LIST) {
  3765. u32 next;
  3766. val = rd32(hw, I40E_QINT_RQCTL(qp));
  3767. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  3768. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  3769. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3770. I40E_QINT_RQCTL_INTEVENT_MASK);
  3771. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  3772. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  3773. wr32(hw, I40E_QINT_RQCTL(qp), val);
  3774. val = rd32(hw, I40E_QINT_TQCTL(qp));
  3775. next = (val & I40E_QINT_TQCTL_NEXTQ_INDX_MASK)
  3776. >> I40E_QINT_TQCTL_NEXTQ_INDX_SHIFT;
  3777. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  3778. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  3779. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3780. I40E_QINT_TQCTL_INTEVENT_MASK);
  3781. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  3782. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  3783. wr32(hw, I40E_QINT_TQCTL(qp), val);
  3784. qp = next;
  3785. }
  3786. }
  3787. } else {
  3788. free_irq(pf->pdev->irq, pf);
  3789. val = rd32(hw, I40E_PFINT_LNKLST0);
  3790. qp = (val & I40E_PFINT_LNKLSTN_FIRSTQ_INDX_MASK)
  3791. >> I40E_PFINT_LNKLSTN_FIRSTQ_INDX_SHIFT;
  3792. val |= I40E_QUEUE_END_OF_LIST
  3793. << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
  3794. wr32(hw, I40E_PFINT_LNKLST0, val);
  3795. val = rd32(hw, I40E_QINT_RQCTL(qp));
  3796. val &= ~(I40E_QINT_RQCTL_MSIX_INDX_MASK |
  3797. I40E_QINT_RQCTL_MSIX0_INDX_MASK |
  3798. I40E_QINT_RQCTL_CAUSE_ENA_MASK |
  3799. I40E_QINT_RQCTL_INTEVENT_MASK);
  3800. val |= (I40E_QINT_RQCTL_ITR_INDX_MASK |
  3801. I40E_QINT_RQCTL_NEXTQ_INDX_MASK);
  3802. wr32(hw, I40E_QINT_RQCTL(qp), val);
  3803. val = rd32(hw, I40E_QINT_TQCTL(qp));
  3804. val &= ~(I40E_QINT_TQCTL_MSIX_INDX_MASK |
  3805. I40E_QINT_TQCTL_MSIX0_INDX_MASK |
  3806. I40E_QINT_TQCTL_CAUSE_ENA_MASK |
  3807. I40E_QINT_TQCTL_INTEVENT_MASK);
  3808. val |= (I40E_QINT_TQCTL_ITR_INDX_MASK |
  3809. I40E_QINT_TQCTL_NEXTQ_INDX_MASK);
  3810. wr32(hw, I40E_QINT_TQCTL(qp), val);
  3811. }
  3812. }
  3813. /**
  3814. * i40e_free_q_vector - Free memory allocated for specific interrupt vector
  3815. * @vsi: the VSI being configured
  3816. * @v_idx: Index of vector to be freed
  3817. *
  3818. * This function frees the memory allocated to the q_vector. In addition if
  3819. * NAPI is enabled it will delete any references to the NAPI struct prior
  3820. * to freeing the q_vector.
  3821. **/
  3822. static void i40e_free_q_vector(struct i40e_vsi *vsi, int v_idx)
  3823. {
  3824. struct i40e_q_vector *q_vector = vsi->q_vectors[v_idx];
  3825. struct i40e_ring *ring;
  3826. if (!q_vector)
  3827. return;
  3828. /* disassociate q_vector from rings */
  3829. i40e_for_each_ring(ring, q_vector->tx)
  3830. ring->q_vector = NULL;
  3831. i40e_for_each_ring(ring, q_vector->rx)
  3832. ring->q_vector = NULL;
  3833. /* only VSI w/ an associated netdev is set up w/ NAPI */
  3834. if (vsi->netdev)
  3835. netif_napi_del(&q_vector->napi);
  3836. vsi->q_vectors[v_idx] = NULL;
  3837. kfree_rcu(q_vector, rcu);
  3838. }
  3839. /**
  3840. * i40e_vsi_free_q_vectors - Free memory allocated for interrupt vectors
  3841. * @vsi: the VSI being un-configured
  3842. *
  3843. * This frees the memory allocated to the q_vectors and
  3844. * deletes references to the NAPI struct.
  3845. **/
  3846. static void i40e_vsi_free_q_vectors(struct i40e_vsi *vsi)
  3847. {
  3848. int v_idx;
  3849. for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++)
  3850. i40e_free_q_vector(vsi, v_idx);
  3851. }
  3852. /**
  3853. * i40e_reset_interrupt_capability - Disable interrupt setup in OS
  3854. * @pf: board private structure
  3855. **/
  3856. static void i40e_reset_interrupt_capability(struct i40e_pf *pf)
  3857. {
  3858. /* If we're in Legacy mode, the interrupt was cleaned in vsi_close */
  3859. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  3860. pci_disable_msix(pf->pdev);
  3861. kfree(pf->msix_entries);
  3862. pf->msix_entries = NULL;
  3863. kfree(pf->irq_pile);
  3864. pf->irq_pile = NULL;
  3865. } else if (pf->flags & I40E_FLAG_MSI_ENABLED) {
  3866. pci_disable_msi(pf->pdev);
  3867. }
  3868. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED);
  3869. }
  3870. /**
  3871. * i40e_clear_interrupt_scheme - Clear the current interrupt scheme settings
  3872. * @pf: board private structure
  3873. *
  3874. * We go through and clear interrupt specific resources and reset the structure
  3875. * to pre-load conditions
  3876. **/
  3877. static void i40e_clear_interrupt_scheme(struct i40e_pf *pf)
  3878. {
  3879. int i;
  3880. i40e_stop_misc_vector(pf);
  3881. if (pf->flags & I40E_FLAG_MSIX_ENABLED && pf->msix_entries) {
  3882. synchronize_irq(pf->msix_entries[0].vector);
  3883. free_irq(pf->msix_entries[0].vector, pf);
  3884. }
  3885. i40e_put_lump(pf->irq_pile, pf->iwarp_base_vector,
  3886. I40E_IWARP_IRQ_PILE_ID);
  3887. i40e_put_lump(pf->irq_pile, 0, I40E_PILE_VALID_BIT-1);
  3888. for (i = 0; i < pf->num_alloc_vsi; i++)
  3889. if (pf->vsi[i])
  3890. i40e_vsi_free_q_vectors(pf->vsi[i]);
  3891. i40e_reset_interrupt_capability(pf);
  3892. }
  3893. /**
  3894. * i40e_napi_enable_all - Enable NAPI for all q_vectors in the VSI
  3895. * @vsi: the VSI being configured
  3896. **/
  3897. static void i40e_napi_enable_all(struct i40e_vsi *vsi)
  3898. {
  3899. int q_idx;
  3900. if (!vsi->netdev)
  3901. return;
  3902. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
  3903. napi_enable(&vsi->q_vectors[q_idx]->napi);
  3904. }
  3905. /**
  3906. * i40e_napi_disable_all - Disable NAPI for all q_vectors in the VSI
  3907. * @vsi: the VSI being configured
  3908. **/
  3909. static void i40e_napi_disable_all(struct i40e_vsi *vsi)
  3910. {
  3911. int q_idx;
  3912. if (!vsi->netdev)
  3913. return;
  3914. for (q_idx = 0; q_idx < vsi->num_q_vectors; q_idx++)
  3915. napi_disable(&vsi->q_vectors[q_idx]->napi);
  3916. }
  3917. /**
  3918. * i40e_vsi_close - Shut down a VSI
  3919. * @vsi: the vsi to be quelled
  3920. **/
  3921. static void i40e_vsi_close(struct i40e_vsi *vsi)
  3922. {
  3923. struct i40e_pf *pf = vsi->back;
  3924. if (!test_and_set_bit(__I40E_DOWN, &vsi->state))
  3925. i40e_down(vsi);
  3926. i40e_vsi_free_irq(vsi);
  3927. i40e_vsi_free_tx_resources(vsi);
  3928. i40e_vsi_free_rx_resources(vsi);
  3929. vsi->current_netdev_flags = 0;
  3930. pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  3931. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
  3932. pf->flags |= I40E_FLAG_CLIENT_RESET;
  3933. }
  3934. /**
  3935. * i40e_quiesce_vsi - Pause a given VSI
  3936. * @vsi: the VSI being paused
  3937. **/
  3938. static void i40e_quiesce_vsi(struct i40e_vsi *vsi)
  3939. {
  3940. if (test_bit(__I40E_DOWN, &vsi->state))
  3941. return;
  3942. /* No need to disable FCoE VSI when Tx suspended */
  3943. if ((test_bit(__I40E_PORT_TX_SUSPENDED, &vsi->back->state)) &&
  3944. vsi->type == I40E_VSI_FCOE) {
  3945. dev_dbg(&vsi->back->pdev->dev,
  3946. "VSI seid %d skipping FCoE VSI disable\n", vsi->seid);
  3947. return;
  3948. }
  3949. set_bit(__I40E_NEEDS_RESTART, &vsi->state);
  3950. if (vsi->netdev && netif_running(vsi->netdev))
  3951. vsi->netdev->netdev_ops->ndo_stop(vsi->netdev);
  3952. else
  3953. i40e_vsi_close(vsi);
  3954. }
  3955. /**
  3956. * i40e_unquiesce_vsi - Resume a given VSI
  3957. * @vsi: the VSI being resumed
  3958. **/
  3959. static void i40e_unquiesce_vsi(struct i40e_vsi *vsi)
  3960. {
  3961. if (!test_bit(__I40E_NEEDS_RESTART, &vsi->state))
  3962. return;
  3963. clear_bit(__I40E_NEEDS_RESTART, &vsi->state);
  3964. if (vsi->netdev && netif_running(vsi->netdev))
  3965. vsi->netdev->netdev_ops->ndo_open(vsi->netdev);
  3966. else
  3967. i40e_vsi_open(vsi); /* this clears the DOWN bit */
  3968. }
  3969. /**
  3970. * i40e_pf_quiesce_all_vsi - Pause all VSIs on a PF
  3971. * @pf: the PF
  3972. **/
  3973. static void i40e_pf_quiesce_all_vsi(struct i40e_pf *pf)
  3974. {
  3975. int v;
  3976. for (v = 0; v < pf->num_alloc_vsi; v++) {
  3977. if (pf->vsi[v])
  3978. i40e_quiesce_vsi(pf->vsi[v]);
  3979. }
  3980. }
  3981. /**
  3982. * i40e_pf_unquiesce_all_vsi - Resume all VSIs on a PF
  3983. * @pf: the PF
  3984. **/
  3985. static void i40e_pf_unquiesce_all_vsi(struct i40e_pf *pf)
  3986. {
  3987. int v;
  3988. for (v = 0; v < pf->num_alloc_vsi; v++) {
  3989. if (pf->vsi[v])
  3990. i40e_unquiesce_vsi(pf->vsi[v]);
  3991. }
  3992. }
  3993. #ifdef CONFIG_I40E_DCB
  3994. /**
  3995. * i40e_vsi_wait_queues_disabled - Wait for VSI's queues to be disabled
  3996. * @vsi: the VSI being configured
  3997. *
  3998. * This function waits for the given VSI's queues to be disabled.
  3999. **/
  4000. static int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi)
  4001. {
  4002. struct i40e_pf *pf = vsi->back;
  4003. int i, pf_q, ret;
  4004. pf_q = vsi->base_queue;
  4005. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  4006. /* Check and wait for the disable status of the queue */
  4007. ret = i40e_pf_txq_wait(pf, pf_q, false);
  4008. if (ret) {
  4009. dev_info(&pf->pdev->dev,
  4010. "VSI seid %d Tx ring %d disable timeout\n",
  4011. vsi->seid, pf_q);
  4012. return ret;
  4013. }
  4014. }
  4015. pf_q = vsi->base_queue;
  4016. for (i = 0; i < vsi->num_queue_pairs; i++, pf_q++) {
  4017. /* Check and wait for the disable status of the queue */
  4018. ret = i40e_pf_rxq_wait(pf, pf_q, false);
  4019. if (ret) {
  4020. dev_info(&pf->pdev->dev,
  4021. "VSI seid %d Rx ring %d disable timeout\n",
  4022. vsi->seid, pf_q);
  4023. return ret;
  4024. }
  4025. }
  4026. return 0;
  4027. }
  4028. /**
  4029. * i40e_pf_wait_queues_disabled - Wait for all queues of PF VSIs to be disabled
  4030. * @pf: the PF
  4031. *
  4032. * This function waits for the queues to be in disabled state for all the
  4033. * VSIs that are managed by this PF.
  4034. **/
  4035. static int i40e_pf_wait_queues_disabled(struct i40e_pf *pf)
  4036. {
  4037. int v, ret = 0;
  4038. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  4039. /* No need to wait for FCoE VSI queues */
  4040. if (pf->vsi[v] && pf->vsi[v]->type != I40E_VSI_FCOE) {
  4041. ret = i40e_vsi_wait_queues_disabled(pf->vsi[v]);
  4042. if (ret)
  4043. break;
  4044. }
  4045. }
  4046. return ret;
  4047. }
  4048. #endif
  4049. /**
  4050. * i40e_detect_recover_hung_queue - Function to detect and recover hung_queue
  4051. * @q_idx: TX queue number
  4052. * @vsi: Pointer to VSI struct
  4053. *
  4054. * This function checks specified queue for given VSI. Detects hung condition.
  4055. * Sets hung bit since it is two step process. Before next run of service task
  4056. * if napi_poll runs, it reset 'hung' bit for respective q_vector. If not,
  4057. * hung condition remain unchanged and during subsequent run, this function
  4058. * issues SW interrupt to recover from hung condition.
  4059. **/
  4060. static void i40e_detect_recover_hung_queue(int q_idx, struct i40e_vsi *vsi)
  4061. {
  4062. struct i40e_ring *tx_ring = NULL;
  4063. struct i40e_pf *pf;
  4064. u32 head, val, tx_pending_hw;
  4065. int i;
  4066. pf = vsi->back;
  4067. /* now that we have an index, find the tx_ring struct */
  4068. for (i = 0; i < vsi->num_queue_pairs; i++) {
  4069. if (vsi->tx_rings[i] && vsi->tx_rings[i]->desc) {
  4070. if (q_idx == vsi->tx_rings[i]->queue_index) {
  4071. tx_ring = vsi->tx_rings[i];
  4072. break;
  4073. }
  4074. }
  4075. }
  4076. if (!tx_ring)
  4077. return;
  4078. /* Read interrupt register */
  4079. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  4080. val = rd32(&pf->hw,
  4081. I40E_PFINT_DYN_CTLN(tx_ring->q_vector->v_idx +
  4082. tx_ring->vsi->base_vector - 1));
  4083. else
  4084. val = rd32(&pf->hw, I40E_PFINT_DYN_CTL0);
  4085. head = i40e_get_head(tx_ring);
  4086. tx_pending_hw = i40e_get_tx_pending(tx_ring, false);
  4087. /* HW is done executing descriptors, updated HEAD write back,
  4088. * but SW hasn't processed those descriptors. If interrupt is
  4089. * not generated from this point ON, it could result into
  4090. * dev_watchdog detecting timeout on those netdev_queue,
  4091. * hence proactively trigger SW interrupt.
  4092. */
  4093. if (tx_pending_hw && (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) {
  4094. /* NAPI Poll didn't run and clear since it was set */
  4095. if (test_and_clear_bit(I40E_Q_VECTOR_HUNG_DETECT,
  4096. &tx_ring->q_vector->hung_detected)) {
  4097. 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",
  4098. vsi->seid, q_idx, tx_pending_hw,
  4099. tx_ring->next_to_clean, head,
  4100. tx_ring->next_to_use,
  4101. readl(tx_ring->tail));
  4102. netdev_info(vsi->netdev, "VSI_seid %d, Issuing force_wb for TX queue %d, Interrupt Reg: 0x%x\n",
  4103. vsi->seid, q_idx, val);
  4104. i40e_force_wb(vsi, tx_ring->q_vector);
  4105. } else {
  4106. /* First Chance - detected possible hung */
  4107. set_bit(I40E_Q_VECTOR_HUNG_DETECT,
  4108. &tx_ring->q_vector->hung_detected);
  4109. }
  4110. }
  4111. /* This is the case where we have interrupts missing,
  4112. * so the tx_pending in HW will most likely be 0, but we
  4113. * will have tx_pending in SW since the WB happened but the
  4114. * interrupt got lost.
  4115. */
  4116. if ((!tx_pending_hw) && i40e_get_tx_pending(tx_ring, true) &&
  4117. (!(val & I40E_PFINT_DYN_CTLN_INTENA_MASK))) {
  4118. local_bh_disable();
  4119. if (napi_reschedule(&tx_ring->q_vector->napi))
  4120. tx_ring->tx_stats.tx_lost_interrupt++;
  4121. local_bh_enable();
  4122. }
  4123. }
  4124. /**
  4125. * i40e_detect_recover_hung - Function to detect and recover hung_queues
  4126. * @pf: pointer to PF struct
  4127. *
  4128. * LAN VSI has netdev and netdev has TX queues. This function is to check
  4129. * each of those TX queues if they are hung, trigger recovery by issuing
  4130. * SW interrupt.
  4131. **/
  4132. static void i40e_detect_recover_hung(struct i40e_pf *pf)
  4133. {
  4134. struct net_device *netdev;
  4135. struct i40e_vsi *vsi;
  4136. int i;
  4137. /* Only for LAN VSI */
  4138. vsi = pf->vsi[pf->lan_vsi];
  4139. if (!vsi)
  4140. return;
  4141. /* Make sure, VSI state is not DOWN/RECOVERY_PENDING */
  4142. if (test_bit(__I40E_DOWN, &vsi->back->state) ||
  4143. test_bit(__I40E_RESET_RECOVERY_PENDING, &vsi->back->state))
  4144. return;
  4145. /* Make sure type is MAIN VSI */
  4146. if (vsi->type != I40E_VSI_MAIN)
  4147. return;
  4148. netdev = vsi->netdev;
  4149. if (!netdev)
  4150. return;
  4151. /* Bail out if netif_carrier is not OK */
  4152. if (!netif_carrier_ok(netdev))
  4153. return;
  4154. /* Go thru' TX queues for netdev */
  4155. for (i = 0; i < netdev->num_tx_queues; i++) {
  4156. struct netdev_queue *q;
  4157. q = netdev_get_tx_queue(netdev, i);
  4158. if (q)
  4159. i40e_detect_recover_hung_queue(i, vsi);
  4160. }
  4161. }
  4162. /**
  4163. * i40e_get_iscsi_tc_map - Return TC map for iSCSI APP
  4164. * @pf: pointer to PF
  4165. *
  4166. * Get TC map for ISCSI PF type that will include iSCSI TC
  4167. * and LAN TC.
  4168. **/
  4169. static u8 i40e_get_iscsi_tc_map(struct i40e_pf *pf)
  4170. {
  4171. struct i40e_dcb_app_priority_table app;
  4172. struct i40e_hw *hw = &pf->hw;
  4173. u8 enabled_tc = 1; /* TC0 is always enabled */
  4174. u8 tc, i;
  4175. /* Get the iSCSI APP TLV */
  4176. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4177. for (i = 0; i < dcbcfg->numapps; i++) {
  4178. app = dcbcfg->app[i];
  4179. if (app.selector == I40E_APP_SEL_TCPIP &&
  4180. app.protocolid == I40E_APP_PROTOID_ISCSI) {
  4181. tc = dcbcfg->etscfg.prioritytable[app.priority];
  4182. enabled_tc |= BIT(tc);
  4183. break;
  4184. }
  4185. }
  4186. return enabled_tc;
  4187. }
  4188. /**
  4189. * i40e_dcb_get_num_tc - Get the number of TCs from DCBx config
  4190. * @dcbcfg: the corresponding DCBx configuration structure
  4191. *
  4192. * Return the number of TCs from given DCBx configuration
  4193. **/
  4194. static u8 i40e_dcb_get_num_tc(struct i40e_dcbx_config *dcbcfg)
  4195. {
  4196. int i, tc_unused = 0;
  4197. u8 num_tc = 0;
  4198. u8 ret = 0;
  4199. /* Scan the ETS Config Priority Table to find
  4200. * traffic class enabled for a given priority
  4201. * and create a bitmask of enabled TCs
  4202. */
  4203. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++)
  4204. num_tc |= BIT(dcbcfg->etscfg.prioritytable[i]);
  4205. /* Now scan the bitmask to check for
  4206. * contiguous TCs starting with TC0
  4207. */
  4208. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4209. if (num_tc & BIT(i)) {
  4210. if (!tc_unused) {
  4211. ret++;
  4212. } else {
  4213. pr_err("Non-contiguous TC - Disabling DCB\n");
  4214. return 1;
  4215. }
  4216. } else {
  4217. tc_unused = 1;
  4218. }
  4219. }
  4220. /* There is always at least TC0 */
  4221. if (!ret)
  4222. ret = 1;
  4223. return ret;
  4224. }
  4225. /**
  4226. * i40e_dcb_get_enabled_tc - Get enabled traffic classes
  4227. * @dcbcfg: the corresponding DCBx configuration structure
  4228. *
  4229. * Query the current DCB configuration and return the number of
  4230. * traffic classes enabled from the given DCBX config
  4231. **/
  4232. static u8 i40e_dcb_get_enabled_tc(struct i40e_dcbx_config *dcbcfg)
  4233. {
  4234. u8 num_tc = i40e_dcb_get_num_tc(dcbcfg);
  4235. u8 enabled_tc = 1;
  4236. u8 i;
  4237. for (i = 0; i < num_tc; i++)
  4238. enabled_tc |= BIT(i);
  4239. return enabled_tc;
  4240. }
  4241. /**
  4242. * i40e_pf_get_num_tc - Get enabled traffic classes for PF
  4243. * @pf: PF being queried
  4244. *
  4245. * Return number of traffic classes enabled for the given PF
  4246. **/
  4247. static u8 i40e_pf_get_num_tc(struct i40e_pf *pf)
  4248. {
  4249. struct i40e_hw *hw = &pf->hw;
  4250. u8 i, enabled_tc = 1;
  4251. u8 num_tc = 0;
  4252. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4253. /* If DCB is not enabled then always in single TC */
  4254. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  4255. return 1;
  4256. /* SFP mode will be enabled for all TCs on port */
  4257. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  4258. return i40e_dcb_get_num_tc(dcbcfg);
  4259. /* MFP mode return count of enabled TCs for this PF */
  4260. if (pf->hw.func_caps.iscsi)
  4261. enabled_tc = i40e_get_iscsi_tc_map(pf);
  4262. else
  4263. return 1; /* Only TC0 */
  4264. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4265. if (enabled_tc & BIT(i))
  4266. num_tc++;
  4267. }
  4268. return num_tc;
  4269. }
  4270. /**
  4271. * i40e_pf_get_pf_tc_map - Get bitmap for enabled traffic classes
  4272. * @pf: PF being queried
  4273. *
  4274. * Return a bitmap for enabled traffic classes for this PF.
  4275. **/
  4276. static u8 i40e_pf_get_tc_map(struct i40e_pf *pf)
  4277. {
  4278. /* If DCB is not enabled for this PF then just return default TC */
  4279. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  4280. return I40E_DEFAULT_TRAFFIC_CLASS;
  4281. /* SFP mode we want PF to be enabled for all TCs */
  4282. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  4283. return i40e_dcb_get_enabled_tc(&pf->hw.local_dcbx_config);
  4284. /* MFP enabled and iSCSI PF type */
  4285. if (pf->hw.func_caps.iscsi)
  4286. return i40e_get_iscsi_tc_map(pf);
  4287. else
  4288. return I40E_DEFAULT_TRAFFIC_CLASS;
  4289. }
  4290. /**
  4291. * i40e_vsi_get_bw_info - Query VSI BW Information
  4292. * @vsi: the VSI being queried
  4293. *
  4294. * Returns 0 on success, negative value on failure
  4295. **/
  4296. static int i40e_vsi_get_bw_info(struct i40e_vsi *vsi)
  4297. {
  4298. struct i40e_aqc_query_vsi_ets_sla_config_resp bw_ets_config = {0};
  4299. struct i40e_aqc_query_vsi_bw_config_resp bw_config = {0};
  4300. struct i40e_pf *pf = vsi->back;
  4301. struct i40e_hw *hw = &pf->hw;
  4302. i40e_status ret;
  4303. u32 tc_bw_max;
  4304. int i;
  4305. /* Get the VSI level BW configuration */
  4306. ret = i40e_aq_query_vsi_bw_config(hw, vsi->seid, &bw_config, NULL);
  4307. if (ret) {
  4308. dev_info(&pf->pdev->dev,
  4309. "couldn't get PF vsi bw config, err %s aq_err %s\n",
  4310. i40e_stat_str(&pf->hw, ret),
  4311. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4312. return -EINVAL;
  4313. }
  4314. /* Get the VSI level BW configuration per TC */
  4315. ret = i40e_aq_query_vsi_ets_sla_config(hw, vsi->seid, &bw_ets_config,
  4316. NULL);
  4317. if (ret) {
  4318. dev_info(&pf->pdev->dev,
  4319. "couldn't get PF vsi ets bw config, err %s aq_err %s\n",
  4320. i40e_stat_str(&pf->hw, ret),
  4321. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4322. return -EINVAL;
  4323. }
  4324. if (bw_config.tc_valid_bits != bw_ets_config.tc_valid_bits) {
  4325. dev_info(&pf->pdev->dev,
  4326. "Enabled TCs mismatch from querying VSI BW info 0x%08x 0x%08x\n",
  4327. bw_config.tc_valid_bits,
  4328. bw_ets_config.tc_valid_bits);
  4329. /* Still continuing */
  4330. }
  4331. vsi->bw_limit = le16_to_cpu(bw_config.port_bw_limit);
  4332. vsi->bw_max_quanta = bw_config.max_bw;
  4333. tc_bw_max = le16_to_cpu(bw_ets_config.tc_bw_max[0]) |
  4334. (le16_to_cpu(bw_ets_config.tc_bw_max[1]) << 16);
  4335. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4336. vsi->bw_ets_share_credits[i] = bw_ets_config.share_credits[i];
  4337. vsi->bw_ets_limit_credits[i] =
  4338. le16_to_cpu(bw_ets_config.credits[i]);
  4339. /* 3 bits out of 4 for each TC */
  4340. vsi->bw_ets_max_quanta[i] = (u8)((tc_bw_max >> (i*4)) & 0x7);
  4341. }
  4342. return 0;
  4343. }
  4344. /**
  4345. * i40e_vsi_configure_bw_alloc - Configure VSI BW allocation per TC
  4346. * @vsi: the VSI being configured
  4347. * @enabled_tc: TC bitmap
  4348. * @bw_credits: BW shared credits per TC
  4349. *
  4350. * Returns 0 on success, negative value on failure
  4351. **/
  4352. static int i40e_vsi_configure_bw_alloc(struct i40e_vsi *vsi, u8 enabled_tc,
  4353. u8 *bw_share)
  4354. {
  4355. struct i40e_aqc_configure_vsi_tc_bw_data bw_data;
  4356. i40e_status ret;
  4357. int i;
  4358. bw_data.tc_valid_bits = enabled_tc;
  4359. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  4360. bw_data.tc_bw_credits[i] = bw_share[i];
  4361. ret = i40e_aq_config_vsi_tc_bw(&vsi->back->hw, vsi->seid, &bw_data,
  4362. NULL);
  4363. if (ret) {
  4364. dev_info(&vsi->back->pdev->dev,
  4365. "AQ command Config VSI BW allocation per TC failed = %d\n",
  4366. vsi->back->hw.aq.asq_last_status);
  4367. return -EINVAL;
  4368. }
  4369. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++)
  4370. vsi->info.qs_handle[i] = bw_data.qs_handles[i];
  4371. return 0;
  4372. }
  4373. /**
  4374. * i40e_vsi_config_netdev_tc - Setup the netdev TC configuration
  4375. * @vsi: the VSI being configured
  4376. * @enabled_tc: TC map to be enabled
  4377. *
  4378. **/
  4379. static void i40e_vsi_config_netdev_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  4380. {
  4381. struct net_device *netdev = vsi->netdev;
  4382. struct i40e_pf *pf = vsi->back;
  4383. struct i40e_hw *hw = &pf->hw;
  4384. u8 netdev_tc = 0;
  4385. int i;
  4386. struct i40e_dcbx_config *dcbcfg = &hw->local_dcbx_config;
  4387. if (!netdev)
  4388. return;
  4389. if (!enabled_tc) {
  4390. netdev_reset_tc(netdev);
  4391. return;
  4392. }
  4393. /* Set up actual enabled TCs on the VSI */
  4394. if (netdev_set_num_tc(netdev, vsi->tc_config.numtc))
  4395. return;
  4396. /* set per TC queues for the VSI */
  4397. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4398. /* Only set TC queues for enabled tcs
  4399. *
  4400. * e.g. For a VSI that has TC0 and TC3 enabled the
  4401. * enabled_tc bitmap would be 0x00001001; the driver
  4402. * will set the numtc for netdev as 2 that will be
  4403. * referenced by the netdev layer as TC 0 and 1.
  4404. */
  4405. if (vsi->tc_config.enabled_tc & BIT(i))
  4406. netdev_set_tc_queue(netdev,
  4407. vsi->tc_config.tc_info[i].netdev_tc,
  4408. vsi->tc_config.tc_info[i].qcount,
  4409. vsi->tc_config.tc_info[i].qoffset);
  4410. }
  4411. /* Assign UP2TC map for the VSI */
  4412. for (i = 0; i < I40E_MAX_USER_PRIORITY; i++) {
  4413. /* Get the actual TC# for the UP */
  4414. u8 ets_tc = dcbcfg->etscfg.prioritytable[i];
  4415. /* Get the mapped netdev TC# for the UP */
  4416. netdev_tc = vsi->tc_config.tc_info[ets_tc].netdev_tc;
  4417. netdev_set_prio_tc_map(netdev, i, netdev_tc);
  4418. }
  4419. }
  4420. /**
  4421. * i40e_vsi_update_queue_map - Update our copy of VSi info with new queue map
  4422. * @vsi: the VSI being configured
  4423. * @ctxt: the ctxt buffer returned from AQ VSI update param command
  4424. **/
  4425. static void i40e_vsi_update_queue_map(struct i40e_vsi *vsi,
  4426. struct i40e_vsi_context *ctxt)
  4427. {
  4428. /* copy just the sections touched not the entire info
  4429. * since not all sections are valid as returned by
  4430. * update vsi params
  4431. */
  4432. vsi->info.mapping_flags = ctxt->info.mapping_flags;
  4433. memcpy(&vsi->info.queue_mapping,
  4434. &ctxt->info.queue_mapping, sizeof(vsi->info.queue_mapping));
  4435. memcpy(&vsi->info.tc_mapping, ctxt->info.tc_mapping,
  4436. sizeof(vsi->info.tc_mapping));
  4437. }
  4438. /**
  4439. * i40e_vsi_config_tc - Configure VSI Tx Scheduler for given TC map
  4440. * @vsi: VSI to be configured
  4441. * @enabled_tc: TC bitmap
  4442. *
  4443. * This configures a particular VSI for TCs that are mapped to the
  4444. * given TC bitmap. It uses default bandwidth share for TCs across
  4445. * VSIs to configure TC for a particular VSI.
  4446. *
  4447. * NOTE:
  4448. * It is expected that the VSI queues have been quisced before calling
  4449. * this function.
  4450. **/
  4451. static int i40e_vsi_config_tc(struct i40e_vsi *vsi, u8 enabled_tc)
  4452. {
  4453. u8 bw_share[I40E_MAX_TRAFFIC_CLASS] = {0};
  4454. struct i40e_vsi_context ctxt;
  4455. int ret = 0;
  4456. int i;
  4457. /* Check if enabled_tc is same as existing or new TCs */
  4458. if (vsi->tc_config.enabled_tc == enabled_tc)
  4459. return ret;
  4460. /* Enable ETS TCs with equal BW Share for now across all VSIs */
  4461. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4462. if (enabled_tc & BIT(i))
  4463. bw_share[i] = 1;
  4464. }
  4465. ret = i40e_vsi_configure_bw_alloc(vsi, enabled_tc, bw_share);
  4466. if (ret) {
  4467. dev_info(&vsi->back->pdev->dev,
  4468. "Failed configuring TC map %d for VSI %d\n",
  4469. enabled_tc, vsi->seid);
  4470. goto out;
  4471. }
  4472. /* Update Queue Pairs Mapping for currently enabled UPs */
  4473. ctxt.seid = vsi->seid;
  4474. ctxt.pf_num = vsi->back->hw.pf_id;
  4475. ctxt.vf_num = 0;
  4476. ctxt.uplink_seid = vsi->uplink_seid;
  4477. ctxt.info = vsi->info;
  4478. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  4479. if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
  4480. ctxt.info.valid_sections |=
  4481. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  4482. ctxt.info.queueing_opt_flags |= I40E_AQ_VSI_QUE_OPT_TCP_ENA;
  4483. }
  4484. /* Update the VSI after updating the VSI queue-mapping information */
  4485. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  4486. if (ret) {
  4487. dev_info(&vsi->back->pdev->dev,
  4488. "Update vsi tc config failed, err %s aq_err %s\n",
  4489. i40e_stat_str(&vsi->back->hw, ret),
  4490. i40e_aq_str(&vsi->back->hw,
  4491. vsi->back->hw.aq.asq_last_status));
  4492. goto out;
  4493. }
  4494. /* update the local VSI info with updated queue map */
  4495. i40e_vsi_update_queue_map(vsi, &ctxt);
  4496. vsi->info.valid_sections = 0;
  4497. /* Update current VSI BW information */
  4498. ret = i40e_vsi_get_bw_info(vsi);
  4499. if (ret) {
  4500. dev_info(&vsi->back->pdev->dev,
  4501. "Failed updating vsi bw info, err %s aq_err %s\n",
  4502. i40e_stat_str(&vsi->back->hw, ret),
  4503. i40e_aq_str(&vsi->back->hw,
  4504. vsi->back->hw.aq.asq_last_status));
  4505. goto out;
  4506. }
  4507. /* Update the netdev TC setup */
  4508. i40e_vsi_config_netdev_tc(vsi, enabled_tc);
  4509. out:
  4510. return ret;
  4511. }
  4512. /**
  4513. * i40e_veb_config_tc - Configure TCs for given VEB
  4514. * @veb: given VEB
  4515. * @enabled_tc: TC bitmap
  4516. *
  4517. * Configures given TC bitmap for VEB (switching) element
  4518. **/
  4519. int i40e_veb_config_tc(struct i40e_veb *veb, u8 enabled_tc)
  4520. {
  4521. struct i40e_aqc_configure_switching_comp_bw_config_data bw_data = {0};
  4522. struct i40e_pf *pf = veb->pf;
  4523. int ret = 0;
  4524. int i;
  4525. /* No TCs or already enabled TCs just return */
  4526. if (!enabled_tc || veb->enabled_tc == enabled_tc)
  4527. return ret;
  4528. bw_data.tc_valid_bits = enabled_tc;
  4529. /* bw_data.absolute_credits is not set (relative) */
  4530. /* Enable ETS TCs with equal BW Share for now */
  4531. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  4532. if (enabled_tc & BIT(i))
  4533. bw_data.tc_bw_share_credits[i] = 1;
  4534. }
  4535. ret = i40e_aq_config_switch_comp_bw_config(&pf->hw, veb->seid,
  4536. &bw_data, NULL);
  4537. if (ret) {
  4538. dev_info(&pf->pdev->dev,
  4539. "VEB bw config failed, err %s aq_err %s\n",
  4540. i40e_stat_str(&pf->hw, ret),
  4541. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4542. goto out;
  4543. }
  4544. /* Update the BW information */
  4545. ret = i40e_veb_get_bw_info(veb);
  4546. if (ret) {
  4547. dev_info(&pf->pdev->dev,
  4548. "Failed getting veb bw config, err %s aq_err %s\n",
  4549. i40e_stat_str(&pf->hw, ret),
  4550. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4551. }
  4552. out:
  4553. return ret;
  4554. }
  4555. #ifdef CONFIG_I40E_DCB
  4556. /**
  4557. * i40e_dcb_reconfigure - Reconfigure all VEBs and VSIs
  4558. * @pf: PF struct
  4559. *
  4560. * Reconfigure VEB/VSIs on a given PF; it is assumed that
  4561. * the caller would've quiesce all the VSIs before calling
  4562. * this function
  4563. **/
  4564. static void i40e_dcb_reconfigure(struct i40e_pf *pf)
  4565. {
  4566. u8 tc_map = 0;
  4567. int ret;
  4568. u8 v;
  4569. /* Enable the TCs available on PF to all VEBs */
  4570. tc_map = i40e_pf_get_tc_map(pf);
  4571. for (v = 0; v < I40E_MAX_VEB; v++) {
  4572. if (!pf->veb[v])
  4573. continue;
  4574. ret = i40e_veb_config_tc(pf->veb[v], tc_map);
  4575. if (ret) {
  4576. dev_info(&pf->pdev->dev,
  4577. "Failed configuring TC for VEB seid=%d\n",
  4578. pf->veb[v]->seid);
  4579. /* Will try to configure as many components */
  4580. }
  4581. }
  4582. /* Update each VSI */
  4583. for (v = 0; v < pf->num_alloc_vsi; v++) {
  4584. if (!pf->vsi[v])
  4585. continue;
  4586. /* - Enable all TCs for the LAN VSI
  4587. #ifdef I40E_FCOE
  4588. * - For FCoE VSI only enable the TC configured
  4589. * as per the APP TLV
  4590. #endif
  4591. * - For all others keep them at TC0 for now
  4592. */
  4593. if (v == pf->lan_vsi)
  4594. tc_map = i40e_pf_get_tc_map(pf);
  4595. else
  4596. tc_map = I40E_DEFAULT_TRAFFIC_CLASS;
  4597. #ifdef I40E_FCOE
  4598. if (pf->vsi[v]->type == I40E_VSI_FCOE)
  4599. tc_map = i40e_get_fcoe_tc_map(pf);
  4600. #endif /* #ifdef I40E_FCOE */
  4601. ret = i40e_vsi_config_tc(pf->vsi[v], tc_map);
  4602. if (ret) {
  4603. dev_info(&pf->pdev->dev,
  4604. "Failed configuring TC for VSI seid=%d\n",
  4605. pf->vsi[v]->seid);
  4606. /* Will try to configure as many components */
  4607. } else {
  4608. /* Re-configure VSI vectors based on updated TC map */
  4609. i40e_vsi_map_rings_to_vectors(pf->vsi[v]);
  4610. if (pf->vsi[v]->netdev)
  4611. i40e_dcbnl_set_all(pf->vsi[v]);
  4612. }
  4613. }
  4614. }
  4615. /**
  4616. * i40e_resume_port_tx - Resume port Tx
  4617. * @pf: PF struct
  4618. *
  4619. * Resume a port's Tx and issue a PF reset in case of failure to
  4620. * resume.
  4621. **/
  4622. static int i40e_resume_port_tx(struct i40e_pf *pf)
  4623. {
  4624. struct i40e_hw *hw = &pf->hw;
  4625. int ret;
  4626. ret = i40e_aq_resume_port_tx(hw, NULL);
  4627. if (ret) {
  4628. dev_info(&pf->pdev->dev,
  4629. "Resume Port Tx failed, err %s aq_err %s\n",
  4630. i40e_stat_str(&pf->hw, ret),
  4631. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4632. /* Schedule PF reset to recover */
  4633. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  4634. i40e_service_event_schedule(pf);
  4635. }
  4636. return ret;
  4637. }
  4638. /**
  4639. * i40e_init_pf_dcb - Initialize DCB configuration
  4640. * @pf: PF being configured
  4641. *
  4642. * Query the current DCB configuration and cache it
  4643. * in the hardware structure
  4644. **/
  4645. static int i40e_init_pf_dcb(struct i40e_pf *pf)
  4646. {
  4647. struct i40e_hw *hw = &pf->hw;
  4648. int err = 0;
  4649. /* Do not enable DCB for SW1 and SW2 images even if the FW is capable */
  4650. if (pf->flags & I40E_FLAG_NO_DCB_SUPPORT)
  4651. goto out;
  4652. /* Get the initial DCB configuration */
  4653. err = i40e_init_dcb(hw);
  4654. if (!err) {
  4655. /* Device/Function is not DCBX capable */
  4656. if ((!hw->func_caps.dcb) ||
  4657. (hw->dcbx_status == I40E_DCBX_STATUS_DISABLED)) {
  4658. dev_info(&pf->pdev->dev,
  4659. "DCBX offload is not supported or is disabled for this PF.\n");
  4660. if (pf->flags & I40E_FLAG_MFP_ENABLED)
  4661. goto out;
  4662. } else {
  4663. /* When status is not DISABLED then DCBX in FW */
  4664. pf->dcbx_cap = DCB_CAP_DCBX_LLD_MANAGED |
  4665. DCB_CAP_DCBX_VER_IEEE;
  4666. pf->flags |= I40E_FLAG_DCB_CAPABLE;
  4667. /* Enable DCB tagging only when more than one TC
  4668. * or explicitly disable if only one TC
  4669. */
  4670. if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
  4671. pf->flags |= I40E_FLAG_DCB_ENABLED;
  4672. else
  4673. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  4674. dev_dbg(&pf->pdev->dev,
  4675. "DCBX offload is supported for this PF.\n");
  4676. }
  4677. } else {
  4678. dev_info(&pf->pdev->dev,
  4679. "Query for DCB configuration failed, err %s aq_err %s\n",
  4680. i40e_stat_str(&pf->hw, err),
  4681. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  4682. }
  4683. out:
  4684. return err;
  4685. }
  4686. #endif /* CONFIG_I40E_DCB */
  4687. #define SPEED_SIZE 14
  4688. #define FC_SIZE 8
  4689. /**
  4690. * i40e_print_link_message - print link up or down
  4691. * @vsi: the VSI for which link needs a message
  4692. */
  4693. void i40e_print_link_message(struct i40e_vsi *vsi, bool isup)
  4694. {
  4695. enum i40e_aq_link_speed new_speed;
  4696. char *speed = "Unknown";
  4697. char *fc = "Unknown";
  4698. char *fec = "";
  4699. char *an = "";
  4700. new_speed = vsi->back->hw.phy.link_info.link_speed;
  4701. if ((vsi->current_isup == isup) && (vsi->current_speed == new_speed))
  4702. return;
  4703. vsi->current_isup = isup;
  4704. vsi->current_speed = new_speed;
  4705. if (!isup) {
  4706. netdev_info(vsi->netdev, "NIC Link is Down\n");
  4707. return;
  4708. }
  4709. /* Warn user if link speed on NPAR enabled partition is not at
  4710. * least 10GB
  4711. */
  4712. if (vsi->back->hw.func_caps.npar_enable &&
  4713. (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_1GB ||
  4714. vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_100MB))
  4715. netdev_warn(vsi->netdev,
  4716. "The partition detected link speed that is less than 10Gbps\n");
  4717. switch (vsi->back->hw.phy.link_info.link_speed) {
  4718. case I40E_LINK_SPEED_40GB:
  4719. speed = "40 G";
  4720. break;
  4721. case I40E_LINK_SPEED_20GB:
  4722. speed = "20 G";
  4723. break;
  4724. case I40E_LINK_SPEED_25GB:
  4725. speed = "25 G";
  4726. break;
  4727. case I40E_LINK_SPEED_10GB:
  4728. speed = "10 G";
  4729. break;
  4730. case I40E_LINK_SPEED_1GB:
  4731. speed = "1000 M";
  4732. break;
  4733. case I40E_LINK_SPEED_100MB:
  4734. speed = "100 M";
  4735. break;
  4736. default:
  4737. break;
  4738. }
  4739. switch (vsi->back->hw.fc.current_mode) {
  4740. case I40E_FC_FULL:
  4741. fc = "RX/TX";
  4742. break;
  4743. case I40E_FC_TX_PAUSE:
  4744. fc = "TX";
  4745. break;
  4746. case I40E_FC_RX_PAUSE:
  4747. fc = "RX";
  4748. break;
  4749. default:
  4750. fc = "None";
  4751. break;
  4752. }
  4753. if (vsi->back->hw.phy.link_info.link_speed == I40E_LINK_SPEED_25GB) {
  4754. fec = ", FEC: None";
  4755. an = ", Autoneg: False";
  4756. if (vsi->back->hw.phy.link_info.an_info & I40E_AQ_AN_COMPLETED)
  4757. an = ", Autoneg: True";
  4758. if (vsi->back->hw.phy.link_info.fec_info &
  4759. I40E_AQ_CONFIG_FEC_KR_ENA)
  4760. fec = ", FEC: CL74 FC-FEC/BASE-R";
  4761. else if (vsi->back->hw.phy.link_info.fec_info &
  4762. I40E_AQ_CONFIG_FEC_RS_ENA)
  4763. fec = ", FEC: CL108 RS-FEC";
  4764. }
  4765. netdev_info(vsi->netdev, "NIC Link is Up, %sbps Full Duplex%s%s, Flow Control: %s\n",
  4766. speed, fec, an, fc);
  4767. }
  4768. /**
  4769. * i40e_up_complete - Finish the last steps of bringing up a connection
  4770. * @vsi: the VSI being configured
  4771. **/
  4772. static int i40e_up_complete(struct i40e_vsi *vsi)
  4773. {
  4774. struct i40e_pf *pf = vsi->back;
  4775. int err;
  4776. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  4777. i40e_vsi_configure_msix(vsi);
  4778. else
  4779. i40e_configure_msi_and_legacy(vsi);
  4780. /* start rings */
  4781. err = i40e_vsi_start_rings(vsi);
  4782. if (err)
  4783. return err;
  4784. clear_bit(__I40E_DOWN, &vsi->state);
  4785. i40e_napi_enable_all(vsi);
  4786. i40e_vsi_enable_irq(vsi);
  4787. if ((pf->hw.phy.link_info.link_info & I40E_AQ_LINK_UP) &&
  4788. (vsi->netdev)) {
  4789. i40e_print_link_message(vsi, true);
  4790. netif_tx_start_all_queues(vsi->netdev);
  4791. netif_carrier_on(vsi->netdev);
  4792. } else if (vsi->netdev) {
  4793. i40e_print_link_message(vsi, false);
  4794. /* need to check for qualified module here*/
  4795. if ((pf->hw.phy.link_info.link_info &
  4796. I40E_AQ_MEDIA_AVAILABLE) &&
  4797. (!(pf->hw.phy.link_info.an_info &
  4798. I40E_AQ_QUALIFIED_MODULE)))
  4799. netdev_err(vsi->netdev,
  4800. "the driver failed to link because an unqualified module was detected.");
  4801. }
  4802. /* replay FDIR SB filters */
  4803. if (vsi->type == I40E_VSI_FDIR) {
  4804. /* reset fd counters */
  4805. pf->fd_add_err = pf->fd_atr_cnt = 0;
  4806. if (pf->fd_tcp_rule > 0) {
  4807. pf->hw_disabled_flags |= I40E_FLAG_FD_ATR_ENABLED;
  4808. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  4809. dev_info(&pf->pdev->dev, "Forcing ATR off, sideband rules for TCP/IPv4 exist\n");
  4810. pf->fd_tcp_rule = 0;
  4811. }
  4812. i40e_fdir_filter_restore(vsi);
  4813. }
  4814. /* On the next run of the service_task, notify any clients of the new
  4815. * opened netdev
  4816. */
  4817. pf->flags |= I40E_FLAG_SERVICE_CLIENT_REQUESTED;
  4818. i40e_service_event_schedule(pf);
  4819. return 0;
  4820. }
  4821. /**
  4822. * i40e_vsi_reinit_locked - Reset the VSI
  4823. * @vsi: the VSI being configured
  4824. *
  4825. * Rebuild the ring structs after some configuration
  4826. * has changed, e.g. MTU size.
  4827. **/
  4828. static void i40e_vsi_reinit_locked(struct i40e_vsi *vsi)
  4829. {
  4830. struct i40e_pf *pf = vsi->back;
  4831. WARN_ON(in_interrupt());
  4832. while (test_and_set_bit(__I40E_CONFIG_BUSY, &pf->state))
  4833. usleep_range(1000, 2000);
  4834. i40e_down(vsi);
  4835. i40e_up(vsi);
  4836. clear_bit(__I40E_CONFIG_BUSY, &pf->state);
  4837. }
  4838. /**
  4839. * i40e_up - Bring the connection back up after being down
  4840. * @vsi: the VSI being configured
  4841. **/
  4842. int i40e_up(struct i40e_vsi *vsi)
  4843. {
  4844. int err;
  4845. err = i40e_vsi_configure(vsi);
  4846. if (!err)
  4847. err = i40e_up_complete(vsi);
  4848. return err;
  4849. }
  4850. /**
  4851. * i40e_down - Shutdown the connection processing
  4852. * @vsi: the VSI being stopped
  4853. **/
  4854. void i40e_down(struct i40e_vsi *vsi)
  4855. {
  4856. int i;
  4857. /* It is assumed that the caller of this function
  4858. * sets the vsi->state __I40E_DOWN bit.
  4859. */
  4860. if (vsi->netdev) {
  4861. netif_carrier_off(vsi->netdev);
  4862. netif_tx_disable(vsi->netdev);
  4863. }
  4864. i40e_vsi_disable_irq(vsi);
  4865. i40e_vsi_stop_rings(vsi);
  4866. i40e_napi_disable_all(vsi);
  4867. for (i = 0; i < vsi->num_queue_pairs; i++) {
  4868. i40e_clean_tx_ring(vsi->tx_rings[i]);
  4869. i40e_clean_rx_ring(vsi->rx_rings[i]);
  4870. }
  4871. }
  4872. /**
  4873. * i40e_setup_tc - configure multiple traffic classes
  4874. * @netdev: net device to configure
  4875. * @tc: number of traffic classes to enable
  4876. **/
  4877. static int i40e_setup_tc(struct net_device *netdev, u8 tc)
  4878. {
  4879. struct i40e_netdev_priv *np = netdev_priv(netdev);
  4880. struct i40e_vsi *vsi = np->vsi;
  4881. struct i40e_pf *pf = vsi->back;
  4882. u8 enabled_tc = 0;
  4883. int ret = -EINVAL;
  4884. int i;
  4885. /* Check if DCB enabled to continue */
  4886. if (!(pf->flags & I40E_FLAG_DCB_ENABLED)) {
  4887. netdev_info(netdev, "DCB is not enabled for adapter\n");
  4888. goto exit;
  4889. }
  4890. /* Check if MFP enabled */
  4891. if (pf->flags & I40E_FLAG_MFP_ENABLED) {
  4892. netdev_info(netdev, "Configuring TC not supported in MFP mode\n");
  4893. goto exit;
  4894. }
  4895. /* Check whether tc count is within enabled limit */
  4896. if (tc > i40e_pf_get_num_tc(pf)) {
  4897. netdev_info(netdev, "TC count greater than enabled on link for adapter\n");
  4898. goto exit;
  4899. }
  4900. /* Generate TC map for number of tc requested */
  4901. for (i = 0; i < tc; i++)
  4902. enabled_tc |= BIT(i);
  4903. /* Requesting same TC configuration as already enabled */
  4904. if (enabled_tc == vsi->tc_config.enabled_tc)
  4905. return 0;
  4906. /* Quiesce VSI queues */
  4907. i40e_quiesce_vsi(vsi);
  4908. /* Configure VSI for enabled TCs */
  4909. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  4910. if (ret) {
  4911. netdev_info(netdev, "Failed configuring TC for VSI seid=%d\n",
  4912. vsi->seid);
  4913. goto exit;
  4914. }
  4915. /* Unquiesce VSI */
  4916. i40e_unquiesce_vsi(vsi);
  4917. exit:
  4918. return ret;
  4919. }
  4920. #ifdef I40E_FCOE
  4921. int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto,
  4922. struct tc_to_netdev *tc)
  4923. #else
  4924. static int __i40e_setup_tc(struct net_device *netdev, u32 handle, __be16 proto,
  4925. struct tc_to_netdev *tc)
  4926. #endif
  4927. {
  4928. if (tc->type != TC_SETUP_MQPRIO)
  4929. return -EINVAL;
  4930. tc->mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
  4931. return i40e_setup_tc(netdev, tc->mqprio->num_tc);
  4932. }
  4933. /**
  4934. * i40e_open - Called when a network interface is made active
  4935. * @netdev: network interface device structure
  4936. *
  4937. * The open entry point is called when a network interface is made
  4938. * active by the system (IFF_UP). At this point all resources needed
  4939. * for transmit and receive operations are allocated, the interrupt
  4940. * handler is registered with the OS, the netdev watchdog subtask is
  4941. * enabled, and the stack is notified that the interface is ready.
  4942. *
  4943. * Returns 0 on success, negative value on failure
  4944. **/
  4945. int i40e_open(struct net_device *netdev)
  4946. {
  4947. struct i40e_netdev_priv *np = netdev_priv(netdev);
  4948. struct i40e_vsi *vsi = np->vsi;
  4949. struct i40e_pf *pf = vsi->back;
  4950. int err;
  4951. /* disallow open during test or if eeprom is broken */
  4952. if (test_bit(__I40E_TESTING, &pf->state) ||
  4953. test_bit(__I40E_BAD_EEPROM, &pf->state))
  4954. return -EBUSY;
  4955. netif_carrier_off(netdev);
  4956. err = i40e_vsi_open(vsi);
  4957. if (err)
  4958. return err;
  4959. /* configure global TSO hardware offload settings */
  4960. wr32(&pf->hw, I40E_GLLAN_TSOMSK_F, be32_to_cpu(TCP_FLAG_PSH |
  4961. TCP_FLAG_FIN) >> 16);
  4962. wr32(&pf->hw, I40E_GLLAN_TSOMSK_M, be32_to_cpu(TCP_FLAG_PSH |
  4963. TCP_FLAG_FIN |
  4964. TCP_FLAG_CWR) >> 16);
  4965. wr32(&pf->hw, I40E_GLLAN_TSOMSK_L, be32_to_cpu(TCP_FLAG_CWR) >> 16);
  4966. udp_tunnel_get_rx_info(netdev);
  4967. return 0;
  4968. }
  4969. /**
  4970. * i40e_vsi_open -
  4971. * @vsi: the VSI to open
  4972. *
  4973. * Finish initialization of the VSI.
  4974. *
  4975. * Returns 0 on success, negative value on failure
  4976. **/
  4977. int i40e_vsi_open(struct i40e_vsi *vsi)
  4978. {
  4979. struct i40e_pf *pf = vsi->back;
  4980. char int_name[I40E_INT_NAME_STR_LEN];
  4981. int err;
  4982. /* allocate descriptors */
  4983. err = i40e_vsi_setup_tx_resources(vsi);
  4984. if (err)
  4985. goto err_setup_tx;
  4986. err = i40e_vsi_setup_rx_resources(vsi);
  4987. if (err)
  4988. goto err_setup_rx;
  4989. err = i40e_vsi_configure(vsi);
  4990. if (err)
  4991. goto err_setup_rx;
  4992. if (vsi->netdev) {
  4993. snprintf(int_name, sizeof(int_name) - 1, "%s-%s",
  4994. dev_driver_string(&pf->pdev->dev), vsi->netdev->name);
  4995. err = i40e_vsi_request_irq(vsi, int_name);
  4996. if (err)
  4997. goto err_setup_rx;
  4998. /* Notify the stack of the actual queue counts. */
  4999. err = netif_set_real_num_tx_queues(vsi->netdev,
  5000. vsi->num_queue_pairs);
  5001. if (err)
  5002. goto err_set_queues;
  5003. err = netif_set_real_num_rx_queues(vsi->netdev,
  5004. vsi->num_queue_pairs);
  5005. if (err)
  5006. goto err_set_queues;
  5007. } else if (vsi->type == I40E_VSI_FDIR) {
  5008. snprintf(int_name, sizeof(int_name) - 1, "%s-%s:fdir",
  5009. dev_driver_string(&pf->pdev->dev),
  5010. dev_name(&pf->pdev->dev));
  5011. err = i40e_vsi_request_irq(vsi, int_name);
  5012. } else {
  5013. err = -EINVAL;
  5014. goto err_setup_rx;
  5015. }
  5016. err = i40e_up_complete(vsi);
  5017. if (err)
  5018. goto err_up_complete;
  5019. return 0;
  5020. err_up_complete:
  5021. i40e_down(vsi);
  5022. err_set_queues:
  5023. i40e_vsi_free_irq(vsi);
  5024. err_setup_rx:
  5025. i40e_vsi_free_rx_resources(vsi);
  5026. err_setup_tx:
  5027. i40e_vsi_free_tx_resources(vsi);
  5028. if (vsi == pf->vsi[pf->lan_vsi])
  5029. i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
  5030. return err;
  5031. }
  5032. /**
  5033. * i40e_fdir_filter_exit - Cleans up the Flow Director accounting
  5034. * @pf: Pointer to PF
  5035. *
  5036. * This function destroys the hlist where all the Flow Director
  5037. * filters were saved.
  5038. **/
  5039. static void i40e_fdir_filter_exit(struct i40e_pf *pf)
  5040. {
  5041. struct i40e_fdir_filter *filter;
  5042. struct hlist_node *node2;
  5043. hlist_for_each_entry_safe(filter, node2,
  5044. &pf->fdir_filter_list, fdir_node) {
  5045. hlist_del(&filter->fdir_node);
  5046. kfree(filter);
  5047. }
  5048. pf->fdir_pf_active_filters = 0;
  5049. }
  5050. /**
  5051. * i40e_close - Disables a network interface
  5052. * @netdev: network interface device structure
  5053. *
  5054. * The close entry point is called when an interface is de-activated
  5055. * by the OS. The hardware is still under the driver's control, but
  5056. * this netdev interface is disabled.
  5057. *
  5058. * Returns 0, this is not allowed to fail
  5059. **/
  5060. int i40e_close(struct net_device *netdev)
  5061. {
  5062. struct i40e_netdev_priv *np = netdev_priv(netdev);
  5063. struct i40e_vsi *vsi = np->vsi;
  5064. i40e_vsi_close(vsi);
  5065. return 0;
  5066. }
  5067. /**
  5068. * i40e_do_reset - Start a PF or Core Reset sequence
  5069. * @pf: board private structure
  5070. * @reset_flags: which reset is requested
  5071. *
  5072. * The essential difference in resets is that the PF Reset
  5073. * doesn't clear the packet buffers, doesn't reset the PE
  5074. * firmware, and doesn't bother the other PFs on the chip.
  5075. **/
  5076. void i40e_do_reset(struct i40e_pf *pf, u32 reset_flags)
  5077. {
  5078. u32 val;
  5079. WARN_ON(in_interrupt());
  5080. /* do the biggest reset indicated */
  5081. if (reset_flags & BIT_ULL(__I40E_GLOBAL_RESET_REQUESTED)) {
  5082. /* Request a Global Reset
  5083. *
  5084. * This will start the chip's countdown to the actual full
  5085. * chip reset event, and a warning interrupt to be sent
  5086. * to all PFs, including the requestor. Our handler
  5087. * for the warning interrupt will deal with the shutdown
  5088. * and recovery of the switch setup.
  5089. */
  5090. dev_dbg(&pf->pdev->dev, "GlobalR requested\n");
  5091. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  5092. val |= I40E_GLGEN_RTRIG_GLOBR_MASK;
  5093. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  5094. } else if (reset_flags & BIT_ULL(__I40E_CORE_RESET_REQUESTED)) {
  5095. /* Request a Core Reset
  5096. *
  5097. * Same as Global Reset, except does *not* include the MAC/PHY
  5098. */
  5099. dev_dbg(&pf->pdev->dev, "CoreR requested\n");
  5100. val = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  5101. val |= I40E_GLGEN_RTRIG_CORER_MASK;
  5102. wr32(&pf->hw, I40E_GLGEN_RTRIG, val);
  5103. i40e_flush(&pf->hw);
  5104. } else if (reset_flags & BIT_ULL(__I40E_PF_RESET_REQUESTED)) {
  5105. /* Request a PF Reset
  5106. *
  5107. * Resets only the PF-specific registers
  5108. *
  5109. * This goes directly to the tear-down and rebuild of
  5110. * the switch, since we need to do all the recovery as
  5111. * for the Core Reset.
  5112. */
  5113. dev_dbg(&pf->pdev->dev, "PFR requested\n");
  5114. i40e_handle_reset_warning(pf);
  5115. } else if (reset_flags & BIT_ULL(__I40E_REINIT_REQUESTED)) {
  5116. int v;
  5117. /* Find the VSI(s) that requested a re-init */
  5118. dev_info(&pf->pdev->dev,
  5119. "VSI reinit requested\n");
  5120. for (v = 0; v < pf->num_alloc_vsi; v++) {
  5121. struct i40e_vsi *vsi = pf->vsi[v];
  5122. if (vsi != NULL &&
  5123. test_bit(__I40E_REINIT_REQUESTED, &vsi->state)) {
  5124. i40e_vsi_reinit_locked(pf->vsi[v]);
  5125. clear_bit(__I40E_REINIT_REQUESTED, &vsi->state);
  5126. }
  5127. }
  5128. } else if (reset_flags & BIT_ULL(__I40E_DOWN_REQUESTED)) {
  5129. int v;
  5130. /* Find the VSI(s) that needs to be brought down */
  5131. dev_info(&pf->pdev->dev, "VSI down requested\n");
  5132. for (v = 0; v < pf->num_alloc_vsi; v++) {
  5133. struct i40e_vsi *vsi = pf->vsi[v];
  5134. if (vsi != NULL &&
  5135. test_bit(__I40E_DOWN_REQUESTED, &vsi->state)) {
  5136. set_bit(__I40E_DOWN, &vsi->state);
  5137. i40e_down(vsi);
  5138. clear_bit(__I40E_DOWN_REQUESTED, &vsi->state);
  5139. }
  5140. }
  5141. } else {
  5142. dev_info(&pf->pdev->dev,
  5143. "bad reset request 0x%08x\n", reset_flags);
  5144. }
  5145. }
  5146. #ifdef CONFIG_I40E_DCB
  5147. /**
  5148. * i40e_dcb_need_reconfig - Check if DCB needs reconfig
  5149. * @pf: board private structure
  5150. * @old_cfg: current DCB config
  5151. * @new_cfg: new DCB config
  5152. **/
  5153. bool i40e_dcb_need_reconfig(struct i40e_pf *pf,
  5154. struct i40e_dcbx_config *old_cfg,
  5155. struct i40e_dcbx_config *new_cfg)
  5156. {
  5157. bool need_reconfig = false;
  5158. /* Check if ETS configuration has changed */
  5159. if (memcmp(&new_cfg->etscfg,
  5160. &old_cfg->etscfg,
  5161. sizeof(new_cfg->etscfg))) {
  5162. /* If Priority Table has changed reconfig is needed */
  5163. if (memcmp(&new_cfg->etscfg.prioritytable,
  5164. &old_cfg->etscfg.prioritytable,
  5165. sizeof(new_cfg->etscfg.prioritytable))) {
  5166. need_reconfig = true;
  5167. dev_dbg(&pf->pdev->dev, "ETS UP2TC changed.\n");
  5168. }
  5169. if (memcmp(&new_cfg->etscfg.tcbwtable,
  5170. &old_cfg->etscfg.tcbwtable,
  5171. sizeof(new_cfg->etscfg.tcbwtable)))
  5172. dev_dbg(&pf->pdev->dev, "ETS TC BW Table changed.\n");
  5173. if (memcmp(&new_cfg->etscfg.tsatable,
  5174. &old_cfg->etscfg.tsatable,
  5175. sizeof(new_cfg->etscfg.tsatable)))
  5176. dev_dbg(&pf->pdev->dev, "ETS TSA Table changed.\n");
  5177. }
  5178. /* Check if PFC configuration has changed */
  5179. if (memcmp(&new_cfg->pfc,
  5180. &old_cfg->pfc,
  5181. sizeof(new_cfg->pfc))) {
  5182. need_reconfig = true;
  5183. dev_dbg(&pf->pdev->dev, "PFC config change detected.\n");
  5184. }
  5185. /* Check if APP Table has changed */
  5186. if (memcmp(&new_cfg->app,
  5187. &old_cfg->app,
  5188. sizeof(new_cfg->app))) {
  5189. need_reconfig = true;
  5190. dev_dbg(&pf->pdev->dev, "APP Table change detected.\n");
  5191. }
  5192. dev_dbg(&pf->pdev->dev, "dcb need_reconfig=%d\n", need_reconfig);
  5193. return need_reconfig;
  5194. }
  5195. /**
  5196. * i40e_handle_lldp_event - Handle LLDP Change MIB event
  5197. * @pf: board private structure
  5198. * @e: event info posted on ARQ
  5199. **/
  5200. static int i40e_handle_lldp_event(struct i40e_pf *pf,
  5201. struct i40e_arq_event_info *e)
  5202. {
  5203. struct i40e_aqc_lldp_get_mib *mib =
  5204. (struct i40e_aqc_lldp_get_mib *)&e->desc.params.raw;
  5205. struct i40e_hw *hw = &pf->hw;
  5206. struct i40e_dcbx_config tmp_dcbx_cfg;
  5207. bool need_reconfig = false;
  5208. int ret = 0;
  5209. u8 type;
  5210. /* Not DCB capable or capability disabled */
  5211. if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
  5212. return ret;
  5213. /* Ignore if event is not for Nearest Bridge */
  5214. type = ((mib->type >> I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT)
  5215. & I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
  5216. dev_dbg(&pf->pdev->dev, "LLDP event mib bridge type 0x%x\n", type);
  5217. if (type != I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE)
  5218. return ret;
  5219. /* Check MIB Type and return if event for Remote MIB update */
  5220. type = mib->type & I40E_AQ_LLDP_MIB_TYPE_MASK;
  5221. dev_dbg(&pf->pdev->dev,
  5222. "LLDP event mib type %s\n", type ? "remote" : "local");
  5223. if (type == I40E_AQ_LLDP_MIB_REMOTE) {
  5224. /* Update the remote cached instance and return */
  5225. ret = i40e_aq_get_dcb_config(hw, I40E_AQ_LLDP_MIB_REMOTE,
  5226. I40E_AQ_LLDP_BRIDGE_TYPE_NEAREST_BRIDGE,
  5227. &hw->remote_dcbx_config);
  5228. goto exit;
  5229. }
  5230. /* Store the old configuration */
  5231. tmp_dcbx_cfg = hw->local_dcbx_config;
  5232. /* Reset the old DCBx configuration data */
  5233. memset(&hw->local_dcbx_config, 0, sizeof(hw->local_dcbx_config));
  5234. /* Get updated DCBX data from firmware */
  5235. ret = i40e_get_dcb_config(&pf->hw);
  5236. if (ret) {
  5237. dev_info(&pf->pdev->dev,
  5238. "Failed querying DCB configuration data from firmware, err %s aq_err %s\n",
  5239. i40e_stat_str(&pf->hw, ret),
  5240. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5241. goto exit;
  5242. }
  5243. /* No change detected in DCBX configs */
  5244. if (!memcmp(&tmp_dcbx_cfg, &hw->local_dcbx_config,
  5245. sizeof(tmp_dcbx_cfg))) {
  5246. dev_dbg(&pf->pdev->dev, "No change detected in DCBX configuration.\n");
  5247. goto exit;
  5248. }
  5249. need_reconfig = i40e_dcb_need_reconfig(pf, &tmp_dcbx_cfg,
  5250. &hw->local_dcbx_config);
  5251. i40e_dcbnl_flush_apps(pf, &tmp_dcbx_cfg, &hw->local_dcbx_config);
  5252. if (!need_reconfig)
  5253. goto exit;
  5254. /* Enable DCB tagging only when more than one TC */
  5255. if (i40e_dcb_get_num_tc(&hw->local_dcbx_config) > 1)
  5256. pf->flags |= I40E_FLAG_DCB_ENABLED;
  5257. else
  5258. pf->flags &= ~I40E_FLAG_DCB_ENABLED;
  5259. set_bit(__I40E_PORT_TX_SUSPENDED, &pf->state);
  5260. /* Reconfiguration needed quiesce all VSIs */
  5261. i40e_pf_quiesce_all_vsi(pf);
  5262. /* Changes in configuration update VEB/VSI */
  5263. i40e_dcb_reconfigure(pf);
  5264. ret = i40e_resume_port_tx(pf);
  5265. clear_bit(__I40E_PORT_TX_SUSPENDED, &pf->state);
  5266. /* In case of error no point in resuming VSIs */
  5267. if (ret)
  5268. goto exit;
  5269. /* Wait for the PF's queues to be disabled */
  5270. ret = i40e_pf_wait_queues_disabled(pf);
  5271. if (ret) {
  5272. /* Schedule PF reset to recover */
  5273. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  5274. i40e_service_event_schedule(pf);
  5275. } else {
  5276. i40e_pf_unquiesce_all_vsi(pf);
  5277. pf->flags |= (I40E_FLAG_SERVICE_CLIENT_REQUESTED |
  5278. I40E_FLAG_CLIENT_L2_CHANGE);
  5279. }
  5280. exit:
  5281. return ret;
  5282. }
  5283. #endif /* CONFIG_I40E_DCB */
  5284. /**
  5285. * i40e_do_reset_safe - Protected reset path for userland calls.
  5286. * @pf: board private structure
  5287. * @reset_flags: which reset is requested
  5288. *
  5289. **/
  5290. void i40e_do_reset_safe(struct i40e_pf *pf, u32 reset_flags)
  5291. {
  5292. rtnl_lock();
  5293. i40e_do_reset(pf, reset_flags);
  5294. rtnl_unlock();
  5295. }
  5296. /**
  5297. * i40e_handle_lan_overflow_event - Handler for LAN queue overflow event
  5298. * @pf: board private structure
  5299. * @e: event info posted on ARQ
  5300. *
  5301. * Handler for LAN Queue Overflow Event generated by the firmware for PF
  5302. * and VF queues
  5303. **/
  5304. static void i40e_handle_lan_overflow_event(struct i40e_pf *pf,
  5305. struct i40e_arq_event_info *e)
  5306. {
  5307. struct i40e_aqc_lan_overflow *data =
  5308. (struct i40e_aqc_lan_overflow *)&e->desc.params.raw;
  5309. u32 queue = le32_to_cpu(data->prtdcb_rupto);
  5310. u32 qtx_ctl = le32_to_cpu(data->otx_ctl);
  5311. struct i40e_hw *hw = &pf->hw;
  5312. struct i40e_vf *vf;
  5313. u16 vf_id;
  5314. dev_dbg(&pf->pdev->dev, "overflow Rx Queue Number = %d QTX_CTL=0x%08x\n",
  5315. queue, qtx_ctl);
  5316. /* Queue belongs to VF, find the VF and issue VF reset */
  5317. if (((qtx_ctl & I40E_QTX_CTL_PFVF_Q_MASK)
  5318. >> I40E_QTX_CTL_PFVF_Q_SHIFT) == I40E_QTX_CTL_VF_QUEUE) {
  5319. vf_id = (u16)((qtx_ctl & I40E_QTX_CTL_VFVM_INDX_MASK)
  5320. >> I40E_QTX_CTL_VFVM_INDX_SHIFT);
  5321. vf_id -= hw->func_caps.vf_base_id;
  5322. vf = &pf->vf[vf_id];
  5323. i40e_vc_notify_vf_reset(vf);
  5324. /* Allow VF to process pending reset notification */
  5325. msleep(20);
  5326. i40e_reset_vf(vf, false);
  5327. }
  5328. }
  5329. /**
  5330. * i40e_get_cur_guaranteed_fd_count - Get the consumed guaranteed FD filters
  5331. * @pf: board private structure
  5332. **/
  5333. u32 i40e_get_cur_guaranteed_fd_count(struct i40e_pf *pf)
  5334. {
  5335. u32 val, fcnt_prog;
  5336. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  5337. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK);
  5338. return fcnt_prog;
  5339. }
  5340. /**
  5341. * i40e_get_current_fd_count - Get total FD filters programmed for this PF
  5342. * @pf: board private structure
  5343. **/
  5344. u32 i40e_get_current_fd_count(struct i40e_pf *pf)
  5345. {
  5346. u32 val, fcnt_prog;
  5347. val = rd32(&pf->hw, I40E_PFQF_FDSTAT);
  5348. fcnt_prog = (val & I40E_PFQF_FDSTAT_GUARANT_CNT_MASK) +
  5349. ((val & I40E_PFQF_FDSTAT_BEST_CNT_MASK) >>
  5350. I40E_PFQF_FDSTAT_BEST_CNT_SHIFT);
  5351. return fcnt_prog;
  5352. }
  5353. /**
  5354. * i40e_get_global_fd_count - Get total FD filters programmed on device
  5355. * @pf: board private structure
  5356. **/
  5357. u32 i40e_get_global_fd_count(struct i40e_pf *pf)
  5358. {
  5359. u32 val, fcnt_prog;
  5360. val = rd32(&pf->hw, I40E_GLQF_FDCNT_0);
  5361. fcnt_prog = (val & I40E_GLQF_FDCNT_0_GUARANT_CNT_MASK) +
  5362. ((val & I40E_GLQF_FDCNT_0_BESTCNT_MASK) >>
  5363. I40E_GLQF_FDCNT_0_BESTCNT_SHIFT);
  5364. return fcnt_prog;
  5365. }
  5366. /**
  5367. * i40e_fdir_check_and_reenable - Function to reenabe FD ATR or SB if disabled
  5368. * @pf: board private structure
  5369. **/
  5370. void i40e_fdir_check_and_reenable(struct i40e_pf *pf)
  5371. {
  5372. struct i40e_fdir_filter *filter;
  5373. u32 fcnt_prog, fcnt_avail;
  5374. struct hlist_node *node;
  5375. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  5376. return;
  5377. /* Check if, FD SB or ATR was auto disabled and if there is enough room
  5378. * to re-enable
  5379. */
  5380. fcnt_prog = i40e_get_global_fd_count(pf);
  5381. fcnt_avail = pf->fdir_pf_filter_count;
  5382. if ((fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM)) ||
  5383. (pf->fd_add_err == 0) ||
  5384. (i40e_get_current_atr_cnt(pf) < pf->fd_atr_cnt)) {
  5385. if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
  5386. (pf->hw_disabled_flags & I40E_FLAG_FD_SB_ENABLED)) {
  5387. pf->hw_disabled_flags &= ~I40E_FLAG_FD_SB_ENABLED;
  5388. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  5389. dev_info(&pf->pdev->dev, "FD Sideband/ntuple is being enabled since we have space in the table now\n");
  5390. }
  5391. }
  5392. /* Wait for some more space to be available to turn on ATR. We also
  5393. * must check that no existing ntuple rules for TCP are in effect
  5394. */
  5395. if (fcnt_prog < (fcnt_avail - I40E_FDIR_BUFFER_HEAD_ROOM * 2)) {
  5396. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  5397. (pf->hw_disabled_flags & I40E_FLAG_FD_ATR_ENABLED) &&
  5398. (pf->fd_tcp_rule == 0)) {
  5399. pf->hw_disabled_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  5400. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  5401. dev_info(&pf->pdev->dev, "ATR is being enabled since we have space in the table and there are no conflicting ntuple rules\n");
  5402. }
  5403. }
  5404. /* if hw had a problem adding a filter, delete it */
  5405. if (pf->fd_inv > 0) {
  5406. hlist_for_each_entry_safe(filter, node,
  5407. &pf->fdir_filter_list, fdir_node) {
  5408. if (filter->fd_id == pf->fd_inv) {
  5409. hlist_del(&filter->fdir_node);
  5410. kfree(filter);
  5411. pf->fdir_pf_active_filters--;
  5412. }
  5413. }
  5414. }
  5415. }
  5416. #define I40E_MIN_FD_FLUSH_INTERVAL 10
  5417. #define I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE 30
  5418. /**
  5419. * i40e_fdir_flush_and_replay - Function to flush all FD filters and replay SB
  5420. * @pf: board private structure
  5421. **/
  5422. static void i40e_fdir_flush_and_replay(struct i40e_pf *pf)
  5423. {
  5424. unsigned long min_flush_time;
  5425. int flush_wait_retry = 50;
  5426. bool disable_atr = false;
  5427. int fd_room;
  5428. int reg;
  5429. if (!time_after(jiffies, pf->fd_flush_timestamp +
  5430. (I40E_MIN_FD_FLUSH_INTERVAL * HZ)))
  5431. return;
  5432. /* If the flush is happening too quick and we have mostly SB rules we
  5433. * should not re-enable ATR for some time.
  5434. */
  5435. min_flush_time = pf->fd_flush_timestamp +
  5436. (I40E_MIN_FD_FLUSH_SB_ATR_UNSTABLE * HZ);
  5437. fd_room = pf->fdir_pf_filter_count - pf->fdir_pf_active_filters;
  5438. if (!(time_after(jiffies, min_flush_time)) &&
  5439. (fd_room < I40E_FDIR_BUFFER_HEAD_ROOM_FOR_ATR)) {
  5440. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  5441. dev_info(&pf->pdev->dev, "ATR disabled, not enough FD filter space.\n");
  5442. disable_atr = true;
  5443. }
  5444. pf->fd_flush_timestamp = jiffies;
  5445. pf->hw_disabled_flags |= I40E_FLAG_FD_ATR_ENABLED;
  5446. /* flush all filters */
  5447. wr32(&pf->hw, I40E_PFQF_CTL_1,
  5448. I40E_PFQF_CTL_1_CLEARFDTABLE_MASK);
  5449. i40e_flush(&pf->hw);
  5450. pf->fd_flush_cnt++;
  5451. pf->fd_add_err = 0;
  5452. do {
  5453. /* Check FD flush status every 5-6msec */
  5454. usleep_range(5000, 6000);
  5455. reg = rd32(&pf->hw, I40E_PFQF_CTL_1);
  5456. if (!(reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK))
  5457. break;
  5458. } while (flush_wait_retry--);
  5459. if (reg & I40E_PFQF_CTL_1_CLEARFDTABLE_MASK) {
  5460. dev_warn(&pf->pdev->dev, "FD table did not flush, needs more time\n");
  5461. } else {
  5462. /* replay sideband filters */
  5463. i40e_fdir_filter_restore(pf->vsi[pf->lan_vsi]);
  5464. if (!disable_atr)
  5465. pf->hw_disabled_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  5466. clear_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state);
  5467. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  5468. dev_info(&pf->pdev->dev, "FD Filter table flushed and FD-SB replayed.\n");
  5469. }
  5470. }
  5471. /**
  5472. * i40e_get_current_atr_count - Get the count of total FD ATR filters programmed
  5473. * @pf: board private structure
  5474. **/
  5475. u32 i40e_get_current_atr_cnt(struct i40e_pf *pf)
  5476. {
  5477. return i40e_get_current_fd_count(pf) - pf->fdir_pf_active_filters;
  5478. }
  5479. /* We can see up to 256 filter programming desc in transit if the filters are
  5480. * being applied really fast; before we see the first
  5481. * filter miss error on Rx queue 0. Accumulating enough error messages before
  5482. * reacting will make sure we don't cause flush too often.
  5483. */
  5484. #define I40E_MAX_FD_PROGRAM_ERROR 256
  5485. /**
  5486. * i40e_fdir_reinit_subtask - Worker thread to reinit FDIR filter table
  5487. * @pf: board private structure
  5488. **/
  5489. static void i40e_fdir_reinit_subtask(struct i40e_pf *pf)
  5490. {
  5491. /* if interface is down do nothing */
  5492. if (test_bit(__I40E_DOWN, &pf->state))
  5493. return;
  5494. if (test_bit(__I40E_FD_FLUSH_REQUESTED, &pf->state))
  5495. i40e_fdir_flush_and_replay(pf);
  5496. i40e_fdir_check_and_reenable(pf);
  5497. }
  5498. /**
  5499. * i40e_vsi_link_event - notify VSI of a link event
  5500. * @vsi: vsi to be notified
  5501. * @link_up: link up or down
  5502. **/
  5503. static void i40e_vsi_link_event(struct i40e_vsi *vsi, bool link_up)
  5504. {
  5505. if (!vsi || test_bit(__I40E_DOWN, &vsi->state))
  5506. return;
  5507. switch (vsi->type) {
  5508. case I40E_VSI_MAIN:
  5509. #ifdef I40E_FCOE
  5510. case I40E_VSI_FCOE:
  5511. #endif
  5512. if (!vsi->netdev || !vsi->netdev_registered)
  5513. break;
  5514. if (link_up) {
  5515. netif_carrier_on(vsi->netdev);
  5516. netif_tx_wake_all_queues(vsi->netdev);
  5517. } else {
  5518. netif_carrier_off(vsi->netdev);
  5519. netif_tx_stop_all_queues(vsi->netdev);
  5520. }
  5521. break;
  5522. case I40E_VSI_SRIOV:
  5523. case I40E_VSI_VMDQ2:
  5524. case I40E_VSI_CTRL:
  5525. case I40E_VSI_IWARP:
  5526. case I40E_VSI_MIRROR:
  5527. default:
  5528. /* there is no notification for other VSIs */
  5529. break;
  5530. }
  5531. }
  5532. /**
  5533. * i40e_veb_link_event - notify elements on the veb of a link event
  5534. * @veb: veb to be notified
  5535. * @link_up: link up or down
  5536. **/
  5537. static void i40e_veb_link_event(struct i40e_veb *veb, bool link_up)
  5538. {
  5539. struct i40e_pf *pf;
  5540. int i;
  5541. if (!veb || !veb->pf)
  5542. return;
  5543. pf = veb->pf;
  5544. /* depth first... */
  5545. for (i = 0; i < I40E_MAX_VEB; i++)
  5546. if (pf->veb[i] && (pf->veb[i]->uplink_seid == veb->seid))
  5547. i40e_veb_link_event(pf->veb[i], link_up);
  5548. /* ... now the local VSIs */
  5549. for (i = 0; i < pf->num_alloc_vsi; i++)
  5550. if (pf->vsi[i] && (pf->vsi[i]->uplink_seid == veb->seid))
  5551. i40e_vsi_link_event(pf->vsi[i], link_up);
  5552. }
  5553. /**
  5554. * i40e_link_event - Update netif_carrier status
  5555. * @pf: board private structure
  5556. **/
  5557. static void i40e_link_event(struct i40e_pf *pf)
  5558. {
  5559. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  5560. u8 new_link_speed, old_link_speed;
  5561. i40e_status status;
  5562. bool new_link, old_link;
  5563. /* save off old link status information */
  5564. pf->hw.phy.link_info_old = pf->hw.phy.link_info;
  5565. /* set this to force the get_link_status call to refresh state */
  5566. pf->hw.phy.get_link_info = true;
  5567. old_link = (pf->hw.phy.link_info_old.link_info & I40E_AQ_LINK_UP);
  5568. status = i40e_get_link_status(&pf->hw, &new_link);
  5569. /* On success, disable temp link polling */
  5570. if (status == I40E_SUCCESS) {
  5571. if (pf->flags & I40E_FLAG_TEMP_LINK_POLLING)
  5572. pf->flags &= ~I40E_FLAG_TEMP_LINK_POLLING;
  5573. } else {
  5574. /* Enable link polling temporarily until i40e_get_link_status
  5575. * returns I40E_SUCCESS
  5576. */
  5577. pf->flags |= I40E_FLAG_TEMP_LINK_POLLING;
  5578. dev_dbg(&pf->pdev->dev, "couldn't get link state, status: %d\n",
  5579. status);
  5580. return;
  5581. }
  5582. old_link_speed = pf->hw.phy.link_info_old.link_speed;
  5583. new_link_speed = pf->hw.phy.link_info.link_speed;
  5584. if (new_link == old_link &&
  5585. new_link_speed == old_link_speed &&
  5586. (test_bit(__I40E_DOWN, &vsi->state) ||
  5587. new_link == netif_carrier_ok(vsi->netdev)))
  5588. return;
  5589. if (!test_bit(__I40E_DOWN, &vsi->state))
  5590. i40e_print_link_message(vsi, new_link);
  5591. /* Notify the base of the switch tree connected to
  5592. * the link. Floating VEBs are not notified.
  5593. */
  5594. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  5595. i40e_veb_link_event(pf->veb[pf->lan_veb], new_link);
  5596. else
  5597. i40e_vsi_link_event(vsi, new_link);
  5598. if (pf->vf)
  5599. i40e_vc_notify_link_state(pf);
  5600. if (pf->flags & I40E_FLAG_PTP)
  5601. i40e_ptp_set_increment(pf);
  5602. }
  5603. /**
  5604. * i40e_watchdog_subtask - periodic checks not using event driven response
  5605. * @pf: board private structure
  5606. **/
  5607. static void i40e_watchdog_subtask(struct i40e_pf *pf)
  5608. {
  5609. int i;
  5610. /* if interface is down do nothing */
  5611. if (test_bit(__I40E_DOWN, &pf->state) ||
  5612. test_bit(__I40E_CONFIG_BUSY, &pf->state))
  5613. return;
  5614. /* make sure we don't do these things too often */
  5615. if (time_before(jiffies, (pf->service_timer_previous +
  5616. pf->service_timer_period)))
  5617. return;
  5618. pf->service_timer_previous = jiffies;
  5619. if ((pf->flags & I40E_FLAG_LINK_POLLING_ENABLED) ||
  5620. (pf->flags & I40E_FLAG_TEMP_LINK_POLLING))
  5621. i40e_link_event(pf);
  5622. /* Update the stats for active netdevs so the network stack
  5623. * can look at updated numbers whenever it cares to
  5624. */
  5625. for (i = 0; i < pf->num_alloc_vsi; i++)
  5626. if (pf->vsi[i] && pf->vsi[i]->netdev)
  5627. i40e_update_stats(pf->vsi[i]);
  5628. if (pf->flags & I40E_FLAG_VEB_STATS_ENABLED) {
  5629. /* Update the stats for the active switching components */
  5630. for (i = 0; i < I40E_MAX_VEB; i++)
  5631. if (pf->veb[i])
  5632. i40e_update_veb_stats(pf->veb[i]);
  5633. }
  5634. i40e_ptp_rx_hang(pf->vsi[pf->lan_vsi]);
  5635. }
  5636. /**
  5637. * i40e_reset_subtask - Set up for resetting the device and driver
  5638. * @pf: board private structure
  5639. **/
  5640. static void i40e_reset_subtask(struct i40e_pf *pf)
  5641. {
  5642. u32 reset_flags = 0;
  5643. rtnl_lock();
  5644. if (test_bit(__I40E_REINIT_REQUESTED, &pf->state)) {
  5645. reset_flags |= BIT(__I40E_REINIT_REQUESTED);
  5646. clear_bit(__I40E_REINIT_REQUESTED, &pf->state);
  5647. }
  5648. if (test_bit(__I40E_PF_RESET_REQUESTED, &pf->state)) {
  5649. reset_flags |= BIT(__I40E_PF_RESET_REQUESTED);
  5650. clear_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  5651. }
  5652. if (test_bit(__I40E_CORE_RESET_REQUESTED, &pf->state)) {
  5653. reset_flags |= BIT(__I40E_CORE_RESET_REQUESTED);
  5654. clear_bit(__I40E_CORE_RESET_REQUESTED, &pf->state);
  5655. }
  5656. if (test_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state)) {
  5657. reset_flags |= BIT(__I40E_GLOBAL_RESET_REQUESTED);
  5658. clear_bit(__I40E_GLOBAL_RESET_REQUESTED, &pf->state);
  5659. }
  5660. if (test_bit(__I40E_DOWN_REQUESTED, &pf->state)) {
  5661. reset_flags |= BIT(__I40E_DOWN_REQUESTED);
  5662. clear_bit(__I40E_DOWN_REQUESTED, &pf->state);
  5663. }
  5664. /* If there's a recovery already waiting, it takes
  5665. * precedence before starting a new reset sequence.
  5666. */
  5667. if (test_bit(__I40E_RESET_INTR_RECEIVED, &pf->state)) {
  5668. i40e_handle_reset_warning(pf);
  5669. goto unlock;
  5670. }
  5671. /* If we're already down or resetting, just bail */
  5672. if (reset_flags &&
  5673. !test_bit(__I40E_DOWN, &pf->state) &&
  5674. !test_bit(__I40E_CONFIG_BUSY, &pf->state))
  5675. i40e_do_reset(pf, reset_flags);
  5676. unlock:
  5677. rtnl_unlock();
  5678. }
  5679. /**
  5680. * i40e_handle_link_event - Handle link event
  5681. * @pf: board private structure
  5682. * @e: event info posted on ARQ
  5683. **/
  5684. static void i40e_handle_link_event(struct i40e_pf *pf,
  5685. struct i40e_arq_event_info *e)
  5686. {
  5687. struct i40e_aqc_get_link_status *status =
  5688. (struct i40e_aqc_get_link_status *)&e->desc.params.raw;
  5689. /* Do a new status request to re-enable LSE reporting
  5690. * and load new status information into the hw struct
  5691. * This completely ignores any state information
  5692. * in the ARQ event info, instead choosing to always
  5693. * issue the AQ update link status command.
  5694. */
  5695. i40e_link_event(pf);
  5696. /* check for unqualified module, if link is down */
  5697. if ((status->link_info & I40E_AQ_MEDIA_AVAILABLE) &&
  5698. (!(status->an_info & I40E_AQ_QUALIFIED_MODULE)) &&
  5699. (!(status->link_info & I40E_AQ_LINK_UP)))
  5700. dev_err(&pf->pdev->dev,
  5701. "The driver failed to link because an unqualified module was detected.\n");
  5702. }
  5703. /**
  5704. * i40e_clean_adminq_subtask - Clean the AdminQ rings
  5705. * @pf: board private structure
  5706. **/
  5707. static void i40e_clean_adminq_subtask(struct i40e_pf *pf)
  5708. {
  5709. struct i40e_arq_event_info event;
  5710. struct i40e_hw *hw = &pf->hw;
  5711. u16 pending, i = 0;
  5712. i40e_status ret;
  5713. u16 opcode;
  5714. u32 oldval;
  5715. u32 val;
  5716. /* Do not run clean AQ when PF reset fails */
  5717. if (test_bit(__I40E_RESET_FAILED, &pf->state))
  5718. return;
  5719. /* check for error indications */
  5720. val = rd32(&pf->hw, pf->hw.aq.arq.len);
  5721. oldval = val;
  5722. if (val & I40E_PF_ARQLEN_ARQVFE_MASK) {
  5723. if (hw->debug_mask & I40E_DEBUG_AQ)
  5724. dev_info(&pf->pdev->dev, "ARQ VF Error detected\n");
  5725. val &= ~I40E_PF_ARQLEN_ARQVFE_MASK;
  5726. }
  5727. if (val & I40E_PF_ARQLEN_ARQOVFL_MASK) {
  5728. if (hw->debug_mask & I40E_DEBUG_AQ)
  5729. dev_info(&pf->pdev->dev, "ARQ Overflow Error detected\n");
  5730. val &= ~I40E_PF_ARQLEN_ARQOVFL_MASK;
  5731. pf->arq_overflows++;
  5732. }
  5733. if (val & I40E_PF_ARQLEN_ARQCRIT_MASK) {
  5734. if (hw->debug_mask & I40E_DEBUG_AQ)
  5735. dev_info(&pf->pdev->dev, "ARQ Critical Error detected\n");
  5736. val &= ~I40E_PF_ARQLEN_ARQCRIT_MASK;
  5737. }
  5738. if (oldval != val)
  5739. wr32(&pf->hw, pf->hw.aq.arq.len, val);
  5740. val = rd32(&pf->hw, pf->hw.aq.asq.len);
  5741. oldval = val;
  5742. if (val & I40E_PF_ATQLEN_ATQVFE_MASK) {
  5743. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  5744. dev_info(&pf->pdev->dev, "ASQ VF Error detected\n");
  5745. val &= ~I40E_PF_ATQLEN_ATQVFE_MASK;
  5746. }
  5747. if (val & I40E_PF_ATQLEN_ATQOVFL_MASK) {
  5748. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  5749. dev_info(&pf->pdev->dev, "ASQ Overflow Error detected\n");
  5750. val &= ~I40E_PF_ATQLEN_ATQOVFL_MASK;
  5751. }
  5752. if (val & I40E_PF_ATQLEN_ATQCRIT_MASK) {
  5753. if (pf->hw.debug_mask & I40E_DEBUG_AQ)
  5754. dev_info(&pf->pdev->dev, "ASQ Critical Error detected\n");
  5755. val &= ~I40E_PF_ATQLEN_ATQCRIT_MASK;
  5756. }
  5757. if (oldval != val)
  5758. wr32(&pf->hw, pf->hw.aq.asq.len, val);
  5759. event.buf_len = I40E_MAX_AQ_BUF_SIZE;
  5760. event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
  5761. if (!event.msg_buf)
  5762. return;
  5763. do {
  5764. ret = i40e_clean_arq_element(hw, &event, &pending);
  5765. if (ret == I40E_ERR_ADMIN_QUEUE_NO_WORK)
  5766. break;
  5767. else if (ret) {
  5768. dev_info(&pf->pdev->dev, "ARQ event error %d\n", ret);
  5769. break;
  5770. }
  5771. opcode = le16_to_cpu(event.desc.opcode);
  5772. switch (opcode) {
  5773. case i40e_aqc_opc_get_link_status:
  5774. i40e_handle_link_event(pf, &event);
  5775. break;
  5776. case i40e_aqc_opc_send_msg_to_pf:
  5777. ret = i40e_vc_process_vf_msg(pf,
  5778. le16_to_cpu(event.desc.retval),
  5779. le32_to_cpu(event.desc.cookie_high),
  5780. le32_to_cpu(event.desc.cookie_low),
  5781. event.msg_buf,
  5782. event.msg_len);
  5783. break;
  5784. case i40e_aqc_opc_lldp_update_mib:
  5785. dev_dbg(&pf->pdev->dev, "ARQ: Update LLDP MIB event received\n");
  5786. #ifdef CONFIG_I40E_DCB
  5787. rtnl_lock();
  5788. ret = i40e_handle_lldp_event(pf, &event);
  5789. rtnl_unlock();
  5790. #endif /* CONFIG_I40E_DCB */
  5791. break;
  5792. case i40e_aqc_opc_event_lan_overflow:
  5793. dev_dbg(&pf->pdev->dev, "ARQ LAN queue overflow event received\n");
  5794. i40e_handle_lan_overflow_event(pf, &event);
  5795. break;
  5796. case i40e_aqc_opc_send_msg_to_peer:
  5797. dev_info(&pf->pdev->dev, "ARQ: Msg from other pf\n");
  5798. break;
  5799. case i40e_aqc_opc_nvm_erase:
  5800. case i40e_aqc_opc_nvm_update:
  5801. case i40e_aqc_opc_oem_post_update:
  5802. i40e_debug(&pf->hw, I40E_DEBUG_NVM,
  5803. "ARQ NVM operation 0x%04x completed\n",
  5804. opcode);
  5805. break;
  5806. default:
  5807. dev_info(&pf->pdev->dev,
  5808. "ARQ: Unknown event 0x%04x ignored\n",
  5809. opcode);
  5810. break;
  5811. }
  5812. } while (pending && (i++ < pf->adminq_work_limit));
  5813. clear_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state);
  5814. /* re-enable Admin queue interrupt cause */
  5815. val = rd32(hw, I40E_PFINT_ICR0_ENA);
  5816. val |= I40E_PFINT_ICR0_ENA_ADMINQ_MASK;
  5817. wr32(hw, I40E_PFINT_ICR0_ENA, val);
  5818. i40e_flush(hw);
  5819. kfree(event.msg_buf);
  5820. }
  5821. /**
  5822. * i40e_verify_eeprom - make sure eeprom is good to use
  5823. * @pf: board private structure
  5824. **/
  5825. static void i40e_verify_eeprom(struct i40e_pf *pf)
  5826. {
  5827. int err;
  5828. err = i40e_diag_eeprom_test(&pf->hw);
  5829. if (err) {
  5830. /* retry in case of garbage read */
  5831. err = i40e_diag_eeprom_test(&pf->hw);
  5832. if (err) {
  5833. dev_info(&pf->pdev->dev, "eeprom check failed (%d), Tx/Rx traffic disabled\n",
  5834. err);
  5835. set_bit(__I40E_BAD_EEPROM, &pf->state);
  5836. }
  5837. }
  5838. if (!err && test_bit(__I40E_BAD_EEPROM, &pf->state)) {
  5839. dev_info(&pf->pdev->dev, "eeprom check passed, Tx/Rx traffic enabled\n");
  5840. clear_bit(__I40E_BAD_EEPROM, &pf->state);
  5841. }
  5842. }
  5843. /**
  5844. * i40e_enable_pf_switch_lb
  5845. * @pf: pointer to the PF structure
  5846. *
  5847. * enable switch loop back or die - no point in a return value
  5848. **/
  5849. static void i40e_enable_pf_switch_lb(struct i40e_pf *pf)
  5850. {
  5851. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  5852. struct i40e_vsi_context ctxt;
  5853. int ret;
  5854. ctxt.seid = pf->main_vsi_seid;
  5855. ctxt.pf_num = pf->hw.pf_id;
  5856. ctxt.vf_num = 0;
  5857. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  5858. if (ret) {
  5859. dev_info(&pf->pdev->dev,
  5860. "couldn't get PF vsi config, err %s aq_err %s\n",
  5861. i40e_stat_str(&pf->hw, ret),
  5862. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5863. return;
  5864. }
  5865. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  5866. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  5867. ctxt.info.switch_id |= cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  5868. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  5869. if (ret) {
  5870. dev_info(&pf->pdev->dev,
  5871. "update vsi switch failed, err %s aq_err %s\n",
  5872. i40e_stat_str(&pf->hw, ret),
  5873. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5874. }
  5875. }
  5876. /**
  5877. * i40e_disable_pf_switch_lb
  5878. * @pf: pointer to the PF structure
  5879. *
  5880. * disable switch loop back or die - no point in a return value
  5881. **/
  5882. static void i40e_disable_pf_switch_lb(struct i40e_pf *pf)
  5883. {
  5884. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  5885. struct i40e_vsi_context ctxt;
  5886. int ret;
  5887. ctxt.seid = pf->main_vsi_seid;
  5888. ctxt.pf_num = pf->hw.pf_id;
  5889. ctxt.vf_num = 0;
  5890. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  5891. if (ret) {
  5892. dev_info(&pf->pdev->dev,
  5893. "couldn't get PF vsi config, err %s aq_err %s\n",
  5894. i40e_stat_str(&pf->hw, ret),
  5895. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5896. return;
  5897. }
  5898. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  5899. ctxt.info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  5900. ctxt.info.switch_id &= ~cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  5901. ret = i40e_aq_update_vsi_params(&vsi->back->hw, &ctxt, NULL);
  5902. if (ret) {
  5903. dev_info(&pf->pdev->dev,
  5904. "update vsi switch failed, err %s aq_err %s\n",
  5905. i40e_stat_str(&pf->hw, ret),
  5906. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  5907. }
  5908. }
  5909. /**
  5910. * i40e_config_bridge_mode - Configure the HW bridge mode
  5911. * @veb: pointer to the bridge instance
  5912. *
  5913. * Configure the loop back mode for the LAN VSI that is downlink to the
  5914. * specified HW bridge instance. It is expected this function is called
  5915. * when a new HW bridge is instantiated.
  5916. **/
  5917. static void i40e_config_bridge_mode(struct i40e_veb *veb)
  5918. {
  5919. struct i40e_pf *pf = veb->pf;
  5920. if (pf->hw.debug_mask & I40E_DEBUG_LAN)
  5921. dev_info(&pf->pdev->dev, "enabling bridge mode: %s\n",
  5922. veb->bridge_mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
  5923. if (veb->bridge_mode & BRIDGE_MODE_VEPA)
  5924. i40e_disable_pf_switch_lb(pf);
  5925. else
  5926. i40e_enable_pf_switch_lb(pf);
  5927. }
  5928. /**
  5929. * i40e_reconstitute_veb - rebuild the VEB and anything connected to it
  5930. * @veb: pointer to the VEB instance
  5931. *
  5932. * This is a recursive function that first builds the attached VSIs then
  5933. * recurses in to build the next layer of VEB. We track the connections
  5934. * through our own index numbers because the seid's from the HW could
  5935. * change across the reset.
  5936. **/
  5937. static int i40e_reconstitute_veb(struct i40e_veb *veb)
  5938. {
  5939. struct i40e_vsi *ctl_vsi = NULL;
  5940. struct i40e_pf *pf = veb->pf;
  5941. int v, veb_idx;
  5942. int ret;
  5943. /* build VSI that owns this VEB, temporarily attached to base VEB */
  5944. for (v = 0; v < pf->num_alloc_vsi && !ctl_vsi; v++) {
  5945. if (pf->vsi[v] &&
  5946. pf->vsi[v]->veb_idx == veb->idx &&
  5947. pf->vsi[v]->flags & I40E_VSI_FLAG_VEB_OWNER) {
  5948. ctl_vsi = pf->vsi[v];
  5949. break;
  5950. }
  5951. }
  5952. if (!ctl_vsi) {
  5953. dev_info(&pf->pdev->dev,
  5954. "missing owner VSI for veb_idx %d\n", veb->idx);
  5955. ret = -ENOENT;
  5956. goto end_reconstitute;
  5957. }
  5958. if (ctl_vsi != pf->vsi[pf->lan_vsi])
  5959. ctl_vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  5960. ret = i40e_add_vsi(ctl_vsi);
  5961. if (ret) {
  5962. dev_info(&pf->pdev->dev,
  5963. "rebuild of veb_idx %d owner VSI failed: %d\n",
  5964. veb->idx, ret);
  5965. goto end_reconstitute;
  5966. }
  5967. i40e_vsi_reset_stats(ctl_vsi);
  5968. /* create the VEB in the switch and move the VSI onto the VEB */
  5969. ret = i40e_add_veb(veb, ctl_vsi);
  5970. if (ret)
  5971. goto end_reconstitute;
  5972. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
  5973. veb->bridge_mode = BRIDGE_MODE_VEB;
  5974. else
  5975. veb->bridge_mode = BRIDGE_MODE_VEPA;
  5976. i40e_config_bridge_mode(veb);
  5977. /* create the remaining VSIs attached to this VEB */
  5978. for (v = 0; v < pf->num_alloc_vsi; v++) {
  5979. if (!pf->vsi[v] || pf->vsi[v] == ctl_vsi)
  5980. continue;
  5981. if (pf->vsi[v]->veb_idx == veb->idx) {
  5982. struct i40e_vsi *vsi = pf->vsi[v];
  5983. vsi->uplink_seid = veb->seid;
  5984. ret = i40e_add_vsi(vsi);
  5985. if (ret) {
  5986. dev_info(&pf->pdev->dev,
  5987. "rebuild of vsi_idx %d failed: %d\n",
  5988. v, ret);
  5989. goto end_reconstitute;
  5990. }
  5991. i40e_vsi_reset_stats(vsi);
  5992. }
  5993. }
  5994. /* create any VEBs attached to this VEB - RECURSION */
  5995. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  5996. if (pf->veb[veb_idx] && pf->veb[veb_idx]->veb_idx == veb->idx) {
  5997. pf->veb[veb_idx]->uplink_seid = veb->seid;
  5998. ret = i40e_reconstitute_veb(pf->veb[veb_idx]);
  5999. if (ret)
  6000. break;
  6001. }
  6002. }
  6003. end_reconstitute:
  6004. return ret;
  6005. }
  6006. /**
  6007. * i40e_get_capabilities - get info about the HW
  6008. * @pf: the PF struct
  6009. **/
  6010. static int i40e_get_capabilities(struct i40e_pf *pf)
  6011. {
  6012. struct i40e_aqc_list_capabilities_element_resp *cap_buf;
  6013. u16 data_size;
  6014. int buf_len;
  6015. int err;
  6016. buf_len = 40 * sizeof(struct i40e_aqc_list_capabilities_element_resp);
  6017. do {
  6018. cap_buf = kzalloc(buf_len, GFP_KERNEL);
  6019. if (!cap_buf)
  6020. return -ENOMEM;
  6021. /* this loads the data into the hw struct for us */
  6022. err = i40e_aq_discover_capabilities(&pf->hw, cap_buf, buf_len,
  6023. &data_size,
  6024. i40e_aqc_opc_list_func_capabilities,
  6025. NULL);
  6026. /* data loaded, buffer no longer needed */
  6027. kfree(cap_buf);
  6028. if (pf->hw.aq.asq_last_status == I40E_AQ_RC_ENOMEM) {
  6029. /* retry with a larger buffer */
  6030. buf_len = data_size;
  6031. } else if (pf->hw.aq.asq_last_status != I40E_AQ_RC_OK) {
  6032. dev_info(&pf->pdev->dev,
  6033. "capability discovery failed, err %s aq_err %s\n",
  6034. i40e_stat_str(&pf->hw, err),
  6035. i40e_aq_str(&pf->hw,
  6036. pf->hw.aq.asq_last_status));
  6037. return -ENODEV;
  6038. }
  6039. } while (err);
  6040. if (pf->hw.debug_mask & I40E_DEBUG_USER)
  6041. dev_info(&pf->pdev->dev,
  6042. "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",
  6043. pf->hw.pf_id, pf->hw.func_caps.num_vfs,
  6044. pf->hw.func_caps.num_msix_vectors,
  6045. pf->hw.func_caps.num_msix_vectors_vf,
  6046. pf->hw.func_caps.fd_filters_guaranteed,
  6047. pf->hw.func_caps.fd_filters_best_effort,
  6048. pf->hw.func_caps.num_tx_qp,
  6049. pf->hw.func_caps.num_vsis);
  6050. #define DEF_NUM_VSI (1 + (pf->hw.func_caps.fcoe ? 1 : 0) \
  6051. + pf->hw.func_caps.num_vfs)
  6052. if (pf->hw.revision_id == 0 && (DEF_NUM_VSI > pf->hw.func_caps.num_vsis)) {
  6053. dev_info(&pf->pdev->dev,
  6054. "got num_vsis %d, setting num_vsis to %d\n",
  6055. pf->hw.func_caps.num_vsis, DEF_NUM_VSI);
  6056. pf->hw.func_caps.num_vsis = DEF_NUM_VSI;
  6057. }
  6058. return 0;
  6059. }
  6060. static int i40e_vsi_clear(struct i40e_vsi *vsi);
  6061. /**
  6062. * i40e_fdir_sb_setup - initialize the Flow Director resources for Sideband
  6063. * @pf: board private structure
  6064. **/
  6065. static void i40e_fdir_sb_setup(struct i40e_pf *pf)
  6066. {
  6067. struct i40e_vsi *vsi;
  6068. /* quick workaround for an NVM issue that leaves a critical register
  6069. * uninitialized
  6070. */
  6071. if (!rd32(&pf->hw, I40E_GLQF_HKEY(0))) {
  6072. static const u32 hkey[] = {
  6073. 0xe640d33f, 0xcdfe98ab, 0x73fa7161, 0x0d7a7d36,
  6074. 0xeacb7d61, 0xaa4f05b6, 0x9c5c89ed, 0xfc425ddb,
  6075. 0xa4654832, 0xfc7461d4, 0x8f827619, 0xf5c63c21,
  6076. 0x95b3a76d};
  6077. int i;
  6078. for (i = 0; i <= I40E_GLQF_HKEY_MAX_INDEX; i++)
  6079. wr32(&pf->hw, I40E_GLQF_HKEY(i), hkey[i]);
  6080. }
  6081. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  6082. return;
  6083. /* find existing VSI and see if it needs configuring */
  6084. vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
  6085. /* create a new VSI if none exists */
  6086. if (!vsi) {
  6087. vsi = i40e_vsi_setup(pf, I40E_VSI_FDIR,
  6088. pf->vsi[pf->lan_vsi]->seid, 0);
  6089. if (!vsi) {
  6090. dev_info(&pf->pdev->dev, "Couldn't create FDir VSI\n");
  6091. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  6092. return;
  6093. }
  6094. }
  6095. i40e_vsi_setup_irqhandler(vsi, i40e_fdir_clean_ring);
  6096. }
  6097. /**
  6098. * i40e_fdir_teardown - release the Flow Director resources
  6099. * @pf: board private structure
  6100. **/
  6101. static void i40e_fdir_teardown(struct i40e_pf *pf)
  6102. {
  6103. struct i40e_vsi *vsi;
  6104. i40e_fdir_filter_exit(pf);
  6105. vsi = i40e_find_vsi_by_type(pf, I40E_VSI_FDIR);
  6106. if (vsi)
  6107. i40e_vsi_release(vsi);
  6108. }
  6109. /**
  6110. * i40e_prep_for_reset - prep for the core to reset
  6111. * @pf: board private structure
  6112. *
  6113. * Close up the VFs and other things in prep for PF Reset.
  6114. **/
  6115. static void i40e_prep_for_reset(struct i40e_pf *pf)
  6116. {
  6117. struct i40e_hw *hw = &pf->hw;
  6118. i40e_status ret = 0;
  6119. u32 v;
  6120. clear_bit(__I40E_RESET_INTR_RECEIVED, &pf->state);
  6121. if (test_and_set_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state))
  6122. return;
  6123. if (i40e_check_asq_alive(&pf->hw))
  6124. i40e_vc_notify_reset(pf);
  6125. dev_dbg(&pf->pdev->dev, "Tearing down internal switch for reset\n");
  6126. /* quiesce the VSIs and their queues that are not already DOWN */
  6127. i40e_pf_quiesce_all_vsi(pf);
  6128. for (v = 0; v < pf->num_alloc_vsi; v++) {
  6129. if (pf->vsi[v])
  6130. pf->vsi[v]->seid = 0;
  6131. }
  6132. i40e_shutdown_adminq(&pf->hw);
  6133. /* call shutdown HMC */
  6134. if (hw->hmc.hmc_obj) {
  6135. ret = i40e_shutdown_lan_hmc(hw);
  6136. if (ret)
  6137. dev_warn(&pf->pdev->dev,
  6138. "shutdown_lan_hmc failed: %d\n", ret);
  6139. }
  6140. }
  6141. /**
  6142. * i40e_send_version - update firmware with driver version
  6143. * @pf: PF struct
  6144. */
  6145. static void i40e_send_version(struct i40e_pf *pf)
  6146. {
  6147. struct i40e_driver_version dv;
  6148. dv.major_version = DRV_VERSION_MAJOR;
  6149. dv.minor_version = DRV_VERSION_MINOR;
  6150. dv.build_version = DRV_VERSION_BUILD;
  6151. dv.subbuild_version = 0;
  6152. strlcpy(dv.driver_string, DRV_VERSION, sizeof(dv.driver_string));
  6153. i40e_aq_send_driver_version(&pf->hw, &dv, NULL);
  6154. }
  6155. /**
  6156. * i40e_reset_and_rebuild - reset and rebuild using a saved config
  6157. * @pf: board private structure
  6158. * @reinit: if the Main VSI needs to re-initialized.
  6159. **/
  6160. static void i40e_reset_and_rebuild(struct i40e_pf *pf, bool reinit)
  6161. {
  6162. struct i40e_hw *hw = &pf->hw;
  6163. u8 set_fc_aq_fail = 0;
  6164. i40e_status ret;
  6165. u32 val;
  6166. u32 v;
  6167. /* Now we wait for GRST to settle out.
  6168. * We don't have to delete the VEBs or VSIs from the hw switch
  6169. * because the reset will make them disappear.
  6170. */
  6171. ret = i40e_pf_reset(hw);
  6172. if (ret) {
  6173. dev_info(&pf->pdev->dev, "PF reset failed, %d\n", ret);
  6174. set_bit(__I40E_RESET_FAILED, &pf->state);
  6175. goto clear_recovery;
  6176. }
  6177. pf->pfr_count++;
  6178. if (test_bit(__I40E_DOWN, &pf->state))
  6179. goto clear_recovery;
  6180. dev_dbg(&pf->pdev->dev, "Rebuilding internal switch\n");
  6181. /* rebuild the basics for the AdminQ, HMC, and initial HW switch */
  6182. ret = i40e_init_adminq(&pf->hw);
  6183. if (ret) {
  6184. dev_info(&pf->pdev->dev, "Rebuild AdminQ failed, err %s aq_err %s\n",
  6185. i40e_stat_str(&pf->hw, ret),
  6186. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  6187. goto clear_recovery;
  6188. }
  6189. /* re-verify the eeprom if we just had an EMP reset */
  6190. if (test_and_clear_bit(__I40E_EMP_RESET_INTR_RECEIVED, &pf->state))
  6191. i40e_verify_eeprom(pf);
  6192. i40e_clear_pxe_mode(hw);
  6193. ret = i40e_get_capabilities(pf);
  6194. if (ret)
  6195. goto end_core_reset;
  6196. ret = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  6197. hw->func_caps.num_rx_qp,
  6198. pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
  6199. if (ret) {
  6200. dev_info(&pf->pdev->dev, "init_lan_hmc failed: %d\n", ret);
  6201. goto end_core_reset;
  6202. }
  6203. ret = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  6204. if (ret) {
  6205. dev_info(&pf->pdev->dev, "configure_lan_hmc failed: %d\n", ret);
  6206. goto end_core_reset;
  6207. }
  6208. #ifdef CONFIG_I40E_DCB
  6209. ret = i40e_init_pf_dcb(pf);
  6210. if (ret) {
  6211. dev_info(&pf->pdev->dev, "DCB init failed %d, disabled\n", ret);
  6212. pf->flags &= ~I40E_FLAG_DCB_CAPABLE;
  6213. /* Continue without DCB enabled */
  6214. }
  6215. #endif /* CONFIG_I40E_DCB */
  6216. #ifdef I40E_FCOE
  6217. i40e_init_pf_fcoe(pf);
  6218. #endif
  6219. /* do basic switch setup */
  6220. ret = i40e_setup_pf_switch(pf, reinit);
  6221. if (ret)
  6222. goto end_core_reset;
  6223. /* The driver only wants link up/down and module qualification
  6224. * reports from firmware. Note the negative logic.
  6225. */
  6226. ret = i40e_aq_set_phy_int_mask(&pf->hw,
  6227. ~(I40E_AQ_EVENT_LINK_UPDOWN |
  6228. I40E_AQ_EVENT_MEDIA_NA |
  6229. I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
  6230. if (ret)
  6231. dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
  6232. i40e_stat_str(&pf->hw, ret),
  6233. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  6234. /* make sure our flow control settings are restored */
  6235. ret = i40e_set_fc(&pf->hw, &set_fc_aq_fail, true);
  6236. if (ret)
  6237. dev_dbg(&pf->pdev->dev, "setting flow control: ret = %s last_status = %s\n",
  6238. i40e_stat_str(&pf->hw, ret),
  6239. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  6240. /* Rebuild the VSIs and VEBs that existed before reset.
  6241. * They are still in our local switch element arrays, so only
  6242. * need to rebuild the switch model in the HW.
  6243. *
  6244. * If there were VEBs but the reconstitution failed, we'll try
  6245. * try to recover minimal use by getting the basic PF VSI working.
  6246. */
  6247. if (pf->vsi[pf->lan_vsi]->uplink_seid != pf->mac_seid) {
  6248. dev_dbg(&pf->pdev->dev, "attempting to rebuild switch\n");
  6249. /* find the one VEB connected to the MAC, and find orphans */
  6250. for (v = 0; v < I40E_MAX_VEB; v++) {
  6251. if (!pf->veb[v])
  6252. continue;
  6253. if (pf->veb[v]->uplink_seid == pf->mac_seid ||
  6254. pf->veb[v]->uplink_seid == 0) {
  6255. ret = i40e_reconstitute_veb(pf->veb[v]);
  6256. if (!ret)
  6257. continue;
  6258. /* If Main VEB failed, we're in deep doodoo,
  6259. * so give up rebuilding the switch and set up
  6260. * for minimal rebuild of PF VSI.
  6261. * If orphan failed, we'll report the error
  6262. * but try to keep going.
  6263. */
  6264. if (pf->veb[v]->uplink_seid == pf->mac_seid) {
  6265. dev_info(&pf->pdev->dev,
  6266. "rebuild of switch failed: %d, will try to set up simple PF connection\n",
  6267. ret);
  6268. pf->vsi[pf->lan_vsi]->uplink_seid
  6269. = pf->mac_seid;
  6270. break;
  6271. } else if (pf->veb[v]->uplink_seid == 0) {
  6272. dev_info(&pf->pdev->dev,
  6273. "rebuild of orphan VEB failed: %d\n",
  6274. ret);
  6275. }
  6276. }
  6277. }
  6278. }
  6279. if (pf->vsi[pf->lan_vsi]->uplink_seid == pf->mac_seid) {
  6280. dev_dbg(&pf->pdev->dev, "attempting to rebuild PF VSI\n");
  6281. /* no VEB, so rebuild only the Main VSI */
  6282. ret = i40e_add_vsi(pf->vsi[pf->lan_vsi]);
  6283. if (ret) {
  6284. dev_info(&pf->pdev->dev,
  6285. "rebuild of Main VSI failed: %d\n", ret);
  6286. goto end_core_reset;
  6287. }
  6288. }
  6289. /* Reconfigure hardware for allowing smaller MSS in the case
  6290. * of TSO, so that we avoid the MDD being fired and causing
  6291. * a reset in the case of small MSS+TSO.
  6292. */
  6293. #define I40E_REG_MSS 0x000E64DC
  6294. #define I40E_REG_MSS_MIN_MASK 0x3FF0000
  6295. #define I40E_64BYTE_MSS 0x400000
  6296. val = rd32(hw, I40E_REG_MSS);
  6297. if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
  6298. val &= ~I40E_REG_MSS_MIN_MASK;
  6299. val |= I40E_64BYTE_MSS;
  6300. wr32(hw, I40E_REG_MSS, val);
  6301. }
  6302. if (pf->flags & I40E_FLAG_RESTART_AUTONEG) {
  6303. msleep(75);
  6304. ret = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
  6305. if (ret)
  6306. dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
  6307. i40e_stat_str(&pf->hw, ret),
  6308. i40e_aq_str(&pf->hw,
  6309. pf->hw.aq.asq_last_status));
  6310. }
  6311. /* reinit the misc interrupt */
  6312. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  6313. ret = i40e_setup_misc_vector(pf);
  6314. /* Add a filter to drop all Flow control frames from any VSI from being
  6315. * transmitted. By doing so we stop a malicious VF from sending out
  6316. * PAUSE or PFC frames and potentially controlling traffic for other
  6317. * PF/VF VSIs.
  6318. * The FW can still send Flow control frames if enabled.
  6319. */
  6320. i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
  6321. pf->main_vsi_seid);
  6322. /* restart the VSIs that were rebuilt and running before the reset */
  6323. i40e_pf_unquiesce_all_vsi(pf);
  6324. if (pf->num_alloc_vfs) {
  6325. for (v = 0; v < pf->num_alloc_vfs; v++)
  6326. i40e_reset_vf(&pf->vf[v], true);
  6327. }
  6328. /* tell the firmware that we're starting */
  6329. i40e_send_version(pf);
  6330. end_core_reset:
  6331. clear_bit(__I40E_RESET_FAILED, &pf->state);
  6332. clear_recovery:
  6333. clear_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state);
  6334. }
  6335. /**
  6336. * i40e_handle_reset_warning - prep for the PF to reset, reset and rebuild
  6337. * @pf: board private structure
  6338. *
  6339. * Close up the VFs and other things in prep for a Core Reset,
  6340. * then get ready to rebuild the world.
  6341. **/
  6342. static void i40e_handle_reset_warning(struct i40e_pf *pf)
  6343. {
  6344. i40e_prep_for_reset(pf);
  6345. i40e_reset_and_rebuild(pf, false);
  6346. }
  6347. /**
  6348. * i40e_handle_mdd_event
  6349. * @pf: pointer to the PF structure
  6350. *
  6351. * Called from the MDD irq handler to identify possibly malicious vfs
  6352. **/
  6353. static void i40e_handle_mdd_event(struct i40e_pf *pf)
  6354. {
  6355. struct i40e_hw *hw = &pf->hw;
  6356. bool mdd_detected = false;
  6357. bool pf_mdd_detected = false;
  6358. struct i40e_vf *vf;
  6359. u32 reg;
  6360. int i;
  6361. if (!test_bit(__I40E_MDD_EVENT_PENDING, &pf->state))
  6362. return;
  6363. /* find what triggered the MDD event */
  6364. reg = rd32(hw, I40E_GL_MDET_TX);
  6365. if (reg & I40E_GL_MDET_TX_VALID_MASK) {
  6366. u8 pf_num = (reg & I40E_GL_MDET_TX_PF_NUM_MASK) >>
  6367. I40E_GL_MDET_TX_PF_NUM_SHIFT;
  6368. u16 vf_num = (reg & I40E_GL_MDET_TX_VF_NUM_MASK) >>
  6369. I40E_GL_MDET_TX_VF_NUM_SHIFT;
  6370. u8 event = (reg & I40E_GL_MDET_TX_EVENT_MASK) >>
  6371. I40E_GL_MDET_TX_EVENT_SHIFT;
  6372. u16 queue = ((reg & I40E_GL_MDET_TX_QUEUE_MASK) >>
  6373. I40E_GL_MDET_TX_QUEUE_SHIFT) -
  6374. pf->hw.func_caps.base_queue;
  6375. if (netif_msg_tx_err(pf))
  6376. dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on TX queue %d PF number 0x%02x VF number 0x%02x\n",
  6377. event, queue, pf_num, vf_num);
  6378. wr32(hw, I40E_GL_MDET_TX, 0xffffffff);
  6379. mdd_detected = true;
  6380. }
  6381. reg = rd32(hw, I40E_GL_MDET_RX);
  6382. if (reg & I40E_GL_MDET_RX_VALID_MASK) {
  6383. u8 func = (reg & I40E_GL_MDET_RX_FUNCTION_MASK) >>
  6384. I40E_GL_MDET_RX_FUNCTION_SHIFT;
  6385. u8 event = (reg & I40E_GL_MDET_RX_EVENT_MASK) >>
  6386. I40E_GL_MDET_RX_EVENT_SHIFT;
  6387. u16 queue = ((reg & I40E_GL_MDET_RX_QUEUE_MASK) >>
  6388. I40E_GL_MDET_RX_QUEUE_SHIFT) -
  6389. pf->hw.func_caps.base_queue;
  6390. if (netif_msg_rx_err(pf))
  6391. dev_info(&pf->pdev->dev, "Malicious Driver Detection event 0x%02x on RX queue %d of function 0x%02x\n",
  6392. event, queue, func);
  6393. wr32(hw, I40E_GL_MDET_RX, 0xffffffff);
  6394. mdd_detected = true;
  6395. }
  6396. if (mdd_detected) {
  6397. reg = rd32(hw, I40E_PF_MDET_TX);
  6398. if (reg & I40E_PF_MDET_TX_VALID_MASK) {
  6399. wr32(hw, I40E_PF_MDET_TX, 0xFFFF);
  6400. dev_info(&pf->pdev->dev, "TX driver issue detected, PF reset issued\n");
  6401. pf_mdd_detected = true;
  6402. }
  6403. reg = rd32(hw, I40E_PF_MDET_RX);
  6404. if (reg & I40E_PF_MDET_RX_VALID_MASK) {
  6405. wr32(hw, I40E_PF_MDET_RX, 0xFFFF);
  6406. dev_info(&pf->pdev->dev, "RX driver issue detected, PF reset issued\n");
  6407. pf_mdd_detected = true;
  6408. }
  6409. /* Queue belongs to the PF, initiate a reset */
  6410. if (pf_mdd_detected) {
  6411. set_bit(__I40E_PF_RESET_REQUESTED, &pf->state);
  6412. i40e_service_event_schedule(pf);
  6413. }
  6414. }
  6415. /* see if one of the VFs needs its hand slapped */
  6416. for (i = 0; i < pf->num_alloc_vfs && mdd_detected; i++) {
  6417. vf = &(pf->vf[i]);
  6418. reg = rd32(hw, I40E_VP_MDET_TX(i));
  6419. if (reg & I40E_VP_MDET_TX_VALID_MASK) {
  6420. wr32(hw, I40E_VP_MDET_TX(i), 0xFFFF);
  6421. vf->num_mdd_events++;
  6422. dev_info(&pf->pdev->dev, "TX driver issue detected on VF %d\n",
  6423. i);
  6424. }
  6425. reg = rd32(hw, I40E_VP_MDET_RX(i));
  6426. if (reg & I40E_VP_MDET_RX_VALID_MASK) {
  6427. wr32(hw, I40E_VP_MDET_RX(i), 0xFFFF);
  6428. vf->num_mdd_events++;
  6429. dev_info(&pf->pdev->dev, "RX driver issue detected on VF %d\n",
  6430. i);
  6431. }
  6432. if (vf->num_mdd_events > I40E_DEFAULT_NUM_MDD_EVENTS_ALLOWED) {
  6433. dev_info(&pf->pdev->dev,
  6434. "Too many MDD events on VF %d, disabled\n", i);
  6435. dev_info(&pf->pdev->dev,
  6436. "Use PF Control I/F to re-enable the VF\n");
  6437. set_bit(I40E_VF_STAT_DISABLED, &vf->vf_states);
  6438. }
  6439. }
  6440. /* re-enable mdd interrupt cause */
  6441. clear_bit(__I40E_MDD_EVENT_PENDING, &pf->state);
  6442. reg = rd32(hw, I40E_PFINT_ICR0_ENA);
  6443. reg |= I40E_PFINT_ICR0_ENA_MAL_DETECT_MASK;
  6444. wr32(hw, I40E_PFINT_ICR0_ENA, reg);
  6445. i40e_flush(hw);
  6446. }
  6447. /**
  6448. * i40e_sync_udp_filters_subtask - Sync the VSI filter list with HW
  6449. * @pf: board private structure
  6450. **/
  6451. static void i40e_sync_udp_filters_subtask(struct i40e_pf *pf)
  6452. {
  6453. struct i40e_hw *hw = &pf->hw;
  6454. i40e_status ret;
  6455. __be16 port;
  6456. int i;
  6457. if (!(pf->flags & I40E_FLAG_UDP_FILTER_SYNC))
  6458. return;
  6459. pf->flags &= ~I40E_FLAG_UDP_FILTER_SYNC;
  6460. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  6461. if (pf->pending_udp_bitmap & BIT_ULL(i)) {
  6462. pf->pending_udp_bitmap &= ~BIT_ULL(i);
  6463. port = pf->udp_ports[i].index;
  6464. if (port)
  6465. ret = i40e_aq_add_udp_tunnel(hw, port,
  6466. pf->udp_ports[i].type,
  6467. NULL, NULL);
  6468. else
  6469. ret = i40e_aq_del_udp_tunnel(hw, i, NULL);
  6470. if (ret) {
  6471. dev_dbg(&pf->pdev->dev,
  6472. "%s %s port %d, index %d failed, err %s aq_err %s\n",
  6473. pf->udp_ports[i].type ? "vxlan" : "geneve",
  6474. port ? "add" : "delete",
  6475. ntohs(port), i,
  6476. i40e_stat_str(&pf->hw, ret),
  6477. i40e_aq_str(&pf->hw,
  6478. pf->hw.aq.asq_last_status));
  6479. pf->udp_ports[i].index = 0;
  6480. }
  6481. }
  6482. }
  6483. }
  6484. /**
  6485. * i40e_service_task - Run the driver's async subtasks
  6486. * @work: pointer to work_struct containing our data
  6487. **/
  6488. static void i40e_service_task(struct work_struct *work)
  6489. {
  6490. struct i40e_pf *pf = container_of(work,
  6491. struct i40e_pf,
  6492. service_task);
  6493. unsigned long start_time = jiffies;
  6494. /* don't bother with service tasks if a reset is in progress */
  6495. if (test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
  6496. return;
  6497. }
  6498. if (test_and_set_bit(__I40E_SERVICE_SCHED, &pf->state))
  6499. return;
  6500. i40e_detect_recover_hung(pf);
  6501. i40e_sync_filters_subtask(pf);
  6502. i40e_reset_subtask(pf);
  6503. i40e_handle_mdd_event(pf);
  6504. i40e_vc_process_vflr_event(pf);
  6505. i40e_watchdog_subtask(pf);
  6506. i40e_fdir_reinit_subtask(pf);
  6507. if (pf->flags & I40E_FLAG_CLIENT_RESET) {
  6508. /* Client subtask will reopen next time through. */
  6509. i40e_notify_client_of_netdev_close(pf->vsi[pf->lan_vsi], true);
  6510. pf->flags &= ~I40E_FLAG_CLIENT_RESET;
  6511. } else {
  6512. i40e_client_subtask(pf);
  6513. if (pf->flags & I40E_FLAG_CLIENT_L2_CHANGE) {
  6514. i40e_notify_client_of_l2_param_changes(
  6515. pf->vsi[pf->lan_vsi]);
  6516. pf->flags &= ~I40E_FLAG_CLIENT_L2_CHANGE;
  6517. }
  6518. }
  6519. i40e_sync_filters_subtask(pf);
  6520. i40e_sync_udp_filters_subtask(pf);
  6521. i40e_clean_adminq_subtask(pf);
  6522. /* flush memory to make sure state is correct before next watchdog */
  6523. smp_mb__before_atomic();
  6524. clear_bit(__I40E_SERVICE_SCHED, &pf->state);
  6525. /* If the tasks have taken longer than one timer cycle or there
  6526. * is more work to be done, reschedule the service task now
  6527. * rather than wait for the timer to tick again.
  6528. */
  6529. if (time_after(jiffies, (start_time + pf->service_timer_period)) ||
  6530. test_bit(__I40E_ADMINQ_EVENT_PENDING, &pf->state) ||
  6531. test_bit(__I40E_MDD_EVENT_PENDING, &pf->state) ||
  6532. test_bit(__I40E_VFLR_EVENT_PENDING, &pf->state))
  6533. i40e_service_event_schedule(pf);
  6534. }
  6535. /**
  6536. * i40e_service_timer - timer callback
  6537. * @data: pointer to PF struct
  6538. **/
  6539. static void i40e_service_timer(unsigned long data)
  6540. {
  6541. struct i40e_pf *pf = (struct i40e_pf *)data;
  6542. mod_timer(&pf->service_timer,
  6543. round_jiffies(jiffies + pf->service_timer_period));
  6544. i40e_service_event_schedule(pf);
  6545. }
  6546. /**
  6547. * i40e_set_num_rings_in_vsi - Determine number of rings in the VSI
  6548. * @vsi: the VSI being configured
  6549. **/
  6550. static int i40e_set_num_rings_in_vsi(struct i40e_vsi *vsi)
  6551. {
  6552. struct i40e_pf *pf = vsi->back;
  6553. switch (vsi->type) {
  6554. case I40E_VSI_MAIN:
  6555. vsi->alloc_queue_pairs = pf->num_lan_qps;
  6556. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  6557. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6558. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  6559. vsi->num_q_vectors = pf->num_lan_msix;
  6560. else
  6561. vsi->num_q_vectors = 1;
  6562. break;
  6563. case I40E_VSI_FDIR:
  6564. vsi->alloc_queue_pairs = 1;
  6565. vsi->num_desc = ALIGN(I40E_FDIR_RING_COUNT,
  6566. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6567. vsi->num_q_vectors = pf->num_fdsb_msix;
  6568. break;
  6569. case I40E_VSI_VMDQ2:
  6570. vsi->alloc_queue_pairs = pf->num_vmdq_qps;
  6571. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  6572. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6573. vsi->num_q_vectors = pf->num_vmdq_msix;
  6574. break;
  6575. case I40E_VSI_SRIOV:
  6576. vsi->alloc_queue_pairs = pf->num_vf_qps;
  6577. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  6578. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6579. break;
  6580. #ifdef I40E_FCOE
  6581. case I40E_VSI_FCOE:
  6582. vsi->alloc_queue_pairs = pf->num_fcoe_qps;
  6583. vsi->num_desc = ALIGN(I40E_DEFAULT_NUM_DESCRIPTORS,
  6584. I40E_REQ_DESCRIPTOR_MULTIPLE);
  6585. vsi->num_q_vectors = pf->num_fcoe_msix;
  6586. break;
  6587. #endif /* I40E_FCOE */
  6588. default:
  6589. WARN_ON(1);
  6590. return -ENODATA;
  6591. }
  6592. return 0;
  6593. }
  6594. /**
  6595. * i40e_vsi_alloc_arrays - Allocate queue and vector pointer arrays for the vsi
  6596. * @type: VSI pointer
  6597. * @alloc_qvectors: a bool to specify if q_vectors need to be allocated.
  6598. *
  6599. * On error: returns error code (negative)
  6600. * On success: returns 0
  6601. **/
  6602. static int i40e_vsi_alloc_arrays(struct i40e_vsi *vsi, bool alloc_qvectors)
  6603. {
  6604. int size;
  6605. int ret = 0;
  6606. /* allocate memory for both Tx and Rx ring pointers */
  6607. size = sizeof(struct i40e_ring *) * vsi->alloc_queue_pairs * 2;
  6608. vsi->tx_rings = kzalloc(size, GFP_KERNEL);
  6609. if (!vsi->tx_rings)
  6610. return -ENOMEM;
  6611. vsi->rx_rings = &vsi->tx_rings[vsi->alloc_queue_pairs];
  6612. if (alloc_qvectors) {
  6613. /* allocate memory for q_vector pointers */
  6614. size = sizeof(struct i40e_q_vector *) * vsi->num_q_vectors;
  6615. vsi->q_vectors = kzalloc(size, GFP_KERNEL);
  6616. if (!vsi->q_vectors) {
  6617. ret = -ENOMEM;
  6618. goto err_vectors;
  6619. }
  6620. }
  6621. return ret;
  6622. err_vectors:
  6623. kfree(vsi->tx_rings);
  6624. return ret;
  6625. }
  6626. /**
  6627. * i40e_vsi_mem_alloc - Allocates the next available struct vsi in the PF
  6628. * @pf: board private structure
  6629. * @type: type of VSI
  6630. *
  6631. * On error: returns error code (negative)
  6632. * On success: returns vsi index in PF (positive)
  6633. **/
  6634. static int i40e_vsi_mem_alloc(struct i40e_pf *pf, enum i40e_vsi_type type)
  6635. {
  6636. int ret = -ENODEV;
  6637. struct i40e_vsi *vsi;
  6638. int vsi_idx;
  6639. int i;
  6640. /* Need to protect the allocation of the VSIs at the PF level */
  6641. mutex_lock(&pf->switch_mutex);
  6642. /* VSI list may be fragmented if VSI creation/destruction has
  6643. * been happening. We can afford to do a quick scan to look
  6644. * for any free VSIs in the list.
  6645. *
  6646. * find next empty vsi slot, looping back around if necessary
  6647. */
  6648. i = pf->next_vsi;
  6649. while (i < pf->num_alloc_vsi && pf->vsi[i])
  6650. i++;
  6651. if (i >= pf->num_alloc_vsi) {
  6652. i = 0;
  6653. while (i < pf->next_vsi && pf->vsi[i])
  6654. i++;
  6655. }
  6656. if (i < pf->num_alloc_vsi && !pf->vsi[i]) {
  6657. vsi_idx = i; /* Found one! */
  6658. } else {
  6659. ret = -ENODEV;
  6660. goto unlock_pf; /* out of VSI slots! */
  6661. }
  6662. pf->next_vsi = ++i;
  6663. vsi = kzalloc(sizeof(*vsi), GFP_KERNEL);
  6664. if (!vsi) {
  6665. ret = -ENOMEM;
  6666. goto unlock_pf;
  6667. }
  6668. vsi->type = type;
  6669. vsi->back = pf;
  6670. set_bit(__I40E_DOWN, &vsi->state);
  6671. vsi->flags = 0;
  6672. vsi->idx = vsi_idx;
  6673. vsi->int_rate_limit = 0;
  6674. vsi->rss_table_size = (vsi->type == I40E_VSI_MAIN) ?
  6675. pf->rss_table_size : 64;
  6676. vsi->netdev_registered = false;
  6677. vsi->work_limit = I40E_DEFAULT_IRQ_WORK;
  6678. hash_init(vsi->mac_filter_hash);
  6679. vsi->irqs_ready = false;
  6680. ret = i40e_set_num_rings_in_vsi(vsi);
  6681. if (ret)
  6682. goto err_rings;
  6683. ret = i40e_vsi_alloc_arrays(vsi, true);
  6684. if (ret)
  6685. goto err_rings;
  6686. /* Setup default MSIX irq handler for VSI */
  6687. i40e_vsi_setup_irqhandler(vsi, i40e_msix_clean_rings);
  6688. /* Initialize VSI lock */
  6689. spin_lock_init(&vsi->mac_filter_hash_lock);
  6690. pf->vsi[vsi_idx] = vsi;
  6691. ret = vsi_idx;
  6692. goto unlock_pf;
  6693. err_rings:
  6694. pf->next_vsi = i - 1;
  6695. kfree(vsi);
  6696. unlock_pf:
  6697. mutex_unlock(&pf->switch_mutex);
  6698. return ret;
  6699. }
  6700. /**
  6701. * i40e_vsi_free_arrays - Free queue and vector pointer arrays for the VSI
  6702. * @type: VSI pointer
  6703. * @free_qvectors: a bool to specify if q_vectors need to be freed.
  6704. *
  6705. * On error: returns error code (negative)
  6706. * On success: returns 0
  6707. **/
  6708. static void i40e_vsi_free_arrays(struct i40e_vsi *vsi, bool free_qvectors)
  6709. {
  6710. /* free the ring and vector containers */
  6711. if (free_qvectors) {
  6712. kfree(vsi->q_vectors);
  6713. vsi->q_vectors = NULL;
  6714. }
  6715. kfree(vsi->tx_rings);
  6716. vsi->tx_rings = NULL;
  6717. vsi->rx_rings = NULL;
  6718. }
  6719. /**
  6720. * i40e_clear_rss_config_user - clear the user configured RSS hash keys
  6721. * and lookup table
  6722. * @vsi: Pointer to VSI structure
  6723. */
  6724. static void i40e_clear_rss_config_user(struct i40e_vsi *vsi)
  6725. {
  6726. if (!vsi)
  6727. return;
  6728. kfree(vsi->rss_hkey_user);
  6729. vsi->rss_hkey_user = NULL;
  6730. kfree(vsi->rss_lut_user);
  6731. vsi->rss_lut_user = NULL;
  6732. }
  6733. /**
  6734. * i40e_vsi_clear - Deallocate the VSI provided
  6735. * @vsi: the VSI being un-configured
  6736. **/
  6737. static int i40e_vsi_clear(struct i40e_vsi *vsi)
  6738. {
  6739. struct i40e_pf *pf;
  6740. if (!vsi)
  6741. return 0;
  6742. if (!vsi->back)
  6743. goto free_vsi;
  6744. pf = vsi->back;
  6745. mutex_lock(&pf->switch_mutex);
  6746. if (!pf->vsi[vsi->idx]) {
  6747. dev_err(&pf->pdev->dev, "pf->vsi[%d] is NULL, just free vsi[%d](%p,type %d)\n",
  6748. vsi->idx, vsi->idx, vsi, vsi->type);
  6749. goto unlock_vsi;
  6750. }
  6751. if (pf->vsi[vsi->idx] != vsi) {
  6752. dev_err(&pf->pdev->dev,
  6753. "pf->vsi[%d](%p, type %d) != vsi[%d](%p,type %d): no free!\n",
  6754. pf->vsi[vsi->idx]->idx,
  6755. pf->vsi[vsi->idx],
  6756. pf->vsi[vsi->idx]->type,
  6757. vsi->idx, vsi, vsi->type);
  6758. goto unlock_vsi;
  6759. }
  6760. /* updates the PF for this cleared vsi */
  6761. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  6762. i40e_put_lump(pf->irq_pile, vsi->base_vector, vsi->idx);
  6763. i40e_vsi_free_arrays(vsi, true);
  6764. i40e_clear_rss_config_user(vsi);
  6765. pf->vsi[vsi->idx] = NULL;
  6766. if (vsi->idx < pf->next_vsi)
  6767. pf->next_vsi = vsi->idx;
  6768. unlock_vsi:
  6769. mutex_unlock(&pf->switch_mutex);
  6770. free_vsi:
  6771. kfree(vsi);
  6772. return 0;
  6773. }
  6774. /**
  6775. * i40e_vsi_clear_rings - Deallocates the Rx and Tx rings for the provided VSI
  6776. * @vsi: the VSI being cleaned
  6777. **/
  6778. static void i40e_vsi_clear_rings(struct i40e_vsi *vsi)
  6779. {
  6780. int i;
  6781. if (vsi->tx_rings && vsi->tx_rings[0]) {
  6782. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  6783. kfree_rcu(vsi->tx_rings[i], rcu);
  6784. vsi->tx_rings[i] = NULL;
  6785. vsi->rx_rings[i] = NULL;
  6786. }
  6787. }
  6788. }
  6789. /**
  6790. * i40e_alloc_rings - Allocates the Rx and Tx rings for the provided VSI
  6791. * @vsi: the VSI being configured
  6792. **/
  6793. static int i40e_alloc_rings(struct i40e_vsi *vsi)
  6794. {
  6795. struct i40e_ring *tx_ring, *rx_ring;
  6796. struct i40e_pf *pf = vsi->back;
  6797. int i;
  6798. /* Set basic values in the rings to be used later during open() */
  6799. for (i = 0; i < vsi->alloc_queue_pairs; i++) {
  6800. /* allocate space for both Tx and Rx in one shot */
  6801. tx_ring = kzalloc(sizeof(struct i40e_ring) * 2, GFP_KERNEL);
  6802. if (!tx_ring)
  6803. goto err_out;
  6804. tx_ring->queue_index = i;
  6805. tx_ring->reg_idx = vsi->base_queue + i;
  6806. tx_ring->ring_active = false;
  6807. tx_ring->vsi = vsi;
  6808. tx_ring->netdev = vsi->netdev;
  6809. tx_ring->dev = &pf->pdev->dev;
  6810. tx_ring->count = vsi->num_desc;
  6811. tx_ring->size = 0;
  6812. tx_ring->dcb_tc = 0;
  6813. if (vsi->back->flags & I40E_FLAG_WB_ON_ITR_CAPABLE)
  6814. tx_ring->flags = I40E_TXR_FLAGS_WB_ON_ITR;
  6815. tx_ring->tx_itr_setting = pf->tx_itr_default;
  6816. vsi->tx_rings[i] = tx_ring;
  6817. rx_ring = &tx_ring[1];
  6818. rx_ring->queue_index = i;
  6819. rx_ring->reg_idx = vsi->base_queue + i;
  6820. rx_ring->ring_active = false;
  6821. rx_ring->vsi = vsi;
  6822. rx_ring->netdev = vsi->netdev;
  6823. rx_ring->dev = &pf->pdev->dev;
  6824. rx_ring->count = vsi->num_desc;
  6825. rx_ring->size = 0;
  6826. rx_ring->dcb_tc = 0;
  6827. rx_ring->rx_itr_setting = pf->rx_itr_default;
  6828. vsi->rx_rings[i] = rx_ring;
  6829. }
  6830. return 0;
  6831. err_out:
  6832. i40e_vsi_clear_rings(vsi);
  6833. return -ENOMEM;
  6834. }
  6835. /**
  6836. * i40e_reserve_msix_vectors - Reserve MSI-X vectors in the kernel
  6837. * @pf: board private structure
  6838. * @vectors: the number of MSI-X vectors to request
  6839. *
  6840. * Returns the number of vectors reserved, or error
  6841. **/
  6842. static int i40e_reserve_msix_vectors(struct i40e_pf *pf, int vectors)
  6843. {
  6844. vectors = pci_enable_msix_range(pf->pdev, pf->msix_entries,
  6845. I40E_MIN_MSIX, vectors);
  6846. if (vectors < 0) {
  6847. dev_info(&pf->pdev->dev,
  6848. "MSI-X vector reservation failed: %d\n", vectors);
  6849. vectors = 0;
  6850. }
  6851. return vectors;
  6852. }
  6853. /**
  6854. * i40e_init_msix - Setup the MSIX capability
  6855. * @pf: board private structure
  6856. *
  6857. * Work with the OS to set up the MSIX vectors needed.
  6858. *
  6859. * Returns the number of vectors reserved or negative on failure
  6860. **/
  6861. static int i40e_init_msix(struct i40e_pf *pf)
  6862. {
  6863. struct i40e_hw *hw = &pf->hw;
  6864. int cpus, extra_vectors;
  6865. int vectors_left;
  6866. int v_budget, i;
  6867. int v_actual;
  6868. int iwarp_requested = 0;
  6869. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  6870. return -ENODEV;
  6871. /* The number of vectors we'll request will be comprised of:
  6872. * - Add 1 for "other" cause for Admin Queue events, etc.
  6873. * - The number of LAN queue pairs
  6874. * - Queues being used for RSS.
  6875. * We don't need as many as max_rss_size vectors.
  6876. * use rss_size instead in the calculation since that
  6877. * is governed by number of cpus in the system.
  6878. * - assumes symmetric Tx/Rx pairing
  6879. * - The number of VMDq pairs
  6880. * - The CPU count within the NUMA node if iWARP is enabled
  6881. #ifdef I40E_FCOE
  6882. * - The number of FCOE qps.
  6883. #endif
  6884. * Once we count this up, try the request.
  6885. *
  6886. * If we can't get what we want, we'll simplify to nearly nothing
  6887. * and try again. If that still fails, we punt.
  6888. */
  6889. vectors_left = hw->func_caps.num_msix_vectors;
  6890. v_budget = 0;
  6891. /* reserve one vector for miscellaneous handler */
  6892. if (vectors_left) {
  6893. v_budget++;
  6894. vectors_left--;
  6895. }
  6896. /* reserve some vectors for the main PF traffic queues. Initially we
  6897. * only reserve at most 50% of the available vectors, in the case that
  6898. * the number of online CPUs is large. This ensures that we can enable
  6899. * extra features as well. Once we've enabled the other features, we
  6900. * will use any remaining vectors to reach as close as we can to the
  6901. * number of online CPUs.
  6902. */
  6903. cpus = num_online_cpus();
  6904. pf->num_lan_msix = min_t(int, cpus, vectors_left / 2);
  6905. vectors_left -= pf->num_lan_msix;
  6906. /* reserve one vector for sideband flow director */
  6907. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  6908. if (vectors_left) {
  6909. pf->num_fdsb_msix = 1;
  6910. v_budget++;
  6911. vectors_left--;
  6912. } else {
  6913. pf->num_fdsb_msix = 0;
  6914. }
  6915. }
  6916. #ifdef I40E_FCOE
  6917. /* can we reserve enough for FCoE? */
  6918. if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
  6919. if (!vectors_left)
  6920. pf->num_fcoe_msix = 0;
  6921. else if (vectors_left >= pf->num_fcoe_qps)
  6922. pf->num_fcoe_msix = pf->num_fcoe_qps;
  6923. else
  6924. pf->num_fcoe_msix = 1;
  6925. v_budget += pf->num_fcoe_msix;
  6926. vectors_left -= pf->num_fcoe_msix;
  6927. }
  6928. #endif
  6929. /* can we reserve enough for iWARP? */
  6930. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  6931. iwarp_requested = pf->num_iwarp_msix;
  6932. if (!vectors_left)
  6933. pf->num_iwarp_msix = 0;
  6934. else if (vectors_left < pf->num_iwarp_msix)
  6935. pf->num_iwarp_msix = 1;
  6936. v_budget += pf->num_iwarp_msix;
  6937. vectors_left -= pf->num_iwarp_msix;
  6938. }
  6939. /* any vectors left over go for VMDq support */
  6940. if (pf->flags & I40E_FLAG_VMDQ_ENABLED) {
  6941. int vmdq_vecs_wanted = pf->num_vmdq_vsis * pf->num_vmdq_qps;
  6942. int vmdq_vecs = min_t(int, vectors_left, vmdq_vecs_wanted);
  6943. if (!vectors_left) {
  6944. pf->num_vmdq_msix = 0;
  6945. pf->num_vmdq_qps = 0;
  6946. } else {
  6947. /* if we're short on vectors for what's desired, we limit
  6948. * the queues per vmdq. If this is still more than are
  6949. * available, the user will need to change the number of
  6950. * queues/vectors used by the PF later with the ethtool
  6951. * channels command
  6952. */
  6953. if (vmdq_vecs < vmdq_vecs_wanted)
  6954. pf->num_vmdq_qps = 1;
  6955. pf->num_vmdq_msix = pf->num_vmdq_qps;
  6956. v_budget += vmdq_vecs;
  6957. vectors_left -= vmdq_vecs;
  6958. }
  6959. }
  6960. /* On systems with a large number of SMP cores, we previously limited
  6961. * the number of vectors for num_lan_msix to be at most 50% of the
  6962. * available vectors, to allow for other features. Now, we add back
  6963. * the remaining vectors. However, we ensure that the total
  6964. * num_lan_msix will not exceed num_online_cpus(). To do this, we
  6965. * calculate the number of vectors we can add without going over the
  6966. * cap of CPUs. For systems with a small number of CPUs this will be
  6967. * zero.
  6968. */
  6969. extra_vectors = min_t(int, cpus - pf->num_lan_msix, vectors_left);
  6970. pf->num_lan_msix += extra_vectors;
  6971. vectors_left -= extra_vectors;
  6972. WARN(vectors_left < 0,
  6973. "Calculation of remaining vectors underflowed. This is an accounting bug when determining total MSI-X vectors.\n");
  6974. v_budget += pf->num_lan_msix;
  6975. pf->msix_entries = kcalloc(v_budget, sizeof(struct msix_entry),
  6976. GFP_KERNEL);
  6977. if (!pf->msix_entries)
  6978. return -ENOMEM;
  6979. for (i = 0; i < v_budget; i++)
  6980. pf->msix_entries[i].entry = i;
  6981. v_actual = i40e_reserve_msix_vectors(pf, v_budget);
  6982. if (v_actual < I40E_MIN_MSIX) {
  6983. pf->flags &= ~I40E_FLAG_MSIX_ENABLED;
  6984. kfree(pf->msix_entries);
  6985. pf->msix_entries = NULL;
  6986. pci_disable_msix(pf->pdev);
  6987. return -ENODEV;
  6988. } else if (v_actual == I40E_MIN_MSIX) {
  6989. /* Adjust for minimal MSIX use */
  6990. pf->num_vmdq_vsis = 0;
  6991. pf->num_vmdq_qps = 0;
  6992. pf->num_lan_qps = 1;
  6993. pf->num_lan_msix = 1;
  6994. } else if (!vectors_left) {
  6995. /* If we have limited resources, we will start with no vectors
  6996. * for the special features and then allocate vectors to some
  6997. * of these features based on the policy and at the end disable
  6998. * the features that did not get any vectors.
  6999. */
  7000. int vec;
  7001. dev_info(&pf->pdev->dev,
  7002. "MSI-X vector limit reached, attempting to redistribute vectors\n");
  7003. /* reserve the misc vector */
  7004. vec = v_actual - 1;
  7005. /* Scale vector usage down */
  7006. pf->num_vmdq_msix = 1; /* force VMDqs to only one vector */
  7007. pf->num_vmdq_vsis = 1;
  7008. pf->num_vmdq_qps = 1;
  7009. #ifdef I40E_FCOE
  7010. pf->num_fcoe_qps = 0;
  7011. pf->num_fcoe_msix = 0;
  7012. #endif
  7013. /* partition out the remaining vectors */
  7014. switch (vec) {
  7015. case 2:
  7016. pf->num_lan_msix = 1;
  7017. break;
  7018. case 3:
  7019. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  7020. pf->num_lan_msix = 1;
  7021. pf->num_iwarp_msix = 1;
  7022. } else {
  7023. pf->num_lan_msix = 2;
  7024. }
  7025. #ifdef I40E_FCOE
  7026. /* give one vector to FCoE */
  7027. if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
  7028. pf->num_lan_msix = 1;
  7029. pf->num_fcoe_msix = 1;
  7030. }
  7031. #endif
  7032. break;
  7033. default:
  7034. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  7035. pf->num_iwarp_msix = min_t(int, (vec / 3),
  7036. iwarp_requested);
  7037. pf->num_vmdq_vsis = min_t(int, (vec / 3),
  7038. I40E_DEFAULT_NUM_VMDQ_VSI);
  7039. } else {
  7040. pf->num_vmdq_vsis = min_t(int, (vec / 2),
  7041. I40E_DEFAULT_NUM_VMDQ_VSI);
  7042. }
  7043. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  7044. pf->num_fdsb_msix = 1;
  7045. vec--;
  7046. }
  7047. pf->num_lan_msix = min_t(int,
  7048. (vec - (pf->num_iwarp_msix + pf->num_vmdq_vsis)),
  7049. pf->num_lan_msix);
  7050. pf->num_lan_qps = pf->num_lan_msix;
  7051. #ifdef I40E_FCOE
  7052. /* give one vector to FCoE */
  7053. if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
  7054. pf->num_fcoe_msix = 1;
  7055. vec--;
  7056. }
  7057. #endif
  7058. break;
  7059. }
  7060. }
  7061. if ((pf->flags & I40E_FLAG_FD_SB_ENABLED) &&
  7062. (pf->num_fdsb_msix == 0)) {
  7063. dev_info(&pf->pdev->dev, "Sideband Flowdir disabled, not enough MSI-X vectors\n");
  7064. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  7065. }
  7066. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  7067. (pf->num_vmdq_msix == 0)) {
  7068. dev_info(&pf->pdev->dev, "VMDq disabled, not enough MSI-X vectors\n");
  7069. pf->flags &= ~I40E_FLAG_VMDQ_ENABLED;
  7070. }
  7071. if ((pf->flags & I40E_FLAG_IWARP_ENABLED) &&
  7072. (pf->num_iwarp_msix == 0)) {
  7073. dev_info(&pf->pdev->dev, "IWARP disabled, not enough MSI-X vectors\n");
  7074. pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
  7075. }
  7076. #ifdef I40E_FCOE
  7077. if ((pf->flags & I40E_FLAG_FCOE_ENABLED) && (pf->num_fcoe_msix == 0)) {
  7078. dev_info(&pf->pdev->dev, "FCOE disabled, not enough MSI-X vectors\n");
  7079. pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
  7080. }
  7081. #endif
  7082. i40e_debug(&pf->hw, I40E_DEBUG_INIT,
  7083. "MSI-X vector distribution: PF %d, VMDq %d, FDSB %d, iWARP %d\n",
  7084. pf->num_lan_msix,
  7085. pf->num_vmdq_msix * pf->num_vmdq_vsis,
  7086. pf->num_fdsb_msix,
  7087. pf->num_iwarp_msix);
  7088. return v_actual;
  7089. }
  7090. /**
  7091. * i40e_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
  7092. * @vsi: the VSI being configured
  7093. * @v_idx: index of the vector in the vsi struct
  7094. * @cpu: cpu to be used on affinity_mask
  7095. *
  7096. * We allocate one q_vector. If allocation fails we return -ENOMEM.
  7097. **/
  7098. static int i40e_vsi_alloc_q_vector(struct i40e_vsi *vsi, int v_idx, int cpu)
  7099. {
  7100. struct i40e_q_vector *q_vector;
  7101. /* allocate q_vector */
  7102. q_vector = kzalloc(sizeof(struct i40e_q_vector), GFP_KERNEL);
  7103. if (!q_vector)
  7104. return -ENOMEM;
  7105. q_vector->vsi = vsi;
  7106. q_vector->v_idx = v_idx;
  7107. cpumask_set_cpu(cpu, &q_vector->affinity_mask);
  7108. if (vsi->netdev)
  7109. netif_napi_add(vsi->netdev, &q_vector->napi,
  7110. i40e_napi_poll, NAPI_POLL_WEIGHT);
  7111. q_vector->rx.latency_range = I40E_LOW_LATENCY;
  7112. q_vector->tx.latency_range = I40E_LOW_LATENCY;
  7113. /* tie q_vector and vsi together */
  7114. vsi->q_vectors[v_idx] = q_vector;
  7115. return 0;
  7116. }
  7117. /**
  7118. * i40e_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
  7119. * @vsi: the VSI being configured
  7120. *
  7121. * We allocate one q_vector per queue interrupt. If allocation fails we
  7122. * return -ENOMEM.
  7123. **/
  7124. static int i40e_vsi_alloc_q_vectors(struct i40e_vsi *vsi)
  7125. {
  7126. struct i40e_pf *pf = vsi->back;
  7127. int err, v_idx, num_q_vectors, current_cpu;
  7128. /* if not MSIX, give the one vector only to the LAN VSI */
  7129. if (pf->flags & I40E_FLAG_MSIX_ENABLED)
  7130. num_q_vectors = vsi->num_q_vectors;
  7131. else if (vsi == pf->vsi[pf->lan_vsi])
  7132. num_q_vectors = 1;
  7133. else
  7134. return -EINVAL;
  7135. current_cpu = cpumask_first(cpu_online_mask);
  7136. for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
  7137. err = i40e_vsi_alloc_q_vector(vsi, v_idx, current_cpu);
  7138. if (err)
  7139. goto err_out;
  7140. current_cpu = cpumask_next(current_cpu, cpu_online_mask);
  7141. if (unlikely(current_cpu >= nr_cpu_ids))
  7142. current_cpu = cpumask_first(cpu_online_mask);
  7143. }
  7144. return 0;
  7145. err_out:
  7146. while (v_idx--)
  7147. i40e_free_q_vector(vsi, v_idx);
  7148. return err;
  7149. }
  7150. /**
  7151. * i40e_init_interrupt_scheme - Determine proper interrupt scheme
  7152. * @pf: board private structure to initialize
  7153. **/
  7154. static int i40e_init_interrupt_scheme(struct i40e_pf *pf)
  7155. {
  7156. int vectors = 0;
  7157. ssize_t size;
  7158. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  7159. vectors = i40e_init_msix(pf);
  7160. if (vectors < 0) {
  7161. pf->flags &= ~(I40E_FLAG_MSIX_ENABLED |
  7162. I40E_FLAG_IWARP_ENABLED |
  7163. #ifdef I40E_FCOE
  7164. I40E_FLAG_FCOE_ENABLED |
  7165. #endif
  7166. I40E_FLAG_RSS_ENABLED |
  7167. I40E_FLAG_DCB_CAPABLE |
  7168. I40E_FLAG_DCB_ENABLED |
  7169. I40E_FLAG_SRIOV_ENABLED |
  7170. I40E_FLAG_FD_SB_ENABLED |
  7171. I40E_FLAG_FD_ATR_ENABLED |
  7172. I40E_FLAG_VMDQ_ENABLED);
  7173. /* rework the queue expectations without MSIX */
  7174. i40e_determine_queue_usage(pf);
  7175. }
  7176. }
  7177. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  7178. (pf->flags & I40E_FLAG_MSI_ENABLED)) {
  7179. dev_info(&pf->pdev->dev, "MSI-X not available, trying MSI\n");
  7180. vectors = pci_enable_msi(pf->pdev);
  7181. if (vectors < 0) {
  7182. dev_info(&pf->pdev->dev, "MSI init failed - %d\n",
  7183. vectors);
  7184. pf->flags &= ~I40E_FLAG_MSI_ENABLED;
  7185. }
  7186. vectors = 1; /* one MSI or Legacy vector */
  7187. }
  7188. if (!(pf->flags & (I40E_FLAG_MSIX_ENABLED | I40E_FLAG_MSI_ENABLED)))
  7189. dev_info(&pf->pdev->dev, "MSI-X and MSI not available, falling back to Legacy IRQ\n");
  7190. /* set up vector assignment tracking */
  7191. size = sizeof(struct i40e_lump_tracking) + (sizeof(u16) * vectors);
  7192. pf->irq_pile = kzalloc(size, GFP_KERNEL);
  7193. if (!pf->irq_pile) {
  7194. dev_err(&pf->pdev->dev, "error allocating irq_pile memory\n");
  7195. return -ENOMEM;
  7196. }
  7197. pf->irq_pile->num_entries = vectors;
  7198. pf->irq_pile->search_hint = 0;
  7199. /* track first vector for misc interrupts, ignore return */
  7200. (void)i40e_get_lump(pf, pf->irq_pile, 1, I40E_PILE_VALID_BIT - 1);
  7201. return 0;
  7202. }
  7203. /**
  7204. * i40e_setup_misc_vector - Setup the misc vector to handle non queue events
  7205. * @pf: board private structure
  7206. *
  7207. * This sets up the handler for MSIX 0, which is used to manage the
  7208. * non-queue interrupts, e.g. AdminQ and errors. This is not used
  7209. * when in MSI or Legacy interrupt mode.
  7210. **/
  7211. static int i40e_setup_misc_vector(struct i40e_pf *pf)
  7212. {
  7213. struct i40e_hw *hw = &pf->hw;
  7214. int err = 0;
  7215. /* Only request the irq if this is the first time through, and
  7216. * not when we're rebuilding after a Reset
  7217. */
  7218. if (!test_bit(__I40E_RESET_RECOVERY_PENDING, &pf->state)) {
  7219. err = request_irq(pf->msix_entries[0].vector,
  7220. i40e_intr, 0, pf->int_name, pf);
  7221. if (err) {
  7222. dev_info(&pf->pdev->dev,
  7223. "request_irq for %s failed: %d\n",
  7224. pf->int_name, err);
  7225. return -EFAULT;
  7226. }
  7227. }
  7228. i40e_enable_misc_int_causes(pf);
  7229. /* associate no queues to the misc vector */
  7230. wr32(hw, I40E_PFINT_LNKLST0, I40E_QUEUE_END_OF_LIST);
  7231. wr32(hw, I40E_PFINT_ITR0(I40E_RX_ITR), I40E_ITR_8K);
  7232. i40e_flush(hw);
  7233. i40e_irq_dynamic_enable_icr0(pf, true);
  7234. return err;
  7235. }
  7236. /**
  7237. * i40e_config_rss_aq - Prepare for RSS using AQ commands
  7238. * @vsi: vsi structure
  7239. * @seed: RSS hash seed
  7240. **/
  7241. static int i40e_config_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
  7242. u8 *lut, u16 lut_size)
  7243. {
  7244. struct i40e_pf *pf = vsi->back;
  7245. struct i40e_hw *hw = &pf->hw;
  7246. int ret = 0;
  7247. if (seed) {
  7248. struct i40e_aqc_get_set_rss_key_data *seed_dw =
  7249. (struct i40e_aqc_get_set_rss_key_data *)seed;
  7250. ret = i40e_aq_set_rss_key(hw, vsi->id, seed_dw);
  7251. if (ret) {
  7252. dev_info(&pf->pdev->dev,
  7253. "Cannot set RSS key, err %s aq_err %s\n",
  7254. i40e_stat_str(hw, ret),
  7255. i40e_aq_str(hw, hw->aq.asq_last_status));
  7256. return ret;
  7257. }
  7258. }
  7259. if (lut) {
  7260. bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
  7261. ret = i40e_aq_set_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
  7262. if (ret) {
  7263. dev_info(&pf->pdev->dev,
  7264. "Cannot set RSS lut, err %s aq_err %s\n",
  7265. i40e_stat_str(hw, ret),
  7266. i40e_aq_str(hw, hw->aq.asq_last_status));
  7267. return ret;
  7268. }
  7269. }
  7270. return ret;
  7271. }
  7272. /**
  7273. * i40e_get_rss_aq - Get RSS keys and lut by using AQ commands
  7274. * @vsi: Pointer to vsi structure
  7275. * @seed: Buffter to store the hash keys
  7276. * @lut: Buffer to store the lookup table entries
  7277. * @lut_size: Size of buffer to store the lookup table entries
  7278. *
  7279. * Return 0 on success, negative on failure
  7280. */
  7281. static int i40e_get_rss_aq(struct i40e_vsi *vsi, const u8 *seed,
  7282. u8 *lut, u16 lut_size)
  7283. {
  7284. struct i40e_pf *pf = vsi->back;
  7285. struct i40e_hw *hw = &pf->hw;
  7286. int ret = 0;
  7287. if (seed) {
  7288. ret = i40e_aq_get_rss_key(hw, vsi->id,
  7289. (struct i40e_aqc_get_set_rss_key_data *)seed);
  7290. if (ret) {
  7291. dev_info(&pf->pdev->dev,
  7292. "Cannot get RSS key, err %s aq_err %s\n",
  7293. i40e_stat_str(&pf->hw, ret),
  7294. i40e_aq_str(&pf->hw,
  7295. pf->hw.aq.asq_last_status));
  7296. return ret;
  7297. }
  7298. }
  7299. if (lut) {
  7300. bool pf_lut = vsi->type == I40E_VSI_MAIN ? true : false;
  7301. ret = i40e_aq_get_rss_lut(hw, vsi->id, pf_lut, lut, lut_size);
  7302. if (ret) {
  7303. dev_info(&pf->pdev->dev,
  7304. "Cannot get RSS lut, err %s aq_err %s\n",
  7305. i40e_stat_str(&pf->hw, ret),
  7306. i40e_aq_str(&pf->hw,
  7307. pf->hw.aq.asq_last_status));
  7308. return ret;
  7309. }
  7310. }
  7311. return ret;
  7312. }
  7313. /**
  7314. * i40e_vsi_config_rss - Prepare for VSI(VMDq) RSS if used
  7315. * @vsi: VSI structure
  7316. **/
  7317. static int i40e_vsi_config_rss(struct i40e_vsi *vsi)
  7318. {
  7319. u8 seed[I40E_HKEY_ARRAY_SIZE];
  7320. struct i40e_pf *pf = vsi->back;
  7321. u8 *lut;
  7322. int ret;
  7323. if (!(pf->flags & I40E_FLAG_RSS_AQ_CAPABLE))
  7324. return 0;
  7325. if (!vsi->rss_size)
  7326. vsi->rss_size = min_t(int, pf->alloc_rss_size,
  7327. vsi->num_queue_pairs);
  7328. if (!vsi->rss_size)
  7329. return -EINVAL;
  7330. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  7331. if (!lut)
  7332. return -ENOMEM;
  7333. /* Use the user configured hash keys and lookup table if there is one,
  7334. * otherwise use default
  7335. */
  7336. if (vsi->rss_lut_user)
  7337. memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
  7338. else
  7339. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
  7340. if (vsi->rss_hkey_user)
  7341. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  7342. else
  7343. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  7344. ret = i40e_config_rss_aq(vsi, seed, lut, vsi->rss_table_size);
  7345. kfree(lut);
  7346. return ret;
  7347. }
  7348. /**
  7349. * i40e_config_rss_reg - Configure RSS keys and lut by writing registers
  7350. * @vsi: Pointer to vsi structure
  7351. * @seed: RSS hash seed
  7352. * @lut: Lookup table
  7353. * @lut_size: Lookup table size
  7354. *
  7355. * Returns 0 on success, negative on failure
  7356. **/
  7357. static int i40e_config_rss_reg(struct i40e_vsi *vsi, const u8 *seed,
  7358. const u8 *lut, u16 lut_size)
  7359. {
  7360. struct i40e_pf *pf = vsi->back;
  7361. struct i40e_hw *hw = &pf->hw;
  7362. u16 vf_id = vsi->vf_id;
  7363. u8 i;
  7364. /* Fill out hash function seed */
  7365. if (seed) {
  7366. u32 *seed_dw = (u32 *)seed;
  7367. if (vsi->type == I40E_VSI_MAIN) {
  7368. for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
  7369. wr32(hw, I40E_PFQF_HKEY(i), seed_dw[i]);
  7370. } else if (vsi->type == I40E_VSI_SRIOV) {
  7371. for (i = 0; i <= I40E_VFQF_HKEY1_MAX_INDEX; i++)
  7372. wr32(hw, I40E_VFQF_HKEY1(i, vf_id), seed_dw[i]);
  7373. } else {
  7374. dev_err(&pf->pdev->dev, "Cannot set RSS seed - invalid VSI type\n");
  7375. }
  7376. }
  7377. if (lut) {
  7378. u32 *lut_dw = (u32 *)lut;
  7379. if (vsi->type == I40E_VSI_MAIN) {
  7380. if (lut_size != I40E_HLUT_ARRAY_SIZE)
  7381. return -EINVAL;
  7382. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  7383. wr32(hw, I40E_PFQF_HLUT(i), lut_dw[i]);
  7384. } else if (vsi->type == I40E_VSI_SRIOV) {
  7385. if (lut_size != I40E_VF_HLUT_ARRAY_SIZE)
  7386. return -EINVAL;
  7387. for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
  7388. wr32(hw, I40E_VFQF_HLUT1(i, vf_id), lut_dw[i]);
  7389. } else {
  7390. dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
  7391. }
  7392. }
  7393. i40e_flush(hw);
  7394. return 0;
  7395. }
  7396. /**
  7397. * i40e_get_rss_reg - Get the RSS keys and lut by reading registers
  7398. * @vsi: Pointer to VSI structure
  7399. * @seed: Buffer to store the keys
  7400. * @lut: Buffer to store the lookup table entries
  7401. * @lut_size: Size of buffer to store the lookup table entries
  7402. *
  7403. * Returns 0 on success, negative on failure
  7404. */
  7405. static int i40e_get_rss_reg(struct i40e_vsi *vsi, u8 *seed,
  7406. u8 *lut, u16 lut_size)
  7407. {
  7408. struct i40e_pf *pf = vsi->back;
  7409. struct i40e_hw *hw = &pf->hw;
  7410. u16 i;
  7411. if (seed) {
  7412. u32 *seed_dw = (u32 *)seed;
  7413. for (i = 0; i <= I40E_PFQF_HKEY_MAX_INDEX; i++)
  7414. seed_dw[i] = i40e_read_rx_ctl(hw, I40E_PFQF_HKEY(i));
  7415. }
  7416. if (lut) {
  7417. u32 *lut_dw = (u32 *)lut;
  7418. if (lut_size != I40E_HLUT_ARRAY_SIZE)
  7419. return -EINVAL;
  7420. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  7421. lut_dw[i] = rd32(hw, I40E_PFQF_HLUT(i));
  7422. }
  7423. return 0;
  7424. }
  7425. /**
  7426. * i40e_config_rss - Configure RSS keys and lut
  7427. * @vsi: Pointer to VSI structure
  7428. * @seed: RSS hash seed
  7429. * @lut: Lookup table
  7430. * @lut_size: Lookup table size
  7431. *
  7432. * Returns 0 on success, negative on failure
  7433. */
  7434. int i40e_config_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
  7435. {
  7436. struct i40e_pf *pf = vsi->back;
  7437. if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
  7438. return i40e_config_rss_aq(vsi, seed, lut, lut_size);
  7439. else
  7440. return i40e_config_rss_reg(vsi, seed, lut, lut_size);
  7441. }
  7442. /**
  7443. * i40e_get_rss - Get RSS keys and lut
  7444. * @vsi: Pointer to VSI structure
  7445. * @seed: Buffer to store the keys
  7446. * @lut: Buffer to store the lookup table entries
  7447. * lut_size: Size of buffer to store the lookup table entries
  7448. *
  7449. * Returns 0 on success, negative on failure
  7450. */
  7451. int i40e_get_rss(struct i40e_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size)
  7452. {
  7453. struct i40e_pf *pf = vsi->back;
  7454. if (pf->flags & I40E_FLAG_RSS_AQ_CAPABLE)
  7455. return i40e_get_rss_aq(vsi, seed, lut, lut_size);
  7456. else
  7457. return i40e_get_rss_reg(vsi, seed, lut, lut_size);
  7458. }
  7459. /**
  7460. * i40e_fill_rss_lut - Fill the RSS lookup table with default values
  7461. * @pf: Pointer to board private structure
  7462. * @lut: Lookup table
  7463. * @rss_table_size: Lookup table size
  7464. * @rss_size: Range of queue number for hashing
  7465. */
  7466. void i40e_fill_rss_lut(struct i40e_pf *pf, u8 *lut,
  7467. u16 rss_table_size, u16 rss_size)
  7468. {
  7469. u16 i;
  7470. for (i = 0; i < rss_table_size; i++)
  7471. lut[i] = i % rss_size;
  7472. }
  7473. /**
  7474. * i40e_pf_config_rss - Prepare for RSS if used
  7475. * @pf: board private structure
  7476. **/
  7477. static int i40e_pf_config_rss(struct i40e_pf *pf)
  7478. {
  7479. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7480. u8 seed[I40E_HKEY_ARRAY_SIZE];
  7481. u8 *lut;
  7482. struct i40e_hw *hw = &pf->hw;
  7483. u32 reg_val;
  7484. u64 hena;
  7485. int ret;
  7486. /* By default we enable TCP/UDP with IPv4/IPv6 ptypes */
  7487. hena = (u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(0)) |
  7488. ((u64)i40e_read_rx_ctl(hw, I40E_PFQF_HENA(1)) << 32);
  7489. hena |= i40e_pf_get_default_rss_hena(pf);
  7490. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), (u32)hena);
  7491. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), (u32)(hena >> 32));
  7492. /* Determine the RSS table size based on the hardware capabilities */
  7493. reg_val = i40e_read_rx_ctl(hw, I40E_PFQF_CTL_0);
  7494. reg_val = (pf->rss_table_size == 512) ?
  7495. (reg_val | I40E_PFQF_CTL_0_HASHLUTSIZE_512) :
  7496. (reg_val & ~I40E_PFQF_CTL_0_HASHLUTSIZE_512);
  7497. i40e_write_rx_ctl(hw, I40E_PFQF_CTL_0, reg_val);
  7498. /* Determine the RSS size of the VSI */
  7499. if (!vsi->rss_size)
  7500. vsi->rss_size = min_t(int, pf->alloc_rss_size,
  7501. vsi->num_queue_pairs);
  7502. if (!vsi->rss_size)
  7503. return -EINVAL;
  7504. lut = kzalloc(vsi->rss_table_size, GFP_KERNEL);
  7505. if (!lut)
  7506. return -ENOMEM;
  7507. /* Use user configured lut if there is one, otherwise use default */
  7508. if (vsi->rss_lut_user)
  7509. memcpy(lut, vsi->rss_lut_user, vsi->rss_table_size);
  7510. else
  7511. i40e_fill_rss_lut(pf, lut, vsi->rss_table_size, vsi->rss_size);
  7512. /* Use user configured hash key if there is one, otherwise
  7513. * use default.
  7514. */
  7515. if (vsi->rss_hkey_user)
  7516. memcpy(seed, vsi->rss_hkey_user, I40E_HKEY_ARRAY_SIZE);
  7517. else
  7518. netdev_rss_key_fill((void *)seed, I40E_HKEY_ARRAY_SIZE);
  7519. ret = i40e_config_rss(vsi, seed, lut, vsi->rss_table_size);
  7520. kfree(lut);
  7521. return ret;
  7522. }
  7523. /**
  7524. * i40e_reconfig_rss_queues - change number of queues for rss and rebuild
  7525. * @pf: board private structure
  7526. * @queue_count: the requested queue count for rss.
  7527. *
  7528. * returns 0 if rss is not enabled, if enabled returns the final rss queue
  7529. * count which may be different from the requested queue count.
  7530. **/
  7531. int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count)
  7532. {
  7533. struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
  7534. int new_rss_size;
  7535. if (!(pf->flags & I40E_FLAG_RSS_ENABLED))
  7536. return 0;
  7537. new_rss_size = min_t(int, queue_count, pf->rss_size_max);
  7538. if (queue_count != vsi->num_queue_pairs) {
  7539. vsi->req_queue_pairs = queue_count;
  7540. i40e_prep_for_reset(pf);
  7541. pf->alloc_rss_size = new_rss_size;
  7542. i40e_reset_and_rebuild(pf, true);
  7543. /* Discard the user configured hash keys and lut, if less
  7544. * queues are enabled.
  7545. */
  7546. if (queue_count < vsi->rss_size) {
  7547. i40e_clear_rss_config_user(vsi);
  7548. dev_dbg(&pf->pdev->dev,
  7549. "discard user configured hash keys and lut\n");
  7550. }
  7551. /* Reset vsi->rss_size, as number of enabled queues changed */
  7552. vsi->rss_size = min_t(int, pf->alloc_rss_size,
  7553. vsi->num_queue_pairs);
  7554. i40e_pf_config_rss(pf);
  7555. }
  7556. dev_info(&pf->pdev->dev, "User requested queue count/HW max RSS count: %d/%d\n",
  7557. vsi->req_queue_pairs, pf->rss_size_max);
  7558. return pf->alloc_rss_size;
  7559. }
  7560. /**
  7561. * i40e_get_npar_bw_setting - Retrieve BW settings for this PF partition
  7562. * @pf: board private structure
  7563. **/
  7564. i40e_status i40e_get_npar_bw_setting(struct i40e_pf *pf)
  7565. {
  7566. i40e_status status;
  7567. bool min_valid, max_valid;
  7568. u32 max_bw, min_bw;
  7569. status = i40e_read_bw_from_alt_ram(&pf->hw, &max_bw, &min_bw,
  7570. &min_valid, &max_valid);
  7571. if (!status) {
  7572. if (min_valid)
  7573. pf->npar_min_bw = min_bw;
  7574. if (max_valid)
  7575. pf->npar_max_bw = max_bw;
  7576. }
  7577. return status;
  7578. }
  7579. /**
  7580. * i40e_set_npar_bw_setting - Set BW settings for this PF partition
  7581. * @pf: board private structure
  7582. **/
  7583. i40e_status i40e_set_npar_bw_setting(struct i40e_pf *pf)
  7584. {
  7585. struct i40e_aqc_configure_partition_bw_data bw_data;
  7586. i40e_status status;
  7587. /* Set the valid bit for this PF */
  7588. bw_data.pf_valid_bits = cpu_to_le16(BIT(pf->hw.pf_id));
  7589. bw_data.max_bw[pf->hw.pf_id] = pf->npar_max_bw & I40E_ALT_BW_VALUE_MASK;
  7590. bw_data.min_bw[pf->hw.pf_id] = pf->npar_min_bw & I40E_ALT_BW_VALUE_MASK;
  7591. /* Set the new bandwidths */
  7592. status = i40e_aq_configure_partition_bw(&pf->hw, &bw_data, NULL);
  7593. return status;
  7594. }
  7595. /**
  7596. * i40e_commit_npar_bw_setting - Commit BW settings for this PF partition
  7597. * @pf: board private structure
  7598. **/
  7599. i40e_status i40e_commit_npar_bw_setting(struct i40e_pf *pf)
  7600. {
  7601. /* Commit temporary BW setting to permanent NVM image */
  7602. enum i40e_admin_queue_err last_aq_status;
  7603. i40e_status ret;
  7604. u16 nvm_word;
  7605. if (pf->hw.partition_id != 1) {
  7606. dev_info(&pf->pdev->dev,
  7607. "Commit BW only works on partition 1! This is partition %d",
  7608. pf->hw.partition_id);
  7609. ret = I40E_NOT_SUPPORTED;
  7610. goto bw_commit_out;
  7611. }
  7612. /* Acquire NVM for read access */
  7613. ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_READ);
  7614. last_aq_status = pf->hw.aq.asq_last_status;
  7615. if (ret) {
  7616. dev_info(&pf->pdev->dev,
  7617. "Cannot acquire NVM for read access, err %s aq_err %s\n",
  7618. i40e_stat_str(&pf->hw, ret),
  7619. i40e_aq_str(&pf->hw, last_aq_status));
  7620. goto bw_commit_out;
  7621. }
  7622. /* Read word 0x10 of NVM - SW compatibility word 1 */
  7623. ret = i40e_aq_read_nvm(&pf->hw,
  7624. I40E_SR_NVM_CONTROL_WORD,
  7625. 0x10, sizeof(nvm_word), &nvm_word,
  7626. false, NULL);
  7627. /* Save off last admin queue command status before releasing
  7628. * the NVM
  7629. */
  7630. last_aq_status = pf->hw.aq.asq_last_status;
  7631. i40e_release_nvm(&pf->hw);
  7632. if (ret) {
  7633. dev_info(&pf->pdev->dev, "NVM read error, err %s aq_err %s\n",
  7634. i40e_stat_str(&pf->hw, ret),
  7635. i40e_aq_str(&pf->hw, last_aq_status));
  7636. goto bw_commit_out;
  7637. }
  7638. /* Wait a bit for NVM release to complete */
  7639. msleep(50);
  7640. /* Acquire NVM for write access */
  7641. ret = i40e_acquire_nvm(&pf->hw, I40E_RESOURCE_WRITE);
  7642. last_aq_status = pf->hw.aq.asq_last_status;
  7643. if (ret) {
  7644. dev_info(&pf->pdev->dev,
  7645. "Cannot acquire NVM for write access, err %s aq_err %s\n",
  7646. i40e_stat_str(&pf->hw, ret),
  7647. i40e_aq_str(&pf->hw, last_aq_status));
  7648. goto bw_commit_out;
  7649. }
  7650. /* Write it back out unchanged to initiate update NVM,
  7651. * which will force a write of the shadow (alt) RAM to
  7652. * the NVM - thus storing the bandwidth values permanently.
  7653. */
  7654. ret = i40e_aq_update_nvm(&pf->hw,
  7655. I40E_SR_NVM_CONTROL_WORD,
  7656. 0x10, sizeof(nvm_word),
  7657. &nvm_word, true, NULL);
  7658. /* Save off last admin queue command status before releasing
  7659. * the NVM
  7660. */
  7661. last_aq_status = pf->hw.aq.asq_last_status;
  7662. i40e_release_nvm(&pf->hw);
  7663. if (ret)
  7664. dev_info(&pf->pdev->dev,
  7665. "BW settings NOT SAVED, err %s aq_err %s\n",
  7666. i40e_stat_str(&pf->hw, ret),
  7667. i40e_aq_str(&pf->hw, last_aq_status));
  7668. bw_commit_out:
  7669. return ret;
  7670. }
  7671. /**
  7672. * i40e_sw_init - Initialize general software structures (struct i40e_pf)
  7673. * @pf: board private structure to initialize
  7674. *
  7675. * i40e_sw_init initializes the Adapter private data structure.
  7676. * Fields are initialized based on PCI device information and
  7677. * OS network device settings (MTU size).
  7678. **/
  7679. static int i40e_sw_init(struct i40e_pf *pf)
  7680. {
  7681. int err = 0;
  7682. int size;
  7683. /* Set default capability flags */
  7684. pf->flags = I40E_FLAG_RX_CSUM_ENABLED |
  7685. I40E_FLAG_MSI_ENABLED |
  7686. I40E_FLAG_MSIX_ENABLED;
  7687. /* Set default ITR */
  7688. pf->rx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_RX_DEF;
  7689. pf->tx_itr_default = I40E_ITR_DYNAMIC | I40E_ITR_TX_DEF;
  7690. /* Depending on PF configurations, it is possible that the RSS
  7691. * maximum might end up larger than the available queues
  7692. */
  7693. pf->rss_size_max = BIT(pf->hw.func_caps.rss_table_entry_width);
  7694. pf->alloc_rss_size = 1;
  7695. pf->rss_table_size = pf->hw.func_caps.rss_table_size;
  7696. pf->rss_size_max = min_t(int, pf->rss_size_max,
  7697. pf->hw.func_caps.num_tx_qp);
  7698. if (pf->hw.func_caps.rss) {
  7699. pf->flags |= I40E_FLAG_RSS_ENABLED;
  7700. pf->alloc_rss_size = min_t(int, pf->rss_size_max,
  7701. num_online_cpus());
  7702. }
  7703. /* MFP mode enabled */
  7704. if (pf->hw.func_caps.npar_enable || pf->hw.func_caps.flex10_enable) {
  7705. pf->flags |= I40E_FLAG_MFP_ENABLED;
  7706. dev_info(&pf->pdev->dev, "MFP mode Enabled\n");
  7707. if (i40e_get_npar_bw_setting(pf))
  7708. dev_warn(&pf->pdev->dev,
  7709. "Could not get NPAR bw settings\n");
  7710. else
  7711. dev_info(&pf->pdev->dev,
  7712. "Min BW = %8.8x, Max BW = %8.8x\n",
  7713. pf->npar_min_bw, pf->npar_max_bw);
  7714. }
  7715. /* FW/NVM is not yet fixed in this regard */
  7716. if ((pf->hw.func_caps.fd_filters_guaranteed > 0) ||
  7717. (pf->hw.func_caps.fd_filters_best_effort > 0)) {
  7718. pf->flags |= I40E_FLAG_FD_ATR_ENABLED;
  7719. pf->atr_sample_rate = I40E_DEFAULT_ATR_SAMPLE_RATE;
  7720. if (pf->flags & I40E_FLAG_MFP_ENABLED &&
  7721. pf->hw.num_partitions > 1)
  7722. dev_info(&pf->pdev->dev,
  7723. "Flow Director Sideband mode Disabled in MFP mode\n");
  7724. else
  7725. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  7726. pf->fdir_pf_filter_count =
  7727. pf->hw.func_caps.fd_filters_guaranteed;
  7728. pf->hw.fdir_shared_filter_count =
  7729. pf->hw.func_caps.fd_filters_best_effort;
  7730. }
  7731. if ((pf->hw.mac.type == I40E_MAC_XL710) &&
  7732. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 33)) ||
  7733. (pf->hw.aq.fw_maj_ver < 4))) {
  7734. pf->flags |= I40E_FLAG_RESTART_AUTONEG;
  7735. /* No DCB support for FW < v4.33 */
  7736. pf->flags |= I40E_FLAG_NO_DCB_SUPPORT;
  7737. }
  7738. /* Disable FW LLDP if FW < v4.3 */
  7739. if ((pf->hw.mac.type == I40E_MAC_XL710) &&
  7740. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver < 3)) ||
  7741. (pf->hw.aq.fw_maj_ver < 4)))
  7742. pf->flags |= I40E_FLAG_STOP_FW_LLDP;
  7743. /* Use the FW Set LLDP MIB API if FW > v4.40 */
  7744. if ((pf->hw.mac.type == I40E_MAC_XL710) &&
  7745. (((pf->hw.aq.fw_maj_ver == 4) && (pf->hw.aq.fw_min_ver >= 40)) ||
  7746. (pf->hw.aq.fw_maj_ver >= 5)))
  7747. pf->flags |= I40E_FLAG_USE_SET_LLDP_MIB;
  7748. if (pf->hw.func_caps.vmdq) {
  7749. pf->num_vmdq_vsis = I40E_DEFAULT_NUM_VMDQ_VSI;
  7750. pf->flags |= I40E_FLAG_VMDQ_ENABLED;
  7751. pf->num_vmdq_qps = i40e_default_queues_per_vmdq(pf);
  7752. }
  7753. if (pf->hw.func_caps.iwarp) {
  7754. pf->flags |= I40E_FLAG_IWARP_ENABLED;
  7755. /* IWARP needs one extra vector for CQP just like MISC.*/
  7756. pf->num_iwarp_msix = (int)num_online_cpus() + 1;
  7757. }
  7758. #ifdef I40E_FCOE
  7759. i40e_init_pf_fcoe(pf);
  7760. #endif /* I40E_FCOE */
  7761. #ifdef CONFIG_PCI_IOV
  7762. if (pf->hw.func_caps.num_vfs && pf->hw.partition_id == 1) {
  7763. pf->num_vf_qps = I40E_DEFAULT_QUEUES_PER_VF;
  7764. pf->flags |= I40E_FLAG_SRIOV_ENABLED;
  7765. pf->num_req_vfs = min_t(int,
  7766. pf->hw.func_caps.num_vfs,
  7767. I40E_MAX_VF_COUNT);
  7768. }
  7769. #endif /* CONFIG_PCI_IOV */
  7770. if (pf->hw.mac.type == I40E_MAC_X722) {
  7771. pf->flags |= I40E_FLAG_RSS_AQ_CAPABLE
  7772. | I40E_FLAG_128_QP_RSS_CAPABLE
  7773. | I40E_FLAG_HW_ATR_EVICT_CAPABLE
  7774. | I40E_FLAG_OUTER_UDP_CSUM_CAPABLE
  7775. | I40E_FLAG_WB_ON_ITR_CAPABLE
  7776. | I40E_FLAG_MULTIPLE_TCP_UDP_RSS_PCTYPE
  7777. | I40E_FLAG_NO_PCI_LINK_CHECK
  7778. | I40E_FLAG_USE_SET_LLDP_MIB
  7779. | I40E_FLAG_GENEVE_OFFLOAD_CAPABLE
  7780. | I40E_FLAG_PTP_L4_CAPABLE
  7781. | I40E_FLAG_WOL_MC_MAGIC_PKT_WAKE;
  7782. } else if ((pf->hw.aq.api_maj_ver > 1) ||
  7783. ((pf->hw.aq.api_maj_ver == 1) &&
  7784. (pf->hw.aq.api_min_ver > 4))) {
  7785. /* Supported in FW API version higher than 1.4 */
  7786. pf->flags |= I40E_FLAG_GENEVE_OFFLOAD_CAPABLE;
  7787. pf->hw_disabled_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE;
  7788. } else {
  7789. pf->hw_disabled_flags = I40E_FLAG_HW_ATR_EVICT_CAPABLE;
  7790. }
  7791. pf->eeprom_version = 0xDEAD;
  7792. pf->lan_veb = I40E_NO_VEB;
  7793. pf->lan_vsi = I40E_NO_VSI;
  7794. /* By default FW has this off for performance reasons */
  7795. pf->flags &= ~I40E_FLAG_VEB_STATS_ENABLED;
  7796. /* set up queue assignment tracking */
  7797. size = sizeof(struct i40e_lump_tracking)
  7798. + (sizeof(u16) * pf->hw.func_caps.num_tx_qp);
  7799. pf->qp_pile = kzalloc(size, GFP_KERNEL);
  7800. if (!pf->qp_pile) {
  7801. err = -ENOMEM;
  7802. goto sw_init_done;
  7803. }
  7804. pf->qp_pile->num_entries = pf->hw.func_caps.num_tx_qp;
  7805. pf->qp_pile->search_hint = 0;
  7806. pf->tx_timeout_recovery_level = 1;
  7807. mutex_init(&pf->switch_mutex);
  7808. /* If NPAR is enabled nudge the Tx scheduler */
  7809. if (pf->hw.func_caps.npar_enable && (!i40e_get_npar_bw_setting(pf)))
  7810. i40e_set_npar_bw_setting(pf);
  7811. sw_init_done:
  7812. return err;
  7813. }
  7814. /**
  7815. * i40e_set_ntuple - set the ntuple feature flag and take action
  7816. * @pf: board private structure to initialize
  7817. * @features: the feature set that the stack is suggesting
  7818. *
  7819. * returns a bool to indicate if reset needs to happen
  7820. **/
  7821. bool i40e_set_ntuple(struct i40e_pf *pf, netdev_features_t features)
  7822. {
  7823. bool need_reset = false;
  7824. /* Check if Flow Director n-tuple support was enabled or disabled. If
  7825. * the state changed, we need to reset.
  7826. */
  7827. if (features & NETIF_F_NTUPLE) {
  7828. /* Enable filters and mark for reset */
  7829. if (!(pf->flags & I40E_FLAG_FD_SB_ENABLED))
  7830. need_reset = true;
  7831. /* enable FD_SB only if there is MSI-X vector */
  7832. if (pf->num_fdsb_msix > 0)
  7833. pf->flags |= I40E_FLAG_FD_SB_ENABLED;
  7834. } else {
  7835. /* turn off filters, mark for reset and clear SW filter list */
  7836. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  7837. need_reset = true;
  7838. i40e_fdir_filter_exit(pf);
  7839. }
  7840. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  7841. pf->hw_disabled_flags &= ~I40E_FLAG_FD_SB_ENABLED;
  7842. /* reset fd counters */
  7843. pf->fd_add_err = pf->fd_atr_cnt = pf->fd_tcp_rule = 0;
  7844. pf->fdir_pf_active_filters = 0;
  7845. /* if ATR was auto disabled it can be re-enabled. */
  7846. if ((pf->flags & I40E_FLAG_FD_ATR_ENABLED) &&
  7847. (pf->hw_disabled_flags & I40E_FLAG_FD_ATR_ENABLED)) {
  7848. pf->hw_disabled_flags &= ~I40E_FLAG_FD_ATR_ENABLED;
  7849. if (I40E_DEBUG_FD & pf->hw.debug_mask)
  7850. dev_info(&pf->pdev->dev, "ATR re-enabled.\n");
  7851. }
  7852. }
  7853. return need_reset;
  7854. }
  7855. /**
  7856. * i40e_clear_rss_lut - clear the rx hash lookup table
  7857. * @vsi: the VSI being configured
  7858. **/
  7859. static void i40e_clear_rss_lut(struct i40e_vsi *vsi)
  7860. {
  7861. struct i40e_pf *pf = vsi->back;
  7862. struct i40e_hw *hw = &pf->hw;
  7863. u16 vf_id = vsi->vf_id;
  7864. u8 i;
  7865. if (vsi->type == I40E_VSI_MAIN) {
  7866. for (i = 0; i <= I40E_PFQF_HLUT_MAX_INDEX; i++)
  7867. wr32(hw, I40E_PFQF_HLUT(i), 0);
  7868. } else if (vsi->type == I40E_VSI_SRIOV) {
  7869. for (i = 0; i <= I40E_VFQF_HLUT_MAX_INDEX; i++)
  7870. i40e_write_rx_ctl(hw, I40E_VFQF_HLUT1(i, vf_id), 0);
  7871. } else {
  7872. dev_err(&pf->pdev->dev, "Cannot set RSS LUT - invalid VSI type\n");
  7873. }
  7874. }
  7875. /**
  7876. * i40e_set_features - set the netdev feature flags
  7877. * @netdev: ptr to the netdev being adjusted
  7878. * @features: the feature set that the stack is suggesting
  7879. **/
  7880. static int i40e_set_features(struct net_device *netdev,
  7881. netdev_features_t features)
  7882. {
  7883. struct i40e_netdev_priv *np = netdev_priv(netdev);
  7884. struct i40e_vsi *vsi = np->vsi;
  7885. struct i40e_pf *pf = vsi->back;
  7886. bool need_reset;
  7887. if (features & NETIF_F_RXHASH && !(netdev->features & NETIF_F_RXHASH))
  7888. i40e_pf_config_rss(pf);
  7889. else if (!(features & NETIF_F_RXHASH) &&
  7890. netdev->features & NETIF_F_RXHASH)
  7891. i40e_clear_rss_lut(vsi);
  7892. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  7893. i40e_vlan_stripping_enable(vsi);
  7894. else
  7895. i40e_vlan_stripping_disable(vsi);
  7896. need_reset = i40e_set_ntuple(pf, features);
  7897. if (need_reset)
  7898. i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
  7899. return 0;
  7900. }
  7901. /**
  7902. * i40e_get_udp_port_idx - Lookup a possibly offloaded for Rx UDP port
  7903. * @pf: board private structure
  7904. * @port: The UDP port to look up
  7905. *
  7906. * Returns the index number or I40E_MAX_PF_UDP_OFFLOAD_PORTS if port not found
  7907. **/
  7908. static u8 i40e_get_udp_port_idx(struct i40e_pf *pf, __be16 port)
  7909. {
  7910. u8 i;
  7911. for (i = 0; i < I40E_MAX_PF_UDP_OFFLOAD_PORTS; i++) {
  7912. if (pf->udp_ports[i].index == port)
  7913. return i;
  7914. }
  7915. return i;
  7916. }
  7917. /**
  7918. * i40e_udp_tunnel_add - Get notifications about UDP tunnel ports that come up
  7919. * @netdev: This physical port's netdev
  7920. * @ti: Tunnel endpoint information
  7921. **/
  7922. static void i40e_udp_tunnel_add(struct net_device *netdev,
  7923. struct udp_tunnel_info *ti)
  7924. {
  7925. struct i40e_netdev_priv *np = netdev_priv(netdev);
  7926. struct i40e_vsi *vsi = np->vsi;
  7927. struct i40e_pf *pf = vsi->back;
  7928. __be16 port = ti->port;
  7929. u8 next_idx;
  7930. u8 idx;
  7931. idx = i40e_get_udp_port_idx(pf, port);
  7932. /* Check if port already exists */
  7933. if (idx < I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  7934. netdev_info(netdev, "port %d already offloaded\n",
  7935. ntohs(port));
  7936. return;
  7937. }
  7938. /* Now check if there is space to add the new port */
  7939. next_idx = i40e_get_udp_port_idx(pf, 0);
  7940. if (next_idx == I40E_MAX_PF_UDP_OFFLOAD_PORTS) {
  7941. netdev_info(netdev, "maximum number of offloaded UDP ports reached, not adding port %d\n",
  7942. ntohs(port));
  7943. return;
  7944. }
  7945. switch (ti->type) {
  7946. case UDP_TUNNEL_TYPE_VXLAN:
  7947. pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_VXLAN;
  7948. break;
  7949. case UDP_TUNNEL_TYPE_GENEVE:
  7950. if (!(pf->flags & I40E_FLAG_GENEVE_OFFLOAD_CAPABLE))
  7951. return;
  7952. pf->udp_ports[next_idx].type = I40E_AQC_TUNNEL_TYPE_NGE;
  7953. break;
  7954. default:
  7955. return;
  7956. }
  7957. /* New port: add it and mark its index in the bitmap */
  7958. pf->udp_ports[next_idx].index = port;
  7959. pf->pending_udp_bitmap |= BIT_ULL(next_idx);
  7960. pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
  7961. }
  7962. /**
  7963. * i40e_udp_tunnel_del - Get notifications about UDP tunnel ports that go away
  7964. * @netdev: This physical port's netdev
  7965. * @ti: Tunnel endpoint information
  7966. **/
  7967. static void i40e_udp_tunnel_del(struct net_device *netdev,
  7968. struct udp_tunnel_info *ti)
  7969. {
  7970. struct i40e_netdev_priv *np = netdev_priv(netdev);
  7971. struct i40e_vsi *vsi = np->vsi;
  7972. struct i40e_pf *pf = vsi->back;
  7973. __be16 port = ti->port;
  7974. u8 idx;
  7975. idx = i40e_get_udp_port_idx(pf, port);
  7976. /* Check if port already exists */
  7977. if (idx >= I40E_MAX_PF_UDP_OFFLOAD_PORTS)
  7978. goto not_found;
  7979. switch (ti->type) {
  7980. case UDP_TUNNEL_TYPE_VXLAN:
  7981. if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_VXLAN)
  7982. goto not_found;
  7983. break;
  7984. case UDP_TUNNEL_TYPE_GENEVE:
  7985. if (pf->udp_ports[idx].type != I40E_AQC_TUNNEL_TYPE_NGE)
  7986. goto not_found;
  7987. break;
  7988. default:
  7989. goto not_found;
  7990. }
  7991. /* if port exists, set it to 0 (mark for deletion)
  7992. * and make it pending
  7993. */
  7994. pf->udp_ports[idx].index = 0;
  7995. pf->pending_udp_bitmap |= BIT_ULL(idx);
  7996. pf->flags |= I40E_FLAG_UDP_FILTER_SYNC;
  7997. return;
  7998. not_found:
  7999. netdev_warn(netdev, "UDP port %d was not found, not deleting\n",
  8000. ntohs(port));
  8001. }
  8002. static int i40e_get_phys_port_id(struct net_device *netdev,
  8003. struct netdev_phys_item_id *ppid)
  8004. {
  8005. struct i40e_netdev_priv *np = netdev_priv(netdev);
  8006. struct i40e_pf *pf = np->vsi->back;
  8007. struct i40e_hw *hw = &pf->hw;
  8008. if (!(pf->flags & I40E_FLAG_PORT_ID_VALID))
  8009. return -EOPNOTSUPP;
  8010. ppid->id_len = min_t(int, sizeof(hw->mac.port_addr), sizeof(ppid->id));
  8011. memcpy(ppid->id, hw->mac.port_addr, ppid->id_len);
  8012. return 0;
  8013. }
  8014. /**
  8015. * i40e_ndo_fdb_add - add an entry to the hardware database
  8016. * @ndm: the input from the stack
  8017. * @tb: pointer to array of nladdr (unused)
  8018. * @dev: the net device pointer
  8019. * @addr: the MAC address entry being added
  8020. * @flags: instructions from stack about fdb operation
  8021. */
  8022. static int i40e_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  8023. struct net_device *dev,
  8024. const unsigned char *addr, u16 vid,
  8025. u16 flags)
  8026. {
  8027. struct i40e_netdev_priv *np = netdev_priv(dev);
  8028. struct i40e_pf *pf = np->vsi->back;
  8029. int err = 0;
  8030. if (!(pf->flags & I40E_FLAG_SRIOV_ENABLED))
  8031. return -EOPNOTSUPP;
  8032. if (vid) {
  8033. pr_info("%s: vlans aren't supported yet for dev_uc|mc_add()\n", dev->name);
  8034. return -EINVAL;
  8035. }
  8036. /* Hardware does not support aging addresses so if a
  8037. * ndm_state is given only allow permanent addresses
  8038. */
  8039. if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
  8040. netdev_info(dev, "FDB only supports static addresses\n");
  8041. return -EINVAL;
  8042. }
  8043. if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr))
  8044. err = dev_uc_add_excl(dev, addr);
  8045. else if (is_multicast_ether_addr(addr))
  8046. err = dev_mc_add_excl(dev, addr);
  8047. else
  8048. err = -EINVAL;
  8049. /* Only return duplicate errors if NLM_F_EXCL is set */
  8050. if (err == -EEXIST && !(flags & NLM_F_EXCL))
  8051. err = 0;
  8052. return err;
  8053. }
  8054. /**
  8055. * i40e_ndo_bridge_setlink - Set the hardware bridge mode
  8056. * @dev: the netdev being configured
  8057. * @nlh: RTNL message
  8058. *
  8059. * Inserts a new hardware bridge if not already created and
  8060. * enables the bridging mode requested (VEB or VEPA). If the
  8061. * hardware bridge has already been inserted and the request
  8062. * is to change the mode then that requires a PF reset to
  8063. * allow rebuild of the components with required hardware
  8064. * bridge mode enabled.
  8065. **/
  8066. static int i40e_ndo_bridge_setlink(struct net_device *dev,
  8067. struct nlmsghdr *nlh,
  8068. u16 flags)
  8069. {
  8070. struct i40e_netdev_priv *np = netdev_priv(dev);
  8071. struct i40e_vsi *vsi = np->vsi;
  8072. struct i40e_pf *pf = vsi->back;
  8073. struct i40e_veb *veb = NULL;
  8074. struct nlattr *attr, *br_spec;
  8075. int i, rem;
  8076. /* Only for PF VSI for now */
  8077. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
  8078. return -EOPNOTSUPP;
  8079. /* Find the HW bridge for PF VSI */
  8080. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  8081. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  8082. veb = pf->veb[i];
  8083. }
  8084. br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
  8085. nla_for_each_nested(attr, br_spec, rem) {
  8086. __u16 mode;
  8087. if (nla_type(attr) != IFLA_BRIDGE_MODE)
  8088. continue;
  8089. mode = nla_get_u16(attr);
  8090. if ((mode != BRIDGE_MODE_VEPA) &&
  8091. (mode != BRIDGE_MODE_VEB))
  8092. return -EINVAL;
  8093. /* Insert a new HW bridge */
  8094. if (!veb) {
  8095. veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
  8096. vsi->tc_config.enabled_tc);
  8097. if (veb) {
  8098. veb->bridge_mode = mode;
  8099. i40e_config_bridge_mode(veb);
  8100. } else {
  8101. /* No Bridge HW offload available */
  8102. return -ENOENT;
  8103. }
  8104. break;
  8105. } else if (mode != veb->bridge_mode) {
  8106. /* Existing HW bridge but different mode needs reset */
  8107. veb->bridge_mode = mode;
  8108. /* TODO: If no VFs or VMDq VSIs, disallow VEB mode */
  8109. if (mode == BRIDGE_MODE_VEB)
  8110. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  8111. else
  8112. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  8113. i40e_do_reset(pf, BIT_ULL(__I40E_PF_RESET_REQUESTED));
  8114. break;
  8115. }
  8116. }
  8117. return 0;
  8118. }
  8119. /**
  8120. * i40e_ndo_bridge_getlink - Get the hardware bridge mode
  8121. * @skb: skb buff
  8122. * @pid: process id
  8123. * @seq: RTNL message seq #
  8124. * @dev: the netdev being configured
  8125. * @filter_mask: unused
  8126. * @nlflags: netlink flags passed in
  8127. *
  8128. * Return the mode in which the hardware bridge is operating in
  8129. * i.e VEB or VEPA.
  8130. **/
  8131. static int i40e_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
  8132. struct net_device *dev,
  8133. u32 __always_unused filter_mask,
  8134. int nlflags)
  8135. {
  8136. struct i40e_netdev_priv *np = netdev_priv(dev);
  8137. struct i40e_vsi *vsi = np->vsi;
  8138. struct i40e_pf *pf = vsi->back;
  8139. struct i40e_veb *veb = NULL;
  8140. int i;
  8141. /* Only for PF VSI for now */
  8142. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid)
  8143. return -EOPNOTSUPP;
  8144. /* Find the HW bridge for the PF VSI */
  8145. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  8146. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  8147. veb = pf->veb[i];
  8148. }
  8149. if (!veb)
  8150. return 0;
  8151. return ndo_dflt_bridge_getlink(skb, pid, seq, dev, veb->bridge_mode,
  8152. 0, 0, nlflags, filter_mask, NULL);
  8153. }
  8154. /**
  8155. * i40e_features_check - Validate encapsulated packet conforms to limits
  8156. * @skb: skb buff
  8157. * @dev: This physical port's netdev
  8158. * @features: Offload features that the stack believes apply
  8159. **/
  8160. static netdev_features_t i40e_features_check(struct sk_buff *skb,
  8161. struct net_device *dev,
  8162. netdev_features_t features)
  8163. {
  8164. size_t len;
  8165. /* No point in doing any of this if neither checksum nor GSO are
  8166. * being requested for this frame. We can rule out both by just
  8167. * checking for CHECKSUM_PARTIAL
  8168. */
  8169. if (skb->ip_summed != CHECKSUM_PARTIAL)
  8170. return features;
  8171. /* We cannot support GSO if the MSS is going to be less than
  8172. * 64 bytes. If it is then we need to drop support for GSO.
  8173. */
  8174. if (skb_is_gso(skb) && (skb_shinfo(skb)->gso_size < 64))
  8175. features &= ~NETIF_F_GSO_MASK;
  8176. /* MACLEN can support at most 63 words */
  8177. len = skb_network_header(skb) - skb->data;
  8178. if (len & ~(63 * 2))
  8179. goto out_err;
  8180. /* IPLEN and EIPLEN can support at most 127 dwords */
  8181. len = skb_transport_header(skb) - skb_network_header(skb);
  8182. if (len & ~(127 * 4))
  8183. goto out_err;
  8184. if (skb->encapsulation) {
  8185. /* L4TUNLEN can support 127 words */
  8186. len = skb_inner_network_header(skb) - skb_transport_header(skb);
  8187. if (len & ~(127 * 2))
  8188. goto out_err;
  8189. /* IPLEN can support at most 127 dwords */
  8190. len = skb_inner_transport_header(skb) -
  8191. skb_inner_network_header(skb);
  8192. if (len & ~(127 * 4))
  8193. goto out_err;
  8194. }
  8195. /* No need to validate L4LEN as TCP is the only protocol with a
  8196. * a flexible value and we support all possible values supported
  8197. * by TCP, which is at most 15 dwords
  8198. */
  8199. return features;
  8200. out_err:
  8201. return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
  8202. }
  8203. static const struct net_device_ops i40e_netdev_ops = {
  8204. .ndo_open = i40e_open,
  8205. .ndo_stop = i40e_close,
  8206. .ndo_start_xmit = i40e_lan_xmit_frame,
  8207. .ndo_get_stats64 = i40e_get_netdev_stats_struct,
  8208. .ndo_set_rx_mode = i40e_set_rx_mode,
  8209. .ndo_validate_addr = eth_validate_addr,
  8210. .ndo_set_mac_address = i40e_set_mac,
  8211. .ndo_change_mtu = i40e_change_mtu,
  8212. .ndo_do_ioctl = i40e_ioctl,
  8213. .ndo_tx_timeout = i40e_tx_timeout,
  8214. .ndo_vlan_rx_add_vid = i40e_vlan_rx_add_vid,
  8215. .ndo_vlan_rx_kill_vid = i40e_vlan_rx_kill_vid,
  8216. #ifdef CONFIG_NET_POLL_CONTROLLER
  8217. .ndo_poll_controller = i40e_netpoll,
  8218. #endif
  8219. .ndo_setup_tc = __i40e_setup_tc,
  8220. #ifdef I40E_FCOE
  8221. .ndo_fcoe_enable = i40e_fcoe_enable,
  8222. .ndo_fcoe_disable = i40e_fcoe_disable,
  8223. #endif
  8224. .ndo_set_features = i40e_set_features,
  8225. .ndo_set_vf_mac = i40e_ndo_set_vf_mac,
  8226. .ndo_set_vf_vlan = i40e_ndo_set_vf_port_vlan,
  8227. .ndo_set_vf_rate = i40e_ndo_set_vf_bw,
  8228. .ndo_get_vf_config = i40e_ndo_get_vf_config,
  8229. .ndo_set_vf_link_state = i40e_ndo_set_vf_link_state,
  8230. .ndo_set_vf_spoofchk = i40e_ndo_set_vf_spoofchk,
  8231. .ndo_set_vf_trust = i40e_ndo_set_vf_trust,
  8232. .ndo_udp_tunnel_add = i40e_udp_tunnel_add,
  8233. .ndo_udp_tunnel_del = i40e_udp_tunnel_del,
  8234. .ndo_get_phys_port_id = i40e_get_phys_port_id,
  8235. .ndo_fdb_add = i40e_ndo_fdb_add,
  8236. .ndo_features_check = i40e_features_check,
  8237. .ndo_bridge_getlink = i40e_ndo_bridge_getlink,
  8238. .ndo_bridge_setlink = i40e_ndo_bridge_setlink,
  8239. };
  8240. /**
  8241. * i40e_config_netdev - Setup the netdev flags
  8242. * @vsi: the VSI being configured
  8243. *
  8244. * Returns 0 on success, negative value on failure
  8245. **/
  8246. static int i40e_config_netdev(struct i40e_vsi *vsi)
  8247. {
  8248. struct i40e_pf *pf = vsi->back;
  8249. struct i40e_hw *hw = &pf->hw;
  8250. struct i40e_netdev_priv *np;
  8251. struct net_device *netdev;
  8252. u8 broadcast[ETH_ALEN];
  8253. u8 mac_addr[ETH_ALEN];
  8254. int etherdev_size;
  8255. etherdev_size = sizeof(struct i40e_netdev_priv);
  8256. netdev = alloc_etherdev_mq(etherdev_size, vsi->alloc_queue_pairs);
  8257. if (!netdev)
  8258. return -ENOMEM;
  8259. vsi->netdev = netdev;
  8260. np = netdev_priv(netdev);
  8261. np->vsi = vsi;
  8262. netdev->hw_enc_features |= NETIF_F_SG |
  8263. NETIF_F_IP_CSUM |
  8264. NETIF_F_IPV6_CSUM |
  8265. NETIF_F_HIGHDMA |
  8266. NETIF_F_SOFT_FEATURES |
  8267. NETIF_F_TSO |
  8268. NETIF_F_TSO_ECN |
  8269. NETIF_F_TSO6 |
  8270. NETIF_F_GSO_GRE |
  8271. NETIF_F_GSO_GRE_CSUM |
  8272. NETIF_F_GSO_IPXIP4 |
  8273. NETIF_F_GSO_IPXIP6 |
  8274. NETIF_F_GSO_UDP_TUNNEL |
  8275. NETIF_F_GSO_UDP_TUNNEL_CSUM |
  8276. NETIF_F_GSO_PARTIAL |
  8277. NETIF_F_SCTP_CRC |
  8278. NETIF_F_RXHASH |
  8279. NETIF_F_RXCSUM |
  8280. 0;
  8281. if (!(pf->flags & I40E_FLAG_OUTER_UDP_CSUM_CAPABLE))
  8282. netdev->gso_partial_features |= NETIF_F_GSO_UDP_TUNNEL_CSUM;
  8283. netdev->gso_partial_features |= NETIF_F_GSO_GRE_CSUM;
  8284. /* record features VLANs can make use of */
  8285. netdev->vlan_features |= netdev->hw_enc_features |
  8286. NETIF_F_TSO_MANGLEID;
  8287. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  8288. netdev->hw_features |= NETIF_F_NTUPLE;
  8289. netdev->hw_features |= netdev->hw_enc_features |
  8290. NETIF_F_HW_VLAN_CTAG_TX |
  8291. NETIF_F_HW_VLAN_CTAG_RX;
  8292. netdev->features |= netdev->hw_features | NETIF_F_HW_VLAN_CTAG_FILTER;
  8293. netdev->hw_enc_features |= NETIF_F_TSO_MANGLEID;
  8294. if (vsi->type == I40E_VSI_MAIN) {
  8295. SET_NETDEV_DEV(netdev, &pf->pdev->dev);
  8296. ether_addr_copy(mac_addr, hw->mac.perm_addr);
  8297. /* The following steps are necessary to properly keep track of
  8298. * MAC-VLAN filters loaded into firmware - first we remove
  8299. * filter that is automatically generated by firmware and then
  8300. * add new filter both to the driver hash table and firmware.
  8301. */
  8302. i40e_rm_default_mac_filter(vsi, mac_addr);
  8303. spin_lock_bh(&vsi->mac_filter_hash_lock);
  8304. i40e_add_mac_filter(vsi, mac_addr);
  8305. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  8306. } else {
  8307. /* relate the VSI_VMDQ name to the VSI_MAIN name */
  8308. snprintf(netdev->name, IFNAMSIZ, "%sv%%d",
  8309. pf->vsi[pf->lan_vsi]->netdev->name);
  8310. random_ether_addr(mac_addr);
  8311. spin_lock_bh(&vsi->mac_filter_hash_lock);
  8312. i40e_add_mac_filter(vsi, mac_addr);
  8313. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  8314. }
  8315. /* Add the broadcast filter so that we initially will receive
  8316. * broadcast packets. Note that when a new VLAN is first added the
  8317. * driver will convert all filters marked I40E_VLAN_ANY into VLAN
  8318. * specific filters as part of transitioning into "vlan" operation.
  8319. * When more VLANs are added, the driver will copy each existing MAC
  8320. * filter and add it for the new VLAN.
  8321. *
  8322. * Broadcast filters are handled specially by
  8323. * i40e_sync_filters_subtask, as the driver must to set the broadcast
  8324. * promiscuous bit instead of adding this directly as a MAC/VLAN
  8325. * filter. The subtask will update the correct broadcast promiscuous
  8326. * bits as VLANs become active or inactive.
  8327. */
  8328. eth_broadcast_addr(broadcast);
  8329. spin_lock_bh(&vsi->mac_filter_hash_lock);
  8330. i40e_add_mac_filter(vsi, broadcast);
  8331. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  8332. ether_addr_copy(netdev->dev_addr, mac_addr);
  8333. ether_addr_copy(netdev->perm_addr, mac_addr);
  8334. netdev->priv_flags |= IFF_UNICAST_FLT;
  8335. netdev->priv_flags |= IFF_SUPP_NOFCS;
  8336. /* Setup netdev TC information */
  8337. i40e_vsi_config_netdev_tc(vsi, vsi->tc_config.enabled_tc);
  8338. netdev->netdev_ops = &i40e_netdev_ops;
  8339. netdev->watchdog_timeo = 5 * HZ;
  8340. i40e_set_ethtool_ops(netdev);
  8341. #ifdef I40E_FCOE
  8342. i40e_fcoe_config_netdev(netdev, vsi);
  8343. #endif
  8344. /* MTU range: 68 - 9706 */
  8345. netdev->min_mtu = ETH_MIN_MTU;
  8346. netdev->max_mtu = I40E_MAX_RXBUFFER -
  8347. (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN);
  8348. return 0;
  8349. }
  8350. /**
  8351. * i40e_vsi_delete - Delete a VSI from the switch
  8352. * @vsi: the VSI being removed
  8353. *
  8354. * Returns 0 on success, negative value on failure
  8355. **/
  8356. static void i40e_vsi_delete(struct i40e_vsi *vsi)
  8357. {
  8358. /* remove default VSI is not allowed */
  8359. if (vsi == vsi->back->vsi[vsi->back->lan_vsi])
  8360. return;
  8361. i40e_aq_delete_element(&vsi->back->hw, vsi->seid, NULL);
  8362. }
  8363. /**
  8364. * i40e_is_vsi_uplink_mode_veb - Check if the VSI's uplink bridge mode is VEB
  8365. * @vsi: the VSI being queried
  8366. *
  8367. * Returns 1 if HW bridge mode is VEB and return 0 in case of VEPA mode
  8368. **/
  8369. int i40e_is_vsi_uplink_mode_veb(struct i40e_vsi *vsi)
  8370. {
  8371. struct i40e_veb *veb;
  8372. struct i40e_pf *pf = vsi->back;
  8373. /* Uplink is not a bridge so default to VEB */
  8374. if (vsi->veb_idx == I40E_NO_VEB)
  8375. return 1;
  8376. veb = pf->veb[vsi->veb_idx];
  8377. if (!veb) {
  8378. dev_info(&pf->pdev->dev,
  8379. "There is no veb associated with the bridge\n");
  8380. return -ENOENT;
  8381. }
  8382. /* Uplink is a bridge in VEPA mode */
  8383. if (veb->bridge_mode & BRIDGE_MODE_VEPA) {
  8384. return 0;
  8385. } else {
  8386. /* Uplink is a bridge in VEB mode */
  8387. return 1;
  8388. }
  8389. /* VEPA is now default bridge, so return 0 */
  8390. return 0;
  8391. }
  8392. /**
  8393. * i40e_add_vsi - Add a VSI to the switch
  8394. * @vsi: the VSI being configured
  8395. *
  8396. * This initializes a VSI context depending on the VSI type to be added and
  8397. * passes it down to the add_vsi aq command.
  8398. **/
  8399. static int i40e_add_vsi(struct i40e_vsi *vsi)
  8400. {
  8401. int ret = -ENODEV;
  8402. struct i40e_pf *pf = vsi->back;
  8403. struct i40e_hw *hw = &pf->hw;
  8404. struct i40e_vsi_context ctxt;
  8405. struct i40e_mac_filter *f;
  8406. struct hlist_node *h;
  8407. int bkt;
  8408. u8 enabled_tc = 0x1; /* TC0 enabled */
  8409. int f_count = 0;
  8410. memset(&ctxt, 0, sizeof(ctxt));
  8411. switch (vsi->type) {
  8412. case I40E_VSI_MAIN:
  8413. /* The PF's main VSI is already setup as part of the
  8414. * device initialization, so we'll not bother with
  8415. * the add_vsi call, but we will retrieve the current
  8416. * VSI context.
  8417. */
  8418. ctxt.seid = pf->main_vsi_seid;
  8419. ctxt.pf_num = pf->hw.pf_id;
  8420. ctxt.vf_num = 0;
  8421. ret = i40e_aq_get_vsi_params(&pf->hw, &ctxt, NULL);
  8422. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  8423. if (ret) {
  8424. dev_info(&pf->pdev->dev,
  8425. "couldn't get PF vsi config, err %s aq_err %s\n",
  8426. i40e_stat_str(&pf->hw, ret),
  8427. i40e_aq_str(&pf->hw,
  8428. pf->hw.aq.asq_last_status));
  8429. return -ENOENT;
  8430. }
  8431. vsi->info = ctxt.info;
  8432. vsi->info.valid_sections = 0;
  8433. vsi->seid = ctxt.seid;
  8434. vsi->id = ctxt.vsi_number;
  8435. enabled_tc = i40e_pf_get_tc_map(pf);
  8436. /* MFP mode setup queue map and update VSI */
  8437. if ((pf->flags & I40E_FLAG_MFP_ENABLED) &&
  8438. !(pf->hw.func_caps.iscsi)) { /* NIC type PF */
  8439. memset(&ctxt, 0, sizeof(ctxt));
  8440. ctxt.seid = pf->main_vsi_seid;
  8441. ctxt.pf_num = pf->hw.pf_id;
  8442. ctxt.vf_num = 0;
  8443. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, false);
  8444. ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
  8445. if (ret) {
  8446. dev_info(&pf->pdev->dev,
  8447. "update vsi failed, err %s aq_err %s\n",
  8448. i40e_stat_str(&pf->hw, ret),
  8449. i40e_aq_str(&pf->hw,
  8450. pf->hw.aq.asq_last_status));
  8451. ret = -ENOENT;
  8452. goto err;
  8453. }
  8454. /* update the local VSI info queue map */
  8455. i40e_vsi_update_queue_map(vsi, &ctxt);
  8456. vsi->info.valid_sections = 0;
  8457. } else {
  8458. /* Default/Main VSI is only enabled for TC0
  8459. * reconfigure it to enable all TCs that are
  8460. * available on the port in SFP mode.
  8461. * For MFP case the iSCSI PF would use this
  8462. * flow to enable LAN+iSCSI TC.
  8463. */
  8464. ret = i40e_vsi_config_tc(vsi, enabled_tc);
  8465. if (ret) {
  8466. dev_info(&pf->pdev->dev,
  8467. "failed to configure TCs for main VSI tc_map 0x%08x, err %s aq_err %s\n",
  8468. enabled_tc,
  8469. i40e_stat_str(&pf->hw, ret),
  8470. i40e_aq_str(&pf->hw,
  8471. pf->hw.aq.asq_last_status));
  8472. ret = -ENOENT;
  8473. }
  8474. }
  8475. break;
  8476. case I40E_VSI_FDIR:
  8477. ctxt.pf_num = hw->pf_id;
  8478. ctxt.vf_num = 0;
  8479. ctxt.uplink_seid = vsi->uplink_seid;
  8480. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  8481. ctxt.flags = I40E_AQ_VSI_TYPE_PF;
  8482. if ((pf->flags & I40E_FLAG_VEB_MODE_ENABLED) &&
  8483. (i40e_is_vsi_uplink_mode_veb(vsi))) {
  8484. ctxt.info.valid_sections |=
  8485. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  8486. ctxt.info.switch_id =
  8487. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  8488. }
  8489. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  8490. break;
  8491. case I40E_VSI_VMDQ2:
  8492. ctxt.pf_num = hw->pf_id;
  8493. ctxt.vf_num = 0;
  8494. ctxt.uplink_seid = vsi->uplink_seid;
  8495. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  8496. ctxt.flags = I40E_AQ_VSI_TYPE_VMDQ2;
  8497. /* This VSI is connected to VEB so the switch_id
  8498. * should be set to zero by default.
  8499. */
  8500. if (i40e_is_vsi_uplink_mode_veb(vsi)) {
  8501. ctxt.info.valid_sections |=
  8502. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  8503. ctxt.info.switch_id =
  8504. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  8505. }
  8506. /* Setup the VSI tx/rx queue map for TC0 only for now */
  8507. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  8508. break;
  8509. case I40E_VSI_SRIOV:
  8510. ctxt.pf_num = hw->pf_id;
  8511. ctxt.vf_num = vsi->vf_id + hw->func_caps.vf_base_id;
  8512. ctxt.uplink_seid = vsi->uplink_seid;
  8513. ctxt.connection_type = I40E_AQ_VSI_CONN_TYPE_NORMAL;
  8514. ctxt.flags = I40E_AQ_VSI_TYPE_VF;
  8515. /* This VSI is connected to VEB so the switch_id
  8516. * should be set to zero by default.
  8517. */
  8518. if (i40e_is_vsi_uplink_mode_veb(vsi)) {
  8519. ctxt.info.valid_sections |=
  8520. cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
  8521. ctxt.info.switch_id =
  8522. cpu_to_le16(I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB);
  8523. }
  8524. if (vsi->back->flags & I40E_FLAG_IWARP_ENABLED) {
  8525. ctxt.info.valid_sections |=
  8526. cpu_to_le16(I40E_AQ_VSI_PROP_QUEUE_OPT_VALID);
  8527. ctxt.info.queueing_opt_flags |=
  8528. (I40E_AQ_VSI_QUE_OPT_TCP_ENA |
  8529. I40E_AQ_VSI_QUE_OPT_RSS_LUT_VSI);
  8530. }
  8531. ctxt.info.valid_sections |= cpu_to_le16(I40E_AQ_VSI_PROP_VLAN_VALID);
  8532. ctxt.info.port_vlan_flags |= I40E_AQ_VSI_PVLAN_MODE_ALL;
  8533. if (pf->vf[vsi->vf_id].spoofchk) {
  8534. ctxt.info.valid_sections |=
  8535. cpu_to_le16(I40E_AQ_VSI_PROP_SECURITY_VALID);
  8536. ctxt.info.sec_flags |=
  8537. (I40E_AQ_VSI_SEC_FLAG_ENABLE_VLAN_CHK |
  8538. I40E_AQ_VSI_SEC_FLAG_ENABLE_MAC_CHK);
  8539. }
  8540. /* Setup the VSI tx/rx queue map for TC0 only for now */
  8541. i40e_vsi_setup_queue_map(vsi, &ctxt, enabled_tc, true);
  8542. break;
  8543. #ifdef I40E_FCOE
  8544. case I40E_VSI_FCOE:
  8545. ret = i40e_fcoe_vsi_init(vsi, &ctxt);
  8546. if (ret) {
  8547. dev_info(&pf->pdev->dev, "failed to initialize FCoE VSI\n");
  8548. return ret;
  8549. }
  8550. break;
  8551. #endif /* I40E_FCOE */
  8552. case I40E_VSI_IWARP:
  8553. /* send down message to iWARP */
  8554. break;
  8555. default:
  8556. return -ENODEV;
  8557. }
  8558. if (vsi->type != I40E_VSI_MAIN) {
  8559. ret = i40e_aq_add_vsi(hw, &ctxt, NULL);
  8560. if (ret) {
  8561. dev_info(&vsi->back->pdev->dev,
  8562. "add vsi failed, err %s aq_err %s\n",
  8563. i40e_stat_str(&pf->hw, ret),
  8564. i40e_aq_str(&pf->hw,
  8565. pf->hw.aq.asq_last_status));
  8566. ret = -ENOENT;
  8567. goto err;
  8568. }
  8569. vsi->info = ctxt.info;
  8570. vsi->info.valid_sections = 0;
  8571. vsi->seid = ctxt.seid;
  8572. vsi->id = ctxt.vsi_number;
  8573. }
  8574. vsi->active_filters = 0;
  8575. clear_bit(__I40E_FILTER_OVERFLOW_PROMISC, &vsi->state);
  8576. spin_lock_bh(&vsi->mac_filter_hash_lock);
  8577. /* If macvlan filters already exist, force them to get loaded */
  8578. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist) {
  8579. f->state = I40E_FILTER_NEW;
  8580. f_count++;
  8581. }
  8582. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  8583. if (f_count) {
  8584. vsi->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
  8585. pf->flags |= I40E_FLAG_FILTER_SYNC;
  8586. }
  8587. /* Update VSI BW information */
  8588. ret = i40e_vsi_get_bw_info(vsi);
  8589. if (ret) {
  8590. dev_info(&pf->pdev->dev,
  8591. "couldn't get vsi bw info, err %s aq_err %s\n",
  8592. i40e_stat_str(&pf->hw, ret),
  8593. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  8594. /* VSI is already added so not tearing that up */
  8595. ret = 0;
  8596. }
  8597. err:
  8598. return ret;
  8599. }
  8600. /**
  8601. * i40e_vsi_release - Delete a VSI and free its resources
  8602. * @vsi: the VSI being removed
  8603. *
  8604. * Returns 0 on success or < 0 on error
  8605. **/
  8606. int i40e_vsi_release(struct i40e_vsi *vsi)
  8607. {
  8608. struct i40e_mac_filter *f;
  8609. struct hlist_node *h;
  8610. struct i40e_veb *veb = NULL;
  8611. struct i40e_pf *pf;
  8612. u16 uplink_seid;
  8613. int i, n, bkt;
  8614. pf = vsi->back;
  8615. /* release of a VEB-owner or last VSI is not allowed */
  8616. if (vsi->flags & I40E_VSI_FLAG_VEB_OWNER) {
  8617. dev_info(&pf->pdev->dev, "VSI %d has existing VEB %d\n",
  8618. vsi->seid, vsi->uplink_seid);
  8619. return -ENODEV;
  8620. }
  8621. if (vsi == pf->vsi[pf->lan_vsi] &&
  8622. !test_bit(__I40E_DOWN, &pf->state)) {
  8623. dev_info(&pf->pdev->dev, "Can't remove PF VSI\n");
  8624. return -ENODEV;
  8625. }
  8626. uplink_seid = vsi->uplink_seid;
  8627. if (vsi->type != I40E_VSI_SRIOV) {
  8628. if (vsi->netdev_registered) {
  8629. vsi->netdev_registered = false;
  8630. if (vsi->netdev) {
  8631. /* results in a call to i40e_close() */
  8632. unregister_netdev(vsi->netdev);
  8633. }
  8634. } else {
  8635. i40e_vsi_close(vsi);
  8636. }
  8637. i40e_vsi_disable_irq(vsi);
  8638. }
  8639. spin_lock_bh(&vsi->mac_filter_hash_lock);
  8640. /* clear the sync flag on all filters */
  8641. if (vsi->netdev) {
  8642. __dev_uc_unsync(vsi->netdev, NULL);
  8643. __dev_mc_unsync(vsi->netdev, NULL);
  8644. }
  8645. /* make sure any remaining filters are marked for deletion */
  8646. hash_for_each_safe(vsi->mac_filter_hash, bkt, h, f, hlist)
  8647. __i40e_del_filter(vsi, f);
  8648. spin_unlock_bh(&vsi->mac_filter_hash_lock);
  8649. i40e_sync_vsi_filters(vsi);
  8650. i40e_vsi_delete(vsi);
  8651. i40e_vsi_free_q_vectors(vsi);
  8652. if (vsi->netdev) {
  8653. free_netdev(vsi->netdev);
  8654. vsi->netdev = NULL;
  8655. }
  8656. i40e_vsi_clear_rings(vsi);
  8657. i40e_vsi_clear(vsi);
  8658. /* If this was the last thing on the VEB, except for the
  8659. * controlling VSI, remove the VEB, which puts the controlling
  8660. * VSI onto the next level down in the switch.
  8661. *
  8662. * Well, okay, there's one more exception here: don't remove
  8663. * the orphan VEBs yet. We'll wait for an explicit remove request
  8664. * from up the network stack.
  8665. */
  8666. for (n = 0, i = 0; i < pf->num_alloc_vsi; i++) {
  8667. if (pf->vsi[i] &&
  8668. pf->vsi[i]->uplink_seid == uplink_seid &&
  8669. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  8670. n++; /* count the VSIs */
  8671. }
  8672. }
  8673. for (i = 0; i < I40E_MAX_VEB; i++) {
  8674. if (!pf->veb[i])
  8675. continue;
  8676. if (pf->veb[i]->uplink_seid == uplink_seid)
  8677. n++; /* count the VEBs */
  8678. if (pf->veb[i]->seid == uplink_seid)
  8679. veb = pf->veb[i];
  8680. }
  8681. if (n == 0 && veb && veb->uplink_seid != 0)
  8682. i40e_veb_release(veb);
  8683. return 0;
  8684. }
  8685. /**
  8686. * i40e_vsi_setup_vectors - Set up the q_vectors for the given VSI
  8687. * @vsi: ptr to the VSI
  8688. *
  8689. * This should only be called after i40e_vsi_mem_alloc() which allocates the
  8690. * corresponding SW VSI structure and initializes num_queue_pairs for the
  8691. * newly allocated VSI.
  8692. *
  8693. * Returns 0 on success or negative on failure
  8694. **/
  8695. static int i40e_vsi_setup_vectors(struct i40e_vsi *vsi)
  8696. {
  8697. int ret = -ENOENT;
  8698. struct i40e_pf *pf = vsi->back;
  8699. if (vsi->q_vectors[0]) {
  8700. dev_info(&pf->pdev->dev, "VSI %d has existing q_vectors\n",
  8701. vsi->seid);
  8702. return -EEXIST;
  8703. }
  8704. if (vsi->base_vector) {
  8705. dev_info(&pf->pdev->dev, "VSI %d has non-zero base vector %d\n",
  8706. vsi->seid, vsi->base_vector);
  8707. return -EEXIST;
  8708. }
  8709. ret = i40e_vsi_alloc_q_vectors(vsi);
  8710. if (ret) {
  8711. dev_info(&pf->pdev->dev,
  8712. "failed to allocate %d q_vector for VSI %d, ret=%d\n",
  8713. vsi->num_q_vectors, vsi->seid, ret);
  8714. vsi->num_q_vectors = 0;
  8715. goto vector_setup_out;
  8716. }
  8717. /* In Legacy mode, we do not have to get any other vector since we
  8718. * piggyback on the misc/ICR0 for queue interrupts.
  8719. */
  8720. if (!(pf->flags & I40E_FLAG_MSIX_ENABLED))
  8721. return ret;
  8722. if (vsi->num_q_vectors)
  8723. vsi->base_vector = i40e_get_lump(pf, pf->irq_pile,
  8724. vsi->num_q_vectors, vsi->idx);
  8725. if (vsi->base_vector < 0) {
  8726. dev_info(&pf->pdev->dev,
  8727. "failed to get tracking for %d vectors for VSI %d, err=%d\n",
  8728. vsi->num_q_vectors, vsi->seid, vsi->base_vector);
  8729. i40e_vsi_free_q_vectors(vsi);
  8730. ret = -ENOENT;
  8731. goto vector_setup_out;
  8732. }
  8733. vector_setup_out:
  8734. return ret;
  8735. }
  8736. /**
  8737. * i40e_vsi_reinit_setup - return and reallocate resources for a VSI
  8738. * @vsi: pointer to the vsi.
  8739. *
  8740. * This re-allocates a vsi's queue resources.
  8741. *
  8742. * Returns pointer to the successfully allocated and configured VSI sw struct
  8743. * on success, otherwise returns NULL on failure.
  8744. **/
  8745. static struct i40e_vsi *i40e_vsi_reinit_setup(struct i40e_vsi *vsi)
  8746. {
  8747. struct i40e_pf *pf;
  8748. u8 enabled_tc;
  8749. int ret;
  8750. if (!vsi)
  8751. return NULL;
  8752. pf = vsi->back;
  8753. i40e_put_lump(pf->qp_pile, vsi->base_queue, vsi->idx);
  8754. i40e_vsi_clear_rings(vsi);
  8755. i40e_vsi_free_arrays(vsi, false);
  8756. i40e_set_num_rings_in_vsi(vsi);
  8757. ret = i40e_vsi_alloc_arrays(vsi, false);
  8758. if (ret)
  8759. goto err_vsi;
  8760. ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs, vsi->idx);
  8761. if (ret < 0) {
  8762. dev_info(&pf->pdev->dev,
  8763. "failed to get tracking for %d queues for VSI %d err %d\n",
  8764. vsi->alloc_queue_pairs, vsi->seid, ret);
  8765. goto err_vsi;
  8766. }
  8767. vsi->base_queue = ret;
  8768. /* Update the FW view of the VSI. Force a reset of TC and queue
  8769. * layout configurations.
  8770. */
  8771. enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  8772. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  8773. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  8774. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  8775. if (vsi->type == I40E_VSI_MAIN)
  8776. i40e_rm_default_mac_filter(vsi, pf->hw.mac.perm_addr);
  8777. /* assign it some queues */
  8778. ret = i40e_alloc_rings(vsi);
  8779. if (ret)
  8780. goto err_rings;
  8781. /* map all of the rings to the q_vectors */
  8782. i40e_vsi_map_rings_to_vectors(vsi);
  8783. return vsi;
  8784. err_rings:
  8785. i40e_vsi_free_q_vectors(vsi);
  8786. if (vsi->netdev_registered) {
  8787. vsi->netdev_registered = false;
  8788. unregister_netdev(vsi->netdev);
  8789. free_netdev(vsi->netdev);
  8790. vsi->netdev = NULL;
  8791. }
  8792. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  8793. err_vsi:
  8794. i40e_vsi_clear(vsi);
  8795. return NULL;
  8796. }
  8797. /**
  8798. * i40e_vsi_setup - Set up a VSI by a given type
  8799. * @pf: board private structure
  8800. * @type: VSI type
  8801. * @uplink_seid: the switch element to link to
  8802. * @param1: usage depends upon VSI type. For VF types, indicates VF id
  8803. *
  8804. * This allocates the sw VSI structure and its queue resources, then add a VSI
  8805. * to the identified VEB.
  8806. *
  8807. * Returns pointer to the successfully allocated and configure VSI sw struct on
  8808. * success, otherwise returns NULL on failure.
  8809. **/
  8810. struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf, u8 type,
  8811. u16 uplink_seid, u32 param1)
  8812. {
  8813. struct i40e_vsi *vsi = NULL;
  8814. struct i40e_veb *veb = NULL;
  8815. int ret, i;
  8816. int v_idx;
  8817. /* The requested uplink_seid must be either
  8818. * - the PF's port seid
  8819. * no VEB is needed because this is the PF
  8820. * or this is a Flow Director special case VSI
  8821. * - seid of an existing VEB
  8822. * - seid of a VSI that owns an existing VEB
  8823. * - seid of a VSI that doesn't own a VEB
  8824. * a new VEB is created and the VSI becomes the owner
  8825. * - seid of the PF VSI, which is what creates the first VEB
  8826. * this is a special case of the previous
  8827. *
  8828. * Find which uplink_seid we were given and create a new VEB if needed
  8829. */
  8830. for (i = 0; i < I40E_MAX_VEB; i++) {
  8831. if (pf->veb[i] && pf->veb[i]->seid == uplink_seid) {
  8832. veb = pf->veb[i];
  8833. break;
  8834. }
  8835. }
  8836. if (!veb && uplink_seid != pf->mac_seid) {
  8837. for (i = 0; i < pf->num_alloc_vsi; i++) {
  8838. if (pf->vsi[i] && pf->vsi[i]->seid == uplink_seid) {
  8839. vsi = pf->vsi[i];
  8840. break;
  8841. }
  8842. }
  8843. if (!vsi) {
  8844. dev_info(&pf->pdev->dev, "no such uplink_seid %d\n",
  8845. uplink_seid);
  8846. return NULL;
  8847. }
  8848. if (vsi->uplink_seid == pf->mac_seid)
  8849. veb = i40e_veb_setup(pf, 0, pf->mac_seid, vsi->seid,
  8850. vsi->tc_config.enabled_tc);
  8851. else if ((vsi->flags & I40E_VSI_FLAG_VEB_OWNER) == 0)
  8852. veb = i40e_veb_setup(pf, 0, vsi->uplink_seid, vsi->seid,
  8853. vsi->tc_config.enabled_tc);
  8854. if (veb) {
  8855. if (vsi->seid != pf->vsi[pf->lan_vsi]->seid) {
  8856. dev_info(&vsi->back->pdev->dev,
  8857. "New VSI creation error, uplink seid of LAN VSI expected.\n");
  8858. return NULL;
  8859. }
  8860. /* We come up by default in VEPA mode if SRIOV is not
  8861. * already enabled, in which case we can't force VEPA
  8862. * mode.
  8863. */
  8864. if (!(pf->flags & I40E_FLAG_VEB_MODE_ENABLED)) {
  8865. veb->bridge_mode = BRIDGE_MODE_VEPA;
  8866. pf->flags &= ~I40E_FLAG_VEB_MODE_ENABLED;
  8867. }
  8868. i40e_config_bridge_mode(veb);
  8869. }
  8870. for (i = 0; i < I40E_MAX_VEB && !veb; i++) {
  8871. if (pf->veb[i] && pf->veb[i]->seid == vsi->uplink_seid)
  8872. veb = pf->veb[i];
  8873. }
  8874. if (!veb) {
  8875. dev_info(&pf->pdev->dev, "couldn't add VEB\n");
  8876. return NULL;
  8877. }
  8878. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  8879. uplink_seid = veb->seid;
  8880. }
  8881. /* get vsi sw struct */
  8882. v_idx = i40e_vsi_mem_alloc(pf, type);
  8883. if (v_idx < 0)
  8884. goto err_alloc;
  8885. vsi = pf->vsi[v_idx];
  8886. if (!vsi)
  8887. goto err_alloc;
  8888. vsi->type = type;
  8889. vsi->veb_idx = (veb ? veb->idx : I40E_NO_VEB);
  8890. if (type == I40E_VSI_MAIN)
  8891. pf->lan_vsi = v_idx;
  8892. else if (type == I40E_VSI_SRIOV)
  8893. vsi->vf_id = param1;
  8894. /* assign it some queues */
  8895. ret = i40e_get_lump(pf, pf->qp_pile, vsi->alloc_queue_pairs,
  8896. vsi->idx);
  8897. if (ret < 0) {
  8898. dev_info(&pf->pdev->dev,
  8899. "failed to get tracking for %d queues for VSI %d err=%d\n",
  8900. vsi->alloc_queue_pairs, vsi->seid, ret);
  8901. goto err_vsi;
  8902. }
  8903. vsi->base_queue = ret;
  8904. /* get a VSI from the hardware */
  8905. vsi->uplink_seid = uplink_seid;
  8906. ret = i40e_add_vsi(vsi);
  8907. if (ret)
  8908. goto err_vsi;
  8909. switch (vsi->type) {
  8910. /* setup the netdev if needed */
  8911. case I40E_VSI_MAIN:
  8912. /* Apply relevant filters if a platform-specific mac
  8913. * address was selected.
  8914. */
  8915. if (!!(pf->flags & I40E_FLAG_PF_MAC)) {
  8916. ret = i40e_macaddr_init(vsi, pf->hw.mac.addr);
  8917. if (ret) {
  8918. dev_warn(&pf->pdev->dev,
  8919. "could not set up macaddr; err %d\n",
  8920. ret);
  8921. }
  8922. }
  8923. case I40E_VSI_VMDQ2:
  8924. case I40E_VSI_FCOE:
  8925. ret = i40e_config_netdev(vsi);
  8926. if (ret)
  8927. goto err_netdev;
  8928. ret = register_netdev(vsi->netdev);
  8929. if (ret)
  8930. goto err_netdev;
  8931. vsi->netdev_registered = true;
  8932. netif_carrier_off(vsi->netdev);
  8933. #ifdef CONFIG_I40E_DCB
  8934. /* Setup DCB netlink interface */
  8935. i40e_dcbnl_setup(vsi);
  8936. #endif /* CONFIG_I40E_DCB */
  8937. /* fall through */
  8938. case I40E_VSI_FDIR:
  8939. /* set up vectors and rings if needed */
  8940. ret = i40e_vsi_setup_vectors(vsi);
  8941. if (ret)
  8942. goto err_msix;
  8943. ret = i40e_alloc_rings(vsi);
  8944. if (ret)
  8945. goto err_rings;
  8946. /* map all of the rings to the q_vectors */
  8947. i40e_vsi_map_rings_to_vectors(vsi);
  8948. i40e_vsi_reset_stats(vsi);
  8949. break;
  8950. default:
  8951. /* no netdev or rings for the other VSI types */
  8952. break;
  8953. }
  8954. if ((pf->flags & I40E_FLAG_RSS_AQ_CAPABLE) &&
  8955. (vsi->type == I40E_VSI_VMDQ2)) {
  8956. ret = i40e_vsi_config_rss(vsi);
  8957. }
  8958. return vsi;
  8959. err_rings:
  8960. i40e_vsi_free_q_vectors(vsi);
  8961. err_msix:
  8962. if (vsi->netdev_registered) {
  8963. vsi->netdev_registered = false;
  8964. unregister_netdev(vsi->netdev);
  8965. free_netdev(vsi->netdev);
  8966. vsi->netdev = NULL;
  8967. }
  8968. err_netdev:
  8969. i40e_aq_delete_element(&pf->hw, vsi->seid, NULL);
  8970. err_vsi:
  8971. i40e_vsi_clear(vsi);
  8972. err_alloc:
  8973. return NULL;
  8974. }
  8975. /**
  8976. * i40e_veb_get_bw_info - Query VEB BW information
  8977. * @veb: the veb to query
  8978. *
  8979. * Query the Tx scheduler BW configuration data for given VEB
  8980. **/
  8981. static int i40e_veb_get_bw_info(struct i40e_veb *veb)
  8982. {
  8983. struct i40e_aqc_query_switching_comp_ets_config_resp ets_data;
  8984. struct i40e_aqc_query_switching_comp_bw_config_resp bw_data;
  8985. struct i40e_pf *pf = veb->pf;
  8986. struct i40e_hw *hw = &pf->hw;
  8987. u32 tc_bw_max;
  8988. int ret = 0;
  8989. int i;
  8990. ret = i40e_aq_query_switch_comp_bw_config(hw, veb->seid,
  8991. &bw_data, NULL);
  8992. if (ret) {
  8993. dev_info(&pf->pdev->dev,
  8994. "query veb bw config failed, err %s aq_err %s\n",
  8995. i40e_stat_str(&pf->hw, ret),
  8996. i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
  8997. goto out;
  8998. }
  8999. ret = i40e_aq_query_switch_comp_ets_config(hw, veb->seid,
  9000. &ets_data, NULL);
  9001. if (ret) {
  9002. dev_info(&pf->pdev->dev,
  9003. "query veb bw ets config failed, err %s aq_err %s\n",
  9004. i40e_stat_str(&pf->hw, ret),
  9005. i40e_aq_str(&pf->hw, hw->aq.asq_last_status));
  9006. goto out;
  9007. }
  9008. veb->bw_limit = le16_to_cpu(ets_data.port_bw_limit);
  9009. veb->bw_max_quanta = ets_data.tc_bw_max;
  9010. veb->is_abs_credits = bw_data.absolute_credits_enable;
  9011. veb->enabled_tc = ets_data.tc_valid_bits;
  9012. tc_bw_max = le16_to_cpu(bw_data.tc_bw_max[0]) |
  9013. (le16_to_cpu(bw_data.tc_bw_max[1]) << 16);
  9014. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  9015. veb->bw_tc_share_credits[i] = bw_data.tc_bw_share_credits[i];
  9016. veb->bw_tc_limit_credits[i] =
  9017. le16_to_cpu(bw_data.tc_bw_limits[i]);
  9018. veb->bw_tc_max_quanta[i] = ((tc_bw_max >> (i*4)) & 0x7);
  9019. }
  9020. out:
  9021. return ret;
  9022. }
  9023. /**
  9024. * i40e_veb_mem_alloc - Allocates the next available struct veb in the PF
  9025. * @pf: board private structure
  9026. *
  9027. * On error: returns error code (negative)
  9028. * On success: returns vsi index in PF (positive)
  9029. **/
  9030. static int i40e_veb_mem_alloc(struct i40e_pf *pf)
  9031. {
  9032. int ret = -ENOENT;
  9033. struct i40e_veb *veb;
  9034. int i;
  9035. /* Need to protect the allocation of switch elements at the PF level */
  9036. mutex_lock(&pf->switch_mutex);
  9037. /* VEB list may be fragmented if VEB creation/destruction has
  9038. * been happening. We can afford to do a quick scan to look
  9039. * for any free slots in the list.
  9040. *
  9041. * find next empty veb slot, looping back around if necessary
  9042. */
  9043. i = 0;
  9044. while ((i < I40E_MAX_VEB) && (pf->veb[i] != NULL))
  9045. i++;
  9046. if (i >= I40E_MAX_VEB) {
  9047. ret = -ENOMEM;
  9048. goto err_alloc_veb; /* out of VEB slots! */
  9049. }
  9050. veb = kzalloc(sizeof(*veb), GFP_KERNEL);
  9051. if (!veb) {
  9052. ret = -ENOMEM;
  9053. goto err_alloc_veb;
  9054. }
  9055. veb->pf = pf;
  9056. veb->idx = i;
  9057. veb->enabled_tc = 1;
  9058. pf->veb[i] = veb;
  9059. ret = i;
  9060. err_alloc_veb:
  9061. mutex_unlock(&pf->switch_mutex);
  9062. return ret;
  9063. }
  9064. /**
  9065. * i40e_switch_branch_release - Delete a branch of the switch tree
  9066. * @branch: where to start deleting
  9067. *
  9068. * This uses recursion to find the tips of the branch to be
  9069. * removed, deleting until we get back to and can delete this VEB.
  9070. **/
  9071. static void i40e_switch_branch_release(struct i40e_veb *branch)
  9072. {
  9073. struct i40e_pf *pf = branch->pf;
  9074. u16 branch_seid = branch->seid;
  9075. u16 veb_idx = branch->idx;
  9076. int i;
  9077. /* release any VEBs on this VEB - RECURSION */
  9078. for (i = 0; i < I40E_MAX_VEB; i++) {
  9079. if (!pf->veb[i])
  9080. continue;
  9081. if (pf->veb[i]->uplink_seid == branch->seid)
  9082. i40e_switch_branch_release(pf->veb[i]);
  9083. }
  9084. /* Release the VSIs on this VEB, but not the owner VSI.
  9085. *
  9086. * NOTE: Removing the last VSI on a VEB has the SIDE EFFECT of removing
  9087. * the VEB itself, so don't use (*branch) after this loop.
  9088. */
  9089. for (i = 0; i < pf->num_alloc_vsi; i++) {
  9090. if (!pf->vsi[i])
  9091. continue;
  9092. if (pf->vsi[i]->uplink_seid == branch_seid &&
  9093. (pf->vsi[i]->flags & I40E_VSI_FLAG_VEB_OWNER) == 0) {
  9094. i40e_vsi_release(pf->vsi[i]);
  9095. }
  9096. }
  9097. /* There's one corner case where the VEB might not have been
  9098. * removed, so double check it here and remove it if needed.
  9099. * This case happens if the veb was created from the debugfs
  9100. * commands and no VSIs were added to it.
  9101. */
  9102. if (pf->veb[veb_idx])
  9103. i40e_veb_release(pf->veb[veb_idx]);
  9104. }
  9105. /**
  9106. * i40e_veb_clear - remove veb struct
  9107. * @veb: the veb to remove
  9108. **/
  9109. static void i40e_veb_clear(struct i40e_veb *veb)
  9110. {
  9111. if (!veb)
  9112. return;
  9113. if (veb->pf) {
  9114. struct i40e_pf *pf = veb->pf;
  9115. mutex_lock(&pf->switch_mutex);
  9116. if (pf->veb[veb->idx] == veb)
  9117. pf->veb[veb->idx] = NULL;
  9118. mutex_unlock(&pf->switch_mutex);
  9119. }
  9120. kfree(veb);
  9121. }
  9122. /**
  9123. * i40e_veb_release - Delete a VEB and free its resources
  9124. * @veb: the VEB being removed
  9125. **/
  9126. void i40e_veb_release(struct i40e_veb *veb)
  9127. {
  9128. struct i40e_vsi *vsi = NULL;
  9129. struct i40e_pf *pf;
  9130. int i, n = 0;
  9131. pf = veb->pf;
  9132. /* find the remaining VSI and check for extras */
  9133. for (i = 0; i < pf->num_alloc_vsi; i++) {
  9134. if (pf->vsi[i] && pf->vsi[i]->uplink_seid == veb->seid) {
  9135. n++;
  9136. vsi = pf->vsi[i];
  9137. }
  9138. }
  9139. if (n != 1) {
  9140. dev_info(&pf->pdev->dev,
  9141. "can't remove VEB %d with %d VSIs left\n",
  9142. veb->seid, n);
  9143. return;
  9144. }
  9145. /* move the remaining VSI to uplink veb */
  9146. vsi->flags &= ~I40E_VSI_FLAG_VEB_OWNER;
  9147. if (veb->uplink_seid) {
  9148. vsi->uplink_seid = veb->uplink_seid;
  9149. if (veb->uplink_seid == pf->mac_seid)
  9150. vsi->veb_idx = I40E_NO_VEB;
  9151. else
  9152. vsi->veb_idx = veb->veb_idx;
  9153. } else {
  9154. /* floating VEB */
  9155. vsi->uplink_seid = pf->vsi[pf->lan_vsi]->uplink_seid;
  9156. vsi->veb_idx = pf->vsi[pf->lan_vsi]->veb_idx;
  9157. }
  9158. i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
  9159. i40e_veb_clear(veb);
  9160. }
  9161. /**
  9162. * i40e_add_veb - create the VEB in the switch
  9163. * @veb: the VEB to be instantiated
  9164. * @vsi: the controlling VSI
  9165. **/
  9166. static int i40e_add_veb(struct i40e_veb *veb, struct i40e_vsi *vsi)
  9167. {
  9168. struct i40e_pf *pf = veb->pf;
  9169. bool enable_stats = !!(pf->flags & I40E_FLAG_VEB_STATS_ENABLED);
  9170. int ret;
  9171. ret = i40e_aq_add_veb(&pf->hw, veb->uplink_seid, vsi->seid,
  9172. veb->enabled_tc, false,
  9173. &veb->seid, enable_stats, NULL);
  9174. /* get a VEB from the hardware */
  9175. if (ret) {
  9176. dev_info(&pf->pdev->dev,
  9177. "couldn't add VEB, err %s aq_err %s\n",
  9178. i40e_stat_str(&pf->hw, ret),
  9179. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  9180. return -EPERM;
  9181. }
  9182. /* get statistics counter */
  9183. ret = i40e_aq_get_veb_parameters(&pf->hw, veb->seid, NULL, NULL,
  9184. &veb->stats_idx, NULL, NULL, NULL);
  9185. if (ret) {
  9186. dev_info(&pf->pdev->dev,
  9187. "couldn't get VEB statistics idx, err %s aq_err %s\n",
  9188. i40e_stat_str(&pf->hw, ret),
  9189. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  9190. return -EPERM;
  9191. }
  9192. ret = i40e_veb_get_bw_info(veb);
  9193. if (ret) {
  9194. dev_info(&pf->pdev->dev,
  9195. "couldn't get VEB bw info, err %s aq_err %s\n",
  9196. i40e_stat_str(&pf->hw, ret),
  9197. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  9198. i40e_aq_delete_element(&pf->hw, veb->seid, NULL);
  9199. return -ENOENT;
  9200. }
  9201. vsi->uplink_seid = veb->seid;
  9202. vsi->veb_idx = veb->idx;
  9203. vsi->flags |= I40E_VSI_FLAG_VEB_OWNER;
  9204. return 0;
  9205. }
  9206. /**
  9207. * i40e_veb_setup - Set up a VEB
  9208. * @pf: board private structure
  9209. * @flags: VEB setup flags
  9210. * @uplink_seid: the switch element to link to
  9211. * @vsi_seid: the initial VSI seid
  9212. * @enabled_tc: Enabled TC bit-map
  9213. *
  9214. * This allocates the sw VEB structure and links it into the switch
  9215. * It is possible and legal for this to be a duplicate of an already
  9216. * existing VEB. It is also possible for both uplink and vsi seids
  9217. * to be zero, in order to create a floating VEB.
  9218. *
  9219. * Returns pointer to the successfully allocated VEB sw struct on
  9220. * success, otherwise returns NULL on failure.
  9221. **/
  9222. struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags,
  9223. u16 uplink_seid, u16 vsi_seid,
  9224. u8 enabled_tc)
  9225. {
  9226. struct i40e_veb *veb, *uplink_veb = NULL;
  9227. int vsi_idx, veb_idx;
  9228. int ret;
  9229. /* if one seid is 0, the other must be 0 to create a floating relay */
  9230. if ((uplink_seid == 0 || vsi_seid == 0) &&
  9231. (uplink_seid + vsi_seid != 0)) {
  9232. dev_info(&pf->pdev->dev,
  9233. "one, not both seid's are 0: uplink=%d vsi=%d\n",
  9234. uplink_seid, vsi_seid);
  9235. return NULL;
  9236. }
  9237. /* make sure there is such a vsi and uplink */
  9238. for (vsi_idx = 0; vsi_idx < pf->num_alloc_vsi; vsi_idx++)
  9239. if (pf->vsi[vsi_idx] && pf->vsi[vsi_idx]->seid == vsi_seid)
  9240. break;
  9241. if (vsi_idx >= pf->num_alloc_vsi && vsi_seid != 0) {
  9242. dev_info(&pf->pdev->dev, "vsi seid %d not found\n",
  9243. vsi_seid);
  9244. return NULL;
  9245. }
  9246. if (uplink_seid && uplink_seid != pf->mac_seid) {
  9247. for (veb_idx = 0; veb_idx < I40E_MAX_VEB; veb_idx++) {
  9248. if (pf->veb[veb_idx] &&
  9249. pf->veb[veb_idx]->seid == uplink_seid) {
  9250. uplink_veb = pf->veb[veb_idx];
  9251. break;
  9252. }
  9253. }
  9254. if (!uplink_veb) {
  9255. dev_info(&pf->pdev->dev,
  9256. "uplink seid %d not found\n", uplink_seid);
  9257. return NULL;
  9258. }
  9259. }
  9260. /* get veb sw struct */
  9261. veb_idx = i40e_veb_mem_alloc(pf);
  9262. if (veb_idx < 0)
  9263. goto err_alloc;
  9264. veb = pf->veb[veb_idx];
  9265. veb->flags = flags;
  9266. veb->uplink_seid = uplink_seid;
  9267. veb->veb_idx = (uplink_veb ? uplink_veb->idx : I40E_NO_VEB);
  9268. veb->enabled_tc = (enabled_tc ? enabled_tc : 0x1);
  9269. /* create the VEB in the switch */
  9270. ret = i40e_add_veb(veb, pf->vsi[vsi_idx]);
  9271. if (ret)
  9272. goto err_veb;
  9273. if (vsi_idx == pf->lan_vsi)
  9274. pf->lan_veb = veb->idx;
  9275. return veb;
  9276. err_veb:
  9277. i40e_veb_clear(veb);
  9278. err_alloc:
  9279. return NULL;
  9280. }
  9281. /**
  9282. * i40e_setup_pf_switch_element - set PF vars based on switch type
  9283. * @pf: board private structure
  9284. * @ele: element we are building info from
  9285. * @num_reported: total number of elements
  9286. * @printconfig: should we print the contents
  9287. *
  9288. * helper function to assist in extracting a few useful SEID values.
  9289. **/
  9290. static void i40e_setup_pf_switch_element(struct i40e_pf *pf,
  9291. struct i40e_aqc_switch_config_element_resp *ele,
  9292. u16 num_reported, bool printconfig)
  9293. {
  9294. u16 downlink_seid = le16_to_cpu(ele->downlink_seid);
  9295. u16 uplink_seid = le16_to_cpu(ele->uplink_seid);
  9296. u8 element_type = ele->element_type;
  9297. u16 seid = le16_to_cpu(ele->seid);
  9298. if (printconfig)
  9299. dev_info(&pf->pdev->dev,
  9300. "type=%d seid=%d uplink=%d downlink=%d\n",
  9301. element_type, seid, uplink_seid, downlink_seid);
  9302. switch (element_type) {
  9303. case I40E_SWITCH_ELEMENT_TYPE_MAC:
  9304. pf->mac_seid = seid;
  9305. break;
  9306. case I40E_SWITCH_ELEMENT_TYPE_VEB:
  9307. /* Main VEB? */
  9308. if (uplink_seid != pf->mac_seid)
  9309. break;
  9310. if (pf->lan_veb == I40E_NO_VEB) {
  9311. int v;
  9312. /* find existing or else empty VEB */
  9313. for (v = 0; v < I40E_MAX_VEB; v++) {
  9314. if (pf->veb[v] && (pf->veb[v]->seid == seid)) {
  9315. pf->lan_veb = v;
  9316. break;
  9317. }
  9318. }
  9319. if (pf->lan_veb == I40E_NO_VEB) {
  9320. v = i40e_veb_mem_alloc(pf);
  9321. if (v < 0)
  9322. break;
  9323. pf->lan_veb = v;
  9324. }
  9325. }
  9326. pf->veb[pf->lan_veb]->seid = seid;
  9327. pf->veb[pf->lan_veb]->uplink_seid = pf->mac_seid;
  9328. pf->veb[pf->lan_veb]->pf = pf;
  9329. pf->veb[pf->lan_veb]->veb_idx = I40E_NO_VEB;
  9330. break;
  9331. case I40E_SWITCH_ELEMENT_TYPE_VSI:
  9332. if (num_reported != 1)
  9333. break;
  9334. /* This is immediately after a reset so we can assume this is
  9335. * the PF's VSI
  9336. */
  9337. pf->mac_seid = uplink_seid;
  9338. pf->pf_seid = downlink_seid;
  9339. pf->main_vsi_seid = seid;
  9340. if (printconfig)
  9341. dev_info(&pf->pdev->dev,
  9342. "pf_seid=%d main_vsi_seid=%d\n",
  9343. pf->pf_seid, pf->main_vsi_seid);
  9344. break;
  9345. case I40E_SWITCH_ELEMENT_TYPE_PF:
  9346. case I40E_SWITCH_ELEMENT_TYPE_VF:
  9347. case I40E_SWITCH_ELEMENT_TYPE_EMP:
  9348. case I40E_SWITCH_ELEMENT_TYPE_BMC:
  9349. case I40E_SWITCH_ELEMENT_TYPE_PE:
  9350. case I40E_SWITCH_ELEMENT_TYPE_PA:
  9351. /* ignore these for now */
  9352. break;
  9353. default:
  9354. dev_info(&pf->pdev->dev, "unknown element type=%d seid=%d\n",
  9355. element_type, seid);
  9356. break;
  9357. }
  9358. }
  9359. /**
  9360. * i40e_fetch_switch_configuration - Get switch config from firmware
  9361. * @pf: board private structure
  9362. * @printconfig: should we print the contents
  9363. *
  9364. * Get the current switch configuration from the device and
  9365. * extract a few useful SEID values.
  9366. **/
  9367. int i40e_fetch_switch_configuration(struct i40e_pf *pf, bool printconfig)
  9368. {
  9369. struct i40e_aqc_get_switch_config_resp *sw_config;
  9370. u16 next_seid = 0;
  9371. int ret = 0;
  9372. u8 *aq_buf;
  9373. int i;
  9374. aq_buf = kzalloc(I40E_AQ_LARGE_BUF, GFP_KERNEL);
  9375. if (!aq_buf)
  9376. return -ENOMEM;
  9377. sw_config = (struct i40e_aqc_get_switch_config_resp *)aq_buf;
  9378. do {
  9379. u16 num_reported, num_total;
  9380. ret = i40e_aq_get_switch_config(&pf->hw, sw_config,
  9381. I40E_AQ_LARGE_BUF,
  9382. &next_seid, NULL);
  9383. if (ret) {
  9384. dev_info(&pf->pdev->dev,
  9385. "get switch config failed err %s aq_err %s\n",
  9386. i40e_stat_str(&pf->hw, ret),
  9387. i40e_aq_str(&pf->hw,
  9388. pf->hw.aq.asq_last_status));
  9389. kfree(aq_buf);
  9390. return -ENOENT;
  9391. }
  9392. num_reported = le16_to_cpu(sw_config->header.num_reported);
  9393. num_total = le16_to_cpu(sw_config->header.num_total);
  9394. if (printconfig)
  9395. dev_info(&pf->pdev->dev,
  9396. "header: %d reported %d total\n",
  9397. num_reported, num_total);
  9398. for (i = 0; i < num_reported; i++) {
  9399. struct i40e_aqc_switch_config_element_resp *ele =
  9400. &sw_config->element[i];
  9401. i40e_setup_pf_switch_element(pf, ele, num_reported,
  9402. printconfig);
  9403. }
  9404. } while (next_seid != 0);
  9405. kfree(aq_buf);
  9406. return ret;
  9407. }
  9408. /**
  9409. * i40e_setup_pf_switch - Setup the HW switch on startup or after reset
  9410. * @pf: board private structure
  9411. * @reinit: if the Main VSI needs to re-initialized.
  9412. *
  9413. * Returns 0 on success, negative value on failure
  9414. **/
  9415. static int i40e_setup_pf_switch(struct i40e_pf *pf, bool reinit)
  9416. {
  9417. u16 flags = 0;
  9418. int ret;
  9419. /* find out what's out there already */
  9420. ret = i40e_fetch_switch_configuration(pf, false);
  9421. if (ret) {
  9422. dev_info(&pf->pdev->dev,
  9423. "couldn't fetch switch config, err %s aq_err %s\n",
  9424. i40e_stat_str(&pf->hw, ret),
  9425. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  9426. return ret;
  9427. }
  9428. i40e_pf_reset_stats(pf);
  9429. /* set the switch config bit for the whole device to
  9430. * support limited promisc or true promisc
  9431. * when user requests promisc. The default is limited
  9432. * promisc.
  9433. */
  9434. if ((pf->hw.pf_id == 0) &&
  9435. !(pf->flags & I40E_FLAG_TRUE_PROMISC_SUPPORT))
  9436. flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  9437. if (pf->hw.pf_id == 0) {
  9438. u16 valid_flags;
  9439. valid_flags = I40E_AQ_SET_SWITCH_CFG_PROMISC;
  9440. ret = i40e_aq_set_switch_config(&pf->hw, flags, valid_flags,
  9441. NULL);
  9442. if (ret && pf->hw.aq.asq_last_status != I40E_AQ_RC_ESRCH) {
  9443. dev_info(&pf->pdev->dev,
  9444. "couldn't set switch config bits, err %s aq_err %s\n",
  9445. i40e_stat_str(&pf->hw, ret),
  9446. i40e_aq_str(&pf->hw,
  9447. pf->hw.aq.asq_last_status));
  9448. /* not a fatal problem, just keep going */
  9449. }
  9450. }
  9451. /* first time setup */
  9452. if (pf->lan_vsi == I40E_NO_VSI || reinit) {
  9453. struct i40e_vsi *vsi = NULL;
  9454. u16 uplink_seid;
  9455. /* Set up the PF VSI associated with the PF's main VSI
  9456. * that is already in the HW switch
  9457. */
  9458. if (pf->lan_veb != I40E_NO_VEB && pf->veb[pf->lan_veb])
  9459. uplink_seid = pf->veb[pf->lan_veb]->seid;
  9460. else
  9461. uplink_seid = pf->mac_seid;
  9462. if (pf->lan_vsi == I40E_NO_VSI)
  9463. vsi = i40e_vsi_setup(pf, I40E_VSI_MAIN, uplink_seid, 0);
  9464. else if (reinit)
  9465. vsi = i40e_vsi_reinit_setup(pf->vsi[pf->lan_vsi]);
  9466. if (!vsi) {
  9467. dev_info(&pf->pdev->dev, "setup of MAIN VSI failed\n");
  9468. i40e_fdir_teardown(pf);
  9469. return -EAGAIN;
  9470. }
  9471. } else {
  9472. /* force a reset of TC and queue layout configurations */
  9473. u8 enabled_tc = pf->vsi[pf->lan_vsi]->tc_config.enabled_tc;
  9474. pf->vsi[pf->lan_vsi]->tc_config.enabled_tc = 0;
  9475. pf->vsi[pf->lan_vsi]->seid = pf->main_vsi_seid;
  9476. i40e_vsi_config_tc(pf->vsi[pf->lan_vsi], enabled_tc);
  9477. }
  9478. i40e_vlan_stripping_disable(pf->vsi[pf->lan_vsi]);
  9479. i40e_fdir_sb_setup(pf);
  9480. /* Setup static PF queue filter control settings */
  9481. ret = i40e_setup_pf_filter_control(pf);
  9482. if (ret) {
  9483. dev_info(&pf->pdev->dev, "setup_pf_filter_control failed: %d\n",
  9484. ret);
  9485. /* Failure here should not stop continuing other steps */
  9486. }
  9487. /* enable RSS in the HW, even for only one queue, as the stack can use
  9488. * the hash
  9489. */
  9490. if ((pf->flags & I40E_FLAG_RSS_ENABLED))
  9491. i40e_pf_config_rss(pf);
  9492. /* fill in link information and enable LSE reporting */
  9493. i40e_link_event(pf);
  9494. /* Initialize user-specific link properties */
  9495. pf->fc_autoneg_status = ((pf->hw.phy.link_info.an_info &
  9496. I40E_AQ_AN_COMPLETED) ? true : false);
  9497. i40e_ptp_init(pf);
  9498. return ret;
  9499. }
  9500. /**
  9501. * i40e_determine_queue_usage - Work out queue distribution
  9502. * @pf: board private structure
  9503. **/
  9504. static void i40e_determine_queue_usage(struct i40e_pf *pf)
  9505. {
  9506. int queues_left;
  9507. pf->num_lan_qps = 0;
  9508. #ifdef I40E_FCOE
  9509. pf->num_fcoe_qps = 0;
  9510. #endif
  9511. /* Find the max queues to be put into basic use. We'll always be
  9512. * using TC0, whether or not DCB is running, and TC0 will get the
  9513. * big RSS set.
  9514. */
  9515. queues_left = pf->hw.func_caps.num_tx_qp;
  9516. if ((queues_left == 1) ||
  9517. !(pf->flags & I40E_FLAG_MSIX_ENABLED)) {
  9518. /* one qp for PF, no queues for anything else */
  9519. queues_left = 0;
  9520. pf->alloc_rss_size = pf->num_lan_qps = 1;
  9521. /* make sure all the fancies are disabled */
  9522. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  9523. I40E_FLAG_IWARP_ENABLED |
  9524. #ifdef I40E_FCOE
  9525. I40E_FLAG_FCOE_ENABLED |
  9526. #endif
  9527. I40E_FLAG_FD_SB_ENABLED |
  9528. I40E_FLAG_FD_ATR_ENABLED |
  9529. I40E_FLAG_DCB_CAPABLE |
  9530. I40E_FLAG_DCB_ENABLED |
  9531. I40E_FLAG_SRIOV_ENABLED |
  9532. I40E_FLAG_VMDQ_ENABLED);
  9533. } else if (!(pf->flags & (I40E_FLAG_RSS_ENABLED |
  9534. I40E_FLAG_FD_SB_ENABLED |
  9535. I40E_FLAG_FD_ATR_ENABLED |
  9536. I40E_FLAG_DCB_CAPABLE))) {
  9537. /* one qp for PF */
  9538. pf->alloc_rss_size = pf->num_lan_qps = 1;
  9539. queues_left -= pf->num_lan_qps;
  9540. pf->flags &= ~(I40E_FLAG_RSS_ENABLED |
  9541. I40E_FLAG_IWARP_ENABLED |
  9542. #ifdef I40E_FCOE
  9543. I40E_FLAG_FCOE_ENABLED |
  9544. #endif
  9545. I40E_FLAG_FD_SB_ENABLED |
  9546. I40E_FLAG_FD_ATR_ENABLED |
  9547. I40E_FLAG_DCB_ENABLED |
  9548. I40E_FLAG_VMDQ_ENABLED);
  9549. } else {
  9550. /* Not enough queues for all TCs */
  9551. if ((pf->flags & I40E_FLAG_DCB_CAPABLE) &&
  9552. (queues_left < I40E_MAX_TRAFFIC_CLASS)) {
  9553. pf->flags &= ~(I40E_FLAG_DCB_CAPABLE |
  9554. I40E_FLAG_DCB_ENABLED);
  9555. dev_info(&pf->pdev->dev, "not enough queues for DCB. DCB is disabled.\n");
  9556. }
  9557. pf->num_lan_qps = max_t(int, pf->rss_size_max,
  9558. num_online_cpus());
  9559. pf->num_lan_qps = min_t(int, pf->num_lan_qps,
  9560. pf->hw.func_caps.num_tx_qp);
  9561. queues_left -= pf->num_lan_qps;
  9562. }
  9563. #ifdef I40E_FCOE
  9564. if (pf->flags & I40E_FLAG_FCOE_ENABLED) {
  9565. if (I40E_DEFAULT_FCOE <= queues_left) {
  9566. pf->num_fcoe_qps = I40E_DEFAULT_FCOE;
  9567. } else if (I40E_MINIMUM_FCOE <= queues_left) {
  9568. pf->num_fcoe_qps = I40E_MINIMUM_FCOE;
  9569. } else {
  9570. pf->num_fcoe_qps = 0;
  9571. pf->flags &= ~I40E_FLAG_FCOE_ENABLED;
  9572. dev_info(&pf->pdev->dev, "not enough queues for FCoE. FCoE feature will be disabled\n");
  9573. }
  9574. queues_left -= pf->num_fcoe_qps;
  9575. }
  9576. #endif
  9577. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  9578. if (queues_left > 1) {
  9579. queues_left -= 1; /* save 1 queue for FD */
  9580. } else {
  9581. pf->flags &= ~I40E_FLAG_FD_SB_ENABLED;
  9582. dev_info(&pf->pdev->dev, "not enough queues for Flow Director. Flow Director feature is disabled\n");
  9583. }
  9584. }
  9585. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  9586. pf->num_vf_qps && pf->num_req_vfs && queues_left) {
  9587. pf->num_req_vfs = min_t(int, pf->num_req_vfs,
  9588. (queues_left / pf->num_vf_qps));
  9589. queues_left -= (pf->num_req_vfs * pf->num_vf_qps);
  9590. }
  9591. if ((pf->flags & I40E_FLAG_VMDQ_ENABLED) &&
  9592. pf->num_vmdq_vsis && pf->num_vmdq_qps && queues_left) {
  9593. pf->num_vmdq_vsis = min_t(int, pf->num_vmdq_vsis,
  9594. (queues_left / pf->num_vmdq_qps));
  9595. queues_left -= (pf->num_vmdq_vsis * pf->num_vmdq_qps);
  9596. }
  9597. pf->queues_left = queues_left;
  9598. dev_dbg(&pf->pdev->dev,
  9599. "qs_avail=%d FD SB=%d lan_qs=%d lan_tc0=%d vf=%d*%d vmdq=%d*%d, remaining=%d\n",
  9600. pf->hw.func_caps.num_tx_qp,
  9601. !!(pf->flags & I40E_FLAG_FD_SB_ENABLED),
  9602. pf->num_lan_qps, pf->alloc_rss_size, pf->num_req_vfs,
  9603. pf->num_vf_qps, pf->num_vmdq_vsis, pf->num_vmdq_qps,
  9604. queues_left);
  9605. #ifdef I40E_FCOE
  9606. dev_dbg(&pf->pdev->dev, "fcoe queues = %d\n", pf->num_fcoe_qps);
  9607. #endif
  9608. }
  9609. /**
  9610. * i40e_setup_pf_filter_control - Setup PF static filter control
  9611. * @pf: PF to be setup
  9612. *
  9613. * i40e_setup_pf_filter_control sets up a PF's initial filter control
  9614. * settings. If PE/FCoE are enabled then it will also set the per PF
  9615. * based filter sizes required for them. It also enables Flow director,
  9616. * ethertype and macvlan type filter settings for the pf.
  9617. *
  9618. * Returns 0 on success, negative on failure
  9619. **/
  9620. static int i40e_setup_pf_filter_control(struct i40e_pf *pf)
  9621. {
  9622. struct i40e_filter_control_settings *settings = &pf->filter_settings;
  9623. settings->hash_lut_size = I40E_HASH_LUT_SIZE_128;
  9624. /* Flow Director is enabled */
  9625. if (pf->flags & (I40E_FLAG_FD_SB_ENABLED | I40E_FLAG_FD_ATR_ENABLED))
  9626. settings->enable_fdir = true;
  9627. /* Ethtype and MACVLAN filters enabled for PF */
  9628. settings->enable_ethtype = true;
  9629. settings->enable_macvlan = true;
  9630. if (i40e_set_filter_control(&pf->hw, settings))
  9631. return -ENOENT;
  9632. return 0;
  9633. }
  9634. #define INFO_STRING_LEN 255
  9635. #define REMAIN(__x) (INFO_STRING_LEN - (__x))
  9636. static void i40e_print_features(struct i40e_pf *pf)
  9637. {
  9638. struct i40e_hw *hw = &pf->hw;
  9639. char *buf;
  9640. int i;
  9641. buf = kmalloc(INFO_STRING_LEN, GFP_KERNEL);
  9642. if (!buf)
  9643. return;
  9644. i = snprintf(buf, INFO_STRING_LEN, "Features: PF-id[%d]", hw->pf_id);
  9645. #ifdef CONFIG_PCI_IOV
  9646. i += snprintf(&buf[i], REMAIN(i), " VFs: %d", pf->num_req_vfs);
  9647. #endif
  9648. i += snprintf(&buf[i], REMAIN(i), " VSIs: %d QP: %d",
  9649. pf->hw.func_caps.num_vsis,
  9650. pf->vsi[pf->lan_vsi]->num_queue_pairs);
  9651. if (pf->flags & I40E_FLAG_RSS_ENABLED)
  9652. i += snprintf(&buf[i], REMAIN(i), " RSS");
  9653. if (pf->flags & I40E_FLAG_FD_ATR_ENABLED)
  9654. i += snprintf(&buf[i], REMAIN(i), " FD_ATR");
  9655. if (pf->flags & I40E_FLAG_FD_SB_ENABLED) {
  9656. i += snprintf(&buf[i], REMAIN(i), " FD_SB");
  9657. i += snprintf(&buf[i], REMAIN(i), " NTUPLE");
  9658. }
  9659. if (pf->flags & I40E_FLAG_DCB_CAPABLE)
  9660. i += snprintf(&buf[i], REMAIN(i), " DCB");
  9661. i += snprintf(&buf[i], REMAIN(i), " VxLAN");
  9662. i += snprintf(&buf[i], REMAIN(i), " Geneve");
  9663. if (pf->flags & I40E_FLAG_PTP)
  9664. i += snprintf(&buf[i], REMAIN(i), " PTP");
  9665. #ifdef I40E_FCOE
  9666. if (pf->flags & I40E_FLAG_FCOE_ENABLED)
  9667. i += snprintf(&buf[i], REMAIN(i), " FCOE");
  9668. #endif
  9669. if (pf->flags & I40E_FLAG_VEB_MODE_ENABLED)
  9670. i += snprintf(&buf[i], REMAIN(i), " VEB");
  9671. else
  9672. i += snprintf(&buf[i], REMAIN(i), " VEPA");
  9673. dev_info(&pf->pdev->dev, "%s\n", buf);
  9674. kfree(buf);
  9675. WARN_ON(i > INFO_STRING_LEN);
  9676. }
  9677. /**
  9678. * i40e_get_platform_mac_addr - get platform-specific MAC address
  9679. *
  9680. * @pdev: PCI device information struct
  9681. * @pf: board private structure
  9682. *
  9683. * Look up the MAC address in Open Firmware on systems that support it,
  9684. * and use IDPROM on SPARC if no OF address is found. On return, the
  9685. * I40E_FLAG_PF_MAC will be wset in pf->flags if a platform-specific value
  9686. * has been selected.
  9687. **/
  9688. static void i40e_get_platform_mac_addr(struct pci_dev *pdev, struct i40e_pf *pf)
  9689. {
  9690. pf->flags &= ~I40E_FLAG_PF_MAC;
  9691. if (!eth_platform_get_mac_address(&pdev->dev, pf->hw.mac.addr))
  9692. pf->flags |= I40E_FLAG_PF_MAC;
  9693. }
  9694. /**
  9695. * i40e_probe - Device initialization routine
  9696. * @pdev: PCI device information struct
  9697. * @ent: entry in i40e_pci_tbl
  9698. *
  9699. * i40e_probe initializes a PF identified by a pci_dev structure.
  9700. * The OS initialization, configuring of the PF private structure,
  9701. * and a hardware reset occur.
  9702. *
  9703. * Returns 0 on success, negative on failure
  9704. **/
  9705. static int i40e_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  9706. {
  9707. struct i40e_aq_get_phy_abilities_resp abilities;
  9708. struct i40e_pf *pf;
  9709. struct i40e_hw *hw;
  9710. static u16 pfs_found;
  9711. u16 wol_nvm_bits;
  9712. u16 link_status;
  9713. int err;
  9714. u32 val;
  9715. u32 i;
  9716. u8 set_fc_aq_fail;
  9717. err = pci_enable_device_mem(pdev);
  9718. if (err)
  9719. return err;
  9720. /* set up for high or low dma */
  9721. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  9722. if (err) {
  9723. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  9724. if (err) {
  9725. dev_err(&pdev->dev,
  9726. "DMA configuration failed: 0x%x\n", err);
  9727. goto err_dma;
  9728. }
  9729. }
  9730. /* set up pci connections */
  9731. err = pci_request_mem_regions(pdev, i40e_driver_name);
  9732. if (err) {
  9733. dev_info(&pdev->dev,
  9734. "pci_request_selected_regions failed %d\n", err);
  9735. goto err_pci_reg;
  9736. }
  9737. pci_enable_pcie_error_reporting(pdev);
  9738. pci_set_master(pdev);
  9739. /* Now that we have a PCI connection, we need to do the
  9740. * low level device setup. This is primarily setting up
  9741. * the Admin Queue structures and then querying for the
  9742. * device's current profile information.
  9743. */
  9744. pf = kzalloc(sizeof(*pf), GFP_KERNEL);
  9745. if (!pf) {
  9746. err = -ENOMEM;
  9747. goto err_pf_alloc;
  9748. }
  9749. pf->next_vsi = 0;
  9750. pf->pdev = pdev;
  9751. set_bit(__I40E_DOWN, &pf->state);
  9752. hw = &pf->hw;
  9753. hw->back = pf;
  9754. pf->ioremap_len = min_t(int, pci_resource_len(pdev, 0),
  9755. I40E_MAX_CSR_SPACE);
  9756. hw->hw_addr = ioremap(pci_resource_start(pdev, 0), pf->ioremap_len);
  9757. if (!hw->hw_addr) {
  9758. err = -EIO;
  9759. dev_info(&pdev->dev, "ioremap(0x%04x, 0x%04x) failed: 0x%x\n",
  9760. (unsigned int)pci_resource_start(pdev, 0),
  9761. pf->ioremap_len, err);
  9762. goto err_ioremap;
  9763. }
  9764. hw->vendor_id = pdev->vendor;
  9765. hw->device_id = pdev->device;
  9766. pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id);
  9767. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  9768. hw->subsystem_device_id = pdev->subsystem_device;
  9769. hw->bus.device = PCI_SLOT(pdev->devfn);
  9770. hw->bus.func = PCI_FUNC(pdev->devfn);
  9771. hw->bus.bus_id = pdev->bus->number;
  9772. pf->instance = pfs_found;
  9773. /* set up the locks for the AQ, do this only once in probe
  9774. * and destroy them only once in remove
  9775. */
  9776. mutex_init(&hw->aq.asq_mutex);
  9777. mutex_init(&hw->aq.arq_mutex);
  9778. pf->msg_enable = netif_msg_init(debug,
  9779. NETIF_MSG_DRV |
  9780. NETIF_MSG_PROBE |
  9781. NETIF_MSG_LINK);
  9782. if (debug < -1)
  9783. pf->hw.debug_mask = debug;
  9784. /* do a special CORER for clearing PXE mode once at init */
  9785. if (hw->revision_id == 0 &&
  9786. (rd32(hw, I40E_GLLAN_RCTL_0) & I40E_GLLAN_RCTL_0_PXE_MODE_MASK)) {
  9787. wr32(hw, I40E_GLGEN_RTRIG, I40E_GLGEN_RTRIG_CORER_MASK);
  9788. i40e_flush(hw);
  9789. msleep(200);
  9790. pf->corer_count++;
  9791. i40e_clear_pxe_mode(hw);
  9792. }
  9793. /* Reset here to make sure all is clean and to define PF 'n' */
  9794. i40e_clear_hw(hw);
  9795. err = i40e_pf_reset(hw);
  9796. if (err) {
  9797. dev_info(&pdev->dev, "Initial pf_reset failed: %d\n", err);
  9798. goto err_pf_reset;
  9799. }
  9800. pf->pfr_count++;
  9801. hw->aq.num_arq_entries = I40E_AQ_LEN;
  9802. hw->aq.num_asq_entries = I40E_AQ_LEN;
  9803. hw->aq.arq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  9804. hw->aq.asq_buf_size = I40E_MAX_AQ_BUF_SIZE;
  9805. pf->adminq_work_limit = I40E_AQ_WORK_LIMIT;
  9806. snprintf(pf->int_name, sizeof(pf->int_name) - 1,
  9807. "%s-%s:misc",
  9808. dev_driver_string(&pf->pdev->dev), dev_name(&pdev->dev));
  9809. err = i40e_init_shared_code(hw);
  9810. if (err) {
  9811. dev_warn(&pdev->dev, "unidentified MAC or BLANK NVM: %d\n",
  9812. err);
  9813. goto err_pf_reset;
  9814. }
  9815. /* set up a default setting for link flow control */
  9816. pf->hw.fc.requested_mode = I40E_FC_NONE;
  9817. err = i40e_init_adminq(hw);
  9818. if (err) {
  9819. if (err == I40E_ERR_FIRMWARE_API_VERSION)
  9820. dev_info(&pdev->dev,
  9821. "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");
  9822. else
  9823. dev_info(&pdev->dev,
  9824. "The driver for the device stopped because the device firmware failed to init. Try updating your NVM image.\n");
  9825. goto err_pf_reset;
  9826. }
  9827. /* provide nvm, fw, api versions */
  9828. dev_info(&pdev->dev, "fw %d.%d.%05d api %d.%d nvm %s\n",
  9829. hw->aq.fw_maj_ver, hw->aq.fw_min_ver, hw->aq.fw_build,
  9830. hw->aq.api_maj_ver, hw->aq.api_min_ver,
  9831. i40e_nvm_version_str(hw));
  9832. if (hw->aq.api_maj_ver == I40E_FW_API_VERSION_MAJOR &&
  9833. hw->aq.api_min_ver > I40E_FW_API_VERSION_MINOR)
  9834. dev_info(&pdev->dev,
  9835. "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");
  9836. else if (hw->aq.api_maj_ver < I40E_FW_API_VERSION_MAJOR ||
  9837. hw->aq.api_min_ver < (I40E_FW_API_VERSION_MINOR - 1))
  9838. dev_info(&pdev->dev,
  9839. "The driver for the device detected an older version of the NVM image than expected. Please update the NVM image.\n");
  9840. i40e_verify_eeprom(pf);
  9841. /* Rev 0 hardware was never productized */
  9842. if (hw->revision_id < 1)
  9843. 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");
  9844. i40e_clear_pxe_mode(hw);
  9845. err = i40e_get_capabilities(pf);
  9846. if (err)
  9847. goto err_adminq_setup;
  9848. err = i40e_sw_init(pf);
  9849. if (err) {
  9850. dev_info(&pdev->dev, "sw_init failed: %d\n", err);
  9851. goto err_sw_init;
  9852. }
  9853. err = i40e_init_lan_hmc(hw, hw->func_caps.num_tx_qp,
  9854. hw->func_caps.num_rx_qp,
  9855. pf->fcoe_hmc_cntx_num, pf->fcoe_hmc_filt_num);
  9856. if (err) {
  9857. dev_info(&pdev->dev, "init_lan_hmc failed: %d\n", err);
  9858. goto err_init_lan_hmc;
  9859. }
  9860. err = i40e_configure_lan_hmc(hw, I40E_HMC_MODEL_DIRECT_ONLY);
  9861. if (err) {
  9862. dev_info(&pdev->dev, "configure_lan_hmc failed: %d\n", err);
  9863. err = -ENOENT;
  9864. goto err_configure_lan_hmc;
  9865. }
  9866. /* Disable LLDP for NICs that have firmware versions lower than v4.3.
  9867. * Ignore error return codes because if it was already disabled via
  9868. * hardware settings this will fail
  9869. */
  9870. if (pf->flags & I40E_FLAG_STOP_FW_LLDP) {
  9871. dev_info(&pdev->dev, "Stopping firmware LLDP agent.\n");
  9872. i40e_aq_stop_lldp(hw, true, NULL);
  9873. }
  9874. i40e_get_mac_addr(hw, hw->mac.addr);
  9875. /* allow a platform config to override the HW addr */
  9876. i40e_get_platform_mac_addr(pdev, pf);
  9877. if (!is_valid_ether_addr(hw->mac.addr)) {
  9878. dev_info(&pdev->dev, "invalid MAC address %pM\n", hw->mac.addr);
  9879. err = -EIO;
  9880. goto err_mac_addr;
  9881. }
  9882. dev_info(&pdev->dev, "MAC address: %pM\n", hw->mac.addr);
  9883. ether_addr_copy(hw->mac.perm_addr, hw->mac.addr);
  9884. i40e_get_port_mac_addr(hw, hw->mac.port_addr);
  9885. if (is_valid_ether_addr(hw->mac.port_addr))
  9886. pf->flags |= I40E_FLAG_PORT_ID_VALID;
  9887. #ifdef I40E_FCOE
  9888. err = i40e_get_san_mac_addr(hw, hw->mac.san_addr);
  9889. if (err)
  9890. dev_info(&pdev->dev,
  9891. "(non-fatal) SAN MAC retrieval failed: %d\n", err);
  9892. if (!is_valid_ether_addr(hw->mac.san_addr)) {
  9893. dev_warn(&pdev->dev, "invalid SAN MAC address %pM, falling back to LAN MAC\n",
  9894. hw->mac.san_addr);
  9895. ether_addr_copy(hw->mac.san_addr, hw->mac.addr);
  9896. }
  9897. dev_info(&pf->pdev->dev, "SAN MAC: %pM\n", hw->mac.san_addr);
  9898. #endif /* I40E_FCOE */
  9899. pci_set_drvdata(pdev, pf);
  9900. pci_save_state(pdev);
  9901. #ifdef CONFIG_I40E_DCB
  9902. err = i40e_init_pf_dcb(pf);
  9903. if (err) {
  9904. dev_info(&pdev->dev, "DCB init failed %d, disabled\n", err);
  9905. pf->flags &= ~(I40E_FLAG_DCB_CAPABLE | I40E_FLAG_DCB_ENABLED);
  9906. /* Continue without DCB enabled */
  9907. }
  9908. #endif /* CONFIG_I40E_DCB */
  9909. /* set up periodic task facility */
  9910. setup_timer(&pf->service_timer, i40e_service_timer, (unsigned long)pf);
  9911. pf->service_timer_period = HZ;
  9912. INIT_WORK(&pf->service_task, i40e_service_task);
  9913. clear_bit(__I40E_SERVICE_SCHED, &pf->state);
  9914. pf->flags |= I40E_FLAG_NEED_LINK_UPDATE;
  9915. /* NVM bit on means WoL disabled for the port */
  9916. i40e_read_nvm_word(hw, I40E_SR_NVM_WAKE_ON_LAN, &wol_nvm_bits);
  9917. if (BIT (hw->port) & wol_nvm_bits || hw->partition_id != 1)
  9918. pf->wol_en = false;
  9919. else
  9920. pf->wol_en = true;
  9921. device_set_wakeup_enable(&pf->pdev->dev, pf->wol_en);
  9922. /* set up the main switch operations */
  9923. i40e_determine_queue_usage(pf);
  9924. err = i40e_init_interrupt_scheme(pf);
  9925. if (err)
  9926. goto err_switch_setup;
  9927. /* The number of VSIs reported by the FW is the minimum guaranteed
  9928. * to us; HW supports far more and we share the remaining pool with
  9929. * the other PFs. We allocate space for more than the guarantee with
  9930. * the understanding that we might not get them all later.
  9931. */
  9932. if (pf->hw.func_caps.num_vsis < I40E_MIN_VSI_ALLOC)
  9933. pf->num_alloc_vsi = I40E_MIN_VSI_ALLOC;
  9934. else
  9935. pf->num_alloc_vsi = pf->hw.func_caps.num_vsis;
  9936. /* Set up the *vsi struct and our local tracking of the MAIN PF vsi. */
  9937. pf->vsi = kcalloc(pf->num_alloc_vsi, sizeof(struct i40e_vsi *),
  9938. GFP_KERNEL);
  9939. if (!pf->vsi) {
  9940. err = -ENOMEM;
  9941. goto err_switch_setup;
  9942. }
  9943. #ifdef CONFIG_PCI_IOV
  9944. /* prep for VF support */
  9945. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  9946. (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  9947. !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
  9948. if (pci_num_vf(pdev))
  9949. pf->flags |= I40E_FLAG_VEB_MODE_ENABLED;
  9950. }
  9951. #endif
  9952. err = i40e_setup_pf_switch(pf, false);
  9953. if (err) {
  9954. dev_info(&pdev->dev, "setup_pf_switch failed: %d\n", err);
  9955. goto err_vsis;
  9956. }
  9957. /* Make sure flow control is set according to current settings */
  9958. err = i40e_set_fc(hw, &set_fc_aq_fail, true);
  9959. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_GET)
  9960. dev_dbg(&pf->pdev->dev,
  9961. "Set fc with err %s aq_err %s on get_phy_cap\n",
  9962. i40e_stat_str(hw, err),
  9963. i40e_aq_str(hw, hw->aq.asq_last_status));
  9964. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_SET)
  9965. dev_dbg(&pf->pdev->dev,
  9966. "Set fc with err %s aq_err %s on set_phy_config\n",
  9967. i40e_stat_str(hw, err),
  9968. i40e_aq_str(hw, hw->aq.asq_last_status));
  9969. if (set_fc_aq_fail & I40E_SET_FC_AQ_FAIL_UPDATE)
  9970. dev_dbg(&pf->pdev->dev,
  9971. "Set fc with err %s aq_err %s on get_link_info\n",
  9972. i40e_stat_str(hw, err),
  9973. i40e_aq_str(hw, hw->aq.asq_last_status));
  9974. /* if FDIR VSI was set up, start it now */
  9975. for (i = 0; i < pf->num_alloc_vsi; i++) {
  9976. if (pf->vsi[i] && pf->vsi[i]->type == I40E_VSI_FDIR) {
  9977. i40e_vsi_open(pf->vsi[i]);
  9978. break;
  9979. }
  9980. }
  9981. /* The driver only wants link up/down and module qualification
  9982. * reports from firmware. Note the negative logic.
  9983. */
  9984. err = i40e_aq_set_phy_int_mask(&pf->hw,
  9985. ~(I40E_AQ_EVENT_LINK_UPDOWN |
  9986. I40E_AQ_EVENT_MEDIA_NA |
  9987. I40E_AQ_EVENT_MODULE_QUAL_FAIL), NULL);
  9988. if (err)
  9989. dev_info(&pf->pdev->dev, "set phy mask fail, err %s aq_err %s\n",
  9990. i40e_stat_str(&pf->hw, err),
  9991. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  9992. /* Reconfigure hardware for allowing smaller MSS in the case
  9993. * of TSO, so that we avoid the MDD being fired and causing
  9994. * a reset in the case of small MSS+TSO.
  9995. */
  9996. val = rd32(hw, I40E_REG_MSS);
  9997. if ((val & I40E_REG_MSS_MIN_MASK) > I40E_64BYTE_MSS) {
  9998. val &= ~I40E_REG_MSS_MIN_MASK;
  9999. val |= I40E_64BYTE_MSS;
  10000. wr32(hw, I40E_REG_MSS, val);
  10001. }
  10002. if (pf->flags & I40E_FLAG_RESTART_AUTONEG) {
  10003. msleep(75);
  10004. err = i40e_aq_set_link_restart_an(&pf->hw, true, NULL);
  10005. if (err)
  10006. dev_info(&pf->pdev->dev, "link restart failed, err %s aq_err %s\n",
  10007. i40e_stat_str(&pf->hw, err),
  10008. i40e_aq_str(&pf->hw,
  10009. pf->hw.aq.asq_last_status));
  10010. }
  10011. /* The main driver is (mostly) up and happy. We need to set this state
  10012. * before setting up the misc vector or we get a race and the vector
  10013. * ends up disabled forever.
  10014. */
  10015. clear_bit(__I40E_DOWN, &pf->state);
  10016. /* In case of MSIX we are going to setup the misc vector right here
  10017. * to handle admin queue events etc. In case of legacy and MSI
  10018. * the misc functionality and queue processing is combined in
  10019. * the same vector and that gets setup at open.
  10020. */
  10021. if (pf->flags & I40E_FLAG_MSIX_ENABLED) {
  10022. err = i40e_setup_misc_vector(pf);
  10023. if (err) {
  10024. dev_info(&pdev->dev,
  10025. "setup of misc vector failed: %d\n", err);
  10026. goto err_vsis;
  10027. }
  10028. }
  10029. #ifdef CONFIG_PCI_IOV
  10030. /* prep for VF support */
  10031. if ((pf->flags & I40E_FLAG_SRIOV_ENABLED) &&
  10032. (pf->flags & I40E_FLAG_MSIX_ENABLED) &&
  10033. !test_bit(__I40E_BAD_EEPROM, &pf->state)) {
  10034. /* disable link interrupts for VFs */
  10035. val = rd32(hw, I40E_PFGEN_PORTMDIO_NUM);
  10036. val &= ~I40E_PFGEN_PORTMDIO_NUM_VFLINK_STAT_ENA_MASK;
  10037. wr32(hw, I40E_PFGEN_PORTMDIO_NUM, val);
  10038. i40e_flush(hw);
  10039. if (pci_num_vf(pdev)) {
  10040. dev_info(&pdev->dev,
  10041. "Active VFs found, allocating resources.\n");
  10042. err = i40e_alloc_vfs(pf, pci_num_vf(pdev));
  10043. if (err)
  10044. dev_info(&pdev->dev,
  10045. "Error %d allocating resources for existing VFs\n",
  10046. err);
  10047. }
  10048. }
  10049. #endif /* CONFIG_PCI_IOV */
  10050. if (pf->flags & I40E_FLAG_IWARP_ENABLED) {
  10051. pf->iwarp_base_vector = i40e_get_lump(pf, pf->irq_pile,
  10052. pf->num_iwarp_msix,
  10053. I40E_IWARP_IRQ_PILE_ID);
  10054. if (pf->iwarp_base_vector < 0) {
  10055. dev_info(&pdev->dev,
  10056. "failed to get tracking for %d vectors for IWARP err=%d\n",
  10057. pf->num_iwarp_msix, pf->iwarp_base_vector);
  10058. pf->flags &= ~I40E_FLAG_IWARP_ENABLED;
  10059. }
  10060. }
  10061. i40e_dbg_pf_init(pf);
  10062. /* tell the firmware that we're starting */
  10063. i40e_send_version(pf);
  10064. /* since everything's happy, start the service_task timer */
  10065. mod_timer(&pf->service_timer,
  10066. round_jiffies(jiffies + pf->service_timer_period));
  10067. /* add this PF to client device list and launch a client service task */
  10068. err = i40e_lan_add_device(pf);
  10069. if (err)
  10070. dev_info(&pdev->dev, "Failed to add PF to client API service list: %d\n",
  10071. err);
  10072. #ifdef I40E_FCOE
  10073. /* create FCoE interface */
  10074. i40e_fcoe_vsi_setup(pf);
  10075. #endif
  10076. #define PCI_SPEED_SIZE 8
  10077. #define PCI_WIDTH_SIZE 8
  10078. /* Devices on the IOSF bus do not have this information
  10079. * and will report PCI Gen 1 x 1 by default so don't bother
  10080. * checking them.
  10081. */
  10082. if (!(pf->flags & I40E_FLAG_NO_PCI_LINK_CHECK)) {
  10083. char speed[PCI_SPEED_SIZE] = "Unknown";
  10084. char width[PCI_WIDTH_SIZE] = "Unknown";
  10085. /* Get the negotiated link width and speed from PCI config
  10086. * space
  10087. */
  10088. pcie_capability_read_word(pf->pdev, PCI_EXP_LNKSTA,
  10089. &link_status);
  10090. i40e_set_pci_config_data(hw, link_status);
  10091. switch (hw->bus.speed) {
  10092. case i40e_bus_speed_8000:
  10093. strncpy(speed, "8.0", PCI_SPEED_SIZE); break;
  10094. case i40e_bus_speed_5000:
  10095. strncpy(speed, "5.0", PCI_SPEED_SIZE); break;
  10096. case i40e_bus_speed_2500:
  10097. strncpy(speed, "2.5", PCI_SPEED_SIZE); break;
  10098. default:
  10099. break;
  10100. }
  10101. switch (hw->bus.width) {
  10102. case i40e_bus_width_pcie_x8:
  10103. strncpy(width, "8", PCI_WIDTH_SIZE); break;
  10104. case i40e_bus_width_pcie_x4:
  10105. strncpy(width, "4", PCI_WIDTH_SIZE); break;
  10106. case i40e_bus_width_pcie_x2:
  10107. strncpy(width, "2", PCI_WIDTH_SIZE); break;
  10108. case i40e_bus_width_pcie_x1:
  10109. strncpy(width, "1", PCI_WIDTH_SIZE); break;
  10110. default:
  10111. break;
  10112. }
  10113. dev_info(&pdev->dev, "PCI-Express: Speed %sGT/s Width x%s\n",
  10114. speed, width);
  10115. if (hw->bus.width < i40e_bus_width_pcie_x8 ||
  10116. hw->bus.speed < i40e_bus_speed_8000) {
  10117. dev_warn(&pdev->dev, "PCI-Express bandwidth available for this device may be insufficient for optimal performance.\n");
  10118. dev_warn(&pdev->dev, "Please move the device to a different PCI-e link with more lanes and/or higher transfer rate.\n");
  10119. }
  10120. }
  10121. /* get the requested speeds from the fw */
  10122. err = i40e_aq_get_phy_capabilities(hw, false, false, &abilities, NULL);
  10123. if (err)
  10124. dev_dbg(&pf->pdev->dev, "get requested speeds ret = %s last_status = %s\n",
  10125. i40e_stat_str(&pf->hw, err),
  10126. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  10127. pf->hw.phy.link_info.requested_speeds = abilities.link_speed;
  10128. /* get the supported phy types from the fw */
  10129. err = i40e_aq_get_phy_capabilities(hw, false, true, &abilities, NULL);
  10130. if (err)
  10131. dev_dbg(&pf->pdev->dev, "get supported phy types ret = %s last_status = %s\n",
  10132. i40e_stat_str(&pf->hw, err),
  10133. i40e_aq_str(&pf->hw, pf->hw.aq.asq_last_status));
  10134. /* Add a filter to drop all Flow control frames from any VSI from being
  10135. * transmitted. By doing so we stop a malicious VF from sending out
  10136. * PAUSE or PFC frames and potentially controlling traffic for other
  10137. * PF/VF VSIs.
  10138. * The FW can still send Flow control frames if enabled.
  10139. */
  10140. i40e_add_filter_to_drop_tx_flow_control_frames(&pf->hw,
  10141. pf->main_vsi_seid);
  10142. if ((pf->hw.device_id == I40E_DEV_ID_10G_BASE_T) ||
  10143. (pf->hw.device_id == I40E_DEV_ID_10G_BASE_T4))
  10144. pf->flags |= I40E_FLAG_PHY_CONTROLS_LEDS;
  10145. if (pf->hw.device_id == I40E_DEV_ID_SFP_I_X722)
  10146. pf->flags |= I40E_FLAG_HAVE_CRT_RETIMER;
  10147. /* print a string summarizing features */
  10148. i40e_print_features(pf);
  10149. return 0;
  10150. /* Unwind what we've done if something failed in the setup */
  10151. err_vsis:
  10152. set_bit(__I40E_DOWN, &pf->state);
  10153. i40e_clear_interrupt_scheme(pf);
  10154. kfree(pf->vsi);
  10155. err_switch_setup:
  10156. i40e_reset_interrupt_capability(pf);
  10157. del_timer_sync(&pf->service_timer);
  10158. err_mac_addr:
  10159. err_configure_lan_hmc:
  10160. (void)i40e_shutdown_lan_hmc(hw);
  10161. err_init_lan_hmc:
  10162. kfree(pf->qp_pile);
  10163. err_sw_init:
  10164. err_adminq_setup:
  10165. err_pf_reset:
  10166. iounmap(hw->hw_addr);
  10167. err_ioremap:
  10168. kfree(pf);
  10169. err_pf_alloc:
  10170. pci_disable_pcie_error_reporting(pdev);
  10171. pci_release_mem_regions(pdev);
  10172. err_pci_reg:
  10173. err_dma:
  10174. pci_disable_device(pdev);
  10175. return err;
  10176. }
  10177. /**
  10178. * i40e_remove - Device removal routine
  10179. * @pdev: PCI device information struct
  10180. *
  10181. * i40e_remove is called by the PCI subsystem to alert the driver
  10182. * that is should release a PCI device. This could be caused by a
  10183. * Hot-Plug event, or because the driver is going to be removed from
  10184. * memory.
  10185. **/
  10186. static void i40e_remove(struct pci_dev *pdev)
  10187. {
  10188. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10189. struct i40e_hw *hw = &pf->hw;
  10190. i40e_status ret_code;
  10191. int i;
  10192. i40e_dbg_pf_exit(pf);
  10193. i40e_ptp_stop(pf);
  10194. /* Disable RSS in hw */
  10195. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(0), 0);
  10196. i40e_write_rx_ctl(hw, I40E_PFQF_HENA(1), 0);
  10197. /* no more scheduling of any task */
  10198. set_bit(__I40E_SUSPENDED, &pf->state);
  10199. set_bit(__I40E_DOWN, &pf->state);
  10200. if (pf->service_timer.data)
  10201. del_timer_sync(&pf->service_timer);
  10202. if (pf->service_task.func)
  10203. cancel_work_sync(&pf->service_task);
  10204. if (pf->flags & I40E_FLAG_SRIOV_ENABLED) {
  10205. i40e_free_vfs(pf);
  10206. pf->flags &= ~I40E_FLAG_SRIOV_ENABLED;
  10207. }
  10208. i40e_fdir_teardown(pf);
  10209. /* If there is a switch structure or any orphans, remove them.
  10210. * This will leave only the PF's VSI remaining.
  10211. */
  10212. for (i = 0; i < I40E_MAX_VEB; i++) {
  10213. if (!pf->veb[i])
  10214. continue;
  10215. if (pf->veb[i]->uplink_seid == pf->mac_seid ||
  10216. pf->veb[i]->uplink_seid == 0)
  10217. i40e_switch_branch_release(pf->veb[i]);
  10218. }
  10219. /* Now we can shutdown the PF's VSI, just before we kill
  10220. * adminq and hmc.
  10221. */
  10222. if (pf->vsi[pf->lan_vsi])
  10223. i40e_vsi_release(pf->vsi[pf->lan_vsi]);
  10224. /* remove attached clients */
  10225. ret_code = i40e_lan_del_device(pf);
  10226. if (ret_code) {
  10227. dev_warn(&pdev->dev, "Failed to delete client device: %d\n",
  10228. ret_code);
  10229. }
  10230. /* shutdown and destroy the HMC */
  10231. if (hw->hmc.hmc_obj) {
  10232. ret_code = i40e_shutdown_lan_hmc(hw);
  10233. if (ret_code)
  10234. dev_warn(&pdev->dev,
  10235. "Failed to destroy the HMC resources: %d\n",
  10236. ret_code);
  10237. }
  10238. /* shutdown the adminq */
  10239. i40e_shutdown_adminq(hw);
  10240. /* destroy the locks only once, here */
  10241. mutex_destroy(&hw->aq.arq_mutex);
  10242. mutex_destroy(&hw->aq.asq_mutex);
  10243. /* Clear all dynamic memory lists of rings, q_vectors, and VSIs */
  10244. i40e_clear_interrupt_scheme(pf);
  10245. for (i = 0; i < pf->num_alloc_vsi; i++) {
  10246. if (pf->vsi[i]) {
  10247. i40e_vsi_clear_rings(pf->vsi[i]);
  10248. i40e_vsi_clear(pf->vsi[i]);
  10249. pf->vsi[i] = NULL;
  10250. }
  10251. }
  10252. for (i = 0; i < I40E_MAX_VEB; i++) {
  10253. kfree(pf->veb[i]);
  10254. pf->veb[i] = NULL;
  10255. }
  10256. kfree(pf->qp_pile);
  10257. kfree(pf->vsi);
  10258. iounmap(hw->hw_addr);
  10259. kfree(pf);
  10260. pci_release_mem_regions(pdev);
  10261. pci_disable_pcie_error_reporting(pdev);
  10262. pci_disable_device(pdev);
  10263. }
  10264. /**
  10265. * i40e_pci_error_detected - warning that something funky happened in PCI land
  10266. * @pdev: PCI device information struct
  10267. *
  10268. * Called to warn that something happened and the error handling steps
  10269. * are in progress. Allows the driver to quiesce things, be ready for
  10270. * remediation.
  10271. **/
  10272. static pci_ers_result_t i40e_pci_error_detected(struct pci_dev *pdev,
  10273. enum pci_channel_state error)
  10274. {
  10275. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10276. dev_info(&pdev->dev, "%s: error %d\n", __func__, error);
  10277. if (!pf) {
  10278. dev_info(&pdev->dev,
  10279. "Cannot recover - error happened during device probe\n");
  10280. return PCI_ERS_RESULT_DISCONNECT;
  10281. }
  10282. /* shutdown all operations */
  10283. if (!test_bit(__I40E_SUSPENDED, &pf->state)) {
  10284. rtnl_lock();
  10285. i40e_prep_for_reset(pf);
  10286. rtnl_unlock();
  10287. }
  10288. /* Request a slot reset */
  10289. return PCI_ERS_RESULT_NEED_RESET;
  10290. }
  10291. /**
  10292. * i40e_pci_error_slot_reset - a PCI slot reset just happened
  10293. * @pdev: PCI device information struct
  10294. *
  10295. * Called to find if the driver can work with the device now that
  10296. * the pci slot has been reset. If a basic connection seems good
  10297. * (registers are readable and have sane content) then return a
  10298. * happy little PCI_ERS_RESULT_xxx.
  10299. **/
  10300. static pci_ers_result_t i40e_pci_error_slot_reset(struct pci_dev *pdev)
  10301. {
  10302. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10303. pci_ers_result_t result;
  10304. int err;
  10305. u32 reg;
  10306. dev_dbg(&pdev->dev, "%s\n", __func__);
  10307. if (pci_enable_device_mem(pdev)) {
  10308. dev_info(&pdev->dev,
  10309. "Cannot re-enable PCI device after reset.\n");
  10310. result = PCI_ERS_RESULT_DISCONNECT;
  10311. } else {
  10312. pci_set_master(pdev);
  10313. pci_restore_state(pdev);
  10314. pci_save_state(pdev);
  10315. pci_wake_from_d3(pdev, false);
  10316. reg = rd32(&pf->hw, I40E_GLGEN_RTRIG);
  10317. if (reg == 0)
  10318. result = PCI_ERS_RESULT_RECOVERED;
  10319. else
  10320. result = PCI_ERS_RESULT_DISCONNECT;
  10321. }
  10322. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  10323. if (err) {
  10324. dev_info(&pdev->dev,
  10325. "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n",
  10326. err);
  10327. /* non-fatal, continue */
  10328. }
  10329. return result;
  10330. }
  10331. /**
  10332. * i40e_pci_error_resume - restart operations after PCI error recovery
  10333. * @pdev: PCI device information struct
  10334. *
  10335. * Called to allow the driver to bring things back up after PCI error
  10336. * and/or reset recovery has finished.
  10337. **/
  10338. static void i40e_pci_error_resume(struct pci_dev *pdev)
  10339. {
  10340. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10341. dev_dbg(&pdev->dev, "%s\n", __func__);
  10342. if (test_bit(__I40E_SUSPENDED, &pf->state))
  10343. return;
  10344. rtnl_lock();
  10345. i40e_handle_reset_warning(pf);
  10346. rtnl_unlock();
  10347. }
  10348. /**
  10349. * i40e_enable_mc_magic_wake - enable multicast magic packet wake up
  10350. * using the mac_address_write admin q function
  10351. * @pf: pointer to i40e_pf struct
  10352. **/
  10353. static void i40e_enable_mc_magic_wake(struct i40e_pf *pf)
  10354. {
  10355. struct i40e_hw *hw = &pf->hw;
  10356. i40e_status ret;
  10357. u8 mac_addr[6];
  10358. u16 flags = 0;
  10359. /* Get current MAC address in case it's an LAA */
  10360. if (pf->vsi[pf->lan_vsi] && pf->vsi[pf->lan_vsi]->netdev) {
  10361. ether_addr_copy(mac_addr,
  10362. pf->vsi[pf->lan_vsi]->netdev->dev_addr);
  10363. } else {
  10364. dev_err(&pf->pdev->dev,
  10365. "Failed to retrieve MAC address; using default\n");
  10366. ether_addr_copy(mac_addr, hw->mac.addr);
  10367. }
  10368. /* The FW expects the mac address write cmd to first be called with
  10369. * one of these flags before calling it again with the multicast
  10370. * enable flags.
  10371. */
  10372. flags = I40E_AQC_WRITE_TYPE_LAA_WOL;
  10373. if (hw->func_caps.flex10_enable && hw->partition_id != 1)
  10374. flags = I40E_AQC_WRITE_TYPE_LAA_ONLY;
  10375. ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL);
  10376. if (ret) {
  10377. dev_err(&pf->pdev->dev,
  10378. "Failed to update MAC address registers; cannot enable Multicast Magic packet wake up");
  10379. return;
  10380. }
  10381. flags = I40E_AQC_MC_MAG_EN
  10382. | I40E_AQC_WOL_PRESERVE_ON_PFR
  10383. | I40E_AQC_WRITE_TYPE_UPDATE_MC_MAG;
  10384. ret = i40e_aq_mac_address_write(hw, flags, mac_addr, NULL);
  10385. if (ret)
  10386. dev_err(&pf->pdev->dev,
  10387. "Failed to enable Multicast Magic Packet wake up\n");
  10388. }
  10389. /**
  10390. * i40e_shutdown - PCI callback for shutting down
  10391. * @pdev: PCI device information struct
  10392. **/
  10393. static void i40e_shutdown(struct pci_dev *pdev)
  10394. {
  10395. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10396. struct i40e_hw *hw = &pf->hw;
  10397. set_bit(__I40E_SUSPENDED, &pf->state);
  10398. set_bit(__I40E_DOWN, &pf->state);
  10399. rtnl_lock();
  10400. i40e_prep_for_reset(pf);
  10401. rtnl_unlock();
  10402. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  10403. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  10404. del_timer_sync(&pf->service_timer);
  10405. cancel_work_sync(&pf->service_task);
  10406. i40e_fdir_teardown(pf);
  10407. if (pf->wol_en && (pf->flags & I40E_FLAG_WOL_MC_MAGIC_PKT_WAKE))
  10408. i40e_enable_mc_magic_wake(pf);
  10409. rtnl_lock();
  10410. i40e_prep_for_reset(pf);
  10411. rtnl_unlock();
  10412. wr32(hw, I40E_PFPM_APM,
  10413. (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  10414. wr32(hw, I40E_PFPM_WUFC,
  10415. (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  10416. i40e_clear_interrupt_scheme(pf);
  10417. if (system_state == SYSTEM_POWER_OFF) {
  10418. pci_wake_from_d3(pdev, pf->wol_en);
  10419. pci_set_power_state(pdev, PCI_D3hot);
  10420. }
  10421. }
  10422. #ifdef CONFIG_PM
  10423. /**
  10424. * i40e_suspend - PCI callback for moving to D3
  10425. * @pdev: PCI device information struct
  10426. **/
  10427. static int i40e_suspend(struct pci_dev *pdev, pm_message_t state)
  10428. {
  10429. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10430. struct i40e_hw *hw = &pf->hw;
  10431. int retval = 0;
  10432. set_bit(__I40E_SUSPENDED, &pf->state);
  10433. set_bit(__I40E_DOWN, &pf->state);
  10434. if (pf->wol_en && (pf->flags & I40E_FLAG_WOL_MC_MAGIC_PKT_WAKE))
  10435. i40e_enable_mc_magic_wake(pf);
  10436. rtnl_lock();
  10437. i40e_prep_for_reset(pf);
  10438. rtnl_unlock();
  10439. wr32(hw, I40E_PFPM_APM, (pf->wol_en ? I40E_PFPM_APM_APME_MASK : 0));
  10440. wr32(hw, I40E_PFPM_WUFC, (pf->wol_en ? I40E_PFPM_WUFC_MAG_MASK : 0));
  10441. i40e_stop_misc_vector(pf);
  10442. retval = pci_save_state(pdev);
  10443. if (retval)
  10444. return retval;
  10445. pci_wake_from_d3(pdev, pf->wol_en);
  10446. pci_set_power_state(pdev, PCI_D3hot);
  10447. return retval;
  10448. }
  10449. /**
  10450. * i40e_resume - PCI callback for waking up from D3
  10451. * @pdev: PCI device information struct
  10452. **/
  10453. static int i40e_resume(struct pci_dev *pdev)
  10454. {
  10455. struct i40e_pf *pf = pci_get_drvdata(pdev);
  10456. u32 err;
  10457. pci_set_power_state(pdev, PCI_D0);
  10458. pci_restore_state(pdev);
  10459. /* pci_restore_state() clears dev->state_saves, so
  10460. * call pci_save_state() again to restore it.
  10461. */
  10462. pci_save_state(pdev);
  10463. err = pci_enable_device_mem(pdev);
  10464. if (err) {
  10465. dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n");
  10466. return err;
  10467. }
  10468. pci_set_master(pdev);
  10469. /* no wakeup events while running */
  10470. pci_wake_from_d3(pdev, false);
  10471. /* handling the reset will rebuild the device state */
  10472. if (test_and_clear_bit(__I40E_SUSPENDED, &pf->state)) {
  10473. clear_bit(__I40E_DOWN, &pf->state);
  10474. rtnl_lock();
  10475. i40e_reset_and_rebuild(pf, false);
  10476. rtnl_unlock();
  10477. }
  10478. return 0;
  10479. }
  10480. #endif
  10481. static const struct pci_error_handlers i40e_err_handler = {
  10482. .error_detected = i40e_pci_error_detected,
  10483. .slot_reset = i40e_pci_error_slot_reset,
  10484. .resume = i40e_pci_error_resume,
  10485. };
  10486. static struct pci_driver i40e_driver = {
  10487. .name = i40e_driver_name,
  10488. .id_table = i40e_pci_tbl,
  10489. .probe = i40e_probe,
  10490. .remove = i40e_remove,
  10491. #ifdef CONFIG_PM
  10492. .suspend = i40e_suspend,
  10493. .resume = i40e_resume,
  10494. #endif
  10495. .shutdown = i40e_shutdown,
  10496. .err_handler = &i40e_err_handler,
  10497. .sriov_configure = i40e_pci_sriov_configure,
  10498. };
  10499. /**
  10500. * i40e_init_module - Driver registration routine
  10501. *
  10502. * i40e_init_module is the first routine called when the driver is
  10503. * loaded. All it does is register with the PCI subsystem.
  10504. **/
  10505. static int __init i40e_init_module(void)
  10506. {
  10507. pr_info("%s: %s - version %s\n", i40e_driver_name,
  10508. i40e_driver_string, i40e_driver_version_str);
  10509. pr_info("%s: %s\n", i40e_driver_name, i40e_copyright);
  10510. /* we will see if single thread per module is enough for now,
  10511. * it can't be any worse than using the system workqueue which
  10512. * was already single threaded
  10513. */
  10514. i40e_wq = alloc_workqueue("%s", WQ_UNBOUND | WQ_MEM_RECLAIM, 1,
  10515. i40e_driver_name);
  10516. if (!i40e_wq) {
  10517. pr_err("%s: Failed to create workqueue\n", i40e_driver_name);
  10518. return -ENOMEM;
  10519. }
  10520. i40e_dbg_init();
  10521. return pci_register_driver(&i40e_driver);
  10522. }
  10523. module_init(i40e_init_module);
  10524. /**
  10525. * i40e_exit_module - Driver exit cleanup routine
  10526. *
  10527. * i40e_exit_module is called just before the driver is removed
  10528. * from memory.
  10529. **/
  10530. static void __exit i40e_exit_module(void)
  10531. {
  10532. pci_unregister_driver(&i40e_driver);
  10533. destroy_workqueue(i40e_wq);
  10534. i40e_dbg_exit();
  10535. }
  10536. module_exit(i40e_exit_module);