ixgbe_main.c 302 KB

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