ixgbe_main.c 300 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright(c) 1999 - 2018 Intel Corporation. */
  3. #include <linux/types.h>
  4. #include <linux/module.h>
  5. #include <linux/pci.h>
  6. #include <linux/netdevice.h>
  7. #include <linux/vmalloc.h>
  8. #include <linux/string.h>
  9. #include <linux/in.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/ip.h>
  12. #include <linux/tcp.h>
  13. #include <linux/sctp.h>
  14. #include <linux/pkt_sched.h>
  15. #include <linux/ipv6.h>
  16. #include <linux/slab.h>
  17. #include <net/checksum.h>
  18. #include <net/ip6_checksum.h>
  19. #include <linux/etherdevice.h>
  20. #include <linux/ethtool.h>
  21. #include <linux/if.h>
  22. #include <linux/if_vlan.h>
  23. #include <linux/if_macvlan.h>
  24. #include <linux/if_bridge.h>
  25. #include <linux/prefetch.h>
  26. #include <linux/bpf.h>
  27. #include <linux/bpf_trace.h>
  28. #include <linux/atomic.h>
  29. #include <scsi/fc/fc_fcoe.h>
  30. #include <net/udp_tunnel.h>
  31. #include <net/pkt_cls.h>
  32. #include <net/tc_act/tc_gact.h>
  33. #include <net/tc_act/tc_mirred.h>
  34. #include <net/vxlan.h>
  35. #include <net/mpls.h>
  36. #include "ixgbe.h"
  37. #include "ixgbe_common.h"
  38. #include "ixgbe_dcb_82599.h"
  39. #include "ixgbe_sriov.h"
  40. #include "ixgbe_model.h"
  41. char ixgbe_driver_name[] = "ixgbe";
  42. static const char ixgbe_driver_string[] =
  43. "Intel(R) 10 Gigabit PCI Express Network Driver";
  44. #ifdef IXGBE_FCOE
  45. char ixgbe_default_device_descr[] =
  46. "Intel(R) 10 Gigabit Network Connection";
  47. #else
  48. static char ixgbe_default_device_descr[] =
  49. "Intel(R) 10 Gigabit Network Connection";
  50. #endif
  51. #define DRV_VERSION "5.1.0-k"
  52. const char ixgbe_driver_version[] = DRV_VERSION;
  53. static const char ixgbe_copyright[] =
  54. "Copyright (c) 1999-2016 Intel Corporation.";
  55. static const char ixgbe_overheat_msg[] = "Network adapter has been stopped because it has over heated. Restart the computer. If the problem persists, power off the system and replace the adapter";
  56. static const struct ixgbe_info *ixgbe_info_tbl[] = {
  57. [board_82598] = &ixgbe_82598_info,
  58. [board_82599] = &ixgbe_82599_info,
  59. [board_X540] = &ixgbe_X540_info,
  60. [board_X550] = &ixgbe_X550_info,
  61. [board_X550EM_x] = &ixgbe_X550EM_x_info,
  62. [board_x550em_x_fw] = &ixgbe_x550em_x_fw_info,
  63. [board_x550em_a] = &ixgbe_x550em_a_info,
  64. [board_x550em_a_fw] = &ixgbe_x550em_a_fw_info,
  65. };
  66. /* ixgbe_pci_tbl - PCI Device ID Table
  67. *
  68. * Wildcard entries (PCI_ANY_ID) should come last
  69. * Last entry must be all 0s
  70. *
  71. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  72. * Class, Class Mask, private data (not used) }
  73. */
  74. static const struct pci_device_id ixgbe_pci_tbl[] = {
  75. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
  76. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
  77. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
  78. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
  79. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
  80. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
  81. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
  82. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
  83. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
  84. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
  85. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
  86. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
  87. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
  88. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
  89. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
  90. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
  91. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
  92. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
  93. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
  94. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
  95. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
  96. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
  97. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
  98. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
  99. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
  100. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
  101. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_QSFP_SF_QP), board_82599 },
  102. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
  103. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
  104. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
  105. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T), board_X550},
  106. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550T1), board_X550},
  107. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KX4), board_X550EM_x},
  108. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_XFI), board_X550EM_x},
  109. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_KR), board_X550EM_x},
  110. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_10G_T), board_X550EM_x},
  111. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_SFP), board_X550EM_x},
  112. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_1G_T), board_x550em_x_fw},
  113. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR), board_x550em_a },
  114. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_KR_L), board_x550em_a },
  115. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP_N), board_x550em_a },
  116. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII), board_x550em_a },
  117. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SGMII_L), board_x550em_a },
  118. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_10G_T), board_x550em_a},
  119. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_SFP), board_x550em_a },
  120. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T), board_x550em_a_fw },
  121. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_1G_T_L), board_x550em_a_fw },
  122. /* required last entry */
  123. {0, }
  124. };
  125. MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
  126. #ifdef CONFIG_IXGBE_DCA
  127. static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
  128. void *p);
  129. static struct notifier_block dca_notifier = {
  130. .notifier_call = ixgbe_notify_dca,
  131. .next = NULL,
  132. .priority = 0
  133. };
  134. #endif
  135. #ifdef CONFIG_PCI_IOV
  136. static unsigned int max_vfs;
  137. module_param(max_vfs, uint, 0);
  138. MODULE_PARM_DESC(max_vfs,
  139. "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63. (Deprecated)");
  140. #endif /* CONFIG_PCI_IOV */
  141. static unsigned int allow_unsupported_sfp;
  142. module_param(allow_unsupported_sfp, uint, 0);
  143. MODULE_PARM_DESC(allow_unsupported_sfp,
  144. "Allow unsupported and untested SFP+ modules on 82599-based adapters");
  145. #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
  146. static int debug = -1;
  147. module_param(debug, int, 0);
  148. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  149. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  150. MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
  151. MODULE_LICENSE("GPL");
  152. MODULE_VERSION(DRV_VERSION);
  153. static struct workqueue_struct *ixgbe_wq;
  154. static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev);
  155. static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *);
  156. static const struct net_device_ops ixgbe_netdev_ops;
  157. static bool netif_is_ixgbe(struct net_device *dev)
  158. {
  159. return dev && (dev->netdev_ops == &ixgbe_netdev_ops);
  160. }
  161. static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter,
  162. u32 reg, u16 *value)
  163. {
  164. struct pci_dev *parent_dev;
  165. struct pci_bus *parent_bus;
  166. parent_bus = adapter->pdev->bus->parent;
  167. if (!parent_bus)
  168. return -1;
  169. parent_dev = parent_bus->self;
  170. if (!parent_dev)
  171. return -1;
  172. if (!pci_is_pcie(parent_dev))
  173. return -1;
  174. pcie_capability_read_word(parent_dev, reg, value);
  175. if (*value == IXGBE_FAILED_READ_CFG_WORD &&
  176. ixgbe_check_cfg_remove(&adapter->hw, parent_dev))
  177. return -1;
  178. return 0;
  179. }
  180. static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter)
  181. {
  182. struct ixgbe_hw *hw = &adapter->hw;
  183. u16 link_status = 0;
  184. int err;
  185. hw->bus.type = ixgbe_bus_type_pci_express;
  186. /* Get the negotiated link width and speed from PCI config space of the
  187. * parent, as this device is behind a switch
  188. */
  189. err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status);
  190. /* assume caller will handle error case */
  191. if (err)
  192. return err;
  193. hw->bus.width = ixgbe_convert_bus_width(link_status);
  194. hw->bus.speed = ixgbe_convert_bus_speed(link_status);
  195. return 0;
  196. }
  197. /**
  198. * ixgbe_check_from_parent - Determine whether PCIe info should come from parent
  199. * @hw: hw specific details
  200. *
  201. * This function is used by probe to determine whether a device's PCI-Express
  202. * bandwidth details should be gathered from the parent bus instead of from the
  203. * device. Used to ensure that various locations all have the correct device ID
  204. * checks.
  205. */
  206. static inline bool ixgbe_pcie_from_parent(struct ixgbe_hw *hw)
  207. {
  208. switch (hw->device_id) {
  209. case IXGBE_DEV_ID_82599_SFP_SF_QP:
  210. case IXGBE_DEV_ID_82599_QSFP_SF_QP:
  211. return true;
  212. default:
  213. return false;
  214. }
  215. }
  216. static void ixgbe_check_minimum_link(struct ixgbe_adapter *adapter,
  217. int expected_gts)
  218. {
  219. struct ixgbe_hw *hw = &adapter->hw;
  220. struct pci_dev *pdev;
  221. /* Some devices are not connected over PCIe and thus do not negotiate
  222. * speed. These devices do not have valid bus info, and thus any report
  223. * we generate may not be correct.
  224. */
  225. if (hw->bus.type == ixgbe_bus_type_internal)
  226. return;
  227. /* determine whether to use the parent device */
  228. if (ixgbe_pcie_from_parent(&adapter->hw))
  229. pdev = adapter->pdev->bus->parent->self;
  230. else
  231. pdev = adapter->pdev;
  232. pcie_print_link_status(pdev);
  233. }
  234. static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
  235. {
  236. if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
  237. !test_bit(__IXGBE_REMOVING, &adapter->state) &&
  238. !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
  239. queue_work(ixgbe_wq, &adapter->service_task);
  240. }
  241. static void ixgbe_remove_adapter(struct ixgbe_hw *hw)
  242. {
  243. struct ixgbe_adapter *adapter = hw->back;
  244. if (!hw->hw_addr)
  245. return;
  246. hw->hw_addr = NULL;
  247. e_dev_err("Adapter removed\n");
  248. if (test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
  249. ixgbe_service_event_schedule(adapter);
  250. }
  251. static u32 ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg)
  252. {
  253. u8 __iomem *reg_addr;
  254. u32 value;
  255. int i;
  256. reg_addr = READ_ONCE(hw->hw_addr);
  257. if (ixgbe_removed(reg_addr))
  258. return IXGBE_FAILED_READ_REG;
  259. /* Register read of 0xFFFFFFF can indicate the adapter has been removed,
  260. * so perform several status register reads to determine if the adapter
  261. * has been removed.
  262. */
  263. for (i = 0; i < IXGBE_FAILED_READ_RETRIES; i++) {
  264. value = readl(reg_addr + IXGBE_STATUS);
  265. if (value != IXGBE_FAILED_READ_REG)
  266. break;
  267. mdelay(3);
  268. }
  269. if (value == IXGBE_FAILED_READ_REG)
  270. ixgbe_remove_adapter(hw);
  271. else
  272. value = readl(reg_addr + reg);
  273. return value;
  274. }
  275. /**
  276. * ixgbe_read_reg - Read from device register
  277. * @hw: hw specific details
  278. * @reg: offset of register to read
  279. *
  280. * Returns : value read or IXGBE_FAILED_READ_REG if removed
  281. *
  282. * This function is used to read device registers. It checks for device
  283. * removal by confirming any read that returns all ones by checking the
  284. * status register value for all ones. This function avoids reading from
  285. * the hardware if a removal was previously detected in which case it
  286. * returns IXGBE_FAILED_READ_REG (all ones).
  287. */
  288. u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg)
  289. {
  290. u8 __iomem *reg_addr = READ_ONCE(hw->hw_addr);
  291. u32 value;
  292. if (ixgbe_removed(reg_addr))
  293. return IXGBE_FAILED_READ_REG;
  294. if (unlikely(hw->phy.nw_mng_if_sel &
  295. IXGBE_NW_MNG_IF_SEL_SGMII_ENABLE)) {
  296. struct ixgbe_adapter *adapter;
  297. int i;
  298. for (i = 0; i < 200; ++i) {
  299. value = readl(reg_addr + IXGBE_MAC_SGMII_BUSY);
  300. if (likely(!value))
  301. goto writes_completed;
  302. if (value == IXGBE_FAILED_READ_REG) {
  303. ixgbe_remove_adapter(hw);
  304. return IXGBE_FAILED_READ_REG;
  305. }
  306. udelay(5);
  307. }
  308. adapter = hw->back;
  309. e_warn(hw, "register writes incomplete %08x\n", value);
  310. }
  311. writes_completed:
  312. value = readl(reg_addr + reg);
  313. if (unlikely(value == IXGBE_FAILED_READ_REG))
  314. value = ixgbe_check_remove(hw, reg);
  315. return value;
  316. }
  317. static bool ixgbe_check_cfg_remove(struct ixgbe_hw *hw, struct pci_dev *pdev)
  318. {
  319. u16 value;
  320. pci_read_config_word(pdev, PCI_VENDOR_ID, &value);
  321. if (value == IXGBE_FAILED_READ_CFG_WORD) {
  322. ixgbe_remove_adapter(hw);
  323. return true;
  324. }
  325. return false;
  326. }
  327. u16 ixgbe_read_pci_cfg_word(struct ixgbe_hw *hw, u32 reg)
  328. {
  329. struct ixgbe_adapter *adapter = hw->back;
  330. u16 value;
  331. if (ixgbe_removed(hw->hw_addr))
  332. return IXGBE_FAILED_READ_CFG_WORD;
  333. pci_read_config_word(adapter->pdev, reg, &value);
  334. if (value == IXGBE_FAILED_READ_CFG_WORD &&
  335. ixgbe_check_cfg_remove(hw, adapter->pdev))
  336. return IXGBE_FAILED_READ_CFG_WORD;
  337. return value;
  338. }
  339. #ifdef CONFIG_PCI_IOV
  340. static u32 ixgbe_read_pci_cfg_dword(struct ixgbe_hw *hw, u32 reg)
  341. {
  342. struct ixgbe_adapter *adapter = hw->back;
  343. u32 value;
  344. if (ixgbe_removed(hw->hw_addr))
  345. return IXGBE_FAILED_READ_CFG_DWORD;
  346. pci_read_config_dword(adapter->pdev, reg, &value);
  347. if (value == IXGBE_FAILED_READ_CFG_DWORD &&
  348. ixgbe_check_cfg_remove(hw, adapter->pdev))
  349. return IXGBE_FAILED_READ_CFG_DWORD;
  350. return value;
  351. }
  352. #endif /* CONFIG_PCI_IOV */
  353. void ixgbe_write_pci_cfg_word(struct ixgbe_hw *hw, u32 reg, u16 value)
  354. {
  355. struct ixgbe_adapter *adapter = hw->back;
  356. if (ixgbe_removed(hw->hw_addr))
  357. return;
  358. pci_write_config_word(adapter->pdev, reg, value);
  359. }
  360. static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
  361. {
  362. BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
  363. /* flush memory to make sure state is correct before next watchdog */
  364. smp_mb__before_atomic();
  365. clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
  366. }
  367. struct ixgbe_reg_info {
  368. u32 ofs;
  369. char *name;
  370. };
  371. static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
  372. /* General Registers */
  373. {IXGBE_CTRL, "CTRL"},
  374. {IXGBE_STATUS, "STATUS"},
  375. {IXGBE_CTRL_EXT, "CTRL_EXT"},
  376. /* Interrupt Registers */
  377. {IXGBE_EICR, "EICR"},
  378. /* RX Registers */
  379. {IXGBE_SRRCTL(0), "SRRCTL"},
  380. {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
  381. {IXGBE_RDLEN(0), "RDLEN"},
  382. {IXGBE_RDH(0), "RDH"},
  383. {IXGBE_RDT(0), "RDT"},
  384. {IXGBE_RXDCTL(0), "RXDCTL"},
  385. {IXGBE_RDBAL(0), "RDBAL"},
  386. {IXGBE_RDBAH(0), "RDBAH"},
  387. /* TX Registers */
  388. {IXGBE_TDBAL(0), "TDBAL"},
  389. {IXGBE_TDBAH(0), "TDBAH"},
  390. {IXGBE_TDLEN(0), "TDLEN"},
  391. {IXGBE_TDH(0), "TDH"},
  392. {IXGBE_TDT(0), "TDT"},
  393. {IXGBE_TXDCTL(0), "TXDCTL"},
  394. /* List Terminator */
  395. { .name = NULL }
  396. };
  397. /*
  398. * ixgbe_regdump - register printout routine
  399. */
  400. static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
  401. {
  402. int i;
  403. char rname[16];
  404. u32 regs[64];
  405. switch (reginfo->ofs) {
  406. case IXGBE_SRRCTL(0):
  407. for (i = 0; i < 64; i++)
  408. regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
  409. break;
  410. case IXGBE_DCA_RXCTRL(0):
  411. for (i = 0; i < 64; i++)
  412. regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
  413. break;
  414. case IXGBE_RDLEN(0):
  415. for (i = 0; i < 64; i++)
  416. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
  417. break;
  418. case IXGBE_RDH(0):
  419. for (i = 0; i < 64; i++)
  420. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
  421. break;
  422. case IXGBE_RDT(0):
  423. for (i = 0; i < 64; i++)
  424. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
  425. break;
  426. case IXGBE_RXDCTL(0):
  427. for (i = 0; i < 64; i++)
  428. regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
  429. break;
  430. case IXGBE_RDBAL(0):
  431. for (i = 0; i < 64; i++)
  432. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
  433. break;
  434. case IXGBE_RDBAH(0):
  435. for (i = 0; i < 64; i++)
  436. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
  437. break;
  438. case IXGBE_TDBAL(0):
  439. for (i = 0; i < 64; i++)
  440. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
  441. break;
  442. case IXGBE_TDBAH(0):
  443. for (i = 0; i < 64; i++)
  444. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
  445. break;
  446. case IXGBE_TDLEN(0):
  447. for (i = 0; i < 64; i++)
  448. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
  449. break;
  450. case IXGBE_TDH(0):
  451. for (i = 0; i < 64; i++)
  452. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
  453. break;
  454. case IXGBE_TDT(0):
  455. for (i = 0; i < 64; i++)
  456. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
  457. break;
  458. case IXGBE_TXDCTL(0):
  459. for (i = 0; i < 64; i++)
  460. regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
  461. break;
  462. default:
  463. pr_info("%-15s %08x\n",
  464. reginfo->name, IXGBE_READ_REG(hw, reginfo->ofs));
  465. return;
  466. }
  467. i = 0;
  468. while (i < 64) {
  469. int j;
  470. char buf[9 * 8 + 1];
  471. char *p = buf;
  472. snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i, i + 7);
  473. for (j = 0; j < 8; j++)
  474. p += sprintf(p, " %08x", regs[i++]);
  475. pr_err("%-15s%s\n", rname, buf);
  476. }
  477. }
  478. static void ixgbe_print_buffer(struct ixgbe_ring *ring, int n)
  479. {
  480. struct ixgbe_tx_buffer *tx_buffer;
  481. tx_buffer = &ring->tx_buffer_info[ring->next_to_clean];
  482. pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
  483. n, ring->next_to_use, ring->next_to_clean,
  484. (u64)dma_unmap_addr(tx_buffer, dma),
  485. dma_unmap_len(tx_buffer, len),
  486. tx_buffer->next_to_watch,
  487. (u64)tx_buffer->time_stamp);
  488. }
  489. /*
  490. * ixgbe_dump - Print registers, tx-rings and rx-rings
  491. */
  492. static void ixgbe_dump(struct ixgbe_adapter *adapter)
  493. {
  494. struct net_device *netdev = adapter->netdev;
  495. struct ixgbe_hw *hw = &adapter->hw;
  496. struct ixgbe_reg_info *reginfo;
  497. int n = 0;
  498. struct ixgbe_ring *ring;
  499. struct ixgbe_tx_buffer *tx_buffer;
  500. union ixgbe_adv_tx_desc *tx_desc;
  501. struct my_u0 { u64 a; u64 b; } *u0;
  502. struct ixgbe_ring *rx_ring;
  503. union ixgbe_adv_rx_desc *rx_desc;
  504. struct ixgbe_rx_buffer *rx_buffer_info;
  505. int i = 0;
  506. if (!netif_msg_hw(adapter))
  507. return;
  508. /* Print netdevice Info */
  509. if (netdev) {
  510. dev_info(&adapter->pdev->dev, "Net device Info\n");
  511. pr_info("Device Name state "
  512. "trans_start\n");
  513. pr_info("%-15s %016lX %016lX\n",
  514. netdev->name,
  515. netdev->state,
  516. dev_trans_start(netdev));
  517. }
  518. /* Print Registers */
  519. dev_info(&adapter->pdev->dev, "Register Dump\n");
  520. pr_info(" Register Name Value\n");
  521. for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
  522. reginfo->name; reginfo++) {
  523. ixgbe_regdump(hw, reginfo);
  524. }
  525. /* Print TX Ring Summary */
  526. if (!netdev || !netif_running(netdev))
  527. return;
  528. dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
  529. pr_info(" %s %s %s %s\n",
  530. "Queue [NTU] [NTC] [bi(ntc)->dma ]",
  531. "leng", "ntw", "timestamp");
  532. for (n = 0; n < adapter->num_tx_queues; n++) {
  533. ring = adapter->tx_ring[n];
  534. ixgbe_print_buffer(ring, n);
  535. }
  536. for (n = 0; n < adapter->num_xdp_queues; n++) {
  537. ring = adapter->xdp_ring[n];
  538. ixgbe_print_buffer(ring, n);
  539. }
  540. /* Print TX Rings */
  541. if (!netif_msg_tx_done(adapter))
  542. goto rx_ring_summary;
  543. dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
  544. /* Transmit Descriptor Formats
  545. *
  546. * 82598 Advanced Transmit Descriptor
  547. * +--------------------------------------------------------------+
  548. * 0 | Buffer Address [63:0] |
  549. * +--------------------------------------------------------------+
  550. * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
  551. * +--------------------------------------------------------------+
  552. * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
  553. *
  554. * 82598 Advanced Transmit Descriptor (Write-Back Format)
  555. * +--------------------------------------------------------------+
  556. * 0 | RSV [63:0] |
  557. * +--------------------------------------------------------------+
  558. * 8 | RSV | STA | NXTSEQ |
  559. * +--------------------------------------------------------------+
  560. * 63 36 35 32 31 0
  561. *
  562. * 82599+ Advanced Transmit Descriptor
  563. * +--------------------------------------------------------------+
  564. * 0 | Buffer Address [63:0] |
  565. * +--------------------------------------------------------------+
  566. * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
  567. * +--------------------------------------------------------------+
  568. * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
  569. *
  570. * 82599+ Advanced Transmit Descriptor (Write-Back Format)
  571. * +--------------------------------------------------------------+
  572. * 0 | RSV [63:0] |
  573. * +--------------------------------------------------------------+
  574. * 8 | RSV | STA | RSV |
  575. * +--------------------------------------------------------------+
  576. * 63 36 35 32 31 0
  577. */
  578. for (n = 0; n < adapter->num_tx_queues; n++) {
  579. ring = adapter->tx_ring[n];
  580. pr_info("------------------------------------\n");
  581. pr_info("TX QUEUE INDEX = %d\n", ring->queue_index);
  582. pr_info("------------------------------------\n");
  583. pr_info("%s%s %s %s %s %s\n",
  584. "T [desc] [address 63:0 ] ",
  585. "[PlPOIdStDDt Ln] [bi->dma ] ",
  586. "leng", "ntw", "timestamp", "bi->skb");
  587. for (i = 0; ring->desc && (i < ring->count); i++) {
  588. tx_desc = IXGBE_TX_DESC(ring, i);
  589. tx_buffer = &ring->tx_buffer_info[i];
  590. u0 = (struct my_u0 *)tx_desc;
  591. if (dma_unmap_len(tx_buffer, len) > 0) {
  592. const char *ring_desc;
  593. if (i == ring->next_to_use &&
  594. i == ring->next_to_clean)
  595. ring_desc = " NTC/U";
  596. else if (i == ring->next_to_use)
  597. ring_desc = " NTU";
  598. else if (i == ring->next_to_clean)
  599. ring_desc = " NTC";
  600. else
  601. ring_desc = "";
  602. pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p%s",
  603. i,
  604. le64_to_cpu((__force __le64)u0->a),
  605. le64_to_cpu((__force __le64)u0->b),
  606. (u64)dma_unmap_addr(tx_buffer, dma),
  607. dma_unmap_len(tx_buffer, len),
  608. tx_buffer->next_to_watch,
  609. (u64)tx_buffer->time_stamp,
  610. tx_buffer->skb,
  611. ring_desc);
  612. if (netif_msg_pktdata(adapter) &&
  613. tx_buffer->skb)
  614. print_hex_dump(KERN_INFO, "",
  615. DUMP_PREFIX_ADDRESS, 16, 1,
  616. tx_buffer->skb->data,
  617. dma_unmap_len(tx_buffer, len),
  618. true);
  619. }
  620. }
  621. }
  622. /* Print RX Rings Summary */
  623. rx_ring_summary:
  624. dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
  625. pr_info("Queue [NTU] [NTC]\n");
  626. for (n = 0; n < adapter->num_rx_queues; n++) {
  627. rx_ring = adapter->rx_ring[n];
  628. pr_info("%5d %5X %5X\n",
  629. n, rx_ring->next_to_use, rx_ring->next_to_clean);
  630. }
  631. /* Print RX Rings */
  632. if (!netif_msg_rx_status(adapter))
  633. return;
  634. dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
  635. /* Receive Descriptor Formats
  636. *
  637. * 82598 Advanced Receive Descriptor (Read) Format
  638. * 63 1 0
  639. * +-----------------------------------------------------+
  640. * 0 | Packet Buffer Address [63:1] |A0/NSE|
  641. * +----------------------------------------------+------+
  642. * 8 | Header Buffer Address [63:1] | DD |
  643. * +-----------------------------------------------------+
  644. *
  645. *
  646. * 82598 Advanced Receive Descriptor (Write-Back) Format
  647. *
  648. * 63 48 47 32 31 30 21 20 16 15 4 3 0
  649. * +------------------------------------------------------+
  650. * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
  651. * | Packet | IP | | | | Type | Type |
  652. * | Checksum | Ident | | | | | |
  653. * +------------------------------------------------------+
  654. * 8 | VLAN Tag | Length | Extended Error | Extended Status |
  655. * +------------------------------------------------------+
  656. * 63 48 47 32 31 20 19 0
  657. *
  658. * 82599+ Advanced Receive Descriptor (Read) Format
  659. * 63 1 0
  660. * +-----------------------------------------------------+
  661. * 0 | Packet Buffer Address [63:1] |A0/NSE|
  662. * +----------------------------------------------+------+
  663. * 8 | Header Buffer Address [63:1] | DD |
  664. * +-----------------------------------------------------+
  665. *
  666. *
  667. * 82599+ Advanced Receive Descriptor (Write-Back) Format
  668. *
  669. * 63 48 47 32 31 30 21 20 17 16 4 3 0
  670. * +------------------------------------------------------+
  671. * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
  672. * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
  673. * |/ Flow Dir Flt ID | | | | | |
  674. * +------------------------------------------------------+
  675. * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
  676. * +------------------------------------------------------+
  677. * 63 48 47 32 31 20 19 0
  678. */
  679. for (n = 0; n < adapter->num_rx_queues; n++) {
  680. rx_ring = adapter->rx_ring[n];
  681. pr_info("------------------------------------\n");
  682. pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
  683. pr_info("------------------------------------\n");
  684. pr_info("%s%s%s\n",
  685. "R [desc] [ PktBuf A0] ",
  686. "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
  687. "<-- Adv Rx Read format");
  688. pr_info("%s%s%s\n",
  689. "RWB[desc] [PcsmIpSHl PtRs] ",
  690. "[vl er S cks ln] ---------------- [bi->skb ] ",
  691. "<-- Adv Rx Write-Back format");
  692. for (i = 0; i < rx_ring->count; i++) {
  693. const char *ring_desc;
  694. if (i == rx_ring->next_to_use)
  695. ring_desc = " NTU";
  696. else if (i == rx_ring->next_to_clean)
  697. ring_desc = " NTC";
  698. else
  699. ring_desc = "";
  700. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  701. rx_desc = IXGBE_RX_DESC(rx_ring, i);
  702. u0 = (struct my_u0 *)rx_desc;
  703. if (rx_desc->wb.upper.length) {
  704. /* Descriptor Done */
  705. pr_info("RWB[0x%03X] %016llX %016llX ---------------- %p%s\n",
  706. i,
  707. le64_to_cpu((__force __le64)u0->a),
  708. le64_to_cpu((__force __le64)u0->b),
  709. rx_buffer_info->skb,
  710. ring_desc);
  711. } else {
  712. pr_info("R [0x%03X] %016llX %016llX %016llX %p%s\n",
  713. i,
  714. le64_to_cpu((__force __le64)u0->a),
  715. le64_to_cpu((__force __le64)u0->b),
  716. (u64)rx_buffer_info->dma,
  717. rx_buffer_info->skb,
  718. ring_desc);
  719. if (netif_msg_pktdata(adapter) &&
  720. rx_buffer_info->dma) {
  721. print_hex_dump(KERN_INFO, "",
  722. DUMP_PREFIX_ADDRESS, 16, 1,
  723. page_address(rx_buffer_info->page) +
  724. rx_buffer_info->page_offset,
  725. ixgbe_rx_bufsz(rx_ring), true);
  726. }
  727. }
  728. }
  729. }
  730. }
  731. static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
  732. {
  733. u32 ctrl_ext;
  734. /* Let firmware take over control of h/w */
  735. ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
  736. IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
  737. ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
  738. }
  739. static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
  740. {
  741. u32 ctrl_ext;
  742. /* Let firmware know the driver has taken over */
  743. ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
  744. IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
  745. ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
  746. }
  747. /**
  748. * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
  749. * @adapter: pointer to adapter struct
  750. * @direction: 0 for Rx, 1 for Tx, -1 for other causes
  751. * @queue: queue to map the corresponding interrupt to
  752. * @msix_vector: the vector to map to the corresponding queue
  753. *
  754. */
  755. static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
  756. u8 queue, u8 msix_vector)
  757. {
  758. u32 ivar, index;
  759. struct ixgbe_hw *hw = &adapter->hw;
  760. switch (hw->mac.type) {
  761. case ixgbe_mac_82598EB:
  762. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  763. if (direction == -1)
  764. direction = 0;
  765. index = (((direction * 64) + queue) >> 2) & 0x1F;
  766. ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
  767. ivar &= ~(0xFF << (8 * (queue & 0x3)));
  768. ivar |= (msix_vector << (8 * (queue & 0x3)));
  769. IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
  770. break;
  771. case ixgbe_mac_82599EB:
  772. case ixgbe_mac_X540:
  773. case ixgbe_mac_X550:
  774. case ixgbe_mac_X550EM_x:
  775. case ixgbe_mac_x550em_a:
  776. if (direction == -1) {
  777. /* other causes */
  778. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  779. index = ((queue & 1) * 8);
  780. ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
  781. ivar &= ~(0xFF << index);
  782. ivar |= (msix_vector << index);
  783. IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
  784. break;
  785. } else {
  786. /* tx or rx causes */
  787. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  788. index = ((16 * (queue & 1)) + (8 * direction));
  789. ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
  790. ivar &= ~(0xFF << index);
  791. ivar |= (msix_vector << index);
  792. IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
  793. break;
  794. }
  795. default:
  796. break;
  797. }
  798. }
  799. static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
  800. u64 qmask)
  801. {
  802. u32 mask;
  803. switch (adapter->hw.mac.type) {
  804. case ixgbe_mac_82598EB:
  805. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  806. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
  807. break;
  808. case ixgbe_mac_82599EB:
  809. case ixgbe_mac_X540:
  810. case ixgbe_mac_X550:
  811. case ixgbe_mac_X550EM_x:
  812. case ixgbe_mac_x550em_a:
  813. mask = (qmask & 0xFFFFFFFF);
  814. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
  815. mask = (qmask >> 32);
  816. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
  817. break;
  818. default:
  819. break;
  820. }
  821. }
  822. static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
  823. {
  824. struct ixgbe_hw *hw = &adapter->hw;
  825. struct ixgbe_hw_stats *hwstats = &adapter->stats;
  826. int i;
  827. u32 data;
  828. if ((hw->fc.current_mode != ixgbe_fc_full) &&
  829. (hw->fc.current_mode != ixgbe_fc_rx_pause))
  830. return;
  831. switch (hw->mac.type) {
  832. case ixgbe_mac_82598EB:
  833. data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
  834. break;
  835. default:
  836. data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
  837. }
  838. hwstats->lxoffrxc += data;
  839. /* refill credits (no tx hang) if we received xoff */
  840. if (!data)
  841. return;
  842. for (i = 0; i < adapter->num_tx_queues; i++)
  843. clear_bit(__IXGBE_HANG_CHECK_ARMED,
  844. &adapter->tx_ring[i]->state);
  845. for (i = 0; i < adapter->num_xdp_queues; i++)
  846. clear_bit(__IXGBE_HANG_CHECK_ARMED,
  847. &adapter->xdp_ring[i]->state);
  848. }
  849. static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
  850. {
  851. struct ixgbe_hw *hw = &adapter->hw;
  852. struct ixgbe_hw_stats *hwstats = &adapter->stats;
  853. u32 xoff[8] = {0};
  854. u8 tc;
  855. int i;
  856. bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
  857. if (adapter->ixgbe_ieee_pfc)
  858. pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
  859. if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
  860. ixgbe_update_xoff_rx_lfc(adapter);
  861. return;
  862. }
  863. /* update stats for each tc, only valid with PFC enabled */
  864. for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
  865. u32 pxoffrxc;
  866. switch (hw->mac.type) {
  867. case ixgbe_mac_82598EB:
  868. pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
  869. break;
  870. default:
  871. pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
  872. }
  873. hwstats->pxoffrxc[i] += pxoffrxc;
  874. /* Get the TC for given UP */
  875. tc = netdev_get_prio_tc_map(adapter->netdev, i);
  876. xoff[tc] += pxoffrxc;
  877. }
  878. /* disarm tx queues that have received xoff frames */
  879. for (i = 0; i < adapter->num_tx_queues; i++) {
  880. struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
  881. tc = tx_ring->dcb_tc;
  882. if (xoff[tc])
  883. clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
  884. }
  885. for (i = 0; i < adapter->num_xdp_queues; i++) {
  886. struct ixgbe_ring *xdp_ring = adapter->xdp_ring[i];
  887. tc = xdp_ring->dcb_tc;
  888. if (xoff[tc])
  889. clear_bit(__IXGBE_HANG_CHECK_ARMED, &xdp_ring->state);
  890. }
  891. }
  892. static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
  893. {
  894. return ring->stats.packets;
  895. }
  896. static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
  897. {
  898. unsigned int head, tail;
  899. head = ring->next_to_clean;
  900. tail = ring->next_to_use;
  901. return ((head <= tail) ? tail : tail + ring->count) - head;
  902. }
  903. static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
  904. {
  905. u32 tx_done = ixgbe_get_tx_completed(tx_ring);
  906. u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
  907. u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
  908. clear_check_for_tx_hang(tx_ring);
  909. /*
  910. * Check for a hung queue, but be thorough. This verifies
  911. * that a transmit has been completed since the previous
  912. * check AND there is at least one packet pending. The
  913. * ARMED bit is set to indicate a potential hang. The
  914. * bit is cleared if a pause frame is received to remove
  915. * false hang detection due to PFC or 802.3x frames. By
  916. * requiring this to fail twice we avoid races with
  917. * pfc clearing the ARMED bit and conditions where we
  918. * run the check_tx_hang logic with a transmit completion
  919. * pending but without time to complete it yet.
  920. */
  921. if (tx_done_old == tx_done && tx_pending)
  922. /* make sure it is true for two checks in a row */
  923. return test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
  924. &tx_ring->state);
  925. /* update completed stats and continue */
  926. tx_ring->tx_stats.tx_done_old = tx_done;
  927. /* reset the countdown */
  928. clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
  929. return false;
  930. }
  931. /**
  932. * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
  933. * @adapter: driver private struct
  934. **/
  935. static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
  936. {
  937. /* Do the reset outside of interrupt context */
  938. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  939. set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  940. e_warn(drv, "initiating reset due to tx timeout\n");
  941. ixgbe_service_event_schedule(adapter);
  942. }
  943. }
  944. /**
  945. * ixgbe_tx_maxrate - callback to set the maximum per-queue bitrate
  946. * @netdev: network interface device structure
  947. * @queue_index: Tx queue to set
  948. * @maxrate: desired maximum transmit bitrate
  949. **/
  950. static int ixgbe_tx_maxrate(struct net_device *netdev,
  951. int queue_index, u32 maxrate)
  952. {
  953. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  954. struct ixgbe_hw *hw = &adapter->hw;
  955. u32 bcnrc_val = ixgbe_link_mbps(adapter);
  956. if (!maxrate)
  957. return 0;
  958. /* Calculate the rate factor values to set */
  959. bcnrc_val <<= IXGBE_RTTBCNRC_RF_INT_SHIFT;
  960. bcnrc_val /= maxrate;
  961. /* clear everything but the rate factor */
  962. bcnrc_val &= IXGBE_RTTBCNRC_RF_INT_MASK |
  963. IXGBE_RTTBCNRC_RF_DEC_MASK;
  964. /* enable the rate scheduler */
  965. bcnrc_val |= IXGBE_RTTBCNRC_RS_ENA;
  966. IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, queue_index);
  967. IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, bcnrc_val);
  968. return 0;
  969. }
  970. /**
  971. * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
  972. * @q_vector: structure containing interrupt and ring information
  973. * @tx_ring: tx ring to clean
  974. * @napi_budget: Used to determine if we are in netpoll
  975. **/
  976. static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
  977. struct ixgbe_ring *tx_ring, int napi_budget)
  978. {
  979. struct ixgbe_adapter *adapter = q_vector->adapter;
  980. struct ixgbe_tx_buffer *tx_buffer;
  981. union ixgbe_adv_tx_desc *tx_desc;
  982. unsigned int total_bytes = 0, total_packets = 0, total_ipsec = 0;
  983. unsigned int budget = q_vector->tx.work_limit;
  984. unsigned int i = tx_ring->next_to_clean;
  985. if (test_bit(__IXGBE_DOWN, &adapter->state))
  986. return true;
  987. tx_buffer = &tx_ring->tx_buffer_info[i];
  988. tx_desc = IXGBE_TX_DESC(tx_ring, i);
  989. i -= tx_ring->count;
  990. do {
  991. union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
  992. /* if next_to_watch is not set then there is no work pending */
  993. if (!eop_desc)
  994. break;
  995. /* prevent any other reads prior to eop_desc */
  996. smp_rmb();
  997. /* if DD is not set pending work has not been completed */
  998. if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
  999. break;
  1000. /* clear next_to_watch to prevent false hangs */
  1001. tx_buffer->next_to_watch = NULL;
  1002. /* update the statistics for this packet */
  1003. total_bytes += tx_buffer->bytecount;
  1004. total_packets += tx_buffer->gso_segs;
  1005. if (tx_buffer->tx_flags & IXGBE_TX_FLAGS_IPSEC)
  1006. total_ipsec++;
  1007. /* free the skb */
  1008. if (ring_is_xdp(tx_ring))
  1009. xdp_return_frame(tx_buffer->xdpf);
  1010. else
  1011. napi_consume_skb(tx_buffer->skb, napi_budget);
  1012. /* unmap skb header data */
  1013. dma_unmap_single(tx_ring->dev,
  1014. dma_unmap_addr(tx_buffer, dma),
  1015. dma_unmap_len(tx_buffer, len),
  1016. DMA_TO_DEVICE);
  1017. /* clear tx_buffer data */
  1018. dma_unmap_len_set(tx_buffer, len, 0);
  1019. /* unmap remaining buffers */
  1020. while (tx_desc != eop_desc) {
  1021. tx_buffer++;
  1022. tx_desc++;
  1023. i++;
  1024. if (unlikely(!i)) {
  1025. i -= tx_ring->count;
  1026. tx_buffer = tx_ring->tx_buffer_info;
  1027. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  1028. }
  1029. /* unmap any remaining paged data */
  1030. if (dma_unmap_len(tx_buffer, len)) {
  1031. dma_unmap_page(tx_ring->dev,
  1032. dma_unmap_addr(tx_buffer, dma),
  1033. dma_unmap_len(tx_buffer, len),
  1034. DMA_TO_DEVICE);
  1035. dma_unmap_len_set(tx_buffer, len, 0);
  1036. }
  1037. }
  1038. /* move us one more past the eop_desc for start of next pkt */
  1039. tx_buffer++;
  1040. tx_desc++;
  1041. i++;
  1042. if (unlikely(!i)) {
  1043. i -= tx_ring->count;
  1044. tx_buffer = tx_ring->tx_buffer_info;
  1045. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  1046. }
  1047. /* issue prefetch for next Tx descriptor */
  1048. prefetch(tx_desc);
  1049. /* update budget accounting */
  1050. budget--;
  1051. } while (likely(budget));
  1052. i += tx_ring->count;
  1053. tx_ring->next_to_clean = i;
  1054. u64_stats_update_begin(&tx_ring->syncp);
  1055. tx_ring->stats.bytes += total_bytes;
  1056. tx_ring->stats.packets += total_packets;
  1057. u64_stats_update_end(&tx_ring->syncp);
  1058. q_vector->tx.total_bytes += total_bytes;
  1059. q_vector->tx.total_packets += total_packets;
  1060. adapter->tx_ipsec += total_ipsec;
  1061. if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
  1062. /* schedule immediate reset if we believe we hung */
  1063. struct ixgbe_hw *hw = &adapter->hw;
  1064. e_err(drv, "Detected Tx Unit Hang %s\n"
  1065. " Tx Queue <%d>\n"
  1066. " TDH, TDT <%x>, <%x>\n"
  1067. " next_to_use <%x>\n"
  1068. " next_to_clean <%x>\n"
  1069. "tx_buffer_info[next_to_clean]\n"
  1070. " time_stamp <%lx>\n"
  1071. " jiffies <%lx>\n",
  1072. ring_is_xdp(tx_ring) ? "(XDP)" : "",
  1073. tx_ring->queue_index,
  1074. IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
  1075. IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
  1076. tx_ring->next_to_use, i,
  1077. tx_ring->tx_buffer_info[i].time_stamp, jiffies);
  1078. if (!ring_is_xdp(tx_ring))
  1079. netif_stop_subqueue(tx_ring->netdev,
  1080. tx_ring->queue_index);
  1081. e_info(probe,
  1082. "tx hang %d detected on queue %d, resetting adapter\n",
  1083. adapter->tx_timeout_count + 1, tx_ring->queue_index);
  1084. /* schedule immediate reset if we believe we hung */
  1085. ixgbe_tx_timeout_reset(adapter);
  1086. /* the adapter is about to reset, no point in enabling stuff */
  1087. return true;
  1088. }
  1089. if (ring_is_xdp(tx_ring))
  1090. return !!budget;
  1091. netdev_tx_completed_queue(txring_txq(tx_ring),
  1092. total_packets, total_bytes);
  1093. #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
  1094. if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
  1095. (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
  1096. /* Make sure that anybody stopping the queue after this
  1097. * sees the new next_to_clean.
  1098. */
  1099. smp_mb();
  1100. if (__netif_subqueue_stopped(tx_ring->netdev,
  1101. tx_ring->queue_index)
  1102. && !test_bit(__IXGBE_DOWN, &adapter->state)) {
  1103. netif_wake_subqueue(tx_ring->netdev,
  1104. tx_ring->queue_index);
  1105. ++tx_ring->tx_stats.restart_queue;
  1106. }
  1107. }
  1108. return !!budget;
  1109. }
  1110. #ifdef CONFIG_IXGBE_DCA
  1111. static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
  1112. struct ixgbe_ring *tx_ring,
  1113. int cpu)
  1114. {
  1115. struct ixgbe_hw *hw = &adapter->hw;
  1116. u32 txctrl = 0;
  1117. u16 reg_offset;
  1118. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1119. txctrl = dca3_get_tag(tx_ring->dev, cpu);
  1120. switch (hw->mac.type) {
  1121. case ixgbe_mac_82598EB:
  1122. reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
  1123. break;
  1124. case ixgbe_mac_82599EB:
  1125. case ixgbe_mac_X540:
  1126. reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
  1127. txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
  1128. break;
  1129. default:
  1130. /* for unknown hardware do not write register */
  1131. return;
  1132. }
  1133. /*
  1134. * We can enable relaxed ordering for reads, but not writes when
  1135. * DCA is enabled. This is due to a known issue in some chipsets
  1136. * which will cause the DCA tag to be cleared.
  1137. */
  1138. txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
  1139. IXGBE_DCA_TXCTRL_DATA_RRO_EN |
  1140. IXGBE_DCA_TXCTRL_DESC_DCA_EN;
  1141. IXGBE_WRITE_REG(hw, reg_offset, txctrl);
  1142. }
  1143. static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
  1144. struct ixgbe_ring *rx_ring,
  1145. int cpu)
  1146. {
  1147. struct ixgbe_hw *hw = &adapter->hw;
  1148. u32 rxctrl = 0;
  1149. u8 reg_idx = rx_ring->reg_idx;
  1150. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1151. rxctrl = dca3_get_tag(rx_ring->dev, cpu);
  1152. switch (hw->mac.type) {
  1153. case ixgbe_mac_82599EB:
  1154. case ixgbe_mac_X540:
  1155. rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
  1156. break;
  1157. default:
  1158. break;
  1159. }
  1160. /*
  1161. * We can enable relaxed ordering for reads, but not writes when
  1162. * DCA is enabled. This is due to a known issue in some chipsets
  1163. * which will cause the DCA tag to be cleared.
  1164. */
  1165. rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
  1166. IXGBE_DCA_RXCTRL_DATA_DCA_EN |
  1167. IXGBE_DCA_RXCTRL_DESC_DCA_EN;
  1168. IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
  1169. }
  1170. static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
  1171. {
  1172. struct ixgbe_adapter *adapter = q_vector->adapter;
  1173. struct ixgbe_ring *ring;
  1174. int cpu = get_cpu();
  1175. if (q_vector->cpu == cpu)
  1176. goto out_no_update;
  1177. ixgbe_for_each_ring(ring, q_vector->tx)
  1178. ixgbe_update_tx_dca(adapter, ring, cpu);
  1179. ixgbe_for_each_ring(ring, q_vector->rx)
  1180. ixgbe_update_rx_dca(adapter, ring, cpu);
  1181. q_vector->cpu = cpu;
  1182. out_no_update:
  1183. put_cpu();
  1184. }
  1185. static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
  1186. {
  1187. int i;
  1188. /* always use CB2 mode, difference is masked in the CB driver */
  1189. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1190. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  1191. IXGBE_DCA_CTRL_DCA_MODE_CB2);
  1192. else
  1193. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  1194. IXGBE_DCA_CTRL_DCA_DISABLE);
  1195. for (i = 0; i < adapter->num_q_vectors; i++) {
  1196. adapter->q_vector[i]->cpu = -1;
  1197. ixgbe_update_dca(adapter->q_vector[i]);
  1198. }
  1199. }
  1200. static int __ixgbe_notify_dca(struct device *dev, void *data)
  1201. {
  1202. struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
  1203. unsigned long event = *(unsigned long *)data;
  1204. if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
  1205. return 0;
  1206. switch (event) {
  1207. case DCA_PROVIDER_ADD:
  1208. /* if we're already enabled, don't do it again */
  1209. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  1210. break;
  1211. if (dca_add_requester(dev) == 0) {
  1212. adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
  1213. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  1214. IXGBE_DCA_CTRL_DCA_MODE_CB2);
  1215. break;
  1216. }
  1217. /* fall through - DCA is disabled. */
  1218. case DCA_PROVIDER_REMOVE:
  1219. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  1220. dca_remove_requester(dev);
  1221. adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
  1222. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  1223. IXGBE_DCA_CTRL_DCA_DISABLE);
  1224. }
  1225. break;
  1226. }
  1227. return 0;
  1228. }
  1229. #endif /* CONFIG_IXGBE_DCA */
  1230. #define IXGBE_RSS_L4_TYPES_MASK \
  1231. ((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \
  1232. (1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \
  1233. (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \
  1234. (1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP))
  1235. static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
  1236. union ixgbe_adv_rx_desc *rx_desc,
  1237. struct sk_buff *skb)
  1238. {
  1239. u16 rss_type;
  1240. if (!(ring->netdev->features & NETIF_F_RXHASH))
  1241. return;
  1242. rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) &
  1243. IXGBE_RXDADV_RSSTYPE_MASK;
  1244. if (!rss_type)
  1245. return;
  1246. skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
  1247. (IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ?
  1248. PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
  1249. }
  1250. #ifdef IXGBE_FCOE
  1251. /**
  1252. * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
  1253. * @ring: structure containing ring specific data
  1254. * @rx_desc: advanced rx descriptor
  1255. *
  1256. * Returns : true if it is FCoE pkt
  1257. */
  1258. static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
  1259. union ixgbe_adv_rx_desc *rx_desc)
  1260. {
  1261. __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
  1262. return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
  1263. ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
  1264. (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
  1265. IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
  1266. }
  1267. #endif /* IXGBE_FCOE */
  1268. /**
  1269. * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
  1270. * @ring: structure containing ring specific data
  1271. * @rx_desc: current Rx descriptor being processed
  1272. * @skb: skb currently being received and modified
  1273. **/
  1274. static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
  1275. union ixgbe_adv_rx_desc *rx_desc,
  1276. struct sk_buff *skb)
  1277. {
  1278. __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
  1279. bool encap_pkt = false;
  1280. skb_checksum_none_assert(skb);
  1281. /* Rx csum disabled */
  1282. if (!(ring->netdev->features & NETIF_F_RXCSUM))
  1283. return;
  1284. /* check for VXLAN and Geneve packets */
  1285. if (pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_VXLAN)) {
  1286. encap_pkt = true;
  1287. skb->encapsulation = 1;
  1288. }
  1289. /* if IP and error */
  1290. if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
  1291. ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
  1292. ring->rx_stats.csum_err++;
  1293. return;
  1294. }
  1295. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
  1296. return;
  1297. if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
  1298. /*
  1299. * 82599 errata, UDP frames with a 0 checksum can be marked as
  1300. * checksum errors.
  1301. */
  1302. if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
  1303. test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
  1304. return;
  1305. ring->rx_stats.csum_err++;
  1306. return;
  1307. }
  1308. /* It must be a TCP or UDP packet with a valid checksum */
  1309. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1310. if (encap_pkt) {
  1311. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_OUTERIPCS))
  1312. return;
  1313. if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_OUTERIPER)) {
  1314. skb->ip_summed = CHECKSUM_NONE;
  1315. return;
  1316. }
  1317. /* If we checked the outer header let the stack know */
  1318. skb->csum_level = 1;
  1319. }
  1320. }
  1321. static inline unsigned int ixgbe_rx_offset(struct ixgbe_ring *rx_ring)
  1322. {
  1323. return ring_uses_build_skb(rx_ring) ? IXGBE_SKB_PAD : 0;
  1324. }
  1325. static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
  1326. struct ixgbe_rx_buffer *bi)
  1327. {
  1328. struct page *page = bi->page;
  1329. dma_addr_t dma;
  1330. /* since we are recycling buffers we should seldom need to alloc */
  1331. if (likely(page))
  1332. return true;
  1333. /* alloc new page for storage */
  1334. page = dev_alloc_pages(ixgbe_rx_pg_order(rx_ring));
  1335. if (unlikely(!page)) {
  1336. rx_ring->rx_stats.alloc_rx_page_failed++;
  1337. return false;
  1338. }
  1339. /* map page for use */
  1340. dma = dma_map_page_attrs(rx_ring->dev, page, 0,
  1341. ixgbe_rx_pg_size(rx_ring),
  1342. DMA_FROM_DEVICE,
  1343. IXGBE_RX_DMA_ATTR);
  1344. /*
  1345. * if mapping failed free memory back to system since
  1346. * there isn't much point in holding memory we can't use
  1347. */
  1348. if (dma_mapping_error(rx_ring->dev, dma)) {
  1349. __free_pages(page, ixgbe_rx_pg_order(rx_ring));
  1350. rx_ring->rx_stats.alloc_rx_page_failed++;
  1351. return false;
  1352. }
  1353. bi->dma = dma;
  1354. bi->page = page;
  1355. bi->page_offset = ixgbe_rx_offset(rx_ring);
  1356. page_ref_add(page, USHRT_MAX - 1);
  1357. bi->pagecnt_bias = USHRT_MAX;
  1358. rx_ring->rx_stats.alloc_rx_page++;
  1359. return true;
  1360. }
  1361. /**
  1362. * ixgbe_alloc_rx_buffers - Replace used receive buffers
  1363. * @rx_ring: ring to place buffers on
  1364. * @cleaned_count: number of buffers to replace
  1365. **/
  1366. void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
  1367. {
  1368. union ixgbe_adv_rx_desc *rx_desc;
  1369. struct ixgbe_rx_buffer *bi;
  1370. u16 i = rx_ring->next_to_use;
  1371. u16 bufsz;
  1372. /* nothing to do */
  1373. if (!cleaned_count)
  1374. return;
  1375. rx_desc = IXGBE_RX_DESC(rx_ring, i);
  1376. bi = &rx_ring->rx_buffer_info[i];
  1377. i -= rx_ring->count;
  1378. bufsz = ixgbe_rx_bufsz(rx_ring);
  1379. do {
  1380. if (!ixgbe_alloc_mapped_page(rx_ring, bi))
  1381. break;
  1382. /* sync the buffer for use by the device */
  1383. dma_sync_single_range_for_device(rx_ring->dev, bi->dma,
  1384. bi->page_offset, bufsz,
  1385. DMA_FROM_DEVICE);
  1386. /*
  1387. * Refresh the desc even if buffer_addrs didn't change
  1388. * because each write-back erases this info.
  1389. */
  1390. rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
  1391. rx_desc++;
  1392. bi++;
  1393. i++;
  1394. if (unlikely(!i)) {
  1395. rx_desc = IXGBE_RX_DESC(rx_ring, 0);
  1396. bi = rx_ring->rx_buffer_info;
  1397. i -= rx_ring->count;
  1398. }
  1399. /* clear the length for the next_to_use descriptor */
  1400. rx_desc->wb.upper.length = 0;
  1401. cleaned_count--;
  1402. } while (cleaned_count);
  1403. i += rx_ring->count;
  1404. if (rx_ring->next_to_use != i) {
  1405. rx_ring->next_to_use = i;
  1406. /* update next to alloc since we have filled the ring */
  1407. rx_ring->next_to_alloc = i;
  1408. /* Force memory writes to complete before letting h/w
  1409. * know there are new descriptors to fetch. (Only
  1410. * applicable for weak-ordered memory model archs,
  1411. * such as IA-64).
  1412. */
  1413. wmb();
  1414. writel(i, rx_ring->tail);
  1415. }
  1416. }
  1417. static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
  1418. struct sk_buff *skb)
  1419. {
  1420. u16 hdr_len = skb_headlen(skb);
  1421. /* set gso_size to avoid messing up TCP MSS */
  1422. skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
  1423. IXGBE_CB(skb)->append_cnt);
  1424. skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
  1425. }
  1426. static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
  1427. struct sk_buff *skb)
  1428. {
  1429. /* if append_cnt is 0 then frame is not RSC */
  1430. if (!IXGBE_CB(skb)->append_cnt)
  1431. return;
  1432. rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
  1433. rx_ring->rx_stats.rsc_flush++;
  1434. ixgbe_set_rsc_gso_size(rx_ring, skb);
  1435. /* gso_size is computed using append_cnt so always clear it last */
  1436. IXGBE_CB(skb)->append_cnt = 0;
  1437. }
  1438. /**
  1439. * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
  1440. * @rx_ring: rx descriptor ring packet is being transacted on
  1441. * @rx_desc: pointer to the EOP Rx descriptor
  1442. * @skb: pointer to current skb being populated
  1443. *
  1444. * This function checks the ring, descriptor, and packet information in
  1445. * order to populate the hash, checksum, VLAN, timestamp, protocol, and
  1446. * other fields within the skb.
  1447. **/
  1448. static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
  1449. union ixgbe_adv_rx_desc *rx_desc,
  1450. struct sk_buff *skb)
  1451. {
  1452. struct net_device *dev = rx_ring->netdev;
  1453. u32 flags = rx_ring->q_vector->adapter->flags;
  1454. ixgbe_update_rsc_stats(rx_ring, skb);
  1455. ixgbe_rx_hash(rx_ring, rx_desc, skb);
  1456. ixgbe_rx_checksum(rx_ring, rx_desc, skb);
  1457. if (unlikely(flags & IXGBE_FLAG_RX_HWTSTAMP_ENABLED))
  1458. ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb);
  1459. if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
  1460. ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
  1461. u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
  1462. __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
  1463. }
  1464. if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_STAT_SECP))
  1465. ixgbe_ipsec_rx(rx_ring, rx_desc, skb);
  1466. /* record Rx queue, or update MACVLAN statistics */
  1467. if (netif_is_ixgbe(dev))
  1468. skb_record_rx_queue(skb, rx_ring->queue_index);
  1469. else
  1470. macvlan_count_rx(netdev_priv(dev), skb->len + ETH_HLEN, true,
  1471. false);
  1472. skb->protocol = eth_type_trans(skb, dev);
  1473. }
  1474. static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
  1475. struct sk_buff *skb)
  1476. {
  1477. napi_gro_receive(&q_vector->napi, skb);
  1478. }
  1479. /**
  1480. * ixgbe_is_non_eop - process handling of non-EOP buffers
  1481. * @rx_ring: Rx ring being processed
  1482. * @rx_desc: Rx descriptor for current buffer
  1483. * @skb: Current socket buffer containing buffer in progress
  1484. *
  1485. * This function updates next to clean. If the buffer is an EOP buffer
  1486. * this function exits returning false, otherwise it will place the
  1487. * sk_buff in the next buffer to be chained and return true indicating
  1488. * that this is in fact a non-EOP buffer.
  1489. **/
  1490. static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
  1491. union ixgbe_adv_rx_desc *rx_desc,
  1492. struct sk_buff *skb)
  1493. {
  1494. u32 ntc = rx_ring->next_to_clean + 1;
  1495. /* fetch, update, and store next to clean */
  1496. ntc = (ntc < rx_ring->count) ? ntc : 0;
  1497. rx_ring->next_to_clean = ntc;
  1498. prefetch(IXGBE_RX_DESC(rx_ring, ntc));
  1499. /* update RSC append count if present */
  1500. if (ring_is_rsc_enabled(rx_ring)) {
  1501. __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
  1502. cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
  1503. if (unlikely(rsc_enabled)) {
  1504. u32 rsc_cnt = le32_to_cpu(rsc_enabled);
  1505. rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
  1506. IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
  1507. /* update ntc based on RSC value */
  1508. ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
  1509. ntc &= IXGBE_RXDADV_NEXTP_MASK;
  1510. ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
  1511. }
  1512. }
  1513. /* if we are the last buffer then there is nothing else to do */
  1514. if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
  1515. return false;
  1516. /* place skb in next buffer to be received */
  1517. rx_ring->rx_buffer_info[ntc].skb = skb;
  1518. rx_ring->rx_stats.non_eop_descs++;
  1519. return true;
  1520. }
  1521. /**
  1522. * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
  1523. * @rx_ring: rx descriptor ring packet is being transacted on
  1524. * @skb: pointer to current skb being adjusted
  1525. *
  1526. * This function is an ixgbe specific version of __pskb_pull_tail. The
  1527. * main difference between this version and the original function is that
  1528. * this function can make several assumptions about the state of things
  1529. * that allow for significant optimizations versus the standard function.
  1530. * As a result we can do things like drop a frag and maintain an accurate
  1531. * truesize for the skb.
  1532. */
  1533. static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
  1534. struct sk_buff *skb)
  1535. {
  1536. struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
  1537. unsigned char *va;
  1538. unsigned int pull_len;
  1539. /*
  1540. * it is valid to use page_address instead of kmap since we are
  1541. * working with pages allocated out of the lomem pool per
  1542. * alloc_page(GFP_ATOMIC)
  1543. */
  1544. va = skb_frag_address(frag);
  1545. /*
  1546. * we need the header to contain the greater of either ETH_HLEN or
  1547. * 60 bytes if the skb->len is less than 60 for skb_pad.
  1548. */
  1549. pull_len = eth_get_headlen(va, IXGBE_RX_HDR_SIZE);
  1550. /* align pull length to size of long to optimize memcpy performance */
  1551. skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
  1552. /* update all of the pointers */
  1553. skb_frag_size_sub(frag, pull_len);
  1554. frag->page_offset += pull_len;
  1555. skb->data_len -= pull_len;
  1556. skb->tail += pull_len;
  1557. }
  1558. /**
  1559. * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
  1560. * @rx_ring: rx descriptor ring packet is being transacted on
  1561. * @skb: pointer to current skb being updated
  1562. *
  1563. * This function provides a basic DMA sync up for the first fragment of an
  1564. * skb. The reason for doing this is that the first fragment cannot be
  1565. * unmapped until we have reached the end of packet descriptor for a buffer
  1566. * chain.
  1567. */
  1568. static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
  1569. struct sk_buff *skb)
  1570. {
  1571. /* if the page was released unmap it, else just sync our portion */
  1572. if (unlikely(IXGBE_CB(skb)->page_released)) {
  1573. dma_unmap_page_attrs(rx_ring->dev, IXGBE_CB(skb)->dma,
  1574. ixgbe_rx_pg_size(rx_ring),
  1575. DMA_FROM_DEVICE,
  1576. IXGBE_RX_DMA_ATTR);
  1577. } else if (ring_uses_build_skb(rx_ring)) {
  1578. unsigned long offset = (unsigned long)(skb->data) & ~PAGE_MASK;
  1579. dma_sync_single_range_for_cpu(rx_ring->dev,
  1580. IXGBE_CB(skb)->dma,
  1581. offset,
  1582. skb_headlen(skb),
  1583. DMA_FROM_DEVICE);
  1584. } else {
  1585. struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
  1586. dma_sync_single_range_for_cpu(rx_ring->dev,
  1587. IXGBE_CB(skb)->dma,
  1588. frag->page_offset,
  1589. skb_frag_size(frag),
  1590. DMA_FROM_DEVICE);
  1591. }
  1592. }
  1593. /**
  1594. * ixgbe_cleanup_headers - Correct corrupted or empty headers
  1595. * @rx_ring: rx descriptor ring packet is being transacted on
  1596. * @rx_desc: pointer to the EOP Rx descriptor
  1597. * @skb: pointer to current skb being fixed
  1598. *
  1599. * Check if the skb is valid in the XDP case it will be an error pointer.
  1600. * Return true in this case to abort processing and advance to next
  1601. * descriptor.
  1602. *
  1603. * Check for corrupted packet headers caused by senders on the local L2
  1604. * embedded NIC switch not setting up their Tx Descriptors right. These
  1605. * should be very rare.
  1606. *
  1607. * Also address the case where we are pulling data in on pages only
  1608. * and as such no data is present in the skb header.
  1609. *
  1610. * In addition if skb is not at least 60 bytes we need to pad it so that
  1611. * it is large enough to qualify as a valid Ethernet frame.
  1612. *
  1613. * Returns true if an error was encountered and skb was freed.
  1614. **/
  1615. static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
  1616. union ixgbe_adv_rx_desc *rx_desc,
  1617. struct sk_buff *skb)
  1618. {
  1619. struct net_device *netdev = rx_ring->netdev;
  1620. /* XDP packets use error pointer so abort at this point */
  1621. if (IS_ERR(skb))
  1622. return true;
  1623. /* Verify netdev is present, and that packet does not have any
  1624. * errors that would be unacceptable to the netdev.
  1625. */
  1626. if (!netdev ||
  1627. (unlikely(ixgbe_test_staterr(rx_desc,
  1628. IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
  1629. !(netdev->features & NETIF_F_RXALL)))) {
  1630. dev_kfree_skb_any(skb);
  1631. return true;
  1632. }
  1633. /* place header in linear portion of buffer */
  1634. if (!skb_headlen(skb))
  1635. ixgbe_pull_tail(rx_ring, skb);
  1636. #ifdef IXGBE_FCOE
  1637. /* do not attempt to pad FCoE Frames as this will disrupt DDP */
  1638. if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
  1639. return false;
  1640. #endif
  1641. /* if eth_skb_pad returns an error the skb was freed */
  1642. if (eth_skb_pad(skb))
  1643. return true;
  1644. return false;
  1645. }
  1646. /**
  1647. * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
  1648. * @rx_ring: rx descriptor ring to store buffers on
  1649. * @old_buff: donor buffer to have page reused
  1650. *
  1651. * Synchronizes page for reuse by the adapter
  1652. **/
  1653. static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
  1654. struct ixgbe_rx_buffer *old_buff)
  1655. {
  1656. struct ixgbe_rx_buffer *new_buff;
  1657. u16 nta = rx_ring->next_to_alloc;
  1658. new_buff = &rx_ring->rx_buffer_info[nta];
  1659. /* update, and store next to alloc */
  1660. nta++;
  1661. rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
  1662. /* Transfer page from old buffer to new buffer.
  1663. * Move each member individually to avoid possible store
  1664. * forwarding stalls and unnecessary copy of skb.
  1665. */
  1666. new_buff->dma = old_buff->dma;
  1667. new_buff->page = old_buff->page;
  1668. new_buff->page_offset = old_buff->page_offset;
  1669. new_buff->pagecnt_bias = old_buff->pagecnt_bias;
  1670. }
  1671. static inline bool ixgbe_page_is_reserved(struct page *page)
  1672. {
  1673. return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page);
  1674. }
  1675. static bool ixgbe_can_reuse_rx_page(struct ixgbe_rx_buffer *rx_buffer)
  1676. {
  1677. unsigned int pagecnt_bias = rx_buffer->pagecnt_bias;
  1678. struct page *page = rx_buffer->page;
  1679. /* avoid re-using remote pages */
  1680. if (unlikely(ixgbe_page_is_reserved(page)))
  1681. return false;
  1682. #if (PAGE_SIZE < 8192)
  1683. /* if we are only owner of page we can reuse it */
  1684. if (unlikely((page_ref_count(page) - pagecnt_bias) > 1))
  1685. return false;
  1686. #else
  1687. /* The last offset is a bit aggressive in that we assume the
  1688. * worst case of FCoE being enabled and using a 3K buffer.
  1689. * However this should have minimal impact as the 1K extra is
  1690. * still less than one buffer in size.
  1691. */
  1692. #define IXGBE_LAST_OFFSET \
  1693. (SKB_WITH_OVERHEAD(PAGE_SIZE) - IXGBE_RXBUFFER_3K)
  1694. if (rx_buffer->page_offset > IXGBE_LAST_OFFSET)
  1695. return false;
  1696. #endif
  1697. /* If we have drained the page fragment pool we need to update
  1698. * the pagecnt_bias and page count so that we fully restock the
  1699. * number of references the driver holds.
  1700. */
  1701. if (unlikely(pagecnt_bias == 1)) {
  1702. page_ref_add(page, USHRT_MAX - 1);
  1703. rx_buffer->pagecnt_bias = USHRT_MAX;
  1704. }
  1705. return true;
  1706. }
  1707. /**
  1708. * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
  1709. * @rx_ring: rx descriptor ring to transact packets on
  1710. * @rx_buffer: buffer containing page to add
  1711. * @skb: sk_buff to place the data into
  1712. * @size: size of data in rx_buffer
  1713. *
  1714. * This function will add the data contained in rx_buffer->page to the skb.
  1715. * This is done either through a direct copy if the data in the buffer is
  1716. * less than the skb header size, otherwise it will just attach the page as
  1717. * a frag to the skb.
  1718. *
  1719. * The function will then update the page offset if necessary and return
  1720. * true if the buffer can be reused by the adapter.
  1721. **/
  1722. static void ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
  1723. struct ixgbe_rx_buffer *rx_buffer,
  1724. struct sk_buff *skb,
  1725. unsigned int size)
  1726. {
  1727. #if (PAGE_SIZE < 8192)
  1728. unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
  1729. #else
  1730. unsigned int truesize = ring_uses_build_skb(rx_ring) ?
  1731. SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) :
  1732. SKB_DATA_ALIGN(size);
  1733. #endif
  1734. skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page,
  1735. rx_buffer->page_offset, size, truesize);
  1736. #if (PAGE_SIZE < 8192)
  1737. rx_buffer->page_offset ^= truesize;
  1738. #else
  1739. rx_buffer->page_offset += truesize;
  1740. #endif
  1741. }
  1742. static struct ixgbe_rx_buffer *ixgbe_get_rx_buffer(struct ixgbe_ring *rx_ring,
  1743. union ixgbe_adv_rx_desc *rx_desc,
  1744. struct sk_buff **skb,
  1745. const unsigned int size)
  1746. {
  1747. struct ixgbe_rx_buffer *rx_buffer;
  1748. rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
  1749. prefetchw(rx_buffer->page);
  1750. *skb = rx_buffer->skb;
  1751. /* Delay unmapping of the first packet. It carries the header
  1752. * information, HW may still access the header after the writeback.
  1753. * Only unmap it when EOP is reached
  1754. */
  1755. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)) {
  1756. if (!*skb)
  1757. goto skip_sync;
  1758. } else {
  1759. if (*skb)
  1760. ixgbe_dma_sync_frag(rx_ring, *skb);
  1761. }
  1762. /* we are reusing so sync this buffer for CPU use */
  1763. dma_sync_single_range_for_cpu(rx_ring->dev,
  1764. rx_buffer->dma,
  1765. rx_buffer->page_offset,
  1766. size,
  1767. DMA_FROM_DEVICE);
  1768. skip_sync:
  1769. rx_buffer->pagecnt_bias--;
  1770. return rx_buffer;
  1771. }
  1772. static void ixgbe_put_rx_buffer(struct ixgbe_ring *rx_ring,
  1773. struct ixgbe_rx_buffer *rx_buffer,
  1774. struct sk_buff *skb)
  1775. {
  1776. if (ixgbe_can_reuse_rx_page(rx_buffer)) {
  1777. /* hand second half of page back to the ring */
  1778. ixgbe_reuse_rx_page(rx_ring, rx_buffer);
  1779. } else {
  1780. if (!IS_ERR(skb) && IXGBE_CB(skb)->dma == rx_buffer->dma) {
  1781. /* the page has been released from the ring */
  1782. IXGBE_CB(skb)->page_released = true;
  1783. } else {
  1784. /* we are not reusing the buffer so unmap it */
  1785. dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
  1786. ixgbe_rx_pg_size(rx_ring),
  1787. DMA_FROM_DEVICE,
  1788. IXGBE_RX_DMA_ATTR);
  1789. }
  1790. __page_frag_cache_drain(rx_buffer->page,
  1791. rx_buffer->pagecnt_bias);
  1792. }
  1793. /* clear contents of rx_buffer */
  1794. rx_buffer->page = NULL;
  1795. rx_buffer->skb = NULL;
  1796. }
  1797. static struct sk_buff *ixgbe_construct_skb(struct ixgbe_ring *rx_ring,
  1798. struct ixgbe_rx_buffer *rx_buffer,
  1799. struct xdp_buff *xdp,
  1800. union ixgbe_adv_rx_desc *rx_desc)
  1801. {
  1802. unsigned int size = xdp->data_end - xdp->data;
  1803. #if (PAGE_SIZE < 8192)
  1804. unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
  1805. #else
  1806. unsigned int truesize = SKB_DATA_ALIGN(xdp->data_end -
  1807. xdp->data_hard_start);
  1808. #endif
  1809. struct sk_buff *skb;
  1810. /* prefetch first cache line of first page */
  1811. prefetch(xdp->data);
  1812. #if L1_CACHE_BYTES < 128
  1813. prefetch(xdp->data + L1_CACHE_BYTES);
  1814. #endif
  1815. /* Note, we get here by enabling legacy-rx via:
  1816. *
  1817. * ethtool --set-priv-flags <dev> legacy-rx on
  1818. *
  1819. * In this mode, we currently get 0 extra XDP headroom as
  1820. * opposed to having legacy-rx off, where we process XDP
  1821. * packets going to stack via ixgbe_build_skb(). The latter
  1822. * provides us currently with 192 bytes of headroom.
  1823. *
  1824. * For ixgbe_construct_skb() mode it means that the
  1825. * xdp->data_meta will always point to xdp->data, since
  1826. * the helper cannot expand the head. Should this ever
  1827. * change in future for legacy-rx mode on, then lets also
  1828. * add xdp->data_meta handling here.
  1829. */
  1830. /* allocate a skb to store the frags */
  1831. skb = napi_alloc_skb(&rx_ring->q_vector->napi, IXGBE_RX_HDR_SIZE);
  1832. if (unlikely(!skb))
  1833. return NULL;
  1834. if (size > IXGBE_RX_HDR_SIZE) {
  1835. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
  1836. IXGBE_CB(skb)->dma = rx_buffer->dma;
  1837. skb_add_rx_frag(skb, 0, rx_buffer->page,
  1838. xdp->data - page_address(rx_buffer->page),
  1839. size, truesize);
  1840. #if (PAGE_SIZE < 8192)
  1841. rx_buffer->page_offset ^= truesize;
  1842. #else
  1843. rx_buffer->page_offset += truesize;
  1844. #endif
  1845. } else {
  1846. memcpy(__skb_put(skb, size),
  1847. xdp->data, ALIGN(size, sizeof(long)));
  1848. rx_buffer->pagecnt_bias++;
  1849. }
  1850. return skb;
  1851. }
  1852. static struct sk_buff *ixgbe_build_skb(struct ixgbe_ring *rx_ring,
  1853. struct ixgbe_rx_buffer *rx_buffer,
  1854. struct xdp_buff *xdp,
  1855. union ixgbe_adv_rx_desc *rx_desc)
  1856. {
  1857. unsigned int metasize = xdp->data - xdp->data_meta;
  1858. #if (PAGE_SIZE < 8192)
  1859. unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
  1860. #else
  1861. unsigned int truesize = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) +
  1862. SKB_DATA_ALIGN(xdp->data_end -
  1863. xdp->data_hard_start);
  1864. #endif
  1865. struct sk_buff *skb;
  1866. /* Prefetch first cache line of first page. If xdp->data_meta
  1867. * is unused, this points extactly as xdp->data, otherwise we
  1868. * likely have a consumer accessing first few bytes of meta
  1869. * data, and then actual data.
  1870. */
  1871. prefetch(xdp->data_meta);
  1872. #if L1_CACHE_BYTES < 128
  1873. prefetch(xdp->data_meta + L1_CACHE_BYTES);
  1874. #endif
  1875. /* build an skb to around the page buffer */
  1876. skb = build_skb(xdp->data_hard_start, truesize);
  1877. if (unlikely(!skb))
  1878. return NULL;
  1879. /* update pointers within the skb to store the data */
  1880. skb_reserve(skb, xdp->data - xdp->data_hard_start);
  1881. __skb_put(skb, xdp->data_end - xdp->data);
  1882. if (metasize)
  1883. skb_metadata_set(skb, metasize);
  1884. /* record DMA address if this is the start of a chain of buffers */
  1885. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
  1886. IXGBE_CB(skb)->dma = rx_buffer->dma;
  1887. /* update buffer offset */
  1888. #if (PAGE_SIZE < 8192)
  1889. rx_buffer->page_offset ^= truesize;
  1890. #else
  1891. rx_buffer->page_offset += truesize;
  1892. #endif
  1893. return skb;
  1894. }
  1895. #define IXGBE_XDP_PASS 0
  1896. #define IXGBE_XDP_CONSUMED 1
  1897. #define IXGBE_XDP_TX 2
  1898. static int ixgbe_xmit_xdp_ring(struct ixgbe_adapter *adapter,
  1899. struct xdp_frame *xdpf);
  1900. static struct sk_buff *ixgbe_run_xdp(struct ixgbe_adapter *adapter,
  1901. struct ixgbe_ring *rx_ring,
  1902. struct xdp_buff *xdp)
  1903. {
  1904. int err, result = IXGBE_XDP_PASS;
  1905. struct bpf_prog *xdp_prog;
  1906. struct xdp_frame *xdpf;
  1907. u32 act;
  1908. rcu_read_lock();
  1909. xdp_prog = READ_ONCE(rx_ring->xdp_prog);
  1910. if (!xdp_prog)
  1911. goto xdp_out;
  1912. prefetchw(xdp->data_hard_start); /* xdp_frame write */
  1913. act = bpf_prog_run_xdp(xdp_prog, xdp);
  1914. switch (act) {
  1915. case XDP_PASS:
  1916. break;
  1917. case XDP_TX:
  1918. xdpf = convert_to_xdp_frame(xdp);
  1919. if (unlikely(!xdpf)) {
  1920. result = IXGBE_XDP_CONSUMED;
  1921. break;
  1922. }
  1923. result = ixgbe_xmit_xdp_ring(adapter, xdpf);
  1924. break;
  1925. case XDP_REDIRECT:
  1926. err = xdp_do_redirect(adapter->netdev, xdp, xdp_prog);
  1927. if (!err)
  1928. result = IXGBE_XDP_TX;
  1929. else
  1930. result = IXGBE_XDP_CONSUMED;
  1931. break;
  1932. default:
  1933. bpf_warn_invalid_xdp_action(act);
  1934. /* fallthrough */
  1935. case XDP_ABORTED:
  1936. trace_xdp_exception(rx_ring->netdev, xdp_prog, act);
  1937. /* fallthrough -- handle aborts by dropping packet */
  1938. case XDP_DROP:
  1939. result = IXGBE_XDP_CONSUMED;
  1940. break;
  1941. }
  1942. xdp_out:
  1943. rcu_read_unlock();
  1944. return ERR_PTR(-result);
  1945. }
  1946. static void ixgbe_rx_buffer_flip(struct ixgbe_ring *rx_ring,
  1947. struct ixgbe_rx_buffer *rx_buffer,
  1948. unsigned int size)
  1949. {
  1950. #if (PAGE_SIZE < 8192)
  1951. unsigned int truesize = ixgbe_rx_pg_size(rx_ring) / 2;
  1952. rx_buffer->page_offset ^= truesize;
  1953. #else
  1954. unsigned int truesize = ring_uses_build_skb(rx_ring) ?
  1955. SKB_DATA_ALIGN(IXGBE_SKB_PAD + size) :
  1956. SKB_DATA_ALIGN(size);
  1957. rx_buffer->page_offset += truesize;
  1958. #endif
  1959. }
  1960. /**
  1961. * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
  1962. * @q_vector: structure containing interrupt and ring information
  1963. * @rx_ring: rx descriptor ring to transact packets on
  1964. * @budget: Total limit on number of packets to process
  1965. *
  1966. * This function provides a "bounce buffer" approach to Rx interrupt
  1967. * processing. The advantage to this is that on systems that have
  1968. * expensive overhead for IOMMU access this provides a means of avoiding
  1969. * it by maintaining the mapping of the page to the syste.
  1970. *
  1971. * Returns amount of work completed
  1972. **/
  1973. static int ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
  1974. struct ixgbe_ring *rx_ring,
  1975. const int budget)
  1976. {
  1977. unsigned int total_rx_bytes = 0, total_rx_packets = 0;
  1978. struct ixgbe_adapter *adapter = q_vector->adapter;
  1979. #ifdef IXGBE_FCOE
  1980. int ddp_bytes;
  1981. unsigned int mss = 0;
  1982. #endif /* IXGBE_FCOE */
  1983. u16 cleaned_count = ixgbe_desc_unused(rx_ring);
  1984. bool xdp_xmit = false;
  1985. struct xdp_buff xdp;
  1986. xdp.rxq = &rx_ring->xdp_rxq;
  1987. while (likely(total_rx_packets < budget)) {
  1988. union ixgbe_adv_rx_desc *rx_desc;
  1989. struct ixgbe_rx_buffer *rx_buffer;
  1990. struct sk_buff *skb;
  1991. unsigned int size;
  1992. /* return some buffers to hardware, one at a time is too slow */
  1993. if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
  1994. ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
  1995. cleaned_count = 0;
  1996. }
  1997. rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
  1998. size = le16_to_cpu(rx_desc->wb.upper.length);
  1999. if (!size)
  2000. break;
  2001. /* This memory barrier is needed to keep us from reading
  2002. * any other fields out of the rx_desc until we know the
  2003. * descriptor has been written back
  2004. */
  2005. dma_rmb();
  2006. rx_buffer = ixgbe_get_rx_buffer(rx_ring, rx_desc, &skb, size);
  2007. /* retrieve a buffer from the ring */
  2008. if (!skb) {
  2009. xdp.data = page_address(rx_buffer->page) +
  2010. rx_buffer->page_offset;
  2011. xdp.data_meta = xdp.data;
  2012. xdp.data_hard_start = xdp.data -
  2013. ixgbe_rx_offset(rx_ring);
  2014. xdp.data_end = xdp.data + size;
  2015. skb = ixgbe_run_xdp(adapter, rx_ring, &xdp);
  2016. }
  2017. if (IS_ERR(skb)) {
  2018. if (PTR_ERR(skb) == -IXGBE_XDP_TX) {
  2019. xdp_xmit = true;
  2020. ixgbe_rx_buffer_flip(rx_ring, rx_buffer, size);
  2021. } else {
  2022. rx_buffer->pagecnt_bias++;
  2023. }
  2024. total_rx_packets++;
  2025. total_rx_bytes += size;
  2026. } else if (skb) {
  2027. ixgbe_add_rx_frag(rx_ring, rx_buffer, skb, size);
  2028. } else if (ring_uses_build_skb(rx_ring)) {
  2029. skb = ixgbe_build_skb(rx_ring, rx_buffer,
  2030. &xdp, rx_desc);
  2031. } else {
  2032. skb = ixgbe_construct_skb(rx_ring, rx_buffer,
  2033. &xdp, rx_desc);
  2034. }
  2035. /* exit if we failed to retrieve a buffer */
  2036. if (!skb) {
  2037. rx_ring->rx_stats.alloc_rx_buff_failed++;
  2038. rx_buffer->pagecnt_bias++;
  2039. break;
  2040. }
  2041. ixgbe_put_rx_buffer(rx_ring, rx_buffer, skb);
  2042. cleaned_count++;
  2043. /* place incomplete frames back on ring for completion */
  2044. if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
  2045. continue;
  2046. /* verify the packet layout is correct */
  2047. if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
  2048. continue;
  2049. /* probably a little skewed due to removing CRC */
  2050. total_rx_bytes += skb->len;
  2051. /* populate checksum, timestamp, VLAN, and protocol */
  2052. ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
  2053. #ifdef IXGBE_FCOE
  2054. /* if ddp, not passing to ULD unless for FCP_RSP or error */
  2055. if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
  2056. ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
  2057. /* include DDPed FCoE data */
  2058. if (ddp_bytes > 0) {
  2059. if (!mss) {
  2060. mss = rx_ring->netdev->mtu -
  2061. sizeof(struct fcoe_hdr) -
  2062. sizeof(struct fc_frame_header) -
  2063. sizeof(struct fcoe_crc_eof);
  2064. if (mss > 512)
  2065. mss &= ~511;
  2066. }
  2067. total_rx_bytes += ddp_bytes;
  2068. total_rx_packets += DIV_ROUND_UP(ddp_bytes,
  2069. mss);
  2070. }
  2071. if (!ddp_bytes) {
  2072. dev_kfree_skb_any(skb);
  2073. continue;
  2074. }
  2075. }
  2076. #endif /* IXGBE_FCOE */
  2077. ixgbe_rx_skb(q_vector, skb);
  2078. /* update budget accounting */
  2079. total_rx_packets++;
  2080. }
  2081. if (xdp_xmit) {
  2082. struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()];
  2083. /* Force memory writes to complete before letting h/w
  2084. * know there are new descriptors to fetch.
  2085. */
  2086. wmb();
  2087. writel(ring->next_to_use, ring->tail);
  2088. xdp_do_flush_map();
  2089. }
  2090. u64_stats_update_begin(&rx_ring->syncp);
  2091. rx_ring->stats.packets += total_rx_packets;
  2092. rx_ring->stats.bytes += total_rx_bytes;
  2093. u64_stats_update_end(&rx_ring->syncp);
  2094. q_vector->rx.total_packets += total_rx_packets;
  2095. q_vector->rx.total_bytes += total_rx_bytes;
  2096. return total_rx_packets;
  2097. }
  2098. /**
  2099. * ixgbe_configure_msix - Configure MSI-X hardware
  2100. * @adapter: board private structure
  2101. *
  2102. * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
  2103. * interrupts.
  2104. **/
  2105. static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
  2106. {
  2107. struct ixgbe_q_vector *q_vector;
  2108. int v_idx;
  2109. u32 mask;
  2110. /* Populate MSIX to EITR Select */
  2111. if (adapter->num_vfs > 32) {
  2112. u32 eitrsel = BIT(adapter->num_vfs - 32) - 1;
  2113. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
  2114. }
  2115. /*
  2116. * Populate the IVAR table and set the ITR values to the
  2117. * corresponding register.
  2118. */
  2119. for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
  2120. struct ixgbe_ring *ring;
  2121. q_vector = adapter->q_vector[v_idx];
  2122. ixgbe_for_each_ring(ring, q_vector->rx)
  2123. ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
  2124. ixgbe_for_each_ring(ring, q_vector->tx)
  2125. ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
  2126. ixgbe_write_eitr(q_vector);
  2127. }
  2128. switch (adapter->hw.mac.type) {
  2129. case ixgbe_mac_82598EB:
  2130. ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
  2131. v_idx);
  2132. break;
  2133. case ixgbe_mac_82599EB:
  2134. case ixgbe_mac_X540:
  2135. case ixgbe_mac_X550:
  2136. case ixgbe_mac_X550EM_x:
  2137. case ixgbe_mac_x550em_a:
  2138. ixgbe_set_ivar(adapter, -1, 1, v_idx);
  2139. break;
  2140. default:
  2141. break;
  2142. }
  2143. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
  2144. /* set up to autoclear timer, and the vectors */
  2145. mask = IXGBE_EIMS_ENABLE_MASK;
  2146. mask &= ~(IXGBE_EIMS_OTHER |
  2147. IXGBE_EIMS_MAILBOX |
  2148. IXGBE_EIMS_LSC);
  2149. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
  2150. }
  2151. /**
  2152. * ixgbe_update_itr - update the dynamic ITR value based on statistics
  2153. * @q_vector: structure containing interrupt and ring information
  2154. * @ring_container: structure containing ring performance data
  2155. *
  2156. * Stores a new ITR value based on packets and byte
  2157. * counts during the last interrupt. The advantage of per interrupt
  2158. * computation is faster updates and more accurate ITR for the current
  2159. * traffic pattern. Constants in this function were computed
  2160. * based on theoretical maximum wire speed and thresholds were set based
  2161. * on testing data as well as attempting to minimize response time
  2162. * while increasing bulk throughput.
  2163. **/
  2164. static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
  2165. struct ixgbe_ring_container *ring_container)
  2166. {
  2167. unsigned int itr = IXGBE_ITR_ADAPTIVE_MIN_USECS |
  2168. IXGBE_ITR_ADAPTIVE_LATENCY;
  2169. unsigned int avg_wire_size, packets, bytes;
  2170. unsigned long next_update = jiffies;
  2171. /* If we don't have any rings just leave ourselves set for maximum
  2172. * possible latency so we take ourselves out of the equation.
  2173. */
  2174. if (!ring_container->ring)
  2175. return;
  2176. /* If we didn't update within up to 1 - 2 jiffies we can assume
  2177. * that either packets are coming in so slow there hasn't been
  2178. * any work, or that there is so much work that NAPI is dealing
  2179. * with interrupt moderation and we don't need to do anything.
  2180. */
  2181. if (time_after(next_update, ring_container->next_update))
  2182. goto clear_counts;
  2183. packets = ring_container->total_packets;
  2184. /* We have no packets to actually measure against. This means
  2185. * either one of the other queues on this vector is active or
  2186. * we are a Tx queue doing TSO with too high of an interrupt rate.
  2187. *
  2188. * When this occurs just tick up our delay by the minimum value
  2189. * and hope that this extra delay will prevent us from being called
  2190. * without any work on our queue.
  2191. */
  2192. if (!packets) {
  2193. itr = (q_vector->itr >> 2) + IXGBE_ITR_ADAPTIVE_MIN_INC;
  2194. if (itr > IXGBE_ITR_ADAPTIVE_MAX_USECS)
  2195. itr = IXGBE_ITR_ADAPTIVE_MAX_USECS;
  2196. itr += ring_container->itr & IXGBE_ITR_ADAPTIVE_LATENCY;
  2197. goto clear_counts;
  2198. }
  2199. bytes = ring_container->total_bytes;
  2200. /* If packets are less than 4 or bytes are less than 9000 assume
  2201. * insufficient data to use bulk rate limiting approach. We are
  2202. * likely latency driven.
  2203. */
  2204. if (packets < 4 && bytes < 9000) {
  2205. itr = IXGBE_ITR_ADAPTIVE_LATENCY;
  2206. goto adjust_by_size;
  2207. }
  2208. /* Between 4 and 48 we can assume that our current interrupt delay
  2209. * is only slightly too low. As such we should increase it by a small
  2210. * fixed amount.
  2211. */
  2212. if (packets < 48) {
  2213. itr = (q_vector->itr >> 2) + IXGBE_ITR_ADAPTIVE_MIN_INC;
  2214. if (itr > IXGBE_ITR_ADAPTIVE_MAX_USECS)
  2215. itr = IXGBE_ITR_ADAPTIVE_MAX_USECS;
  2216. goto clear_counts;
  2217. }
  2218. /* Between 48 and 96 is our "goldilocks" zone where we are working
  2219. * out "just right". Just report that our current ITR is good for us.
  2220. */
  2221. if (packets < 96) {
  2222. itr = q_vector->itr >> 2;
  2223. goto clear_counts;
  2224. }
  2225. /* If packet count is 96 or greater we are likely looking at a slight
  2226. * overrun of the delay we want. Try halving our delay to see if that
  2227. * will cut the number of packets in half per interrupt.
  2228. */
  2229. if (packets < 256) {
  2230. itr = q_vector->itr >> 3;
  2231. if (itr < IXGBE_ITR_ADAPTIVE_MIN_USECS)
  2232. itr = IXGBE_ITR_ADAPTIVE_MIN_USECS;
  2233. goto clear_counts;
  2234. }
  2235. /* The paths below assume we are dealing with a bulk ITR since number
  2236. * of packets is 256 or greater. We are just going to have to compute
  2237. * a value and try to bring the count under control, though for smaller
  2238. * packet sizes there isn't much we can do as NAPI polling will likely
  2239. * be kicking in sooner rather than later.
  2240. */
  2241. itr = IXGBE_ITR_ADAPTIVE_BULK;
  2242. adjust_by_size:
  2243. /* If packet counts are 256 or greater we can assume we have a gross
  2244. * overestimation of what the rate should be. Instead of trying to fine
  2245. * tune it just use the formula below to try and dial in an exact value
  2246. * give the current packet size of the frame.
  2247. */
  2248. avg_wire_size = bytes / packets;
  2249. /* The following is a crude approximation of:
  2250. * wmem_default / (size + overhead) = desired_pkts_per_int
  2251. * rate / bits_per_byte / (size + ethernet overhead) = pkt_rate
  2252. * (desired_pkt_rate / pkt_rate) * usecs_per_sec = ITR value
  2253. *
  2254. * Assuming wmem_default is 212992 and overhead is 640 bytes per
  2255. * packet, (256 skb, 64 headroom, 320 shared info), we can reduce the
  2256. * formula down to
  2257. *
  2258. * (170 * (size + 24)) / (size + 640) = ITR
  2259. *
  2260. * We first do some math on the packet size and then finally bitshift
  2261. * by 8 after rounding up. We also have to account for PCIe link speed
  2262. * difference as ITR scales based on this.
  2263. */
  2264. if (avg_wire_size <= 60) {
  2265. /* Start at 50k ints/sec */
  2266. avg_wire_size = 5120;
  2267. } else if (avg_wire_size <= 316) {
  2268. /* 50K ints/sec to 16K ints/sec */
  2269. avg_wire_size *= 40;
  2270. avg_wire_size += 2720;
  2271. } else if (avg_wire_size <= 1084) {
  2272. /* 16K ints/sec to 9.2K ints/sec */
  2273. avg_wire_size *= 15;
  2274. avg_wire_size += 11452;
  2275. } else if (avg_wire_size <= 1980) {
  2276. /* 9.2K ints/sec to 8K ints/sec */
  2277. avg_wire_size *= 5;
  2278. avg_wire_size += 22420;
  2279. } else {
  2280. /* plateau at a limit of 8K ints/sec */
  2281. avg_wire_size = 32256;
  2282. }
  2283. /* If we are in low latency mode half our delay which doubles the rate
  2284. * to somewhere between 100K to 16K ints/sec
  2285. */
  2286. if (itr & IXGBE_ITR_ADAPTIVE_LATENCY)
  2287. avg_wire_size >>= 1;
  2288. /* Resultant value is 256 times larger than it needs to be. This
  2289. * gives us room to adjust the value as needed to either increase
  2290. * or decrease the value based on link speeds of 10G, 2.5G, 1G, etc.
  2291. *
  2292. * Use addition as we have already recorded the new latency flag
  2293. * for the ITR value.
  2294. */
  2295. switch (q_vector->adapter->link_speed) {
  2296. case IXGBE_LINK_SPEED_10GB_FULL:
  2297. case IXGBE_LINK_SPEED_100_FULL:
  2298. default:
  2299. itr += DIV_ROUND_UP(avg_wire_size,
  2300. IXGBE_ITR_ADAPTIVE_MIN_INC * 256) *
  2301. IXGBE_ITR_ADAPTIVE_MIN_INC;
  2302. break;
  2303. case IXGBE_LINK_SPEED_2_5GB_FULL:
  2304. case IXGBE_LINK_SPEED_1GB_FULL:
  2305. case IXGBE_LINK_SPEED_10_FULL:
  2306. itr += DIV_ROUND_UP(avg_wire_size,
  2307. IXGBE_ITR_ADAPTIVE_MIN_INC * 64) *
  2308. IXGBE_ITR_ADAPTIVE_MIN_INC;
  2309. break;
  2310. }
  2311. clear_counts:
  2312. /* write back value */
  2313. ring_container->itr = itr;
  2314. /* next update should occur within next jiffy */
  2315. ring_container->next_update = next_update + 1;
  2316. ring_container->total_bytes = 0;
  2317. ring_container->total_packets = 0;
  2318. }
  2319. /**
  2320. * ixgbe_write_eitr - write EITR register in hardware specific way
  2321. * @q_vector: structure containing interrupt and ring information
  2322. *
  2323. * This function is made to be called by ethtool and by the driver
  2324. * when it needs to update EITR registers at runtime. Hardware
  2325. * specific quirks/differences are taken care of here.
  2326. */
  2327. void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
  2328. {
  2329. struct ixgbe_adapter *adapter = q_vector->adapter;
  2330. struct ixgbe_hw *hw = &adapter->hw;
  2331. int v_idx = q_vector->v_idx;
  2332. u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
  2333. switch (adapter->hw.mac.type) {
  2334. case ixgbe_mac_82598EB:
  2335. /* must write high and low 16 bits to reset counter */
  2336. itr_reg |= (itr_reg << 16);
  2337. break;
  2338. case ixgbe_mac_82599EB:
  2339. case ixgbe_mac_X540:
  2340. case ixgbe_mac_X550:
  2341. case ixgbe_mac_X550EM_x:
  2342. case ixgbe_mac_x550em_a:
  2343. /*
  2344. * set the WDIS bit to not clear the timer bits and cause an
  2345. * immediate assertion of the interrupt
  2346. */
  2347. itr_reg |= IXGBE_EITR_CNT_WDIS;
  2348. break;
  2349. default:
  2350. break;
  2351. }
  2352. IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
  2353. }
  2354. static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
  2355. {
  2356. u32 new_itr;
  2357. ixgbe_update_itr(q_vector, &q_vector->tx);
  2358. ixgbe_update_itr(q_vector, &q_vector->rx);
  2359. /* use the smallest value of new ITR delay calculations */
  2360. new_itr = min(q_vector->rx.itr, q_vector->tx.itr);
  2361. /* Clear latency flag if set, shift into correct position */
  2362. new_itr &= ~IXGBE_ITR_ADAPTIVE_LATENCY;
  2363. new_itr <<= 2;
  2364. if (new_itr != q_vector->itr) {
  2365. /* save the algorithm value here */
  2366. q_vector->itr = new_itr;
  2367. ixgbe_write_eitr(q_vector);
  2368. }
  2369. }
  2370. /**
  2371. * ixgbe_check_overtemp_subtask - check for over temperature
  2372. * @adapter: pointer to adapter
  2373. **/
  2374. static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
  2375. {
  2376. struct ixgbe_hw *hw = &adapter->hw;
  2377. u32 eicr = adapter->interrupt_event;
  2378. s32 rc;
  2379. if (test_bit(__IXGBE_DOWN, &adapter->state))
  2380. return;
  2381. if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
  2382. return;
  2383. adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
  2384. switch (hw->device_id) {
  2385. case IXGBE_DEV_ID_82599_T3_LOM:
  2386. /*
  2387. * Since the warning interrupt is for both ports
  2388. * we don't have to check if:
  2389. * - This interrupt wasn't for our port.
  2390. * - We may have missed the interrupt so always have to
  2391. * check if we got a LSC
  2392. */
  2393. if (!(eicr & IXGBE_EICR_GPI_SDP0_8259X) &&
  2394. !(eicr & IXGBE_EICR_LSC))
  2395. return;
  2396. if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
  2397. u32 speed;
  2398. bool link_up = false;
  2399. hw->mac.ops.check_link(hw, &speed, &link_up, false);
  2400. if (link_up)
  2401. return;
  2402. }
  2403. /* Check if this is not due to overtemp */
  2404. if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
  2405. return;
  2406. break;
  2407. case IXGBE_DEV_ID_X550EM_A_1G_T:
  2408. case IXGBE_DEV_ID_X550EM_A_1G_T_L:
  2409. rc = hw->phy.ops.check_overtemp(hw);
  2410. if (rc != IXGBE_ERR_OVERTEMP)
  2411. return;
  2412. break;
  2413. default:
  2414. if (adapter->hw.mac.type >= ixgbe_mac_X540)
  2415. return;
  2416. if (!(eicr & IXGBE_EICR_GPI_SDP0(hw)))
  2417. return;
  2418. break;
  2419. }
  2420. e_crit(drv, "%s\n", ixgbe_overheat_msg);
  2421. adapter->interrupt_event = 0;
  2422. }
  2423. static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
  2424. {
  2425. struct ixgbe_hw *hw = &adapter->hw;
  2426. if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
  2427. (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
  2428. e_crit(probe, "Fan has stopped, replace the adapter\n");
  2429. /* write to clear the interrupt */
  2430. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
  2431. }
  2432. }
  2433. static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
  2434. {
  2435. struct ixgbe_hw *hw = &adapter->hw;
  2436. if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
  2437. return;
  2438. switch (adapter->hw.mac.type) {
  2439. case ixgbe_mac_82599EB:
  2440. /*
  2441. * Need to check link state so complete overtemp check
  2442. * on service task
  2443. */
  2444. if (((eicr & IXGBE_EICR_GPI_SDP0(hw)) ||
  2445. (eicr & IXGBE_EICR_LSC)) &&
  2446. (!test_bit(__IXGBE_DOWN, &adapter->state))) {
  2447. adapter->interrupt_event = eicr;
  2448. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
  2449. ixgbe_service_event_schedule(adapter);
  2450. return;
  2451. }
  2452. return;
  2453. case ixgbe_mac_x550em_a:
  2454. if (eicr & IXGBE_EICR_GPI_SDP0_X550EM_a) {
  2455. adapter->interrupt_event = eicr;
  2456. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
  2457. ixgbe_service_event_schedule(adapter);
  2458. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC,
  2459. IXGBE_EICR_GPI_SDP0_X550EM_a);
  2460. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICR,
  2461. IXGBE_EICR_GPI_SDP0_X550EM_a);
  2462. }
  2463. return;
  2464. case ixgbe_mac_X550:
  2465. case ixgbe_mac_X540:
  2466. if (!(eicr & IXGBE_EICR_TS))
  2467. return;
  2468. break;
  2469. default:
  2470. return;
  2471. }
  2472. e_crit(drv, "%s\n", ixgbe_overheat_msg);
  2473. }
  2474. static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
  2475. {
  2476. switch (hw->mac.type) {
  2477. case ixgbe_mac_82598EB:
  2478. if (hw->phy.type == ixgbe_phy_nl)
  2479. return true;
  2480. return false;
  2481. case ixgbe_mac_82599EB:
  2482. case ixgbe_mac_X550EM_x:
  2483. case ixgbe_mac_x550em_a:
  2484. switch (hw->mac.ops.get_media_type(hw)) {
  2485. case ixgbe_media_type_fiber:
  2486. case ixgbe_media_type_fiber_qsfp:
  2487. return true;
  2488. default:
  2489. return false;
  2490. }
  2491. default:
  2492. return false;
  2493. }
  2494. }
  2495. static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
  2496. {
  2497. struct ixgbe_hw *hw = &adapter->hw;
  2498. u32 eicr_mask = IXGBE_EICR_GPI_SDP2(hw);
  2499. if (!ixgbe_is_sfp(hw))
  2500. return;
  2501. /* Later MAC's use different SDP */
  2502. if (hw->mac.type >= ixgbe_mac_X540)
  2503. eicr_mask = IXGBE_EICR_GPI_SDP0_X540;
  2504. if (eicr & eicr_mask) {
  2505. /* Clear the interrupt */
  2506. IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr_mask);
  2507. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  2508. adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
  2509. adapter->sfp_poll_time = 0;
  2510. ixgbe_service_event_schedule(adapter);
  2511. }
  2512. }
  2513. if (adapter->hw.mac.type == ixgbe_mac_82599EB &&
  2514. (eicr & IXGBE_EICR_GPI_SDP1(hw))) {
  2515. /* Clear the interrupt */
  2516. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1(hw));
  2517. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  2518. adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
  2519. ixgbe_service_event_schedule(adapter);
  2520. }
  2521. }
  2522. }
  2523. static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
  2524. {
  2525. struct ixgbe_hw *hw = &adapter->hw;
  2526. adapter->lsc_int++;
  2527. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  2528. adapter->link_check_timeout = jiffies;
  2529. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  2530. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
  2531. IXGBE_WRITE_FLUSH(hw);
  2532. ixgbe_service_event_schedule(adapter);
  2533. }
  2534. }
  2535. static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
  2536. u64 qmask)
  2537. {
  2538. u32 mask;
  2539. struct ixgbe_hw *hw = &adapter->hw;
  2540. switch (hw->mac.type) {
  2541. case ixgbe_mac_82598EB:
  2542. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  2543. IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
  2544. break;
  2545. case ixgbe_mac_82599EB:
  2546. case ixgbe_mac_X540:
  2547. case ixgbe_mac_X550:
  2548. case ixgbe_mac_X550EM_x:
  2549. case ixgbe_mac_x550em_a:
  2550. mask = (qmask & 0xFFFFFFFF);
  2551. if (mask)
  2552. IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
  2553. mask = (qmask >> 32);
  2554. if (mask)
  2555. IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
  2556. break;
  2557. default:
  2558. break;
  2559. }
  2560. /* skip the flush */
  2561. }
  2562. static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
  2563. u64 qmask)
  2564. {
  2565. u32 mask;
  2566. struct ixgbe_hw *hw = &adapter->hw;
  2567. switch (hw->mac.type) {
  2568. case ixgbe_mac_82598EB:
  2569. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  2570. IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
  2571. break;
  2572. case ixgbe_mac_82599EB:
  2573. case ixgbe_mac_X540:
  2574. case ixgbe_mac_X550:
  2575. case ixgbe_mac_X550EM_x:
  2576. case ixgbe_mac_x550em_a:
  2577. mask = (qmask & 0xFFFFFFFF);
  2578. if (mask)
  2579. IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
  2580. mask = (qmask >> 32);
  2581. if (mask)
  2582. IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
  2583. break;
  2584. default:
  2585. break;
  2586. }
  2587. /* skip the flush */
  2588. }
  2589. /**
  2590. * ixgbe_irq_enable - Enable default interrupt generation settings
  2591. * @adapter: board private structure
  2592. * @queues: enable irqs for queues
  2593. * @flush: flush register write
  2594. **/
  2595. static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
  2596. bool flush)
  2597. {
  2598. struct ixgbe_hw *hw = &adapter->hw;
  2599. u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
  2600. /* don't reenable LSC while waiting for link */
  2601. if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
  2602. mask &= ~IXGBE_EIMS_LSC;
  2603. if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
  2604. switch (adapter->hw.mac.type) {
  2605. case ixgbe_mac_82599EB:
  2606. mask |= IXGBE_EIMS_GPI_SDP0(hw);
  2607. break;
  2608. case ixgbe_mac_X540:
  2609. case ixgbe_mac_X550:
  2610. case ixgbe_mac_X550EM_x:
  2611. case ixgbe_mac_x550em_a:
  2612. mask |= IXGBE_EIMS_TS;
  2613. break;
  2614. default:
  2615. break;
  2616. }
  2617. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
  2618. mask |= IXGBE_EIMS_GPI_SDP1(hw);
  2619. switch (adapter->hw.mac.type) {
  2620. case ixgbe_mac_82599EB:
  2621. mask |= IXGBE_EIMS_GPI_SDP1(hw);
  2622. mask |= IXGBE_EIMS_GPI_SDP2(hw);
  2623. /* fall through */
  2624. case ixgbe_mac_X540:
  2625. case ixgbe_mac_X550:
  2626. case ixgbe_mac_X550EM_x:
  2627. case ixgbe_mac_x550em_a:
  2628. if (adapter->hw.device_id == IXGBE_DEV_ID_X550EM_X_SFP ||
  2629. adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP ||
  2630. adapter->hw.device_id == IXGBE_DEV_ID_X550EM_A_SFP_N)
  2631. mask |= IXGBE_EIMS_GPI_SDP0(&adapter->hw);
  2632. if (adapter->hw.phy.type == ixgbe_phy_x550em_ext_t)
  2633. mask |= IXGBE_EICR_GPI_SDP0_X540;
  2634. mask |= IXGBE_EIMS_ECC;
  2635. mask |= IXGBE_EIMS_MAILBOX;
  2636. break;
  2637. default:
  2638. break;
  2639. }
  2640. if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
  2641. !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
  2642. mask |= IXGBE_EIMS_FLOW_DIR;
  2643. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
  2644. if (queues)
  2645. ixgbe_irq_enable_queues(adapter, ~0);
  2646. if (flush)
  2647. IXGBE_WRITE_FLUSH(&adapter->hw);
  2648. }
  2649. static irqreturn_t ixgbe_msix_other(int irq, void *data)
  2650. {
  2651. struct ixgbe_adapter *adapter = data;
  2652. struct ixgbe_hw *hw = &adapter->hw;
  2653. u32 eicr;
  2654. /*
  2655. * Workaround for Silicon errata. Use clear-by-write instead
  2656. * of clear-by-read. Reading with EICS will return the
  2657. * interrupt causes without clearing, which later be done
  2658. * with the write to EICR.
  2659. */
  2660. eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
  2661. /* The lower 16bits of the EICR register are for the queue interrupts
  2662. * which should be masked here in order to not accidentally clear them if
  2663. * the bits are high when ixgbe_msix_other is called. There is a race
  2664. * condition otherwise which results in possible performance loss
  2665. * especially if the ixgbe_msix_other interrupt is triggering
  2666. * consistently (as it would when PPS is turned on for the X540 device)
  2667. */
  2668. eicr &= 0xFFFF0000;
  2669. IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
  2670. if (eicr & IXGBE_EICR_LSC)
  2671. ixgbe_check_lsc(adapter);
  2672. if (eicr & IXGBE_EICR_MAILBOX)
  2673. ixgbe_msg_task(adapter);
  2674. switch (hw->mac.type) {
  2675. case ixgbe_mac_82599EB:
  2676. case ixgbe_mac_X540:
  2677. case ixgbe_mac_X550:
  2678. case ixgbe_mac_X550EM_x:
  2679. case ixgbe_mac_x550em_a:
  2680. if (hw->phy.type == ixgbe_phy_x550em_ext_t &&
  2681. (eicr & IXGBE_EICR_GPI_SDP0_X540)) {
  2682. adapter->flags2 |= IXGBE_FLAG2_PHY_INTERRUPT;
  2683. ixgbe_service_event_schedule(adapter);
  2684. IXGBE_WRITE_REG(hw, IXGBE_EICR,
  2685. IXGBE_EICR_GPI_SDP0_X540);
  2686. }
  2687. if (eicr & IXGBE_EICR_ECC) {
  2688. e_info(link, "Received ECC Err, initiating reset\n");
  2689. set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  2690. ixgbe_service_event_schedule(adapter);
  2691. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
  2692. }
  2693. /* Handle Flow Director Full threshold interrupt */
  2694. if (eicr & IXGBE_EICR_FLOW_DIR) {
  2695. int reinit_count = 0;
  2696. int i;
  2697. for (i = 0; i < adapter->num_tx_queues; i++) {
  2698. struct ixgbe_ring *ring = adapter->tx_ring[i];
  2699. if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
  2700. &ring->state))
  2701. reinit_count++;
  2702. }
  2703. if (reinit_count) {
  2704. /* no more flow director interrupts until after init */
  2705. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
  2706. adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
  2707. ixgbe_service_event_schedule(adapter);
  2708. }
  2709. }
  2710. ixgbe_check_sfp_event(adapter, eicr);
  2711. ixgbe_check_overtemp_event(adapter, eicr);
  2712. break;
  2713. default:
  2714. break;
  2715. }
  2716. ixgbe_check_fan_failure(adapter, eicr);
  2717. if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
  2718. ixgbe_ptp_check_pps_event(adapter);
  2719. /* re-enable the original interrupt state, no lsc, no queues */
  2720. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2721. ixgbe_irq_enable(adapter, false, false);
  2722. return IRQ_HANDLED;
  2723. }
  2724. static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
  2725. {
  2726. struct ixgbe_q_vector *q_vector = data;
  2727. /* EIAM disabled interrupts (on this vector) for us */
  2728. if (q_vector->rx.ring || q_vector->tx.ring)
  2729. napi_schedule_irqoff(&q_vector->napi);
  2730. return IRQ_HANDLED;
  2731. }
  2732. /**
  2733. * ixgbe_poll - NAPI Rx polling callback
  2734. * @napi: structure for representing this polling device
  2735. * @budget: how many packets driver is allowed to clean
  2736. *
  2737. * This function is used for legacy and MSI, NAPI mode
  2738. **/
  2739. int ixgbe_poll(struct napi_struct *napi, int budget)
  2740. {
  2741. struct ixgbe_q_vector *q_vector =
  2742. container_of(napi, struct ixgbe_q_vector, napi);
  2743. struct ixgbe_adapter *adapter = q_vector->adapter;
  2744. struct ixgbe_ring *ring;
  2745. int per_ring_budget, work_done = 0;
  2746. bool clean_complete = true;
  2747. #ifdef CONFIG_IXGBE_DCA
  2748. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  2749. ixgbe_update_dca(q_vector);
  2750. #endif
  2751. ixgbe_for_each_ring(ring, q_vector->tx) {
  2752. if (!ixgbe_clean_tx_irq(q_vector, ring, budget))
  2753. clean_complete = false;
  2754. }
  2755. /* Exit if we are called by netpoll */
  2756. if (budget <= 0)
  2757. return budget;
  2758. /* attempt to distribute budget to each queue fairly, but don't allow
  2759. * the budget to go below 1 because we'll exit polling */
  2760. if (q_vector->rx.count > 1)
  2761. per_ring_budget = max(budget/q_vector->rx.count, 1);
  2762. else
  2763. per_ring_budget = budget;
  2764. ixgbe_for_each_ring(ring, q_vector->rx) {
  2765. int cleaned = ixgbe_clean_rx_irq(q_vector, ring,
  2766. per_ring_budget);
  2767. work_done += cleaned;
  2768. if (cleaned >= per_ring_budget)
  2769. clean_complete = false;
  2770. }
  2771. /* If all work not completed, return budget and keep polling */
  2772. if (!clean_complete)
  2773. return budget;
  2774. /* all work done, exit the polling mode */
  2775. napi_complete_done(napi, work_done);
  2776. if (adapter->rx_itr_setting & 1)
  2777. ixgbe_set_itr(q_vector);
  2778. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2779. ixgbe_irq_enable_queues(adapter, BIT_ULL(q_vector->v_idx));
  2780. return min(work_done, budget - 1);
  2781. }
  2782. /**
  2783. * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
  2784. * @adapter: board private structure
  2785. *
  2786. * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
  2787. * interrupts from the kernel.
  2788. **/
  2789. static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
  2790. {
  2791. struct net_device *netdev = adapter->netdev;
  2792. unsigned int ri = 0, ti = 0;
  2793. int vector, err;
  2794. for (vector = 0; vector < adapter->num_q_vectors; vector++) {
  2795. struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
  2796. struct msix_entry *entry = &adapter->msix_entries[vector];
  2797. if (q_vector->tx.ring && q_vector->rx.ring) {
  2798. snprintf(q_vector->name, sizeof(q_vector->name),
  2799. "%s-TxRx-%u", netdev->name, ri++);
  2800. ti++;
  2801. } else if (q_vector->rx.ring) {
  2802. snprintf(q_vector->name, sizeof(q_vector->name),
  2803. "%s-rx-%u", netdev->name, ri++);
  2804. } else if (q_vector->tx.ring) {
  2805. snprintf(q_vector->name, sizeof(q_vector->name),
  2806. "%s-tx-%u", netdev->name, ti++);
  2807. } else {
  2808. /* skip this unused q_vector */
  2809. continue;
  2810. }
  2811. err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
  2812. q_vector->name, q_vector);
  2813. if (err) {
  2814. e_err(probe, "request_irq failed for MSIX interrupt "
  2815. "Error: %d\n", err);
  2816. goto free_queue_irqs;
  2817. }
  2818. /* If Flow Director is enabled, set interrupt affinity */
  2819. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  2820. /* assign the mask for this irq */
  2821. irq_set_affinity_hint(entry->vector,
  2822. &q_vector->affinity_mask);
  2823. }
  2824. }
  2825. err = request_irq(adapter->msix_entries[vector].vector,
  2826. ixgbe_msix_other, 0, netdev->name, adapter);
  2827. if (err) {
  2828. e_err(probe, "request_irq for msix_other failed: %d\n", err);
  2829. goto free_queue_irqs;
  2830. }
  2831. return 0;
  2832. free_queue_irqs:
  2833. while (vector) {
  2834. vector--;
  2835. irq_set_affinity_hint(adapter->msix_entries[vector].vector,
  2836. NULL);
  2837. free_irq(adapter->msix_entries[vector].vector,
  2838. adapter->q_vector[vector]);
  2839. }
  2840. adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
  2841. pci_disable_msix(adapter->pdev);
  2842. kfree(adapter->msix_entries);
  2843. adapter->msix_entries = NULL;
  2844. return err;
  2845. }
  2846. /**
  2847. * ixgbe_intr - legacy mode Interrupt Handler
  2848. * @irq: interrupt number
  2849. * @data: pointer to a network interface device structure
  2850. **/
  2851. static irqreturn_t ixgbe_intr(int irq, void *data)
  2852. {
  2853. struct ixgbe_adapter *adapter = data;
  2854. struct ixgbe_hw *hw = &adapter->hw;
  2855. struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
  2856. u32 eicr;
  2857. /*
  2858. * Workaround for silicon errata #26 on 82598. Mask the interrupt
  2859. * before the read of EICR.
  2860. */
  2861. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
  2862. /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
  2863. * therefore no explicit interrupt disable is necessary */
  2864. eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
  2865. if (!eicr) {
  2866. /*
  2867. * shared interrupt alert!
  2868. * make sure interrupts are enabled because the read will
  2869. * have disabled interrupts due to EIAM
  2870. * finish the workaround of silicon errata on 82598. Unmask
  2871. * the interrupt that we masked before the EICR read.
  2872. */
  2873. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2874. ixgbe_irq_enable(adapter, true, true);
  2875. return IRQ_NONE; /* Not our interrupt */
  2876. }
  2877. if (eicr & IXGBE_EICR_LSC)
  2878. ixgbe_check_lsc(adapter);
  2879. switch (hw->mac.type) {
  2880. case ixgbe_mac_82599EB:
  2881. ixgbe_check_sfp_event(adapter, eicr);
  2882. /* Fall through */
  2883. case ixgbe_mac_X540:
  2884. case ixgbe_mac_X550:
  2885. case ixgbe_mac_X550EM_x:
  2886. case ixgbe_mac_x550em_a:
  2887. if (eicr & IXGBE_EICR_ECC) {
  2888. e_info(link, "Received ECC Err, initiating reset\n");
  2889. set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  2890. ixgbe_service_event_schedule(adapter);
  2891. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_ECC);
  2892. }
  2893. ixgbe_check_overtemp_event(adapter, eicr);
  2894. break;
  2895. default:
  2896. break;
  2897. }
  2898. ixgbe_check_fan_failure(adapter, eicr);
  2899. if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
  2900. ixgbe_ptp_check_pps_event(adapter);
  2901. /* would disable interrupts here but EIAM disabled it */
  2902. napi_schedule_irqoff(&q_vector->napi);
  2903. /*
  2904. * re-enable link(maybe) and non-queue interrupts, no flush.
  2905. * ixgbe_poll will re-enable the queue interrupts
  2906. */
  2907. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2908. ixgbe_irq_enable(adapter, false, false);
  2909. return IRQ_HANDLED;
  2910. }
  2911. /**
  2912. * ixgbe_request_irq - initialize interrupts
  2913. * @adapter: board private structure
  2914. *
  2915. * Attempts to configure interrupts using the best available
  2916. * capabilities of the hardware and kernel.
  2917. **/
  2918. static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
  2919. {
  2920. struct net_device *netdev = adapter->netdev;
  2921. int err;
  2922. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  2923. err = ixgbe_request_msix_irqs(adapter);
  2924. else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
  2925. err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
  2926. netdev->name, adapter);
  2927. else
  2928. err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
  2929. netdev->name, adapter);
  2930. if (err)
  2931. e_err(probe, "request_irq failed, Error %d\n", err);
  2932. return err;
  2933. }
  2934. static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
  2935. {
  2936. int vector;
  2937. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
  2938. free_irq(adapter->pdev->irq, adapter);
  2939. return;
  2940. }
  2941. if (!adapter->msix_entries)
  2942. return;
  2943. for (vector = 0; vector < adapter->num_q_vectors; vector++) {
  2944. struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
  2945. struct msix_entry *entry = &adapter->msix_entries[vector];
  2946. /* free only the irqs that were actually requested */
  2947. if (!q_vector->rx.ring && !q_vector->tx.ring)
  2948. continue;
  2949. /* clear the affinity_mask in the IRQ descriptor */
  2950. irq_set_affinity_hint(entry->vector, NULL);
  2951. free_irq(entry->vector, q_vector);
  2952. }
  2953. free_irq(adapter->msix_entries[vector].vector, adapter);
  2954. }
  2955. /**
  2956. * ixgbe_irq_disable - Mask off interrupt generation on the NIC
  2957. * @adapter: board private structure
  2958. **/
  2959. static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
  2960. {
  2961. switch (adapter->hw.mac.type) {
  2962. case ixgbe_mac_82598EB:
  2963. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
  2964. break;
  2965. case ixgbe_mac_82599EB:
  2966. case ixgbe_mac_X540:
  2967. case ixgbe_mac_X550:
  2968. case ixgbe_mac_X550EM_x:
  2969. case ixgbe_mac_x550em_a:
  2970. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
  2971. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
  2972. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
  2973. break;
  2974. default:
  2975. break;
  2976. }
  2977. IXGBE_WRITE_FLUSH(&adapter->hw);
  2978. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  2979. int vector;
  2980. for (vector = 0; vector < adapter->num_q_vectors; vector++)
  2981. synchronize_irq(adapter->msix_entries[vector].vector);
  2982. synchronize_irq(adapter->msix_entries[vector++].vector);
  2983. } else {
  2984. synchronize_irq(adapter->pdev->irq);
  2985. }
  2986. }
  2987. /**
  2988. * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
  2989. * @adapter: board private structure
  2990. *
  2991. **/
  2992. static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
  2993. {
  2994. struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
  2995. ixgbe_write_eitr(q_vector);
  2996. ixgbe_set_ivar(adapter, 0, 0, 0);
  2997. ixgbe_set_ivar(adapter, 1, 0, 0);
  2998. e_info(hw, "Legacy interrupt IVAR setup done\n");
  2999. }
  3000. /**
  3001. * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
  3002. * @adapter: board private structure
  3003. * @ring: structure containing ring specific data
  3004. *
  3005. * Configure the Tx descriptor ring after a reset.
  3006. **/
  3007. void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
  3008. struct ixgbe_ring *ring)
  3009. {
  3010. struct ixgbe_hw *hw = &adapter->hw;
  3011. u64 tdba = ring->dma;
  3012. int wait_loop = 10;
  3013. u32 txdctl = IXGBE_TXDCTL_ENABLE;
  3014. u8 reg_idx = ring->reg_idx;
  3015. /* disable queue to avoid issues while updating state */
  3016. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
  3017. IXGBE_WRITE_FLUSH(hw);
  3018. IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
  3019. (tdba & DMA_BIT_MASK(32)));
  3020. IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
  3021. IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
  3022. ring->count * sizeof(union ixgbe_adv_tx_desc));
  3023. IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
  3024. IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
  3025. ring->tail = adapter->io_addr + IXGBE_TDT(reg_idx);
  3026. /*
  3027. * set WTHRESH to encourage burst writeback, it should not be set
  3028. * higher than 1 when:
  3029. * - ITR is 0 as it could cause false TX hangs
  3030. * - ITR is set to > 100k int/sec and BQL is enabled
  3031. *
  3032. * In order to avoid issues WTHRESH + PTHRESH should always be equal
  3033. * to or less than the number of on chip descriptors, which is
  3034. * currently 40.
  3035. */
  3036. if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
  3037. txdctl |= 1u << 16; /* WTHRESH = 1 */
  3038. else
  3039. txdctl |= 8u << 16; /* WTHRESH = 8 */
  3040. /*
  3041. * Setting PTHRESH to 32 both improves performance
  3042. * and avoids a TX hang with DFP enabled
  3043. */
  3044. txdctl |= (1u << 8) | /* HTHRESH = 1 */
  3045. 32; /* PTHRESH = 32 */
  3046. /* reinitialize flowdirector state */
  3047. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  3048. ring->atr_sample_rate = adapter->atr_sample_rate;
  3049. ring->atr_count = 0;
  3050. set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
  3051. } else {
  3052. ring->atr_sample_rate = 0;
  3053. }
  3054. /* initialize XPS */
  3055. if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
  3056. struct ixgbe_q_vector *q_vector = ring->q_vector;
  3057. if (q_vector)
  3058. netif_set_xps_queue(ring->netdev,
  3059. &q_vector->affinity_mask,
  3060. ring->queue_index);
  3061. }
  3062. clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
  3063. /* reinitialize tx_buffer_info */
  3064. memset(ring->tx_buffer_info, 0,
  3065. sizeof(struct ixgbe_tx_buffer) * ring->count);
  3066. /* enable queue */
  3067. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
  3068. /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
  3069. if (hw->mac.type == ixgbe_mac_82598EB &&
  3070. !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  3071. return;
  3072. /* poll to verify queue is enabled */
  3073. do {
  3074. usleep_range(1000, 2000);
  3075. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
  3076. } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
  3077. if (!wait_loop)
  3078. hw_dbg(hw, "Could not enable Tx Queue %d\n", reg_idx);
  3079. }
  3080. static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
  3081. {
  3082. struct ixgbe_hw *hw = &adapter->hw;
  3083. u32 rttdcs, mtqc;
  3084. u8 tcs = adapter->hw_tcs;
  3085. if (hw->mac.type == ixgbe_mac_82598EB)
  3086. return;
  3087. /* disable the arbiter while setting MTQC */
  3088. rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
  3089. rttdcs |= IXGBE_RTTDCS_ARBDIS;
  3090. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
  3091. /* set transmit pool layout */
  3092. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  3093. mtqc = IXGBE_MTQC_VT_ENA;
  3094. if (tcs > 4)
  3095. mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
  3096. else if (tcs > 1)
  3097. mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
  3098. else if (adapter->ring_feature[RING_F_VMDQ].mask ==
  3099. IXGBE_82599_VMDQ_4Q_MASK)
  3100. mtqc |= IXGBE_MTQC_32VF;
  3101. else
  3102. mtqc |= IXGBE_MTQC_64VF;
  3103. } else {
  3104. if (tcs > 4)
  3105. mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
  3106. else if (tcs > 1)
  3107. mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
  3108. else
  3109. mtqc = IXGBE_MTQC_64Q_1PB;
  3110. }
  3111. IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
  3112. /* Enable Security TX Buffer IFG for multiple pb */
  3113. if (tcs) {
  3114. u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
  3115. sectx |= IXGBE_SECTX_DCB;
  3116. IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
  3117. }
  3118. /* re-enable the arbiter */
  3119. rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
  3120. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
  3121. }
  3122. /**
  3123. * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
  3124. * @adapter: board private structure
  3125. *
  3126. * Configure the Tx unit of the MAC after a reset.
  3127. **/
  3128. static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
  3129. {
  3130. struct ixgbe_hw *hw = &adapter->hw;
  3131. u32 dmatxctl;
  3132. u32 i;
  3133. ixgbe_setup_mtqc(adapter);
  3134. if (hw->mac.type != ixgbe_mac_82598EB) {
  3135. /* DMATXCTL.EN must be before Tx queues are enabled */
  3136. dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
  3137. dmatxctl |= IXGBE_DMATXCTL_TE;
  3138. IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
  3139. }
  3140. /* Setup the HW Tx Head and Tail descriptor pointers */
  3141. for (i = 0; i < adapter->num_tx_queues; i++)
  3142. ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
  3143. for (i = 0; i < adapter->num_xdp_queues; i++)
  3144. ixgbe_configure_tx_ring(adapter, adapter->xdp_ring[i]);
  3145. }
  3146. static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
  3147. struct ixgbe_ring *ring)
  3148. {
  3149. struct ixgbe_hw *hw = &adapter->hw;
  3150. u8 reg_idx = ring->reg_idx;
  3151. u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
  3152. srrctl |= IXGBE_SRRCTL_DROP_EN;
  3153. IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
  3154. }
  3155. static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
  3156. struct ixgbe_ring *ring)
  3157. {
  3158. struct ixgbe_hw *hw = &adapter->hw;
  3159. u8 reg_idx = ring->reg_idx;
  3160. u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
  3161. srrctl &= ~IXGBE_SRRCTL_DROP_EN;
  3162. IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
  3163. }
  3164. #ifdef CONFIG_IXGBE_DCB
  3165. void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
  3166. #else
  3167. static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
  3168. #endif
  3169. {
  3170. int i;
  3171. bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
  3172. if (adapter->ixgbe_ieee_pfc)
  3173. pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
  3174. /*
  3175. * We should set the drop enable bit if:
  3176. * SR-IOV is enabled
  3177. * or
  3178. * Number of Rx queues > 1 and flow control is disabled
  3179. *
  3180. * This allows us to avoid head of line blocking for security
  3181. * and performance reasons.
  3182. */
  3183. if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
  3184. !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
  3185. for (i = 0; i < adapter->num_rx_queues; i++)
  3186. ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
  3187. } else {
  3188. for (i = 0; i < adapter->num_rx_queues; i++)
  3189. ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
  3190. }
  3191. }
  3192. #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
  3193. static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
  3194. struct ixgbe_ring *rx_ring)
  3195. {
  3196. struct ixgbe_hw *hw = &adapter->hw;
  3197. u32 srrctl;
  3198. u8 reg_idx = rx_ring->reg_idx;
  3199. if (hw->mac.type == ixgbe_mac_82598EB) {
  3200. u16 mask = adapter->ring_feature[RING_F_RSS].mask;
  3201. /*
  3202. * if VMDq is not active we must program one srrctl register
  3203. * per RSS queue since we have enabled RDRXCTL.MVMEN
  3204. */
  3205. reg_idx &= mask;
  3206. }
  3207. /* configure header buffer length, needed for RSC */
  3208. srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
  3209. /* configure the packet buffer length */
  3210. if (test_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state))
  3211. srrctl |= IXGBE_RXBUFFER_3K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  3212. else
  3213. srrctl |= IXGBE_RXBUFFER_2K >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  3214. /* configure descriptor type */
  3215. srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
  3216. IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
  3217. }
  3218. /**
  3219. * ixgbe_rss_indir_tbl_entries - Return RSS indirection table entries
  3220. * @adapter: device handle
  3221. *
  3222. * - 82598/82599/X540: 128
  3223. * - X550(non-SRIOV mode): 512
  3224. * - X550(SRIOV mode): 64
  3225. */
  3226. u32 ixgbe_rss_indir_tbl_entries(struct ixgbe_adapter *adapter)
  3227. {
  3228. if (adapter->hw.mac.type < ixgbe_mac_X550)
  3229. return 128;
  3230. else if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  3231. return 64;
  3232. else
  3233. return 512;
  3234. }
  3235. /**
  3236. * ixgbe_store_key - Write the RSS key to HW
  3237. * @adapter: device handle
  3238. *
  3239. * Write the RSS key stored in adapter.rss_key to HW.
  3240. */
  3241. void ixgbe_store_key(struct ixgbe_adapter *adapter)
  3242. {
  3243. struct ixgbe_hw *hw = &adapter->hw;
  3244. int i;
  3245. for (i = 0; i < 10; i++)
  3246. IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), adapter->rss_key[i]);
  3247. }
  3248. /**
  3249. * ixgbe_init_rss_key - Initialize adapter RSS key
  3250. * @adapter: device handle
  3251. *
  3252. * Allocates and initializes the RSS key if it is not allocated.
  3253. **/
  3254. static inline int ixgbe_init_rss_key(struct ixgbe_adapter *adapter)
  3255. {
  3256. u32 *rss_key;
  3257. if (!adapter->rss_key) {
  3258. rss_key = kzalloc(IXGBE_RSS_KEY_SIZE, GFP_KERNEL);
  3259. if (unlikely(!rss_key))
  3260. return -ENOMEM;
  3261. netdev_rss_key_fill(rss_key, IXGBE_RSS_KEY_SIZE);
  3262. adapter->rss_key = rss_key;
  3263. }
  3264. return 0;
  3265. }
  3266. /**
  3267. * ixgbe_store_reta - Write the RETA table to HW
  3268. * @adapter: device handle
  3269. *
  3270. * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
  3271. */
  3272. void ixgbe_store_reta(struct ixgbe_adapter *adapter)
  3273. {
  3274. u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
  3275. struct ixgbe_hw *hw = &adapter->hw;
  3276. u32 reta = 0;
  3277. u32 indices_multi;
  3278. u8 *indir_tbl = adapter->rss_indir_tbl;
  3279. /* Fill out the redirection table as follows:
  3280. * - 82598: 8 bit wide entries containing pair of 4 bit RSS
  3281. * indices.
  3282. * - 82599/X540: 8 bit wide entries containing 4 bit RSS index
  3283. * - X550: 8 bit wide entries containing 6 bit RSS index
  3284. */
  3285. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  3286. indices_multi = 0x11;
  3287. else
  3288. indices_multi = 0x1;
  3289. /* Write redirection table to HW */
  3290. for (i = 0; i < reta_entries; i++) {
  3291. reta |= indices_multi * indir_tbl[i] << (i & 0x3) * 8;
  3292. if ((i & 3) == 3) {
  3293. if (i < 128)
  3294. IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
  3295. else
  3296. IXGBE_WRITE_REG(hw, IXGBE_ERETA((i >> 2) - 32),
  3297. reta);
  3298. reta = 0;
  3299. }
  3300. }
  3301. }
  3302. /**
  3303. * ixgbe_store_vfreta - Write the RETA table to HW (x550 devices in SRIOV mode)
  3304. * @adapter: device handle
  3305. *
  3306. * Write the RSS redirection table stored in adapter.rss_indir_tbl[] to HW.
  3307. */
  3308. static void ixgbe_store_vfreta(struct ixgbe_adapter *adapter)
  3309. {
  3310. u32 i, reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
  3311. struct ixgbe_hw *hw = &adapter->hw;
  3312. u32 vfreta = 0;
  3313. /* Write redirection table to HW */
  3314. for (i = 0; i < reta_entries; i++) {
  3315. u16 pool = adapter->num_rx_pools;
  3316. vfreta |= (u32)adapter->rss_indir_tbl[i] << (i & 0x3) * 8;
  3317. if ((i & 3) != 3)
  3318. continue;
  3319. while (pool--)
  3320. IXGBE_WRITE_REG(hw,
  3321. IXGBE_PFVFRETA(i >> 2, VMDQ_P(pool)),
  3322. vfreta);
  3323. vfreta = 0;
  3324. }
  3325. }
  3326. static void ixgbe_setup_reta(struct ixgbe_adapter *adapter)
  3327. {
  3328. u32 i, j;
  3329. u32 reta_entries = ixgbe_rss_indir_tbl_entries(adapter);
  3330. u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
  3331. /* Program table for at least 4 queues w/ SR-IOV so that VFs can
  3332. * make full use of any rings they may have. We will use the
  3333. * PSRTYPE register to control how many rings we use within the PF.
  3334. */
  3335. if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 4))
  3336. rss_i = 4;
  3337. /* Fill out hash function seeds */
  3338. ixgbe_store_key(adapter);
  3339. /* Fill out redirection table */
  3340. memset(adapter->rss_indir_tbl, 0, sizeof(adapter->rss_indir_tbl));
  3341. for (i = 0, j = 0; i < reta_entries; i++, j++) {
  3342. if (j == rss_i)
  3343. j = 0;
  3344. adapter->rss_indir_tbl[i] = j;
  3345. }
  3346. ixgbe_store_reta(adapter);
  3347. }
  3348. static void ixgbe_setup_vfreta(struct ixgbe_adapter *adapter)
  3349. {
  3350. struct ixgbe_hw *hw = &adapter->hw;
  3351. u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
  3352. int i, j;
  3353. /* Fill out hash function seeds */
  3354. for (i = 0; i < 10; i++) {
  3355. u16 pool = adapter->num_rx_pools;
  3356. while (pool--)
  3357. IXGBE_WRITE_REG(hw,
  3358. IXGBE_PFVFRSSRK(i, VMDQ_P(pool)),
  3359. *(adapter->rss_key + i));
  3360. }
  3361. /* Fill out the redirection table */
  3362. for (i = 0, j = 0; i < 64; i++, j++) {
  3363. if (j == rss_i)
  3364. j = 0;
  3365. adapter->rss_indir_tbl[i] = j;
  3366. }
  3367. ixgbe_store_vfreta(adapter);
  3368. }
  3369. static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
  3370. {
  3371. struct ixgbe_hw *hw = &adapter->hw;
  3372. u32 mrqc = 0, rss_field = 0, vfmrqc = 0;
  3373. u32 rxcsum;
  3374. /* Disable indicating checksum in descriptor, enables RSS hash */
  3375. rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
  3376. rxcsum |= IXGBE_RXCSUM_PCSD;
  3377. IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
  3378. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  3379. if (adapter->ring_feature[RING_F_RSS].mask)
  3380. mrqc = IXGBE_MRQC_RSSEN;
  3381. } else {
  3382. u8 tcs = adapter->hw_tcs;
  3383. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  3384. if (tcs > 4)
  3385. mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
  3386. else if (tcs > 1)
  3387. mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
  3388. else if (adapter->ring_feature[RING_F_VMDQ].mask ==
  3389. IXGBE_82599_VMDQ_4Q_MASK)
  3390. mrqc = IXGBE_MRQC_VMDQRSS32EN;
  3391. else
  3392. mrqc = IXGBE_MRQC_VMDQRSS64EN;
  3393. /* Enable L3/L4 for Tx Switched packets */
  3394. mrqc |= IXGBE_MRQC_L3L4TXSWEN;
  3395. } else {
  3396. if (tcs > 4)
  3397. mrqc = IXGBE_MRQC_RTRSS8TCEN;
  3398. else if (tcs > 1)
  3399. mrqc = IXGBE_MRQC_RTRSS4TCEN;
  3400. else
  3401. mrqc = IXGBE_MRQC_RSSEN;
  3402. }
  3403. }
  3404. /* Perform hash on these packet types */
  3405. rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4 |
  3406. IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
  3407. IXGBE_MRQC_RSS_FIELD_IPV6 |
  3408. IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
  3409. if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
  3410. rss_field |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
  3411. if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
  3412. rss_field |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
  3413. if ((hw->mac.type >= ixgbe_mac_X550) &&
  3414. (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) {
  3415. u16 pool = adapter->num_rx_pools;
  3416. /* Enable VF RSS mode */
  3417. mrqc |= IXGBE_MRQC_MULTIPLE_RSS;
  3418. IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
  3419. /* Setup RSS through the VF registers */
  3420. ixgbe_setup_vfreta(adapter);
  3421. vfmrqc = IXGBE_MRQC_RSSEN;
  3422. vfmrqc |= rss_field;
  3423. while (pool--)
  3424. IXGBE_WRITE_REG(hw,
  3425. IXGBE_PFVFMRQC(VMDQ_P(pool)),
  3426. vfmrqc);
  3427. } else {
  3428. ixgbe_setup_reta(adapter);
  3429. mrqc |= rss_field;
  3430. IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
  3431. }
  3432. }
  3433. /**
  3434. * ixgbe_configure_rscctl - enable RSC for the indicated ring
  3435. * @adapter: address of board private structure
  3436. * @ring: structure containing ring specific data
  3437. **/
  3438. static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
  3439. struct ixgbe_ring *ring)
  3440. {
  3441. struct ixgbe_hw *hw = &adapter->hw;
  3442. u32 rscctrl;
  3443. u8 reg_idx = ring->reg_idx;
  3444. if (!ring_is_rsc_enabled(ring))
  3445. return;
  3446. rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
  3447. rscctrl |= IXGBE_RSCCTL_RSCEN;
  3448. /*
  3449. * we must limit the number of descriptors so that the
  3450. * total size of max desc * buf_len is not greater
  3451. * than 65536
  3452. */
  3453. rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
  3454. IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
  3455. }
  3456. #define IXGBE_MAX_RX_DESC_POLL 10
  3457. static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
  3458. struct ixgbe_ring *ring)
  3459. {
  3460. struct ixgbe_hw *hw = &adapter->hw;
  3461. int wait_loop = IXGBE_MAX_RX_DESC_POLL;
  3462. u32 rxdctl;
  3463. u8 reg_idx = ring->reg_idx;
  3464. if (ixgbe_removed(hw->hw_addr))
  3465. return;
  3466. /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
  3467. if (hw->mac.type == ixgbe_mac_82598EB &&
  3468. !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  3469. return;
  3470. do {
  3471. usleep_range(1000, 2000);
  3472. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  3473. } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
  3474. if (!wait_loop) {
  3475. e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
  3476. "the polling period\n", reg_idx);
  3477. }
  3478. }
  3479. void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
  3480. struct ixgbe_ring *ring)
  3481. {
  3482. struct ixgbe_hw *hw = &adapter->hw;
  3483. int wait_loop = IXGBE_MAX_RX_DESC_POLL;
  3484. u32 rxdctl;
  3485. u8 reg_idx = ring->reg_idx;
  3486. if (ixgbe_removed(hw->hw_addr))
  3487. return;
  3488. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  3489. rxdctl &= ~IXGBE_RXDCTL_ENABLE;
  3490. /* write value back with RXDCTL.ENABLE bit cleared */
  3491. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
  3492. if (hw->mac.type == ixgbe_mac_82598EB &&
  3493. !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  3494. return;
  3495. /* the hardware may take up to 100us to really disable the rx queue */
  3496. do {
  3497. udelay(10);
  3498. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  3499. } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
  3500. if (!wait_loop) {
  3501. e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
  3502. "the polling period\n", reg_idx);
  3503. }
  3504. }
  3505. void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
  3506. struct ixgbe_ring *ring)
  3507. {
  3508. struct ixgbe_hw *hw = &adapter->hw;
  3509. union ixgbe_adv_rx_desc *rx_desc;
  3510. u64 rdba = ring->dma;
  3511. u32 rxdctl;
  3512. u8 reg_idx = ring->reg_idx;
  3513. /* disable queue to avoid issues while updating state */
  3514. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  3515. ixgbe_disable_rx_queue(adapter, ring);
  3516. IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
  3517. IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
  3518. IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
  3519. ring->count * sizeof(union ixgbe_adv_rx_desc));
  3520. /* Force flushing of IXGBE_RDLEN to prevent MDD */
  3521. IXGBE_WRITE_FLUSH(hw);
  3522. IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
  3523. IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
  3524. ring->tail = adapter->io_addr + IXGBE_RDT(reg_idx);
  3525. ixgbe_configure_srrctl(adapter, ring);
  3526. ixgbe_configure_rscctl(adapter, ring);
  3527. if (hw->mac.type == ixgbe_mac_82598EB) {
  3528. /*
  3529. * enable cache line friendly hardware writes:
  3530. * PTHRESH=32 descriptors (half the internal cache),
  3531. * this also removes ugly rx_no_buffer_count increment
  3532. * HTHRESH=4 descriptors (to minimize latency on fetch)
  3533. * WTHRESH=8 burst writeback up to two cache lines
  3534. */
  3535. rxdctl &= ~0x3FFFFF;
  3536. rxdctl |= 0x080420;
  3537. #if (PAGE_SIZE < 8192)
  3538. /* RXDCTL.RLPML does not work on 82599 */
  3539. } else if (hw->mac.type != ixgbe_mac_82599EB) {
  3540. rxdctl &= ~(IXGBE_RXDCTL_RLPMLMASK |
  3541. IXGBE_RXDCTL_RLPML_EN);
  3542. /* Limit the maximum frame size so we don't overrun the skb.
  3543. * This can happen in SRIOV mode when the MTU of the VF is
  3544. * higher than the MTU of the PF.
  3545. */
  3546. if (ring_uses_build_skb(ring) &&
  3547. !test_bit(__IXGBE_RX_3K_BUFFER, &ring->state))
  3548. rxdctl |= IXGBE_MAX_2K_FRAME_BUILD_SKB |
  3549. IXGBE_RXDCTL_RLPML_EN;
  3550. #endif
  3551. }
  3552. /* initialize rx_buffer_info */
  3553. memset(ring->rx_buffer_info, 0,
  3554. sizeof(struct ixgbe_rx_buffer) * ring->count);
  3555. /* initialize Rx descriptor 0 */
  3556. rx_desc = IXGBE_RX_DESC(ring, 0);
  3557. rx_desc->wb.upper.length = 0;
  3558. /* enable receive descriptor ring */
  3559. rxdctl |= IXGBE_RXDCTL_ENABLE;
  3560. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
  3561. ixgbe_rx_desc_queue_enable(adapter, ring);
  3562. ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
  3563. }
  3564. static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
  3565. {
  3566. struct ixgbe_hw *hw = &adapter->hw;
  3567. int rss_i = adapter->ring_feature[RING_F_RSS].indices;
  3568. u16 pool = adapter->num_rx_pools;
  3569. /* PSRTYPE must be initialized in non 82598 adapters */
  3570. u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
  3571. IXGBE_PSRTYPE_UDPHDR |
  3572. IXGBE_PSRTYPE_IPV4HDR |
  3573. IXGBE_PSRTYPE_L2HDR |
  3574. IXGBE_PSRTYPE_IPV6HDR;
  3575. if (hw->mac.type == ixgbe_mac_82598EB)
  3576. return;
  3577. if (rss_i > 3)
  3578. psrtype |= 2u << 29;
  3579. else if (rss_i > 1)
  3580. psrtype |= 1u << 29;
  3581. while (pool--)
  3582. IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(pool)), psrtype);
  3583. }
  3584. static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
  3585. {
  3586. struct ixgbe_hw *hw = &adapter->hw;
  3587. u16 pool = adapter->num_rx_pools;
  3588. u32 reg_offset, vf_shift, vmolr;
  3589. u32 gcr_ext, vmdctl;
  3590. int i;
  3591. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  3592. return;
  3593. vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
  3594. vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
  3595. vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
  3596. vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
  3597. vmdctl |= IXGBE_VT_CTL_REPLEN;
  3598. IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
  3599. /* accept untagged packets until a vlan tag is
  3600. * specifically set for the VMDQ queue/pool
  3601. */
  3602. vmolr = IXGBE_VMOLR_AUPE;
  3603. while (pool--)
  3604. IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(pool)), vmolr);
  3605. vf_shift = VMDQ_P(0) % 32;
  3606. reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
  3607. /* Enable only the PF's pool for Tx/Rx */
  3608. IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), GENMASK(31, vf_shift));
  3609. IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
  3610. IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), GENMASK(31, vf_shift));
  3611. IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
  3612. if (adapter->bridge_mode == BRIDGE_MODE_VEB)
  3613. IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
  3614. /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
  3615. hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
  3616. /* clear VLAN promisc flag so VFTA will be updated if necessary */
  3617. adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
  3618. /*
  3619. * Set up VF register offsets for selected VT Mode,
  3620. * i.e. 32 or 64 VFs for SR-IOV
  3621. */
  3622. switch (adapter->ring_feature[RING_F_VMDQ].mask) {
  3623. case IXGBE_82599_VMDQ_8Q_MASK:
  3624. gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
  3625. break;
  3626. case IXGBE_82599_VMDQ_4Q_MASK:
  3627. gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
  3628. break;
  3629. default:
  3630. gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
  3631. break;
  3632. }
  3633. IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
  3634. for (i = 0; i < adapter->num_vfs; i++) {
  3635. /* configure spoof checking */
  3636. ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i,
  3637. adapter->vfinfo[i].spoofchk_enabled);
  3638. /* Enable/Disable RSS query feature */
  3639. ixgbe_ndo_set_vf_rss_query_en(adapter->netdev, i,
  3640. adapter->vfinfo[i].rss_query_enabled);
  3641. }
  3642. }
  3643. static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
  3644. {
  3645. struct ixgbe_hw *hw = &adapter->hw;
  3646. struct net_device *netdev = adapter->netdev;
  3647. int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  3648. struct ixgbe_ring *rx_ring;
  3649. int i;
  3650. u32 mhadd, hlreg0;
  3651. #ifdef IXGBE_FCOE
  3652. /* adjust max frame to be able to do baby jumbo for FCoE */
  3653. if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
  3654. (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
  3655. max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
  3656. #endif /* IXGBE_FCOE */
  3657. /* adjust max frame to be at least the size of a standard frame */
  3658. if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
  3659. max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
  3660. mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
  3661. if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
  3662. mhadd &= ~IXGBE_MHADD_MFS_MASK;
  3663. mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
  3664. IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
  3665. }
  3666. hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
  3667. /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
  3668. hlreg0 |= IXGBE_HLREG0_JUMBOEN;
  3669. IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
  3670. /*
  3671. * Setup the HW Rx Head and Tail Descriptor Pointers and
  3672. * the Base and Length of the Rx Descriptor Ring
  3673. */
  3674. for (i = 0; i < adapter->num_rx_queues; i++) {
  3675. rx_ring = adapter->rx_ring[i];
  3676. clear_ring_rsc_enabled(rx_ring);
  3677. clear_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
  3678. clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
  3679. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  3680. set_ring_rsc_enabled(rx_ring);
  3681. if (test_bit(__IXGBE_RX_FCOE, &rx_ring->state))
  3682. set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
  3683. clear_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
  3684. if (adapter->flags2 & IXGBE_FLAG2_RX_LEGACY)
  3685. continue;
  3686. set_bit(__IXGBE_RX_BUILD_SKB_ENABLED, &rx_ring->state);
  3687. #if (PAGE_SIZE < 8192)
  3688. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  3689. set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
  3690. if (IXGBE_2K_TOO_SMALL_WITH_PADDING ||
  3691. (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)))
  3692. set_bit(__IXGBE_RX_3K_BUFFER, &rx_ring->state);
  3693. #endif
  3694. }
  3695. }
  3696. static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
  3697. {
  3698. struct ixgbe_hw *hw = &adapter->hw;
  3699. u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
  3700. switch (hw->mac.type) {
  3701. case ixgbe_mac_82598EB:
  3702. /*
  3703. * For VMDq support of different descriptor types or
  3704. * buffer sizes through the use of multiple SRRCTL
  3705. * registers, RDRXCTL.MVMEN must be set to 1
  3706. *
  3707. * also, the manual doesn't mention it clearly but DCA hints
  3708. * will only use queue 0's tags unless this bit is set. Side
  3709. * effects of setting this bit are only that SRRCTL must be
  3710. * fully programmed [0..15]
  3711. */
  3712. rdrxctl |= IXGBE_RDRXCTL_MVMEN;
  3713. break;
  3714. case ixgbe_mac_X550:
  3715. case ixgbe_mac_X550EM_x:
  3716. case ixgbe_mac_x550em_a:
  3717. if (adapter->num_vfs)
  3718. rdrxctl |= IXGBE_RDRXCTL_PSP;
  3719. /* fall through */
  3720. case ixgbe_mac_82599EB:
  3721. case ixgbe_mac_X540:
  3722. /* Disable RSC for ACK packets */
  3723. IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
  3724. (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
  3725. rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
  3726. /* hardware requires some bits to be set by default */
  3727. rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
  3728. rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
  3729. break;
  3730. default:
  3731. /* We should do nothing since we don't know this hardware */
  3732. return;
  3733. }
  3734. IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
  3735. }
  3736. /**
  3737. * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
  3738. * @adapter: board private structure
  3739. *
  3740. * Configure the Rx unit of the MAC after a reset.
  3741. **/
  3742. static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
  3743. {
  3744. struct ixgbe_hw *hw = &adapter->hw;
  3745. int i;
  3746. u32 rxctrl, rfctl;
  3747. /* disable receives while setting up the descriptors */
  3748. hw->mac.ops.disable_rx(hw);
  3749. ixgbe_setup_psrtype(adapter);
  3750. ixgbe_setup_rdrxctl(adapter);
  3751. /* RSC Setup */
  3752. rfctl = IXGBE_READ_REG(hw, IXGBE_RFCTL);
  3753. rfctl &= ~IXGBE_RFCTL_RSC_DIS;
  3754. if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
  3755. rfctl |= IXGBE_RFCTL_RSC_DIS;
  3756. /* disable NFS filtering */
  3757. rfctl |= (IXGBE_RFCTL_NFSW_DIS | IXGBE_RFCTL_NFSR_DIS);
  3758. IXGBE_WRITE_REG(hw, IXGBE_RFCTL, rfctl);
  3759. /* Program registers for the distribution of queues */
  3760. ixgbe_setup_mrqc(adapter);
  3761. /* set_rx_buffer_len must be called before ring initialization */
  3762. ixgbe_set_rx_buffer_len(adapter);
  3763. /*
  3764. * Setup the HW Rx Head and Tail Descriptor Pointers and
  3765. * the Base and Length of the Rx Descriptor Ring
  3766. */
  3767. for (i = 0; i < adapter->num_rx_queues; i++)
  3768. ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
  3769. rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  3770. /* disable drop enable for 82598 parts */
  3771. if (hw->mac.type == ixgbe_mac_82598EB)
  3772. rxctrl |= IXGBE_RXCTRL_DMBYPS;
  3773. /* enable all receives */
  3774. rxctrl |= IXGBE_RXCTRL_RXEN;
  3775. hw->mac.ops.enable_rx_dma(hw, rxctrl);
  3776. }
  3777. static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
  3778. __be16 proto, u16 vid)
  3779. {
  3780. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3781. struct ixgbe_hw *hw = &adapter->hw;
  3782. /* add VID to filter table */
  3783. if (!vid || !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
  3784. hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true, !!vid);
  3785. set_bit(vid, adapter->active_vlans);
  3786. return 0;
  3787. }
  3788. static int ixgbe_find_vlvf_entry(struct ixgbe_hw *hw, u32 vlan)
  3789. {
  3790. u32 vlvf;
  3791. int idx;
  3792. /* short cut the special case */
  3793. if (vlan == 0)
  3794. return 0;
  3795. /* Search for the vlan id in the VLVF entries */
  3796. for (idx = IXGBE_VLVF_ENTRIES; --idx;) {
  3797. vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(idx));
  3798. if ((vlvf & VLAN_VID_MASK) == vlan)
  3799. break;
  3800. }
  3801. return idx;
  3802. }
  3803. void ixgbe_update_pf_promisc_vlvf(struct ixgbe_adapter *adapter, u32 vid)
  3804. {
  3805. struct ixgbe_hw *hw = &adapter->hw;
  3806. u32 bits, word;
  3807. int idx;
  3808. idx = ixgbe_find_vlvf_entry(hw, vid);
  3809. if (!idx)
  3810. return;
  3811. /* See if any other pools are set for this VLAN filter
  3812. * entry other than the PF.
  3813. */
  3814. word = idx * 2 + (VMDQ_P(0) / 32);
  3815. bits = ~BIT(VMDQ_P(0) % 32);
  3816. bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
  3817. /* Disable the filter so this falls into the default pool. */
  3818. if (!bits && !IXGBE_READ_REG(hw, IXGBE_VLVFB(word ^ 1))) {
  3819. if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
  3820. IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), 0);
  3821. IXGBE_WRITE_REG(hw, IXGBE_VLVF(idx), 0);
  3822. }
  3823. }
  3824. static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
  3825. __be16 proto, u16 vid)
  3826. {
  3827. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3828. struct ixgbe_hw *hw = &adapter->hw;
  3829. /* remove VID from filter table */
  3830. if (vid && !(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
  3831. hw->mac.ops.set_vfta(hw, vid, VMDQ_P(0), false, true);
  3832. clear_bit(vid, adapter->active_vlans);
  3833. return 0;
  3834. }
  3835. /**
  3836. * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
  3837. * @adapter: driver data
  3838. */
  3839. static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
  3840. {
  3841. struct ixgbe_hw *hw = &adapter->hw;
  3842. u32 vlnctrl;
  3843. int i, j;
  3844. switch (hw->mac.type) {
  3845. case ixgbe_mac_82598EB:
  3846. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3847. vlnctrl &= ~IXGBE_VLNCTRL_VME;
  3848. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3849. break;
  3850. case ixgbe_mac_82599EB:
  3851. case ixgbe_mac_X540:
  3852. case ixgbe_mac_X550:
  3853. case ixgbe_mac_X550EM_x:
  3854. case ixgbe_mac_x550em_a:
  3855. for (i = 0; i < adapter->num_rx_queues; i++) {
  3856. struct ixgbe_ring *ring = adapter->rx_ring[i];
  3857. if (!netif_is_ixgbe(ring->netdev))
  3858. continue;
  3859. j = ring->reg_idx;
  3860. vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
  3861. vlnctrl &= ~IXGBE_RXDCTL_VME;
  3862. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
  3863. }
  3864. break;
  3865. default:
  3866. break;
  3867. }
  3868. }
  3869. /**
  3870. * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
  3871. * @adapter: driver data
  3872. */
  3873. static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
  3874. {
  3875. struct ixgbe_hw *hw = &adapter->hw;
  3876. u32 vlnctrl;
  3877. int i, j;
  3878. switch (hw->mac.type) {
  3879. case ixgbe_mac_82598EB:
  3880. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3881. vlnctrl |= IXGBE_VLNCTRL_VME;
  3882. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3883. break;
  3884. case ixgbe_mac_82599EB:
  3885. case ixgbe_mac_X540:
  3886. case ixgbe_mac_X550:
  3887. case ixgbe_mac_X550EM_x:
  3888. case ixgbe_mac_x550em_a:
  3889. for (i = 0; i < adapter->num_rx_queues; i++) {
  3890. struct ixgbe_ring *ring = adapter->rx_ring[i];
  3891. if (!netif_is_ixgbe(ring->netdev))
  3892. continue;
  3893. j = ring->reg_idx;
  3894. vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
  3895. vlnctrl |= IXGBE_RXDCTL_VME;
  3896. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
  3897. }
  3898. break;
  3899. default:
  3900. break;
  3901. }
  3902. }
  3903. static void ixgbe_vlan_promisc_enable(struct ixgbe_adapter *adapter)
  3904. {
  3905. struct ixgbe_hw *hw = &adapter->hw;
  3906. u32 vlnctrl, i;
  3907. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3908. if (adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) {
  3909. /* For VMDq and SR-IOV we must leave VLAN filtering enabled */
  3910. vlnctrl |= IXGBE_VLNCTRL_VFE;
  3911. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3912. } else {
  3913. vlnctrl &= ~IXGBE_VLNCTRL_VFE;
  3914. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3915. return;
  3916. }
  3917. /* Nothing to do for 82598 */
  3918. if (hw->mac.type == ixgbe_mac_82598EB)
  3919. return;
  3920. /* We are already in VLAN promisc, nothing to do */
  3921. if (adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC)
  3922. return;
  3923. /* Set flag so we don't redo unnecessary work */
  3924. adapter->flags2 |= IXGBE_FLAG2_VLAN_PROMISC;
  3925. /* Add PF to all active pools */
  3926. for (i = IXGBE_VLVF_ENTRIES; --i;) {
  3927. u32 reg_offset = IXGBE_VLVFB(i * 2 + VMDQ_P(0) / 32);
  3928. u32 vlvfb = IXGBE_READ_REG(hw, reg_offset);
  3929. vlvfb |= BIT(VMDQ_P(0) % 32);
  3930. IXGBE_WRITE_REG(hw, reg_offset, vlvfb);
  3931. }
  3932. /* Set all bits in the VLAN filter table array */
  3933. for (i = hw->mac.vft_size; i--;)
  3934. IXGBE_WRITE_REG(hw, IXGBE_VFTA(i), ~0U);
  3935. }
  3936. #define VFTA_BLOCK_SIZE 8
  3937. static void ixgbe_scrub_vfta(struct ixgbe_adapter *adapter, u32 vfta_offset)
  3938. {
  3939. struct ixgbe_hw *hw = &adapter->hw;
  3940. u32 vfta[VFTA_BLOCK_SIZE] = { 0 };
  3941. u32 vid_start = vfta_offset * 32;
  3942. u32 vid_end = vid_start + (VFTA_BLOCK_SIZE * 32);
  3943. u32 i, vid, word, bits;
  3944. for (i = IXGBE_VLVF_ENTRIES; --i;) {
  3945. u32 vlvf = IXGBE_READ_REG(hw, IXGBE_VLVF(i));
  3946. /* pull VLAN ID from VLVF */
  3947. vid = vlvf & VLAN_VID_MASK;
  3948. /* only concern outselves with a certain range */
  3949. if (vid < vid_start || vid >= vid_end)
  3950. continue;
  3951. if (vlvf) {
  3952. /* record VLAN ID in VFTA */
  3953. vfta[(vid - vid_start) / 32] |= BIT(vid % 32);
  3954. /* if PF is part of this then continue */
  3955. if (test_bit(vid, adapter->active_vlans))
  3956. continue;
  3957. }
  3958. /* remove PF from the pool */
  3959. word = i * 2 + VMDQ_P(0) / 32;
  3960. bits = ~BIT(VMDQ_P(0) % 32);
  3961. bits &= IXGBE_READ_REG(hw, IXGBE_VLVFB(word));
  3962. IXGBE_WRITE_REG(hw, IXGBE_VLVFB(word), bits);
  3963. }
  3964. /* extract values from active_vlans and write back to VFTA */
  3965. for (i = VFTA_BLOCK_SIZE; i--;) {
  3966. vid = (vfta_offset + i) * 32;
  3967. word = vid / BITS_PER_LONG;
  3968. bits = vid % BITS_PER_LONG;
  3969. vfta[i] |= adapter->active_vlans[word] >> bits;
  3970. IXGBE_WRITE_REG(hw, IXGBE_VFTA(vfta_offset + i), vfta[i]);
  3971. }
  3972. }
  3973. static void ixgbe_vlan_promisc_disable(struct ixgbe_adapter *adapter)
  3974. {
  3975. struct ixgbe_hw *hw = &adapter->hw;
  3976. u32 vlnctrl, i;
  3977. /* Set VLAN filtering to enabled */
  3978. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3979. vlnctrl |= IXGBE_VLNCTRL_VFE;
  3980. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3981. if (!(adapter->flags & IXGBE_FLAG_VMDQ_ENABLED) ||
  3982. hw->mac.type == ixgbe_mac_82598EB)
  3983. return;
  3984. /* We are not in VLAN promisc, nothing to do */
  3985. if (!(adapter->flags2 & IXGBE_FLAG2_VLAN_PROMISC))
  3986. return;
  3987. /* Set flag so we don't redo unnecessary work */
  3988. adapter->flags2 &= ~IXGBE_FLAG2_VLAN_PROMISC;
  3989. for (i = 0; i < hw->mac.vft_size; i += VFTA_BLOCK_SIZE)
  3990. ixgbe_scrub_vfta(adapter, i);
  3991. }
  3992. static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
  3993. {
  3994. u16 vid = 1;
  3995. ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
  3996. for_each_set_bit_from(vid, adapter->active_vlans, VLAN_N_VID)
  3997. ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
  3998. }
  3999. /**
  4000. * ixgbe_write_mc_addr_list - write multicast addresses to MTA
  4001. * @netdev: network interface device structure
  4002. *
  4003. * Writes multicast address list to the MTA hash table.
  4004. * Returns: -ENOMEM on failure
  4005. * 0 on no addresses written
  4006. * X on writing X addresses to MTA
  4007. **/
  4008. static int ixgbe_write_mc_addr_list(struct net_device *netdev)
  4009. {
  4010. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4011. struct ixgbe_hw *hw = &adapter->hw;
  4012. if (!netif_running(netdev))
  4013. return 0;
  4014. if (hw->mac.ops.update_mc_addr_list)
  4015. hw->mac.ops.update_mc_addr_list(hw, netdev);
  4016. else
  4017. return -ENOMEM;
  4018. #ifdef CONFIG_PCI_IOV
  4019. ixgbe_restore_vf_multicasts(adapter);
  4020. #endif
  4021. return netdev_mc_count(netdev);
  4022. }
  4023. #ifdef CONFIG_PCI_IOV
  4024. void ixgbe_full_sync_mac_table(struct ixgbe_adapter *adapter)
  4025. {
  4026. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  4027. struct ixgbe_hw *hw = &adapter->hw;
  4028. int i;
  4029. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  4030. mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
  4031. if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
  4032. hw->mac.ops.set_rar(hw, i,
  4033. mac_table->addr,
  4034. mac_table->pool,
  4035. IXGBE_RAH_AV);
  4036. else
  4037. hw->mac.ops.clear_rar(hw, i);
  4038. }
  4039. }
  4040. #endif
  4041. static void ixgbe_sync_mac_table(struct ixgbe_adapter *adapter)
  4042. {
  4043. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  4044. struct ixgbe_hw *hw = &adapter->hw;
  4045. int i;
  4046. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  4047. if (!(mac_table->state & IXGBE_MAC_STATE_MODIFIED))
  4048. continue;
  4049. mac_table->state &= ~IXGBE_MAC_STATE_MODIFIED;
  4050. if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
  4051. hw->mac.ops.set_rar(hw, i,
  4052. mac_table->addr,
  4053. mac_table->pool,
  4054. IXGBE_RAH_AV);
  4055. else
  4056. hw->mac.ops.clear_rar(hw, i);
  4057. }
  4058. }
  4059. static void ixgbe_flush_sw_mac_table(struct ixgbe_adapter *adapter)
  4060. {
  4061. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  4062. struct ixgbe_hw *hw = &adapter->hw;
  4063. int i;
  4064. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  4065. mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
  4066. mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
  4067. }
  4068. ixgbe_sync_mac_table(adapter);
  4069. }
  4070. static int ixgbe_available_rars(struct ixgbe_adapter *adapter, u16 pool)
  4071. {
  4072. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  4073. struct ixgbe_hw *hw = &adapter->hw;
  4074. int i, count = 0;
  4075. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  4076. /* do not count default RAR as available */
  4077. if (mac_table->state & IXGBE_MAC_STATE_DEFAULT)
  4078. continue;
  4079. /* only count unused and addresses that belong to us */
  4080. if (mac_table->state & IXGBE_MAC_STATE_IN_USE) {
  4081. if (mac_table->pool != pool)
  4082. continue;
  4083. }
  4084. count++;
  4085. }
  4086. return count;
  4087. }
  4088. /* this function destroys the first RAR entry */
  4089. static void ixgbe_mac_set_default_filter(struct ixgbe_adapter *adapter)
  4090. {
  4091. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  4092. struct ixgbe_hw *hw = &adapter->hw;
  4093. memcpy(&mac_table->addr, hw->mac.addr, ETH_ALEN);
  4094. mac_table->pool = VMDQ_P(0);
  4095. mac_table->state = IXGBE_MAC_STATE_DEFAULT | IXGBE_MAC_STATE_IN_USE;
  4096. hw->mac.ops.set_rar(hw, 0, mac_table->addr, mac_table->pool,
  4097. IXGBE_RAH_AV);
  4098. }
  4099. int ixgbe_add_mac_filter(struct ixgbe_adapter *adapter,
  4100. const u8 *addr, u16 pool)
  4101. {
  4102. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  4103. struct ixgbe_hw *hw = &adapter->hw;
  4104. int i;
  4105. if (is_zero_ether_addr(addr))
  4106. return -EINVAL;
  4107. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  4108. if (mac_table->state & IXGBE_MAC_STATE_IN_USE)
  4109. continue;
  4110. ether_addr_copy(mac_table->addr, addr);
  4111. mac_table->pool = pool;
  4112. mac_table->state |= IXGBE_MAC_STATE_MODIFIED |
  4113. IXGBE_MAC_STATE_IN_USE;
  4114. ixgbe_sync_mac_table(adapter);
  4115. return i;
  4116. }
  4117. return -ENOMEM;
  4118. }
  4119. int ixgbe_del_mac_filter(struct ixgbe_adapter *adapter,
  4120. const u8 *addr, u16 pool)
  4121. {
  4122. struct ixgbe_mac_addr *mac_table = &adapter->mac_table[0];
  4123. struct ixgbe_hw *hw = &adapter->hw;
  4124. int i;
  4125. if (is_zero_ether_addr(addr))
  4126. return -EINVAL;
  4127. /* search table for addr, if found clear IN_USE flag and sync */
  4128. for (i = 0; i < hw->mac.num_rar_entries; i++, mac_table++) {
  4129. /* we can only delete an entry if it is in use */
  4130. if (!(mac_table->state & IXGBE_MAC_STATE_IN_USE))
  4131. continue;
  4132. /* we only care about entries that belong to the given pool */
  4133. if (mac_table->pool != pool)
  4134. continue;
  4135. /* we only care about a specific MAC address */
  4136. if (!ether_addr_equal(addr, mac_table->addr))
  4137. continue;
  4138. mac_table->state |= IXGBE_MAC_STATE_MODIFIED;
  4139. mac_table->state &= ~IXGBE_MAC_STATE_IN_USE;
  4140. ixgbe_sync_mac_table(adapter);
  4141. return 0;
  4142. }
  4143. return -ENOMEM;
  4144. }
  4145. static int ixgbe_uc_sync(struct net_device *netdev, const unsigned char *addr)
  4146. {
  4147. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4148. int ret;
  4149. ret = ixgbe_add_mac_filter(adapter, addr, VMDQ_P(0));
  4150. return min_t(int, ret, 0);
  4151. }
  4152. static int ixgbe_uc_unsync(struct net_device *netdev, const unsigned char *addr)
  4153. {
  4154. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4155. ixgbe_del_mac_filter(adapter, addr, VMDQ_P(0));
  4156. return 0;
  4157. }
  4158. /**
  4159. * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
  4160. * @netdev: network interface device structure
  4161. *
  4162. * The set_rx_method entry point is called whenever the unicast/multicast
  4163. * address list or the network interface flags are updated. This routine is
  4164. * responsible for configuring the hardware for proper unicast, multicast and
  4165. * promiscuous mode.
  4166. **/
  4167. void ixgbe_set_rx_mode(struct net_device *netdev)
  4168. {
  4169. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4170. struct ixgbe_hw *hw = &adapter->hw;
  4171. u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
  4172. netdev_features_t features = netdev->features;
  4173. int count;
  4174. /* Check for Promiscuous and All Multicast modes */
  4175. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  4176. /* set all bits that we expect to always be set */
  4177. fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
  4178. fctrl |= IXGBE_FCTRL_BAM;
  4179. fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
  4180. fctrl |= IXGBE_FCTRL_PMCF;
  4181. /* clear the bits we are changing the status of */
  4182. fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
  4183. if (netdev->flags & IFF_PROMISC) {
  4184. hw->addr_ctrl.user_set_promisc = true;
  4185. fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
  4186. vmolr |= IXGBE_VMOLR_MPE;
  4187. features &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
  4188. } else {
  4189. if (netdev->flags & IFF_ALLMULTI) {
  4190. fctrl |= IXGBE_FCTRL_MPE;
  4191. vmolr |= IXGBE_VMOLR_MPE;
  4192. }
  4193. hw->addr_ctrl.user_set_promisc = false;
  4194. }
  4195. /*
  4196. * Write addresses to available RAR registers, if there is not
  4197. * sufficient space to store all the addresses then enable
  4198. * unicast promiscuous mode
  4199. */
  4200. if (__dev_uc_sync(netdev, ixgbe_uc_sync, ixgbe_uc_unsync)) {
  4201. fctrl |= IXGBE_FCTRL_UPE;
  4202. vmolr |= IXGBE_VMOLR_ROPE;
  4203. }
  4204. /* Write addresses to the MTA, if the attempt fails
  4205. * then we should just turn on promiscuous mode so
  4206. * that we can at least receive multicast traffic
  4207. */
  4208. count = ixgbe_write_mc_addr_list(netdev);
  4209. if (count < 0) {
  4210. fctrl |= IXGBE_FCTRL_MPE;
  4211. vmolr |= IXGBE_VMOLR_MPE;
  4212. } else if (count) {
  4213. vmolr |= IXGBE_VMOLR_ROMPE;
  4214. }
  4215. if (hw->mac.type != ixgbe_mac_82598EB) {
  4216. vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
  4217. ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
  4218. IXGBE_VMOLR_ROPE);
  4219. IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
  4220. }
  4221. /* This is useful for sniffing bad packets. */
  4222. if (features & NETIF_F_RXALL) {
  4223. /* UPE and MPE will be handled by normal PROMISC logic
  4224. * in e1000e_set_rx_mode */
  4225. fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
  4226. IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
  4227. IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
  4228. fctrl &= ~(IXGBE_FCTRL_DPF);
  4229. /* NOTE: VLAN filtering is disabled by setting PROMISC */
  4230. }
  4231. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  4232. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  4233. ixgbe_vlan_strip_enable(adapter);
  4234. else
  4235. ixgbe_vlan_strip_disable(adapter);
  4236. if (features & NETIF_F_HW_VLAN_CTAG_FILTER)
  4237. ixgbe_vlan_promisc_disable(adapter);
  4238. else
  4239. ixgbe_vlan_promisc_enable(adapter);
  4240. }
  4241. static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
  4242. {
  4243. int q_idx;
  4244. for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
  4245. napi_enable(&adapter->q_vector[q_idx]->napi);
  4246. }
  4247. static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
  4248. {
  4249. int q_idx;
  4250. for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
  4251. napi_disable(&adapter->q_vector[q_idx]->napi);
  4252. }
  4253. static void ixgbe_clear_udp_tunnel_port(struct ixgbe_adapter *adapter, u32 mask)
  4254. {
  4255. struct ixgbe_hw *hw = &adapter->hw;
  4256. u32 vxlanctrl;
  4257. if (!(adapter->flags & (IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE |
  4258. IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)))
  4259. return;
  4260. vxlanctrl = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) & ~mask;
  4261. IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, vxlanctrl);
  4262. if (mask & IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK)
  4263. adapter->vxlan_port = 0;
  4264. if (mask & IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK)
  4265. adapter->geneve_port = 0;
  4266. }
  4267. #ifdef CONFIG_IXGBE_DCB
  4268. /**
  4269. * ixgbe_configure_dcb - Configure DCB hardware
  4270. * @adapter: ixgbe adapter struct
  4271. *
  4272. * This is called by the driver on open to configure the DCB hardware.
  4273. * This is also called by the gennetlink interface when reconfiguring
  4274. * the DCB state.
  4275. */
  4276. static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
  4277. {
  4278. struct ixgbe_hw *hw = &adapter->hw;
  4279. int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  4280. if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
  4281. if (hw->mac.type == ixgbe_mac_82598EB)
  4282. netif_set_gso_max_size(adapter->netdev, 65536);
  4283. return;
  4284. }
  4285. if (hw->mac.type == ixgbe_mac_82598EB)
  4286. netif_set_gso_max_size(adapter->netdev, 32768);
  4287. #ifdef IXGBE_FCOE
  4288. if (adapter->netdev->features & NETIF_F_FCOE_MTU)
  4289. max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
  4290. #endif
  4291. /* reconfigure the hardware */
  4292. if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
  4293. ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
  4294. DCB_TX_CONFIG);
  4295. ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
  4296. DCB_RX_CONFIG);
  4297. ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
  4298. } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
  4299. ixgbe_dcb_hw_ets(&adapter->hw,
  4300. adapter->ixgbe_ieee_ets,
  4301. max_frame);
  4302. ixgbe_dcb_hw_pfc_config(&adapter->hw,
  4303. adapter->ixgbe_ieee_pfc->pfc_en,
  4304. adapter->ixgbe_ieee_ets->prio_tc);
  4305. }
  4306. /* Enable RSS Hash per TC */
  4307. if (hw->mac.type != ixgbe_mac_82598EB) {
  4308. u32 msb = 0;
  4309. u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
  4310. while (rss_i) {
  4311. msb++;
  4312. rss_i >>= 1;
  4313. }
  4314. /* write msb to all 8 TCs in one write */
  4315. IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
  4316. }
  4317. }
  4318. #endif
  4319. /* Additional bittime to account for IXGBE framing */
  4320. #define IXGBE_ETH_FRAMING 20
  4321. /**
  4322. * ixgbe_hpbthresh - calculate high water mark for flow control
  4323. *
  4324. * @adapter: board private structure to calculate for
  4325. * @pb: packet buffer to calculate
  4326. */
  4327. static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
  4328. {
  4329. struct ixgbe_hw *hw = &adapter->hw;
  4330. struct net_device *dev = adapter->netdev;
  4331. int link, tc, kb, marker;
  4332. u32 dv_id, rx_pba;
  4333. /* Calculate max LAN frame size */
  4334. tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
  4335. #ifdef IXGBE_FCOE
  4336. /* FCoE traffic class uses FCOE jumbo frames */
  4337. if ((dev->features & NETIF_F_FCOE_MTU) &&
  4338. (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
  4339. (pb == ixgbe_fcoe_get_tc(adapter)))
  4340. tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
  4341. #endif
  4342. /* Calculate delay value for device */
  4343. switch (hw->mac.type) {
  4344. case ixgbe_mac_X540:
  4345. case ixgbe_mac_X550:
  4346. case ixgbe_mac_X550EM_x:
  4347. case ixgbe_mac_x550em_a:
  4348. dv_id = IXGBE_DV_X540(link, tc);
  4349. break;
  4350. default:
  4351. dv_id = IXGBE_DV(link, tc);
  4352. break;
  4353. }
  4354. /* Loopback switch introduces additional latency */
  4355. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  4356. dv_id += IXGBE_B2BT(tc);
  4357. /* Delay value is calculated in bit times convert to KB */
  4358. kb = IXGBE_BT2KB(dv_id);
  4359. rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
  4360. marker = rx_pba - kb;
  4361. /* It is possible that the packet buffer is not large enough
  4362. * to provide required headroom. In this case throw an error
  4363. * to user and a do the best we can.
  4364. */
  4365. if (marker < 0) {
  4366. e_warn(drv, "Packet Buffer(%i) can not provide enough"
  4367. "headroom to support flow control."
  4368. "Decrease MTU or number of traffic classes\n", pb);
  4369. marker = tc + 1;
  4370. }
  4371. return marker;
  4372. }
  4373. /**
  4374. * ixgbe_lpbthresh - calculate low water mark for for flow control
  4375. *
  4376. * @adapter: board private structure to calculate for
  4377. * @pb: packet buffer to calculate
  4378. */
  4379. static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter, int pb)
  4380. {
  4381. struct ixgbe_hw *hw = &adapter->hw;
  4382. struct net_device *dev = adapter->netdev;
  4383. int tc;
  4384. u32 dv_id;
  4385. /* Calculate max LAN frame size */
  4386. tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
  4387. #ifdef IXGBE_FCOE
  4388. /* FCoE traffic class uses FCOE jumbo frames */
  4389. if ((dev->features & NETIF_F_FCOE_MTU) &&
  4390. (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
  4391. (pb == netdev_get_prio_tc_map(dev, adapter->fcoe.up)))
  4392. tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
  4393. #endif
  4394. /* Calculate delay value for device */
  4395. switch (hw->mac.type) {
  4396. case ixgbe_mac_X540:
  4397. case ixgbe_mac_X550:
  4398. case ixgbe_mac_X550EM_x:
  4399. case ixgbe_mac_x550em_a:
  4400. dv_id = IXGBE_LOW_DV_X540(tc);
  4401. break;
  4402. default:
  4403. dv_id = IXGBE_LOW_DV(tc);
  4404. break;
  4405. }
  4406. /* Delay value is calculated in bit times convert to KB */
  4407. return IXGBE_BT2KB(dv_id);
  4408. }
  4409. /*
  4410. * ixgbe_pbthresh_setup - calculate and setup high low water marks
  4411. */
  4412. static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
  4413. {
  4414. struct ixgbe_hw *hw = &adapter->hw;
  4415. int num_tc = adapter->hw_tcs;
  4416. int i;
  4417. if (!num_tc)
  4418. num_tc = 1;
  4419. for (i = 0; i < num_tc; i++) {
  4420. hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
  4421. hw->fc.low_water[i] = ixgbe_lpbthresh(adapter, i);
  4422. /* Low water marks must not be larger than high water marks */
  4423. if (hw->fc.low_water[i] > hw->fc.high_water[i])
  4424. hw->fc.low_water[i] = 0;
  4425. }
  4426. for (; i < MAX_TRAFFIC_CLASS; i++)
  4427. hw->fc.high_water[i] = 0;
  4428. }
  4429. static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
  4430. {
  4431. struct ixgbe_hw *hw = &adapter->hw;
  4432. int hdrm;
  4433. u8 tc = adapter->hw_tcs;
  4434. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  4435. adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  4436. hdrm = 32 << adapter->fdir_pballoc;
  4437. else
  4438. hdrm = 0;
  4439. hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
  4440. ixgbe_pbthresh_setup(adapter);
  4441. }
  4442. static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
  4443. {
  4444. struct ixgbe_hw *hw = &adapter->hw;
  4445. struct hlist_node *node2;
  4446. struct ixgbe_fdir_filter *filter;
  4447. spin_lock(&adapter->fdir_perfect_lock);
  4448. if (!hlist_empty(&adapter->fdir_filter_list))
  4449. ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
  4450. hlist_for_each_entry_safe(filter, node2,
  4451. &adapter->fdir_filter_list, fdir_node) {
  4452. ixgbe_fdir_write_perfect_filter_82599(hw,
  4453. &filter->filter,
  4454. filter->sw_idx,
  4455. (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
  4456. IXGBE_FDIR_DROP_QUEUE :
  4457. adapter->rx_ring[filter->action]->reg_idx);
  4458. }
  4459. spin_unlock(&adapter->fdir_perfect_lock);
  4460. }
  4461. /**
  4462. * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
  4463. * @rx_ring: ring to free buffers from
  4464. **/
  4465. static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
  4466. {
  4467. u16 i = rx_ring->next_to_clean;
  4468. struct ixgbe_rx_buffer *rx_buffer = &rx_ring->rx_buffer_info[i];
  4469. /* Free all the Rx ring sk_buffs */
  4470. while (i != rx_ring->next_to_alloc) {
  4471. if (rx_buffer->skb) {
  4472. struct sk_buff *skb = rx_buffer->skb;
  4473. if (IXGBE_CB(skb)->page_released)
  4474. dma_unmap_page_attrs(rx_ring->dev,
  4475. IXGBE_CB(skb)->dma,
  4476. ixgbe_rx_pg_size(rx_ring),
  4477. DMA_FROM_DEVICE,
  4478. IXGBE_RX_DMA_ATTR);
  4479. dev_kfree_skb(skb);
  4480. }
  4481. /* Invalidate cache lines that may have been written to by
  4482. * device so that we avoid corrupting memory.
  4483. */
  4484. dma_sync_single_range_for_cpu(rx_ring->dev,
  4485. rx_buffer->dma,
  4486. rx_buffer->page_offset,
  4487. ixgbe_rx_bufsz(rx_ring),
  4488. DMA_FROM_DEVICE);
  4489. /* free resources associated with mapping */
  4490. dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma,
  4491. ixgbe_rx_pg_size(rx_ring),
  4492. DMA_FROM_DEVICE,
  4493. IXGBE_RX_DMA_ATTR);
  4494. __page_frag_cache_drain(rx_buffer->page,
  4495. rx_buffer->pagecnt_bias);
  4496. i++;
  4497. rx_buffer++;
  4498. if (i == rx_ring->count) {
  4499. i = 0;
  4500. rx_buffer = rx_ring->rx_buffer_info;
  4501. }
  4502. }
  4503. rx_ring->next_to_alloc = 0;
  4504. rx_ring->next_to_clean = 0;
  4505. rx_ring->next_to_use = 0;
  4506. }
  4507. static int ixgbe_fwd_ring_up(struct ixgbe_adapter *adapter,
  4508. struct ixgbe_fwd_adapter *accel)
  4509. {
  4510. struct net_device *vdev = accel->netdev;
  4511. int i, baseq, err;
  4512. baseq = accel->pool * adapter->num_rx_queues_per_pool;
  4513. netdev_dbg(vdev, "pool %i:%i queues %i:%i\n",
  4514. accel->pool, adapter->num_rx_pools,
  4515. baseq, baseq + adapter->num_rx_queues_per_pool);
  4516. accel->rx_base_queue = baseq;
  4517. accel->tx_base_queue = baseq;
  4518. for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
  4519. adapter->rx_ring[baseq + i]->netdev = vdev;
  4520. /* Guarantee all rings are updated before we update the
  4521. * MAC address filter.
  4522. */
  4523. wmb();
  4524. /* ixgbe_add_mac_filter will return an index if it succeeds, so we
  4525. * need to only treat it as an error value if it is negative.
  4526. */
  4527. err = ixgbe_add_mac_filter(adapter, vdev->dev_addr,
  4528. VMDQ_P(accel->pool));
  4529. if (err >= 0)
  4530. return 0;
  4531. /* if we cannot add the MAC rule then disable the offload */
  4532. macvlan_release_l2fw_offload(vdev);
  4533. for (i = 0; i < adapter->num_rx_queues_per_pool; i++)
  4534. adapter->rx_ring[baseq + i]->netdev = NULL;
  4535. netdev_err(vdev, "L2FW offload disabled due to L2 filter error\n");
  4536. clear_bit(accel->pool, adapter->fwd_bitmask);
  4537. kfree(accel);
  4538. return err;
  4539. }
  4540. static int ixgbe_macvlan_up(struct net_device *vdev, void *data)
  4541. {
  4542. struct ixgbe_adapter *adapter = data;
  4543. struct ixgbe_fwd_adapter *accel;
  4544. if (!netif_is_macvlan(vdev))
  4545. return 0;
  4546. accel = macvlan_accel_priv(vdev);
  4547. if (!accel)
  4548. return 0;
  4549. ixgbe_fwd_ring_up(adapter, accel);
  4550. return 0;
  4551. }
  4552. static void ixgbe_configure_dfwd(struct ixgbe_adapter *adapter)
  4553. {
  4554. netdev_walk_all_upper_dev_rcu(adapter->netdev,
  4555. ixgbe_macvlan_up, adapter);
  4556. }
  4557. static void ixgbe_configure(struct ixgbe_adapter *adapter)
  4558. {
  4559. struct ixgbe_hw *hw = &adapter->hw;
  4560. ixgbe_configure_pb(adapter);
  4561. #ifdef CONFIG_IXGBE_DCB
  4562. ixgbe_configure_dcb(adapter);
  4563. #endif
  4564. /*
  4565. * We must restore virtualization before VLANs or else
  4566. * the VLVF registers will not be populated
  4567. */
  4568. ixgbe_configure_virtualization(adapter);
  4569. ixgbe_set_rx_mode(adapter->netdev);
  4570. ixgbe_restore_vlan(adapter);
  4571. ixgbe_ipsec_restore(adapter);
  4572. switch (hw->mac.type) {
  4573. case ixgbe_mac_82599EB:
  4574. case ixgbe_mac_X540:
  4575. hw->mac.ops.disable_rx_buff(hw);
  4576. break;
  4577. default:
  4578. break;
  4579. }
  4580. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  4581. ixgbe_init_fdir_signature_82599(&adapter->hw,
  4582. adapter->fdir_pballoc);
  4583. } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
  4584. ixgbe_init_fdir_perfect_82599(&adapter->hw,
  4585. adapter->fdir_pballoc);
  4586. ixgbe_fdir_filter_restore(adapter);
  4587. }
  4588. switch (hw->mac.type) {
  4589. case ixgbe_mac_82599EB:
  4590. case ixgbe_mac_X540:
  4591. hw->mac.ops.enable_rx_buff(hw);
  4592. break;
  4593. default:
  4594. break;
  4595. }
  4596. #ifdef CONFIG_IXGBE_DCA
  4597. /* configure DCA */
  4598. if (adapter->flags & IXGBE_FLAG_DCA_CAPABLE)
  4599. ixgbe_setup_dca(adapter);
  4600. #endif /* CONFIG_IXGBE_DCA */
  4601. #ifdef IXGBE_FCOE
  4602. /* configure FCoE L2 filters, redirection table, and Rx control */
  4603. ixgbe_configure_fcoe(adapter);
  4604. #endif /* IXGBE_FCOE */
  4605. ixgbe_configure_tx(adapter);
  4606. ixgbe_configure_rx(adapter);
  4607. ixgbe_configure_dfwd(adapter);
  4608. }
  4609. /**
  4610. * ixgbe_sfp_link_config - set up SFP+ link
  4611. * @adapter: pointer to private adapter struct
  4612. **/
  4613. static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
  4614. {
  4615. /*
  4616. * We are assuming the worst case scenario here, and that
  4617. * is that an SFP was inserted/removed after the reset
  4618. * but before SFP detection was enabled. As such the best
  4619. * solution is to just start searching as soon as we start
  4620. */
  4621. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  4622. adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
  4623. adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
  4624. adapter->sfp_poll_time = 0;
  4625. }
  4626. /**
  4627. * ixgbe_non_sfp_link_config - set up non-SFP+ link
  4628. * @hw: pointer to private hardware struct
  4629. *
  4630. * Returns 0 on success, negative on failure
  4631. **/
  4632. static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
  4633. {
  4634. u32 speed;
  4635. bool autoneg, link_up = false;
  4636. int ret = IXGBE_ERR_LINK_SETUP;
  4637. if (hw->mac.ops.check_link)
  4638. ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
  4639. if (ret)
  4640. return ret;
  4641. speed = hw->phy.autoneg_advertised;
  4642. if ((!speed) && (hw->mac.ops.get_link_capabilities))
  4643. ret = hw->mac.ops.get_link_capabilities(hw, &speed,
  4644. &autoneg);
  4645. if (ret)
  4646. return ret;
  4647. if (hw->mac.ops.setup_link)
  4648. ret = hw->mac.ops.setup_link(hw, speed, link_up);
  4649. return ret;
  4650. }
  4651. static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
  4652. {
  4653. struct ixgbe_hw *hw = &adapter->hw;
  4654. u32 gpie = 0;
  4655. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  4656. gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
  4657. IXGBE_GPIE_OCD;
  4658. gpie |= IXGBE_GPIE_EIAME;
  4659. /*
  4660. * use EIAM to auto-mask when MSI-X interrupt is asserted
  4661. * this saves a register write for every interrupt
  4662. */
  4663. switch (hw->mac.type) {
  4664. case ixgbe_mac_82598EB:
  4665. IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
  4666. break;
  4667. case ixgbe_mac_82599EB:
  4668. case ixgbe_mac_X540:
  4669. case ixgbe_mac_X550:
  4670. case ixgbe_mac_X550EM_x:
  4671. case ixgbe_mac_x550em_a:
  4672. default:
  4673. IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
  4674. IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
  4675. break;
  4676. }
  4677. } else {
  4678. /* legacy interrupts, use EIAM to auto-mask when reading EICR,
  4679. * specifically only auto mask tx and rx interrupts */
  4680. IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
  4681. }
  4682. /* XXX: to interrupt immediately for EICS writes, enable this */
  4683. /* gpie |= IXGBE_GPIE_EIMEN; */
  4684. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  4685. gpie &= ~IXGBE_GPIE_VTMODE_MASK;
  4686. switch (adapter->ring_feature[RING_F_VMDQ].mask) {
  4687. case IXGBE_82599_VMDQ_8Q_MASK:
  4688. gpie |= IXGBE_GPIE_VTMODE_16;
  4689. break;
  4690. case IXGBE_82599_VMDQ_4Q_MASK:
  4691. gpie |= IXGBE_GPIE_VTMODE_32;
  4692. break;
  4693. default:
  4694. gpie |= IXGBE_GPIE_VTMODE_64;
  4695. break;
  4696. }
  4697. }
  4698. /* Enable Thermal over heat sensor interrupt */
  4699. if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
  4700. switch (adapter->hw.mac.type) {
  4701. case ixgbe_mac_82599EB:
  4702. gpie |= IXGBE_SDP0_GPIEN_8259X;
  4703. break;
  4704. default:
  4705. break;
  4706. }
  4707. }
  4708. /* Enable fan failure interrupt */
  4709. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
  4710. gpie |= IXGBE_SDP1_GPIEN(hw);
  4711. switch (hw->mac.type) {
  4712. case ixgbe_mac_82599EB:
  4713. gpie |= IXGBE_SDP1_GPIEN_8259X | IXGBE_SDP2_GPIEN_8259X;
  4714. break;
  4715. case ixgbe_mac_X550EM_x:
  4716. case ixgbe_mac_x550em_a:
  4717. gpie |= IXGBE_SDP0_GPIEN_X540;
  4718. break;
  4719. default:
  4720. break;
  4721. }
  4722. IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
  4723. }
  4724. static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
  4725. {
  4726. struct ixgbe_hw *hw = &adapter->hw;
  4727. int err;
  4728. u32 ctrl_ext;
  4729. ixgbe_get_hw_control(adapter);
  4730. ixgbe_setup_gpie(adapter);
  4731. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  4732. ixgbe_configure_msix(adapter);
  4733. else
  4734. ixgbe_configure_msi_and_legacy(adapter);
  4735. /* enable the optics for 82599 SFP+ fiber */
  4736. if (hw->mac.ops.enable_tx_laser)
  4737. hw->mac.ops.enable_tx_laser(hw);
  4738. if (hw->phy.ops.set_phy_power)
  4739. hw->phy.ops.set_phy_power(hw, true);
  4740. smp_mb__before_atomic();
  4741. clear_bit(__IXGBE_DOWN, &adapter->state);
  4742. ixgbe_napi_enable_all(adapter);
  4743. if (ixgbe_is_sfp(hw)) {
  4744. ixgbe_sfp_link_config(adapter);
  4745. } else {
  4746. err = ixgbe_non_sfp_link_config(hw);
  4747. if (err)
  4748. e_err(probe, "link_config FAILED %d\n", err);
  4749. }
  4750. /* clear any pending interrupts, may auto mask */
  4751. IXGBE_READ_REG(hw, IXGBE_EICR);
  4752. ixgbe_irq_enable(adapter, true, true);
  4753. /*
  4754. * If this adapter has a fan, check to see if we had a failure
  4755. * before we enabled the interrupt.
  4756. */
  4757. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  4758. u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  4759. if (esdp & IXGBE_ESDP_SDP1)
  4760. e_crit(drv, "Fan has stopped, replace the adapter\n");
  4761. }
  4762. /* bring the link up in the watchdog, this could race with our first
  4763. * link up interrupt but shouldn't be a problem */
  4764. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  4765. adapter->link_check_timeout = jiffies;
  4766. mod_timer(&adapter->service_timer, jiffies);
  4767. /* Set PF Reset Done bit so PF/VF Mail Ops can work */
  4768. ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
  4769. ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
  4770. IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
  4771. }
  4772. void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
  4773. {
  4774. WARN_ON(in_interrupt());
  4775. /* put off any impending NetWatchDogTimeout */
  4776. netif_trans_update(adapter->netdev);
  4777. while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
  4778. usleep_range(1000, 2000);
  4779. if (adapter->hw.phy.type == ixgbe_phy_fw)
  4780. ixgbe_watchdog_link_is_down(adapter);
  4781. ixgbe_down(adapter);
  4782. /*
  4783. * If SR-IOV enabled then wait a bit before bringing the adapter
  4784. * back up to give the VFs time to respond to the reset. The
  4785. * two second wait is based upon the watchdog timer cycle in
  4786. * the VF driver.
  4787. */
  4788. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  4789. msleep(2000);
  4790. ixgbe_up(adapter);
  4791. clear_bit(__IXGBE_RESETTING, &adapter->state);
  4792. }
  4793. void ixgbe_up(struct ixgbe_adapter *adapter)
  4794. {
  4795. /* hardware has been reset, we need to reload some things */
  4796. ixgbe_configure(adapter);
  4797. ixgbe_up_complete(adapter);
  4798. }
  4799. void ixgbe_reset(struct ixgbe_adapter *adapter)
  4800. {
  4801. struct ixgbe_hw *hw = &adapter->hw;
  4802. struct net_device *netdev = adapter->netdev;
  4803. int err;
  4804. if (ixgbe_removed(hw->hw_addr))
  4805. return;
  4806. /* lock SFP init bit to prevent race conditions with the watchdog */
  4807. while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
  4808. usleep_range(1000, 2000);
  4809. /* clear all SFP and link config related flags while holding SFP_INIT */
  4810. adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
  4811. IXGBE_FLAG2_SFP_NEEDS_RESET);
  4812. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
  4813. err = hw->mac.ops.init_hw(hw);
  4814. switch (err) {
  4815. case 0:
  4816. case IXGBE_ERR_SFP_NOT_PRESENT:
  4817. case IXGBE_ERR_SFP_NOT_SUPPORTED:
  4818. break;
  4819. case IXGBE_ERR_MASTER_REQUESTS_PENDING:
  4820. e_dev_err("master disable timed out\n");
  4821. break;
  4822. case IXGBE_ERR_EEPROM_VERSION:
  4823. /* We are running on a pre-production device, log a warning */
  4824. e_dev_warn("This device is a pre-production adapter/LOM. "
  4825. "Please be aware there may be issues associated with "
  4826. "your hardware. If you are experiencing problems "
  4827. "please contact your Intel or hardware "
  4828. "representative who provided you with this "
  4829. "hardware.\n");
  4830. break;
  4831. default:
  4832. e_dev_err("Hardware Error: %d\n", err);
  4833. }
  4834. clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
  4835. /* flush entries out of MAC table */
  4836. ixgbe_flush_sw_mac_table(adapter);
  4837. __dev_uc_unsync(netdev, NULL);
  4838. /* do not flush user set addresses */
  4839. ixgbe_mac_set_default_filter(adapter);
  4840. /* update SAN MAC vmdq pool selection */
  4841. if (hw->mac.san_mac_rar_index)
  4842. hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
  4843. if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
  4844. ixgbe_ptp_reset(adapter);
  4845. if (hw->phy.ops.set_phy_power) {
  4846. if (!netif_running(adapter->netdev) && !adapter->wol)
  4847. hw->phy.ops.set_phy_power(hw, false);
  4848. else
  4849. hw->phy.ops.set_phy_power(hw, true);
  4850. }
  4851. }
  4852. /**
  4853. * ixgbe_clean_tx_ring - Free Tx Buffers
  4854. * @tx_ring: ring to be cleaned
  4855. **/
  4856. static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
  4857. {
  4858. u16 i = tx_ring->next_to_clean;
  4859. struct ixgbe_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i];
  4860. while (i != tx_ring->next_to_use) {
  4861. union ixgbe_adv_tx_desc *eop_desc, *tx_desc;
  4862. /* Free all the Tx ring sk_buffs */
  4863. if (ring_is_xdp(tx_ring))
  4864. xdp_return_frame(tx_buffer->xdpf);
  4865. else
  4866. dev_kfree_skb_any(tx_buffer->skb);
  4867. /* unmap skb header data */
  4868. dma_unmap_single(tx_ring->dev,
  4869. dma_unmap_addr(tx_buffer, dma),
  4870. dma_unmap_len(tx_buffer, len),
  4871. DMA_TO_DEVICE);
  4872. /* check for eop_desc to determine the end of the packet */
  4873. eop_desc = tx_buffer->next_to_watch;
  4874. tx_desc = IXGBE_TX_DESC(tx_ring, i);
  4875. /* unmap remaining buffers */
  4876. while (tx_desc != eop_desc) {
  4877. tx_buffer++;
  4878. tx_desc++;
  4879. i++;
  4880. if (unlikely(i == tx_ring->count)) {
  4881. i = 0;
  4882. tx_buffer = tx_ring->tx_buffer_info;
  4883. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  4884. }
  4885. /* unmap any remaining paged data */
  4886. if (dma_unmap_len(tx_buffer, len))
  4887. dma_unmap_page(tx_ring->dev,
  4888. dma_unmap_addr(tx_buffer, dma),
  4889. dma_unmap_len(tx_buffer, len),
  4890. DMA_TO_DEVICE);
  4891. }
  4892. /* move us one more past the eop_desc for start of next pkt */
  4893. tx_buffer++;
  4894. i++;
  4895. if (unlikely(i == tx_ring->count)) {
  4896. i = 0;
  4897. tx_buffer = tx_ring->tx_buffer_info;
  4898. }
  4899. }
  4900. /* reset BQL for queue */
  4901. if (!ring_is_xdp(tx_ring))
  4902. netdev_tx_reset_queue(txring_txq(tx_ring));
  4903. /* reset next_to_use and next_to_clean */
  4904. tx_ring->next_to_use = 0;
  4905. tx_ring->next_to_clean = 0;
  4906. }
  4907. /**
  4908. * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
  4909. * @adapter: board private structure
  4910. **/
  4911. static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
  4912. {
  4913. int i;
  4914. for (i = 0; i < adapter->num_rx_queues; i++)
  4915. ixgbe_clean_rx_ring(adapter->rx_ring[i]);
  4916. }
  4917. /**
  4918. * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
  4919. * @adapter: board private structure
  4920. **/
  4921. static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
  4922. {
  4923. int i;
  4924. for (i = 0; i < adapter->num_tx_queues; i++)
  4925. ixgbe_clean_tx_ring(adapter->tx_ring[i]);
  4926. for (i = 0; i < adapter->num_xdp_queues; i++)
  4927. ixgbe_clean_tx_ring(adapter->xdp_ring[i]);
  4928. }
  4929. static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
  4930. {
  4931. struct hlist_node *node2;
  4932. struct ixgbe_fdir_filter *filter;
  4933. spin_lock(&adapter->fdir_perfect_lock);
  4934. hlist_for_each_entry_safe(filter, node2,
  4935. &adapter->fdir_filter_list, fdir_node) {
  4936. hlist_del(&filter->fdir_node);
  4937. kfree(filter);
  4938. }
  4939. adapter->fdir_filter_count = 0;
  4940. spin_unlock(&adapter->fdir_perfect_lock);
  4941. }
  4942. void ixgbe_down(struct ixgbe_adapter *adapter)
  4943. {
  4944. struct net_device *netdev = adapter->netdev;
  4945. struct ixgbe_hw *hw = &adapter->hw;
  4946. int i;
  4947. /* signal that we are down to the interrupt handler */
  4948. if (test_and_set_bit(__IXGBE_DOWN, &adapter->state))
  4949. return; /* do nothing if already down */
  4950. /* disable receives */
  4951. hw->mac.ops.disable_rx(hw);
  4952. /* disable all enabled rx queues */
  4953. for (i = 0; i < adapter->num_rx_queues; i++)
  4954. /* this call also flushes the previous write */
  4955. ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
  4956. usleep_range(10000, 20000);
  4957. /* synchronize_sched() needed for pending XDP buffers to drain */
  4958. if (adapter->xdp_ring[0])
  4959. synchronize_sched();
  4960. netif_tx_stop_all_queues(netdev);
  4961. /* call carrier off first to avoid false dev_watchdog timeouts */
  4962. netif_carrier_off(netdev);
  4963. netif_tx_disable(netdev);
  4964. ixgbe_irq_disable(adapter);
  4965. ixgbe_napi_disable_all(adapter);
  4966. clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  4967. adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
  4968. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
  4969. del_timer_sync(&adapter->service_timer);
  4970. if (adapter->num_vfs) {
  4971. /* Clear EITR Select mapping */
  4972. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
  4973. /* Mark all the VFs as inactive */
  4974. for (i = 0 ; i < adapter->num_vfs; i++)
  4975. adapter->vfinfo[i].clear_to_send = false;
  4976. /* ping all the active vfs to let them know we are going down */
  4977. ixgbe_ping_all_vfs(adapter);
  4978. /* Disable all VFTE/VFRE TX/RX */
  4979. ixgbe_disable_tx_rx(adapter);
  4980. }
  4981. /* disable transmits in the hardware now that interrupts are off */
  4982. for (i = 0; i < adapter->num_tx_queues; i++) {
  4983. u8 reg_idx = adapter->tx_ring[i]->reg_idx;
  4984. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
  4985. }
  4986. for (i = 0; i < adapter->num_xdp_queues; i++) {
  4987. u8 reg_idx = adapter->xdp_ring[i]->reg_idx;
  4988. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
  4989. }
  4990. /* Disable the Tx DMA engine on 82599 and later MAC */
  4991. switch (hw->mac.type) {
  4992. case ixgbe_mac_82599EB:
  4993. case ixgbe_mac_X540:
  4994. case ixgbe_mac_X550:
  4995. case ixgbe_mac_X550EM_x:
  4996. case ixgbe_mac_x550em_a:
  4997. IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
  4998. (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
  4999. ~IXGBE_DMATXCTL_TE));
  5000. break;
  5001. default:
  5002. break;
  5003. }
  5004. if (!pci_channel_offline(adapter->pdev))
  5005. ixgbe_reset(adapter);
  5006. /* power down the optics for 82599 SFP+ fiber */
  5007. if (hw->mac.ops.disable_tx_laser)
  5008. hw->mac.ops.disable_tx_laser(hw);
  5009. ixgbe_clean_all_tx_rings(adapter);
  5010. ixgbe_clean_all_rx_rings(adapter);
  5011. }
  5012. /**
  5013. * ixgbe_eee_capable - helper function to determine EEE support on X550
  5014. * @adapter: board private structure
  5015. */
  5016. static void ixgbe_set_eee_capable(struct ixgbe_adapter *adapter)
  5017. {
  5018. struct ixgbe_hw *hw = &adapter->hw;
  5019. switch (hw->device_id) {
  5020. case IXGBE_DEV_ID_X550EM_A_1G_T:
  5021. case IXGBE_DEV_ID_X550EM_A_1G_T_L:
  5022. if (!hw->phy.eee_speeds_supported)
  5023. break;
  5024. adapter->flags2 |= IXGBE_FLAG2_EEE_CAPABLE;
  5025. if (!hw->phy.eee_speeds_advertised)
  5026. break;
  5027. adapter->flags2 |= IXGBE_FLAG2_EEE_ENABLED;
  5028. break;
  5029. default:
  5030. adapter->flags2 &= ~IXGBE_FLAG2_EEE_CAPABLE;
  5031. adapter->flags2 &= ~IXGBE_FLAG2_EEE_ENABLED;
  5032. break;
  5033. }
  5034. }
  5035. /**
  5036. * ixgbe_tx_timeout - Respond to a Tx Hang
  5037. * @netdev: network interface device structure
  5038. **/
  5039. static void ixgbe_tx_timeout(struct net_device *netdev)
  5040. {
  5041. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5042. /* Do the reset outside of interrupt context */
  5043. ixgbe_tx_timeout_reset(adapter);
  5044. }
  5045. #ifdef CONFIG_IXGBE_DCB
  5046. static void ixgbe_init_dcb(struct ixgbe_adapter *adapter)
  5047. {
  5048. struct ixgbe_hw *hw = &adapter->hw;
  5049. struct tc_configuration *tc;
  5050. int j;
  5051. switch (hw->mac.type) {
  5052. case ixgbe_mac_82598EB:
  5053. case ixgbe_mac_82599EB:
  5054. adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
  5055. adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
  5056. break;
  5057. case ixgbe_mac_X540:
  5058. case ixgbe_mac_X550:
  5059. adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
  5060. adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
  5061. break;
  5062. case ixgbe_mac_X550EM_x:
  5063. case ixgbe_mac_x550em_a:
  5064. default:
  5065. adapter->dcb_cfg.num_tcs.pg_tcs = DEF_TRAFFIC_CLASS;
  5066. adapter->dcb_cfg.num_tcs.pfc_tcs = DEF_TRAFFIC_CLASS;
  5067. break;
  5068. }
  5069. /* Configure DCB traffic classes */
  5070. for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
  5071. tc = &adapter->dcb_cfg.tc_config[j];
  5072. tc->path[DCB_TX_CONFIG].bwg_id = 0;
  5073. tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
  5074. tc->path[DCB_RX_CONFIG].bwg_id = 0;
  5075. tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
  5076. tc->dcb_pfc = pfc_disabled;
  5077. }
  5078. /* Initialize default user to priority mapping, UPx->TC0 */
  5079. tc = &adapter->dcb_cfg.tc_config[0];
  5080. tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
  5081. tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
  5082. adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
  5083. adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
  5084. adapter->dcb_cfg.pfc_mode_enable = false;
  5085. adapter->dcb_set_bitmap = 0x00;
  5086. if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
  5087. adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
  5088. memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
  5089. sizeof(adapter->temp_dcb_cfg));
  5090. }
  5091. #endif
  5092. /**
  5093. * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
  5094. * @adapter: board private structure to initialize
  5095. * @ii: pointer to ixgbe_info for device
  5096. *
  5097. * ixgbe_sw_init initializes the Adapter private data structure.
  5098. * Fields are initialized based on PCI device information and
  5099. * OS network device settings (MTU size).
  5100. **/
  5101. static int ixgbe_sw_init(struct ixgbe_adapter *adapter,
  5102. const struct ixgbe_info *ii)
  5103. {
  5104. struct ixgbe_hw *hw = &adapter->hw;
  5105. struct pci_dev *pdev = adapter->pdev;
  5106. unsigned int rss, fdir;
  5107. u32 fwsm;
  5108. int i;
  5109. /* PCI config space info */
  5110. hw->vendor_id = pdev->vendor;
  5111. hw->device_id = pdev->device;
  5112. hw->revision_id = pdev->revision;
  5113. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  5114. hw->subsystem_device_id = pdev->subsystem_device;
  5115. /* get_invariants needs the device IDs */
  5116. ii->get_invariants(hw);
  5117. /* Set common capability flags and settings */
  5118. rss = min_t(int, ixgbe_max_rss_indices(adapter), num_online_cpus());
  5119. adapter->ring_feature[RING_F_RSS].limit = rss;
  5120. adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
  5121. adapter->max_q_vectors = MAX_Q_VECTORS_82599;
  5122. adapter->atr_sample_rate = 20;
  5123. fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
  5124. adapter->ring_feature[RING_F_FDIR].limit = fdir;
  5125. adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
  5126. adapter->ring_feature[RING_F_VMDQ].limit = 1;
  5127. #ifdef CONFIG_IXGBE_DCA
  5128. adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
  5129. #endif
  5130. #ifdef CONFIG_IXGBE_DCB
  5131. adapter->flags |= IXGBE_FLAG_DCB_CAPABLE;
  5132. adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
  5133. #endif
  5134. #ifdef IXGBE_FCOE
  5135. adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
  5136. adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
  5137. #ifdef CONFIG_IXGBE_DCB
  5138. /* Default traffic class to use for FCoE */
  5139. adapter->fcoe.up = IXGBE_FCOE_DEFTC;
  5140. #endif /* CONFIG_IXGBE_DCB */
  5141. #endif /* IXGBE_FCOE */
  5142. /* initialize static ixgbe jump table entries */
  5143. adapter->jump_tables[0] = kzalloc(sizeof(*adapter->jump_tables[0]),
  5144. GFP_KERNEL);
  5145. if (!adapter->jump_tables[0])
  5146. return -ENOMEM;
  5147. adapter->jump_tables[0]->mat = ixgbe_ipv4_fields;
  5148. for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++)
  5149. adapter->jump_tables[i] = NULL;
  5150. adapter->mac_table = kcalloc(hw->mac.num_rar_entries,
  5151. sizeof(struct ixgbe_mac_addr),
  5152. GFP_ATOMIC);
  5153. if (!adapter->mac_table)
  5154. return -ENOMEM;
  5155. if (ixgbe_init_rss_key(adapter))
  5156. return -ENOMEM;
  5157. /* Set MAC specific capability flags and exceptions */
  5158. switch (hw->mac.type) {
  5159. case ixgbe_mac_82598EB:
  5160. adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
  5161. if (hw->device_id == IXGBE_DEV_ID_82598AT)
  5162. adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
  5163. adapter->max_q_vectors = MAX_Q_VECTORS_82598;
  5164. adapter->ring_feature[RING_F_FDIR].limit = 0;
  5165. adapter->atr_sample_rate = 0;
  5166. adapter->fdir_pballoc = 0;
  5167. #ifdef IXGBE_FCOE
  5168. adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
  5169. adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
  5170. #ifdef CONFIG_IXGBE_DCB
  5171. adapter->fcoe.up = 0;
  5172. #endif /* IXGBE_DCB */
  5173. #endif /* IXGBE_FCOE */
  5174. break;
  5175. case ixgbe_mac_82599EB:
  5176. if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
  5177. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  5178. break;
  5179. case ixgbe_mac_X540:
  5180. fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
  5181. if (fwsm & IXGBE_FWSM_TS_ENABLED)
  5182. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  5183. break;
  5184. case ixgbe_mac_x550em_a:
  5185. adapter->flags |= IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE;
  5186. switch (hw->device_id) {
  5187. case IXGBE_DEV_ID_X550EM_A_1G_T:
  5188. case IXGBE_DEV_ID_X550EM_A_1G_T_L:
  5189. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  5190. break;
  5191. default:
  5192. break;
  5193. }
  5194. /* fall through */
  5195. case ixgbe_mac_X550EM_x:
  5196. #ifdef CONFIG_IXGBE_DCB
  5197. adapter->flags &= ~IXGBE_FLAG_DCB_CAPABLE;
  5198. #endif
  5199. #ifdef IXGBE_FCOE
  5200. adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
  5201. #ifdef CONFIG_IXGBE_DCB
  5202. adapter->fcoe.up = 0;
  5203. #endif /* IXGBE_DCB */
  5204. #endif /* IXGBE_FCOE */
  5205. /* Fall Through */
  5206. case ixgbe_mac_X550:
  5207. if (hw->mac.type == ixgbe_mac_X550)
  5208. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  5209. #ifdef CONFIG_IXGBE_DCA
  5210. adapter->flags &= ~IXGBE_FLAG_DCA_CAPABLE;
  5211. #endif
  5212. adapter->flags |= IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE;
  5213. break;
  5214. default:
  5215. break;
  5216. }
  5217. #ifdef IXGBE_FCOE
  5218. /* FCoE support exists, always init the FCoE lock */
  5219. spin_lock_init(&adapter->fcoe.lock);
  5220. #endif
  5221. /* n-tuple support exists, always init our spinlock */
  5222. spin_lock_init(&adapter->fdir_perfect_lock);
  5223. #ifdef CONFIG_IXGBE_DCB
  5224. ixgbe_init_dcb(adapter);
  5225. #endif
  5226. ixgbe_init_ipsec_offload(adapter);
  5227. /* default flow control settings */
  5228. hw->fc.requested_mode = ixgbe_fc_full;
  5229. hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
  5230. ixgbe_pbthresh_setup(adapter);
  5231. hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
  5232. hw->fc.send_xon = true;
  5233. hw->fc.disable_fc_autoneg = ixgbe_device_supports_autoneg_fc(hw);
  5234. #ifdef CONFIG_PCI_IOV
  5235. if (max_vfs > 0)
  5236. e_dev_warn("Enabling SR-IOV VFs using the max_vfs module parameter is deprecated - please use the pci sysfs interface instead.\n");
  5237. /* assign number of SR-IOV VFs */
  5238. if (hw->mac.type != ixgbe_mac_82598EB) {
  5239. if (max_vfs > IXGBE_MAX_VFS_DRV_LIMIT) {
  5240. max_vfs = 0;
  5241. e_dev_warn("max_vfs parameter out of range. Not assigning any SR-IOV VFs\n");
  5242. }
  5243. }
  5244. #endif /* CONFIG_PCI_IOV */
  5245. /* enable itr by default in dynamic mode */
  5246. adapter->rx_itr_setting = 1;
  5247. adapter->tx_itr_setting = 1;
  5248. /* set default ring sizes */
  5249. adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
  5250. adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
  5251. /* set default work limits */
  5252. adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
  5253. /* initialize eeprom parameters */
  5254. if (ixgbe_init_eeprom_params_generic(hw)) {
  5255. e_dev_err("EEPROM initialization failed\n");
  5256. return -EIO;
  5257. }
  5258. /* PF holds first pool slot */
  5259. set_bit(0, adapter->fwd_bitmask);
  5260. set_bit(__IXGBE_DOWN, &adapter->state);
  5261. return 0;
  5262. }
  5263. /**
  5264. * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
  5265. * @tx_ring: tx descriptor ring (for a specific queue) to setup
  5266. *
  5267. * Return 0 on success, negative on failure
  5268. **/
  5269. int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
  5270. {
  5271. struct device *dev = tx_ring->dev;
  5272. int orig_node = dev_to_node(dev);
  5273. int ring_node = -1;
  5274. int size;
  5275. size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
  5276. if (tx_ring->q_vector)
  5277. ring_node = tx_ring->q_vector->numa_node;
  5278. tx_ring->tx_buffer_info = vmalloc_node(size, ring_node);
  5279. if (!tx_ring->tx_buffer_info)
  5280. tx_ring->tx_buffer_info = vmalloc(size);
  5281. if (!tx_ring->tx_buffer_info)
  5282. goto err;
  5283. /* round up to nearest 4K */
  5284. tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
  5285. tx_ring->size = ALIGN(tx_ring->size, 4096);
  5286. set_dev_node(dev, ring_node);
  5287. tx_ring->desc = dma_alloc_coherent(dev,
  5288. tx_ring->size,
  5289. &tx_ring->dma,
  5290. GFP_KERNEL);
  5291. set_dev_node(dev, orig_node);
  5292. if (!tx_ring->desc)
  5293. tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
  5294. &tx_ring->dma, GFP_KERNEL);
  5295. if (!tx_ring->desc)
  5296. goto err;
  5297. tx_ring->next_to_use = 0;
  5298. tx_ring->next_to_clean = 0;
  5299. return 0;
  5300. err:
  5301. vfree(tx_ring->tx_buffer_info);
  5302. tx_ring->tx_buffer_info = NULL;
  5303. dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
  5304. return -ENOMEM;
  5305. }
  5306. /**
  5307. * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
  5308. * @adapter: board private structure
  5309. *
  5310. * If this function returns with an error, then it's possible one or
  5311. * more of the rings is populated (while the rest are not). It is the
  5312. * callers duty to clean those orphaned rings.
  5313. *
  5314. * Return 0 on success, negative on failure
  5315. **/
  5316. static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
  5317. {
  5318. int i, j = 0, err = 0;
  5319. for (i = 0; i < adapter->num_tx_queues; i++) {
  5320. err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
  5321. if (!err)
  5322. continue;
  5323. e_err(probe, "Allocation for Tx Queue %u failed\n", i);
  5324. goto err_setup_tx;
  5325. }
  5326. for (j = 0; j < adapter->num_xdp_queues; j++) {
  5327. err = ixgbe_setup_tx_resources(adapter->xdp_ring[j]);
  5328. if (!err)
  5329. continue;
  5330. e_err(probe, "Allocation for Tx Queue %u failed\n", j);
  5331. goto err_setup_tx;
  5332. }
  5333. return 0;
  5334. err_setup_tx:
  5335. /* rewind the index freeing the rings as we go */
  5336. while (j--)
  5337. ixgbe_free_tx_resources(adapter->xdp_ring[j]);
  5338. while (i--)
  5339. ixgbe_free_tx_resources(adapter->tx_ring[i]);
  5340. return err;
  5341. }
  5342. /**
  5343. * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
  5344. * @adapter: pointer to ixgbe_adapter
  5345. * @rx_ring: rx descriptor ring (for a specific queue) to setup
  5346. *
  5347. * Returns 0 on success, negative on failure
  5348. **/
  5349. int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter,
  5350. struct ixgbe_ring *rx_ring)
  5351. {
  5352. struct device *dev = rx_ring->dev;
  5353. int orig_node = dev_to_node(dev);
  5354. int ring_node = -1;
  5355. int size, err;
  5356. size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
  5357. if (rx_ring->q_vector)
  5358. ring_node = rx_ring->q_vector->numa_node;
  5359. rx_ring->rx_buffer_info = vmalloc_node(size, ring_node);
  5360. if (!rx_ring->rx_buffer_info)
  5361. rx_ring->rx_buffer_info = vmalloc(size);
  5362. if (!rx_ring->rx_buffer_info)
  5363. goto err;
  5364. /* Round up to nearest 4K */
  5365. rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
  5366. rx_ring->size = ALIGN(rx_ring->size, 4096);
  5367. set_dev_node(dev, ring_node);
  5368. rx_ring->desc = dma_alloc_coherent(dev,
  5369. rx_ring->size,
  5370. &rx_ring->dma,
  5371. GFP_KERNEL);
  5372. set_dev_node(dev, orig_node);
  5373. if (!rx_ring->desc)
  5374. rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
  5375. &rx_ring->dma, GFP_KERNEL);
  5376. if (!rx_ring->desc)
  5377. goto err;
  5378. rx_ring->next_to_clean = 0;
  5379. rx_ring->next_to_use = 0;
  5380. /* XDP RX-queue info */
  5381. if (xdp_rxq_info_reg(&rx_ring->xdp_rxq, adapter->netdev,
  5382. rx_ring->queue_index) < 0)
  5383. goto err;
  5384. err = xdp_rxq_info_reg_mem_model(&rx_ring->xdp_rxq,
  5385. MEM_TYPE_PAGE_SHARED, NULL);
  5386. if (err) {
  5387. xdp_rxq_info_unreg(&rx_ring->xdp_rxq);
  5388. goto err;
  5389. }
  5390. rx_ring->xdp_prog = adapter->xdp_prog;
  5391. return 0;
  5392. err:
  5393. vfree(rx_ring->rx_buffer_info);
  5394. rx_ring->rx_buffer_info = NULL;
  5395. dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
  5396. return -ENOMEM;
  5397. }
  5398. /**
  5399. * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
  5400. * @adapter: board private structure
  5401. *
  5402. * If this function returns with an error, then it's possible one or
  5403. * more of the rings is populated (while the rest are not). It is the
  5404. * callers duty to clean those orphaned rings.
  5405. *
  5406. * Return 0 on success, negative on failure
  5407. **/
  5408. static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
  5409. {
  5410. int i, err = 0;
  5411. for (i = 0; i < adapter->num_rx_queues; i++) {
  5412. err = ixgbe_setup_rx_resources(adapter, adapter->rx_ring[i]);
  5413. if (!err)
  5414. continue;
  5415. e_err(probe, "Allocation for Rx Queue %u failed\n", i);
  5416. goto err_setup_rx;
  5417. }
  5418. #ifdef IXGBE_FCOE
  5419. err = ixgbe_setup_fcoe_ddp_resources(adapter);
  5420. if (!err)
  5421. #endif
  5422. return 0;
  5423. err_setup_rx:
  5424. /* rewind the index freeing the rings as we go */
  5425. while (i--)
  5426. ixgbe_free_rx_resources(adapter->rx_ring[i]);
  5427. return err;
  5428. }
  5429. /**
  5430. * ixgbe_free_tx_resources - Free Tx Resources per Queue
  5431. * @tx_ring: Tx descriptor ring for a specific queue
  5432. *
  5433. * Free all transmit software resources
  5434. **/
  5435. void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
  5436. {
  5437. ixgbe_clean_tx_ring(tx_ring);
  5438. vfree(tx_ring->tx_buffer_info);
  5439. tx_ring->tx_buffer_info = NULL;
  5440. /* if not set, then don't free */
  5441. if (!tx_ring->desc)
  5442. return;
  5443. dma_free_coherent(tx_ring->dev, tx_ring->size,
  5444. tx_ring->desc, tx_ring->dma);
  5445. tx_ring->desc = NULL;
  5446. }
  5447. /**
  5448. * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
  5449. * @adapter: board private structure
  5450. *
  5451. * Free all transmit software resources
  5452. **/
  5453. static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
  5454. {
  5455. int i;
  5456. for (i = 0; i < adapter->num_tx_queues; i++)
  5457. if (adapter->tx_ring[i]->desc)
  5458. ixgbe_free_tx_resources(adapter->tx_ring[i]);
  5459. for (i = 0; i < adapter->num_xdp_queues; i++)
  5460. if (adapter->xdp_ring[i]->desc)
  5461. ixgbe_free_tx_resources(adapter->xdp_ring[i]);
  5462. }
  5463. /**
  5464. * ixgbe_free_rx_resources - Free Rx Resources
  5465. * @rx_ring: ring to clean the resources from
  5466. *
  5467. * Free all receive software resources
  5468. **/
  5469. void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
  5470. {
  5471. ixgbe_clean_rx_ring(rx_ring);
  5472. rx_ring->xdp_prog = NULL;
  5473. xdp_rxq_info_unreg(&rx_ring->xdp_rxq);
  5474. vfree(rx_ring->rx_buffer_info);
  5475. rx_ring->rx_buffer_info = NULL;
  5476. /* if not set, then don't free */
  5477. if (!rx_ring->desc)
  5478. return;
  5479. dma_free_coherent(rx_ring->dev, rx_ring->size,
  5480. rx_ring->desc, rx_ring->dma);
  5481. rx_ring->desc = NULL;
  5482. }
  5483. /**
  5484. * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
  5485. * @adapter: board private structure
  5486. *
  5487. * Free all receive software resources
  5488. **/
  5489. static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
  5490. {
  5491. int i;
  5492. #ifdef IXGBE_FCOE
  5493. ixgbe_free_fcoe_ddp_resources(adapter);
  5494. #endif
  5495. for (i = 0; i < adapter->num_rx_queues; i++)
  5496. if (adapter->rx_ring[i]->desc)
  5497. ixgbe_free_rx_resources(adapter->rx_ring[i]);
  5498. }
  5499. /**
  5500. * ixgbe_change_mtu - Change the Maximum Transfer Unit
  5501. * @netdev: network interface device structure
  5502. * @new_mtu: new value for maximum frame size
  5503. *
  5504. * Returns 0 on success, negative on failure
  5505. **/
  5506. static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
  5507. {
  5508. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5509. /*
  5510. * For 82599EB we cannot allow legacy VFs to enable their receive
  5511. * paths when MTU greater than 1500 is configured. So display a
  5512. * warning that legacy VFs will be disabled.
  5513. */
  5514. if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
  5515. (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
  5516. (new_mtu > ETH_DATA_LEN))
  5517. e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
  5518. e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
  5519. /* must set new MTU before calling down or up */
  5520. netdev->mtu = new_mtu;
  5521. if (netif_running(netdev))
  5522. ixgbe_reinit_locked(adapter);
  5523. return 0;
  5524. }
  5525. /**
  5526. * ixgbe_open - Called when a network interface is made active
  5527. * @netdev: network interface device structure
  5528. *
  5529. * Returns 0 on success, negative value on failure
  5530. *
  5531. * The open entry point is called when a network interface is made
  5532. * active by the system (IFF_UP). At this point all resources needed
  5533. * for transmit and receive operations are allocated, the interrupt
  5534. * handler is registered with the OS, the watchdog timer is started,
  5535. * and the stack is notified that the interface is ready.
  5536. **/
  5537. int ixgbe_open(struct net_device *netdev)
  5538. {
  5539. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5540. struct ixgbe_hw *hw = &adapter->hw;
  5541. int err, queues;
  5542. /* disallow open during test */
  5543. if (test_bit(__IXGBE_TESTING, &adapter->state))
  5544. return -EBUSY;
  5545. netif_carrier_off(netdev);
  5546. /* allocate transmit descriptors */
  5547. err = ixgbe_setup_all_tx_resources(adapter);
  5548. if (err)
  5549. goto err_setup_tx;
  5550. /* allocate receive descriptors */
  5551. err = ixgbe_setup_all_rx_resources(adapter);
  5552. if (err)
  5553. goto err_setup_rx;
  5554. ixgbe_configure(adapter);
  5555. err = ixgbe_request_irq(adapter);
  5556. if (err)
  5557. goto err_req_irq;
  5558. /* Notify the stack of the actual queue counts. */
  5559. queues = adapter->num_tx_queues;
  5560. err = netif_set_real_num_tx_queues(netdev, queues);
  5561. if (err)
  5562. goto err_set_queues;
  5563. queues = adapter->num_rx_queues;
  5564. err = netif_set_real_num_rx_queues(netdev, queues);
  5565. if (err)
  5566. goto err_set_queues;
  5567. ixgbe_ptp_init(adapter);
  5568. ixgbe_up_complete(adapter);
  5569. ixgbe_clear_udp_tunnel_port(adapter, IXGBE_VXLANCTRL_ALL_UDPPORT_MASK);
  5570. udp_tunnel_get_rx_info(netdev);
  5571. return 0;
  5572. err_set_queues:
  5573. ixgbe_free_irq(adapter);
  5574. err_req_irq:
  5575. ixgbe_free_all_rx_resources(adapter);
  5576. if (hw->phy.ops.set_phy_power && !adapter->wol)
  5577. hw->phy.ops.set_phy_power(&adapter->hw, false);
  5578. err_setup_rx:
  5579. ixgbe_free_all_tx_resources(adapter);
  5580. err_setup_tx:
  5581. ixgbe_reset(adapter);
  5582. return err;
  5583. }
  5584. static void ixgbe_close_suspend(struct ixgbe_adapter *adapter)
  5585. {
  5586. ixgbe_ptp_suspend(adapter);
  5587. if (adapter->hw.phy.ops.enter_lplu) {
  5588. adapter->hw.phy.reset_disable = true;
  5589. ixgbe_down(adapter);
  5590. adapter->hw.phy.ops.enter_lplu(&adapter->hw);
  5591. adapter->hw.phy.reset_disable = false;
  5592. } else {
  5593. ixgbe_down(adapter);
  5594. }
  5595. ixgbe_free_irq(adapter);
  5596. ixgbe_free_all_tx_resources(adapter);
  5597. ixgbe_free_all_rx_resources(adapter);
  5598. }
  5599. /**
  5600. * ixgbe_close - Disables a network interface
  5601. * @netdev: network interface device structure
  5602. *
  5603. * Returns 0, this is not allowed to fail
  5604. *
  5605. * The close entry point is called when an interface is de-activated
  5606. * by the OS. The hardware is still under the drivers control, but
  5607. * needs to be disabled. A global MAC reset is issued to stop the
  5608. * hardware, and all transmit and receive resources are freed.
  5609. **/
  5610. int ixgbe_close(struct net_device *netdev)
  5611. {
  5612. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5613. ixgbe_ptp_stop(adapter);
  5614. if (netif_device_present(netdev))
  5615. ixgbe_close_suspend(adapter);
  5616. ixgbe_fdir_filter_exit(adapter);
  5617. ixgbe_release_hw_control(adapter);
  5618. return 0;
  5619. }
  5620. #ifdef CONFIG_PM
  5621. static int ixgbe_resume(struct pci_dev *pdev)
  5622. {
  5623. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  5624. struct net_device *netdev = adapter->netdev;
  5625. u32 err;
  5626. adapter->hw.hw_addr = adapter->io_addr;
  5627. pci_set_power_state(pdev, PCI_D0);
  5628. pci_restore_state(pdev);
  5629. /*
  5630. * pci_restore_state clears dev->state_saved so call
  5631. * pci_save_state to restore it.
  5632. */
  5633. pci_save_state(pdev);
  5634. err = pci_enable_device_mem(pdev);
  5635. if (err) {
  5636. e_dev_err("Cannot enable PCI device from suspend\n");
  5637. return err;
  5638. }
  5639. smp_mb__before_atomic();
  5640. clear_bit(__IXGBE_DISABLED, &adapter->state);
  5641. pci_set_master(pdev);
  5642. pci_wake_from_d3(pdev, false);
  5643. ixgbe_reset(adapter);
  5644. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  5645. rtnl_lock();
  5646. err = ixgbe_init_interrupt_scheme(adapter);
  5647. if (!err && netif_running(netdev))
  5648. err = ixgbe_open(netdev);
  5649. if (!err)
  5650. netif_device_attach(netdev);
  5651. rtnl_unlock();
  5652. return err;
  5653. }
  5654. #endif /* CONFIG_PM */
  5655. static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
  5656. {
  5657. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  5658. struct net_device *netdev = adapter->netdev;
  5659. struct ixgbe_hw *hw = &adapter->hw;
  5660. u32 ctrl;
  5661. u32 wufc = adapter->wol;
  5662. #ifdef CONFIG_PM
  5663. int retval = 0;
  5664. #endif
  5665. rtnl_lock();
  5666. netif_device_detach(netdev);
  5667. if (netif_running(netdev))
  5668. ixgbe_close_suspend(adapter);
  5669. ixgbe_clear_interrupt_scheme(adapter);
  5670. rtnl_unlock();
  5671. #ifdef CONFIG_PM
  5672. retval = pci_save_state(pdev);
  5673. if (retval)
  5674. return retval;
  5675. #endif
  5676. if (hw->mac.ops.stop_link_on_d3)
  5677. hw->mac.ops.stop_link_on_d3(hw);
  5678. if (wufc) {
  5679. u32 fctrl;
  5680. ixgbe_set_rx_mode(netdev);
  5681. /* enable the optics for 82599 SFP+ fiber as we can WoL */
  5682. if (hw->mac.ops.enable_tx_laser)
  5683. hw->mac.ops.enable_tx_laser(hw);
  5684. /* enable the reception of multicast packets */
  5685. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  5686. fctrl |= IXGBE_FCTRL_MPE;
  5687. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  5688. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  5689. ctrl |= IXGBE_CTRL_GIO_DIS;
  5690. IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
  5691. IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
  5692. } else {
  5693. IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
  5694. IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
  5695. }
  5696. switch (hw->mac.type) {
  5697. case ixgbe_mac_82598EB:
  5698. pci_wake_from_d3(pdev, false);
  5699. break;
  5700. case ixgbe_mac_82599EB:
  5701. case ixgbe_mac_X540:
  5702. case ixgbe_mac_X550:
  5703. case ixgbe_mac_X550EM_x:
  5704. case ixgbe_mac_x550em_a:
  5705. pci_wake_from_d3(pdev, !!wufc);
  5706. break;
  5707. default:
  5708. break;
  5709. }
  5710. *enable_wake = !!wufc;
  5711. if (hw->phy.ops.set_phy_power && !*enable_wake)
  5712. hw->phy.ops.set_phy_power(hw, false);
  5713. ixgbe_release_hw_control(adapter);
  5714. if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
  5715. pci_disable_device(pdev);
  5716. return 0;
  5717. }
  5718. #ifdef CONFIG_PM
  5719. static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
  5720. {
  5721. int retval;
  5722. bool wake;
  5723. retval = __ixgbe_shutdown(pdev, &wake);
  5724. if (retval)
  5725. return retval;
  5726. if (wake) {
  5727. pci_prepare_to_sleep(pdev);
  5728. } else {
  5729. pci_wake_from_d3(pdev, false);
  5730. pci_set_power_state(pdev, PCI_D3hot);
  5731. }
  5732. return 0;
  5733. }
  5734. #endif /* CONFIG_PM */
  5735. static void ixgbe_shutdown(struct pci_dev *pdev)
  5736. {
  5737. bool wake;
  5738. __ixgbe_shutdown(pdev, &wake);
  5739. if (system_state == SYSTEM_POWER_OFF) {
  5740. pci_wake_from_d3(pdev, wake);
  5741. pci_set_power_state(pdev, PCI_D3hot);
  5742. }
  5743. }
  5744. /**
  5745. * ixgbe_update_stats - Update the board statistics counters.
  5746. * @adapter: board private structure
  5747. **/
  5748. void ixgbe_update_stats(struct ixgbe_adapter *adapter)
  5749. {
  5750. struct net_device *netdev = adapter->netdev;
  5751. struct ixgbe_hw *hw = &adapter->hw;
  5752. struct ixgbe_hw_stats *hwstats = &adapter->stats;
  5753. u64 total_mpc = 0;
  5754. u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
  5755. u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
  5756. u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
  5757. u64 alloc_rx_page = 0;
  5758. u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
  5759. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  5760. test_bit(__IXGBE_RESETTING, &adapter->state))
  5761. return;
  5762. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
  5763. u64 rsc_count = 0;
  5764. u64 rsc_flush = 0;
  5765. for (i = 0; i < adapter->num_rx_queues; i++) {
  5766. rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
  5767. rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
  5768. }
  5769. adapter->rsc_total_count = rsc_count;
  5770. adapter->rsc_total_flush = rsc_flush;
  5771. }
  5772. for (i = 0; i < adapter->num_rx_queues; i++) {
  5773. struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
  5774. non_eop_descs += rx_ring->rx_stats.non_eop_descs;
  5775. alloc_rx_page += rx_ring->rx_stats.alloc_rx_page;
  5776. alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
  5777. alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
  5778. hw_csum_rx_error += rx_ring->rx_stats.csum_err;
  5779. bytes += rx_ring->stats.bytes;
  5780. packets += rx_ring->stats.packets;
  5781. }
  5782. adapter->non_eop_descs = non_eop_descs;
  5783. adapter->alloc_rx_page = alloc_rx_page;
  5784. adapter->alloc_rx_page_failed = alloc_rx_page_failed;
  5785. adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
  5786. adapter->hw_csum_rx_error = hw_csum_rx_error;
  5787. netdev->stats.rx_bytes = bytes;
  5788. netdev->stats.rx_packets = packets;
  5789. bytes = 0;
  5790. packets = 0;
  5791. /* gather some stats to the adapter struct that are per queue */
  5792. for (i = 0; i < adapter->num_tx_queues; i++) {
  5793. struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
  5794. restart_queue += tx_ring->tx_stats.restart_queue;
  5795. tx_busy += tx_ring->tx_stats.tx_busy;
  5796. bytes += tx_ring->stats.bytes;
  5797. packets += tx_ring->stats.packets;
  5798. }
  5799. for (i = 0; i < adapter->num_xdp_queues; i++) {
  5800. struct ixgbe_ring *xdp_ring = adapter->xdp_ring[i];
  5801. restart_queue += xdp_ring->tx_stats.restart_queue;
  5802. tx_busy += xdp_ring->tx_stats.tx_busy;
  5803. bytes += xdp_ring->stats.bytes;
  5804. packets += xdp_ring->stats.packets;
  5805. }
  5806. adapter->restart_queue = restart_queue;
  5807. adapter->tx_busy = tx_busy;
  5808. netdev->stats.tx_bytes = bytes;
  5809. netdev->stats.tx_packets = packets;
  5810. hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
  5811. /* 8 register reads */
  5812. for (i = 0; i < 8; i++) {
  5813. /* for packet buffers not used, the register should read 0 */
  5814. mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
  5815. missed_rx += mpc;
  5816. hwstats->mpc[i] += mpc;
  5817. total_mpc += hwstats->mpc[i];
  5818. hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
  5819. hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
  5820. switch (hw->mac.type) {
  5821. case ixgbe_mac_82598EB:
  5822. hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
  5823. hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
  5824. hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
  5825. hwstats->pxonrxc[i] +=
  5826. IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
  5827. break;
  5828. case ixgbe_mac_82599EB:
  5829. case ixgbe_mac_X540:
  5830. case ixgbe_mac_X550:
  5831. case ixgbe_mac_X550EM_x:
  5832. case ixgbe_mac_x550em_a:
  5833. hwstats->pxonrxc[i] +=
  5834. IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
  5835. break;
  5836. default:
  5837. break;
  5838. }
  5839. }
  5840. /*16 register reads */
  5841. for (i = 0; i < 16; i++) {
  5842. hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
  5843. hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
  5844. if ((hw->mac.type == ixgbe_mac_82599EB) ||
  5845. (hw->mac.type == ixgbe_mac_X540) ||
  5846. (hw->mac.type == ixgbe_mac_X550) ||
  5847. (hw->mac.type == ixgbe_mac_X550EM_x) ||
  5848. (hw->mac.type == ixgbe_mac_x550em_a)) {
  5849. hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
  5850. IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
  5851. hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
  5852. IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
  5853. }
  5854. }
  5855. hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
  5856. /* work around hardware counting issue */
  5857. hwstats->gprc -= missed_rx;
  5858. ixgbe_update_xoff_received(adapter);
  5859. /* 82598 hardware only has a 32 bit counter in the high register */
  5860. switch (hw->mac.type) {
  5861. case ixgbe_mac_82598EB:
  5862. hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
  5863. hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
  5864. hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
  5865. hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
  5866. break;
  5867. case ixgbe_mac_X540:
  5868. case ixgbe_mac_X550:
  5869. case ixgbe_mac_X550EM_x:
  5870. case ixgbe_mac_x550em_a:
  5871. /* OS2BMC stats are X540 and later */
  5872. hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
  5873. hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
  5874. hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
  5875. hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
  5876. /* fall through */
  5877. case ixgbe_mac_82599EB:
  5878. for (i = 0; i < 16; i++)
  5879. adapter->hw_rx_no_dma_resources +=
  5880. IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
  5881. hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
  5882. IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
  5883. hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
  5884. IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
  5885. hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
  5886. IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
  5887. hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
  5888. hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
  5889. hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
  5890. #ifdef IXGBE_FCOE
  5891. hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
  5892. hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
  5893. hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
  5894. hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
  5895. hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
  5896. hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
  5897. /* Add up per cpu counters for total ddp aloc fail */
  5898. if (adapter->fcoe.ddp_pool) {
  5899. struct ixgbe_fcoe *fcoe = &adapter->fcoe;
  5900. struct ixgbe_fcoe_ddp_pool *ddp_pool;
  5901. unsigned int cpu;
  5902. u64 noddp = 0, noddp_ext_buff = 0;
  5903. for_each_possible_cpu(cpu) {
  5904. ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
  5905. noddp += ddp_pool->noddp;
  5906. noddp_ext_buff += ddp_pool->noddp_ext_buff;
  5907. }
  5908. hwstats->fcoe_noddp = noddp;
  5909. hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
  5910. }
  5911. #endif /* IXGBE_FCOE */
  5912. break;
  5913. default:
  5914. break;
  5915. }
  5916. bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
  5917. hwstats->bprc += bprc;
  5918. hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
  5919. if (hw->mac.type == ixgbe_mac_82598EB)
  5920. hwstats->mprc -= bprc;
  5921. hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
  5922. hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
  5923. hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
  5924. hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
  5925. hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
  5926. hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
  5927. hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
  5928. hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
  5929. lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
  5930. hwstats->lxontxc += lxon;
  5931. lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
  5932. hwstats->lxofftxc += lxoff;
  5933. hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
  5934. hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
  5935. /*
  5936. * 82598 errata - tx of flow control packets is included in tx counters
  5937. */
  5938. xon_off_tot = lxon + lxoff;
  5939. hwstats->gptc -= xon_off_tot;
  5940. hwstats->mptc -= xon_off_tot;
  5941. hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
  5942. hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
  5943. hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
  5944. hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
  5945. hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
  5946. hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
  5947. hwstats->ptc64 -= xon_off_tot;
  5948. hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
  5949. hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
  5950. hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
  5951. hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
  5952. hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
  5953. hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
  5954. /* Fill out the OS statistics structure */
  5955. netdev->stats.multicast = hwstats->mprc;
  5956. /* Rx Errors */
  5957. netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
  5958. netdev->stats.rx_dropped = 0;
  5959. netdev->stats.rx_length_errors = hwstats->rlec;
  5960. netdev->stats.rx_crc_errors = hwstats->crcerrs;
  5961. netdev->stats.rx_missed_errors = total_mpc;
  5962. }
  5963. /**
  5964. * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
  5965. * @adapter: pointer to the device adapter structure
  5966. **/
  5967. static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
  5968. {
  5969. struct ixgbe_hw *hw = &adapter->hw;
  5970. int i;
  5971. if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
  5972. return;
  5973. adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
  5974. /* if interface is down do nothing */
  5975. if (test_bit(__IXGBE_DOWN, &adapter->state))
  5976. return;
  5977. /* do nothing if we are not using signature filters */
  5978. if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
  5979. return;
  5980. adapter->fdir_overflow++;
  5981. if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
  5982. for (i = 0; i < adapter->num_tx_queues; i++)
  5983. set_bit(__IXGBE_TX_FDIR_INIT_DONE,
  5984. &(adapter->tx_ring[i]->state));
  5985. for (i = 0; i < adapter->num_xdp_queues; i++)
  5986. set_bit(__IXGBE_TX_FDIR_INIT_DONE,
  5987. &adapter->xdp_ring[i]->state);
  5988. /* re-enable flow director interrupts */
  5989. IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
  5990. } else {
  5991. e_err(probe, "failed to finish FDIR re-initialization, "
  5992. "ignored adding FDIR ATR filters\n");
  5993. }
  5994. }
  5995. /**
  5996. * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
  5997. * @adapter: pointer to the device adapter structure
  5998. *
  5999. * This function serves two purposes. First it strobes the interrupt lines
  6000. * in order to make certain interrupts are occurring. Secondly it sets the
  6001. * bits needed to check for TX hangs. As a result we should immediately
  6002. * determine if a hang has occurred.
  6003. */
  6004. static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
  6005. {
  6006. struct ixgbe_hw *hw = &adapter->hw;
  6007. u64 eics = 0;
  6008. int i;
  6009. /* If we're down, removing or resetting, just bail */
  6010. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  6011. test_bit(__IXGBE_REMOVING, &adapter->state) ||
  6012. test_bit(__IXGBE_RESETTING, &adapter->state))
  6013. return;
  6014. /* Force detection of hung controller */
  6015. if (netif_carrier_ok(adapter->netdev)) {
  6016. for (i = 0; i < adapter->num_tx_queues; i++)
  6017. set_check_for_tx_hang(adapter->tx_ring[i]);
  6018. for (i = 0; i < adapter->num_xdp_queues; i++)
  6019. set_check_for_tx_hang(adapter->xdp_ring[i]);
  6020. }
  6021. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
  6022. /*
  6023. * for legacy and MSI interrupts don't set any bits
  6024. * that are enabled for EIAM, because this operation
  6025. * would set *both* EIMS and EICS for any bit in EIAM
  6026. */
  6027. IXGBE_WRITE_REG(hw, IXGBE_EICS,
  6028. (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
  6029. } else {
  6030. /* get one bit for every active tx/rx interrupt vector */
  6031. for (i = 0; i < adapter->num_q_vectors; i++) {
  6032. struct ixgbe_q_vector *qv = adapter->q_vector[i];
  6033. if (qv->rx.ring || qv->tx.ring)
  6034. eics |= BIT_ULL(i);
  6035. }
  6036. }
  6037. /* Cause software interrupt to ensure rings are cleaned */
  6038. ixgbe_irq_rearm_queues(adapter, eics);
  6039. }
  6040. /**
  6041. * ixgbe_watchdog_update_link - update the link status
  6042. * @adapter: pointer to the device adapter structure
  6043. **/
  6044. static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
  6045. {
  6046. struct ixgbe_hw *hw = &adapter->hw;
  6047. u32 link_speed = adapter->link_speed;
  6048. bool link_up = adapter->link_up;
  6049. bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
  6050. if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
  6051. return;
  6052. if (hw->mac.ops.check_link) {
  6053. hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
  6054. } else {
  6055. /* always assume link is up, if no check link function */
  6056. link_speed = IXGBE_LINK_SPEED_10GB_FULL;
  6057. link_up = true;
  6058. }
  6059. if (adapter->ixgbe_ieee_pfc)
  6060. pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
  6061. if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
  6062. hw->mac.ops.fc_enable(hw);
  6063. ixgbe_set_rx_drop_en(adapter);
  6064. }
  6065. if (link_up ||
  6066. time_after(jiffies, (adapter->link_check_timeout +
  6067. IXGBE_TRY_LINK_TIMEOUT))) {
  6068. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
  6069. IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
  6070. IXGBE_WRITE_FLUSH(hw);
  6071. }
  6072. adapter->link_up = link_up;
  6073. adapter->link_speed = link_speed;
  6074. }
  6075. static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
  6076. {
  6077. #ifdef CONFIG_IXGBE_DCB
  6078. struct net_device *netdev = adapter->netdev;
  6079. struct dcb_app app = {
  6080. .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
  6081. .protocol = 0,
  6082. };
  6083. u8 up = 0;
  6084. if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
  6085. up = dcb_ieee_getapp_mask(netdev, &app);
  6086. adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
  6087. #endif
  6088. }
  6089. /**
  6090. * ixgbe_watchdog_link_is_up - update netif_carrier status and
  6091. * print link up message
  6092. * @adapter: pointer to the device adapter structure
  6093. **/
  6094. static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
  6095. {
  6096. struct net_device *netdev = adapter->netdev;
  6097. struct ixgbe_hw *hw = &adapter->hw;
  6098. u32 link_speed = adapter->link_speed;
  6099. const char *speed_str;
  6100. bool flow_rx, flow_tx;
  6101. /* only continue if link was previously down */
  6102. if (netif_carrier_ok(netdev))
  6103. return;
  6104. adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
  6105. switch (hw->mac.type) {
  6106. case ixgbe_mac_82598EB: {
  6107. u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  6108. u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
  6109. flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
  6110. flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
  6111. }
  6112. break;
  6113. case ixgbe_mac_X540:
  6114. case ixgbe_mac_X550:
  6115. case ixgbe_mac_X550EM_x:
  6116. case ixgbe_mac_x550em_a:
  6117. case ixgbe_mac_82599EB: {
  6118. u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
  6119. u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
  6120. flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
  6121. flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
  6122. }
  6123. break;
  6124. default:
  6125. flow_tx = false;
  6126. flow_rx = false;
  6127. break;
  6128. }
  6129. adapter->last_rx_ptp_check = jiffies;
  6130. if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
  6131. ixgbe_ptp_start_cyclecounter(adapter);
  6132. switch (link_speed) {
  6133. case IXGBE_LINK_SPEED_10GB_FULL:
  6134. speed_str = "10 Gbps";
  6135. break;
  6136. case IXGBE_LINK_SPEED_5GB_FULL:
  6137. speed_str = "5 Gbps";
  6138. break;
  6139. case IXGBE_LINK_SPEED_2_5GB_FULL:
  6140. speed_str = "2.5 Gbps";
  6141. break;
  6142. case IXGBE_LINK_SPEED_1GB_FULL:
  6143. speed_str = "1 Gbps";
  6144. break;
  6145. case IXGBE_LINK_SPEED_100_FULL:
  6146. speed_str = "100 Mbps";
  6147. break;
  6148. case IXGBE_LINK_SPEED_10_FULL:
  6149. speed_str = "10 Mbps";
  6150. break;
  6151. default:
  6152. speed_str = "unknown speed";
  6153. break;
  6154. }
  6155. e_info(drv, "NIC Link is Up %s, Flow Control: %s\n", speed_str,
  6156. ((flow_rx && flow_tx) ? "RX/TX" :
  6157. (flow_rx ? "RX" :
  6158. (flow_tx ? "TX" : "None"))));
  6159. netif_carrier_on(netdev);
  6160. ixgbe_check_vf_rate_limit(adapter);
  6161. /* enable transmits */
  6162. netif_tx_wake_all_queues(adapter->netdev);
  6163. /* update the default user priority for VFs */
  6164. ixgbe_update_default_up(adapter);
  6165. /* ping all the active vfs to let them know link has changed */
  6166. ixgbe_ping_all_vfs(adapter);
  6167. }
  6168. /**
  6169. * ixgbe_watchdog_link_is_down - update netif_carrier status and
  6170. * print link down message
  6171. * @adapter: pointer to the adapter structure
  6172. **/
  6173. static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
  6174. {
  6175. struct net_device *netdev = adapter->netdev;
  6176. struct ixgbe_hw *hw = &adapter->hw;
  6177. adapter->link_up = false;
  6178. adapter->link_speed = 0;
  6179. /* only continue if link was up previously */
  6180. if (!netif_carrier_ok(netdev))
  6181. return;
  6182. /* poll for SFP+ cable when link is down */
  6183. if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
  6184. adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
  6185. if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state))
  6186. ixgbe_ptp_start_cyclecounter(adapter);
  6187. e_info(drv, "NIC Link is Down\n");
  6188. netif_carrier_off(netdev);
  6189. /* ping all the active vfs to let them know link has changed */
  6190. ixgbe_ping_all_vfs(adapter);
  6191. }
  6192. static bool ixgbe_ring_tx_pending(struct ixgbe_adapter *adapter)
  6193. {
  6194. int i;
  6195. for (i = 0; i < adapter->num_tx_queues; i++) {
  6196. struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
  6197. if (tx_ring->next_to_use != tx_ring->next_to_clean)
  6198. return true;
  6199. }
  6200. for (i = 0; i < adapter->num_xdp_queues; i++) {
  6201. struct ixgbe_ring *ring = adapter->xdp_ring[i];
  6202. if (ring->next_to_use != ring->next_to_clean)
  6203. return true;
  6204. }
  6205. return false;
  6206. }
  6207. static bool ixgbe_vf_tx_pending(struct ixgbe_adapter *adapter)
  6208. {
  6209. struct ixgbe_hw *hw = &adapter->hw;
  6210. struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
  6211. u32 q_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
  6212. int i, j;
  6213. if (!adapter->num_vfs)
  6214. return false;
  6215. /* resetting the PF is only needed for MAC before X550 */
  6216. if (hw->mac.type >= ixgbe_mac_X550)
  6217. return false;
  6218. for (i = 0; i < adapter->num_vfs; i++) {
  6219. for (j = 0; j < q_per_pool; j++) {
  6220. u32 h, t;
  6221. h = IXGBE_READ_REG(hw, IXGBE_PVFTDHN(q_per_pool, i, j));
  6222. t = IXGBE_READ_REG(hw, IXGBE_PVFTDTN(q_per_pool, i, j));
  6223. if (h != t)
  6224. return true;
  6225. }
  6226. }
  6227. return false;
  6228. }
  6229. /**
  6230. * ixgbe_watchdog_flush_tx - flush queues on link down
  6231. * @adapter: pointer to the device adapter structure
  6232. **/
  6233. static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
  6234. {
  6235. if (!netif_carrier_ok(adapter->netdev)) {
  6236. if (ixgbe_ring_tx_pending(adapter) ||
  6237. ixgbe_vf_tx_pending(adapter)) {
  6238. /* We've lost link, so the controller stops DMA,
  6239. * but we've got queued Tx work that's never going
  6240. * to get done, so reset controller to flush Tx.
  6241. * (Do the reset outside of interrupt context).
  6242. */
  6243. e_warn(drv, "initiating reset to clear Tx work after link loss\n");
  6244. set_bit(__IXGBE_RESET_REQUESTED, &adapter->state);
  6245. }
  6246. }
  6247. }
  6248. #ifdef CONFIG_PCI_IOV
  6249. static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
  6250. {
  6251. struct ixgbe_hw *hw = &adapter->hw;
  6252. struct pci_dev *pdev = adapter->pdev;
  6253. unsigned int vf;
  6254. u32 gpc;
  6255. if (!(netif_carrier_ok(adapter->netdev)))
  6256. return;
  6257. gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
  6258. if (gpc) /* If incrementing then no need for the check below */
  6259. return;
  6260. /* Check to see if a bad DMA write target from an errant or
  6261. * malicious VF has caused a PCIe error. If so then we can
  6262. * issue a VFLR to the offending VF(s) and then resume without
  6263. * requesting a full slot reset.
  6264. */
  6265. if (!pdev)
  6266. return;
  6267. /* check status reg for all VFs owned by this PF */
  6268. for (vf = 0; vf < adapter->num_vfs; ++vf) {
  6269. struct pci_dev *vfdev = adapter->vfinfo[vf].vfdev;
  6270. u16 status_reg;
  6271. if (!vfdev)
  6272. continue;
  6273. pci_read_config_word(vfdev, PCI_STATUS, &status_reg);
  6274. if (status_reg != IXGBE_FAILED_READ_CFG_WORD &&
  6275. status_reg & PCI_STATUS_REC_MASTER_ABORT)
  6276. pcie_flr(vfdev);
  6277. }
  6278. }
  6279. static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
  6280. {
  6281. u32 ssvpc;
  6282. /* Do not perform spoof check for 82598 or if not in IOV mode */
  6283. if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
  6284. adapter->num_vfs == 0)
  6285. return;
  6286. ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
  6287. /*
  6288. * ssvpc register is cleared on read, if zero then no
  6289. * spoofed packets in the last interval.
  6290. */
  6291. if (!ssvpc)
  6292. return;
  6293. e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
  6294. }
  6295. #else
  6296. static void ixgbe_spoof_check(struct ixgbe_adapter __always_unused *adapter)
  6297. {
  6298. }
  6299. static void
  6300. ixgbe_check_for_bad_vf(struct ixgbe_adapter __always_unused *adapter)
  6301. {
  6302. }
  6303. #endif /* CONFIG_PCI_IOV */
  6304. /**
  6305. * ixgbe_watchdog_subtask - check and bring link up
  6306. * @adapter: pointer to the device adapter structure
  6307. **/
  6308. static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
  6309. {
  6310. /* if interface is down, removing or resetting, do nothing */
  6311. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  6312. test_bit(__IXGBE_REMOVING, &adapter->state) ||
  6313. test_bit(__IXGBE_RESETTING, &adapter->state))
  6314. return;
  6315. ixgbe_watchdog_update_link(adapter);
  6316. if (adapter->link_up)
  6317. ixgbe_watchdog_link_is_up(adapter);
  6318. else
  6319. ixgbe_watchdog_link_is_down(adapter);
  6320. ixgbe_check_for_bad_vf(adapter);
  6321. ixgbe_spoof_check(adapter);
  6322. ixgbe_update_stats(adapter);
  6323. ixgbe_watchdog_flush_tx(adapter);
  6324. }
  6325. /**
  6326. * ixgbe_sfp_detection_subtask - poll for SFP+ cable
  6327. * @adapter: the ixgbe adapter structure
  6328. **/
  6329. static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
  6330. {
  6331. struct ixgbe_hw *hw = &adapter->hw;
  6332. s32 err;
  6333. /* not searching for SFP so there is nothing to do here */
  6334. if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
  6335. !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
  6336. return;
  6337. if (adapter->sfp_poll_time &&
  6338. time_after(adapter->sfp_poll_time, jiffies))
  6339. return; /* If not yet time to poll for SFP */
  6340. /* someone else is in init, wait until next service event */
  6341. if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
  6342. return;
  6343. adapter->sfp_poll_time = jiffies + IXGBE_SFP_POLL_JIFFIES - 1;
  6344. err = hw->phy.ops.identify_sfp(hw);
  6345. if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
  6346. goto sfp_out;
  6347. if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
  6348. /* If no cable is present, then we need to reset
  6349. * the next time we find a good cable. */
  6350. adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
  6351. }
  6352. /* exit on error */
  6353. if (err)
  6354. goto sfp_out;
  6355. /* exit if reset not needed */
  6356. if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
  6357. goto sfp_out;
  6358. adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
  6359. /*
  6360. * A module may be identified correctly, but the EEPROM may not have
  6361. * support for that module. setup_sfp() will fail in that case, so
  6362. * we should not allow that module to load.
  6363. */
  6364. if (hw->mac.type == ixgbe_mac_82598EB)
  6365. err = hw->phy.ops.reset(hw);
  6366. else
  6367. err = hw->mac.ops.setup_sfp(hw);
  6368. if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
  6369. goto sfp_out;
  6370. adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
  6371. e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
  6372. sfp_out:
  6373. clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
  6374. if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
  6375. (adapter->netdev->reg_state == NETREG_REGISTERED)) {
  6376. e_dev_err("failed to initialize because an unsupported "
  6377. "SFP+ module type was detected.\n");
  6378. e_dev_err("Reload the driver after installing a "
  6379. "supported module.\n");
  6380. unregister_netdev(adapter->netdev);
  6381. }
  6382. }
  6383. /**
  6384. * ixgbe_sfp_link_config_subtask - set up link SFP after module install
  6385. * @adapter: the ixgbe adapter structure
  6386. **/
  6387. static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
  6388. {
  6389. struct ixgbe_hw *hw = &adapter->hw;
  6390. u32 cap_speed;
  6391. u32 speed;
  6392. bool autoneg = false;
  6393. if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
  6394. return;
  6395. /* someone else is in init, wait until next service event */
  6396. if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
  6397. return;
  6398. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
  6399. hw->mac.ops.get_link_capabilities(hw, &cap_speed, &autoneg);
  6400. /* advertise highest capable link speed */
  6401. if (!autoneg && (cap_speed & IXGBE_LINK_SPEED_10GB_FULL))
  6402. speed = IXGBE_LINK_SPEED_10GB_FULL;
  6403. else
  6404. speed = cap_speed & (IXGBE_LINK_SPEED_10GB_FULL |
  6405. IXGBE_LINK_SPEED_1GB_FULL);
  6406. if (hw->mac.ops.setup_link)
  6407. hw->mac.ops.setup_link(hw, speed, true);
  6408. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  6409. adapter->link_check_timeout = jiffies;
  6410. clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
  6411. }
  6412. /**
  6413. * ixgbe_service_timer - Timer Call-back
  6414. * @t: pointer to timer_list structure
  6415. **/
  6416. static void ixgbe_service_timer(struct timer_list *t)
  6417. {
  6418. struct ixgbe_adapter *adapter = from_timer(adapter, t, service_timer);
  6419. unsigned long next_event_offset;
  6420. /* poll faster when waiting for link */
  6421. if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
  6422. next_event_offset = HZ / 10;
  6423. else
  6424. next_event_offset = HZ * 2;
  6425. /* Reset the timer */
  6426. mod_timer(&adapter->service_timer, next_event_offset + jiffies);
  6427. ixgbe_service_event_schedule(adapter);
  6428. }
  6429. static void ixgbe_phy_interrupt_subtask(struct ixgbe_adapter *adapter)
  6430. {
  6431. struct ixgbe_hw *hw = &adapter->hw;
  6432. u32 status;
  6433. if (!(adapter->flags2 & IXGBE_FLAG2_PHY_INTERRUPT))
  6434. return;
  6435. adapter->flags2 &= ~IXGBE_FLAG2_PHY_INTERRUPT;
  6436. if (!hw->phy.ops.handle_lasi)
  6437. return;
  6438. status = hw->phy.ops.handle_lasi(&adapter->hw);
  6439. if (status != IXGBE_ERR_OVERTEMP)
  6440. return;
  6441. e_crit(drv, "%s\n", ixgbe_overheat_msg);
  6442. }
  6443. static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
  6444. {
  6445. if (!test_and_clear_bit(__IXGBE_RESET_REQUESTED, &adapter->state))
  6446. return;
  6447. rtnl_lock();
  6448. /* If we're already down, removing or resetting, just bail */
  6449. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  6450. test_bit(__IXGBE_REMOVING, &adapter->state) ||
  6451. test_bit(__IXGBE_RESETTING, &adapter->state)) {
  6452. rtnl_unlock();
  6453. return;
  6454. }
  6455. ixgbe_dump(adapter);
  6456. netdev_err(adapter->netdev, "Reset adapter\n");
  6457. adapter->tx_timeout_count++;
  6458. ixgbe_reinit_locked(adapter);
  6459. rtnl_unlock();
  6460. }
  6461. /**
  6462. * ixgbe_service_task - manages and runs subtasks
  6463. * @work: pointer to work_struct containing our data
  6464. **/
  6465. static void ixgbe_service_task(struct work_struct *work)
  6466. {
  6467. struct ixgbe_adapter *adapter = container_of(work,
  6468. struct ixgbe_adapter,
  6469. service_task);
  6470. if (ixgbe_removed(adapter->hw.hw_addr)) {
  6471. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  6472. rtnl_lock();
  6473. ixgbe_down(adapter);
  6474. rtnl_unlock();
  6475. }
  6476. ixgbe_service_event_complete(adapter);
  6477. return;
  6478. }
  6479. if (adapter->flags2 & IXGBE_FLAG2_UDP_TUN_REREG_NEEDED) {
  6480. rtnl_lock();
  6481. adapter->flags2 &= ~IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
  6482. udp_tunnel_get_rx_info(adapter->netdev);
  6483. rtnl_unlock();
  6484. }
  6485. ixgbe_reset_subtask(adapter);
  6486. ixgbe_phy_interrupt_subtask(adapter);
  6487. ixgbe_sfp_detection_subtask(adapter);
  6488. ixgbe_sfp_link_config_subtask(adapter);
  6489. ixgbe_check_overtemp_subtask(adapter);
  6490. ixgbe_watchdog_subtask(adapter);
  6491. ixgbe_fdir_reinit_subtask(adapter);
  6492. ixgbe_check_hang_subtask(adapter);
  6493. if (test_bit(__IXGBE_PTP_RUNNING, &adapter->state)) {
  6494. ixgbe_ptp_overflow_check(adapter);
  6495. if (adapter->flags & IXGBE_FLAG_RX_HWTSTAMP_IN_REGISTER)
  6496. ixgbe_ptp_rx_hang(adapter);
  6497. ixgbe_ptp_tx_hang(adapter);
  6498. }
  6499. ixgbe_service_event_complete(adapter);
  6500. }
  6501. static int ixgbe_tso(struct ixgbe_ring *tx_ring,
  6502. struct ixgbe_tx_buffer *first,
  6503. u8 *hdr_len,
  6504. struct ixgbe_ipsec_tx_data *itd)
  6505. {
  6506. u32 vlan_macip_lens, type_tucmd, mss_l4len_idx;
  6507. struct sk_buff *skb = first->skb;
  6508. union {
  6509. struct iphdr *v4;
  6510. struct ipv6hdr *v6;
  6511. unsigned char *hdr;
  6512. } ip;
  6513. union {
  6514. struct tcphdr *tcp;
  6515. unsigned char *hdr;
  6516. } l4;
  6517. u32 paylen, l4_offset;
  6518. u32 fceof_saidx = 0;
  6519. int err;
  6520. if (skb->ip_summed != CHECKSUM_PARTIAL)
  6521. return 0;
  6522. if (!skb_is_gso(skb))
  6523. return 0;
  6524. err = skb_cow_head(skb, 0);
  6525. if (err < 0)
  6526. return err;
  6527. if (eth_p_mpls(first->protocol))
  6528. ip.hdr = skb_inner_network_header(skb);
  6529. else
  6530. ip.hdr = skb_network_header(skb);
  6531. l4.hdr = skb_checksum_start(skb);
  6532. /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
  6533. type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
  6534. /* initialize outer IP header fields */
  6535. if (ip.v4->version == 4) {
  6536. unsigned char *csum_start = skb_checksum_start(skb);
  6537. unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4);
  6538. int len = csum_start - trans_start;
  6539. /* IP header will have to cancel out any data that
  6540. * is not a part of the outer IP header, so set to
  6541. * a reverse csum if needed, else init check to 0.
  6542. */
  6543. ip.v4->check = (skb_shinfo(skb)->gso_type & SKB_GSO_PARTIAL) ?
  6544. csum_fold(csum_partial(trans_start,
  6545. len, 0)) : 0;
  6546. type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
  6547. ip.v4->tot_len = 0;
  6548. first->tx_flags |= IXGBE_TX_FLAGS_TSO |
  6549. IXGBE_TX_FLAGS_CSUM |
  6550. IXGBE_TX_FLAGS_IPV4;
  6551. } else {
  6552. ip.v6->payload_len = 0;
  6553. first->tx_flags |= IXGBE_TX_FLAGS_TSO |
  6554. IXGBE_TX_FLAGS_CSUM;
  6555. }
  6556. /* determine offset of inner transport header */
  6557. l4_offset = l4.hdr - skb->data;
  6558. /* compute length of segmentation header */
  6559. *hdr_len = (l4.tcp->doff * 4) + l4_offset;
  6560. /* remove payload length from inner checksum */
  6561. paylen = skb->len - l4_offset;
  6562. csum_replace_by_diff(&l4.tcp->check, (__force __wsum)htonl(paylen));
  6563. /* update gso size and bytecount with header size */
  6564. first->gso_segs = skb_shinfo(skb)->gso_segs;
  6565. first->bytecount += (first->gso_segs - 1) * *hdr_len;
  6566. /* mss_l4len_id: use 0 as index for TSO */
  6567. mss_l4len_idx = (*hdr_len - l4_offset) << IXGBE_ADVTXD_L4LEN_SHIFT;
  6568. mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
  6569. fceof_saidx |= itd->sa_idx;
  6570. type_tucmd |= itd->flags | itd->trailer_len;
  6571. /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
  6572. vlan_macip_lens = l4.hdr - ip.hdr;
  6573. vlan_macip_lens |= (ip.hdr - skb->data) << IXGBE_ADVTXD_MACLEN_SHIFT;
  6574. vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
  6575. ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, fceof_saidx, type_tucmd,
  6576. mss_l4len_idx);
  6577. return 1;
  6578. }
  6579. static inline bool ixgbe_ipv6_csum_is_sctp(struct sk_buff *skb)
  6580. {
  6581. unsigned int offset = 0;
  6582. ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL);
  6583. return offset == skb_checksum_start_offset(skb);
  6584. }
  6585. static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
  6586. struct ixgbe_tx_buffer *first,
  6587. struct ixgbe_ipsec_tx_data *itd)
  6588. {
  6589. struct sk_buff *skb = first->skb;
  6590. u32 vlan_macip_lens = 0;
  6591. u32 fceof_saidx = 0;
  6592. u32 type_tucmd = 0;
  6593. if (skb->ip_summed != CHECKSUM_PARTIAL) {
  6594. csum_failed:
  6595. if (!(first->tx_flags & (IXGBE_TX_FLAGS_HW_VLAN |
  6596. IXGBE_TX_FLAGS_CC)))
  6597. return;
  6598. goto no_csum;
  6599. }
  6600. switch (skb->csum_offset) {
  6601. case offsetof(struct tcphdr, check):
  6602. type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
  6603. /* fall through */
  6604. case offsetof(struct udphdr, check):
  6605. break;
  6606. case offsetof(struct sctphdr, checksum):
  6607. /* validate that this is actually an SCTP request */
  6608. if (((first->protocol == htons(ETH_P_IP)) &&
  6609. (ip_hdr(skb)->protocol == IPPROTO_SCTP)) ||
  6610. ((first->protocol == htons(ETH_P_IPV6)) &&
  6611. ixgbe_ipv6_csum_is_sctp(skb))) {
  6612. type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP;
  6613. break;
  6614. }
  6615. /* fall through */
  6616. default:
  6617. skb_checksum_help(skb);
  6618. goto csum_failed;
  6619. }
  6620. /* update TX checksum flag */
  6621. first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
  6622. vlan_macip_lens = skb_checksum_start_offset(skb) -
  6623. skb_network_offset(skb);
  6624. no_csum:
  6625. /* vlan_macip_lens: MACLEN, VLAN tag */
  6626. vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
  6627. vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
  6628. fceof_saidx |= itd->sa_idx;
  6629. type_tucmd |= itd->flags | itd->trailer_len;
  6630. ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, fceof_saidx, type_tucmd, 0);
  6631. }
  6632. #define IXGBE_SET_FLAG(_input, _flag, _result) \
  6633. ((_flag <= _result) ? \
  6634. ((u32)(_input & _flag) * (_result / _flag)) : \
  6635. ((u32)(_input & _flag) / (_flag / _result)))
  6636. static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
  6637. {
  6638. /* set type for advanced descriptor with frame checksum insertion */
  6639. u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
  6640. IXGBE_ADVTXD_DCMD_DEXT |
  6641. IXGBE_ADVTXD_DCMD_IFCS;
  6642. /* set HW vlan bit if vlan is present */
  6643. cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
  6644. IXGBE_ADVTXD_DCMD_VLE);
  6645. /* set segmentation enable bits for TSO/FSO */
  6646. cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
  6647. IXGBE_ADVTXD_DCMD_TSE);
  6648. /* set timestamp bit if present */
  6649. cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
  6650. IXGBE_ADVTXD_MAC_TSTAMP);
  6651. /* insert frame checksum */
  6652. cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
  6653. return cmd_type;
  6654. }
  6655. static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
  6656. u32 tx_flags, unsigned int paylen)
  6657. {
  6658. u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
  6659. /* enable L4 checksum for TSO and TX checksum offload */
  6660. olinfo_status |= IXGBE_SET_FLAG(tx_flags,
  6661. IXGBE_TX_FLAGS_CSUM,
  6662. IXGBE_ADVTXD_POPTS_TXSM);
  6663. /* enable IPv4 checksum for TSO */
  6664. olinfo_status |= IXGBE_SET_FLAG(tx_flags,
  6665. IXGBE_TX_FLAGS_IPV4,
  6666. IXGBE_ADVTXD_POPTS_IXSM);
  6667. /* enable IPsec */
  6668. olinfo_status |= IXGBE_SET_FLAG(tx_flags,
  6669. IXGBE_TX_FLAGS_IPSEC,
  6670. IXGBE_ADVTXD_POPTS_IPSEC);
  6671. /*
  6672. * Check Context must be set if Tx switch is enabled, which it
  6673. * always is for case where virtual functions are running
  6674. */
  6675. olinfo_status |= IXGBE_SET_FLAG(tx_flags,
  6676. IXGBE_TX_FLAGS_CC,
  6677. IXGBE_ADVTXD_CC);
  6678. tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
  6679. }
  6680. static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
  6681. {
  6682. netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
  6683. /* Herbert's original patch had:
  6684. * smp_mb__after_netif_stop_queue();
  6685. * but since that doesn't exist yet, just open code it.
  6686. */
  6687. smp_mb();
  6688. /* We need to check again in a case another CPU has just
  6689. * made room available.
  6690. */
  6691. if (likely(ixgbe_desc_unused(tx_ring) < size))
  6692. return -EBUSY;
  6693. /* A reprieve! - use start_queue because it doesn't call schedule */
  6694. netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
  6695. ++tx_ring->tx_stats.restart_queue;
  6696. return 0;
  6697. }
  6698. static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
  6699. {
  6700. if (likely(ixgbe_desc_unused(tx_ring) >= size))
  6701. return 0;
  6702. return __ixgbe_maybe_stop_tx(tx_ring, size);
  6703. }
  6704. #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
  6705. IXGBE_TXD_CMD_RS)
  6706. static int ixgbe_tx_map(struct ixgbe_ring *tx_ring,
  6707. struct ixgbe_tx_buffer *first,
  6708. const u8 hdr_len)
  6709. {
  6710. struct sk_buff *skb = first->skb;
  6711. struct ixgbe_tx_buffer *tx_buffer;
  6712. union ixgbe_adv_tx_desc *tx_desc;
  6713. struct skb_frag_struct *frag;
  6714. dma_addr_t dma;
  6715. unsigned int data_len, size;
  6716. u32 tx_flags = first->tx_flags;
  6717. u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
  6718. u16 i = tx_ring->next_to_use;
  6719. tx_desc = IXGBE_TX_DESC(tx_ring, i);
  6720. ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
  6721. size = skb_headlen(skb);
  6722. data_len = skb->data_len;
  6723. #ifdef IXGBE_FCOE
  6724. if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
  6725. if (data_len < sizeof(struct fcoe_crc_eof)) {
  6726. size -= sizeof(struct fcoe_crc_eof) - data_len;
  6727. data_len = 0;
  6728. } else {
  6729. data_len -= sizeof(struct fcoe_crc_eof);
  6730. }
  6731. }
  6732. #endif
  6733. dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
  6734. tx_buffer = first;
  6735. for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
  6736. if (dma_mapping_error(tx_ring->dev, dma))
  6737. goto dma_error;
  6738. /* record length, and DMA address */
  6739. dma_unmap_len_set(tx_buffer, len, size);
  6740. dma_unmap_addr_set(tx_buffer, dma, dma);
  6741. tx_desc->read.buffer_addr = cpu_to_le64(dma);
  6742. while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
  6743. tx_desc->read.cmd_type_len =
  6744. cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
  6745. i++;
  6746. tx_desc++;
  6747. if (i == tx_ring->count) {
  6748. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  6749. i = 0;
  6750. }
  6751. tx_desc->read.olinfo_status = 0;
  6752. dma += IXGBE_MAX_DATA_PER_TXD;
  6753. size -= IXGBE_MAX_DATA_PER_TXD;
  6754. tx_desc->read.buffer_addr = cpu_to_le64(dma);
  6755. }
  6756. if (likely(!data_len))
  6757. break;
  6758. tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
  6759. i++;
  6760. tx_desc++;
  6761. if (i == tx_ring->count) {
  6762. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  6763. i = 0;
  6764. }
  6765. tx_desc->read.olinfo_status = 0;
  6766. #ifdef IXGBE_FCOE
  6767. size = min_t(unsigned int, data_len, skb_frag_size(frag));
  6768. #else
  6769. size = skb_frag_size(frag);
  6770. #endif
  6771. data_len -= size;
  6772. dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
  6773. DMA_TO_DEVICE);
  6774. tx_buffer = &tx_ring->tx_buffer_info[i];
  6775. }
  6776. /* write last descriptor with RS and EOP bits */
  6777. cmd_type |= size | IXGBE_TXD_CMD;
  6778. tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
  6779. netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
  6780. /* set the timestamp */
  6781. first->time_stamp = jiffies;
  6782. /*
  6783. * Force memory writes to complete before letting h/w know there
  6784. * are new descriptors to fetch. (Only applicable for weak-ordered
  6785. * memory model archs, such as IA-64).
  6786. *
  6787. * We also need this memory barrier to make certain all of the
  6788. * status bits have been updated before next_to_watch is written.
  6789. */
  6790. wmb();
  6791. /* set next_to_watch value indicating a packet is present */
  6792. first->next_to_watch = tx_desc;
  6793. i++;
  6794. if (i == tx_ring->count)
  6795. i = 0;
  6796. tx_ring->next_to_use = i;
  6797. ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
  6798. if (netif_xmit_stopped(txring_txq(tx_ring)) || !skb->xmit_more) {
  6799. writel(i, tx_ring->tail);
  6800. /* we need this if more than one processor can write to our tail
  6801. * at a time, it synchronizes IO on IA64/Altix systems
  6802. */
  6803. mmiowb();
  6804. }
  6805. return 0;
  6806. dma_error:
  6807. dev_err(tx_ring->dev, "TX DMA map failed\n");
  6808. /* clear dma mappings for failed tx_buffer_info map */
  6809. for (;;) {
  6810. tx_buffer = &tx_ring->tx_buffer_info[i];
  6811. if (dma_unmap_len(tx_buffer, len))
  6812. dma_unmap_page(tx_ring->dev,
  6813. dma_unmap_addr(tx_buffer, dma),
  6814. dma_unmap_len(tx_buffer, len),
  6815. DMA_TO_DEVICE);
  6816. dma_unmap_len_set(tx_buffer, len, 0);
  6817. if (tx_buffer == first)
  6818. break;
  6819. if (i == 0)
  6820. i += tx_ring->count;
  6821. i--;
  6822. }
  6823. dev_kfree_skb_any(first->skb);
  6824. first->skb = NULL;
  6825. tx_ring->next_to_use = i;
  6826. return -1;
  6827. }
  6828. static void ixgbe_atr(struct ixgbe_ring *ring,
  6829. struct ixgbe_tx_buffer *first)
  6830. {
  6831. struct ixgbe_q_vector *q_vector = ring->q_vector;
  6832. union ixgbe_atr_hash_dword input = { .dword = 0 };
  6833. union ixgbe_atr_hash_dword common = { .dword = 0 };
  6834. union {
  6835. unsigned char *network;
  6836. struct iphdr *ipv4;
  6837. struct ipv6hdr *ipv6;
  6838. } hdr;
  6839. struct tcphdr *th;
  6840. unsigned int hlen;
  6841. struct sk_buff *skb;
  6842. __be16 vlan_id;
  6843. int l4_proto;
  6844. /* if ring doesn't have a interrupt vector, cannot perform ATR */
  6845. if (!q_vector)
  6846. return;
  6847. /* do nothing if sampling is disabled */
  6848. if (!ring->atr_sample_rate)
  6849. return;
  6850. ring->atr_count++;
  6851. /* currently only IPv4/IPv6 with TCP is supported */
  6852. if ((first->protocol != htons(ETH_P_IP)) &&
  6853. (first->protocol != htons(ETH_P_IPV6)))
  6854. return;
  6855. /* snag network header to get L4 type and address */
  6856. skb = first->skb;
  6857. hdr.network = skb_network_header(skb);
  6858. if (unlikely(hdr.network <= skb->data))
  6859. return;
  6860. if (skb->encapsulation &&
  6861. first->protocol == htons(ETH_P_IP) &&
  6862. hdr.ipv4->protocol == IPPROTO_UDP) {
  6863. struct ixgbe_adapter *adapter = q_vector->adapter;
  6864. if (unlikely(skb_tail_pointer(skb) < hdr.network +
  6865. VXLAN_HEADROOM))
  6866. return;
  6867. /* verify the port is recognized as VXLAN */
  6868. if (adapter->vxlan_port &&
  6869. udp_hdr(skb)->dest == adapter->vxlan_port)
  6870. hdr.network = skb_inner_network_header(skb);
  6871. if (adapter->geneve_port &&
  6872. udp_hdr(skb)->dest == adapter->geneve_port)
  6873. hdr.network = skb_inner_network_header(skb);
  6874. }
  6875. /* Make sure we have at least [minimum IPv4 header + TCP]
  6876. * or [IPv6 header] bytes
  6877. */
  6878. if (unlikely(skb_tail_pointer(skb) < hdr.network + 40))
  6879. return;
  6880. /* Currently only IPv4/IPv6 with TCP is supported */
  6881. switch (hdr.ipv4->version) {
  6882. case IPVERSION:
  6883. /* access ihl as u8 to avoid unaligned access on ia64 */
  6884. hlen = (hdr.network[0] & 0x0F) << 2;
  6885. l4_proto = hdr.ipv4->protocol;
  6886. break;
  6887. case 6:
  6888. hlen = hdr.network - skb->data;
  6889. l4_proto = ipv6_find_hdr(skb, &hlen, IPPROTO_TCP, NULL, NULL);
  6890. hlen -= hdr.network - skb->data;
  6891. break;
  6892. default:
  6893. return;
  6894. }
  6895. if (l4_proto != IPPROTO_TCP)
  6896. return;
  6897. if (unlikely(skb_tail_pointer(skb) < hdr.network +
  6898. hlen + sizeof(struct tcphdr)))
  6899. return;
  6900. th = (struct tcphdr *)(hdr.network + hlen);
  6901. /* skip this packet since the socket is closing */
  6902. if (th->fin)
  6903. return;
  6904. /* sample on all syn packets or once every atr sample count */
  6905. if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
  6906. return;
  6907. /* reset sample count */
  6908. ring->atr_count = 0;
  6909. vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
  6910. /*
  6911. * src and dst are inverted, think how the receiver sees them
  6912. *
  6913. * The input is broken into two sections, a non-compressed section
  6914. * containing vm_pool, vlan_id, and flow_type. The rest of the data
  6915. * is XORed together and stored in the compressed dword.
  6916. */
  6917. input.formatted.vlan_id = vlan_id;
  6918. /*
  6919. * since src port and flex bytes occupy the same word XOR them together
  6920. * and write the value to source port portion of compressed dword
  6921. */
  6922. if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
  6923. common.port.src ^= th->dest ^ htons(ETH_P_8021Q);
  6924. else
  6925. common.port.src ^= th->dest ^ first->protocol;
  6926. common.port.dst ^= th->source;
  6927. switch (hdr.ipv4->version) {
  6928. case IPVERSION:
  6929. input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
  6930. common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
  6931. break;
  6932. case 6:
  6933. input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
  6934. common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
  6935. hdr.ipv6->saddr.s6_addr32[1] ^
  6936. hdr.ipv6->saddr.s6_addr32[2] ^
  6937. hdr.ipv6->saddr.s6_addr32[3] ^
  6938. hdr.ipv6->daddr.s6_addr32[0] ^
  6939. hdr.ipv6->daddr.s6_addr32[1] ^
  6940. hdr.ipv6->daddr.s6_addr32[2] ^
  6941. hdr.ipv6->daddr.s6_addr32[3];
  6942. break;
  6943. default:
  6944. break;
  6945. }
  6946. if (hdr.network != skb_network_header(skb))
  6947. input.formatted.flow_type |= IXGBE_ATR_L4TYPE_TUNNEL_MASK;
  6948. /* This assumes the Rx queue and Tx queue are bound to the same CPU */
  6949. ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
  6950. input, common, ring->queue_index);
  6951. }
  6952. static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
  6953. void *accel_priv, select_queue_fallback_t fallback)
  6954. {
  6955. struct ixgbe_fwd_adapter *fwd_adapter = accel_priv;
  6956. struct ixgbe_adapter *adapter;
  6957. int txq;
  6958. #ifdef IXGBE_FCOE
  6959. struct ixgbe_ring_feature *f;
  6960. #endif
  6961. if (fwd_adapter) {
  6962. adapter = netdev_priv(dev);
  6963. txq = reciprocal_scale(skb_get_hash(skb),
  6964. adapter->num_rx_queues_per_pool);
  6965. return txq + fwd_adapter->tx_base_queue;
  6966. }
  6967. #ifdef IXGBE_FCOE
  6968. /*
  6969. * only execute the code below if protocol is FCoE
  6970. * or FIP and we have FCoE enabled on the adapter
  6971. */
  6972. switch (vlan_get_protocol(skb)) {
  6973. case htons(ETH_P_FCOE):
  6974. case htons(ETH_P_FIP):
  6975. adapter = netdev_priv(dev);
  6976. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
  6977. break;
  6978. /* fall through */
  6979. default:
  6980. return fallback(dev, skb);
  6981. }
  6982. f = &adapter->ring_feature[RING_F_FCOE];
  6983. txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
  6984. smp_processor_id();
  6985. while (txq >= f->indices)
  6986. txq -= f->indices;
  6987. return txq + f->offset;
  6988. #else
  6989. return fallback(dev, skb);
  6990. #endif
  6991. }
  6992. static int ixgbe_xmit_xdp_ring(struct ixgbe_adapter *adapter,
  6993. struct xdp_frame *xdpf)
  6994. {
  6995. struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()];
  6996. struct ixgbe_tx_buffer *tx_buffer;
  6997. union ixgbe_adv_tx_desc *tx_desc;
  6998. u32 len, cmd_type;
  6999. dma_addr_t dma;
  7000. u16 i;
  7001. len = xdpf->len;
  7002. if (unlikely(!ixgbe_desc_unused(ring)))
  7003. return IXGBE_XDP_CONSUMED;
  7004. dma = dma_map_single(ring->dev, xdpf->data, len, DMA_TO_DEVICE);
  7005. if (dma_mapping_error(ring->dev, dma))
  7006. return IXGBE_XDP_CONSUMED;
  7007. /* record the location of the first descriptor for this packet */
  7008. tx_buffer = &ring->tx_buffer_info[ring->next_to_use];
  7009. tx_buffer->bytecount = len;
  7010. tx_buffer->gso_segs = 1;
  7011. tx_buffer->protocol = 0;
  7012. i = ring->next_to_use;
  7013. tx_desc = IXGBE_TX_DESC(ring, i);
  7014. dma_unmap_len_set(tx_buffer, len, len);
  7015. dma_unmap_addr_set(tx_buffer, dma, dma);
  7016. tx_buffer->xdpf = xdpf;
  7017. tx_desc->read.buffer_addr = cpu_to_le64(dma);
  7018. /* put descriptor type bits */
  7019. cmd_type = IXGBE_ADVTXD_DTYP_DATA |
  7020. IXGBE_ADVTXD_DCMD_DEXT |
  7021. IXGBE_ADVTXD_DCMD_IFCS;
  7022. cmd_type |= len | IXGBE_TXD_CMD;
  7023. tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
  7024. tx_desc->read.olinfo_status =
  7025. cpu_to_le32(len << IXGBE_ADVTXD_PAYLEN_SHIFT);
  7026. /* Avoid any potential race with xdp_xmit and cleanup */
  7027. smp_wmb();
  7028. /* set next_to_watch value indicating a packet is present */
  7029. i++;
  7030. if (i == ring->count)
  7031. i = 0;
  7032. tx_buffer->next_to_watch = tx_desc;
  7033. ring->next_to_use = i;
  7034. return IXGBE_XDP_TX;
  7035. }
  7036. netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
  7037. struct ixgbe_adapter *adapter,
  7038. struct ixgbe_ring *tx_ring)
  7039. {
  7040. struct ixgbe_tx_buffer *first;
  7041. int tso;
  7042. u32 tx_flags = 0;
  7043. unsigned short f;
  7044. u16 count = TXD_USE_COUNT(skb_headlen(skb));
  7045. struct ixgbe_ipsec_tx_data ipsec_tx = { 0 };
  7046. __be16 protocol = skb->protocol;
  7047. u8 hdr_len = 0;
  7048. /*
  7049. * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
  7050. * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
  7051. * + 2 desc gap to keep tail from touching head,
  7052. * + 1 desc for context descriptor,
  7053. * otherwise try next time
  7054. */
  7055. for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
  7056. count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
  7057. if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
  7058. tx_ring->tx_stats.tx_busy++;
  7059. return NETDEV_TX_BUSY;
  7060. }
  7061. /* record the location of the first descriptor for this packet */
  7062. first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
  7063. first->skb = skb;
  7064. first->bytecount = skb->len;
  7065. first->gso_segs = 1;
  7066. /* if we have a HW VLAN tag being added default to the HW one */
  7067. if (skb_vlan_tag_present(skb)) {
  7068. tx_flags |= skb_vlan_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
  7069. tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
  7070. /* else if it is a SW VLAN check the next protocol and store the tag */
  7071. } else if (protocol == htons(ETH_P_8021Q)) {
  7072. struct vlan_hdr *vhdr, _vhdr;
  7073. vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
  7074. if (!vhdr)
  7075. goto out_drop;
  7076. tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
  7077. IXGBE_TX_FLAGS_VLAN_SHIFT;
  7078. tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
  7079. }
  7080. protocol = vlan_get_protocol(skb);
  7081. if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
  7082. adapter->ptp_clock) {
  7083. if (!test_and_set_bit_lock(__IXGBE_PTP_TX_IN_PROGRESS,
  7084. &adapter->state)) {
  7085. skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
  7086. tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
  7087. /* schedule check for Tx timestamp */
  7088. adapter->ptp_tx_skb = skb_get(skb);
  7089. adapter->ptp_tx_start = jiffies;
  7090. schedule_work(&adapter->ptp_tx_work);
  7091. } else {
  7092. adapter->tx_hwtstamp_skipped++;
  7093. }
  7094. }
  7095. skb_tx_timestamp(skb);
  7096. #ifdef CONFIG_PCI_IOV
  7097. /*
  7098. * Use the l2switch_enable flag - would be false if the DMA
  7099. * Tx switch had been disabled.
  7100. */
  7101. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  7102. tx_flags |= IXGBE_TX_FLAGS_CC;
  7103. #endif
  7104. /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
  7105. if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
  7106. ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
  7107. (skb->priority != TC_PRIO_CONTROL))) {
  7108. tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
  7109. tx_flags |= (skb->priority & 0x7) <<
  7110. IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
  7111. if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
  7112. struct vlan_ethhdr *vhdr;
  7113. if (skb_cow_head(skb, 0))
  7114. goto out_drop;
  7115. vhdr = (struct vlan_ethhdr *)skb->data;
  7116. vhdr->h_vlan_TCI = htons(tx_flags >>
  7117. IXGBE_TX_FLAGS_VLAN_SHIFT);
  7118. } else {
  7119. tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
  7120. }
  7121. }
  7122. /* record initial flags and protocol */
  7123. first->tx_flags = tx_flags;
  7124. first->protocol = protocol;
  7125. #ifdef IXGBE_FCOE
  7126. /* setup tx offload for FCoE */
  7127. if ((protocol == htons(ETH_P_FCOE)) &&
  7128. (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
  7129. tso = ixgbe_fso(tx_ring, first, &hdr_len);
  7130. if (tso < 0)
  7131. goto out_drop;
  7132. goto xmit_fcoe;
  7133. }
  7134. #endif /* IXGBE_FCOE */
  7135. #ifdef CONFIG_XFRM_OFFLOAD
  7136. if (skb->sp && !ixgbe_ipsec_tx(tx_ring, first, &ipsec_tx))
  7137. goto out_drop;
  7138. #endif
  7139. tso = ixgbe_tso(tx_ring, first, &hdr_len, &ipsec_tx);
  7140. if (tso < 0)
  7141. goto out_drop;
  7142. else if (!tso)
  7143. ixgbe_tx_csum(tx_ring, first, &ipsec_tx);
  7144. /* add the ATR filter if ATR is on */
  7145. if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
  7146. ixgbe_atr(tx_ring, first);
  7147. #ifdef IXGBE_FCOE
  7148. xmit_fcoe:
  7149. #endif /* IXGBE_FCOE */
  7150. if (ixgbe_tx_map(tx_ring, first, hdr_len))
  7151. goto cleanup_tx_timestamp;
  7152. return NETDEV_TX_OK;
  7153. out_drop:
  7154. dev_kfree_skb_any(first->skb);
  7155. first->skb = NULL;
  7156. cleanup_tx_timestamp:
  7157. if (unlikely(tx_flags & IXGBE_TX_FLAGS_TSTAMP)) {
  7158. dev_kfree_skb_any(adapter->ptp_tx_skb);
  7159. adapter->ptp_tx_skb = NULL;
  7160. cancel_work_sync(&adapter->ptp_tx_work);
  7161. clear_bit_unlock(__IXGBE_PTP_TX_IN_PROGRESS, &adapter->state);
  7162. }
  7163. return NETDEV_TX_OK;
  7164. }
  7165. static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
  7166. struct net_device *netdev,
  7167. struct ixgbe_ring *ring)
  7168. {
  7169. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7170. struct ixgbe_ring *tx_ring;
  7171. /*
  7172. * The minimum packet size for olinfo paylen is 17 so pad the skb
  7173. * in order to meet this minimum size requirement.
  7174. */
  7175. if (skb_put_padto(skb, 17))
  7176. return NETDEV_TX_OK;
  7177. tx_ring = ring ? ring : adapter->tx_ring[skb->queue_mapping];
  7178. return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
  7179. }
  7180. static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
  7181. struct net_device *netdev)
  7182. {
  7183. return __ixgbe_xmit_frame(skb, netdev, NULL);
  7184. }
  7185. /**
  7186. * ixgbe_set_mac - Change the Ethernet Address of the NIC
  7187. * @netdev: network interface device structure
  7188. * @p: pointer to an address structure
  7189. *
  7190. * Returns 0 on success, negative on failure
  7191. **/
  7192. static int ixgbe_set_mac(struct net_device *netdev, void *p)
  7193. {
  7194. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7195. struct ixgbe_hw *hw = &adapter->hw;
  7196. struct sockaddr *addr = p;
  7197. if (!is_valid_ether_addr(addr->sa_data))
  7198. return -EADDRNOTAVAIL;
  7199. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  7200. memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
  7201. ixgbe_mac_set_default_filter(adapter);
  7202. return 0;
  7203. }
  7204. static int
  7205. ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
  7206. {
  7207. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7208. struct ixgbe_hw *hw = &adapter->hw;
  7209. u16 value;
  7210. int rc;
  7211. if (prtad != hw->phy.mdio.prtad)
  7212. return -EINVAL;
  7213. rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
  7214. if (!rc)
  7215. rc = value;
  7216. return rc;
  7217. }
  7218. static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
  7219. u16 addr, u16 value)
  7220. {
  7221. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7222. struct ixgbe_hw *hw = &adapter->hw;
  7223. if (prtad != hw->phy.mdio.prtad)
  7224. return -EINVAL;
  7225. return hw->phy.ops.write_reg(hw, addr, devad, value);
  7226. }
  7227. static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
  7228. {
  7229. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7230. switch (cmd) {
  7231. case SIOCSHWTSTAMP:
  7232. return ixgbe_ptp_set_ts_config(adapter, req);
  7233. case SIOCGHWTSTAMP:
  7234. return ixgbe_ptp_get_ts_config(adapter, req);
  7235. case SIOCGMIIPHY:
  7236. if (!adapter->hw.phy.ops.read_reg)
  7237. return -EOPNOTSUPP;
  7238. /* fall through */
  7239. default:
  7240. return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
  7241. }
  7242. }
  7243. /**
  7244. * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
  7245. * netdev->dev_addrs
  7246. * @dev: network interface device structure
  7247. *
  7248. * Returns non-zero on failure
  7249. **/
  7250. static int ixgbe_add_sanmac_netdev(struct net_device *dev)
  7251. {
  7252. int err = 0;
  7253. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7254. struct ixgbe_hw *hw = &adapter->hw;
  7255. if (is_valid_ether_addr(hw->mac.san_addr)) {
  7256. rtnl_lock();
  7257. err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
  7258. rtnl_unlock();
  7259. /* update SAN MAC vmdq pool selection */
  7260. hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
  7261. }
  7262. return err;
  7263. }
  7264. /**
  7265. * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
  7266. * netdev->dev_addrs
  7267. * @dev: network interface device structure
  7268. *
  7269. * Returns non-zero on failure
  7270. **/
  7271. static int ixgbe_del_sanmac_netdev(struct net_device *dev)
  7272. {
  7273. int err = 0;
  7274. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7275. struct ixgbe_mac_info *mac = &adapter->hw.mac;
  7276. if (is_valid_ether_addr(mac->san_addr)) {
  7277. rtnl_lock();
  7278. err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
  7279. rtnl_unlock();
  7280. }
  7281. return err;
  7282. }
  7283. #ifdef CONFIG_NET_POLL_CONTROLLER
  7284. /*
  7285. * Polling 'interrupt' - used by things like netconsole to send skbs
  7286. * without having to re-enable interrupts. It's not called while
  7287. * the interrupt routine is executing.
  7288. */
  7289. static void ixgbe_netpoll(struct net_device *netdev)
  7290. {
  7291. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7292. int i;
  7293. /* if interface is down do nothing */
  7294. if (test_bit(__IXGBE_DOWN, &adapter->state))
  7295. return;
  7296. /* loop through and schedule all active queues */
  7297. for (i = 0; i < adapter->num_q_vectors; i++)
  7298. ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
  7299. }
  7300. #endif
  7301. static void ixgbe_get_ring_stats64(struct rtnl_link_stats64 *stats,
  7302. struct ixgbe_ring *ring)
  7303. {
  7304. u64 bytes, packets;
  7305. unsigned int start;
  7306. if (ring) {
  7307. do {
  7308. start = u64_stats_fetch_begin_irq(&ring->syncp);
  7309. packets = ring->stats.packets;
  7310. bytes = ring->stats.bytes;
  7311. } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
  7312. stats->tx_packets += packets;
  7313. stats->tx_bytes += bytes;
  7314. }
  7315. }
  7316. static void ixgbe_get_stats64(struct net_device *netdev,
  7317. struct rtnl_link_stats64 *stats)
  7318. {
  7319. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7320. int i;
  7321. rcu_read_lock();
  7322. for (i = 0; i < adapter->num_rx_queues; i++) {
  7323. struct ixgbe_ring *ring = READ_ONCE(adapter->rx_ring[i]);
  7324. u64 bytes, packets;
  7325. unsigned int start;
  7326. if (ring) {
  7327. do {
  7328. start = u64_stats_fetch_begin_irq(&ring->syncp);
  7329. packets = ring->stats.packets;
  7330. bytes = ring->stats.bytes;
  7331. } while (u64_stats_fetch_retry_irq(&ring->syncp, start));
  7332. stats->rx_packets += packets;
  7333. stats->rx_bytes += bytes;
  7334. }
  7335. }
  7336. for (i = 0; i < adapter->num_tx_queues; i++) {
  7337. struct ixgbe_ring *ring = READ_ONCE(adapter->tx_ring[i]);
  7338. ixgbe_get_ring_stats64(stats, ring);
  7339. }
  7340. for (i = 0; i < adapter->num_xdp_queues; i++) {
  7341. struct ixgbe_ring *ring = READ_ONCE(adapter->xdp_ring[i]);
  7342. ixgbe_get_ring_stats64(stats, ring);
  7343. }
  7344. rcu_read_unlock();
  7345. /* following stats updated by ixgbe_watchdog_task() */
  7346. stats->multicast = netdev->stats.multicast;
  7347. stats->rx_errors = netdev->stats.rx_errors;
  7348. stats->rx_length_errors = netdev->stats.rx_length_errors;
  7349. stats->rx_crc_errors = netdev->stats.rx_crc_errors;
  7350. stats->rx_missed_errors = netdev->stats.rx_missed_errors;
  7351. }
  7352. #ifdef CONFIG_IXGBE_DCB
  7353. /**
  7354. * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
  7355. * @adapter: pointer to ixgbe_adapter
  7356. * @tc: number of traffic classes currently enabled
  7357. *
  7358. * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
  7359. * 802.1Q priority maps to a packet buffer that exists.
  7360. */
  7361. static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
  7362. {
  7363. struct ixgbe_hw *hw = &adapter->hw;
  7364. u32 reg, rsave;
  7365. int i;
  7366. /* 82598 have a static priority to TC mapping that can not
  7367. * be changed so no validation is needed.
  7368. */
  7369. if (hw->mac.type == ixgbe_mac_82598EB)
  7370. return;
  7371. reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
  7372. rsave = reg;
  7373. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  7374. u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
  7375. /* If up2tc is out of bounds default to zero */
  7376. if (up2tc > tc)
  7377. reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
  7378. }
  7379. if (reg != rsave)
  7380. IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
  7381. return;
  7382. }
  7383. /**
  7384. * ixgbe_set_prio_tc_map - Configure netdev prio tc map
  7385. * @adapter: Pointer to adapter struct
  7386. *
  7387. * Populate the netdev user priority to tc map
  7388. */
  7389. static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
  7390. {
  7391. struct net_device *dev = adapter->netdev;
  7392. struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
  7393. struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
  7394. u8 prio;
  7395. for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
  7396. u8 tc = 0;
  7397. if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
  7398. tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
  7399. else if (ets)
  7400. tc = ets->prio_tc[prio];
  7401. netdev_set_prio_tc_map(dev, prio, tc);
  7402. }
  7403. }
  7404. #endif /* CONFIG_IXGBE_DCB */
  7405. static int ixgbe_reassign_macvlan_pool(struct net_device *vdev, void *data)
  7406. {
  7407. struct ixgbe_adapter *adapter = data;
  7408. struct ixgbe_fwd_adapter *accel;
  7409. int pool;
  7410. /* we only care about macvlans... */
  7411. if (!netif_is_macvlan(vdev))
  7412. return 0;
  7413. /* that have hardware offload enabled... */
  7414. accel = macvlan_accel_priv(vdev);
  7415. if (!accel)
  7416. return 0;
  7417. /* If we can relocate to a different bit do so */
  7418. pool = find_first_zero_bit(adapter->fwd_bitmask, adapter->num_rx_pools);
  7419. if (pool < adapter->num_rx_pools) {
  7420. set_bit(pool, adapter->fwd_bitmask);
  7421. accel->pool = pool;
  7422. return 0;
  7423. }
  7424. /* if we cannot find a free pool then disable the offload */
  7425. netdev_err(vdev, "L2FW offload disabled due to lack of queue resources\n");
  7426. macvlan_release_l2fw_offload(vdev);
  7427. kfree(accel);
  7428. return 0;
  7429. }
  7430. static void ixgbe_defrag_macvlan_pools(struct net_device *dev)
  7431. {
  7432. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7433. /* flush any stale bits out of the fwd bitmask */
  7434. bitmap_clear(adapter->fwd_bitmask, 1, 63);
  7435. /* walk through upper devices reassigning pools */
  7436. netdev_walk_all_upper_dev_rcu(dev, ixgbe_reassign_macvlan_pool,
  7437. adapter);
  7438. }
  7439. /**
  7440. * ixgbe_setup_tc - configure net_device for multiple traffic classes
  7441. *
  7442. * @dev: net device to configure
  7443. * @tc: number of traffic classes to enable
  7444. */
  7445. int ixgbe_setup_tc(struct net_device *dev, u8 tc)
  7446. {
  7447. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7448. struct ixgbe_hw *hw = &adapter->hw;
  7449. /* Hardware supports up to 8 traffic classes */
  7450. if (tc > adapter->dcb_cfg.num_tcs.pg_tcs)
  7451. return -EINVAL;
  7452. if (hw->mac.type == ixgbe_mac_82598EB && tc && tc < MAX_TRAFFIC_CLASS)
  7453. return -EINVAL;
  7454. /* Hardware has to reinitialize queues and interrupts to
  7455. * match packet buffer alignment. Unfortunately, the
  7456. * hardware is not flexible enough to do this dynamically.
  7457. */
  7458. if (netif_running(dev))
  7459. ixgbe_close(dev);
  7460. else
  7461. ixgbe_reset(adapter);
  7462. ixgbe_clear_interrupt_scheme(adapter);
  7463. #ifdef CONFIG_IXGBE_DCB
  7464. if (tc) {
  7465. netdev_set_num_tc(dev, tc);
  7466. ixgbe_set_prio_tc_map(adapter);
  7467. adapter->hw_tcs = tc;
  7468. adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
  7469. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  7470. adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
  7471. adapter->hw.fc.requested_mode = ixgbe_fc_none;
  7472. }
  7473. } else {
  7474. netdev_reset_tc(dev);
  7475. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  7476. adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
  7477. adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
  7478. adapter->hw_tcs = tc;
  7479. adapter->temp_dcb_cfg.pfc_mode_enable = false;
  7480. adapter->dcb_cfg.pfc_mode_enable = false;
  7481. }
  7482. ixgbe_validate_rtr(adapter, tc);
  7483. #endif /* CONFIG_IXGBE_DCB */
  7484. ixgbe_init_interrupt_scheme(adapter);
  7485. ixgbe_defrag_macvlan_pools(dev);
  7486. if (netif_running(dev))
  7487. return ixgbe_open(dev);
  7488. return 0;
  7489. }
  7490. static int ixgbe_delete_clsu32(struct ixgbe_adapter *adapter,
  7491. struct tc_cls_u32_offload *cls)
  7492. {
  7493. u32 hdl = cls->knode.handle;
  7494. u32 uhtid = TC_U32_USERHTID(cls->knode.handle);
  7495. u32 loc = cls->knode.handle & 0xfffff;
  7496. int err = 0, i, j;
  7497. struct ixgbe_jump_table *jump = NULL;
  7498. if (loc > IXGBE_MAX_HW_ENTRIES)
  7499. return -EINVAL;
  7500. if ((uhtid != 0x800) && (uhtid >= IXGBE_MAX_LINK_HANDLE))
  7501. return -EINVAL;
  7502. /* Clear this filter in the link data it is associated with */
  7503. if (uhtid != 0x800) {
  7504. jump = adapter->jump_tables[uhtid];
  7505. if (!jump)
  7506. return -EINVAL;
  7507. if (!test_bit(loc - 1, jump->child_loc_map))
  7508. return -EINVAL;
  7509. clear_bit(loc - 1, jump->child_loc_map);
  7510. }
  7511. /* Check if the filter being deleted is a link */
  7512. for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
  7513. jump = adapter->jump_tables[i];
  7514. if (jump && jump->link_hdl == hdl) {
  7515. /* Delete filters in the hardware in the child hash
  7516. * table associated with this link
  7517. */
  7518. for (j = 0; j < IXGBE_MAX_HW_ENTRIES; j++) {
  7519. if (!test_bit(j, jump->child_loc_map))
  7520. continue;
  7521. spin_lock(&adapter->fdir_perfect_lock);
  7522. err = ixgbe_update_ethtool_fdir_entry(adapter,
  7523. NULL,
  7524. j + 1);
  7525. spin_unlock(&adapter->fdir_perfect_lock);
  7526. clear_bit(j, jump->child_loc_map);
  7527. }
  7528. /* Remove resources for this link */
  7529. kfree(jump->input);
  7530. kfree(jump->mask);
  7531. kfree(jump);
  7532. adapter->jump_tables[i] = NULL;
  7533. return err;
  7534. }
  7535. }
  7536. spin_lock(&adapter->fdir_perfect_lock);
  7537. err = ixgbe_update_ethtool_fdir_entry(adapter, NULL, loc);
  7538. spin_unlock(&adapter->fdir_perfect_lock);
  7539. return err;
  7540. }
  7541. static int ixgbe_configure_clsu32_add_hnode(struct ixgbe_adapter *adapter,
  7542. struct tc_cls_u32_offload *cls)
  7543. {
  7544. u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
  7545. if (uhtid >= IXGBE_MAX_LINK_HANDLE)
  7546. return -EINVAL;
  7547. /* This ixgbe devices do not support hash tables at the moment
  7548. * so abort when given hash tables.
  7549. */
  7550. if (cls->hnode.divisor > 0)
  7551. return -EINVAL;
  7552. set_bit(uhtid - 1, &adapter->tables);
  7553. return 0;
  7554. }
  7555. static int ixgbe_configure_clsu32_del_hnode(struct ixgbe_adapter *adapter,
  7556. struct tc_cls_u32_offload *cls)
  7557. {
  7558. u32 uhtid = TC_U32_USERHTID(cls->hnode.handle);
  7559. if (uhtid >= IXGBE_MAX_LINK_HANDLE)
  7560. return -EINVAL;
  7561. clear_bit(uhtid - 1, &adapter->tables);
  7562. return 0;
  7563. }
  7564. #ifdef CONFIG_NET_CLS_ACT
  7565. struct upper_walk_data {
  7566. struct ixgbe_adapter *adapter;
  7567. u64 action;
  7568. int ifindex;
  7569. u8 queue;
  7570. };
  7571. static int get_macvlan_queue(struct net_device *upper, void *_data)
  7572. {
  7573. if (netif_is_macvlan(upper)) {
  7574. struct ixgbe_fwd_adapter *vadapter = macvlan_accel_priv(upper);
  7575. struct upper_walk_data *data = _data;
  7576. struct ixgbe_adapter *adapter = data->adapter;
  7577. int ifindex = data->ifindex;
  7578. if (vadapter && upper->ifindex == ifindex) {
  7579. data->queue = adapter->rx_ring[vadapter->rx_base_queue]->reg_idx;
  7580. data->action = data->queue;
  7581. return 1;
  7582. }
  7583. }
  7584. return 0;
  7585. }
  7586. static int handle_redirect_action(struct ixgbe_adapter *adapter, int ifindex,
  7587. u8 *queue, u64 *action)
  7588. {
  7589. struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
  7590. unsigned int num_vfs = adapter->num_vfs, vf;
  7591. struct upper_walk_data data;
  7592. struct net_device *upper;
  7593. /* redirect to a SRIOV VF */
  7594. for (vf = 0; vf < num_vfs; ++vf) {
  7595. upper = pci_get_drvdata(adapter->vfinfo[vf].vfdev);
  7596. if (upper->ifindex == ifindex) {
  7597. *queue = vf * __ALIGN_MASK(1, ~vmdq->mask);
  7598. *action = vf + 1;
  7599. *action <<= ETHTOOL_RX_FLOW_SPEC_RING_VF_OFF;
  7600. return 0;
  7601. }
  7602. }
  7603. /* redirect to a offloaded macvlan netdev */
  7604. data.adapter = adapter;
  7605. data.ifindex = ifindex;
  7606. data.action = 0;
  7607. data.queue = 0;
  7608. if (netdev_walk_all_upper_dev_rcu(adapter->netdev,
  7609. get_macvlan_queue, &data)) {
  7610. *action = data.action;
  7611. *queue = data.queue;
  7612. return 0;
  7613. }
  7614. return -EINVAL;
  7615. }
  7616. static int parse_tc_actions(struct ixgbe_adapter *adapter,
  7617. struct tcf_exts *exts, u64 *action, u8 *queue)
  7618. {
  7619. const struct tc_action *a;
  7620. LIST_HEAD(actions);
  7621. if (!tcf_exts_has_actions(exts))
  7622. return -EINVAL;
  7623. tcf_exts_to_list(exts, &actions);
  7624. list_for_each_entry(a, &actions, list) {
  7625. /* Drop action */
  7626. if (is_tcf_gact_shot(a)) {
  7627. *action = IXGBE_FDIR_DROP_QUEUE;
  7628. *queue = IXGBE_FDIR_DROP_QUEUE;
  7629. return 0;
  7630. }
  7631. /* Redirect to a VF or a offloaded macvlan */
  7632. if (is_tcf_mirred_egress_redirect(a)) {
  7633. struct net_device *dev = tcf_mirred_dev(a);
  7634. if (!dev)
  7635. return -EINVAL;
  7636. return handle_redirect_action(adapter, dev->ifindex,
  7637. queue, action);
  7638. }
  7639. return -EINVAL;
  7640. }
  7641. return -EINVAL;
  7642. }
  7643. #else
  7644. static int parse_tc_actions(struct ixgbe_adapter *adapter,
  7645. struct tcf_exts *exts, u64 *action, u8 *queue)
  7646. {
  7647. return -EINVAL;
  7648. }
  7649. #endif /* CONFIG_NET_CLS_ACT */
  7650. static int ixgbe_clsu32_build_input(struct ixgbe_fdir_filter *input,
  7651. union ixgbe_atr_input *mask,
  7652. struct tc_cls_u32_offload *cls,
  7653. struct ixgbe_mat_field *field_ptr,
  7654. struct ixgbe_nexthdr *nexthdr)
  7655. {
  7656. int i, j, off;
  7657. __be32 val, m;
  7658. bool found_entry = false, found_jump_field = false;
  7659. for (i = 0; i < cls->knode.sel->nkeys; i++) {
  7660. off = cls->knode.sel->keys[i].off;
  7661. val = cls->knode.sel->keys[i].val;
  7662. m = cls->knode.sel->keys[i].mask;
  7663. for (j = 0; field_ptr[j].val; j++) {
  7664. if (field_ptr[j].off == off) {
  7665. field_ptr[j].val(input, mask, (__force u32)val,
  7666. (__force u32)m);
  7667. input->filter.formatted.flow_type |=
  7668. field_ptr[j].type;
  7669. found_entry = true;
  7670. break;
  7671. }
  7672. }
  7673. if (nexthdr) {
  7674. if (nexthdr->off == cls->knode.sel->keys[i].off &&
  7675. nexthdr->val ==
  7676. (__force u32)cls->knode.sel->keys[i].val &&
  7677. nexthdr->mask ==
  7678. (__force u32)cls->knode.sel->keys[i].mask)
  7679. found_jump_field = true;
  7680. else
  7681. continue;
  7682. }
  7683. }
  7684. if (nexthdr && !found_jump_field)
  7685. return -EINVAL;
  7686. if (!found_entry)
  7687. return 0;
  7688. mask->formatted.flow_type = IXGBE_ATR_L4TYPE_IPV6_MASK |
  7689. IXGBE_ATR_L4TYPE_MASK;
  7690. if (input->filter.formatted.flow_type == IXGBE_ATR_FLOW_TYPE_IPV4)
  7691. mask->formatted.flow_type &= IXGBE_ATR_L4TYPE_IPV6_MASK;
  7692. return 0;
  7693. }
  7694. static int ixgbe_configure_clsu32(struct ixgbe_adapter *adapter,
  7695. struct tc_cls_u32_offload *cls)
  7696. {
  7697. __be16 protocol = cls->common.protocol;
  7698. u32 loc = cls->knode.handle & 0xfffff;
  7699. struct ixgbe_hw *hw = &adapter->hw;
  7700. struct ixgbe_mat_field *field_ptr;
  7701. struct ixgbe_fdir_filter *input = NULL;
  7702. union ixgbe_atr_input *mask = NULL;
  7703. struct ixgbe_jump_table *jump = NULL;
  7704. int i, err = -EINVAL;
  7705. u8 queue;
  7706. u32 uhtid, link_uhtid;
  7707. uhtid = TC_U32_USERHTID(cls->knode.handle);
  7708. link_uhtid = TC_U32_USERHTID(cls->knode.link_handle);
  7709. /* At the moment cls_u32 jumps to network layer and skips past
  7710. * L2 headers. The canonical method to match L2 frames is to use
  7711. * negative values. However this is error prone at best but really
  7712. * just broken because there is no way to "know" what sort of hdr
  7713. * is in front of the network layer. Fix cls_u32 to support L2
  7714. * headers when needed.
  7715. */
  7716. if (protocol != htons(ETH_P_IP))
  7717. return err;
  7718. if (loc >= ((1024 << adapter->fdir_pballoc) - 2)) {
  7719. e_err(drv, "Location out of range\n");
  7720. return err;
  7721. }
  7722. /* cls u32 is a graph starting at root node 0x800. The driver tracks
  7723. * links and also the fields used to advance the parser across each
  7724. * link (e.g. nexthdr/eat parameters from 'tc'). This way we can map
  7725. * the u32 graph onto the hardware parse graph denoted in ixgbe_model.h
  7726. * To add support for new nodes update ixgbe_model.h parse structures
  7727. * this function _should_ be generic try not to hardcode values here.
  7728. */
  7729. if (uhtid == 0x800) {
  7730. field_ptr = (adapter->jump_tables[0])->mat;
  7731. } else {
  7732. if (uhtid >= IXGBE_MAX_LINK_HANDLE)
  7733. return err;
  7734. if (!adapter->jump_tables[uhtid])
  7735. return err;
  7736. field_ptr = (adapter->jump_tables[uhtid])->mat;
  7737. }
  7738. if (!field_ptr)
  7739. return err;
  7740. /* At this point we know the field_ptr is valid and need to either
  7741. * build cls_u32 link or attach filter. Because adding a link to
  7742. * a handle that does not exist is invalid and the same for adding
  7743. * rules to handles that don't exist.
  7744. */
  7745. if (link_uhtid) {
  7746. struct ixgbe_nexthdr *nexthdr = ixgbe_ipv4_jumps;
  7747. if (link_uhtid >= IXGBE_MAX_LINK_HANDLE)
  7748. return err;
  7749. if (!test_bit(link_uhtid - 1, &adapter->tables))
  7750. return err;
  7751. /* Multiple filters as links to the same hash table are not
  7752. * supported. To add a new filter with the same next header
  7753. * but different match/jump conditions, create a new hash table
  7754. * and link to it.
  7755. */
  7756. if (adapter->jump_tables[link_uhtid] &&
  7757. (adapter->jump_tables[link_uhtid])->link_hdl) {
  7758. e_err(drv, "Link filter exists for link: %x\n",
  7759. link_uhtid);
  7760. return err;
  7761. }
  7762. for (i = 0; nexthdr[i].jump; i++) {
  7763. if (nexthdr[i].o != cls->knode.sel->offoff ||
  7764. nexthdr[i].s != cls->knode.sel->offshift ||
  7765. nexthdr[i].m !=
  7766. (__force u32)cls->knode.sel->offmask)
  7767. return err;
  7768. jump = kzalloc(sizeof(*jump), GFP_KERNEL);
  7769. if (!jump)
  7770. return -ENOMEM;
  7771. input = kzalloc(sizeof(*input), GFP_KERNEL);
  7772. if (!input) {
  7773. err = -ENOMEM;
  7774. goto free_jump;
  7775. }
  7776. mask = kzalloc(sizeof(*mask), GFP_KERNEL);
  7777. if (!mask) {
  7778. err = -ENOMEM;
  7779. goto free_input;
  7780. }
  7781. jump->input = input;
  7782. jump->mask = mask;
  7783. jump->link_hdl = cls->knode.handle;
  7784. err = ixgbe_clsu32_build_input(input, mask, cls,
  7785. field_ptr, &nexthdr[i]);
  7786. if (!err) {
  7787. jump->mat = nexthdr[i].jump;
  7788. adapter->jump_tables[link_uhtid] = jump;
  7789. break;
  7790. }
  7791. }
  7792. return 0;
  7793. }
  7794. input = kzalloc(sizeof(*input), GFP_KERNEL);
  7795. if (!input)
  7796. return -ENOMEM;
  7797. mask = kzalloc(sizeof(*mask), GFP_KERNEL);
  7798. if (!mask) {
  7799. err = -ENOMEM;
  7800. goto free_input;
  7801. }
  7802. if ((uhtid != 0x800) && (adapter->jump_tables[uhtid])) {
  7803. if ((adapter->jump_tables[uhtid])->input)
  7804. memcpy(input, (adapter->jump_tables[uhtid])->input,
  7805. sizeof(*input));
  7806. if ((adapter->jump_tables[uhtid])->mask)
  7807. memcpy(mask, (adapter->jump_tables[uhtid])->mask,
  7808. sizeof(*mask));
  7809. /* Lookup in all child hash tables if this location is already
  7810. * filled with a filter
  7811. */
  7812. for (i = 1; i < IXGBE_MAX_LINK_HANDLE; i++) {
  7813. struct ixgbe_jump_table *link = adapter->jump_tables[i];
  7814. if (link && (test_bit(loc - 1, link->child_loc_map))) {
  7815. e_err(drv, "Filter exists in location: %x\n",
  7816. loc);
  7817. err = -EINVAL;
  7818. goto err_out;
  7819. }
  7820. }
  7821. }
  7822. err = ixgbe_clsu32_build_input(input, mask, cls, field_ptr, NULL);
  7823. if (err)
  7824. goto err_out;
  7825. err = parse_tc_actions(adapter, cls->knode.exts, &input->action,
  7826. &queue);
  7827. if (err < 0)
  7828. goto err_out;
  7829. input->sw_idx = loc;
  7830. spin_lock(&adapter->fdir_perfect_lock);
  7831. if (hlist_empty(&adapter->fdir_filter_list)) {
  7832. memcpy(&adapter->fdir_mask, mask, sizeof(*mask));
  7833. err = ixgbe_fdir_set_input_mask_82599(hw, mask);
  7834. if (err)
  7835. goto err_out_w_lock;
  7836. } else if (memcmp(&adapter->fdir_mask, mask, sizeof(*mask))) {
  7837. err = -EINVAL;
  7838. goto err_out_w_lock;
  7839. }
  7840. ixgbe_atr_compute_perfect_hash_82599(&input->filter, mask);
  7841. err = ixgbe_fdir_write_perfect_filter_82599(hw, &input->filter,
  7842. input->sw_idx, queue);
  7843. if (!err)
  7844. ixgbe_update_ethtool_fdir_entry(adapter, input, input->sw_idx);
  7845. spin_unlock(&adapter->fdir_perfect_lock);
  7846. if ((uhtid != 0x800) && (adapter->jump_tables[uhtid]))
  7847. set_bit(loc - 1, (adapter->jump_tables[uhtid])->child_loc_map);
  7848. kfree(mask);
  7849. return err;
  7850. err_out_w_lock:
  7851. spin_unlock(&adapter->fdir_perfect_lock);
  7852. err_out:
  7853. kfree(mask);
  7854. free_input:
  7855. kfree(input);
  7856. free_jump:
  7857. kfree(jump);
  7858. return err;
  7859. }
  7860. static int ixgbe_setup_tc_cls_u32(struct ixgbe_adapter *adapter,
  7861. struct tc_cls_u32_offload *cls_u32)
  7862. {
  7863. switch (cls_u32->command) {
  7864. case TC_CLSU32_NEW_KNODE:
  7865. case TC_CLSU32_REPLACE_KNODE:
  7866. return ixgbe_configure_clsu32(adapter, cls_u32);
  7867. case TC_CLSU32_DELETE_KNODE:
  7868. return ixgbe_delete_clsu32(adapter, cls_u32);
  7869. case TC_CLSU32_NEW_HNODE:
  7870. case TC_CLSU32_REPLACE_HNODE:
  7871. return ixgbe_configure_clsu32_add_hnode(adapter, cls_u32);
  7872. case TC_CLSU32_DELETE_HNODE:
  7873. return ixgbe_configure_clsu32_del_hnode(adapter, cls_u32);
  7874. default:
  7875. return -EOPNOTSUPP;
  7876. }
  7877. }
  7878. static int ixgbe_setup_tc_block_cb(enum tc_setup_type type, void *type_data,
  7879. void *cb_priv)
  7880. {
  7881. struct ixgbe_adapter *adapter = cb_priv;
  7882. if (!tc_cls_can_offload_and_chain0(adapter->netdev, type_data))
  7883. return -EOPNOTSUPP;
  7884. switch (type) {
  7885. case TC_SETUP_CLSU32:
  7886. return ixgbe_setup_tc_cls_u32(adapter, type_data);
  7887. default:
  7888. return -EOPNOTSUPP;
  7889. }
  7890. }
  7891. static int ixgbe_setup_tc_block(struct net_device *dev,
  7892. struct tc_block_offload *f)
  7893. {
  7894. struct ixgbe_adapter *adapter = netdev_priv(dev);
  7895. if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
  7896. return -EOPNOTSUPP;
  7897. switch (f->command) {
  7898. case TC_BLOCK_BIND:
  7899. return tcf_block_cb_register(f->block, ixgbe_setup_tc_block_cb,
  7900. adapter, adapter);
  7901. case TC_BLOCK_UNBIND:
  7902. tcf_block_cb_unregister(f->block, ixgbe_setup_tc_block_cb,
  7903. adapter);
  7904. return 0;
  7905. default:
  7906. return -EOPNOTSUPP;
  7907. }
  7908. }
  7909. static int ixgbe_setup_tc_mqprio(struct net_device *dev,
  7910. struct tc_mqprio_qopt *mqprio)
  7911. {
  7912. mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS;
  7913. return ixgbe_setup_tc(dev, mqprio->num_tc);
  7914. }
  7915. static int __ixgbe_setup_tc(struct net_device *dev, enum tc_setup_type type,
  7916. void *type_data)
  7917. {
  7918. switch (type) {
  7919. case TC_SETUP_BLOCK:
  7920. return ixgbe_setup_tc_block(dev, type_data);
  7921. case TC_SETUP_QDISC_MQPRIO:
  7922. return ixgbe_setup_tc_mqprio(dev, type_data);
  7923. default:
  7924. return -EOPNOTSUPP;
  7925. }
  7926. }
  7927. #ifdef CONFIG_PCI_IOV
  7928. void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
  7929. {
  7930. struct net_device *netdev = adapter->netdev;
  7931. rtnl_lock();
  7932. ixgbe_setup_tc(netdev, adapter->hw_tcs);
  7933. rtnl_unlock();
  7934. }
  7935. #endif
  7936. void ixgbe_do_reset(struct net_device *netdev)
  7937. {
  7938. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7939. if (netif_running(netdev))
  7940. ixgbe_reinit_locked(adapter);
  7941. else
  7942. ixgbe_reset(adapter);
  7943. }
  7944. static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
  7945. netdev_features_t features)
  7946. {
  7947. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7948. /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
  7949. if (!(features & NETIF_F_RXCSUM))
  7950. features &= ~NETIF_F_LRO;
  7951. /* Turn off LRO if not RSC capable */
  7952. if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
  7953. features &= ~NETIF_F_LRO;
  7954. return features;
  7955. }
  7956. static void ixgbe_reset_l2fw_offload(struct ixgbe_adapter *adapter)
  7957. {
  7958. int rss = min_t(int, ixgbe_max_rss_indices(adapter),
  7959. num_online_cpus());
  7960. /* go back to full RSS if we're not running SR-IOV */
  7961. if (!adapter->ring_feature[RING_F_VMDQ].offset)
  7962. adapter->flags &= ~(IXGBE_FLAG_VMDQ_ENABLED |
  7963. IXGBE_FLAG_SRIOV_ENABLED);
  7964. adapter->ring_feature[RING_F_RSS].limit = rss;
  7965. adapter->ring_feature[RING_F_VMDQ].limit = 1;
  7966. ixgbe_setup_tc(adapter->netdev, adapter->hw_tcs);
  7967. }
  7968. static int ixgbe_set_features(struct net_device *netdev,
  7969. netdev_features_t features)
  7970. {
  7971. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  7972. netdev_features_t changed = netdev->features ^ features;
  7973. bool need_reset = false;
  7974. /* Make sure RSC matches LRO, reset if change */
  7975. if (!(features & NETIF_F_LRO)) {
  7976. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  7977. need_reset = true;
  7978. adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
  7979. } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
  7980. !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
  7981. if (adapter->rx_itr_setting == 1 ||
  7982. adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
  7983. adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
  7984. need_reset = true;
  7985. } else if ((changed ^ features) & NETIF_F_LRO) {
  7986. e_info(probe, "rx-usecs set too low, "
  7987. "disabling RSC\n");
  7988. }
  7989. }
  7990. /*
  7991. * Check if Flow Director n-tuple support or hw_tc support was
  7992. * enabled or disabled. If the state changed, we need to reset.
  7993. */
  7994. if ((features & NETIF_F_NTUPLE) || (features & NETIF_F_HW_TC)) {
  7995. /* turn off ATR, enable perfect filters and reset */
  7996. if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
  7997. need_reset = true;
  7998. adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
  7999. adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  8000. } else {
  8001. /* turn off perfect filters, enable ATR and reset */
  8002. if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  8003. need_reset = true;
  8004. adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  8005. /* We cannot enable ATR if SR-IOV is enabled */
  8006. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED ||
  8007. /* We cannot enable ATR if we have 2 or more tcs */
  8008. (adapter->hw_tcs > 1) ||
  8009. /* We cannot enable ATR if RSS is disabled */
  8010. (adapter->ring_feature[RING_F_RSS].limit <= 1) ||
  8011. /* A sample rate of 0 indicates ATR disabled */
  8012. (!adapter->atr_sample_rate))
  8013. ; /* do nothing not supported */
  8014. else /* otherwise supported and set the flag */
  8015. adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
  8016. }
  8017. if (changed & NETIF_F_RXALL)
  8018. need_reset = true;
  8019. netdev->features = features;
  8020. if ((adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE)) {
  8021. if (features & NETIF_F_RXCSUM) {
  8022. adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
  8023. } else {
  8024. u32 port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
  8025. ixgbe_clear_udp_tunnel_port(adapter, port_mask);
  8026. }
  8027. }
  8028. if ((adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE)) {
  8029. if (features & NETIF_F_RXCSUM) {
  8030. adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
  8031. } else {
  8032. u32 port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
  8033. ixgbe_clear_udp_tunnel_port(adapter, port_mask);
  8034. }
  8035. }
  8036. if ((changed & NETIF_F_HW_L2FW_DOFFLOAD) && adapter->num_rx_pools > 1)
  8037. ixgbe_reset_l2fw_offload(adapter);
  8038. else if (need_reset)
  8039. ixgbe_do_reset(netdev);
  8040. else if (changed & (NETIF_F_HW_VLAN_CTAG_RX |
  8041. NETIF_F_HW_VLAN_CTAG_FILTER))
  8042. ixgbe_set_rx_mode(netdev);
  8043. return 0;
  8044. }
  8045. /**
  8046. * ixgbe_add_udp_tunnel_port - Get notifications about adding UDP tunnel ports
  8047. * @dev: The port's netdev
  8048. * @ti: Tunnel endpoint information
  8049. **/
  8050. static void ixgbe_add_udp_tunnel_port(struct net_device *dev,
  8051. struct udp_tunnel_info *ti)
  8052. {
  8053. struct ixgbe_adapter *adapter = netdev_priv(dev);
  8054. struct ixgbe_hw *hw = &adapter->hw;
  8055. __be16 port = ti->port;
  8056. u32 port_shift = 0;
  8057. u32 reg;
  8058. if (ti->sa_family != AF_INET)
  8059. return;
  8060. switch (ti->type) {
  8061. case UDP_TUNNEL_TYPE_VXLAN:
  8062. if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
  8063. return;
  8064. if (adapter->vxlan_port == port)
  8065. return;
  8066. if (adapter->vxlan_port) {
  8067. netdev_info(dev,
  8068. "VXLAN port %d set, not adding port %d\n",
  8069. ntohs(adapter->vxlan_port),
  8070. ntohs(port));
  8071. return;
  8072. }
  8073. adapter->vxlan_port = port;
  8074. break;
  8075. case UDP_TUNNEL_TYPE_GENEVE:
  8076. if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
  8077. return;
  8078. if (adapter->geneve_port == port)
  8079. return;
  8080. if (adapter->geneve_port) {
  8081. netdev_info(dev,
  8082. "GENEVE port %d set, not adding port %d\n",
  8083. ntohs(adapter->geneve_port),
  8084. ntohs(port));
  8085. return;
  8086. }
  8087. port_shift = IXGBE_VXLANCTRL_GENEVE_UDPPORT_SHIFT;
  8088. adapter->geneve_port = port;
  8089. break;
  8090. default:
  8091. return;
  8092. }
  8093. reg = IXGBE_READ_REG(hw, IXGBE_VXLANCTRL) | ntohs(port) << port_shift;
  8094. IXGBE_WRITE_REG(hw, IXGBE_VXLANCTRL, reg);
  8095. }
  8096. /**
  8097. * ixgbe_del_udp_tunnel_port - Get notifications about removing UDP tunnel ports
  8098. * @dev: The port's netdev
  8099. * @ti: Tunnel endpoint information
  8100. **/
  8101. static void ixgbe_del_udp_tunnel_port(struct net_device *dev,
  8102. struct udp_tunnel_info *ti)
  8103. {
  8104. struct ixgbe_adapter *adapter = netdev_priv(dev);
  8105. u32 port_mask;
  8106. if (ti->type != UDP_TUNNEL_TYPE_VXLAN &&
  8107. ti->type != UDP_TUNNEL_TYPE_GENEVE)
  8108. return;
  8109. if (ti->sa_family != AF_INET)
  8110. return;
  8111. switch (ti->type) {
  8112. case UDP_TUNNEL_TYPE_VXLAN:
  8113. if (!(adapter->flags & IXGBE_FLAG_VXLAN_OFFLOAD_CAPABLE))
  8114. return;
  8115. if (adapter->vxlan_port != ti->port) {
  8116. netdev_info(dev, "VXLAN port %d not found\n",
  8117. ntohs(ti->port));
  8118. return;
  8119. }
  8120. port_mask = IXGBE_VXLANCTRL_VXLAN_UDPPORT_MASK;
  8121. break;
  8122. case UDP_TUNNEL_TYPE_GENEVE:
  8123. if (!(adapter->flags & IXGBE_FLAG_GENEVE_OFFLOAD_CAPABLE))
  8124. return;
  8125. if (adapter->geneve_port != ti->port) {
  8126. netdev_info(dev, "GENEVE port %d not found\n",
  8127. ntohs(ti->port));
  8128. return;
  8129. }
  8130. port_mask = IXGBE_VXLANCTRL_GENEVE_UDPPORT_MASK;
  8131. break;
  8132. default:
  8133. return;
  8134. }
  8135. ixgbe_clear_udp_tunnel_port(adapter, port_mask);
  8136. adapter->flags2 |= IXGBE_FLAG2_UDP_TUN_REREG_NEEDED;
  8137. }
  8138. static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  8139. struct net_device *dev,
  8140. const unsigned char *addr, u16 vid,
  8141. u16 flags)
  8142. {
  8143. /* guarantee we can provide a unique filter for the unicast address */
  8144. if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
  8145. struct ixgbe_adapter *adapter = netdev_priv(dev);
  8146. u16 pool = VMDQ_P(0);
  8147. if (netdev_uc_count(dev) >= ixgbe_available_rars(adapter, pool))
  8148. return -ENOMEM;
  8149. }
  8150. return ndo_dflt_fdb_add(ndm, tb, dev, addr, vid, flags);
  8151. }
  8152. /**
  8153. * ixgbe_configure_bridge_mode - set various bridge modes
  8154. * @adapter: the private structure
  8155. * @mode: requested bridge mode
  8156. *
  8157. * Configure some settings require for various bridge modes.
  8158. **/
  8159. static int ixgbe_configure_bridge_mode(struct ixgbe_adapter *adapter,
  8160. __u16 mode)
  8161. {
  8162. struct ixgbe_hw *hw = &adapter->hw;
  8163. unsigned int p, num_pools;
  8164. u32 vmdctl;
  8165. switch (mode) {
  8166. case BRIDGE_MODE_VEPA:
  8167. /* disable Tx loopback, rely on switch hairpin mode */
  8168. IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, 0);
  8169. /* must enable Rx switching replication to allow multicast
  8170. * packet reception on all VFs, and to enable source address
  8171. * pruning.
  8172. */
  8173. vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
  8174. vmdctl |= IXGBE_VT_CTL_REPLEN;
  8175. IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
  8176. /* enable Rx source address pruning. Note, this requires
  8177. * replication to be enabled or else it does nothing.
  8178. */
  8179. num_pools = adapter->num_vfs + adapter->num_rx_pools;
  8180. for (p = 0; p < num_pools; p++) {
  8181. if (hw->mac.ops.set_source_address_pruning)
  8182. hw->mac.ops.set_source_address_pruning(hw,
  8183. true,
  8184. p);
  8185. }
  8186. break;
  8187. case BRIDGE_MODE_VEB:
  8188. /* enable Tx loopback for internal VF/PF communication */
  8189. IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC,
  8190. IXGBE_PFDTXGSWC_VT_LBEN);
  8191. /* disable Rx switching replication unless we have SR-IOV
  8192. * virtual functions
  8193. */
  8194. vmdctl = IXGBE_READ_REG(hw, IXGBE_VMD_CTL);
  8195. if (!adapter->num_vfs)
  8196. vmdctl &= ~IXGBE_VT_CTL_REPLEN;
  8197. IXGBE_WRITE_REG(hw, IXGBE_VMD_CTL, vmdctl);
  8198. /* disable Rx source address pruning, since we don't expect to
  8199. * be receiving external loopback of our transmitted frames.
  8200. */
  8201. num_pools = adapter->num_vfs + adapter->num_rx_pools;
  8202. for (p = 0; p < num_pools; p++) {
  8203. if (hw->mac.ops.set_source_address_pruning)
  8204. hw->mac.ops.set_source_address_pruning(hw,
  8205. false,
  8206. p);
  8207. }
  8208. break;
  8209. default:
  8210. return -EINVAL;
  8211. }
  8212. adapter->bridge_mode = mode;
  8213. e_info(drv, "enabling bridge mode: %s\n",
  8214. mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
  8215. return 0;
  8216. }
  8217. static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
  8218. struct nlmsghdr *nlh, u16 flags)
  8219. {
  8220. struct ixgbe_adapter *adapter = netdev_priv(dev);
  8221. struct nlattr *attr, *br_spec;
  8222. int rem;
  8223. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  8224. return -EOPNOTSUPP;
  8225. br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
  8226. if (!br_spec)
  8227. return -EINVAL;
  8228. nla_for_each_nested(attr, br_spec, rem) {
  8229. int status;
  8230. __u16 mode;
  8231. if (nla_type(attr) != IFLA_BRIDGE_MODE)
  8232. continue;
  8233. if (nla_len(attr) < sizeof(mode))
  8234. return -EINVAL;
  8235. mode = nla_get_u16(attr);
  8236. status = ixgbe_configure_bridge_mode(adapter, mode);
  8237. if (status)
  8238. return status;
  8239. break;
  8240. }
  8241. return 0;
  8242. }
  8243. static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
  8244. struct net_device *dev,
  8245. u32 filter_mask, int nlflags)
  8246. {
  8247. struct ixgbe_adapter *adapter = netdev_priv(dev);
  8248. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  8249. return 0;
  8250. return ndo_dflt_bridge_getlink(skb, pid, seq, dev,
  8251. adapter->bridge_mode, 0, 0, nlflags,
  8252. filter_mask, NULL);
  8253. }
  8254. static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev)
  8255. {
  8256. struct ixgbe_adapter *adapter = netdev_priv(pdev);
  8257. struct ixgbe_fwd_adapter *accel;
  8258. int tcs = adapter->hw_tcs ? : 1;
  8259. int pool, err;
  8260. /* The hardware supported by ixgbe only filters on the destination MAC
  8261. * address. In order to avoid issues we only support offloading modes
  8262. * where the hardware can actually provide the functionality.
  8263. */
  8264. if (!macvlan_supports_dest_filter(vdev))
  8265. return ERR_PTR(-EMEDIUMTYPE);
  8266. pool = find_first_zero_bit(adapter->fwd_bitmask, adapter->num_rx_pools);
  8267. if (pool == adapter->num_rx_pools) {
  8268. u16 used_pools = adapter->num_vfs + adapter->num_rx_pools;
  8269. u16 reserved_pools;
  8270. if (((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
  8271. adapter->num_rx_pools >= (MAX_TX_QUEUES / tcs)) ||
  8272. adapter->num_rx_pools > IXGBE_MAX_MACVLANS)
  8273. return ERR_PTR(-EBUSY);
  8274. /* Hardware has a limited number of available pools. Each VF,
  8275. * and the PF require a pool. Check to ensure we don't
  8276. * attempt to use more then the available number of pools.
  8277. */
  8278. if (used_pools >= IXGBE_MAX_VF_FUNCTIONS)
  8279. return ERR_PTR(-EBUSY);
  8280. /* Enable VMDq flag so device will be set in VM mode */
  8281. adapter->flags |= IXGBE_FLAG_VMDQ_ENABLED |
  8282. IXGBE_FLAG_SRIOV_ENABLED;
  8283. /* Try to reserve as many queues per pool as possible,
  8284. * we start with the configurations that support 4 queues
  8285. * per pools, followed by 2, and then by just 1 per pool.
  8286. */
  8287. if (used_pools < 32 && adapter->num_rx_pools < 16)
  8288. reserved_pools = min_t(u16,
  8289. 32 - used_pools,
  8290. 16 - adapter->num_rx_pools);
  8291. else if (adapter->num_rx_pools < 32)
  8292. reserved_pools = min_t(u16,
  8293. 64 - used_pools,
  8294. 32 - adapter->num_rx_pools);
  8295. else
  8296. reserved_pools = 64 - used_pools;
  8297. if (!reserved_pools)
  8298. return ERR_PTR(-EBUSY);
  8299. adapter->ring_feature[RING_F_VMDQ].limit += reserved_pools;
  8300. /* Force reinit of ring allocation with VMDQ enabled */
  8301. err = ixgbe_setup_tc(pdev, adapter->hw_tcs);
  8302. if (err)
  8303. return ERR_PTR(err);
  8304. if (pool >= adapter->num_rx_pools)
  8305. return ERR_PTR(-ENOMEM);
  8306. }
  8307. accel = kzalloc(sizeof(*accel), GFP_KERNEL);
  8308. if (!accel)
  8309. return ERR_PTR(-ENOMEM);
  8310. set_bit(pool, adapter->fwd_bitmask);
  8311. accel->pool = pool;
  8312. accel->netdev = vdev;
  8313. if (!netif_running(pdev))
  8314. return accel;
  8315. err = ixgbe_fwd_ring_up(adapter, accel);
  8316. if (err)
  8317. return ERR_PTR(err);
  8318. return accel;
  8319. }
  8320. static void ixgbe_fwd_del(struct net_device *pdev, void *priv)
  8321. {
  8322. struct ixgbe_fwd_adapter *accel = priv;
  8323. struct ixgbe_adapter *adapter = netdev_priv(pdev);
  8324. unsigned int rxbase = accel->rx_base_queue;
  8325. unsigned int i;
  8326. /* delete unicast filter associated with offloaded interface */
  8327. ixgbe_del_mac_filter(adapter, accel->netdev->dev_addr,
  8328. VMDQ_P(accel->pool));
  8329. /* Allow remaining Rx packets to get flushed out of the
  8330. * Rx FIFO before we drop the netdev for the ring.
  8331. */
  8332. usleep_range(10000, 20000);
  8333. for (i = 0; i < adapter->num_rx_queues_per_pool; i++) {
  8334. struct ixgbe_ring *ring = adapter->rx_ring[rxbase + i];
  8335. struct ixgbe_q_vector *qv = ring->q_vector;
  8336. /* Make sure we aren't processing any packets and clear
  8337. * netdev to shut down the ring.
  8338. */
  8339. if (netif_running(adapter->netdev))
  8340. napi_synchronize(&qv->napi);
  8341. ring->netdev = NULL;
  8342. }
  8343. clear_bit(accel->pool, adapter->fwd_bitmask);
  8344. kfree(accel);
  8345. }
  8346. #define IXGBE_MAX_MAC_HDR_LEN 127
  8347. #define IXGBE_MAX_NETWORK_HDR_LEN 511
  8348. static netdev_features_t
  8349. ixgbe_features_check(struct sk_buff *skb, struct net_device *dev,
  8350. netdev_features_t features)
  8351. {
  8352. unsigned int network_hdr_len, mac_hdr_len;
  8353. /* Make certain the headers can be described by a context descriptor */
  8354. mac_hdr_len = skb_network_header(skb) - skb->data;
  8355. if (unlikely(mac_hdr_len > IXGBE_MAX_MAC_HDR_LEN))
  8356. return features & ~(NETIF_F_HW_CSUM |
  8357. NETIF_F_SCTP_CRC |
  8358. NETIF_F_HW_VLAN_CTAG_TX |
  8359. NETIF_F_TSO |
  8360. NETIF_F_TSO6);
  8361. network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb);
  8362. if (unlikely(network_hdr_len > IXGBE_MAX_NETWORK_HDR_LEN))
  8363. return features & ~(NETIF_F_HW_CSUM |
  8364. NETIF_F_SCTP_CRC |
  8365. NETIF_F_TSO |
  8366. NETIF_F_TSO6);
  8367. /* We can only support IPV4 TSO in tunnels if we can mangle the
  8368. * inner IP ID field, so strip TSO if MANGLEID is not supported.
  8369. * IPsec offoad sets skb->encapsulation but still can handle
  8370. * the TSO, so it's the exception.
  8371. */
  8372. if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID)) {
  8373. #ifdef CONFIG_XFRM_OFFLOAD
  8374. if (!skb->sp)
  8375. #endif
  8376. features &= ~NETIF_F_TSO;
  8377. }
  8378. return features;
  8379. }
  8380. static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog)
  8381. {
  8382. int i, frame_size = dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN;
  8383. struct ixgbe_adapter *adapter = netdev_priv(dev);
  8384. struct bpf_prog *old_prog;
  8385. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  8386. return -EINVAL;
  8387. if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
  8388. return -EINVAL;
  8389. /* verify ixgbe ring attributes are sufficient for XDP */
  8390. for (i = 0; i < adapter->num_rx_queues; i++) {
  8391. struct ixgbe_ring *ring = adapter->rx_ring[i];
  8392. if (ring_is_rsc_enabled(ring))
  8393. return -EINVAL;
  8394. if (frame_size > ixgbe_rx_bufsz(ring))
  8395. return -EINVAL;
  8396. }
  8397. if (nr_cpu_ids > MAX_XDP_QUEUES)
  8398. return -ENOMEM;
  8399. old_prog = xchg(&adapter->xdp_prog, prog);
  8400. /* If transitioning XDP modes reconfigure rings */
  8401. if (!!prog != !!old_prog) {
  8402. int err = ixgbe_setup_tc(dev, adapter->hw_tcs);
  8403. if (err) {
  8404. rcu_assign_pointer(adapter->xdp_prog, old_prog);
  8405. return -EINVAL;
  8406. }
  8407. } else {
  8408. for (i = 0; i < adapter->num_rx_queues; i++)
  8409. (void)xchg(&adapter->rx_ring[i]->xdp_prog,
  8410. adapter->xdp_prog);
  8411. }
  8412. if (old_prog)
  8413. bpf_prog_put(old_prog);
  8414. return 0;
  8415. }
  8416. static int ixgbe_xdp(struct net_device *dev, struct netdev_bpf *xdp)
  8417. {
  8418. struct ixgbe_adapter *adapter = netdev_priv(dev);
  8419. switch (xdp->command) {
  8420. case XDP_SETUP_PROG:
  8421. return ixgbe_xdp_setup(dev, xdp->prog);
  8422. case XDP_QUERY_PROG:
  8423. xdp->prog_attached = !!(adapter->xdp_prog);
  8424. xdp->prog_id = adapter->xdp_prog ?
  8425. adapter->xdp_prog->aux->id : 0;
  8426. return 0;
  8427. default:
  8428. return -EINVAL;
  8429. }
  8430. }
  8431. static void ixgbe_xdp_ring_update_tail(struct ixgbe_ring *ring)
  8432. {
  8433. /* Force memory writes to complete before letting h/w know there
  8434. * are new descriptors to fetch.
  8435. */
  8436. wmb();
  8437. writel(ring->next_to_use, ring->tail);
  8438. }
  8439. static int ixgbe_xdp_xmit(struct net_device *dev, int n,
  8440. struct xdp_frame **frames, u32 flags)
  8441. {
  8442. struct ixgbe_adapter *adapter = netdev_priv(dev);
  8443. struct ixgbe_ring *ring;
  8444. int drops = 0;
  8445. int i;
  8446. if (unlikely(test_bit(__IXGBE_DOWN, &adapter->state)))
  8447. return -ENETDOWN;
  8448. if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))
  8449. return -EINVAL;
  8450. /* During program transitions its possible adapter->xdp_prog is assigned
  8451. * but ring has not been configured yet. In this case simply abort xmit.
  8452. */
  8453. ring = adapter->xdp_prog ? adapter->xdp_ring[smp_processor_id()] : NULL;
  8454. if (unlikely(!ring))
  8455. return -ENXIO;
  8456. for (i = 0; i < n; i++) {
  8457. struct xdp_frame *xdpf = frames[i];
  8458. int err;
  8459. err = ixgbe_xmit_xdp_ring(adapter, xdpf);
  8460. if (err != IXGBE_XDP_TX) {
  8461. xdp_return_frame_rx_napi(xdpf);
  8462. drops++;
  8463. }
  8464. }
  8465. if (unlikely(flags & XDP_XMIT_FLUSH))
  8466. ixgbe_xdp_ring_update_tail(ring);
  8467. return n - drops;
  8468. }
  8469. static const struct net_device_ops ixgbe_netdev_ops = {
  8470. .ndo_open = ixgbe_open,
  8471. .ndo_stop = ixgbe_close,
  8472. .ndo_start_xmit = ixgbe_xmit_frame,
  8473. .ndo_select_queue = ixgbe_select_queue,
  8474. .ndo_set_rx_mode = ixgbe_set_rx_mode,
  8475. .ndo_validate_addr = eth_validate_addr,
  8476. .ndo_set_mac_address = ixgbe_set_mac,
  8477. .ndo_change_mtu = ixgbe_change_mtu,
  8478. .ndo_tx_timeout = ixgbe_tx_timeout,
  8479. .ndo_set_tx_maxrate = ixgbe_tx_maxrate,
  8480. .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
  8481. .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
  8482. .ndo_do_ioctl = ixgbe_ioctl,
  8483. .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
  8484. .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
  8485. .ndo_set_vf_rate = ixgbe_ndo_set_vf_bw,
  8486. .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
  8487. .ndo_set_vf_rss_query_en = ixgbe_ndo_set_vf_rss_query_en,
  8488. .ndo_set_vf_trust = ixgbe_ndo_set_vf_trust,
  8489. .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
  8490. .ndo_get_stats64 = ixgbe_get_stats64,
  8491. .ndo_setup_tc = __ixgbe_setup_tc,
  8492. #ifdef CONFIG_NET_POLL_CONTROLLER
  8493. .ndo_poll_controller = ixgbe_netpoll,
  8494. #endif
  8495. #ifdef IXGBE_FCOE
  8496. .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
  8497. .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
  8498. .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
  8499. .ndo_fcoe_enable = ixgbe_fcoe_enable,
  8500. .ndo_fcoe_disable = ixgbe_fcoe_disable,
  8501. .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
  8502. .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
  8503. #endif /* IXGBE_FCOE */
  8504. .ndo_set_features = ixgbe_set_features,
  8505. .ndo_fix_features = ixgbe_fix_features,
  8506. .ndo_fdb_add = ixgbe_ndo_fdb_add,
  8507. .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
  8508. .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
  8509. .ndo_dfwd_add_station = ixgbe_fwd_add,
  8510. .ndo_dfwd_del_station = ixgbe_fwd_del,
  8511. .ndo_udp_tunnel_add = ixgbe_add_udp_tunnel_port,
  8512. .ndo_udp_tunnel_del = ixgbe_del_udp_tunnel_port,
  8513. .ndo_features_check = ixgbe_features_check,
  8514. .ndo_bpf = ixgbe_xdp,
  8515. .ndo_xdp_xmit = ixgbe_xdp_xmit,
  8516. };
  8517. /**
  8518. * ixgbe_enumerate_functions - Get the number of ports this device has
  8519. * @adapter: adapter structure
  8520. *
  8521. * This function enumerates the phsyical functions co-located on a single slot,
  8522. * in order to determine how many ports a device has. This is most useful in
  8523. * determining the required GT/s of PCIe bandwidth necessary for optimal
  8524. * performance.
  8525. **/
  8526. static inline int ixgbe_enumerate_functions(struct ixgbe_adapter *adapter)
  8527. {
  8528. struct pci_dev *entry, *pdev = adapter->pdev;
  8529. int physfns = 0;
  8530. /* Some cards can not use the generic count PCIe functions method,
  8531. * because they are behind a parent switch, so we hardcode these with
  8532. * the correct number of functions.
  8533. */
  8534. if (ixgbe_pcie_from_parent(&adapter->hw))
  8535. physfns = 4;
  8536. list_for_each_entry(entry, &adapter->pdev->bus->devices, bus_list) {
  8537. /* don't count virtual functions */
  8538. if (entry->is_virtfn)
  8539. continue;
  8540. /* When the devices on the bus don't all match our device ID,
  8541. * we can't reliably determine the correct number of
  8542. * functions. This can occur if a function has been direct
  8543. * attached to a virtual machine using VT-d, for example. In
  8544. * this case, simply return -1 to indicate this.
  8545. */
  8546. if ((entry->vendor != pdev->vendor) ||
  8547. (entry->device != pdev->device))
  8548. return -1;
  8549. physfns++;
  8550. }
  8551. return physfns;
  8552. }
  8553. /**
  8554. * ixgbe_wol_supported - Check whether device supports WoL
  8555. * @adapter: the adapter private structure
  8556. * @device_id: the device ID
  8557. * @subdevice_id: the subsystem device ID
  8558. *
  8559. * This function is used by probe and ethtool to determine
  8560. * which devices have WoL support
  8561. *
  8562. **/
  8563. bool ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
  8564. u16 subdevice_id)
  8565. {
  8566. struct ixgbe_hw *hw = &adapter->hw;
  8567. u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
  8568. /* WOL not supported on 82598 */
  8569. if (hw->mac.type == ixgbe_mac_82598EB)
  8570. return false;
  8571. /* check eeprom to see if WOL is enabled for X540 and newer */
  8572. if (hw->mac.type >= ixgbe_mac_X540) {
  8573. if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
  8574. ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
  8575. (hw->bus.func == 0)))
  8576. return true;
  8577. }
  8578. /* WOL is determined based on device IDs for 82599 MACs */
  8579. switch (device_id) {
  8580. case IXGBE_DEV_ID_82599_SFP:
  8581. /* Only these subdevices could supports WOL */
  8582. switch (subdevice_id) {
  8583. case IXGBE_SUBDEV_ID_82599_560FLR:
  8584. case IXGBE_SUBDEV_ID_82599_LOM_SNAP6:
  8585. case IXGBE_SUBDEV_ID_82599_SFP_WOL0:
  8586. case IXGBE_SUBDEV_ID_82599_SFP_2OCP:
  8587. /* only support first port */
  8588. if (hw->bus.func != 0)
  8589. break;
  8590. /* fall through */
  8591. case IXGBE_SUBDEV_ID_82599_SP_560FLR:
  8592. case IXGBE_SUBDEV_ID_82599_SFP:
  8593. case IXGBE_SUBDEV_ID_82599_RNDC:
  8594. case IXGBE_SUBDEV_ID_82599_ECNA_DP:
  8595. case IXGBE_SUBDEV_ID_82599_SFP_1OCP:
  8596. case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM1:
  8597. case IXGBE_SUBDEV_ID_82599_SFP_LOM_OEM2:
  8598. return true;
  8599. }
  8600. break;
  8601. case IXGBE_DEV_ID_82599EN_SFP:
  8602. /* Only these subdevices support WOL */
  8603. switch (subdevice_id) {
  8604. case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
  8605. return true;
  8606. }
  8607. break;
  8608. case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
  8609. /* All except this subdevice support WOL */
  8610. if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
  8611. return true;
  8612. break;
  8613. case IXGBE_DEV_ID_82599_KX4:
  8614. return true;
  8615. default:
  8616. break;
  8617. }
  8618. return false;
  8619. }
  8620. /**
  8621. * ixgbe_set_fw_version - Set FW version
  8622. * @adapter: the adapter private structure
  8623. *
  8624. * This function is used by probe and ethtool to determine the FW version to
  8625. * format to display. The FW version is taken from the EEPROM/NVM.
  8626. */
  8627. static void ixgbe_set_fw_version(struct ixgbe_adapter *adapter)
  8628. {
  8629. struct ixgbe_hw *hw = &adapter->hw;
  8630. struct ixgbe_nvm_version nvm_ver;
  8631. ixgbe_get_oem_prod_version(hw, &nvm_ver);
  8632. if (nvm_ver.oem_valid) {
  8633. snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
  8634. "%x.%x.%x", nvm_ver.oem_major, nvm_ver.oem_minor,
  8635. nvm_ver.oem_release);
  8636. return;
  8637. }
  8638. ixgbe_get_etk_id(hw, &nvm_ver);
  8639. ixgbe_get_orom_version(hw, &nvm_ver);
  8640. if (nvm_ver.or_valid) {
  8641. snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
  8642. "0x%08x, %d.%d.%d", nvm_ver.etk_id, nvm_ver.or_major,
  8643. nvm_ver.or_build, nvm_ver.or_patch);
  8644. return;
  8645. }
  8646. /* Set ETrack ID format */
  8647. snprintf(adapter->eeprom_id, sizeof(adapter->eeprom_id),
  8648. "0x%08x", nvm_ver.etk_id);
  8649. }
  8650. /**
  8651. * ixgbe_probe - Device Initialization Routine
  8652. * @pdev: PCI device information struct
  8653. * @ent: entry in ixgbe_pci_tbl
  8654. *
  8655. * Returns 0 on success, negative on failure
  8656. *
  8657. * ixgbe_probe initializes an adapter identified by a pci_dev structure.
  8658. * The OS initialization, configuring of the adapter private structure,
  8659. * and a hardware reset occur.
  8660. **/
  8661. static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  8662. {
  8663. struct net_device *netdev;
  8664. struct ixgbe_adapter *adapter = NULL;
  8665. struct ixgbe_hw *hw;
  8666. const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
  8667. int i, err, pci_using_dac, expected_gts;
  8668. unsigned int indices = MAX_TX_QUEUES;
  8669. u8 part_str[IXGBE_PBANUM_LENGTH];
  8670. bool disable_dev = false;
  8671. #ifdef IXGBE_FCOE
  8672. u16 device_caps;
  8673. #endif
  8674. u32 eec;
  8675. /* Catch broken hardware that put the wrong VF device ID in
  8676. * the PCIe SR-IOV capability.
  8677. */
  8678. if (pdev->is_virtfn) {
  8679. WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
  8680. pci_name(pdev), pdev->vendor, pdev->device);
  8681. return -EINVAL;
  8682. }
  8683. err = pci_enable_device_mem(pdev);
  8684. if (err)
  8685. return err;
  8686. if (!dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64))) {
  8687. pci_using_dac = 1;
  8688. } else {
  8689. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  8690. if (err) {
  8691. dev_err(&pdev->dev,
  8692. "No usable DMA configuration, aborting\n");
  8693. goto err_dma;
  8694. }
  8695. pci_using_dac = 0;
  8696. }
  8697. err = pci_request_mem_regions(pdev, ixgbe_driver_name);
  8698. if (err) {
  8699. dev_err(&pdev->dev,
  8700. "pci_request_selected_regions failed 0x%x\n", err);
  8701. goto err_pci_reg;
  8702. }
  8703. pci_enable_pcie_error_reporting(pdev);
  8704. pci_set_master(pdev);
  8705. pci_save_state(pdev);
  8706. if (ii->mac == ixgbe_mac_82598EB) {
  8707. #ifdef CONFIG_IXGBE_DCB
  8708. /* 8 TC w/ 4 queues per TC */
  8709. indices = 4 * MAX_TRAFFIC_CLASS;
  8710. #else
  8711. indices = IXGBE_MAX_RSS_INDICES;
  8712. #endif
  8713. }
  8714. netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
  8715. if (!netdev) {
  8716. err = -ENOMEM;
  8717. goto err_alloc_etherdev;
  8718. }
  8719. SET_NETDEV_DEV(netdev, &pdev->dev);
  8720. adapter = netdev_priv(netdev);
  8721. adapter->netdev = netdev;
  8722. adapter->pdev = pdev;
  8723. hw = &adapter->hw;
  8724. hw->back = adapter;
  8725. adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
  8726. hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
  8727. pci_resource_len(pdev, 0));
  8728. adapter->io_addr = hw->hw_addr;
  8729. if (!hw->hw_addr) {
  8730. err = -EIO;
  8731. goto err_ioremap;
  8732. }
  8733. netdev->netdev_ops = &ixgbe_netdev_ops;
  8734. ixgbe_set_ethtool_ops(netdev);
  8735. netdev->watchdog_timeo = 5 * HZ;
  8736. strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
  8737. /* Setup hw api */
  8738. hw->mac.ops = *ii->mac_ops;
  8739. hw->mac.type = ii->mac;
  8740. hw->mvals = ii->mvals;
  8741. if (ii->link_ops)
  8742. hw->link.ops = *ii->link_ops;
  8743. /* EEPROM */
  8744. hw->eeprom.ops = *ii->eeprom_ops;
  8745. eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
  8746. if (ixgbe_removed(hw->hw_addr)) {
  8747. err = -EIO;
  8748. goto err_ioremap;
  8749. }
  8750. /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
  8751. if (!(eec & BIT(8)))
  8752. hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
  8753. /* PHY */
  8754. hw->phy.ops = *ii->phy_ops;
  8755. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  8756. /* ixgbe_identify_phy_generic will set prtad and mmds properly */
  8757. hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
  8758. hw->phy.mdio.mmds = 0;
  8759. hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  8760. hw->phy.mdio.dev = netdev;
  8761. hw->phy.mdio.mdio_read = ixgbe_mdio_read;
  8762. hw->phy.mdio.mdio_write = ixgbe_mdio_write;
  8763. /* setup the private structure */
  8764. err = ixgbe_sw_init(adapter, ii);
  8765. if (err)
  8766. goto err_sw_init;
  8767. /* Make sure the SWFW semaphore is in a valid state */
  8768. if (hw->mac.ops.init_swfw_sync)
  8769. hw->mac.ops.init_swfw_sync(hw);
  8770. /* Make it possible the adapter to be woken up via WOL */
  8771. switch (adapter->hw.mac.type) {
  8772. case ixgbe_mac_82599EB:
  8773. case ixgbe_mac_X540:
  8774. case ixgbe_mac_X550:
  8775. case ixgbe_mac_X550EM_x:
  8776. case ixgbe_mac_x550em_a:
  8777. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  8778. break;
  8779. default:
  8780. break;
  8781. }
  8782. /*
  8783. * If there is a fan on this device and it has failed log the
  8784. * failure.
  8785. */
  8786. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  8787. u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  8788. if (esdp & IXGBE_ESDP_SDP1)
  8789. e_crit(probe, "Fan has stopped, replace the adapter\n");
  8790. }
  8791. if (allow_unsupported_sfp)
  8792. hw->allow_unsupported_sfp = allow_unsupported_sfp;
  8793. /* reset_hw fills in the perm_addr as well */
  8794. hw->phy.reset_if_overtemp = true;
  8795. err = hw->mac.ops.reset_hw(hw);
  8796. hw->phy.reset_if_overtemp = false;
  8797. ixgbe_set_eee_capable(adapter);
  8798. if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
  8799. err = 0;
  8800. } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
  8801. e_dev_err("failed to load because an unsupported SFP+ or QSFP module type was detected.\n");
  8802. e_dev_err("Reload the driver after installing a supported module.\n");
  8803. goto err_sw_init;
  8804. } else if (err) {
  8805. e_dev_err("HW Init failed: %d\n", err);
  8806. goto err_sw_init;
  8807. }
  8808. #ifdef CONFIG_PCI_IOV
  8809. /* SR-IOV not supported on the 82598 */
  8810. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  8811. goto skip_sriov;
  8812. /* Mailbox */
  8813. ixgbe_init_mbx_params_pf(hw);
  8814. hw->mbx.ops = ii->mbx_ops;
  8815. pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
  8816. ixgbe_enable_sriov(adapter, max_vfs);
  8817. skip_sriov:
  8818. #endif
  8819. netdev->features = NETIF_F_SG |
  8820. NETIF_F_TSO |
  8821. NETIF_F_TSO6 |
  8822. NETIF_F_RXHASH |
  8823. NETIF_F_RXCSUM |
  8824. NETIF_F_HW_CSUM;
  8825. #define IXGBE_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \
  8826. NETIF_F_GSO_GRE_CSUM | \
  8827. NETIF_F_GSO_IPXIP4 | \
  8828. NETIF_F_GSO_IPXIP6 | \
  8829. NETIF_F_GSO_UDP_TUNNEL | \
  8830. NETIF_F_GSO_UDP_TUNNEL_CSUM)
  8831. netdev->gso_partial_features = IXGBE_GSO_PARTIAL_FEATURES;
  8832. netdev->features |= NETIF_F_GSO_PARTIAL |
  8833. IXGBE_GSO_PARTIAL_FEATURES;
  8834. if (hw->mac.type >= ixgbe_mac_82599EB)
  8835. netdev->features |= NETIF_F_SCTP_CRC;
  8836. #ifdef CONFIG_XFRM_OFFLOAD
  8837. #define IXGBE_ESP_FEATURES (NETIF_F_HW_ESP | \
  8838. NETIF_F_HW_ESP_TX_CSUM | \
  8839. NETIF_F_GSO_ESP)
  8840. if (adapter->ipsec)
  8841. netdev->features |= IXGBE_ESP_FEATURES;
  8842. #endif
  8843. /* copy netdev features into list of user selectable features */
  8844. netdev->hw_features |= netdev->features |
  8845. NETIF_F_HW_VLAN_CTAG_FILTER |
  8846. NETIF_F_HW_VLAN_CTAG_RX |
  8847. NETIF_F_HW_VLAN_CTAG_TX |
  8848. NETIF_F_RXALL |
  8849. NETIF_F_HW_L2FW_DOFFLOAD;
  8850. if (hw->mac.type >= ixgbe_mac_82599EB)
  8851. netdev->hw_features |= NETIF_F_NTUPLE |
  8852. NETIF_F_HW_TC;
  8853. if (pci_using_dac)
  8854. netdev->features |= NETIF_F_HIGHDMA;
  8855. netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID;
  8856. netdev->hw_enc_features |= netdev->vlan_features;
  8857. netdev->mpls_features |= NETIF_F_SG |
  8858. NETIF_F_TSO |
  8859. NETIF_F_TSO6 |
  8860. NETIF_F_HW_CSUM;
  8861. netdev->mpls_features |= IXGBE_GSO_PARTIAL_FEATURES;
  8862. /* set this bit last since it cannot be part of vlan_features */
  8863. netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER |
  8864. NETIF_F_HW_VLAN_CTAG_RX |
  8865. NETIF_F_HW_VLAN_CTAG_TX;
  8866. netdev->priv_flags |= IFF_UNICAST_FLT;
  8867. netdev->priv_flags |= IFF_SUPP_NOFCS;
  8868. /* MTU range: 68 - 9710 */
  8869. netdev->min_mtu = ETH_MIN_MTU;
  8870. netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE - (ETH_HLEN + ETH_FCS_LEN);
  8871. #ifdef CONFIG_IXGBE_DCB
  8872. if (adapter->flags & IXGBE_FLAG_DCB_CAPABLE)
  8873. netdev->dcbnl_ops = &ixgbe_dcbnl_ops;
  8874. #endif
  8875. #ifdef IXGBE_FCOE
  8876. if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
  8877. unsigned int fcoe_l;
  8878. if (hw->mac.ops.get_device_caps) {
  8879. hw->mac.ops.get_device_caps(hw, &device_caps);
  8880. if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
  8881. adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
  8882. }
  8883. fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
  8884. adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
  8885. netdev->features |= NETIF_F_FSO |
  8886. NETIF_F_FCOE_CRC;
  8887. netdev->vlan_features |= NETIF_F_FSO |
  8888. NETIF_F_FCOE_CRC |
  8889. NETIF_F_FCOE_MTU;
  8890. }
  8891. #endif /* IXGBE_FCOE */
  8892. if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
  8893. netdev->hw_features |= NETIF_F_LRO;
  8894. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  8895. netdev->features |= NETIF_F_LRO;
  8896. /* make sure the EEPROM is good */
  8897. if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
  8898. e_dev_err("The EEPROM Checksum Is Not Valid\n");
  8899. err = -EIO;
  8900. goto err_sw_init;
  8901. }
  8902. eth_platform_get_mac_address(&adapter->pdev->dev,
  8903. adapter->hw.mac.perm_addr);
  8904. memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
  8905. if (!is_valid_ether_addr(netdev->dev_addr)) {
  8906. e_dev_err("invalid MAC address\n");
  8907. err = -EIO;
  8908. goto err_sw_init;
  8909. }
  8910. /* Set hw->mac.addr to permanent MAC address */
  8911. ether_addr_copy(hw->mac.addr, hw->mac.perm_addr);
  8912. ixgbe_mac_set_default_filter(adapter);
  8913. timer_setup(&adapter->service_timer, ixgbe_service_timer, 0);
  8914. if (ixgbe_removed(hw->hw_addr)) {
  8915. err = -EIO;
  8916. goto err_sw_init;
  8917. }
  8918. INIT_WORK(&adapter->service_task, ixgbe_service_task);
  8919. set_bit(__IXGBE_SERVICE_INITED, &adapter->state);
  8920. clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
  8921. err = ixgbe_init_interrupt_scheme(adapter);
  8922. if (err)
  8923. goto err_sw_init;
  8924. for (i = 0; i < adapter->num_rx_queues; i++)
  8925. u64_stats_init(&adapter->rx_ring[i]->syncp);
  8926. for (i = 0; i < adapter->num_tx_queues; i++)
  8927. u64_stats_init(&adapter->tx_ring[i]->syncp);
  8928. for (i = 0; i < adapter->num_xdp_queues; i++)
  8929. u64_stats_init(&adapter->xdp_ring[i]->syncp);
  8930. /* WOL not supported for all devices */
  8931. adapter->wol = 0;
  8932. hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
  8933. hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
  8934. pdev->subsystem_device);
  8935. if (hw->wol_enabled)
  8936. adapter->wol = IXGBE_WUFC_MAG;
  8937. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  8938. /* save off EEPROM version number */
  8939. ixgbe_set_fw_version(adapter);
  8940. /* pick up the PCI bus settings for reporting later */
  8941. if (ixgbe_pcie_from_parent(hw))
  8942. ixgbe_get_parent_bus_info(adapter);
  8943. else
  8944. hw->mac.ops.get_bus_info(hw);
  8945. /* calculate the expected PCIe bandwidth required for optimal
  8946. * performance. Note that some older parts will never have enough
  8947. * bandwidth due to being older generation PCIe parts. We clamp these
  8948. * parts to ensure no warning is displayed if it can't be fixed.
  8949. */
  8950. switch (hw->mac.type) {
  8951. case ixgbe_mac_82598EB:
  8952. expected_gts = min(ixgbe_enumerate_functions(adapter) * 10, 16);
  8953. break;
  8954. default:
  8955. expected_gts = ixgbe_enumerate_functions(adapter) * 10;
  8956. break;
  8957. }
  8958. /* don't check link if we failed to enumerate functions */
  8959. if (expected_gts > 0)
  8960. ixgbe_check_minimum_link(adapter, expected_gts);
  8961. err = ixgbe_read_pba_string_generic(hw, part_str, sizeof(part_str));
  8962. if (err)
  8963. strlcpy(part_str, "Unknown", sizeof(part_str));
  8964. if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
  8965. e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
  8966. hw->mac.type, hw->phy.type, hw->phy.sfp_type,
  8967. part_str);
  8968. else
  8969. e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
  8970. hw->mac.type, hw->phy.type, part_str);
  8971. e_dev_info("%pM\n", netdev->dev_addr);
  8972. /* reset the hardware with the new settings */
  8973. err = hw->mac.ops.start_hw(hw);
  8974. if (err == IXGBE_ERR_EEPROM_VERSION) {
  8975. /* We are running on a pre-production device, log a warning */
  8976. e_dev_warn("This device is a pre-production adapter/LOM. "
  8977. "Please be aware there may be issues associated "
  8978. "with your hardware. If you are experiencing "
  8979. "problems please contact your Intel or hardware "
  8980. "representative who provided you with this "
  8981. "hardware.\n");
  8982. }
  8983. strcpy(netdev->name, "eth%d");
  8984. pci_set_drvdata(pdev, adapter);
  8985. err = register_netdev(netdev);
  8986. if (err)
  8987. goto err_register;
  8988. /* power down the optics for 82599 SFP+ fiber */
  8989. if (hw->mac.ops.disable_tx_laser)
  8990. hw->mac.ops.disable_tx_laser(hw);
  8991. /* carrier off reporting is important to ethtool even BEFORE open */
  8992. netif_carrier_off(netdev);
  8993. #ifdef CONFIG_IXGBE_DCA
  8994. if (dca_add_requester(&pdev->dev) == 0) {
  8995. adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
  8996. ixgbe_setup_dca(adapter);
  8997. }
  8998. #endif
  8999. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  9000. e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
  9001. for (i = 0; i < adapter->num_vfs; i++)
  9002. ixgbe_vf_configuration(pdev, (i | 0x10000000));
  9003. }
  9004. /* firmware requires driver version to be 0xFFFFFFFF
  9005. * since os does not support feature
  9006. */
  9007. if (hw->mac.ops.set_fw_drv_ver)
  9008. hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF, 0xFF,
  9009. sizeof(ixgbe_driver_version) - 1,
  9010. ixgbe_driver_version);
  9011. /* add san mac addr to netdev */
  9012. ixgbe_add_sanmac_netdev(netdev);
  9013. e_dev_info("%s\n", ixgbe_default_device_descr);
  9014. #ifdef CONFIG_IXGBE_HWMON
  9015. if (ixgbe_sysfs_init(adapter))
  9016. e_err(probe, "failed to allocate sysfs resources\n");
  9017. #endif /* CONFIG_IXGBE_HWMON */
  9018. ixgbe_dbg_adapter_init(adapter);
  9019. /* setup link for SFP devices with MNG FW, else wait for IXGBE_UP */
  9020. if (ixgbe_mng_enabled(hw) && ixgbe_is_sfp(hw) && hw->mac.ops.setup_link)
  9021. hw->mac.ops.setup_link(hw,
  9022. IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
  9023. true);
  9024. return 0;
  9025. err_register:
  9026. ixgbe_release_hw_control(adapter);
  9027. ixgbe_clear_interrupt_scheme(adapter);
  9028. err_sw_init:
  9029. ixgbe_disable_sriov(adapter);
  9030. adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
  9031. iounmap(adapter->io_addr);
  9032. kfree(adapter->jump_tables[0]);
  9033. kfree(adapter->mac_table);
  9034. kfree(adapter->rss_key);
  9035. err_ioremap:
  9036. disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
  9037. free_netdev(netdev);
  9038. err_alloc_etherdev:
  9039. pci_release_mem_regions(pdev);
  9040. err_pci_reg:
  9041. err_dma:
  9042. if (!adapter || disable_dev)
  9043. pci_disable_device(pdev);
  9044. return err;
  9045. }
  9046. /**
  9047. * ixgbe_remove - Device Removal Routine
  9048. * @pdev: PCI device information struct
  9049. *
  9050. * ixgbe_remove is called by the PCI subsystem to alert the driver
  9051. * that it should release a PCI device. The could be caused by a
  9052. * Hot-Plug event, or because the driver is going to be removed from
  9053. * memory.
  9054. **/
  9055. static void ixgbe_remove(struct pci_dev *pdev)
  9056. {
  9057. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  9058. struct net_device *netdev;
  9059. bool disable_dev;
  9060. int i;
  9061. /* if !adapter then we already cleaned up in probe */
  9062. if (!adapter)
  9063. return;
  9064. netdev = adapter->netdev;
  9065. ixgbe_dbg_adapter_exit(adapter);
  9066. set_bit(__IXGBE_REMOVING, &adapter->state);
  9067. cancel_work_sync(&adapter->service_task);
  9068. #ifdef CONFIG_IXGBE_DCA
  9069. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  9070. adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
  9071. dca_remove_requester(&pdev->dev);
  9072. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL,
  9073. IXGBE_DCA_CTRL_DCA_DISABLE);
  9074. }
  9075. #endif
  9076. #ifdef CONFIG_IXGBE_HWMON
  9077. ixgbe_sysfs_exit(adapter);
  9078. #endif /* CONFIG_IXGBE_HWMON */
  9079. /* remove the added san mac */
  9080. ixgbe_del_sanmac_netdev(netdev);
  9081. #ifdef CONFIG_PCI_IOV
  9082. ixgbe_disable_sriov(adapter);
  9083. #endif
  9084. if (netdev->reg_state == NETREG_REGISTERED)
  9085. unregister_netdev(netdev);
  9086. ixgbe_stop_ipsec_offload(adapter);
  9087. ixgbe_clear_interrupt_scheme(adapter);
  9088. ixgbe_release_hw_control(adapter);
  9089. #ifdef CONFIG_DCB
  9090. kfree(adapter->ixgbe_ieee_pfc);
  9091. kfree(adapter->ixgbe_ieee_ets);
  9092. #endif
  9093. iounmap(adapter->io_addr);
  9094. pci_release_mem_regions(pdev);
  9095. e_dev_info("complete\n");
  9096. for (i = 0; i < IXGBE_MAX_LINK_HANDLE; i++) {
  9097. if (adapter->jump_tables[i]) {
  9098. kfree(adapter->jump_tables[i]->input);
  9099. kfree(adapter->jump_tables[i]->mask);
  9100. }
  9101. kfree(adapter->jump_tables[i]);
  9102. }
  9103. kfree(adapter->mac_table);
  9104. kfree(adapter->rss_key);
  9105. disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
  9106. free_netdev(netdev);
  9107. pci_disable_pcie_error_reporting(pdev);
  9108. if (disable_dev)
  9109. pci_disable_device(pdev);
  9110. }
  9111. /**
  9112. * ixgbe_io_error_detected - called when PCI error is detected
  9113. * @pdev: Pointer to PCI device
  9114. * @state: The current pci connection state
  9115. *
  9116. * This function is called after a PCI bus error affecting
  9117. * this device has been detected.
  9118. */
  9119. static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
  9120. pci_channel_state_t state)
  9121. {
  9122. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  9123. struct net_device *netdev = adapter->netdev;
  9124. #ifdef CONFIG_PCI_IOV
  9125. struct ixgbe_hw *hw = &adapter->hw;
  9126. struct pci_dev *bdev, *vfdev;
  9127. u32 dw0, dw1, dw2, dw3;
  9128. int vf, pos;
  9129. u16 req_id, pf_func;
  9130. if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
  9131. adapter->num_vfs == 0)
  9132. goto skip_bad_vf_detection;
  9133. bdev = pdev->bus->self;
  9134. while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
  9135. bdev = bdev->bus->self;
  9136. if (!bdev)
  9137. goto skip_bad_vf_detection;
  9138. pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
  9139. if (!pos)
  9140. goto skip_bad_vf_detection;
  9141. dw0 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG);
  9142. dw1 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 4);
  9143. dw2 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 8);
  9144. dw3 = ixgbe_read_pci_cfg_dword(hw, pos + PCI_ERR_HEADER_LOG + 12);
  9145. if (ixgbe_removed(hw->hw_addr))
  9146. goto skip_bad_vf_detection;
  9147. req_id = dw1 >> 16;
  9148. /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
  9149. if (!(req_id & 0x0080))
  9150. goto skip_bad_vf_detection;
  9151. pf_func = req_id & 0x01;
  9152. if ((pf_func & 1) == (pdev->devfn & 1)) {
  9153. unsigned int device_id;
  9154. vf = (req_id & 0x7F) >> 1;
  9155. e_dev_err("VF %d has caused a PCIe error\n", vf);
  9156. e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
  9157. "%8.8x\tdw3: %8.8x\n",
  9158. dw0, dw1, dw2, dw3);
  9159. switch (adapter->hw.mac.type) {
  9160. case ixgbe_mac_82599EB:
  9161. device_id = IXGBE_82599_VF_DEVICE_ID;
  9162. break;
  9163. case ixgbe_mac_X540:
  9164. device_id = IXGBE_X540_VF_DEVICE_ID;
  9165. break;
  9166. case ixgbe_mac_X550:
  9167. device_id = IXGBE_DEV_ID_X550_VF;
  9168. break;
  9169. case ixgbe_mac_X550EM_x:
  9170. device_id = IXGBE_DEV_ID_X550EM_X_VF;
  9171. break;
  9172. case ixgbe_mac_x550em_a:
  9173. device_id = IXGBE_DEV_ID_X550EM_A_VF;
  9174. break;
  9175. default:
  9176. device_id = 0;
  9177. break;
  9178. }
  9179. /* Find the pci device of the offending VF */
  9180. vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
  9181. while (vfdev) {
  9182. if (vfdev->devfn == (req_id & 0xFF))
  9183. break;
  9184. vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  9185. device_id, vfdev);
  9186. }
  9187. /*
  9188. * There's a slim chance the VF could have been hot plugged,
  9189. * so if it is no longer present we don't need to issue the
  9190. * VFLR. Just clean up the AER in that case.
  9191. */
  9192. if (vfdev) {
  9193. pcie_flr(vfdev);
  9194. /* Free device reference count */
  9195. pci_dev_put(vfdev);
  9196. }
  9197. pci_cleanup_aer_uncorrect_error_status(pdev);
  9198. }
  9199. /*
  9200. * Even though the error may have occurred on the other port
  9201. * we still need to increment the vf error reference count for
  9202. * both ports because the I/O resume function will be called
  9203. * for both of them.
  9204. */
  9205. adapter->vferr_refcount++;
  9206. return PCI_ERS_RESULT_RECOVERED;
  9207. skip_bad_vf_detection:
  9208. #endif /* CONFIG_PCI_IOV */
  9209. if (!test_bit(__IXGBE_SERVICE_INITED, &adapter->state))
  9210. return PCI_ERS_RESULT_DISCONNECT;
  9211. if (!netif_device_present(netdev))
  9212. return PCI_ERS_RESULT_DISCONNECT;
  9213. rtnl_lock();
  9214. netif_device_detach(netdev);
  9215. if (netif_running(netdev))
  9216. ixgbe_close_suspend(adapter);
  9217. if (state == pci_channel_io_perm_failure) {
  9218. rtnl_unlock();
  9219. return PCI_ERS_RESULT_DISCONNECT;
  9220. }
  9221. if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state))
  9222. pci_disable_device(pdev);
  9223. rtnl_unlock();
  9224. /* Request a slot reset. */
  9225. return PCI_ERS_RESULT_NEED_RESET;
  9226. }
  9227. /**
  9228. * ixgbe_io_slot_reset - called after the pci bus has been reset.
  9229. * @pdev: Pointer to PCI device
  9230. *
  9231. * Restart the card from scratch, as if from a cold-boot.
  9232. */
  9233. static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
  9234. {
  9235. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  9236. pci_ers_result_t result;
  9237. int err;
  9238. if (pci_enable_device_mem(pdev)) {
  9239. e_err(probe, "Cannot re-enable PCI device after reset.\n");
  9240. result = PCI_ERS_RESULT_DISCONNECT;
  9241. } else {
  9242. smp_mb__before_atomic();
  9243. clear_bit(__IXGBE_DISABLED, &adapter->state);
  9244. adapter->hw.hw_addr = adapter->io_addr;
  9245. pci_set_master(pdev);
  9246. pci_restore_state(pdev);
  9247. pci_save_state(pdev);
  9248. pci_wake_from_d3(pdev, false);
  9249. ixgbe_reset(adapter);
  9250. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  9251. result = PCI_ERS_RESULT_RECOVERED;
  9252. }
  9253. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  9254. if (err) {
  9255. e_dev_err("pci_cleanup_aer_uncorrect_error_status "
  9256. "failed 0x%0x\n", err);
  9257. /* non-fatal, continue */
  9258. }
  9259. return result;
  9260. }
  9261. /**
  9262. * ixgbe_io_resume - called when traffic can start flowing again.
  9263. * @pdev: Pointer to PCI device
  9264. *
  9265. * This callback is called when the error recovery driver tells us that
  9266. * its OK to resume normal operation.
  9267. */
  9268. static void ixgbe_io_resume(struct pci_dev *pdev)
  9269. {
  9270. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  9271. struct net_device *netdev = adapter->netdev;
  9272. #ifdef CONFIG_PCI_IOV
  9273. if (adapter->vferr_refcount) {
  9274. e_info(drv, "Resuming after VF err\n");
  9275. adapter->vferr_refcount--;
  9276. return;
  9277. }
  9278. #endif
  9279. rtnl_lock();
  9280. if (netif_running(netdev))
  9281. ixgbe_open(netdev);
  9282. netif_device_attach(netdev);
  9283. rtnl_unlock();
  9284. }
  9285. static const struct pci_error_handlers ixgbe_err_handler = {
  9286. .error_detected = ixgbe_io_error_detected,
  9287. .slot_reset = ixgbe_io_slot_reset,
  9288. .resume = ixgbe_io_resume,
  9289. };
  9290. static struct pci_driver ixgbe_driver = {
  9291. .name = ixgbe_driver_name,
  9292. .id_table = ixgbe_pci_tbl,
  9293. .probe = ixgbe_probe,
  9294. .remove = ixgbe_remove,
  9295. #ifdef CONFIG_PM
  9296. .suspend = ixgbe_suspend,
  9297. .resume = ixgbe_resume,
  9298. #endif
  9299. .shutdown = ixgbe_shutdown,
  9300. .sriov_configure = ixgbe_pci_sriov_configure,
  9301. .err_handler = &ixgbe_err_handler
  9302. };
  9303. /**
  9304. * ixgbe_init_module - Driver Registration Routine
  9305. *
  9306. * ixgbe_init_module is the first routine called when the driver is
  9307. * loaded. All it does is register with the PCI subsystem.
  9308. **/
  9309. static int __init ixgbe_init_module(void)
  9310. {
  9311. int ret;
  9312. pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
  9313. pr_info("%s\n", ixgbe_copyright);
  9314. ixgbe_wq = create_singlethread_workqueue(ixgbe_driver_name);
  9315. if (!ixgbe_wq) {
  9316. pr_err("%s: Failed to create workqueue\n", ixgbe_driver_name);
  9317. return -ENOMEM;
  9318. }
  9319. ixgbe_dbg_init();
  9320. ret = pci_register_driver(&ixgbe_driver);
  9321. if (ret) {
  9322. destroy_workqueue(ixgbe_wq);
  9323. ixgbe_dbg_exit();
  9324. return ret;
  9325. }
  9326. #ifdef CONFIG_IXGBE_DCA
  9327. dca_register_notify(&dca_notifier);
  9328. #endif
  9329. return 0;
  9330. }
  9331. module_init(ixgbe_init_module);
  9332. /**
  9333. * ixgbe_exit_module - Driver Exit Cleanup Routine
  9334. *
  9335. * ixgbe_exit_module is called just before the driver is removed
  9336. * from memory.
  9337. **/
  9338. static void __exit ixgbe_exit_module(void)
  9339. {
  9340. #ifdef CONFIG_IXGBE_DCA
  9341. dca_unregister_notify(&dca_notifier);
  9342. #endif
  9343. pci_unregister_driver(&ixgbe_driver);
  9344. ixgbe_dbg_exit();
  9345. if (ixgbe_wq) {
  9346. destroy_workqueue(ixgbe_wq);
  9347. ixgbe_wq = NULL;
  9348. }
  9349. }
  9350. #ifdef CONFIG_IXGBE_DCA
  9351. static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
  9352. void *p)
  9353. {
  9354. int ret_val;
  9355. ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
  9356. __ixgbe_notify_dca);
  9357. return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
  9358. }
  9359. #endif /* CONFIG_IXGBE_DCA */
  9360. module_exit(ixgbe_exit_module);
  9361. /* ixgbe_main.c */