ixgbe_main.c 270 KB

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