ixgbe_main.c 219 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2013 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. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. #include <linux/types.h>
  21. #include <linux/module.h>
  22. #include <linux/pci.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/vmalloc.h>
  25. #include <linux/string.h>
  26. #include <linux/in.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/ip.h>
  29. #include <linux/tcp.h>
  30. #include <linux/sctp.h>
  31. #include <linux/pkt_sched.h>
  32. #include <linux/ipv6.h>
  33. #include <linux/slab.h>
  34. #include <net/checksum.h>
  35. #include <net/ip6_checksum.h>
  36. #include <linux/ethtool.h>
  37. #include <linux/if.h>
  38. #include <linux/if_vlan.h>
  39. #include <linux/if_bridge.h>
  40. #include <linux/prefetch.h>
  41. #include <scsi/fc/fc_fcoe.h>
  42. #include "ixgbe.h"
  43. #include "ixgbe_common.h"
  44. #include "ixgbe_dcb_82599.h"
  45. #include "ixgbe_sriov.h"
  46. char ixgbe_driver_name[] = "ixgbe";
  47. static const char ixgbe_driver_string[] =
  48. "Intel(R) 10 Gigabit PCI Express Network Driver";
  49. #ifdef IXGBE_FCOE
  50. char ixgbe_default_device_descr[] =
  51. "Intel(R) 10 Gigabit Network Connection";
  52. #else
  53. static char ixgbe_default_device_descr[] =
  54. "Intel(R) 10 Gigabit Network Connection";
  55. #endif
  56. #define DRV_VERSION "3.13.10-k"
  57. const char ixgbe_driver_version[] = DRV_VERSION;
  58. static const char ixgbe_copyright[] =
  59. "Copyright (c) 1999-2013 Intel Corporation.";
  60. static const struct ixgbe_info *ixgbe_info_tbl[] = {
  61. [board_82598] = &ixgbe_82598_info,
  62. [board_82599] = &ixgbe_82599_info,
  63. [board_X540] = &ixgbe_X540_info,
  64. };
  65. /* ixgbe_pci_tbl - PCI Device ID Table
  66. *
  67. * Wildcard entries (PCI_ANY_ID) should come last
  68. * Last entry must be all 0s
  69. *
  70. * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
  71. * Class, Class Mask, private data (not used) }
  72. */
  73. static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
  74. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
  75. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
  76. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
  77. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
  78. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
  79. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
  80. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
  81. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
  82. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
  83. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
  84. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
  85. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
  86. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
  87. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
  88. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
  89. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
  90. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
  91. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
  92. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
  93. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
  94. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
  95. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
  96. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
  97. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
  98. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
  99. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
  100. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
  101. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
  102. {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T1), board_X540 },
  103. /* required last entry */
  104. {0, }
  105. };
  106. MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
  107. #ifdef CONFIG_IXGBE_DCA
  108. static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
  109. void *p);
  110. static struct notifier_block dca_notifier = {
  111. .notifier_call = ixgbe_notify_dca,
  112. .next = NULL,
  113. .priority = 0
  114. };
  115. #endif
  116. #ifdef CONFIG_PCI_IOV
  117. static unsigned int max_vfs;
  118. module_param(max_vfs, uint, 0);
  119. MODULE_PARM_DESC(max_vfs,
  120. "Maximum number of virtual functions to allocate per physical function - default is zero and maximum value is 63");
  121. #endif /* CONFIG_PCI_IOV */
  122. static unsigned int allow_unsupported_sfp;
  123. module_param(allow_unsupported_sfp, uint, 0);
  124. MODULE_PARM_DESC(allow_unsupported_sfp,
  125. "Allow unsupported and untested SFP+ modules on 82599-based adapters");
  126. #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
  127. static int debug = -1;
  128. module_param(debug, int, 0);
  129. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  130. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  131. MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
  132. MODULE_LICENSE("GPL");
  133. MODULE_VERSION(DRV_VERSION);
  134. static int ixgbe_read_pci_cfg_word_parent(struct ixgbe_adapter *adapter,
  135. u32 reg, u16 *value)
  136. {
  137. int pos = 0;
  138. struct pci_dev *parent_dev;
  139. struct pci_bus *parent_bus;
  140. parent_bus = adapter->pdev->bus->parent;
  141. if (!parent_bus)
  142. return -1;
  143. parent_dev = parent_bus->self;
  144. if (!parent_dev)
  145. return -1;
  146. pos = pci_find_capability(parent_dev, PCI_CAP_ID_EXP);
  147. if (!pos)
  148. return -1;
  149. pci_read_config_word(parent_dev, pos + reg, value);
  150. return 0;
  151. }
  152. static s32 ixgbe_get_parent_bus_info(struct ixgbe_adapter *adapter)
  153. {
  154. struct ixgbe_hw *hw = &adapter->hw;
  155. u16 link_status = 0;
  156. int err;
  157. hw->bus.type = ixgbe_bus_type_pci_express;
  158. /* Get the negotiated link width and speed from PCI config space of the
  159. * parent, as this device is behind a switch
  160. */
  161. err = ixgbe_read_pci_cfg_word_parent(adapter, 18, &link_status);
  162. /* assume caller will handle error case */
  163. if (err)
  164. return err;
  165. hw->bus.width = ixgbe_convert_bus_width(link_status);
  166. hw->bus.speed = ixgbe_convert_bus_speed(link_status);
  167. return 0;
  168. }
  169. static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
  170. {
  171. if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
  172. !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
  173. schedule_work(&adapter->service_task);
  174. }
  175. static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
  176. {
  177. BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
  178. /* flush memory to make sure state is correct before next watchdog */
  179. smp_mb__before_clear_bit();
  180. clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
  181. }
  182. struct ixgbe_reg_info {
  183. u32 ofs;
  184. char *name;
  185. };
  186. static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
  187. /* General Registers */
  188. {IXGBE_CTRL, "CTRL"},
  189. {IXGBE_STATUS, "STATUS"},
  190. {IXGBE_CTRL_EXT, "CTRL_EXT"},
  191. /* Interrupt Registers */
  192. {IXGBE_EICR, "EICR"},
  193. /* RX Registers */
  194. {IXGBE_SRRCTL(0), "SRRCTL"},
  195. {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
  196. {IXGBE_RDLEN(0), "RDLEN"},
  197. {IXGBE_RDH(0), "RDH"},
  198. {IXGBE_RDT(0), "RDT"},
  199. {IXGBE_RXDCTL(0), "RXDCTL"},
  200. {IXGBE_RDBAL(0), "RDBAL"},
  201. {IXGBE_RDBAH(0), "RDBAH"},
  202. /* TX Registers */
  203. {IXGBE_TDBAL(0), "TDBAL"},
  204. {IXGBE_TDBAH(0), "TDBAH"},
  205. {IXGBE_TDLEN(0), "TDLEN"},
  206. {IXGBE_TDH(0), "TDH"},
  207. {IXGBE_TDT(0), "TDT"},
  208. {IXGBE_TXDCTL(0), "TXDCTL"},
  209. /* List Terminator */
  210. {}
  211. };
  212. /*
  213. * ixgbe_regdump - register printout routine
  214. */
  215. static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
  216. {
  217. int i = 0, j = 0;
  218. char rname[16];
  219. u32 regs[64];
  220. switch (reginfo->ofs) {
  221. case IXGBE_SRRCTL(0):
  222. for (i = 0; i < 64; i++)
  223. regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
  224. break;
  225. case IXGBE_DCA_RXCTRL(0):
  226. for (i = 0; i < 64; i++)
  227. regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
  228. break;
  229. case IXGBE_RDLEN(0):
  230. for (i = 0; i < 64; i++)
  231. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
  232. break;
  233. case IXGBE_RDH(0):
  234. for (i = 0; i < 64; i++)
  235. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
  236. break;
  237. case IXGBE_RDT(0):
  238. for (i = 0; i < 64; i++)
  239. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
  240. break;
  241. case IXGBE_RXDCTL(0):
  242. for (i = 0; i < 64; i++)
  243. regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
  244. break;
  245. case IXGBE_RDBAL(0):
  246. for (i = 0; i < 64; i++)
  247. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
  248. break;
  249. case IXGBE_RDBAH(0):
  250. for (i = 0; i < 64; i++)
  251. regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
  252. break;
  253. case IXGBE_TDBAL(0):
  254. for (i = 0; i < 64; i++)
  255. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
  256. break;
  257. case IXGBE_TDBAH(0):
  258. for (i = 0; i < 64; i++)
  259. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
  260. break;
  261. case IXGBE_TDLEN(0):
  262. for (i = 0; i < 64; i++)
  263. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
  264. break;
  265. case IXGBE_TDH(0):
  266. for (i = 0; i < 64; i++)
  267. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
  268. break;
  269. case IXGBE_TDT(0):
  270. for (i = 0; i < 64; i++)
  271. regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
  272. break;
  273. case IXGBE_TXDCTL(0):
  274. for (i = 0; i < 64; i++)
  275. regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
  276. break;
  277. default:
  278. pr_info("%-15s %08x\n", reginfo->name,
  279. IXGBE_READ_REG(hw, reginfo->ofs));
  280. return;
  281. }
  282. for (i = 0; i < 8; i++) {
  283. snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
  284. pr_err("%-15s", rname);
  285. for (j = 0; j < 8; j++)
  286. pr_cont(" %08x", regs[i*8+j]);
  287. pr_cont("\n");
  288. }
  289. }
  290. /*
  291. * ixgbe_dump - Print registers, tx-rings and rx-rings
  292. */
  293. static void ixgbe_dump(struct ixgbe_adapter *adapter)
  294. {
  295. struct net_device *netdev = adapter->netdev;
  296. struct ixgbe_hw *hw = &adapter->hw;
  297. struct ixgbe_reg_info *reginfo;
  298. int n = 0;
  299. struct ixgbe_ring *tx_ring;
  300. struct ixgbe_tx_buffer *tx_buffer;
  301. union ixgbe_adv_tx_desc *tx_desc;
  302. struct my_u0 { u64 a; u64 b; } *u0;
  303. struct ixgbe_ring *rx_ring;
  304. union ixgbe_adv_rx_desc *rx_desc;
  305. struct ixgbe_rx_buffer *rx_buffer_info;
  306. u32 staterr;
  307. int i = 0;
  308. if (!netif_msg_hw(adapter))
  309. return;
  310. /* Print netdevice Info */
  311. if (netdev) {
  312. dev_info(&adapter->pdev->dev, "Net device Info\n");
  313. pr_info("Device Name state "
  314. "trans_start last_rx\n");
  315. pr_info("%-15s %016lX %016lX %016lX\n",
  316. netdev->name,
  317. netdev->state,
  318. netdev->trans_start,
  319. netdev->last_rx);
  320. }
  321. /* Print Registers */
  322. dev_info(&adapter->pdev->dev, "Register Dump\n");
  323. pr_info(" Register Name Value\n");
  324. for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
  325. reginfo->name; reginfo++) {
  326. ixgbe_regdump(hw, reginfo);
  327. }
  328. /* Print TX Ring Summary */
  329. if (!netdev || !netif_running(netdev))
  330. goto exit;
  331. dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
  332. pr_info(" %s %s %s %s\n",
  333. "Queue [NTU] [NTC] [bi(ntc)->dma ]",
  334. "leng", "ntw", "timestamp");
  335. for (n = 0; n < adapter->num_tx_queues; n++) {
  336. tx_ring = adapter->tx_ring[n];
  337. tx_buffer = &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
  338. pr_info(" %5d %5X %5X %016llX %08X %p %016llX\n",
  339. n, tx_ring->next_to_use, tx_ring->next_to_clean,
  340. (u64)dma_unmap_addr(tx_buffer, dma),
  341. dma_unmap_len(tx_buffer, len),
  342. tx_buffer->next_to_watch,
  343. (u64)tx_buffer->time_stamp);
  344. }
  345. /* Print TX Rings */
  346. if (!netif_msg_tx_done(adapter))
  347. goto rx_ring_summary;
  348. dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
  349. /* Transmit Descriptor Formats
  350. *
  351. * 82598 Advanced Transmit Descriptor
  352. * +--------------------------------------------------------------+
  353. * 0 | Buffer Address [63:0] |
  354. * +--------------------------------------------------------------+
  355. * 8 | PAYLEN | POPTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
  356. * +--------------------------------------------------------------+
  357. * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
  358. *
  359. * 82598 Advanced Transmit Descriptor (Write-Back Format)
  360. * +--------------------------------------------------------------+
  361. * 0 | RSV [63:0] |
  362. * +--------------------------------------------------------------+
  363. * 8 | RSV | STA | NXTSEQ |
  364. * +--------------------------------------------------------------+
  365. * 63 36 35 32 31 0
  366. *
  367. * 82599+ Advanced Transmit Descriptor
  368. * +--------------------------------------------------------------+
  369. * 0 | Buffer Address [63:0] |
  370. * +--------------------------------------------------------------+
  371. * 8 |PAYLEN |POPTS|CC|IDX |STA |DCMD |DTYP |MAC |RSV |DTALEN |
  372. * +--------------------------------------------------------------+
  373. * 63 46 45 40 39 38 36 35 32 31 24 23 20 19 18 17 16 15 0
  374. *
  375. * 82599+ Advanced Transmit Descriptor (Write-Back Format)
  376. * +--------------------------------------------------------------+
  377. * 0 | RSV [63:0] |
  378. * +--------------------------------------------------------------+
  379. * 8 | RSV | STA | RSV |
  380. * +--------------------------------------------------------------+
  381. * 63 36 35 32 31 0
  382. */
  383. for (n = 0; n < adapter->num_tx_queues; n++) {
  384. tx_ring = adapter->tx_ring[n];
  385. pr_info("------------------------------------\n");
  386. pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
  387. pr_info("------------------------------------\n");
  388. pr_info("%s%s %s %s %s %s\n",
  389. "T [desc] [address 63:0 ] ",
  390. "[PlPOIdStDDt Ln] [bi->dma ] ",
  391. "leng", "ntw", "timestamp", "bi->skb");
  392. for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
  393. tx_desc = IXGBE_TX_DESC(tx_ring, i);
  394. tx_buffer = &tx_ring->tx_buffer_info[i];
  395. u0 = (struct my_u0 *)tx_desc;
  396. if (dma_unmap_len(tx_buffer, len) > 0) {
  397. pr_info("T [0x%03X] %016llX %016llX %016llX %08X %p %016llX %p",
  398. i,
  399. le64_to_cpu(u0->a),
  400. le64_to_cpu(u0->b),
  401. (u64)dma_unmap_addr(tx_buffer, dma),
  402. dma_unmap_len(tx_buffer, len),
  403. tx_buffer->next_to_watch,
  404. (u64)tx_buffer->time_stamp,
  405. tx_buffer->skb);
  406. if (i == tx_ring->next_to_use &&
  407. i == tx_ring->next_to_clean)
  408. pr_cont(" NTC/U\n");
  409. else if (i == tx_ring->next_to_use)
  410. pr_cont(" NTU\n");
  411. else if (i == tx_ring->next_to_clean)
  412. pr_cont(" NTC\n");
  413. else
  414. pr_cont("\n");
  415. if (netif_msg_pktdata(adapter) &&
  416. tx_buffer->skb)
  417. print_hex_dump(KERN_INFO, "",
  418. DUMP_PREFIX_ADDRESS, 16, 1,
  419. tx_buffer->skb->data,
  420. dma_unmap_len(tx_buffer, len),
  421. true);
  422. }
  423. }
  424. }
  425. /* Print RX Rings Summary */
  426. rx_ring_summary:
  427. dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
  428. pr_info("Queue [NTU] [NTC]\n");
  429. for (n = 0; n < adapter->num_rx_queues; n++) {
  430. rx_ring = adapter->rx_ring[n];
  431. pr_info("%5d %5X %5X\n",
  432. n, rx_ring->next_to_use, rx_ring->next_to_clean);
  433. }
  434. /* Print RX Rings */
  435. if (!netif_msg_rx_status(adapter))
  436. goto exit;
  437. dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
  438. /* Receive Descriptor Formats
  439. *
  440. * 82598 Advanced Receive Descriptor (Read) Format
  441. * 63 1 0
  442. * +-----------------------------------------------------+
  443. * 0 | Packet Buffer Address [63:1] |A0/NSE|
  444. * +----------------------------------------------+------+
  445. * 8 | Header Buffer Address [63:1] | DD |
  446. * +-----------------------------------------------------+
  447. *
  448. *
  449. * 82598 Advanced Receive Descriptor (Write-Back) Format
  450. *
  451. * 63 48 47 32 31 30 21 20 16 15 4 3 0
  452. * +------------------------------------------------------+
  453. * 0 | RSS Hash / |SPH| HDR_LEN | RSV |Packet| RSS |
  454. * | Packet | IP | | | | Type | Type |
  455. * | Checksum | Ident | | | | | |
  456. * +------------------------------------------------------+
  457. * 8 | VLAN Tag | Length | Extended Error | Extended Status |
  458. * +------------------------------------------------------+
  459. * 63 48 47 32 31 20 19 0
  460. *
  461. * 82599+ Advanced Receive Descriptor (Read) Format
  462. * 63 1 0
  463. * +-----------------------------------------------------+
  464. * 0 | Packet Buffer Address [63:1] |A0/NSE|
  465. * +----------------------------------------------+------+
  466. * 8 | Header Buffer Address [63:1] | DD |
  467. * +-----------------------------------------------------+
  468. *
  469. *
  470. * 82599+ Advanced Receive Descriptor (Write-Back) Format
  471. *
  472. * 63 48 47 32 31 30 21 20 17 16 4 3 0
  473. * +------------------------------------------------------+
  474. * 0 |RSS / Frag Checksum|SPH| HDR_LEN |RSC- |Packet| RSS |
  475. * |/ RTT / PCoE_PARAM | | | CNT | Type | Type |
  476. * |/ Flow Dir Flt ID | | | | | |
  477. * +------------------------------------------------------+
  478. * 8 | VLAN Tag | Length |Extended Error| Xtnd Status/NEXTP |
  479. * +------------------------------------------------------+
  480. * 63 48 47 32 31 20 19 0
  481. */
  482. for (n = 0; n < adapter->num_rx_queues; n++) {
  483. rx_ring = adapter->rx_ring[n];
  484. pr_info("------------------------------------\n");
  485. pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
  486. pr_info("------------------------------------\n");
  487. pr_info("%s%s%s",
  488. "R [desc] [ PktBuf A0] ",
  489. "[ HeadBuf DD] [bi->dma ] [bi->skb ] ",
  490. "<-- Adv Rx Read format\n");
  491. pr_info("%s%s%s",
  492. "RWB[desc] [PcsmIpSHl PtRs] ",
  493. "[vl er S cks ln] ---------------- [bi->skb ] ",
  494. "<-- Adv Rx Write-Back format\n");
  495. for (i = 0; i < rx_ring->count; i++) {
  496. rx_buffer_info = &rx_ring->rx_buffer_info[i];
  497. rx_desc = IXGBE_RX_DESC(rx_ring, i);
  498. u0 = (struct my_u0 *)rx_desc;
  499. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  500. if (staterr & IXGBE_RXD_STAT_DD) {
  501. /* Descriptor Done */
  502. pr_info("RWB[0x%03X] %016llX "
  503. "%016llX ---------------- %p", i,
  504. le64_to_cpu(u0->a),
  505. le64_to_cpu(u0->b),
  506. rx_buffer_info->skb);
  507. } else {
  508. pr_info("R [0x%03X] %016llX "
  509. "%016llX %016llX %p", i,
  510. le64_to_cpu(u0->a),
  511. le64_to_cpu(u0->b),
  512. (u64)rx_buffer_info->dma,
  513. rx_buffer_info->skb);
  514. if (netif_msg_pktdata(adapter) &&
  515. rx_buffer_info->dma) {
  516. print_hex_dump(KERN_INFO, "",
  517. DUMP_PREFIX_ADDRESS, 16, 1,
  518. page_address(rx_buffer_info->page) +
  519. rx_buffer_info->page_offset,
  520. ixgbe_rx_bufsz(rx_ring), true);
  521. }
  522. }
  523. if (i == rx_ring->next_to_use)
  524. pr_cont(" NTU\n");
  525. else if (i == rx_ring->next_to_clean)
  526. pr_cont(" NTC\n");
  527. else
  528. pr_cont("\n");
  529. }
  530. }
  531. exit:
  532. return;
  533. }
  534. static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
  535. {
  536. u32 ctrl_ext;
  537. /* Let firmware take over control of h/w */
  538. ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
  539. IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
  540. ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
  541. }
  542. static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
  543. {
  544. u32 ctrl_ext;
  545. /* Let firmware know the driver has taken over */
  546. ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
  547. IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
  548. ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
  549. }
  550. /**
  551. * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
  552. * @adapter: pointer to adapter struct
  553. * @direction: 0 for Rx, 1 for Tx, -1 for other causes
  554. * @queue: queue to map the corresponding interrupt to
  555. * @msix_vector: the vector to map to the corresponding queue
  556. *
  557. */
  558. static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
  559. u8 queue, u8 msix_vector)
  560. {
  561. u32 ivar, index;
  562. struct ixgbe_hw *hw = &adapter->hw;
  563. switch (hw->mac.type) {
  564. case ixgbe_mac_82598EB:
  565. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  566. if (direction == -1)
  567. direction = 0;
  568. index = (((direction * 64) + queue) >> 2) & 0x1F;
  569. ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
  570. ivar &= ~(0xFF << (8 * (queue & 0x3)));
  571. ivar |= (msix_vector << (8 * (queue & 0x3)));
  572. IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
  573. break;
  574. case ixgbe_mac_82599EB:
  575. case ixgbe_mac_X540:
  576. if (direction == -1) {
  577. /* other causes */
  578. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  579. index = ((queue & 1) * 8);
  580. ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
  581. ivar &= ~(0xFF << index);
  582. ivar |= (msix_vector << index);
  583. IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
  584. break;
  585. } else {
  586. /* tx or rx causes */
  587. msix_vector |= IXGBE_IVAR_ALLOC_VAL;
  588. index = ((16 * (queue & 1)) + (8 * direction));
  589. ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
  590. ivar &= ~(0xFF << index);
  591. ivar |= (msix_vector << index);
  592. IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
  593. break;
  594. }
  595. default:
  596. break;
  597. }
  598. }
  599. static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
  600. u64 qmask)
  601. {
  602. u32 mask;
  603. switch (adapter->hw.mac.type) {
  604. case ixgbe_mac_82598EB:
  605. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  606. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
  607. break;
  608. case ixgbe_mac_82599EB:
  609. case ixgbe_mac_X540:
  610. mask = (qmask & 0xFFFFFFFF);
  611. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
  612. mask = (qmask >> 32);
  613. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
  614. break;
  615. default:
  616. break;
  617. }
  618. }
  619. void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *ring,
  620. struct ixgbe_tx_buffer *tx_buffer)
  621. {
  622. if (tx_buffer->skb) {
  623. dev_kfree_skb_any(tx_buffer->skb);
  624. if (dma_unmap_len(tx_buffer, len))
  625. dma_unmap_single(ring->dev,
  626. dma_unmap_addr(tx_buffer, dma),
  627. dma_unmap_len(tx_buffer, len),
  628. DMA_TO_DEVICE);
  629. } else if (dma_unmap_len(tx_buffer, len)) {
  630. dma_unmap_page(ring->dev,
  631. dma_unmap_addr(tx_buffer, dma),
  632. dma_unmap_len(tx_buffer, len),
  633. DMA_TO_DEVICE);
  634. }
  635. tx_buffer->next_to_watch = NULL;
  636. tx_buffer->skb = NULL;
  637. dma_unmap_len_set(tx_buffer, len, 0);
  638. /* tx_buffer must be completely set up in the transmit path */
  639. }
  640. static void ixgbe_update_xoff_rx_lfc(struct ixgbe_adapter *adapter)
  641. {
  642. struct ixgbe_hw *hw = &adapter->hw;
  643. struct ixgbe_hw_stats *hwstats = &adapter->stats;
  644. int i;
  645. u32 data;
  646. if ((hw->fc.current_mode != ixgbe_fc_full) &&
  647. (hw->fc.current_mode != ixgbe_fc_rx_pause))
  648. return;
  649. switch (hw->mac.type) {
  650. case ixgbe_mac_82598EB:
  651. data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
  652. break;
  653. default:
  654. data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
  655. }
  656. hwstats->lxoffrxc += data;
  657. /* refill credits (no tx hang) if we received xoff */
  658. if (!data)
  659. return;
  660. for (i = 0; i < adapter->num_tx_queues; i++)
  661. clear_bit(__IXGBE_HANG_CHECK_ARMED,
  662. &adapter->tx_ring[i]->state);
  663. }
  664. static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
  665. {
  666. struct ixgbe_hw *hw = &adapter->hw;
  667. struct ixgbe_hw_stats *hwstats = &adapter->stats;
  668. u32 xoff[8] = {0};
  669. u8 tc;
  670. int i;
  671. bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
  672. if (adapter->ixgbe_ieee_pfc)
  673. pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
  674. if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !pfc_en) {
  675. ixgbe_update_xoff_rx_lfc(adapter);
  676. return;
  677. }
  678. /* update stats for each tc, only valid with PFC enabled */
  679. for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
  680. u32 pxoffrxc;
  681. switch (hw->mac.type) {
  682. case ixgbe_mac_82598EB:
  683. pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
  684. break;
  685. default:
  686. pxoffrxc = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
  687. }
  688. hwstats->pxoffrxc[i] += pxoffrxc;
  689. /* Get the TC for given UP */
  690. tc = netdev_get_prio_tc_map(adapter->netdev, i);
  691. xoff[tc] += pxoffrxc;
  692. }
  693. /* disarm tx queues that have received xoff frames */
  694. for (i = 0; i < adapter->num_tx_queues; i++) {
  695. struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
  696. tc = tx_ring->dcb_tc;
  697. if (xoff[tc])
  698. clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
  699. }
  700. }
  701. static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
  702. {
  703. return ring->stats.packets;
  704. }
  705. static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
  706. {
  707. struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
  708. struct ixgbe_hw *hw = &adapter->hw;
  709. u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
  710. u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
  711. if (head != tail)
  712. return (head < tail) ?
  713. tail - head : (tail + ring->count - head);
  714. return 0;
  715. }
  716. static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
  717. {
  718. u32 tx_done = ixgbe_get_tx_completed(tx_ring);
  719. u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
  720. u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
  721. bool ret = false;
  722. clear_check_for_tx_hang(tx_ring);
  723. /*
  724. * Check for a hung queue, but be thorough. This verifies
  725. * that a transmit has been completed since the previous
  726. * check AND there is at least one packet pending. The
  727. * ARMED bit is set to indicate a potential hang. The
  728. * bit is cleared if a pause frame is received to remove
  729. * false hang detection due to PFC or 802.3x frames. By
  730. * requiring this to fail twice we avoid races with
  731. * pfc clearing the ARMED bit and conditions where we
  732. * run the check_tx_hang logic with a transmit completion
  733. * pending but without time to complete it yet.
  734. */
  735. if ((tx_done_old == tx_done) && tx_pending) {
  736. /* make sure it is true for two checks in a row */
  737. ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
  738. &tx_ring->state);
  739. } else {
  740. /* update completed stats and continue */
  741. tx_ring->tx_stats.tx_done_old = tx_done;
  742. /* reset the countdown */
  743. clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
  744. }
  745. return ret;
  746. }
  747. /**
  748. * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
  749. * @adapter: driver private struct
  750. **/
  751. static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
  752. {
  753. /* Do the reset outside of interrupt context */
  754. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  755. adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
  756. e_warn(drv, "initiating reset due to tx timeout\n");
  757. ixgbe_service_event_schedule(adapter);
  758. }
  759. }
  760. /**
  761. * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
  762. * @q_vector: structure containing interrupt and ring information
  763. * @tx_ring: tx ring to clean
  764. **/
  765. static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
  766. struct ixgbe_ring *tx_ring)
  767. {
  768. struct ixgbe_adapter *adapter = q_vector->adapter;
  769. struct ixgbe_tx_buffer *tx_buffer;
  770. union ixgbe_adv_tx_desc *tx_desc;
  771. unsigned int total_bytes = 0, total_packets = 0;
  772. unsigned int budget = q_vector->tx.work_limit;
  773. unsigned int i = tx_ring->next_to_clean;
  774. if (test_bit(__IXGBE_DOWN, &adapter->state))
  775. return true;
  776. tx_buffer = &tx_ring->tx_buffer_info[i];
  777. tx_desc = IXGBE_TX_DESC(tx_ring, i);
  778. i -= tx_ring->count;
  779. do {
  780. union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
  781. /* if next_to_watch is not set then there is no work pending */
  782. if (!eop_desc)
  783. break;
  784. /* prevent any other reads prior to eop_desc */
  785. read_barrier_depends();
  786. /* if DD is not set pending work has not been completed */
  787. if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
  788. break;
  789. /* clear next_to_watch to prevent false hangs */
  790. tx_buffer->next_to_watch = NULL;
  791. /* update the statistics for this packet */
  792. total_bytes += tx_buffer->bytecount;
  793. total_packets += tx_buffer->gso_segs;
  794. /* free the skb */
  795. dev_kfree_skb_any(tx_buffer->skb);
  796. /* unmap skb header data */
  797. dma_unmap_single(tx_ring->dev,
  798. dma_unmap_addr(tx_buffer, dma),
  799. dma_unmap_len(tx_buffer, len),
  800. DMA_TO_DEVICE);
  801. /* clear tx_buffer data */
  802. tx_buffer->skb = NULL;
  803. dma_unmap_len_set(tx_buffer, len, 0);
  804. /* unmap remaining buffers */
  805. while (tx_desc != eop_desc) {
  806. tx_buffer++;
  807. tx_desc++;
  808. i++;
  809. if (unlikely(!i)) {
  810. i -= tx_ring->count;
  811. tx_buffer = tx_ring->tx_buffer_info;
  812. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  813. }
  814. /* unmap any remaining paged data */
  815. if (dma_unmap_len(tx_buffer, len)) {
  816. dma_unmap_page(tx_ring->dev,
  817. dma_unmap_addr(tx_buffer, dma),
  818. dma_unmap_len(tx_buffer, len),
  819. DMA_TO_DEVICE);
  820. dma_unmap_len_set(tx_buffer, len, 0);
  821. }
  822. }
  823. /* move us one more past the eop_desc for start of next pkt */
  824. tx_buffer++;
  825. tx_desc++;
  826. i++;
  827. if (unlikely(!i)) {
  828. i -= tx_ring->count;
  829. tx_buffer = tx_ring->tx_buffer_info;
  830. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  831. }
  832. /* issue prefetch for next Tx descriptor */
  833. prefetch(tx_desc);
  834. /* update budget accounting */
  835. budget--;
  836. } while (likely(budget));
  837. i += tx_ring->count;
  838. tx_ring->next_to_clean = i;
  839. u64_stats_update_begin(&tx_ring->syncp);
  840. tx_ring->stats.bytes += total_bytes;
  841. tx_ring->stats.packets += total_packets;
  842. u64_stats_update_end(&tx_ring->syncp);
  843. q_vector->tx.total_bytes += total_bytes;
  844. q_vector->tx.total_packets += total_packets;
  845. if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
  846. /* schedule immediate reset if we believe we hung */
  847. struct ixgbe_hw *hw = &adapter->hw;
  848. e_err(drv, "Detected Tx Unit Hang\n"
  849. " Tx Queue <%d>\n"
  850. " TDH, TDT <%x>, <%x>\n"
  851. " next_to_use <%x>\n"
  852. " next_to_clean <%x>\n"
  853. "tx_buffer_info[next_to_clean]\n"
  854. " time_stamp <%lx>\n"
  855. " jiffies <%lx>\n",
  856. tx_ring->queue_index,
  857. IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
  858. IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
  859. tx_ring->next_to_use, i,
  860. tx_ring->tx_buffer_info[i].time_stamp, jiffies);
  861. netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
  862. e_info(probe,
  863. "tx hang %d detected on queue %d, resetting adapter\n",
  864. adapter->tx_timeout_count + 1, tx_ring->queue_index);
  865. /* schedule immediate reset if we believe we hung */
  866. ixgbe_tx_timeout_reset(adapter);
  867. /* the adapter is about to reset, no point in enabling stuff */
  868. return true;
  869. }
  870. netdev_tx_completed_queue(txring_txq(tx_ring),
  871. total_packets, total_bytes);
  872. #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
  873. if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
  874. (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
  875. /* Make sure that anybody stopping the queue after this
  876. * sees the new next_to_clean.
  877. */
  878. smp_mb();
  879. if (__netif_subqueue_stopped(tx_ring->netdev,
  880. tx_ring->queue_index)
  881. && !test_bit(__IXGBE_DOWN, &adapter->state)) {
  882. netif_wake_subqueue(tx_ring->netdev,
  883. tx_ring->queue_index);
  884. ++tx_ring->tx_stats.restart_queue;
  885. }
  886. }
  887. return !!budget;
  888. }
  889. #ifdef CONFIG_IXGBE_DCA
  890. static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
  891. struct ixgbe_ring *tx_ring,
  892. int cpu)
  893. {
  894. struct ixgbe_hw *hw = &adapter->hw;
  895. u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
  896. u16 reg_offset;
  897. switch (hw->mac.type) {
  898. case ixgbe_mac_82598EB:
  899. reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
  900. break;
  901. case ixgbe_mac_82599EB:
  902. case ixgbe_mac_X540:
  903. reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
  904. txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
  905. break;
  906. default:
  907. /* for unknown hardware do not write register */
  908. return;
  909. }
  910. /*
  911. * We can enable relaxed ordering for reads, but not writes when
  912. * DCA is enabled. This is due to a known issue in some chipsets
  913. * which will cause the DCA tag to be cleared.
  914. */
  915. txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
  916. IXGBE_DCA_TXCTRL_DATA_RRO_EN |
  917. IXGBE_DCA_TXCTRL_DESC_DCA_EN;
  918. IXGBE_WRITE_REG(hw, reg_offset, txctrl);
  919. }
  920. static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
  921. struct ixgbe_ring *rx_ring,
  922. int cpu)
  923. {
  924. struct ixgbe_hw *hw = &adapter->hw;
  925. u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
  926. u8 reg_idx = rx_ring->reg_idx;
  927. switch (hw->mac.type) {
  928. case ixgbe_mac_82599EB:
  929. case ixgbe_mac_X540:
  930. rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
  931. break;
  932. default:
  933. break;
  934. }
  935. /*
  936. * We can enable relaxed ordering for reads, but not writes when
  937. * DCA is enabled. This is due to a known issue in some chipsets
  938. * which will cause the DCA tag to be cleared.
  939. */
  940. rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
  941. IXGBE_DCA_RXCTRL_DESC_DCA_EN;
  942. IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
  943. }
  944. static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
  945. {
  946. struct ixgbe_adapter *adapter = q_vector->adapter;
  947. struct ixgbe_ring *ring;
  948. int cpu = get_cpu();
  949. if (q_vector->cpu == cpu)
  950. goto out_no_update;
  951. ixgbe_for_each_ring(ring, q_vector->tx)
  952. ixgbe_update_tx_dca(adapter, ring, cpu);
  953. ixgbe_for_each_ring(ring, q_vector->rx)
  954. ixgbe_update_rx_dca(adapter, ring, cpu);
  955. q_vector->cpu = cpu;
  956. out_no_update:
  957. put_cpu();
  958. }
  959. static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
  960. {
  961. int i;
  962. if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
  963. return;
  964. /* always use CB2 mode, difference is masked in the CB driver */
  965. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
  966. for (i = 0; i < adapter->num_q_vectors; i++) {
  967. adapter->q_vector[i]->cpu = -1;
  968. ixgbe_update_dca(adapter->q_vector[i]);
  969. }
  970. }
  971. static int __ixgbe_notify_dca(struct device *dev, void *data)
  972. {
  973. struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
  974. unsigned long event = *(unsigned long *)data;
  975. if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
  976. return 0;
  977. switch (event) {
  978. case DCA_PROVIDER_ADD:
  979. /* if we're already enabled, don't do it again */
  980. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  981. break;
  982. if (dca_add_requester(dev) == 0) {
  983. adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
  984. ixgbe_setup_dca(adapter);
  985. break;
  986. }
  987. /* Fall Through since DCA is disabled. */
  988. case DCA_PROVIDER_REMOVE:
  989. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  990. dca_remove_requester(dev);
  991. adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
  992. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
  993. }
  994. break;
  995. }
  996. return 0;
  997. }
  998. #endif /* CONFIG_IXGBE_DCA */
  999. static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
  1000. union ixgbe_adv_rx_desc *rx_desc,
  1001. struct sk_buff *skb)
  1002. {
  1003. if (ring->netdev->features & NETIF_F_RXHASH)
  1004. skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
  1005. }
  1006. #ifdef IXGBE_FCOE
  1007. /**
  1008. * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
  1009. * @ring: structure containing ring specific data
  1010. * @rx_desc: advanced rx descriptor
  1011. *
  1012. * Returns : true if it is FCoE pkt
  1013. */
  1014. static inline bool ixgbe_rx_is_fcoe(struct ixgbe_ring *ring,
  1015. union ixgbe_adv_rx_desc *rx_desc)
  1016. {
  1017. __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
  1018. return test_bit(__IXGBE_RX_FCOE, &ring->state) &&
  1019. ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
  1020. (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
  1021. IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
  1022. }
  1023. #endif /* IXGBE_FCOE */
  1024. /**
  1025. * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
  1026. * @ring: structure containing ring specific data
  1027. * @rx_desc: current Rx descriptor being processed
  1028. * @skb: skb currently being received and modified
  1029. **/
  1030. static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
  1031. union ixgbe_adv_rx_desc *rx_desc,
  1032. struct sk_buff *skb)
  1033. {
  1034. skb_checksum_none_assert(skb);
  1035. /* Rx csum disabled */
  1036. if (!(ring->netdev->features & NETIF_F_RXCSUM))
  1037. return;
  1038. /* if IP and error */
  1039. if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
  1040. ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
  1041. ring->rx_stats.csum_err++;
  1042. return;
  1043. }
  1044. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
  1045. return;
  1046. if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
  1047. __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
  1048. /*
  1049. * 82599 errata, UDP frames with a 0 checksum can be marked as
  1050. * checksum errors.
  1051. */
  1052. if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
  1053. test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
  1054. return;
  1055. ring->rx_stats.csum_err++;
  1056. return;
  1057. }
  1058. /* It must be a TCP or UDP packet with a valid checksum */
  1059. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1060. }
  1061. static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
  1062. {
  1063. rx_ring->next_to_use = val;
  1064. /* update next to alloc since we have filled the ring */
  1065. rx_ring->next_to_alloc = val;
  1066. /*
  1067. * Force memory writes to complete before letting h/w
  1068. * know there are new descriptors to fetch. (Only
  1069. * applicable for weak-ordered memory model archs,
  1070. * such as IA-64).
  1071. */
  1072. wmb();
  1073. writel(val, rx_ring->tail);
  1074. }
  1075. static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
  1076. struct ixgbe_rx_buffer *bi)
  1077. {
  1078. struct page *page = bi->page;
  1079. dma_addr_t dma = bi->dma;
  1080. /* since we are recycling buffers we should seldom need to alloc */
  1081. if (likely(dma))
  1082. return true;
  1083. /* alloc new page for storage */
  1084. if (likely(!page)) {
  1085. page = __skb_alloc_pages(GFP_ATOMIC | __GFP_COLD | __GFP_COMP,
  1086. bi->skb, ixgbe_rx_pg_order(rx_ring));
  1087. if (unlikely(!page)) {
  1088. rx_ring->rx_stats.alloc_rx_page_failed++;
  1089. return false;
  1090. }
  1091. bi->page = page;
  1092. }
  1093. /* map page for use */
  1094. dma = dma_map_page(rx_ring->dev, page, 0,
  1095. ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
  1096. /*
  1097. * if mapping failed free memory back to system since
  1098. * there isn't much point in holding memory we can't use
  1099. */
  1100. if (dma_mapping_error(rx_ring->dev, dma)) {
  1101. __free_pages(page, ixgbe_rx_pg_order(rx_ring));
  1102. bi->page = NULL;
  1103. rx_ring->rx_stats.alloc_rx_page_failed++;
  1104. return false;
  1105. }
  1106. bi->dma = dma;
  1107. bi->page_offset = 0;
  1108. return true;
  1109. }
  1110. /**
  1111. * ixgbe_alloc_rx_buffers - Replace used receive buffers
  1112. * @rx_ring: ring to place buffers on
  1113. * @cleaned_count: number of buffers to replace
  1114. **/
  1115. void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
  1116. {
  1117. union ixgbe_adv_rx_desc *rx_desc;
  1118. struct ixgbe_rx_buffer *bi;
  1119. u16 i = rx_ring->next_to_use;
  1120. /* nothing to do */
  1121. if (!cleaned_count)
  1122. return;
  1123. rx_desc = IXGBE_RX_DESC(rx_ring, i);
  1124. bi = &rx_ring->rx_buffer_info[i];
  1125. i -= rx_ring->count;
  1126. do {
  1127. if (!ixgbe_alloc_mapped_page(rx_ring, bi))
  1128. break;
  1129. /*
  1130. * Refresh the desc even if buffer_addrs didn't change
  1131. * because each write-back erases this info.
  1132. */
  1133. rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset);
  1134. rx_desc++;
  1135. bi++;
  1136. i++;
  1137. if (unlikely(!i)) {
  1138. rx_desc = IXGBE_RX_DESC(rx_ring, 0);
  1139. bi = rx_ring->rx_buffer_info;
  1140. i -= rx_ring->count;
  1141. }
  1142. /* clear the hdr_addr for the next_to_use descriptor */
  1143. rx_desc->read.hdr_addr = 0;
  1144. cleaned_count--;
  1145. } while (cleaned_count);
  1146. i += rx_ring->count;
  1147. if (rx_ring->next_to_use != i)
  1148. ixgbe_release_rx_desc(rx_ring, i);
  1149. }
  1150. /**
  1151. * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
  1152. * @data: pointer to the start of the headers
  1153. * @max_len: total length of section to find headers in
  1154. *
  1155. * This function is meant to determine the length of headers that will
  1156. * be recognized by hardware for LRO, GRO, and RSC offloads. The main
  1157. * motivation of doing this is to only perform one pull for IPv4 TCP
  1158. * packets so that we can do basic things like calculating the gso_size
  1159. * based on the average data per packet.
  1160. **/
  1161. static unsigned int ixgbe_get_headlen(unsigned char *data,
  1162. unsigned int max_len)
  1163. {
  1164. union {
  1165. unsigned char *network;
  1166. /* l2 headers */
  1167. struct ethhdr *eth;
  1168. struct vlan_hdr *vlan;
  1169. /* l3 headers */
  1170. struct iphdr *ipv4;
  1171. struct ipv6hdr *ipv6;
  1172. } hdr;
  1173. __be16 protocol;
  1174. u8 nexthdr = 0; /* default to not TCP */
  1175. u8 hlen;
  1176. /* this should never happen, but better safe than sorry */
  1177. if (max_len < ETH_HLEN)
  1178. return max_len;
  1179. /* initialize network frame pointer */
  1180. hdr.network = data;
  1181. /* set first protocol and move network header forward */
  1182. protocol = hdr.eth->h_proto;
  1183. hdr.network += ETH_HLEN;
  1184. /* handle any vlan tag if present */
  1185. if (protocol == __constant_htons(ETH_P_8021Q)) {
  1186. if ((hdr.network - data) > (max_len - VLAN_HLEN))
  1187. return max_len;
  1188. protocol = hdr.vlan->h_vlan_encapsulated_proto;
  1189. hdr.network += VLAN_HLEN;
  1190. }
  1191. /* handle L3 protocols */
  1192. if (protocol == __constant_htons(ETH_P_IP)) {
  1193. if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
  1194. return max_len;
  1195. /* access ihl as a u8 to avoid unaligned access on ia64 */
  1196. hlen = (hdr.network[0] & 0x0F) << 2;
  1197. /* verify hlen meets minimum size requirements */
  1198. if (hlen < sizeof(struct iphdr))
  1199. return hdr.network - data;
  1200. /* record next protocol if header is present */
  1201. if (!(hdr.ipv4->frag_off & htons(IP_OFFSET)))
  1202. nexthdr = hdr.ipv4->protocol;
  1203. } else if (protocol == __constant_htons(ETH_P_IPV6)) {
  1204. if ((hdr.network - data) > (max_len - sizeof(struct ipv6hdr)))
  1205. return max_len;
  1206. /* record next protocol */
  1207. nexthdr = hdr.ipv6->nexthdr;
  1208. hlen = sizeof(struct ipv6hdr);
  1209. #ifdef IXGBE_FCOE
  1210. } else if (protocol == __constant_htons(ETH_P_FCOE)) {
  1211. if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
  1212. return max_len;
  1213. hlen = FCOE_HEADER_LEN;
  1214. #endif
  1215. } else {
  1216. return hdr.network - data;
  1217. }
  1218. /* relocate pointer to start of L4 header */
  1219. hdr.network += hlen;
  1220. /* finally sort out TCP/UDP */
  1221. if (nexthdr == IPPROTO_TCP) {
  1222. if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
  1223. return max_len;
  1224. /* access doff as a u8 to avoid unaligned access on ia64 */
  1225. hlen = (hdr.network[12] & 0xF0) >> 2;
  1226. /* verify hlen meets minimum size requirements */
  1227. if (hlen < sizeof(struct tcphdr))
  1228. return hdr.network - data;
  1229. hdr.network += hlen;
  1230. } else if (nexthdr == IPPROTO_UDP) {
  1231. if ((hdr.network - data) > (max_len - sizeof(struct udphdr)))
  1232. return max_len;
  1233. hdr.network += sizeof(struct udphdr);
  1234. }
  1235. /*
  1236. * If everything has gone correctly hdr.network should be the
  1237. * data section of the packet and will be the end of the header.
  1238. * If not then it probably represents the end of the last recognized
  1239. * header.
  1240. */
  1241. if ((hdr.network - data) < max_len)
  1242. return hdr.network - data;
  1243. else
  1244. return max_len;
  1245. }
  1246. static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
  1247. struct sk_buff *skb)
  1248. {
  1249. u16 hdr_len = skb_headlen(skb);
  1250. /* set gso_size to avoid messing up TCP MSS */
  1251. skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
  1252. IXGBE_CB(skb)->append_cnt);
  1253. skb_shinfo(skb)->gso_type = SKB_GSO_TCPV4;
  1254. }
  1255. static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
  1256. struct sk_buff *skb)
  1257. {
  1258. /* if append_cnt is 0 then frame is not RSC */
  1259. if (!IXGBE_CB(skb)->append_cnt)
  1260. return;
  1261. rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
  1262. rx_ring->rx_stats.rsc_flush++;
  1263. ixgbe_set_rsc_gso_size(rx_ring, skb);
  1264. /* gso_size is computed using append_cnt so always clear it last */
  1265. IXGBE_CB(skb)->append_cnt = 0;
  1266. }
  1267. /**
  1268. * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
  1269. * @rx_ring: rx descriptor ring packet is being transacted on
  1270. * @rx_desc: pointer to the EOP Rx descriptor
  1271. * @skb: pointer to current skb being populated
  1272. *
  1273. * This function checks the ring, descriptor, and packet information in
  1274. * order to populate the hash, checksum, VLAN, timestamp, protocol, and
  1275. * other fields within the skb.
  1276. **/
  1277. static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
  1278. union ixgbe_adv_rx_desc *rx_desc,
  1279. struct sk_buff *skb)
  1280. {
  1281. struct net_device *dev = rx_ring->netdev;
  1282. ixgbe_update_rsc_stats(rx_ring, skb);
  1283. ixgbe_rx_hash(rx_ring, rx_desc, skb);
  1284. ixgbe_rx_checksum(rx_ring, rx_desc, skb);
  1285. ixgbe_ptp_rx_hwtstamp(rx_ring, rx_desc, skb);
  1286. if ((dev->features & NETIF_F_HW_VLAN_CTAG_RX) &&
  1287. ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
  1288. u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
  1289. __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
  1290. }
  1291. skb_record_rx_queue(skb, rx_ring->queue_index);
  1292. skb->protocol = eth_type_trans(skb, dev);
  1293. }
  1294. static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
  1295. struct sk_buff *skb)
  1296. {
  1297. struct ixgbe_adapter *adapter = q_vector->adapter;
  1298. if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
  1299. napi_gro_receive(&q_vector->napi, skb);
  1300. else
  1301. netif_rx(skb);
  1302. }
  1303. /**
  1304. * ixgbe_is_non_eop - process handling of non-EOP buffers
  1305. * @rx_ring: Rx ring being processed
  1306. * @rx_desc: Rx descriptor for current buffer
  1307. * @skb: Current socket buffer containing buffer in progress
  1308. *
  1309. * This function updates next to clean. If the buffer is an EOP buffer
  1310. * this function exits returning false, otherwise it will place the
  1311. * sk_buff in the next buffer to be chained and return true indicating
  1312. * that this is in fact a non-EOP buffer.
  1313. **/
  1314. static bool ixgbe_is_non_eop(struct ixgbe_ring *rx_ring,
  1315. union ixgbe_adv_rx_desc *rx_desc,
  1316. struct sk_buff *skb)
  1317. {
  1318. u32 ntc = rx_ring->next_to_clean + 1;
  1319. /* fetch, update, and store next to clean */
  1320. ntc = (ntc < rx_ring->count) ? ntc : 0;
  1321. rx_ring->next_to_clean = ntc;
  1322. prefetch(IXGBE_RX_DESC(rx_ring, ntc));
  1323. /* update RSC append count if present */
  1324. if (ring_is_rsc_enabled(rx_ring)) {
  1325. __le32 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
  1326. cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
  1327. if (unlikely(rsc_enabled)) {
  1328. u32 rsc_cnt = le32_to_cpu(rsc_enabled);
  1329. rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
  1330. IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
  1331. /* update ntc based on RSC value */
  1332. ntc = le32_to_cpu(rx_desc->wb.upper.status_error);
  1333. ntc &= IXGBE_RXDADV_NEXTP_MASK;
  1334. ntc >>= IXGBE_RXDADV_NEXTP_SHIFT;
  1335. }
  1336. }
  1337. /* if we are the last buffer then there is nothing else to do */
  1338. if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
  1339. return false;
  1340. /* place skb in next buffer to be received */
  1341. rx_ring->rx_buffer_info[ntc].skb = skb;
  1342. rx_ring->rx_stats.non_eop_descs++;
  1343. return true;
  1344. }
  1345. /**
  1346. * ixgbe_pull_tail - ixgbe specific version of skb_pull_tail
  1347. * @rx_ring: rx descriptor ring packet is being transacted on
  1348. * @skb: pointer to current skb being adjusted
  1349. *
  1350. * This function is an ixgbe specific version of __pskb_pull_tail. The
  1351. * main difference between this version and the original function is that
  1352. * this function can make several assumptions about the state of things
  1353. * that allow for significant optimizations versus the standard function.
  1354. * As a result we can do things like drop a frag and maintain an accurate
  1355. * truesize for the skb.
  1356. */
  1357. static void ixgbe_pull_tail(struct ixgbe_ring *rx_ring,
  1358. struct sk_buff *skb)
  1359. {
  1360. struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
  1361. unsigned char *va;
  1362. unsigned int pull_len;
  1363. /*
  1364. * it is valid to use page_address instead of kmap since we are
  1365. * working with pages allocated out of the lomem pool per
  1366. * alloc_page(GFP_ATOMIC)
  1367. */
  1368. va = skb_frag_address(frag);
  1369. /*
  1370. * we need the header to contain the greater of either ETH_HLEN or
  1371. * 60 bytes if the skb->len is less than 60 for skb_pad.
  1372. */
  1373. pull_len = ixgbe_get_headlen(va, IXGBE_RX_HDR_SIZE);
  1374. /* align pull length to size of long to optimize memcpy performance */
  1375. skb_copy_to_linear_data(skb, va, ALIGN(pull_len, sizeof(long)));
  1376. /* update all of the pointers */
  1377. skb_frag_size_sub(frag, pull_len);
  1378. frag->page_offset += pull_len;
  1379. skb->data_len -= pull_len;
  1380. skb->tail += pull_len;
  1381. }
  1382. /**
  1383. * ixgbe_dma_sync_frag - perform DMA sync for first frag of SKB
  1384. * @rx_ring: rx descriptor ring packet is being transacted on
  1385. * @skb: pointer to current skb being updated
  1386. *
  1387. * This function provides a basic DMA sync up for the first fragment of an
  1388. * skb. The reason for doing this is that the first fragment cannot be
  1389. * unmapped until we have reached the end of packet descriptor for a buffer
  1390. * chain.
  1391. */
  1392. static void ixgbe_dma_sync_frag(struct ixgbe_ring *rx_ring,
  1393. struct sk_buff *skb)
  1394. {
  1395. /* if the page was released unmap it, else just sync our portion */
  1396. if (unlikely(IXGBE_CB(skb)->page_released)) {
  1397. dma_unmap_page(rx_ring->dev, IXGBE_CB(skb)->dma,
  1398. ixgbe_rx_pg_size(rx_ring), DMA_FROM_DEVICE);
  1399. IXGBE_CB(skb)->page_released = false;
  1400. } else {
  1401. struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[0];
  1402. dma_sync_single_range_for_cpu(rx_ring->dev,
  1403. IXGBE_CB(skb)->dma,
  1404. frag->page_offset,
  1405. ixgbe_rx_bufsz(rx_ring),
  1406. DMA_FROM_DEVICE);
  1407. }
  1408. IXGBE_CB(skb)->dma = 0;
  1409. }
  1410. /**
  1411. * ixgbe_cleanup_headers - Correct corrupted or empty headers
  1412. * @rx_ring: rx descriptor ring packet is being transacted on
  1413. * @rx_desc: pointer to the EOP Rx descriptor
  1414. * @skb: pointer to current skb being fixed
  1415. *
  1416. * Check for corrupted packet headers caused by senders on the local L2
  1417. * embedded NIC switch not setting up their Tx Descriptors right. These
  1418. * should be very rare.
  1419. *
  1420. * Also address the case where we are pulling data in on pages only
  1421. * and as such no data is present in the skb header.
  1422. *
  1423. * In addition if skb is not at least 60 bytes we need to pad it so that
  1424. * it is large enough to qualify as a valid Ethernet frame.
  1425. *
  1426. * Returns true if an error was encountered and skb was freed.
  1427. **/
  1428. static bool ixgbe_cleanup_headers(struct ixgbe_ring *rx_ring,
  1429. union ixgbe_adv_rx_desc *rx_desc,
  1430. struct sk_buff *skb)
  1431. {
  1432. struct net_device *netdev = rx_ring->netdev;
  1433. /* verify that the packet does not have any known errors */
  1434. if (unlikely(ixgbe_test_staterr(rx_desc,
  1435. IXGBE_RXDADV_ERR_FRAME_ERR_MASK) &&
  1436. !(netdev->features & NETIF_F_RXALL))) {
  1437. dev_kfree_skb_any(skb);
  1438. return true;
  1439. }
  1440. /* place header in linear portion of buffer */
  1441. if (skb_is_nonlinear(skb))
  1442. ixgbe_pull_tail(rx_ring, skb);
  1443. #ifdef IXGBE_FCOE
  1444. /* do not attempt to pad FCoE Frames as this will disrupt DDP */
  1445. if (ixgbe_rx_is_fcoe(rx_ring, rx_desc))
  1446. return false;
  1447. #endif
  1448. /* if skb_pad returns an error the skb was freed */
  1449. if (unlikely(skb->len < 60)) {
  1450. int pad_len = 60 - skb->len;
  1451. if (skb_pad(skb, pad_len))
  1452. return true;
  1453. __skb_put(skb, pad_len);
  1454. }
  1455. return false;
  1456. }
  1457. /**
  1458. * ixgbe_reuse_rx_page - page flip buffer and store it back on the ring
  1459. * @rx_ring: rx descriptor ring to store buffers on
  1460. * @old_buff: donor buffer to have page reused
  1461. *
  1462. * Synchronizes page for reuse by the adapter
  1463. **/
  1464. static void ixgbe_reuse_rx_page(struct ixgbe_ring *rx_ring,
  1465. struct ixgbe_rx_buffer *old_buff)
  1466. {
  1467. struct ixgbe_rx_buffer *new_buff;
  1468. u16 nta = rx_ring->next_to_alloc;
  1469. new_buff = &rx_ring->rx_buffer_info[nta];
  1470. /* update, and store next to alloc */
  1471. nta++;
  1472. rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0;
  1473. /* transfer page from old buffer to new buffer */
  1474. new_buff->page = old_buff->page;
  1475. new_buff->dma = old_buff->dma;
  1476. new_buff->page_offset = old_buff->page_offset;
  1477. /* sync the buffer for use by the device */
  1478. dma_sync_single_range_for_device(rx_ring->dev, new_buff->dma,
  1479. new_buff->page_offset,
  1480. ixgbe_rx_bufsz(rx_ring),
  1481. DMA_FROM_DEVICE);
  1482. }
  1483. /**
  1484. * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff
  1485. * @rx_ring: rx descriptor ring to transact packets on
  1486. * @rx_buffer: buffer containing page to add
  1487. * @rx_desc: descriptor containing length of buffer written by hardware
  1488. * @skb: sk_buff to place the data into
  1489. *
  1490. * This function will add the data contained in rx_buffer->page to the skb.
  1491. * This is done either through a direct copy if the data in the buffer is
  1492. * less than the skb header size, otherwise it will just attach the page as
  1493. * a frag to the skb.
  1494. *
  1495. * The function will then update the page offset if necessary and return
  1496. * true if the buffer can be reused by the adapter.
  1497. **/
  1498. static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring,
  1499. struct ixgbe_rx_buffer *rx_buffer,
  1500. union ixgbe_adv_rx_desc *rx_desc,
  1501. struct sk_buff *skb)
  1502. {
  1503. struct page *page = rx_buffer->page;
  1504. unsigned int size = le16_to_cpu(rx_desc->wb.upper.length);
  1505. #if (PAGE_SIZE < 8192)
  1506. unsigned int truesize = ixgbe_rx_bufsz(rx_ring);
  1507. #else
  1508. unsigned int truesize = ALIGN(size, L1_CACHE_BYTES);
  1509. unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) -
  1510. ixgbe_rx_bufsz(rx_ring);
  1511. #endif
  1512. if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) {
  1513. unsigned char *va = page_address(page) + rx_buffer->page_offset;
  1514. memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long)));
  1515. /* we can reuse buffer as-is, just make sure it is local */
  1516. if (likely(page_to_nid(page) == numa_node_id()))
  1517. return true;
  1518. /* this page cannot be reused so discard it */
  1519. put_page(page);
  1520. return false;
  1521. }
  1522. skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page,
  1523. rx_buffer->page_offset, size, truesize);
  1524. /* avoid re-using remote pages */
  1525. if (unlikely(page_to_nid(page) != numa_node_id()))
  1526. return false;
  1527. #if (PAGE_SIZE < 8192)
  1528. /* if we are only owner of page we can reuse it */
  1529. if (unlikely(page_count(page) != 1))
  1530. return false;
  1531. /* flip page offset to other buffer */
  1532. rx_buffer->page_offset ^= truesize;
  1533. /*
  1534. * since we are the only owner of the page and we need to
  1535. * increment it, just set the value to 2 in order to avoid
  1536. * an unecessary locked operation
  1537. */
  1538. atomic_set(&page->_count, 2);
  1539. #else
  1540. /* move offset up to the next cache line */
  1541. rx_buffer->page_offset += truesize;
  1542. if (rx_buffer->page_offset > last_offset)
  1543. return false;
  1544. /* bump ref count on page before it is given to the stack */
  1545. get_page(page);
  1546. #endif
  1547. return true;
  1548. }
  1549. static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring,
  1550. union ixgbe_adv_rx_desc *rx_desc)
  1551. {
  1552. struct ixgbe_rx_buffer *rx_buffer;
  1553. struct sk_buff *skb;
  1554. struct page *page;
  1555. rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
  1556. page = rx_buffer->page;
  1557. prefetchw(page);
  1558. skb = rx_buffer->skb;
  1559. if (likely(!skb)) {
  1560. void *page_addr = page_address(page) +
  1561. rx_buffer->page_offset;
  1562. /* prefetch first cache line of first page */
  1563. prefetch(page_addr);
  1564. #if L1_CACHE_BYTES < 128
  1565. prefetch(page_addr + L1_CACHE_BYTES);
  1566. #endif
  1567. /* allocate a skb to store the frags */
  1568. skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
  1569. IXGBE_RX_HDR_SIZE);
  1570. if (unlikely(!skb)) {
  1571. rx_ring->rx_stats.alloc_rx_buff_failed++;
  1572. return NULL;
  1573. }
  1574. /*
  1575. * we will be copying header into skb->data in
  1576. * pskb_may_pull so it is in our interest to prefetch
  1577. * it now to avoid a possible cache miss
  1578. */
  1579. prefetchw(skb->data);
  1580. /*
  1581. * Delay unmapping of the first packet. It carries the
  1582. * header information, HW may still access the header
  1583. * after the writeback. Only unmap it when EOP is
  1584. * reached
  1585. */
  1586. if (likely(ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP)))
  1587. goto dma_sync;
  1588. IXGBE_CB(skb)->dma = rx_buffer->dma;
  1589. } else {
  1590. if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))
  1591. ixgbe_dma_sync_frag(rx_ring, skb);
  1592. dma_sync:
  1593. /* we are reusing so sync this buffer for CPU use */
  1594. dma_sync_single_range_for_cpu(rx_ring->dev,
  1595. rx_buffer->dma,
  1596. rx_buffer->page_offset,
  1597. ixgbe_rx_bufsz(rx_ring),
  1598. DMA_FROM_DEVICE);
  1599. }
  1600. /* pull page into skb */
  1601. if (ixgbe_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
  1602. /* hand second half of page back to the ring */
  1603. ixgbe_reuse_rx_page(rx_ring, rx_buffer);
  1604. } else if (IXGBE_CB(skb)->dma == rx_buffer->dma) {
  1605. /* the page has been released from the ring */
  1606. IXGBE_CB(skb)->page_released = true;
  1607. } else {
  1608. /* we are not reusing the buffer so unmap it */
  1609. dma_unmap_page(rx_ring->dev, rx_buffer->dma,
  1610. ixgbe_rx_pg_size(rx_ring),
  1611. DMA_FROM_DEVICE);
  1612. }
  1613. /* clear contents of buffer_info */
  1614. rx_buffer->skb = NULL;
  1615. rx_buffer->dma = 0;
  1616. rx_buffer->page = NULL;
  1617. return skb;
  1618. }
  1619. /**
  1620. * ixgbe_clean_rx_irq - Clean completed descriptors from Rx ring - bounce buf
  1621. * @q_vector: structure containing interrupt and ring information
  1622. * @rx_ring: rx descriptor ring to transact packets on
  1623. * @budget: Total limit on number of packets to process
  1624. *
  1625. * This function provides a "bounce buffer" approach to Rx interrupt
  1626. * processing. The advantage to this is that on systems that have
  1627. * expensive overhead for IOMMU access this provides a means of avoiding
  1628. * it by maintaining the mapping of the page to the syste.
  1629. *
  1630. * Returns true if all work is completed without reaching budget
  1631. **/
  1632. static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
  1633. struct ixgbe_ring *rx_ring,
  1634. const int budget)
  1635. {
  1636. unsigned int total_rx_bytes = 0, total_rx_packets = 0;
  1637. #ifdef IXGBE_FCOE
  1638. struct ixgbe_adapter *adapter = q_vector->adapter;
  1639. int ddp_bytes;
  1640. unsigned int mss = 0;
  1641. #endif /* IXGBE_FCOE */
  1642. u16 cleaned_count = ixgbe_desc_unused(rx_ring);
  1643. do {
  1644. union ixgbe_adv_rx_desc *rx_desc;
  1645. struct sk_buff *skb;
  1646. /* return some buffers to hardware, one at a time is too slow */
  1647. if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
  1648. ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
  1649. cleaned_count = 0;
  1650. }
  1651. rx_desc = IXGBE_RX_DESC(rx_ring, rx_ring->next_to_clean);
  1652. if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD))
  1653. break;
  1654. /*
  1655. * This memory barrier is needed to keep us from reading
  1656. * any other fields out of the rx_desc until we know the
  1657. * RXD_STAT_DD bit is set
  1658. */
  1659. rmb();
  1660. /* retrieve a buffer from the ring */
  1661. skb = ixgbe_fetch_rx_buffer(rx_ring, rx_desc);
  1662. /* exit if we failed to retrieve a buffer */
  1663. if (!skb)
  1664. break;
  1665. cleaned_count++;
  1666. /* place incomplete frames back on ring for completion */
  1667. if (ixgbe_is_non_eop(rx_ring, rx_desc, skb))
  1668. continue;
  1669. /* verify the packet layout is correct */
  1670. if (ixgbe_cleanup_headers(rx_ring, rx_desc, skb))
  1671. continue;
  1672. /* probably a little skewed due to removing CRC */
  1673. total_rx_bytes += skb->len;
  1674. /* populate checksum, timestamp, VLAN, and protocol */
  1675. ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
  1676. #ifdef IXGBE_FCOE
  1677. /* if ddp, not passing to ULD unless for FCP_RSP or error */
  1678. if (ixgbe_rx_is_fcoe(rx_ring, rx_desc)) {
  1679. ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
  1680. /* include DDPed FCoE data */
  1681. if (ddp_bytes > 0) {
  1682. if (!mss) {
  1683. mss = rx_ring->netdev->mtu -
  1684. sizeof(struct fcoe_hdr) -
  1685. sizeof(struct fc_frame_header) -
  1686. sizeof(struct fcoe_crc_eof);
  1687. if (mss > 512)
  1688. mss &= ~511;
  1689. }
  1690. total_rx_bytes += ddp_bytes;
  1691. total_rx_packets += DIV_ROUND_UP(ddp_bytes,
  1692. mss);
  1693. }
  1694. if (!ddp_bytes) {
  1695. dev_kfree_skb_any(skb);
  1696. continue;
  1697. }
  1698. }
  1699. #endif /* IXGBE_FCOE */
  1700. ixgbe_rx_skb(q_vector, skb);
  1701. /* update budget accounting */
  1702. total_rx_packets++;
  1703. } while (likely(total_rx_packets < budget));
  1704. u64_stats_update_begin(&rx_ring->syncp);
  1705. rx_ring->stats.packets += total_rx_packets;
  1706. rx_ring->stats.bytes += total_rx_bytes;
  1707. u64_stats_update_end(&rx_ring->syncp);
  1708. q_vector->rx.total_packets += total_rx_packets;
  1709. q_vector->rx.total_bytes += total_rx_bytes;
  1710. if (cleaned_count)
  1711. ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
  1712. return (total_rx_packets < budget);
  1713. }
  1714. /**
  1715. * ixgbe_configure_msix - Configure MSI-X hardware
  1716. * @adapter: board private structure
  1717. *
  1718. * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
  1719. * interrupts.
  1720. **/
  1721. static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
  1722. {
  1723. struct ixgbe_q_vector *q_vector;
  1724. int v_idx;
  1725. u32 mask;
  1726. /* Populate MSIX to EITR Select */
  1727. if (adapter->num_vfs > 32) {
  1728. u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
  1729. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
  1730. }
  1731. /*
  1732. * Populate the IVAR table and set the ITR values to the
  1733. * corresponding register.
  1734. */
  1735. for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
  1736. struct ixgbe_ring *ring;
  1737. q_vector = adapter->q_vector[v_idx];
  1738. ixgbe_for_each_ring(ring, q_vector->rx)
  1739. ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
  1740. ixgbe_for_each_ring(ring, q_vector->tx)
  1741. ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
  1742. ixgbe_write_eitr(q_vector);
  1743. }
  1744. switch (adapter->hw.mac.type) {
  1745. case ixgbe_mac_82598EB:
  1746. ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
  1747. v_idx);
  1748. break;
  1749. case ixgbe_mac_82599EB:
  1750. case ixgbe_mac_X540:
  1751. ixgbe_set_ivar(adapter, -1, 1, v_idx);
  1752. break;
  1753. default:
  1754. break;
  1755. }
  1756. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
  1757. /* set up to autoclear timer, and the vectors */
  1758. mask = IXGBE_EIMS_ENABLE_MASK;
  1759. mask &= ~(IXGBE_EIMS_OTHER |
  1760. IXGBE_EIMS_MAILBOX |
  1761. IXGBE_EIMS_LSC);
  1762. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
  1763. }
  1764. enum latency_range {
  1765. lowest_latency = 0,
  1766. low_latency = 1,
  1767. bulk_latency = 2,
  1768. latency_invalid = 255
  1769. };
  1770. /**
  1771. * ixgbe_update_itr - update the dynamic ITR value based on statistics
  1772. * @q_vector: structure containing interrupt and ring information
  1773. * @ring_container: structure containing ring performance data
  1774. *
  1775. * Stores a new ITR value based on packets and byte
  1776. * counts during the last interrupt. The advantage of per interrupt
  1777. * computation is faster updates and more accurate ITR for the current
  1778. * traffic pattern. Constants in this function were computed
  1779. * based on theoretical maximum wire speed and thresholds were set based
  1780. * on testing data as well as attempting to minimize response time
  1781. * while increasing bulk throughput.
  1782. * this functionality is controlled by the InterruptThrottleRate module
  1783. * parameter (see ixgbe_param.c)
  1784. **/
  1785. static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
  1786. struct ixgbe_ring_container *ring_container)
  1787. {
  1788. int bytes = ring_container->total_bytes;
  1789. int packets = ring_container->total_packets;
  1790. u32 timepassed_us;
  1791. u64 bytes_perint;
  1792. u8 itr_setting = ring_container->itr;
  1793. if (packets == 0)
  1794. return;
  1795. /* simple throttlerate management
  1796. * 0-10MB/s lowest (100000 ints/s)
  1797. * 10-20MB/s low (20000 ints/s)
  1798. * 20-1249MB/s bulk (8000 ints/s)
  1799. */
  1800. /* what was last interrupt timeslice? */
  1801. timepassed_us = q_vector->itr >> 2;
  1802. if (timepassed_us == 0)
  1803. return;
  1804. bytes_perint = bytes / timepassed_us; /* bytes/usec */
  1805. switch (itr_setting) {
  1806. case lowest_latency:
  1807. if (bytes_perint > 10)
  1808. itr_setting = low_latency;
  1809. break;
  1810. case low_latency:
  1811. if (bytes_perint > 20)
  1812. itr_setting = bulk_latency;
  1813. else if (bytes_perint <= 10)
  1814. itr_setting = lowest_latency;
  1815. break;
  1816. case bulk_latency:
  1817. if (bytes_perint <= 20)
  1818. itr_setting = low_latency;
  1819. break;
  1820. }
  1821. /* clear work counters since we have the values we need */
  1822. ring_container->total_bytes = 0;
  1823. ring_container->total_packets = 0;
  1824. /* write updated itr to ring container */
  1825. ring_container->itr = itr_setting;
  1826. }
  1827. /**
  1828. * ixgbe_write_eitr - write EITR register in hardware specific way
  1829. * @q_vector: structure containing interrupt and ring information
  1830. *
  1831. * This function is made to be called by ethtool and by the driver
  1832. * when it needs to update EITR registers at runtime. Hardware
  1833. * specific quirks/differences are taken care of here.
  1834. */
  1835. void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
  1836. {
  1837. struct ixgbe_adapter *adapter = q_vector->adapter;
  1838. struct ixgbe_hw *hw = &adapter->hw;
  1839. int v_idx = q_vector->v_idx;
  1840. u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
  1841. switch (adapter->hw.mac.type) {
  1842. case ixgbe_mac_82598EB:
  1843. /* must write high and low 16 bits to reset counter */
  1844. itr_reg |= (itr_reg << 16);
  1845. break;
  1846. case ixgbe_mac_82599EB:
  1847. case ixgbe_mac_X540:
  1848. /*
  1849. * set the WDIS bit to not clear the timer bits and cause an
  1850. * immediate assertion of the interrupt
  1851. */
  1852. itr_reg |= IXGBE_EITR_CNT_WDIS;
  1853. break;
  1854. default:
  1855. break;
  1856. }
  1857. IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
  1858. }
  1859. static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
  1860. {
  1861. u32 new_itr = q_vector->itr;
  1862. u8 current_itr;
  1863. ixgbe_update_itr(q_vector, &q_vector->tx);
  1864. ixgbe_update_itr(q_vector, &q_vector->rx);
  1865. current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
  1866. switch (current_itr) {
  1867. /* counts and packets in update_itr are dependent on these numbers */
  1868. case lowest_latency:
  1869. new_itr = IXGBE_100K_ITR;
  1870. break;
  1871. case low_latency:
  1872. new_itr = IXGBE_20K_ITR;
  1873. break;
  1874. case bulk_latency:
  1875. new_itr = IXGBE_8K_ITR;
  1876. break;
  1877. default:
  1878. break;
  1879. }
  1880. if (new_itr != q_vector->itr) {
  1881. /* do an exponential smoothing */
  1882. new_itr = (10 * new_itr * q_vector->itr) /
  1883. ((9 * new_itr) + q_vector->itr);
  1884. /* save the algorithm value here */
  1885. q_vector->itr = new_itr;
  1886. ixgbe_write_eitr(q_vector);
  1887. }
  1888. }
  1889. /**
  1890. * ixgbe_check_overtemp_subtask - check for over temperature
  1891. * @adapter: pointer to adapter
  1892. **/
  1893. static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
  1894. {
  1895. struct ixgbe_hw *hw = &adapter->hw;
  1896. u32 eicr = adapter->interrupt_event;
  1897. if (test_bit(__IXGBE_DOWN, &adapter->state))
  1898. return;
  1899. if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
  1900. !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
  1901. return;
  1902. adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
  1903. switch (hw->device_id) {
  1904. case IXGBE_DEV_ID_82599_T3_LOM:
  1905. /*
  1906. * Since the warning interrupt is for both ports
  1907. * we don't have to check if:
  1908. * - This interrupt wasn't for our port.
  1909. * - We may have missed the interrupt so always have to
  1910. * check if we got a LSC
  1911. */
  1912. if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
  1913. !(eicr & IXGBE_EICR_LSC))
  1914. return;
  1915. if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
  1916. u32 speed;
  1917. bool link_up = false;
  1918. hw->mac.ops.check_link(hw, &speed, &link_up, false);
  1919. if (link_up)
  1920. return;
  1921. }
  1922. /* Check if this is not due to overtemp */
  1923. if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
  1924. return;
  1925. break;
  1926. default:
  1927. if (!(eicr & IXGBE_EICR_GPI_SDP0))
  1928. return;
  1929. break;
  1930. }
  1931. e_crit(drv,
  1932. "Network adapter has been stopped because it has over heated. "
  1933. "Restart the computer. If the problem persists, "
  1934. "power off the system and replace the adapter\n");
  1935. adapter->interrupt_event = 0;
  1936. }
  1937. static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
  1938. {
  1939. struct ixgbe_hw *hw = &adapter->hw;
  1940. if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
  1941. (eicr & IXGBE_EICR_GPI_SDP1)) {
  1942. e_crit(probe, "Fan has stopped, replace the adapter\n");
  1943. /* write to clear the interrupt */
  1944. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
  1945. }
  1946. }
  1947. static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
  1948. {
  1949. if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
  1950. return;
  1951. switch (adapter->hw.mac.type) {
  1952. case ixgbe_mac_82599EB:
  1953. /*
  1954. * Need to check link state so complete overtemp check
  1955. * on service task
  1956. */
  1957. if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
  1958. (!test_bit(__IXGBE_DOWN, &adapter->state))) {
  1959. adapter->interrupt_event = eicr;
  1960. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
  1961. ixgbe_service_event_schedule(adapter);
  1962. return;
  1963. }
  1964. return;
  1965. case ixgbe_mac_X540:
  1966. if (!(eicr & IXGBE_EICR_TS))
  1967. return;
  1968. break;
  1969. default:
  1970. return;
  1971. }
  1972. e_crit(drv,
  1973. "Network adapter has been stopped because it has over heated. "
  1974. "Restart the computer. If the problem persists, "
  1975. "power off the system and replace the adapter\n");
  1976. }
  1977. static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
  1978. {
  1979. struct ixgbe_hw *hw = &adapter->hw;
  1980. if (eicr & IXGBE_EICR_GPI_SDP2) {
  1981. /* Clear the interrupt */
  1982. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
  1983. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  1984. adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
  1985. ixgbe_service_event_schedule(adapter);
  1986. }
  1987. }
  1988. if (eicr & IXGBE_EICR_GPI_SDP1) {
  1989. /* Clear the interrupt */
  1990. IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
  1991. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  1992. adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
  1993. ixgbe_service_event_schedule(adapter);
  1994. }
  1995. }
  1996. }
  1997. static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
  1998. {
  1999. struct ixgbe_hw *hw = &adapter->hw;
  2000. adapter->lsc_int++;
  2001. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  2002. adapter->link_check_timeout = jiffies;
  2003. if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
  2004. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
  2005. IXGBE_WRITE_FLUSH(hw);
  2006. ixgbe_service_event_schedule(adapter);
  2007. }
  2008. }
  2009. static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
  2010. u64 qmask)
  2011. {
  2012. u32 mask;
  2013. struct ixgbe_hw *hw = &adapter->hw;
  2014. switch (hw->mac.type) {
  2015. case ixgbe_mac_82598EB:
  2016. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  2017. IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
  2018. break;
  2019. case ixgbe_mac_82599EB:
  2020. case ixgbe_mac_X540:
  2021. mask = (qmask & 0xFFFFFFFF);
  2022. if (mask)
  2023. IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
  2024. mask = (qmask >> 32);
  2025. if (mask)
  2026. IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
  2027. break;
  2028. default:
  2029. break;
  2030. }
  2031. /* skip the flush */
  2032. }
  2033. static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
  2034. u64 qmask)
  2035. {
  2036. u32 mask;
  2037. struct ixgbe_hw *hw = &adapter->hw;
  2038. switch (hw->mac.type) {
  2039. case ixgbe_mac_82598EB:
  2040. mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
  2041. IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
  2042. break;
  2043. case ixgbe_mac_82599EB:
  2044. case ixgbe_mac_X540:
  2045. mask = (qmask & 0xFFFFFFFF);
  2046. if (mask)
  2047. IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
  2048. mask = (qmask >> 32);
  2049. if (mask)
  2050. IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
  2051. break;
  2052. default:
  2053. break;
  2054. }
  2055. /* skip the flush */
  2056. }
  2057. /**
  2058. * ixgbe_irq_enable - Enable default interrupt generation settings
  2059. * @adapter: board private structure
  2060. **/
  2061. static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
  2062. bool flush)
  2063. {
  2064. u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
  2065. /* don't reenable LSC while waiting for link */
  2066. if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
  2067. mask &= ~IXGBE_EIMS_LSC;
  2068. if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
  2069. switch (adapter->hw.mac.type) {
  2070. case ixgbe_mac_82599EB:
  2071. mask |= IXGBE_EIMS_GPI_SDP0;
  2072. break;
  2073. case ixgbe_mac_X540:
  2074. mask |= IXGBE_EIMS_TS;
  2075. break;
  2076. default:
  2077. break;
  2078. }
  2079. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
  2080. mask |= IXGBE_EIMS_GPI_SDP1;
  2081. switch (adapter->hw.mac.type) {
  2082. case ixgbe_mac_82599EB:
  2083. mask |= IXGBE_EIMS_GPI_SDP1;
  2084. mask |= IXGBE_EIMS_GPI_SDP2;
  2085. case ixgbe_mac_X540:
  2086. mask |= IXGBE_EIMS_ECC;
  2087. mask |= IXGBE_EIMS_MAILBOX;
  2088. break;
  2089. default:
  2090. break;
  2091. }
  2092. if (adapter->hw.mac.type == ixgbe_mac_X540)
  2093. mask |= IXGBE_EIMS_TIMESYNC;
  2094. if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
  2095. !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
  2096. mask |= IXGBE_EIMS_FLOW_DIR;
  2097. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
  2098. if (queues)
  2099. ixgbe_irq_enable_queues(adapter, ~0);
  2100. if (flush)
  2101. IXGBE_WRITE_FLUSH(&adapter->hw);
  2102. }
  2103. static irqreturn_t ixgbe_msix_other(int irq, void *data)
  2104. {
  2105. struct ixgbe_adapter *adapter = data;
  2106. struct ixgbe_hw *hw = &adapter->hw;
  2107. u32 eicr;
  2108. /*
  2109. * Workaround for Silicon errata. Use clear-by-write instead
  2110. * of clear-by-read. Reading with EICS will return the
  2111. * interrupt causes without clearing, which later be done
  2112. * with the write to EICR.
  2113. */
  2114. eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
  2115. /* The lower 16bits of the EICR register are for the queue interrupts
  2116. * which should be masked here in order to not accidently clear them if
  2117. * the bits are high when ixgbe_msix_other is called. There is a race
  2118. * condition otherwise which results in possible performance loss
  2119. * especially if the ixgbe_msix_other interrupt is triggering
  2120. * consistently (as it would when PPS is turned on for the X540 device)
  2121. */
  2122. eicr &= 0xFFFF0000;
  2123. IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
  2124. if (eicr & IXGBE_EICR_LSC)
  2125. ixgbe_check_lsc(adapter);
  2126. if (eicr & IXGBE_EICR_MAILBOX)
  2127. ixgbe_msg_task(adapter);
  2128. switch (hw->mac.type) {
  2129. case ixgbe_mac_82599EB:
  2130. case ixgbe_mac_X540:
  2131. if (eicr & IXGBE_EICR_ECC)
  2132. e_info(link, "Received unrecoverable ECC Err, please "
  2133. "reboot\n");
  2134. /* Handle Flow Director Full threshold interrupt */
  2135. if (eicr & IXGBE_EICR_FLOW_DIR) {
  2136. int reinit_count = 0;
  2137. int i;
  2138. for (i = 0; i < adapter->num_tx_queues; i++) {
  2139. struct ixgbe_ring *ring = adapter->tx_ring[i];
  2140. if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
  2141. &ring->state))
  2142. reinit_count++;
  2143. }
  2144. if (reinit_count) {
  2145. /* no more flow director interrupts until after init */
  2146. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
  2147. adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
  2148. ixgbe_service_event_schedule(adapter);
  2149. }
  2150. }
  2151. ixgbe_check_sfp_event(adapter, eicr);
  2152. ixgbe_check_overtemp_event(adapter, eicr);
  2153. break;
  2154. default:
  2155. break;
  2156. }
  2157. ixgbe_check_fan_failure(adapter, eicr);
  2158. if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
  2159. ixgbe_ptp_check_pps_event(adapter, eicr);
  2160. /* re-enable the original interrupt state, no lsc, no queues */
  2161. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2162. ixgbe_irq_enable(adapter, false, false);
  2163. return IRQ_HANDLED;
  2164. }
  2165. static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
  2166. {
  2167. struct ixgbe_q_vector *q_vector = data;
  2168. /* EIAM disabled interrupts (on this vector) for us */
  2169. if (q_vector->rx.ring || q_vector->tx.ring)
  2170. napi_schedule(&q_vector->napi);
  2171. return IRQ_HANDLED;
  2172. }
  2173. /**
  2174. * ixgbe_poll - NAPI Rx polling callback
  2175. * @napi: structure for representing this polling device
  2176. * @budget: how many packets driver is allowed to clean
  2177. *
  2178. * This function is used for legacy and MSI, NAPI mode
  2179. **/
  2180. int ixgbe_poll(struct napi_struct *napi, int budget)
  2181. {
  2182. struct ixgbe_q_vector *q_vector =
  2183. container_of(napi, struct ixgbe_q_vector, napi);
  2184. struct ixgbe_adapter *adapter = q_vector->adapter;
  2185. struct ixgbe_ring *ring;
  2186. int per_ring_budget;
  2187. bool clean_complete = true;
  2188. #ifdef CONFIG_IXGBE_DCA
  2189. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
  2190. ixgbe_update_dca(q_vector);
  2191. #endif
  2192. ixgbe_for_each_ring(ring, q_vector->tx)
  2193. clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
  2194. /* attempt to distribute budget to each queue fairly, but don't allow
  2195. * the budget to go below 1 because we'll exit polling */
  2196. if (q_vector->rx.count > 1)
  2197. per_ring_budget = max(budget/q_vector->rx.count, 1);
  2198. else
  2199. per_ring_budget = budget;
  2200. ixgbe_for_each_ring(ring, q_vector->rx)
  2201. clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
  2202. per_ring_budget);
  2203. /* If all work not completed, return budget and keep polling */
  2204. if (!clean_complete)
  2205. return budget;
  2206. /* all work done, exit the polling mode */
  2207. napi_complete(napi);
  2208. if (adapter->rx_itr_setting & 1)
  2209. ixgbe_set_itr(q_vector);
  2210. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2211. ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
  2212. return 0;
  2213. }
  2214. /**
  2215. * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
  2216. * @adapter: board private structure
  2217. *
  2218. * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
  2219. * interrupts from the kernel.
  2220. **/
  2221. static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
  2222. {
  2223. struct net_device *netdev = adapter->netdev;
  2224. int vector, err;
  2225. int ri = 0, ti = 0;
  2226. for (vector = 0; vector < adapter->num_q_vectors; vector++) {
  2227. struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
  2228. struct msix_entry *entry = &adapter->msix_entries[vector];
  2229. if (q_vector->tx.ring && q_vector->rx.ring) {
  2230. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2231. "%s-%s-%d", netdev->name, "TxRx", ri++);
  2232. ti++;
  2233. } else if (q_vector->rx.ring) {
  2234. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2235. "%s-%s-%d", netdev->name, "rx", ri++);
  2236. } else if (q_vector->tx.ring) {
  2237. snprintf(q_vector->name, sizeof(q_vector->name) - 1,
  2238. "%s-%s-%d", netdev->name, "tx", ti++);
  2239. } else {
  2240. /* skip this unused q_vector */
  2241. continue;
  2242. }
  2243. err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
  2244. q_vector->name, q_vector);
  2245. if (err) {
  2246. e_err(probe, "request_irq failed for MSIX interrupt "
  2247. "Error: %d\n", err);
  2248. goto free_queue_irqs;
  2249. }
  2250. /* If Flow Director is enabled, set interrupt affinity */
  2251. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  2252. /* assign the mask for this irq */
  2253. irq_set_affinity_hint(entry->vector,
  2254. &q_vector->affinity_mask);
  2255. }
  2256. }
  2257. err = request_irq(adapter->msix_entries[vector].vector,
  2258. ixgbe_msix_other, 0, netdev->name, adapter);
  2259. if (err) {
  2260. e_err(probe, "request_irq for msix_other failed: %d\n", err);
  2261. goto free_queue_irqs;
  2262. }
  2263. return 0;
  2264. free_queue_irqs:
  2265. while (vector) {
  2266. vector--;
  2267. irq_set_affinity_hint(adapter->msix_entries[vector].vector,
  2268. NULL);
  2269. free_irq(adapter->msix_entries[vector].vector,
  2270. adapter->q_vector[vector]);
  2271. }
  2272. adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
  2273. pci_disable_msix(adapter->pdev);
  2274. kfree(adapter->msix_entries);
  2275. adapter->msix_entries = NULL;
  2276. return err;
  2277. }
  2278. /**
  2279. * ixgbe_intr - legacy mode Interrupt Handler
  2280. * @irq: interrupt number
  2281. * @data: pointer to a network interface device structure
  2282. **/
  2283. static irqreturn_t ixgbe_intr(int irq, void *data)
  2284. {
  2285. struct ixgbe_adapter *adapter = data;
  2286. struct ixgbe_hw *hw = &adapter->hw;
  2287. struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
  2288. u32 eicr;
  2289. /*
  2290. * Workaround for silicon errata #26 on 82598. Mask the interrupt
  2291. * before the read of EICR.
  2292. */
  2293. IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
  2294. /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
  2295. * therefore no explicit interrupt disable is necessary */
  2296. eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
  2297. if (!eicr) {
  2298. /*
  2299. * shared interrupt alert!
  2300. * make sure interrupts are enabled because the read will
  2301. * have disabled interrupts due to EIAM
  2302. * finish the workaround of silicon errata on 82598. Unmask
  2303. * the interrupt that we masked before the EICR read.
  2304. */
  2305. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2306. ixgbe_irq_enable(adapter, true, true);
  2307. return IRQ_NONE; /* Not our interrupt */
  2308. }
  2309. if (eicr & IXGBE_EICR_LSC)
  2310. ixgbe_check_lsc(adapter);
  2311. switch (hw->mac.type) {
  2312. case ixgbe_mac_82599EB:
  2313. ixgbe_check_sfp_event(adapter, eicr);
  2314. /* Fall through */
  2315. case ixgbe_mac_X540:
  2316. if (eicr & IXGBE_EICR_ECC)
  2317. e_info(link, "Received unrecoverable ECC err, please "
  2318. "reboot\n");
  2319. ixgbe_check_overtemp_event(adapter, eicr);
  2320. break;
  2321. default:
  2322. break;
  2323. }
  2324. ixgbe_check_fan_failure(adapter, eicr);
  2325. if (unlikely(eicr & IXGBE_EICR_TIMESYNC))
  2326. ixgbe_ptp_check_pps_event(adapter, eicr);
  2327. /* would disable interrupts here but EIAM disabled it */
  2328. napi_schedule(&q_vector->napi);
  2329. /*
  2330. * re-enable link(maybe) and non-queue interrupts, no flush.
  2331. * ixgbe_poll will re-enable the queue interrupts
  2332. */
  2333. if (!test_bit(__IXGBE_DOWN, &adapter->state))
  2334. ixgbe_irq_enable(adapter, false, false);
  2335. return IRQ_HANDLED;
  2336. }
  2337. /**
  2338. * ixgbe_request_irq - initialize interrupts
  2339. * @adapter: board private structure
  2340. *
  2341. * Attempts to configure interrupts using the best available
  2342. * capabilities of the hardware and kernel.
  2343. **/
  2344. static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
  2345. {
  2346. struct net_device *netdev = adapter->netdev;
  2347. int err;
  2348. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  2349. err = ixgbe_request_msix_irqs(adapter);
  2350. else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
  2351. err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
  2352. netdev->name, adapter);
  2353. else
  2354. err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
  2355. netdev->name, adapter);
  2356. if (err)
  2357. e_err(probe, "request_irq failed, Error %d\n", err);
  2358. return err;
  2359. }
  2360. static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
  2361. {
  2362. int vector;
  2363. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
  2364. free_irq(adapter->pdev->irq, adapter);
  2365. return;
  2366. }
  2367. for (vector = 0; vector < adapter->num_q_vectors; vector++) {
  2368. struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
  2369. struct msix_entry *entry = &adapter->msix_entries[vector];
  2370. /* free only the irqs that were actually requested */
  2371. if (!q_vector->rx.ring && !q_vector->tx.ring)
  2372. continue;
  2373. /* clear the affinity_mask in the IRQ descriptor */
  2374. irq_set_affinity_hint(entry->vector, NULL);
  2375. free_irq(entry->vector, q_vector);
  2376. }
  2377. free_irq(adapter->msix_entries[vector++].vector, adapter);
  2378. }
  2379. /**
  2380. * ixgbe_irq_disable - Mask off interrupt generation on the NIC
  2381. * @adapter: board private structure
  2382. **/
  2383. static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
  2384. {
  2385. switch (adapter->hw.mac.type) {
  2386. case ixgbe_mac_82598EB:
  2387. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
  2388. break;
  2389. case ixgbe_mac_82599EB:
  2390. case ixgbe_mac_X540:
  2391. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
  2392. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
  2393. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
  2394. break;
  2395. default:
  2396. break;
  2397. }
  2398. IXGBE_WRITE_FLUSH(&adapter->hw);
  2399. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  2400. int vector;
  2401. for (vector = 0; vector < adapter->num_q_vectors; vector++)
  2402. synchronize_irq(adapter->msix_entries[vector].vector);
  2403. synchronize_irq(adapter->msix_entries[vector++].vector);
  2404. } else {
  2405. synchronize_irq(adapter->pdev->irq);
  2406. }
  2407. }
  2408. /**
  2409. * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
  2410. *
  2411. **/
  2412. static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
  2413. {
  2414. struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
  2415. ixgbe_write_eitr(q_vector);
  2416. ixgbe_set_ivar(adapter, 0, 0, 0);
  2417. ixgbe_set_ivar(adapter, 1, 0, 0);
  2418. e_info(hw, "Legacy interrupt IVAR setup done\n");
  2419. }
  2420. /**
  2421. * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
  2422. * @adapter: board private structure
  2423. * @ring: structure containing ring specific data
  2424. *
  2425. * Configure the Tx descriptor ring after a reset.
  2426. **/
  2427. void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
  2428. struct ixgbe_ring *ring)
  2429. {
  2430. struct ixgbe_hw *hw = &adapter->hw;
  2431. u64 tdba = ring->dma;
  2432. int wait_loop = 10;
  2433. u32 txdctl = IXGBE_TXDCTL_ENABLE;
  2434. u8 reg_idx = ring->reg_idx;
  2435. /* disable queue to avoid issues while updating state */
  2436. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
  2437. IXGBE_WRITE_FLUSH(hw);
  2438. IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
  2439. (tdba & DMA_BIT_MASK(32)));
  2440. IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
  2441. IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
  2442. ring->count * sizeof(union ixgbe_adv_tx_desc));
  2443. IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
  2444. IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
  2445. ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
  2446. /*
  2447. * set WTHRESH to encourage burst writeback, it should not be set
  2448. * higher than 1 when:
  2449. * - ITR is 0 as it could cause false TX hangs
  2450. * - ITR is set to > 100k int/sec and BQL is enabled
  2451. *
  2452. * In order to avoid issues WTHRESH + PTHRESH should always be equal
  2453. * to or less than the number of on chip descriptors, which is
  2454. * currently 40.
  2455. */
  2456. #if IS_ENABLED(CONFIG_BQL)
  2457. if (!ring->q_vector || (ring->q_vector->itr < IXGBE_100K_ITR))
  2458. #else
  2459. if (!ring->q_vector || (ring->q_vector->itr < 8))
  2460. #endif
  2461. txdctl |= (1 << 16); /* WTHRESH = 1 */
  2462. else
  2463. txdctl |= (8 << 16); /* WTHRESH = 8 */
  2464. /*
  2465. * Setting PTHRESH to 32 both improves performance
  2466. * and avoids a TX hang with DFP enabled
  2467. */
  2468. txdctl |= (1 << 8) | /* HTHRESH = 1 */
  2469. 32; /* PTHRESH = 32 */
  2470. /* reinitialize flowdirector state */
  2471. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  2472. ring->atr_sample_rate = adapter->atr_sample_rate;
  2473. ring->atr_count = 0;
  2474. set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
  2475. } else {
  2476. ring->atr_sample_rate = 0;
  2477. }
  2478. /* initialize XPS */
  2479. if (!test_and_set_bit(__IXGBE_TX_XPS_INIT_DONE, &ring->state)) {
  2480. struct ixgbe_q_vector *q_vector = ring->q_vector;
  2481. if (q_vector)
  2482. netif_set_xps_queue(adapter->netdev,
  2483. &q_vector->affinity_mask,
  2484. ring->queue_index);
  2485. }
  2486. clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
  2487. /* enable queue */
  2488. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
  2489. /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
  2490. if (hw->mac.type == ixgbe_mac_82598EB &&
  2491. !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  2492. return;
  2493. /* poll to verify queue is enabled */
  2494. do {
  2495. usleep_range(1000, 2000);
  2496. txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
  2497. } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
  2498. if (!wait_loop)
  2499. e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
  2500. }
  2501. static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
  2502. {
  2503. struct ixgbe_hw *hw = &adapter->hw;
  2504. u32 rttdcs, mtqc;
  2505. u8 tcs = netdev_get_num_tc(adapter->netdev);
  2506. if (hw->mac.type == ixgbe_mac_82598EB)
  2507. return;
  2508. /* disable the arbiter while setting MTQC */
  2509. rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
  2510. rttdcs |= IXGBE_RTTDCS_ARBDIS;
  2511. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
  2512. /* set transmit pool layout */
  2513. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  2514. mtqc = IXGBE_MTQC_VT_ENA;
  2515. if (tcs > 4)
  2516. mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
  2517. else if (tcs > 1)
  2518. mtqc |= IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
  2519. else if (adapter->ring_feature[RING_F_RSS].indices == 4)
  2520. mtqc |= IXGBE_MTQC_32VF;
  2521. else
  2522. mtqc |= IXGBE_MTQC_64VF;
  2523. } else {
  2524. if (tcs > 4)
  2525. mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
  2526. else if (tcs > 1)
  2527. mtqc = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
  2528. else
  2529. mtqc = IXGBE_MTQC_64Q_1PB;
  2530. }
  2531. IXGBE_WRITE_REG(hw, IXGBE_MTQC, mtqc);
  2532. /* Enable Security TX Buffer IFG for multiple pb */
  2533. if (tcs) {
  2534. u32 sectx = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
  2535. sectx |= IXGBE_SECTX_DCB;
  2536. IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, sectx);
  2537. }
  2538. /* re-enable the arbiter */
  2539. rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
  2540. IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
  2541. }
  2542. /**
  2543. * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
  2544. * @adapter: board private structure
  2545. *
  2546. * Configure the Tx unit of the MAC after a reset.
  2547. **/
  2548. static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
  2549. {
  2550. struct ixgbe_hw *hw = &adapter->hw;
  2551. u32 dmatxctl;
  2552. u32 i;
  2553. ixgbe_setup_mtqc(adapter);
  2554. if (hw->mac.type != ixgbe_mac_82598EB) {
  2555. /* DMATXCTL.EN must be before Tx queues are enabled */
  2556. dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
  2557. dmatxctl |= IXGBE_DMATXCTL_TE;
  2558. IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
  2559. }
  2560. /* Setup the HW Tx Head and Tail descriptor pointers */
  2561. for (i = 0; i < adapter->num_tx_queues; i++)
  2562. ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
  2563. }
  2564. static void ixgbe_enable_rx_drop(struct ixgbe_adapter *adapter,
  2565. struct ixgbe_ring *ring)
  2566. {
  2567. struct ixgbe_hw *hw = &adapter->hw;
  2568. u8 reg_idx = ring->reg_idx;
  2569. u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
  2570. srrctl |= IXGBE_SRRCTL_DROP_EN;
  2571. IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
  2572. }
  2573. static void ixgbe_disable_rx_drop(struct ixgbe_adapter *adapter,
  2574. struct ixgbe_ring *ring)
  2575. {
  2576. struct ixgbe_hw *hw = &adapter->hw;
  2577. u8 reg_idx = ring->reg_idx;
  2578. u32 srrctl = IXGBE_READ_REG(hw, IXGBE_SRRCTL(reg_idx));
  2579. srrctl &= ~IXGBE_SRRCTL_DROP_EN;
  2580. IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
  2581. }
  2582. #ifdef CONFIG_IXGBE_DCB
  2583. void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
  2584. #else
  2585. static void ixgbe_set_rx_drop_en(struct ixgbe_adapter *adapter)
  2586. #endif
  2587. {
  2588. int i;
  2589. bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
  2590. if (adapter->ixgbe_ieee_pfc)
  2591. pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
  2592. /*
  2593. * We should set the drop enable bit if:
  2594. * SR-IOV is enabled
  2595. * or
  2596. * Number of Rx queues > 1 and flow control is disabled
  2597. *
  2598. * This allows us to avoid head of line blocking for security
  2599. * and performance reasons.
  2600. */
  2601. if (adapter->num_vfs || (adapter->num_rx_queues > 1 &&
  2602. !(adapter->hw.fc.current_mode & ixgbe_fc_tx_pause) && !pfc_en)) {
  2603. for (i = 0; i < adapter->num_rx_queues; i++)
  2604. ixgbe_enable_rx_drop(adapter, adapter->rx_ring[i]);
  2605. } else {
  2606. for (i = 0; i < adapter->num_rx_queues; i++)
  2607. ixgbe_disable_rx_drop(adapter, adapter->rx_ring[i]);
  2608. }
  2609. }
  2610. #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
  2611. static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
  2612. struct ixgbe_ring *rx_ring)
  2613. {
  2614. struct ixgbe_hw *hw = &adapter->hw;
  2615. u32 srrctl;
  2616. u8 reg_idx = rx_ring->reg_idx;
  2617. if (hw->mac.type == ixgbe_mac_82598EB) {
  2618. u16 mask = adapter->ring_feature[RING_F_RSS].mask;
  2619. /*
  2620. * if VMDq is not active we must program one srrctl register
  2621. * per RSS queue since we have enabled RDRXCTL.MVMEN
  2622. */
  2623. reg_idx &= mask;
  2624. }
  2625. /* configure header buffer length, needed for RSC */
  2626. srrctl = IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT;
  2627. /* configure the packet buffer length */
  2628. srrctl |= ixgbe_rx_bufsz(rx_ring) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
  2629. /* configure descriptor type */
  2630. srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
  2631. IXGBE_WRITE_REG(hw, IXGBE_SRRCTL(reg_idx), srrctl);
  2632. }
  2633. static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
  2634. {
  2635. struct ixgbe_hw *hw = &adapter->hw;
  2636. static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
  2637. 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
  2638. 0x6A3E67EA, 0x14364D17, 0x3BED200D};
  2639. u32 mrqc = 0, reta = 0;
  2640. u32 rxcsum;
  2641. int i, j;
  2642. u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
  2643. /*
  2644. * Program table for at least 2 queues w/ SR-IOV so that VFs can
  2645. * make full use of any rings they may have. We will use the
  2646. * PSRTYPE register to control how many rings we use within the PF.
  2647. */
  2648. if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) && (rss_i < 2))
  2649. rss_i = 2;
  2650. /* Fill out hash function seeds */
  2651. for (i = 0; i < 10; i++)
  2652. IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
  2653. /* Fill out redirection table */
  2654. for (i = 0, j = 0; i < 128; i++, j++) {
  2655. if (j == rss_i)
  2656. j = 0;
  2657. /* reta = 4-byte sliding window of
  2658. * 0x00..(indices-1)(indices-1)00..etc. */
  2659. reta = (reta << 8) | (j * 0x11);
  2660. if ((i & 3) == 3)
  2661. IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
  2662. }
  2663. /* Disable indicating checksum in descriptor, enables RSS hash */
  2664. rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
  2665. rxcsum |= IXGBE_RXCSUM_PCSD;
  2666. IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
  2667. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  2668. if (adapter->ring_feature[RING_F_RSS].mask)
  2669. mrqc = IXGBE_MRQC_RSSEN;
  2670. } else {
  2671. u8 tcs = netdev_get_num_tc(adapter->netdev);
  2672. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  2673. if (tcs > 4)
  2674. mrqc = IXGBE_MRQC_VMDQRT8TCEN; /* 8 TCs */
  2675. else if (tcs > 1)
  2676. mrqc = IXGBE_MRQC_VMDQRT4TCEN; /* 4 TCs */
  2677. else if (adapter->ring_feature[RING_F_RSS].indices == 4)
  2678. mrqc = IXGBE_MRQC_VMDQRSS32EN;
  2679. else
  2680. mrqc = IXGBE_MRQC_VMDQRSS64EN;
  2681. } else {
  2682. if (tcs > 4)
  2683. mrqc = IXGBE_MRQC_RTRSS8TCEN;
  2684. else if (tcs > 1)
  2685. mrqc = IXGBE_MRQC_RTRSS4TCEN;
  2686. else
  2687. mrqc = IXGBE_MRQC_RSSEN;
  2688. }
  2689. }
  2690. /* Perform hash on these packet types */
  2691. mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
  2692. IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
  2693. IXGBE_MRQC_RSS_FIELD_IPV6 |
  2694. IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
  2695. if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV4_UDP)
  2696. mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4_UDP;
  2697. if (adapter->flags2 & IXGBE_FLAG2_RSS_FIELD_IPV6_UDP)
  2698. mrqc |= IXGBE_MRQC_RSS_FIELD_IPV6_UDP;
  2699. IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
  2700. }
  2701. /**
  2702. * ixgbe_configure_rscctl - enable RSC for the indicated ring
  2703. * @adapter: address of board private structure
  2704. * @index: index of ring to set
  2705. **/
  2706. static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
  2707. struct ixgbe_ring *ring)
  2708. {
  2709. struct ixgbe_hw *hw = &adapter->hw;
  2710. u32 rscctrl;
  2711. u8 reg_idx = ring->reg_idx;
  2712. if (!ring_is_rsc_enabled(ring))
  2713. return;
  2714. rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
  2715. rscctrl |= IXGBE_RSCCTL_RSCEN;
  2716. /*
  2717. * we must limit the number of descriptors so that the
  2718. * total size of max desc * buf_len is not greater
  2719. * than 65536
  2720. */
  2721. rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
  2722. IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
  2723. }
  2724. #define IXGBE_MAX_RX_DESC_POLL 10
  2725. static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
  2726. struct ixgbe_ring *ring)
  2727. {
  2728. struct ixgbe_hw *hw = &adapter->hw;
  2729. int wait_loop = IXGBE_MAX_RX_DESC_POLL;
  2730. u32 rxdctl;
  2731. u8 reg_idx = ring->reg_idx;
  2732. /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
  2733. if (hw->mac.type == ixgbe_mac_82598EB &&
  2734. !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  2735. return;
  2736. do {
  2737. usleep_range(1000, 2000);
  2738. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  2739. } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
  2740. if (!wait_loop) {
  2741. e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
  2742. "the polling period\n", reg_idx);
  2743. }
  2744. }
  2745. void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
  2746. struct ixgbe_ring *ring)
  2747. {
  2748. struct ixgbe_hw *hw = &adapter->hw;
  2749. int wait_loop = IXGBE_MAX_RX_DESC_POLL;
  2750. u32 rxdctl;
  2751. u8 reg_idx = ring->reg_idx;
  2752. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  2753. rxdctl &= ~IXGBE_RXDCTL_ENABLE;
  2754. /* write value back with RXDCTL.ENABLE bit cleared */
  2755. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
  2756. if (hw->mac.type == ixgbe_mac_82598EB &&
  2757. !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
  2758. return;
  2759. /* the hardware may take up to 100us to really disable the rx queue */
  2760. do {
  2761. udelay(10);
  2762. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  2763. } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
  2764. if (!wait_loop) {
  2765. e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
  2766. "the polling period\n", reg_idx);
  2767. }
  2768. }
  2769. void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
  2770. struct ixgbe_ring *ring)
  2771. {
  2772. struct ixgbe_hw *hw = &adapter->hw;
  2773. u64 rdba = ring->dma;
  2774. u32 rxdctl;
  2775. u8 reg_idx = ring->reg_idx;
  2776. /* disable queue to avoid issues while updating state */
  2777. rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
  2778. ixgbe_disable_rx_queue(adapter, ring);
  2779. IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
  2780. IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
  2781. IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
  2782. ring->count * sizeof(union ixgbe_adv_rx_desc));
  2783. IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
  2784. IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
  2785. ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
  2786. ixgbe_configure_srrctl(adapter, ring);
  2787. ixgbe_configure_rscctl(adapter, ring);
  2788. if (hw->mac.type == ixgbe_mac_82598EB) {
  2789. /*
  2790. * enable cache line friendly hardware writes:
  2791. * PTHRESH=32 descriptors (half the internal cache),
  2792. * this also removes ugly rx_no_buffer_count increment
  2793. * HTHRESH=4 descriptors (to minimize latency on fetch)
  2794. * WTHRESH=8 burst writeback up to two cache lines
  2795. */
  2796. rxdctl &= ~0x3FFFFF;
  2797. rxdctl |= 0x080420;
  2798. }
  2799. /* enable receive descriptor ring */
  2800. rxdctl |= IXGBE_RXDCTL_ENABLE;
  2801. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
  2802. ixgbe_rx_desc_queue_enable(adapter, ring);
  2803. ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
  2804. }
  2805. static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
  2806. {
  2807. struct ixgbe_hw *hw = &adapter->hw;
  2808. int rss_i = adapter->ring_feature[RING_F_RSS].indices;
  2809. int p;
  2810. /* PSRTYPE must be initialized in non 82598 adapters */
  2811. u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
  2812. IXGBE_PSRTYPE_UDPHDR |
  2813. IXGBE_PSRTYPE_IPV4HDR |
  2814. IXGBE_PSRTYPE_L2HDR |
  2815. IXGBE_PSRTYPE_IPV6HDR;
  2816. if (hw->mac.type == ixgbe_mac_82598EB)
  2817. return;
  2818. if (rss_i > 3)
  2819. psrtype |= 2 << 29;
  2820. else if (rss_i > 1)
  2821. psrtype |= 1 << 29;
  2822. for (p = 0; p < adapter->num_rx_pools; p++)
  2823. IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(VMDQ_P(p)),
  2824. psrtype);
  2825. }
  2826. static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
  2827. {
  2828. struct ixgbe_hw *hw = &adapter->hw;
  2829. u32 reg_offset, vf_shift;
  2830. u32 gcr_ext, vmdctl;
  2831. int i;
  2832. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  2833. return;
  2834. vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
  2835. vmdctl |= IXGBE_VMD_CTL_VMDQ_EN;
  2836. vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
  2837. vmdctl |= VMDQ_P(0) << IXGBE_VT_CTL_POOL_SHIFT;
  2838. vmdctl |= IXGBE_VT_CTL_REPLEN;
  2839. IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
  2840. vf_shift = VMDQ_P(0) % 32;
  2841. reg_offset = (VMDQ_P(0) >= 32) ? 1 : 0;
  2842. /* Enable only the PF's pool for Tx/Rx */
  2843. IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (~0) << vf_shift);
  2844. IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), reg_offset - 1);
  2845. IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (~0) << vf_shift);
  2846. IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), reg_offset - 1);
  2847. if (adapter->flags2 & IXGBE_FLAG2_BRIDGE_MODE_VEB)
  2848. IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
  2849. /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
  2850. hw->mac.ops.set_vmdq(hw, 0, VMDQ_P(0));
  2851. /*
  2852. * Set up VF register offsets for selected VT Mode,
  2853. * i.e. 32 or 64 VFs for SR-IOV
  2854. */
  2855. switch (adapter->ring_feature[RING_F_VMDQ].mask) {
  2856. case IXGBE_82599_VMDQ_8Q_MASK:
  2857. gcr_ext = IXGBE_GCR_EXT_VT_MODE_16;
  2858. break;
  2859. case IXGBE_82599_VMDQ_4Q_MASK:
  2860. gcr_ext = IXGBE_GCR_EXT_VT_MODE_32;
  2861. break;
  2862. default:
  2863. gcr_ext = IXGBE_GCR_EXT_VT_MODE_64;
  2864. break;
  2865. }
  2866. IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
  2867. /* Enable MAC Anti-Spoofing */
  2868. hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0),
  2869. adapter->num_vfs);
  2870. /* For VFs that have spoof checking turned off */
  2871. for (i = 0; i < adapter->num_vfs; i++) {
  2872. if (!adapter->vfinfo[i].spoofchk_enabled)
  2873. ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
  2874. }
  2875. }
  2876. static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
  2877. {
  2878. struct ixgbe_hw *hw = &adapter->hw;
  2879. struct net_device *netdev = adapter->netdev;
  2880. int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  2881. struct ixgbe_ring *rx_ring;
  2882. int i;
  2883. u32 mhadd, hlreg0;
  2884. #ifdef IXGBE_FCOE
  2885. /* adjust max frame to be able to do baby jumbo for FCoE */
  2886. if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
  2887. (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
  2888. max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
  2889. #endif /* IXGBE_FCOE */
  2890. /* adjust max frame to be at least the size of a standard frame */
  2891. if (max_frame < (ETH_FRAME_LEN + ETH_FCS_LEN))
  2892. max_frame = (ETH_FRAME_LEN + ETH_FCS_LEN);
  2893. mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
  2894. if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
  2895. mhadd &= ~IXGBE_MHADD_MFS_MASK;
  2896. mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
  2897. IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
  2898. }
  2899. hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
  2900. /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
  2901. hlreg0 |= IXGBE_HLREG0_JUMBOEN;
  2902. IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
  2903. /*
  2904. * Setup the HW Rx Head and Tail Descriptor Pointers and
  2905. * the Base and Length of the Rx Descriptor Ring
  2906. */
  2907. for (i = 0; i < adapter->num_rx_queues; i++) {
  2908. rx_ring = adapter->rx_ring[i];
  2909. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  2910. set_ring_rsc_enabled(rx_ring);
  2911. else
  2912. clear_ring_rsc_enabled(rx_ring);
  2913. }
  2914. }
  2915. static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
  2916. {
  2917. struct ixgbe_hw *hw = &adapter->hw;
  2918. u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
  2919. switch (hw->mac.type) {
  2920. case ixgbe_mac_82598EB:
  2921. /*
  2922. * For VMDq support of different descriptor types or
  2923. * buffer sizes through the use of multiple SRRCTL
  2924. * registers, RDRXCTL.MVMEN must be set to 1
  2925. *
  2926. * also, the manual doesn't mention it clearly but DCA hints
  2927. * will only use queue 0's tags unless this bit is set. Side
  2928. * effects of setting this bit are only that SRRCTL must be
  2929. * fully programmed [0..15]
  2930. */
  2931. rdrxctl |= IXGBE_RDRXCTL_MVMEN;
  2932. break;
  2933. case ixgbe_mac_82599EB:
  2934. case ixgbe_mac_X540:
  2935. /* Disable RSC for ACK packets */
  2936. IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
  2937. (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
  2938. rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
  2939. /* hardware requires some bits to be set by default */
  2940. rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
  2941. rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
  2942. break;
  2943. default:
  2944. /* We should do nothing since we don't know this hardware */
  2945. return;
  2946. }
  2947. IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
  2948. }
  2949. /**
  2950. * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
  2951. * @adapter: board private structure
  2952. *
  2953. * Configure the Rx unit of the MAC after a reset.
  2954. **/
  2955. static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
  2956. {
  2957. struct ixgbe_hw *hw = &adapter->hw;
  2958. int i;
  2959. u32 rxctrl;
  2960. /* disable receives while setting up the descriptors */
  2961. rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  2962. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
  2963. ixgbe_setup_psrtype(adapter);
  2964. ixgbe_setup_rdrxctl(adapter);
  2965. /* Program registers for the distribution of queues */
  2966. ixgbe_setup_mrqc(adapter);
  2967. /* set_rx_buffer_len must be called before ring initialization */
  2968. ixgbe_set_rx_buffer_len(adapter);
  2969. /*
  2970. * Setup the HW Rx Head and Tail Descriptor Pointers and
  2971. * the Base and Length of the Rx Descriptor Ring
  2972. */
  2973. for (i = 0; i < adapter->num_rx_queues; i++)
  2974. ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
  2975. /* disable drop enable for 82598 parts */
  2976. if (hw->mac.type == ixgbe_mac_82598EB)
  2977. rxctrl |= IXGBE_RXCTRL_DMBYPS;
  2978. /* enable all receives */
  2979. rxctrl |= IXGBE_RXCTRL_RXEN;
  2980. hw->mac.ops.enable_rx_dma(hw, rxctrl);
  2981. }
  2982. static int ixgbe_vlan_rx_add_vid(struct net_device *netdev,
  2983. __be16 proto, u16 vid)
  2984. {
  2985. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  2986. struct ixgbe_hw *hw = &adapter->hw;
  2987. /* add VID to filter table */
  2988. hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), true);
  2989. set_bit(vid, adapter->active_vlans);
  2990. return 0;
  2991. }
  2992. static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev,
  2993. __be16 proto, u16 vid)
  2994. {
  2995. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  2996. struct ixgbe_hw *hw = &adapter->hw;
  2997. /* remove VID from filter table */
  2998. hw->mac.ops.set_vfta(&adapter->hw, vid, VMDQ_P(0), false);
  2999. clear_bit(vid, adapter->active_vlans);
  3000. return 0;
  3001. }
  3002. /**
  3003. * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
  3004. * @adapter: driver data
  3005. */
  3006. static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
  3007. {
  3008. struct ixgbe_hw *hw = &adapter->hw;
  3009. u32 vlnctrl;
  3010. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3011. vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
  3012. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3013. }
  3014. /**
  3015. * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
  3016. * @adapter: driver data
  3017. */
  3018. static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
  3019. {
  3020. struct ixgbe_hw *hw = &adapter->hw;
  3021. u32 vlnctrl;
  3022. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3023. vlnctrl |= IXGBE_VLNCTRL_VFE;
  3024. vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
  3025. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3026. }
  3027. /**
  3028. * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
  3029. * @adapter: driver data
  3030. */
  3031. static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
  3032. {
  3033. struct ixgbe_hw *hw = &adapter->hw;
  3034. u32 vlnctrl;
  3035. int i, j;
  3036. switch (hw->mac.type) {
  3037. case ixgbe_mac_82598EB:
  3038. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3039. vlnctrl &= ~IXGBE_VLNCTRL_VME;
  3040. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3041. break;
  3042. case ixgbe_mac_82599EB:
  3043. case ixgbe_mac_X540:
  3044. for (i = 0; i < adapter->num_rx_queues; i++) {
  3045. j = adapter->rx_ring[i]->reg_idx;
  3046. vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
  3047. vlnctrl &= ~IXGBE_RXDCTL_VME;
  3048. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
  3049. }
  3050. break;
  3051. default:
  3052. break;
  3053. }
  3054. }
  3055. /**
  3056. * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
  3057. * @adapter: driver data
  3058. */
  3059. static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
  3060. {
  3061. struct ixgbe_hw *hw = &adapter->hw;
  3062. u32 vlnctrl;
  3063. int i, j;
  3064. switch (hw->mac.type) {
  3065. case ixgbe_mac_82598EB:
  3066. vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
  3067. vlnctrl |= IXGBE_VLNCTRL_VME;
  3068. IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
  3069. break;
  3070. case ixgbe_mac_82599EB:
  3071. case ixgbe_mac_X540:
  3072. for (i = 0; i < adapter->num_rx_queues; i++) {
  3073. j = adapter->rx_ring[i]->reg_idx;
  3074. vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
  3075. vlnctrl |= IXGBE_RXDCTL_VME;
  3076. IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
  3077. }
  3078. break;
  3079. default:
  3080. break;
  3081. }
  3082. }
  3083. static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
  3084. {
  3085. u16 vid;
  3086. ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
  3087. for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
  3088. ixgbe_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
  3089. }
  3090. /**
  3091. * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
  3092. * @netdev: network interface device structure
  3093. *
  3094. * Writes unicast address list to the RAR table.
  3095. * Returns: -ENOMEM on failure/insufficient address space
  3096. * 0 on no addresses written
  3097. * X on writing X addresses to the RAR table
  3098. **/
  3099. static int ixgbe_write_uc_addr_list(struct net_device *netdev)
  3100. {
  3101. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3102. struct ixgbe_hw *hw = &adapter->hw;
  3103. unsigned int rar_entries = hw->mac.num_rar_entries - 1;
  3104. int count = 0;
  3105. /* In SR-IOV mode significantly less RAR entries are available */
  3106. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  3107. rar_entries = IXGBE_MAX_PF_MACVLANS - 1;
  3108. /* return ENOMEM indicating insufficient memory for addresses */
  3109. if (netdev_uc_count(netdev) > rar_entries)
  3110. return -ENOMEM;
  3111. if (!netdev_uc_empty(netdev)) {
  3112. struct netdev_hw_addr *ha;
  3113. /* return error if we do not support writing to RAR table */
  3114. if (!hw->mac.ops.set_rar)
  3115. return -ENOMEM;
  3116. netdev_for_each_uc_addr(ha, netdev) {
  3117. if (!rar_entries)
  3118. break;
  3119. hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
  3120. VMDQ_P(0), IXGBE_RAH_AV);
  3121. count++;
  3122. }
  3123. }
  3124. /* write the addresses in reverse order to avoid write combining */
  3125. for (; rar_entries > 0 ; rar_entries--)
  3126. hw->mac.ops.clear_rar(hw, rar_entries);
  3127. return count;
  3128. }
  3129. /**
  3130. * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
  3131. * @netdev: network interface device structure
  3132. *
  3133. * The set_rx_method entry point is called whenever the unicast/multicast
  3134. * address list or the network interface flags are updated. This routine is
  3135. * responsible for configuring the hardware for proper unicast, multicast and
  3136. * promiscuous mode.
  3137. **/
  3138. void ixgbe_set_rx_mode(struct net_device *netdev)
  3139. {
  3140. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3141. struct ixgbe_hw *hw = &adapter->hw;
  3142. u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
  3143. int count;
  3144. /* Check for Promiscuous and All Multicast modes */
  3145. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  3146. /* set all bits that we expect to always be set */
  3147. fctrl &= ~IXGBE_FCTRL_SBP; /* disable store-bad-packets */
  3148. fctrl |= IXGBE_FCTRL_BAM;
  3149. fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
  3150. fctrl |= IXGBE_FCTRL_PMCF;
  3151. /* clear the bits we are changing the status of */
  3152. fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
  3153. if (netdev->flags & IFF_PROMISC) {
  3154. hw->addr_ctrl.user_set_promisc = true;
  3155. fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
  3156. vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
  3157. /* don't hardware filter vlans in promisc mode */
  3158. ixgbe_vlan_filter_disable(adapter);
  3159. } else {
  3160. if (netdev->flags & IFF_ALLMULTI) {
  3161. fctrl |= IXGBE_FCTRL_MPE;
  3162. vmolr |= IXGBE_VMOLR_MPE;
  3163. } else {
  3164. /*
  3165. * Write addresses to the MTA, if the attempt fails
  3166. * then we should just turn on promiscuous mode so
  3167. * that we can at least receive multicast traffic
  3168. */
  3169. hw->mac.ops.update_mc_addr_list(hw, netdev);
  3170. vmolr |= IXGBE_VMOLR_ROMPE;
  3171. }
  3172. ixgbe_vlan_filter_enable(adapter);
  3173. hw->addr_ctrl.user_set_promisc = false;
  3174. }
  3175. /*
  3176. * Write addresses to available RAR registers, if there is not
  3177. * sufficient space to store all the addresses then enable
  3178. * unicast promiscuous mode
  3179. */
  3180. count = ixgbe_write_uc_addr_list(netdev);
  3181. if (count < 0) {
  3182. fctrl |= IXGBE_FCTRL_UPE;
  3183. vmolr |= IXGBE_VMOLR_ROPE;
  3184. }
  3185. if (adapter->num_vfs)
  3186. ixgbe_restore_vf_multicasts(adapter);
  3187. if (hw->mac.type != ixgbe_mac_82598EB) {
  3188. vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(VMDQ_P(0))) &
  3189. ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
  3190. IXGBE_VMOLR_ROPE);
  3191. IXGBE_WRITE_REG(hw, IXGBE_VMOLR(VMDQ_P(0)), vmolr);
  3192. }
  3193. /* This is useful for sniffing bad packets. */
  3194. if (adapter->netdev->features & NETIF_F_RXALL) {
  3195. /* UPE and MPE will be handled by normal PROMISC logic
  3196. * in e1000e_set_rx_mode */
  3197. fctrl |= (IXGBE_FCTRL_SBP | /* Receive bad packets */
  3198. IXGBE_FCTRL_BAM | /* RX All Bcast Pkts */
  3199. IXGBE_FCTRL_PMCF); /* RX All MAC Ctrl Pkts */
  3200. fctrl &= ~(IXGBE_FCTRL_DPF);
  3201. /* NOTE: VLAN filtering is disabled by setting PROMISC */
  3202. }
  3203. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  3204. if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
  3205. ixgbe_vlan_strip_enable(adapter);
  3206. else
  3207. ixgbe_vlan_strip_disable(adapter);
  3208. }
  3209. static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
  3210. {
  3211. int q_idx;
  3212. for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
  3213. napi_enable(&adapter->q_vector[q_idx]->napi);
  3214. }
  3215. static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
  3216. {
  3217. int q_idx;
  3218. for (q_idx = 0; q_idx < adapter->num_q_vectors; q_idx++)
  3219. napi_disable(&adapter->q_vector[q_idx]->napi);
  3220. }
  3221. #ifdef CONFIG_IXGBE_DCB
  3222. /**
  3223. * ixgbe_configure_dcb - Configure DCB hardware
  3224. * @adapter: ixgbe adapter struct
  3225. *
  3226. * This is called by the driver on open to configure the DCB hardware.
  3227. * This is also called by the gennetlink interface when reconfiguring
  3228. * the DCB state.
  3229. */
  3230. static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
  3231. {
  3232. struct ixgbe_hw *hw = &adapter->hw;
  3233. int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  3234. if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
  3235. if (hw->mac.type == ixgbe_mac_82598EB)
  3236. netif_set_gso_max_size(adapter->netdev, 65536);
  3237. return;
  3238. }
  3239. if (hw->mac.type == ixgbe_mac_82598EB)
  3240. netif_set_gso_max_size(adapter->netdev, 32768);
  3241. #ifdef IXGBE_FCOE
  3242. if (adapter->netdev->features & NETIF_F_FCOE_MTU)
  3243. max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
  3244. #endif
  3245. /* reconfigure the hardware */
  3246. if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
  3247. ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
  3248. DCB_TX_CONFIG);
  3249. ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
  3250. DCB_RX_CONFIG);
  3251. ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
  3252. } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
  3253. ixgbe_dcb_hw_ets(&adapter->hw,
  3254. adapter->ixgbe_ieee_ets,
  3255. max_frame);
  3256. ixgbe_dcb_hw_pfc_config(&adapter->hw,
  3257. adapter->ixgbe_ieee_pfc->pfc_en,
  3258. adapter->ixgbe_ieee_ets->prio_tc);
  3259. }
  3260. /* Enable RSS Hash per TC */
  3261. if (hw->mac.type != ixgbe_mac_82598EB) {
  3262. u32 msb = 0;
  3263. u16 rss_i = adapter->ring_feature[RING_F_RSS].indices - 1;
  3264. while (rss_i) {
  3265. msb++;
  3266. rss_i >>= 1;
  3267. }
  3268. /* write msb to all 8 TCs in one write */
  3269. IXGBE_WRITE_REG(hw, IXGBE_RQTC, msb * 0x11111111);
  3270. }
  3271. }
  3272. #endif
  3273. /* Additional bittime to account for IXGBE framing */
  3274. #define IXGBE_ETH_FRAMING 20
  3275. /**
  3276. * ixgbe_hpbthresh - calculate high water mark for flow control
  3277. *
  3278. * @adapter: board private structure to calculate for
  3279. * @pb: packet buffer to calculate
  3280. */
  3281. static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
  3282. {
  3283. struct ixgbe_hw *hw = &adapter->hw;
  3284. struct net_device *dev = adapter->netdev;
  3285. int link, tc, kb, marker;
  3286. u32 dv_id, rx_pba;
  3287. /* Calculate max LAN frame size */
  3288. tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
  3289. #ifdef IXGBE_FCOE
  3290. /* FCoE traffic class uses FCOE jumbo frames */
  3291. if ((dev->features & NETIF_F_FCOE_MTU) &&
  3292. (tc < IXGBE_FCOE_JUMBO_FRAME_SIZE) &&
  3293. (pb == ixgbe_fcoe_get_tc(adapter)))
  3294. tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
  3295. #endif
  3296. /* Calculate delay value for device */
  3297. switch (hw->mac.type) {
  3298. case ixgbe_mac_X540:
  3299. dv_id = IXGBE_DV_X540(link, tc);
  3300. break;
  3301. default:
  3302. dv_id = IXGBE_DV(link, tc);
  3303. break;
  3304. }
  3305. /* Loopback switch introduces additional latency */
  3306. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  3307. dv_id += IXGBE_B2BT(tc);
  3308. /* Delay value is calculated in bit times convert to KB */
  3309. kb = IXGBE_BT2KB(dv_id);
  3310. rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
  3311. marker = rx_pba - kb;
  3312. /* It is possible that the packet buffer is not large enough
  3313. * to provide required headroom. In this case throw an error
  3314. * to user and a do the best we can.
  3315. */
  3316. if (marker < 0) {
  3317. e_warn(drv, "Packet Buffer(%i) can not provide enough"
  3318. "headroom to support flow control."
  3319. "Decrease MTU or number of traffic classes\n", pb);
  3320. marker = tc + 1;
  3321. }
  3322. return marker;
  3323. }
  3324. /**
  3325. * ixgbe_lpbthresh - calculate low water mark for for flow control
  3326. *
  3327. * @adapter: board private structure to calculate for
  3328. * @pb: packet buffer to calculate
  3329. */
  3330. static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
  3331. {
  3332. struct ixgbe_hw *hw = &adapter->hw;
  3333. struct net_device *dev = adapter->netdev;
  3334. int tc;
  3335. u32 dv_id;
  3336. /* Calculate max LAN frame size */
  3337. tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
  3338. /* Calculate delay value for device */
  3339. switch (hw->mac.type) {
  3340. case ixgbe_mac_X540:
  3341. dv_id = IXGBE_LOW_DV_X540(tc);
  3342. break;
  3343. default:
  3344. dv_id = IXGBE_LOW_DV(tc);
  3345. break;
  3346. }
  3347. /* Delay value is calculated in bit times convert to KB */
  3348. return IXGBE_BT2KB(dv_id);
  3349. }
  3350. /*
  3351. * ixgbe_pbthresh_setup - calculate and setup high low water marks
  3352. */
  3353. static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
  3354. {
  3355. struct ixgbe_hw *hw = &adapter->hw;
  3356. int num_tc = netdev_get_num_tc(adapter->netdev);
  3357. int i;
  3358. if (!num_tc)
  3359. num_tc = 1;
  3360. hw->fc.low_water = ixgbe_lpbthresh(adapter);
  3361. for (i = 0; i < num_tc; i++) {
  3362. hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
  3363. /* Low water marks must not be larger than high water marks */
  3364. if (hw->fc.low_water > hw->fc.high_water[i])
  3365. hw->fc.low_water = 0;
  3366. }
  3367. }
  3368. static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
  3369. {
  3370. struct ixgbe_hw *hw = &adapter->hw;
  3371. int hdrm;
  3372. u8 tc = netdev_get_num_tc(adapter->netdev);
  3373. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
  3374. adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  3375. hdrm = 32 << adapter->fdir_pballoc;
  3376. else
  3377. hdrm = 0;
  3378. hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
  3379. ixgbe_pbthresh_setup(adapter);
  3380. }
  3381. static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
  3382. {
  3383. struct ixgbe_hw *hw = &adapter->hw;
  3384. struct hlist_node *node2;
  3385. struct ixgbe_fdir_filter *filter;
  3386. spin_lock(&adapter->fdir_perfect_lock);
  3387. if (!hlist_empty(&adapter->fdir_filter_list))
  3388. ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
  3389. hlist_for_each_entry_safe(filter, node2,
  3390. &adapter->fdir_filter_list, fdir_node) {
  3391. ixgbe_fdir_write_perfect_filter_82599(hw,
  3392. &filter->filter,
  3393. filter->sw_idx,
  3394. (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
  3395. IXGBE_FDIR_DROP_QUEUE :
  3396. adapter->rx_ring[filter->action]->reg_idx);
  3397. }
  3398. spin_unlock(&adapter->fdir_perfect_lock);
  3399. }
  3400. static void ixgbe_configure(struct ixgbe_adapter *adapter)
  3401. {
  3402. struct ixgbe_hw *hw = &adapter->hw;
  3403. ixgbe_configure_pb(adapter);
  3404. #ifdef CONFIG_IXGBE_DCB
  3405. ixgbe_configure_dcb(adapter);
  3406. #endif
  3407. /*
  3408. * We must restore virtualization before VLANs or else
  3409. * the VLVF registers will not be populated
  3410. */
  3411. ixgbe_configure_virtualization(adapter);
  3412. ixgbe_set_rx_mode(adapter->netdev);
  3413. ixgbe_restore_vlan(adapter);
  3414. switch (hw->mac.type) {
  3415. case ixgbe_mac_82599EB:
  3416. case ixgbe_mac_X540:
  3417. hw->mac.ops.disable_rx_buff(hw);
  3418. break;
  3419. default:
  3420. break;
  3421. }
  3422. if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
  3423. ixgbe_init_fdir_signature_82599(&adapter->hw,
  3424. adapter->fdir_pballoc);
  3425. } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
  3426. ixgbe_init_fdir_perfect_82599(&adapter->hw,
  3427. adapter->fdir_pballoc);
  3428. ixgbe_fdir_filter_restore(adapter);
  3429. }
  3430. switch (hw->mac.type) {
  3431. case ixgbe_mac_82599EB:
  3432. case ixgbe_mac_X540:
  3433. hw->mac.ops.enable_rx_buff(hw);
  3434. break;
  3435. default:
  3436. break;
  3437. }
  3438. #ifdef IXGBE_FCOE
  3439. /* configure FCoE L2 filters, redirection table, and Rx control */
  3440. ixgbe_configure_fcoe(adapter);
  3441. #endif /* IXGBE_FCOE */
  3442. ixgbe_configure_tx(adapter);
  3443. ixgbe_configure_rx(adapter);
  3444. }
  3445. static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
  3446. {
  3447. switch (hw->phy.type) {
  3448. case ixgbe_phy_sfp_avago:
  3449. case ixgbe_phy_sfp_ftl:
  3450. case ixgbe_phy_sfp_intel:
  3451. case ixgbe_phy_sfp_unknown:
  3452. case ixgbe_phy_sfp_passive_tyco:
  3453. case ixgbe_phy_sfp_passive_unknown:
  3454. case ixgbe_phy_sfp_active_unknown:
  3455. case ixgbe_phy_sfp_ftl_active:
  3456. return true;
  3457. case ixgbe_phy_nl:
  3458. if (hw->mac.type == ixgbe_mac_82598EB)
  3459. return true;
  3460. default:
  3461. return false;
  3462. }
  3463. }
  3464. /**
  3465. * ixgbe_sfp_link_config - set up SFP+ link
  3466. * @adapter: pointer to private adapter struct
  3467. **/
  3468. static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
  3469. {
  3470. /*
  3471. * We are assuming the worst case scenario here, and that
  3472. * is that an SFP was inserted/removed after the reset
  3473. * but before SFP detection was enabled. As such the best
  3474. * solution is to just start searching as soon as we start
  3475. */
  3476. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  3477. adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
  3478. adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
  3479. }
  3480. /**
  3481. * ixgbe_non_sfp_link_config - set up non-SFP+ link
  3482. * @hw: pointer to private hardware struct
  3483. *
  3484. * Returns 0 on success, negative on failure
  3485. **/
  3486. static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
  3487. {
  3488. u32 speed;
  3489. bool autoneg, link_up = false;
  3490. u32 ret = IXGBE_ERR_LINK_SETUP;
  3491. if (hw->mac.ops.check_link)
  3492. ret = hw->mac.ops.check_link(hw, &speed, &link_up, false);
  3493. if (ret)
  3494. goto link_cfg_out;
  3495. speed = hw->phy.autoneg_advertised;
  3496. if ((!speed) && (hw->mac.ops.get_link_capabilities))
  3497. ret = hw->mac.ops.get_link_capabilities(hw, &speed,
  3498. &autoneg);
  3499. if (ret)
  3500. goto link_cfg_out;
  3501. if (hw->mac.ops.setup_link)
  3502. ret = hw->mac.ops.setup_link(hw, speed, link_up);
  3503. link_cfg_out:
  3504. return ret;
  3505. }
  3506. static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
  3507. {
  3508. struct ixgbe_hw *hw = &adapter->hw;
  3509. u32 gpie = 0;
  3510. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  3511. gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
  3512. IXGBE_GPIE_OCD;
  3513. gpie |= IXGBE_GPIE_EIAME;
  3514. /*
  3515. * use EIAM to auto-mask when MSI-X interrupt is asserted
  3516. * this saves a register write for every interrupt
  3517. */
  3518. switch (hw->mac.type) {
  3519. case ixgbe_mac_82598EB:
  3520. IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
  3521. break;
  3522. case ixgbe_mac_82599EB:
  3523. case ixgbe_mac_X540:
  3524. default:
  3525. IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
  3526. IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
  3527. break;
  3528. }
  3529. } else {
  3530. /* legacy interrupts, use EIAM to auto-mask when reading EICR,
  3531. * specifically only auto mask tx and rx interrupts */
  3532. IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
  3533. }
  3534. /* XXX: to interrupt immediately for EICS writes, enable this */
  3535. /* gpie |= IXGBE_GPIE_EIMEN; */
  3536. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  3537. gpie &= ~IXGBE_GPIE_VTMODE_MASK;
  3538. switch (adapter->ring_feature[RING_F_VMDQ].mask) {
  3539. case IXGBE_82599_VMDQ_8Q_MASK:
  3540. gpie |= IXGBE_GPIE_VTMODE_16;
  3541. break;
  3542. case IXGBE_82599_VMDQ_4Q_MASK:
  3543. gpie |= IXGBE_GPIE_VTMODE_32;
  3544. break;
  3545. default:
  3546. gpie |= IXGBE_GPIE_VTMODE_64;
  3547. break;
  3548. }
  3549. }
  3550. /* Enable Thermal over heat sensor interrupt */
  3551. if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
  3552. switch (adapter->hw.mac.type) {
  3553. case ixgbe_mac_82599EB:
  3554. gpie |= IXGBE_SDP0_GPIEN;
  3555. break;
  3556. case ixgbe_mac_X540:
  3557. gpie |= IXGBE_EIMS_TS;
  3558. break;
  3559. default:
  3560. break;
  3561. }
  3562. }
  3563. /* Enable fan failure interrupt */
  3564. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
  3565. gpie |= IXGBE_SDP1_GPIEN;
  3566. if (hw->mac.type == ixgbe_mac_82599EB) {
  3567. gpie |= IXGBE_SDP1_GPIEN;
  3568. gpie |= IXGBE_SDP2_GPIEN;
  3569. }
  3570. IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
  3571. }
  3572. static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
  3573. {
  3574. struct ixgbe_hw *hw = &adapter->hw;
  3575. int err;
  3576. u32 ctrl_ext;
  3577. ixgbe_get_hw_control(adapter);
  3578. ixgbe_setup_gpie(adapter);
  3579. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  3580. ixgbe_configure_msix(adapter);
  3581. else
  3582. ixgbe_configure_msi_and_legacy(adapter);
  3583. /* enable the optics for 82599 SFP+ fiber */
  3584. if (hw->mac.ops.enable_tx_laser)
  3585. hw->mac.ops.enable_tx_laser(hw);
  3586. clear_bit(__IXGBE_DOWN, &adapter->state);
  3587. ixgbe_napi_enable_all(adapter);
  3588. if (ixgbe_is_sfp(hw)) {
  3589. ixgbe_sfp_link_config(adapter);
  3590. } else {
  3591. err = ixgbe_non_sfp_link_config(hw);
  3592. if (err)
  3593. e_err(probe, "link_config FAILED %d\n", err);
  3594. }
  3595. /* clear any pending interrupts, may auto mask */
  3596. IXGBE_READ_REG(hw, IXGBE_EICR);
  3597. ixgbe_irq_enable(adapter, true, true);
  3598. /*
  3599. * If this adapter has a fan, check to see if we had a failure
  3600. * before we enabled the interrupt.
  3601. */
  3602. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  3603. u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  3604. if (esdp & IXGBE_ESDP_SDP1)
  3605. e_crit(drv, "Fan has stopped, replace the adapter\n");
  3606. }
  3607. /* enable transmits */
  3608. netif_tx_start_all_queues(adapter->netdev);
  3609. /* bring the link up in the watchdog, this could race with our first
  3610. * link up interrupt but shouldn't be a problem */
  3611. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  3612. adapter->link_check_timeout = jiffies;
  3613. mod_timer(&adapter->service_timer, jiffies);
  3614. /* Set PF Reset Done bit so PF/VF Mail Ops can work */
  3615. ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
  3616. ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
  3617. IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
  3618. }
  3619. void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
  3620. {
  3621. WARN_ON(in_interrupt());
  3622. /* put off any impending NetWatchDogTimeout */
  3623. adapter->netdev->trans_start = jiffies;
  3624. while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
  3625. usleep_range(1000, 2000);
  3626. ixgbe_down(adapter);
  3627. /*
  3628. * If SR-IOV enabled then wait a bit before bringing the adapter
  3629. * back up to give the VFs time to respond to the reset. The
  3630. * two second wait is based upon the watchdog timer cycle in
  3631. * the VF driver.
  3632. */
  3633. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  3634. msleep(2000);
  3635. ixgbe_up(adapter);
  3636. clear_bit(__IXGBE_RESETTING, &adapter->state);
  3637. }
  3638. void ixgbe_up(struct ixgbe_adapter *adapter)
  3639. {
  3640. /* hardware has been reset, we need to reload some things */
  3641. ixgbe_configure(adapter);
  3642. ixgbe_up_complete(adapter);
  3643. }
  3644. void ixgbe_reset(struct ixgbe_adapter *adapter)
  3645. {
  3646. struct ixgbe_hw *hw = &adapter->hw;
  3647. int err;
  3648. /* lock SFP init bit to prevent race conditions with the watchdog */
  3649. while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
  3650. usleep_range(1000, 2000);
  3651. /* clear all SFP and link config related flags while holding SFP_INIT */
  3652. adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
  3653. IXGBE_FLAG2_SFP_NEEDS_RESET);
  3654. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
  3655. err = hw->mac.ops.init_hw(hw);
  3656. switch (err) {
  3657. case 0:
  3658. case IXGBE_ERR_SFP_NOT_PRESENT:
  3659. case IXGBE_ERR_SFP_NOT_SUPPORTED:
  3660. break;
  3661. case IXGBE_ERR_MASTER_REQUESTS_PENDING:
  3662. e_dev_err("master disable timed out\n");
  3663. break;
  3664. case IXGBE_ERR_EEPROM_VERSION:
  3665. /* We are running on a pre-production device, log a warning */
  3666. e_dev_warn("This device is a pre-production adapter/LOM. "
  3667. "Please be aware there may be issues associated with "
  3668. "your hardware. If you are experiencing problems "
  3669. "please contact your Intel or hardware "
  3670. "representative who provided you with this "
  3671. "hardware.\n");
  3672. break;
  3673. default:
  3674. e_dev_err("Hardware Error: %d\n", err);
  3675. }
  3676. clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
  3677. /* reprogram the RAR[0] in case user changed it. */
  3678. hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV);
  3679. /* update SAN MAC vmdq pool selection */
  3680. if (hw->mac.san_mac_rar_index)
  3681. hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
  3682. if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
  3683. ixgbe_ptp_reset(adapter);
  3684. }
  3685. /**
  3686. * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
  3687. * @rx_ring: ring to free buffers from
  3688. **/
  3689. static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
  3690. {
  3691. struct device *dev = rx_ring->dev;
  3692. unsigned long size;
  3693. u16 i;
  3694. /* ring already cleared, nothing to do */
  3695. if (!rx_ring->rx_buffer_info)
  3696. return;
  3697. /* Free all the Rx ring sk_buffs */
  3698. for (i = 0; i < rx_ring->count; i++) {
  3699. struct ixgbe_rx_buffer *rx_buffer;
  3700. rx_buffer = &rx_ring->rx_buffer_info[i];
  3701. if (rx_buffer->skb) {
  3702. struct sk_buff *skb = rx_buffer->skb;
  3703. if (IXGBE_CB(skb)->page_released) {
  3704. dma_unmap_page(dev,
  3705. IXGBE_CB(skb)->dma,
  3706. ixgbe_rx_bufsz(rx_ring),
  3707. DMA_FROM_DEVICE);
  3708. IXGBE_CB(skb)->page_released = false;
  3709. }
  3710. dev_kfree_skb(skb);
  3711. }
  3712. rx_buffer->skb = NULL;
  3713. if (rx_buffer->dma)
  3714. dma_unmap_page(dev, rx_buffer->dma,
  3715. ixgbe_rx_pg_size(rx_ring),
  3716. DMA_FROM_DEVICE);
  3717. rx_buffer->dma = 0;
  3718. if (rx_buffer->page)
  3719. __free_pages(rx_buffer->page,
  3720. ixgbe_rx_pg_order(rx_ring));
  3721. rx_buffer->page = NULL;
  3722. }
  3723. size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
  3724. memset(rx_ring->rx_buffer_info, 0, size);
  3725. /* Zero out the descriptor ring */
  3726. memset(rx_ring->desc, 0, rx_ring->size);
  3727. rx_ring->next_to_alloc = 0;
  3728. rx_ring->next_to_clean = 0;
  3729. rx_ring->next_to_use = 0;
  3730. }
  3731. /**
  3732. * ixgbe_clean_tx_ring - Free Tx Buffers
  3733. * @tx_ring: ring to be cleaned
  3734. **/
  3735. static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
  3736. {
  3737. struct ixgbe_tx_buffer *tx_buffer_info;
  3738. unsigned long size;
  3739. u16 i;
  3740. /* ring already cleared, nothing to do */
  3741. if (!tx_ring->tx_buffer_info)
  3742. return;
  3743. /* Free all the Tx ring sk_buffs */
  3744. for (i = 0; i < tx_ring->count; i++) {
  3745. tx_buffer_info = &tx_ring->tx_buffer_info[i];
  3746. ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
  3747. }
  3748. netdev_tx_reset_queue(txring_txq(tx_ring));
  3749. size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
  3750. memset(tx_ring->tx_buffer_info, 0, size);
  3751. /* Zero out the descriptor ring */
  3752. memset(tx_ring->desc, 0, tx_ring->size);
  3753. tx_ring->next_to_use = 0;
  3754. tx_ring->next_to_clean = 0;
  3755. }
  3756. /**
  3757. * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
  3758. * @adapter: board private structure
  3759. **/
  3760. static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
  3761. {
  3762. int i;
  3763. for (i = 0; i < adapter->num_rx_queues; i++)
  3764. ixgbe_clean_rx_ring(adapter->rx_ring[i]);
  3765. }
  3766. /**
  3767. * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
  3768. * @adapter: board private structure
  3769. **/
  3770. static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
  3771. {
  3772. int i;
  3773. for (i = 0; i < adapter->num_tx_queues; i++)
  3774. ixgbe_clean_tx_ring(adapter->tx_ring[i]);
  3775. }
  3776. static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
  3777. {
  3778. struct hlist_node *node2;
  3779. struct ixgbe_fdir_filter *filter;
  3780. spin_lock(&adapter->fdir_perfect_lock);
  3781. hlist_for_each_entry_safe(filter, node2,
  3782. &adapter->fdir_filter_list, fdir_node) {
  3783. hlist_del(&filter->fdir_node);
  3784. kfree(filter);
  3785. }
  3786. adapter->fdir_filter_count = 0;
  3787. spin_unlock(&adapter->fdir_perfect_lock);
  3788. }
  3789. void ixgbe_down(struct ixgbe_adapter *adapter)
  3790. {
  3791. struct net_device *netdev = adapter->netdev;
  3792. struct ixgbe_hw *hw = &adapter->hw;
  3793. u32 rxctrl;
  3794. int i;
  3795. /* signal that we are down to the interrupt handler */
  3796. set_bit(__IXGBE_DOWN, &adapter->state);
  3797. /* disable receives */
  3798. rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  3799. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
  3800. /* disable all enabled rx queues */
  3801. for (i = 0; i < adapter->num_rx_queues; i++)
  3802. /* this call also flushes the previous write */
  3803. ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
  3804. usleep_range(10000, 20000);
  3805. netif_tx_stop_all_queues(netdev);
  3806. /* call carrier off first to avoid false dev_watchdog timeouts */
  3807. netif_carrier_off(netdev);
  3808. netif_tx_disable(netdev);
  3809. ixgbe_irq_disable(adapter);
  3810. ixgbe_napi_disable_all(adapter);
  3811. adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
  3812. IXGBE_FLAG2_RESET_REQUESTED);
  3813. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
  3814. del_timer_sync(&adapter->service_timer);
  3815. if (adapter->num_vfs) {
  3816. /* Clear EITR Select mapping */
  3817. IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
  3818. /* Mark all the VFs as inactive */
  3819. for (i = 0 ; i < adapter->num_vfs; i++)
  3820. adapter->vfinfo[i].clear_to_send = false;
  3821. /* ping all the active vfs to let them know we are going down */
  3822. ixgbe_ping_all_vfs(adapter);
  3823. /* Disable all VFTE/VFRE TX/RX */
  3824. ixgbe_disable_tx_rx(adapter);
  3825. }
  3826. /* disable transmits in the hardware now that interrupts are off */
  3827. for (i = 0; i < adapter->num_tx_queues; i++) {
  3828. u8 reg_idx = adapter->tx_ring[i]->reg_idx;
  3829. IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
  3830. }
  3831. /* Disable the Tx DMA engine on 82599 and X540 */
  3832. switch (hw->mac.type) {
  3833. case ixgbe_mac_82599EB:
  3834. case ixgbe_mac_X540:
  3835. IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
  3836. (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
  3837. ~IXGBE_DMATXCTL_TE));
  3838. break;
  3839. default:
  3840. break;
  3841. }
  3842. if (!pci_channel_offline(adapter->pdev))
  3843. ixgbe_reset(adapter);
  3844. /* power down the optics for 82599 SFP+ fiber */
  3845. if (hw->mac.ops.disable_tx_laser)
  3846. hw->mac.ops.disable_tx_laser(hw);
  3847. ixgbe_clean_all_tx_rings(adapter);
  3848. ixgbe_clean_all_rx_rings(adapter);
  3849. #ifdef CONFIG_IXGBE_DCA
  3850. /* since we reset the hardware DCA settings were cleared */
  3851. ixgbe_setup_dca(adapter);
  3852. #endif
  3853. }
  3854. /**
  3855. * ixgbe_tx_timeout - Respond to a Tx Hang
  3856. * @netdev: network interface device structure
  3857. **/
  3858. static void ixgbe_tx_timeout(struct net_device *netdev)
  3859. {
  3860. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  3861. /* Do the reset outside of interrupt context */
  3862. ixgbe_tx_timeout_reset(adapter);
  3863. }
  3864. /**
  3865. * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
  3866. * @adapter: board private structure to initialize
  3867. *
  3868. * ixgbe_sw_init initializes the Adapter private data structure.
  3869. * Fields are initialized based on PCI device information and
  3870. * OS network device settings (MTU size).
  3871. **/
  3872. static int ixgbe_sw_init(struct ixgbe_adapter *adapter)
  3873. {
  3874. struct ixgbe_hw *hw = &adapter->hw;
  3875. struct pci_dev *pdev = adapter->pdev;
  3876. unsigned int rss, fdir;
  3877. u32 fwsm;
  3878. #ifdef CONFIG_IXGBE_DCB
  3879. int j;
  3880. struct tc_configuration *tc;
  3881. #endif
  3882. /* PCI config space info */
  3883. hw->vendor_id = pdev->vendor;
  3884. hw->device_id = pdev->device;
  3885. hw->revision_id = pdev->revision;
  3886. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  3887. hw->subsystem_device_id = pdev->subsystem_device;
  3888. /* Set common capability flags and settings */
  3889. rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus());
  3890. adapter->ring_feature[RING_F_RSS].limit = rss;
  3891. adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
  3892. adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
  3893. adapter->max_q_vectors = MAX_Q_VECTORS_82599;
  3894. adapter->atr_sample_rate = 20;
  3895. fdir = min_t(int, IXGBE_MAX_FDIR_INDICES, num_online_cpus());
  3896. adapter->ring_feature[RING_F_FDIR].limit = fdir;
  3897. adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
  3898. #ifdef CONFIG_IXGBE_DCA
  3899. adapter->flags |= IXGBE_FLAG_DCA_CAPABLE;
  3900. #endif
  3901. #ifdef IXGBE_FCOE
  3902. adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
  3903. adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
  3904. #ifdef CONFIG_IXGBE_DCB
  3905. /* Default traffic class to use for FCoE */
  3906. adapter->fcoe.up = IXGBE_FCOE_DEFTC;
  3907. #endif /* CONFIG_IXGBE_DCB */
  3908. #endif /* IXGBE_FCOE */
  3909. /* Set MAC specific capability flags and exceptions */
  3910. switch (hw->mac.type) {
  3911. case ixgbe_mac_82598EB:
  3912. adapter->flags2 &= ~IXGBE_FLAG2_RSC_CAPABLE;
  3913. adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
  3914. if (hw->device_id == IXGBE_DEV_ID_82598AT)
  3915. adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
  3916. adapter->max_q_vectors = MAX_Q_VECTORS_82598;
  3917. adapter->ring_feature[RING_F_FDIR].limit = 0;
  3918. adapter->atr_sample_rate = 0;
  3919. adapter->fdir_pballoc = 0;
  3920. #ifdef IXGBE_FCOE
  3921. adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
  3922. adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
  3923. #ifdef CONFIG_IXGBE_DCB
  3924. adapter->fcoe.up = 0;
  3925. #endif /* IXGBE_DCB */
  3926. #endif /* IXGBE_FCOE */
  3927. break;
  3928. case ixgbe_mac_82599EB:
  3929. if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
  3930. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  3931. break;
  3932. case ixgbe_mac_X540:
  3933. fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM);
  3934. if (fwsm & IXGBE_FWSM_TS_ENABLED)
  3935. adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
  3936. break;
  3937. default:
  3938. break;
  3939. }
  3940. #ifdef IXGBE_FCOE
  3941. /* FCoE support exists, always init the FCoE lock */
  3942. spin_lock_init(&adapter->fcoe.lock);
  3943. #endif
  3944. /* n-tuple support exists, always init our spinlock */
  3945. spin_lock_init(&adapter->fdir_perfect_lock);
  3946. #ifdef CONFIG_IXGBE_DCB
  3947. switch (hw->mac.type) {
  3948. case ixgbe_mac_X540:
  3949. adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
  3950. adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
  3951. break;
  3952. default:
  3953. adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
  3954. adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
  3955. break;
  3956. }
  3957. /* Configure DCB traffic classes */
  3958. for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
  3959. tc = &adapter->dcb_cfg.tc_config[j];
  3960. tc->path[DCB_TX_CONFIG].bwg_id = 0;
  3961. tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
  3962. tc->path[DCB_RX_CONFIG].bwg_id = 0;
  3963. tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
  3964. tc->dcb_pfc = pfc_disabled;
  3965. }
  3966. /* Initialize default user to priority mapping, UPx->TC0 */
  3967. tc = &adapter->dcb_cfg.tc_config[0];
  3968. tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
  3969. tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
  3970. adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
  3971. adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
  3972. adapter->dcb_cfg.pfc_mode_enable = false;
  3973. adapter->dcb_set_bitmap = 0x00;
  3974. adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
  3975. memcpy(&adapter->temp_dcb_cfg, &adapter->dcb_cfg,
  3976. sizeof(adapter->temp_dcb_cfg));
  3977. #endif
  3978. /* default flow control settings */
  3979. hw->fc.requested_mode = ixgbe_fc_full;
  3980. hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
  3981. ixgbe_pbthresh_setup(adapter);
  3982. hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
  3983. hw->fc.send_xon = true;
  3984. hw->fc.disable_fc_autoneg =
  3985. (ixgbe_device_supports_autoneg_fc(hw) == 0) ? false : true;
  3986. #ifdef CONFIG_PCI_IOV
  3987. /* assign number of SR-IOV VFs */
  3988. if (hw->mac.type != ixgbe_mac_82598EB)
  3989. adapter->num_vfs = (max_vfs > 63) ? 0 : max_vfs;
  3990. #endif
  3991. /* enable itr by default in dynamic mode */
  3992. adapter->rx_itr_setting = 1;
  3993. adapter->tx_itr_setting = 1;
  3994. /* set default ring sizes */
  3995. adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
  3996. adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
  3997. /* set default work limits */
  3998. adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
  3999. /* initialize eeprom parameters */
  4000. if (ixgbe_init_eeprom_params_generic(hw)) {
  4001. e_dev_err("EEPROM initialization failed\n");
  4002. return -EIO;
  4003. }
  4004. set_bit(__IXGBE_DOWN, &adapter->state);
  4005. return 0;
  4006. }
  4007. /**
  4008. * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
  4009. * @tx_ring: tx descriptor ring (for a specific queue) to setup
  4010. *
  4011. * Return 0 on success, negative on failure
  4012. **/
  4013. int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
  4014. {
  4015. struct device *dev = tx_ring->dev;
  4016. int orig_node = dev_to_node(dev);
  4017. int numa_node = -1;
  4018. int size;
  4019. size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
  4020. if (tx_ring->q_vector)
  4021. numa_node = tx_ring->q_vector->numa_node;
  4022. tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
  4023. if (!tx_ring->tx_buffer_info)
  4024. tx_ring->tx_buffer_info = vzalloc(size);
  4025. if (!tx_ring->tx_buffer_info)
  4026. goto err;
  4027. /* round up to nearest 4K */
  4028. tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
  4029. tx_ring->size = ALIGN(tx_ring->size, 4096);
  4030. set_dev_node(dev, numa_node);
  4031. tx_ring->desc = dma_alloc_coherent(dev,
  4032. tx_ring->size,
  4033. &tx_ring->dma,
  4034. GFP_KERNEL);
  4035. set_dev_node(dev, orig_node);
  4036. if (!tx_ring->desc)
  4037. tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
  4038. &tx_ring->dma, GFP_KERNEL);
  4039. if (!tx_ring->desc)
  4040. goto err;
  4041. tx_ring->next_to_use = 0;
  4042. tx_ring->next_to_clean = 0;
  4043. return 0;
  4044. err:
  4045. vfree(tx_ring->tx_buffer_info);
  4046. tx_ring->tx_buffer_info = NULL;
  4047. dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
  4048. return -ENOMEM;
  4049. }
  4050. /**
  4051. * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
  4052. * @adapter: board private structure
  4053. *
  4054. * If this function returns with an error, then it's possible one or
  4055. * more of the rings is populated (while the rest are not). It is the
  4056. * callers duty to clean those orphaned rings.
  4057. *
  4058. * Return 0 on success, negative on failure
  4059. **/
  4060. static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
  4061. {
  4062. int i, err = 0;
  4063. for (i = 0; i < adapter->num_tx_queues; i++) {
  4064. err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
  4065. if (!err)
  4066. continue;
  4067. e_err(probe, "Allocation for Tx Queue %u failed\n", i);
  4068. goto err_setup_tx;
  4069. }
  4070. return 0;
  4071. err_setup_tx:
  4072. /* rewind the index freeing the rings as we go */
  4073. while (i--)
  4074. ixgbe_free_tx_resources(adapter->tx_ring[i]);
  4075. return err;
  4076. }
  4077. /**
  4078. * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
  4079. * @rx_ring: rx descriptor ring (for a specific queue) to setup
  4080. *
  4081. * Returns 0 on success, negative on failure
  4082. **/
  4083. int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
  4084. {
  4085. struct device *dev = rx_ring->dev;
  4086. int orig_node = dev_to_node(dev);
  4087. int numa_node = -1;
  4088. int size;
  4089. size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
  4090. if (rx_ring->q_vector)
  4091. numa_node = rx_ring->q_vector->numa_node;
  4092. rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
  4093. if (!rx_ring->rx_buffer_info)
  4094. rx_ring->rx_buffer_info = vzalloc(size);
  4095. if (!rx_ring->rx_buffer_info)
  4096. goto err;
  4097. /* Round up to nearest 4K */
  4098. rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
  4099. rx_ring->size = ALIGN(rx_ring->size, 4096);
  4100. set_dev_node(dev, numa_node);
  4101. rx_ring->desc = dma_alloc_coherent(dev,
  4102. rx_ring->size,
  4103. &rx_ring->dma,
  4104. GFP_KERNEL);
  4105. set_dev_node(dev, orig_node);
  4106. if (!rx_ring->desc)
  4107. rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
  4108. &rx_ring->dma, GFP_KERNEL);
  4109. if (!rx_ring->desc)
  4110. goto err;
  4111. rx_ring->next_to_clean = 0;
  4112. rx_ring->next_to_use = 0;
  4113. return 0;
  4114. err:
  4115. vfree(rx_ring->rx_buffer_info);
  4116. rx_ring->rx_buffer_info = NULL;
  4117. dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
  4118. return -ENOMEM;
  4119. }
  4120. /**
  4121. * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
  4122. * @adapter: board private structure
  4123. *
  4124. * If this function returns with an error, then it's possible one or
  4125. * more of the rings is populated (while the rest are not). It is the
  4126. * callers duty to clean those orphaned rings.
  4127. *
  4128. * Return 0 on success, negative on failure
  4129. **/
  4130. static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
  4131. {
  4132. int i, err = 0;
  4133. for (i = 0; i < adapter->num_rx_queues; i++) {
  4134. err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
  4135. if (!err)
  4136. continue;
  4137. e_err(probe, "Allocation for Rx Queue %u failed\n", i);
  4138. goto err_setup_rx;
  4139. }
  4140. #ifdef IXGBE_FCOE
  4141. err = ixgbe_setup_fcoe_ddp_resources(adapter);
  4142. if (!err)
  4143. #endif
  4144. return 0;
  4145. err_setup_rx:
  4146. /* rewind the index freeing the rings as we go */
  4147. while (i--)
  4148. ixgbe_free_rx_resources(adapter->rx_ring[i]);
  4149. return err;
  4150. }
  4151. /**
  4152. * ixgbe_free_tx_resources - Free Tx Resources per Queue
  4153. * @tx_ring: Tx descriptor ring for a specific queue
  4154. *
  4155. * Free all transmit software resources
  4156. **/
  4157. void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
  4158. {
  4159. ixgbe_clean_tx_ring(tx_ring);
  4160. vfree(tx_ring->tx_buffer_info);
  4161. tx_ring->tx_buffer_info = NULL;
  4162. /* if not set, then don't free */
  4163. if (!tx_ring->desc)
  4164. return;
  4165. dma_free_coherent(tx_ring->dev, tx_ring->size,
  4166. tx_ring->desc, tx_ring->dma);
  4167. tx_ring->desc = NULL;
  4168. }
  4169. /**
  4170. * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
  4171. * @adapter: board private structure
  4172. *
  4173. * Free all transmit software resources
  4174. **/
  4175. static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
  4176. {
  4177. int i;
  4178. for (i = 0; i < adapter->num_tx_queues; i++)
  4179. if (adapter->tx_ring[i]->desc)
  4180. ixgbe_free_tx_resources(adapter->tx_ring[i]);
  4181. }
  4182. /**
  4183. * ixgbe_free_rx_resources - Free Rx Resources
  4184. * @rx_ring: ring to clean the resources from
  4185. *
  4186. * Free all receive software resources
  4187. **/
  4188. void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
  4189. {
  4190. ixgbe_clean_rx_ring(rx_ring);
  4191. vfree(rx_ring->rx_buffer_info);
  4192. rx_ring->rx_buffer_info = NULL;
  4193. /* if not set, then don't free */
  4194. if (!rx_ring->desc)
  4195. return;
  4196. dma_free_coherent(rx_ring->dev, rx_ring->size,
  4197. rx_ring->desc, rx_ring->dma);
  4198. rx_ring->desc = NULL;
  4199. }
  4200. /**
  4201. * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
  4202. * @adapter: board private structure
  4203. *
  4204. * Free all receive software resources
  4205. **/
  4206. static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
  4207. {
  4208. int i;
  4209. #ifdef IXGBE_FCOE
  4210. ixgbe_free_fcoe_ddp_resources(adapter);
  4211. #endif
  4212. for (i = 0; i < adapter->num_rx_queues; i++)
  4213. if (adapter->rx_ring[i]->desc)
  4214. ixgbe_free_rx_resources(adapter->rx_ring[i]);
  4215. }
  4216. /**
  4217. * ixgbe_change_mtu - Change the Maximum Transfer Unit
  4218. * @netdev: network interface device structure
  4219. * @new_mtu: new value for maximum frame size
  4220. *
  4221. * Returns 0 on success, negative on failure
  4222. **/
  4223. static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
  4224. {
  4225. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4226. int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
  4227. /* MTU < 68 is an error and causes problems on some kernels */
  4228. if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
  4229. return -EINVAL;
  4230. /*
  4231. * For 82599EB we cannot allow legacy VFs to enable their receive
  4232. * paths when MTU greater than 1500 is configured. So display a
  4233. * warning that legacy VFs will be disabled.
  4234. */
  4235. if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
  4236. (adapter->hw.mac.type == ixgbe_mac_82599EB) &&
  4237. (max_frame > (ETH_FRAME_LEN + ETH_FCS_LEN)))
  4238. e_warn(probe, "Setting MTU > 1500 will disable legacy VFs\n");
  4239. e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
  4240. /* must set new MTU before calling down or up */
  4241. netdev->mtu = new_mtu;
  4242. if (netif_running(netdev))
  4243. ixgbe_reinit_locked(adapter);
  4244. return 0;
  4245. }
  4246. /**
  4247. * ixgbe_open - Called when a network interface is made active
  4248. * @netdev: network interface device structure
  4249. *
  4250. * Returns 0 on success, negative value on failure
  4251. *
  4252. * The open entry point is called when a network interface is made
  4253. * active by the system (IFF_UP). At this point all resources needed
  4254. * for transmit and receive operations are allocated, the interrupt
  4255. * handler is registered with the OS, the watchdog timer is started,
  4256. * and the stack is notified that the interface is ready.
  4257. **/
  4258. static int ixgbe_open(struct net_device *netdev)
  4259. {
  4260. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4261. int err;
  4262. /* disallow open during test */
  4263. if (test_bit(__IXGBE_TESTING, &adapter->state))
  4264. return -EBUSY;
  4265. netif_carrier_off(netdev);
  4266. /* allocate transmit descriptors */
  4267. err = ixgbe_setup_all_tx_resources(adapter);
  4268. if (err)
  4269. goto err_setup_tx;
  4270. /* allocate receive descriptors */
  4271. err = ixgbe_setup_all_rx_resources(adapter);
  4272. if (err)
  4273. goto err_setup_rx;
  4274. ixgbe_configure(adapter);
  4275. err = ixgbe_request_irq(adapter);
  4276. if (err)
  4277. goto err_req_irq;
  4278. /* Notify the stack of the actual queue counts. */
  4279. err = netif_set_real_num_tx_queues(netdev,
  4280. adapter->num_rx_pools > 1 ? 1 :
  4281. adapter->num_tx_queues);
  4282. if (err)
  4283. goto err_set_queues;
  4284. err = netif_set_real_num_rx_queues(netdev,
  4285. adapter->num_rx_pools > 1 ? 1 :
  4286. adapter->num_rx_queues);
  4287. if (err)
  4288. goto err_set_queues;
  4289. ixgbe_ptp_init(adapter);
  4290. ixgbe_up_complete(adapter);
  4291. return 0;
  4292. err_set_queues:
  4293. ixgbe_free_irq(adapter);
  4294. err_req_irq:
  4295. ixgbe_free_all_rx_resources(adapter);
  4296. err_setup_rx:
  4297. ixgbe_free_all_tx_resources(adapter);
  4298. err_setup_tx:
  4299. ixgbe_reset(adapter);
  4300. return err;
  4301. }
  4302. /**
  4303. * ixgbe_close - Disables a network interface
  4304. * @netdev: network interface device structure
  4305. *
  4306. * Returns 0, this is not allowed to fail
  4307. *
  4308. * The close entry point is called when an interface is de-activated
  4309. * by the OS. The hardware is still under the drivers control, but
  4310. * needs to be disabled. A global MAC reset is issued to stop the
  4311. * hardware, and all transmit and receive resources are freed.
  4312. **/
  4313. static int ixgbe_close(struct net_device *netdev)
  4314. {
  4315. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  4316. ixgbe_ptp_stop(adapter);
  4317. ixgbe_down(adapter);
  4318. ixgbe_free_irq(adapter);
  4319. ixgbe_fdir_filter_exit(adapter);
  4320. ixgbe_free_all_tx_resources(adapter);
  4321. ixgbe_free_all_rx_resources(adapter);
  4322. ixgbe_release_hw_control(adapter);
  4323. return 0;
  4324. }
  4325. #ifdef CONFIG_PM
  4326. static int ixgbe_resume(struct pci_dev *pdev)
  4327. {
  4328. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  4329. struct net_device *netdev = adapter->netdev;
  4330. u32 err;
  4331. pci_set_power_state(pdev, PCI_D0);
  4332. pci_restore_state(pdev);
  4333. /*
  4334. * pci_restore_state clears dev->state_saved so call
  4335. * pci_save_state to restore it.
  4336. */
  4337. pci_save_state(pdev);
  4338. err = pci_enable_device_mem(pdev);
  4339. if (err) {
  4340. e_dev_err("Cannot enable PCI device from suspend\n");
  4341. return err;
  4342. }
  4343. pci_set_master(pdev);
  4344. pci_wake_from_d3(pdev, false);
  4345. ixgbe_reset(adapter);
  4346. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  4347. rtnl_lock();
  4348. err = ixgbe_init_interrupt_scheme(adapter);
  4349. if (!err && netif_running(netdev))
  4350. err = ixgbe_open(netdev);
  4351. rtnl_unlock();
  4352. if (err)
  4353. return err;
  4354. netif_device_attach(netdev);
  4355. return 0;
  4356. }
  4357. #endif /* CONFIG_PM */
  4358. static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
  4359. {
  4360. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  4361. struct net_device *netdev = adapter->netdev;
  4362. struct ixgbe_hw *hw = &adapter->hw;
  4363. u32 ctrl, fctrl;
  4364. u32 wufc = adapter->wol;
  4365. #ifdef CONFIG_PM
  4366. int retval = 0;
  4367. #endif
  4368. netif_device_detach(netdev);
  4369. rtnl_lock();
  4370. if (netif_running(netdev)) {
  4371. ixgbe_down(adapter);
  4372. ixgbe_free_irq(adapter);
  4373. ixgbe_free_all_tx_resources(adapter);
  4374. ixgbe_free_all_rx_resources(adapter);
  4375. }
  4376. rtnl_unlock();
  4377. ixgbe_clear_interrupt_scheme(adapter);
  4378. #ifdef CONFIG_PM
  4379. retval = pci_save_state(pdev);
  4380. if (retval)
  4381. return retval;
  4382. #endif
  4383. if (wufc) {
  4384. ixgbe_set_rx_mode(netdev);
  4385. /* enable the optics for 82599 SFP+ fiber as we can WoL */
  4386. if (hw->mac.ops.enable_tx_laser)
  4387. hw->mac.ops.enable_tx_laser(hw);
  4388. /* turn on all-multi mode if wake on multicast is enabled */
  4389. if (wufc & IXGBE_WUFC_MC) {
  4390. fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  4391. fctrl |= IXGBE_FCTRL_MPE;
  4392. IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
  4393. }
  4394. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  4395. ctrl |= IXGBE_CTRL_GIO_DIS;
  4396. IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
  4397. IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
  4398. } else {
  4399. IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
  4400. IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
  4401. }
  4402. switch (hw->mac.type) {
  4403. case ixgbe_mac_82598EB:
  4404. pci_wake_from_d3(pdev, false);
  4405. break;
  4406. case ixgbe_mac_82599EB:
  4407. case ixgbe_mac_X540:
  4408. pci_wake_from_d3(pdev, !!wufc);
  4409. break;
  4410. default:
  4411. break;
  4412. }
  4413. *enable_wake = !!wufc;
  4414. ixgbe_release_hw_control(adapter);
  4415. pci_disable_device(pdev);
  4416. return 0;
  4417. }
  4418. #ifdef CONFIG_PM
  4419. static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
  4420. {
  4421. int retval;
  4422. bool wake;
  4423. retval = __ixgbe_shutdown(pdev, &wake);
  4424. if (retval)
  4425. return retval;
  4426. if (wake) {
  4427. pci_prepare_to_sleep(pdev);
  4428. } else {
  4429. pci_wake_from_d3(pdev, false);
  4430. pci_set_power_state(pdev, PCI_D3hot);
  4431. }
  4432. return 0;
  4433. }
  4434. #endif /* CONFIG_PM */
  4435. static void ixgbe_shutdown(struct pci_dev *pdev)
  4436. {
  4437. bool wake;
  4438. __ixgbe_shutdown(pdev, &wake);
  4439. if (system_state == SYSTEM_POWER_OFF) {
  4440. pci_wake_from_d3(pdev, wake);
  4441. pci_set_power_state(pdev, PCI_D3hot);
  4442. }
  4443. }
  4444. /**
  4445. * ixgbe_update_stats - Update the board statistics counters.
  4446. * @adapter: board private structure
  4447. **/
  4448. void ixgbe_update_stats(struct ixgbe_adapter *adapter)
  4449. {
  4450. struct net_device *netdev = adapter->netdev;
  4451. struct ixgbe_hw *hw = &adapter->hw;
  4452. struct ixgbe_hw_stats *hwstats = &adapter->stats;
  4453. u64 total_mpc = 0;
  4454. u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
  4455. u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
  4456. u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
  4457. u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
  4458. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  4459. test_bit(__IXGBE_RESETTING, &adapter->state))
  4460. return;
  4461. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
  4462. u64 rsc_count = 0;
  4463. u64 rsc_flush = 0;
  4464. for (i = 0; i < adapter->num_rx_queues; i++) {
  4465. rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
  4466. rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
  4467. }
  4468. adapter->rsc_total_count = rsc_count;
  4469. adapter->rsc_total_flush = rsc_flush;
  4470. }
  4471. for (i = 0; i < adapter->num_rx_queues; i++) {
  4472. struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
  4473. non_eop_descs += rx_ring->rx_stats.non_eop_descs;
  4474. alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
  4475. alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
  4476. hw_csum_rx_error += rx_ring->rx_stats.csum_err;
  4477. bytes += rx_ring->stats.bytes;
  4478. packets += rx_ring->stats.packets;
  4479. }
  4480. adapter->non_eop_descs = non_eop_descs;
  4481. adapter->alloc_rx_page_failed = alloc_rx_page_failed;
  4482. adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
  4483. adapter->hw_csum_rx_error = hw_csum_rx_error;
  4484. netdev->stats.rx_bytes = bytes;
  4485. netdev->stats.rx_packets = packets;
  4486. bytes = 0;
  4487. packets = 0;
  4488. /* gather some stats to the adapter struct that are per queue */
  4489. for (i = 0; i < adapter->num_tx_queues; i++) {
  4490. struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
  4491. restart_queue += tx_ring->tx_stats.restart_queue;
  4492. tx_busy += tx_ring->tx_stats.tx_busy;
  4493. bytes += tx_ring->stats.bytes;
  4494. packets += tx_ring->stats.packets;
  4495. }
  4496. adapter->restart_queue = restart_queue;
  4497. adapter->tx_busy = tx_busy;
  4498. netdev->stats.tx_bytes = bytes;
  4499. netdev->stats.tx_packets = packets;
  4500. hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
  4501. /* 8 register reads */
  4502. for (i = 0; i < 8; i++) {
  4503. /* for packet buffers not used, the register should read 0 */
  4504. mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
  4505. missed_rx += mpc;
  4506. hwstats->mpc[i] += mpc;
  4507. total_mpc += hwstats->mpc[i];
  4508. hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
  4509. hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
  4510. switch (hw->mac.type) {
  4511. case ixgbe_mac_82598EB:
  4512. hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
  4513. hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
  4514. hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
  4515. hwstats->pxonrxc[i] +=
  4516. IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
  4517. break;
  4518. case ixgbe_mac_82599EB:
  4519. case ixgbe_mac_X540:
  4520. hwstats->pxonrxc[i] +=
  4521. IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
  4522. break;
  4523. default:
  4524. break;
  4525. }
  4526. }
  4527. /*16 register reads */
  4528. for (i = 0; i < 16; i++) {
  4529. hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
  4530. hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
  4531. if ((hw->mac.type == ixgbe_mac_82599EB) ||
  4532. (hw->mac.type == ixgbe_mac_X540)) {
  4533. hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
  4534. IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
  4535. hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
  4536. IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
  4537. }
  4538. }
  4539. hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
  4540. /* work around hardware counting issue */
  4541. hwstats->gprc -= missed_rx;
  4542. ixgbe_update_xoff_received(adapter);
  4543. /* 82598 hardware only has a 32 bit counter in the high register */
  4544. switch (hw->mac.type) {
  4545. case ixgbe_mac_82598EB:
  4546. hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
  4547. hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
  4548. hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
  4549. hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
  4550. break;
  4551. case ixgbe_mac_X540:
  4552. /* OS2BMC stats are X540 only*/
  4553. hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
  4554. hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
  4555. hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
  4556. hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
  4557. case ixgbe_mac_82599EB:
  4558. for (i = 0; i < 16; i++)
  4559. adapter->hw_rx_no_dma_resources +=
  4560. IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
  4561. hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
  4562. IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
  4563. hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
  4564. IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
  4565. hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
  4566. IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
  4567. hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
  4568. hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
  4569. hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
  4570. #ifdef IXGBE_FCOE
  4571. hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
  4572. hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
  4573. hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
  4574. hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
  4575. hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
  4576. hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
  4577. /* Add up per cpu counters for total ddp aloc fail */
  4578. if (adapter->fcoe.ddp_pool) {
  4579. struct ixgbe_fcoe *fcoe = &adapter->fcoe;
  4580. struct ixgbe_fcoe_ddp_pool *ddp_pool;
  4581. unsigned int cpu;
  4582. u64 noddp = 0, noddp_ext_buff = 0;
  4583. for_each_possible_cpu(cpu) {
  4584. ddp_pool = per_cpu_ptr(fcoe->ddp_pool, cpu);
  4585. noddp += ddp_pool->noddp;
  4586. noddp_ext_buff += ddp_pool->noddp_ext_buff;
  4587. }
  4588. hwstats->fcoe_noddp = noddp;
  4589. hwstats->fcoe_noddp_ext_buff = noddp_ext_buff;
  4590. }
  4591. #endif /* IXGBE_FCOE */
  4592. break;
  4593. default:
  4594. break;
  4595. }
  4596. bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
  4597. hwstats->bprc += bprc;
  4598. hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
  4599. if (hw->mac.type == ixgbe_mac_82598EB)
  4600. hwstats->mprc -= bprc;
  4601. hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
  4602. hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
  4603. hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
  4604. hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
  4605. hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
  4606. hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
  4607. hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
  4608. hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
  4609. lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
  4610. hwstats->lxontxc += lxon;
  4611. lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
  4612. hwstats->lxofftxc += lxoff;
  4613. hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
  4614. hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
  4615. /*
  4616. * 82598 errata - tx of flow control packets is included in tx counters
  4617. */
  4618. xon_off_tot = lxon + lxoff;
  4619. hwstats->gptc -= xon_off_tot;
  4620. hwstats->mptc -= xon_off_tot;
  4621. hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
  4622. hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
  4623. hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
  4624. hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
  4625. hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
  4626. hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
  4627. hwstats->ptc64 -= xon_off_tot;
  4628. hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
  4629. hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
  4630. hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
  4631. hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
  4632. hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
  4633. hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
  4634. /* Fill out the OS statistics structure */
  4635. netdev->stats.multicast = hwstats->mprc;
  4636. /* Rx Errors */
  4637. netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
  4638. netdev->stats.rx_dropped = 0;
  4639. netdev->stats.rx_length_errors = hwstats->rlec;
  4640. netdev->stats.rx_crc_errors = hwstats->crcerrs;
  4641. netdev->stats.rx_missed_errors = total_mpc;
  4642. }
  4643. /**
  4644. * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
  4645. * @adapter: pointer to the device adapter structure
  4646. **/
  4647. static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
  4648. {
  4649. struct ixgbe_hw *hw = &adapter->hw;
  4650. int i;
  4651. if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
  4652. return;
  4653. adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
  4654. /* if interface is down do nothing */
  4655. if (test_bit(__IXGBE_DOWN, &adapter->state))
  4656. return;
  4657. /* do nothing if we are not using signature filters */
  4658. if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
  4659. return;
  4660. adapter->fdir_overflow++;
  4661. if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
  4662. for (i = 0; i < adapter->num_tx_queues; i++)
  4663. set_bit(__IXGBE_TX_FDIR_INIT_DONE,
  4664. &(adapter->tx_ring[i]->state));
  4665. /* re-enable flow director interrupts */
  4666. IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
  4667. } else {
  4668. e_err(probe, "failed to finish FDIR re-initialization, "
  4669. "ignored adding FDIR ATR filters\n");
  4670. }
  4671. }
  4672. /**
  4673. * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
  4674. * @adapter: pointer to the device adapter structure
  4675. *
  4676. * This function serves two purposes. First it strobes the interrupt lines
  4677. * in order to make certain interrupts are occurring. Secondly it sets the
  4678. * bits needed to check for TX hangs. As a result we should immediately
  4679. * determine if a hang has occurred.
  4680. */
  4681. static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
  4682. {
  4683. struct ixgbe_hw *hw = &adapter->hw;
  4684. u64 eics = 0;
  4685. int i;
  4686. /* If we're down or resetting, just bail */
  4687. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  4688. test_bit(__IXGBE_RESETTING, &adapter->state))
  4689. return;
  4690. /* Force detection of hung controller */
  4691. if (netif_carrier_ok(adapter->netdev)) {
  4692. for (i = 0; i < adapter->num_tx_queues; i++)
  4693. set_check_for_tx_hang(adapter->tx_ring[i]);
  4694. }
  4695. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
  4696. /*
  4697. * for legacy and MSI interrupts don't set any bits
  4698. * that are enabled for EIAM, because this operation
  4699. * would set *both* EIMS and EICS for any bit in EIAM
  4700. */
  4701. IXGBE_WRITE_REG(hw, IXGBE_EICS,
  4702. (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
  4703. } else {
  4704. /* get one bit for every active tx/rx interrupt vector */
  4705. for (i = 0; i < adapter->num_q_vectors; i++) {
  4706. struct ixgbe_q_vector *qv = adapter->q_vector[i];
  4707. if (qv->rx.ring || qv->tx.ring)
  4708. eics |= ((u64)1 << i);
  4709. }
  4710. }
  4711. /* Cause software interrupt to ensure rings are cleaned */
  4712. ixgbe_irq_rearm_queues(adapter, eics);
  4713. }
  4714. /**
  4715. * ixgbe_watchdog_update_link - update the link status
  4716. * @adapter: pointer to the device adapter structure
  4717. * @link_speed: pointer to a u32 to store the link_speed
  4718. **/
  4719. static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
  4720. {
  4721. struct ixgbe_hw *hw = &adapter->hw;
  4722. u32 link_speed = adapter->link_speed;
  4723. bool link_up = adapter->link_up;
  4724. bool pfc_en = adapter->dcb_cfg.pfc_mode_enable;
  4725. if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
  4726. return;
  4727. if (hw->mac.ops.check_link) {
  4728. hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
  4729. } else {
  4730. /* always assume link is up, if no check link function */
  4731. link_speed = IXGBE_LINK_SPEED_10GB_FULL;
  4732. link_up = true;
  4733. }
  4734. if (adapter->ixgbe_ieee_pfc)
  4735. pfc_en |= !!(adapter->ixgbe_ieee_pfc->pfc_en);
  4736. if (link_up && !((adapter->flags & IXGBE_FLAG_DCB_ENABLED) && pfc_en)) {
  4737. hw->mac.ops.fc_enable(hw);
  4738. ixgbe_set_rx_drop_en(adapter);
  4739. }
  4740. if (link_up ||
  4741. time_after(jiffies, (adapter->link_check_timeout +
  4742. IXGBE_TRY_LINK_TIMEOUT))) {
  4743. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
  4744. IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
  4745. IXGBE_WRITE_FLUSH(hw);
  4746. }
  4747. adapter->link_up = link_up;
  4748. adapter->link_speed = link_speed;
  4749. }
  4750. static void ixgbe_update_default_up(struct ixgbe_adapter *adapter)
  4751. {
  4752. #ifdef CONFIG_IXGBE_DCB
  4753. struct net_device *netdev = adapter->netdev;
  4754. struct dcb_app app = {
  4755. .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE,
  4756. .protocol = 0,
  4757. };
  4758. u8 up = 0;
  4759. if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_IEEE)
  4760. up = dcb_ieee_getapp_mask(netdev, &app);
  4761. adapter->default_up = (up > 1) ? (ffs(up) - 1) : 0;
  4762. #endif
  4763. }
  4764. /**
  4765. * ixgbe_watchdog_link_is_up - update netif_carrier status and
  4766. * print link up message
  4767. * @adapter: pointer to the device adapter structure
  4768. **/
  4769. static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
  4770. {
  4771. struct net_device *netdev = adapter->netdev;
  4772. struct ixgbe_hw *hw = &adapter->hw;
  4773. u32 link_speed = adapter->link_speed;
  4774. bool flow_rx, flow_tx;
  4775. /* only continue if link was previously down */
  4776. if (netif_carrier_ok(netdev))
  4777. return;
  4778. adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
  4779. switch (hw->mac.type) {
  4780. case ixgbe_mac_82598EB: {
  4781. u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
  4782. u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
  4783. flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
  4784. flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
  4785. }
  4786. break;
  4787. case ixgbe_mac_X540:
  4788. case ixgbe_mac_82599EB: {
  4789. u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
  4790. u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
  4791. flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
  4792. flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
  4793. }
  4794. break;
  4795. default:
  4796. flow_tx = false;
  4797. flow_rx = false;
  4798. break;
  4799. }
  4800. adapter->last_rx_ptp_check = jiffies;
  4801. if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
  4802. ixgbe_ptp_start_cyclecounter(adapter);
  4803. e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
  4804. (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
  4805. "10 Gbps" :
  4806. (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
  4807. "1 Gbps" :
  4808. (link_speed == IXGBE_LINK_SPEED_100_FULL ?
  4809. "100 Mbps" :
  4810. "unknown speed"))),
  4811. ((flow_rx && flow_tx) ? "RX/TX" :
  4812. (flow_rx ? "RX" :
  4813. (flow_tx ? "TX" : "None"))));
  4814. netif_carrier_on(netdev);
  4815. ixgbe_check_vf_rate_limit(adapter);
  4816. /* update the default user priority for VFs */
  4817. ixgbe_update_default_up(adapter);
  4818. /* ping all the active vfs to let them know link has changed */
  4819. ixgbe_ping_all_vfs(adapter);
  4820. }
  4821. /**
  4822. * ixgbe_watchdog_link_is_down - update netif_carrier status and
  4823. * print link down message
  4824. * @adapter: pointer to the adapter structure
  4825. **/
  4826. static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter *adapter)
  4827. {
  4828. struct net_device *netdev = adapter->netdev;
  4829. struct ixgbe_hw *hw = &adapter->hw;
  4830. adapter->link_up = false;
  4831. adapter->link_speed = 0;
  4832. /* only continue if link was up previously */
  4833. if (!netif_carrier_ok(netdev))
  4834. return;
  4835. /* poll for SFP+ cable when link is down */
  4836. if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
  4837. adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
  4838. if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED)
  4839. ixgbe_ptp_start_cyclecounter(adapter);
  4840. e_info(drv, "NIC Link is Down\n");
  4841. netif_carrier_off(netdev);
  4842. /* ping all the active vfs to let them know link has changed */
  4843. ixgbe_ping_all_vfs(adapter);
  4844. }
  4845. /**
  4846. * ixgbe_watchdog_flush_tx - flush queues on link down
  4847. * @adapter: pointer to the device adapter structure
  4848. **/
  4849. static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
  4850. {
  4851. int i;
  4852. int some_tx_pending = 0;
  4853. if (!netif_carrier_ok(adapter->netdev)) {
  4854. for (i = 0; i < adapter->num_tx_queues; i++) {
  4855. struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
  4856. if (tx_ring->next_to_use != tx_ring->next_to_clean) {
  4857. some_tx_pending = 1;
  4858. break;
  4859. }
  4860. }
  4861. if (some_tx_pending) {
  4862. /* We've lost link, so the controller stops DMA,
  4863. * but we've got queued Tx work that's never going
  4864. * to get done, so reset controller to flush Tx.
  4865. * (Do the reset outside of interrupt context).
  4866. */
  4867. e_warn(drv, "initiating reset to clear Tx work after link loss\n");
  4868. adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
  4869. }
  4870. }
  4871. }
  4872. static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
  4873. {
  4874. u32 ssvpc;
  4875. /* Do not perform spoof check for 82598 or if not in IOV mode */
  4876. if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
  4877. adapter->num_vfs == 0)
  4878. return;
  4879. ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
  4880. /*
  4881. * ssvpc register is cleared on read, if zero then no
  4882. * spoofed packets in the last interval.
  4883. */
  4884. if (!ssvpc)
  4885. return;
  4886. e_warn(drv, "%u Spoofed packets detected\n", ssvpc);
  4887. }
  4888. /**
  4889. * ixgbe_watchdog_subtask - check and bring link up
  4890. * @adapter: pointer to the device adapter structure
  4891. **/
  4892. static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
  4893. {
  4894. /* if interface is down do nothing */
  4895. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  4896. test_bit(__IXGBE_RESETTING, &adapter->state))
  4897. return;
  4898. ixgbe_watchdog_update_link(adapter);
  4899. if (adapter->link_up)
  4900. ixgbe_watchdog_link_is_up(adapter);
  4901. else
  4902. ixgbe_watchdog_link_is_down(adapter);
  4903. ixgbe_spoof_check(adapter);
  4904. ixgbe_update_stats(adapter);
  4905. ixgbe_watchdog_flush_tx(adapter);
  4906. }
  4907. /**
  4908. * ixgbe_sfp_detection_subtask - poll for SFP+ cable
  4909. * @adapter: the ixgbe adapter structure
  4910. **/
  4911. static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
  4912. {
  4913. struct ixgbe_hw *hw = &adapter->hw;
  4914. s32 err;
  4915. /* not searching for SFP so there is nothing to do here */
  4916. if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
  4917. !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
  4918. return;
  4919. /* concurent i2c reads are not supported */
  4920. if (test_bit(__IXGBE_READ_I2C, &adapter->state))
  4921. return;
  4922. /* someone else is in init, wait until next service event */
  4923. if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
  4924. return;
  4925. err = hw->phy.ops.identify_sfp(hw);
  4926. if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
  4927. goto sfp_out;
  4928. if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
  4929. /* If no cable is present, then we need to reset
  4930. * the next time we find a good cable. */
  4931. adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
  4932. }
  4933. /* exit on error */
  4934. if (err)
  4935. goto sfp_out;
  4936. /* exit if reset not needed */
  4937. if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
  4938. goto sfp_out;
  4939. adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
  4940. /*
  4941. * A module may be identified correctly, but the EEPROM may not have
  4942. * support for that module. setup_sfp() will fail in that case, so
  4943. * we should not allow that module to load.
  4944. */
  4945. if (hw->mac.type == ixgbe_mac_82598EB)
  4946. err = hw->phy.ops.reset(hw);
  4947. else
  4948. err = hw->mac.ops.setup_sfp(hw);
  4949. if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
  4950. goto sfp_out;
  4951. adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
  4952. e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
  4953. sfp_out:
  4954. clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
  4955. if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
  4956. (adapter->netdev->reg_state == NETREG_REGISTERED)) {
  4957. e_dev_err("failed to initialize because an unsupported "
  4958. "SFP+ module type was detected.\n");
  4959. e_dev_err("Reload the driver after installing a "
  4960. "supported module.\n");
  4961. unregister_netdev(adapter->netdev);
  4962. }
  4963. }
  4964. /**
  4965. * ixgbe_sfp_link_config_subtask - set up link SFP after module install
  4966. * @adapter: the ixgbe adapter structure
  4967. **/
  4968. static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
  4969. {
  4970. struct ixgbe_hw *hw = &adapter->hw;
  4971. u32 speed;
  4972. bool autoneg = false;
  4973. if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
  4974. return;
  4975. /* someone else is in init, wait until next service event */
  4976. if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
  4977. return;
  4978. adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
  4979. speed = hw->phy.autoneg_advertised;
  4980. if ((!speed) && (hw->mac.ops.get_link_capabilities))
  4981. hw->mac.ops.get_link_capabilities(hw, &speed, &autoneg);
  4982. if (hw->mac.ops.setup_link)
  4983. hw->mac.ops.setup_link(hw, speed, true);
  4984. adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
  4985. adapter->link_check_timeout = jiffies;
  4986. clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
  4987. }
  4988. #ifdef CONFIG_PCI_IOV
  4989. static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
  4990. {
  4991. int vf;
  4992. struct ixgbe_hw *hw = &adapter->hw;
  4993. struct net_device *netdev = adapter->netdev;
  4994. u32 gpc;
  4995. u32 ciaa, ciad;
  4996. gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
  4997. if (gpc) /* If incrementing then no need for the check below */
  4998. return;
  4999. /*
  5000. * Check to see if a bad DMA write target from an errant or
  5001. * malicious VF has caused a PCIe error. If so then we can
  5002. * issue a VFLR to the offending VF(s) and then resume without
  5003. * requesting a full slot reset.
  5004. */
  5005. for (vf = 0; vf < adapter->num_vfs; vf++) {
  5006. ciaa = (vf << 16) | 0x80000000;
  5007. /* 32 bit read so align, we really want status at offset 6 */
  5008. ciaa |= PCI_COMMAND;
  5009. IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
  5010. ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
  5011. ciaa &= 0x7FFFFFFF;
  5012. /* disable debug mode asap after reading data */
  5013. IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
  5014. /* Get the upper 16 bits which will be the PCI status reg */
  5015. ciad >>= 16;
  5016. if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
  5017. netdev_err(netdev, "VF %d Hung DMA\n", vf);
  5018. /* Issue VFLR */
  5019. ciaa = (vf << 16) | 0x80000000;
  5020. ciaa |= 0xA8;
  5021. IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
  5022. ciad = 0x00008000; /* VFLR */
  5023. IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
  5024. ciaa &= 0x7FFFFFFF;
  5025. IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
  5026. }
  5027. }
  5028. }
  5029. #endif
  5030. /**
  5031. * ixgbe_service_timer - Timer Call-back
  5032. * @data: pointer to adapter cast into an unsigned long
  5033. **/
  5034. static void ixgbe_service_timer(unsigned long data)
  5035. {
  5036. struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
  5037. unsigned long next_event_offset;
  5038. bool ready = true;
  5039. /* poll faster when waiting for link */
  5040. if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
  5041. next_event_offset = HZ / 10;
  5042. else
  5043. next_event_offset = HZ * 2;
  5044. #ifdef CONFIG_PCI_IOV
  5045. /*
  5046. * don't bother with SR-IOV VF DMA hang check if there are
  5047. * no VFs or the link is down
  5048. */
  5049. if (!adapter->num_vfs ||
  5050. (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
  5051. goto normal_timer_service;
  5052. /* If we have VFs allocated then we must check for DMA hangs */
  5053. ixgbe_check_for_bad_vf(adapter);
  5054. next_event_offset = HZ / 50;
  5055. adapter->timer_event_accumulator++;
  5056. if (adapter->timer_event_accumulator >= 100)
  5057. adapter->timer_event_accumulator = 0;
  5058. else
  5059. ready = false;
  5060. normal_timer_service:
  5061. #endif
  5062. /* Reset the timer */
  5063. mod_timer(&adapter->service_timer, next_event_offset + jiffies);
  5064. if (ready)
  5065. ixgbe_service_event_schedule(adapter);
  5066. }
  5067. static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
  5068. {
  5069. if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
  5070. return;
  5071. adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
  5072. /* If we're already down or resetting, just bail */
  5073. if (test_bit(__IXGBE_DOWN, &adapter->state) ||
  5074. test_bit(__IXGBE_RESETTING, &adapter->state))
  5075. return;
  5076. ixgbe_dump(adapter);
  5077. netdev_err(adapter->netdev, "Reset adapter\n");
  5078. adapter->tx_timeout_count++;
  5079. ixgbe_reinit_locked(adapter);
  5080. }
  5081. /**
  5082. * ixgbe_service_task - manages and runs subtasks
  5083. * @work: pointer to work_struct containing our data
  5084. **/
  5085. static void ixgbe_service_task(struct work_struct *work)
  5086. {
  5087. struct ixgbe_adapter *adapter = container_of(work,
  5088. struct ixgbe_adapter,
  5089. service_task);
  5090. ixgbe_reset_subtask(adapter);
  5091. ixgbe_sfp_detection_subtask(adapter);
  5092. ixgbe_sfp_link_config_subtask(adapter);
  5093. ixgbe_check_overtemp_subtask(adapter);
  5094. ixgbe_watchdog_subtask(adapter);
  5095. ixgbe_fdir_reinit_subtask(adapter);
  5096. ixgbe_check_hang_subtask(adapter);
  5097. if (adapter->flags2 & IXGBE_FLAG2_PTP_ENABLED) {
  5098. ixgbe_ptp_overflow_check(adapter);
  5099. ixgbe_ptp_rx_hang(adapter);
  5100. }
  5101. ixgbe_service_event_complete(adapter);
  5102. }
  5103. static int ixgbe_tso(struct ixgbe_ring *tx_ring,
  5104. struct ixgbe_tx_buffer *first,
  5105. u8 *hdr_len)
  5106. {
  5107. struct sk_buff *skb = first->skb;
  5108. u32 vlan_macip_lens, type_tucmd;
  5109. u32 mss_l4len_idx, l4len;
  5110. if (skb->ip_summed != CHECKSUM_PARTIAL)
  5111. return 0;
  5112. if (!skb_is_gso(skb))
  5113. return 0;
  5114. if (skb_header_cloned(skb)) {
  5115. int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
  5116. if (err)
  5117. return err;
  5118. }
  5119. /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
  5120. type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
  5121. if (first->protocol == __constant_htons(ETH_P_IP)) {
  5122. struct iphdr *iph = ip_hdr(skb);
  5123. iph->tot_len = 0;
  5124. iph->check = 0;
  5125. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
  5126. iph->daddr, 0,
  5127. IPPROTO_TCP,
  5128. 0);
  5129. type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
  5130. first->tx_flags |= IXGBE_TX_FLAGS_TSO |
  5131. IXGBE_TX_FLAGS_CSUM |
  5132. IXGBE_TX_FLAGS_IPV4;
  5133. } else if (skb_is_gso_v6(skb)) {
  5134. ipv6_hdr(skb)->payload_len = 0;
  5135. tcp_hdr(skb)->check =
  5136. ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  5137. &ipv6_hdr(skb)->daddr,
  5138. 0, IPPROTO_TCP, 0);
  5139. first->tx_flags |= IXGBE_TX_FLAGS_TSO |
  5140. IXGBE_TX_FLAGS_CSUM;
  5141. }
  5142. /* compute header lengths */
  5143. l4len = tcp_hdrlen(skb);
  5144. *hdr_len = skb_transport_offset(skb) + l4len;
  5145. /* update gso size and bytecount with header size */
  5146. first->gso_segs = skb_shinfo(skb)->gso_segs;
  5147. first->bytecount += (first->gso_segs - 1) * *hdr_len;
  5148. /* mss_l4len_id: use 0 as index for TSO */
  5149. mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
  5150. mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
  5151. /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
  5152. vlan_macip_lens = skb_network_header_len(skb);
  5153. vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
  5154. vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
  5155. ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
  5156. mss_l4len_idx);
  5157. return 1;
  5158. }
  5159. static void ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
  5160. struct ixgbe_tx_buffer *first)
  5161. {
  5162. struct sk_buff *skb = first->skb;
  5163. u32 vlan_macip_lens = 0;
  5164. u32 mss_l4len_idx = 0;
  5165. u32 type_tucmd = 0;
  5166. if (skb->ip_summed != CHECKSUM_PARTIAL) {
  5167. if (!(first->tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
  5168. !(first->tx_flags & IXGBE_TX_FLAGS_CC))
  5169. return;
  5170. } else {
  5171. u8 l4_hdr = 0;
  5172. switch (first->protocol) {
  5173. case __constant_htons(ETH_P_IP):
  5174. vlan_macip_lens |= skb_network_header_len(skb);
  5175. type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
  5176. l4_hdr = ip_hdr(skb)->protocol;
  5177. break;
  5178. case __constant_htons(ETH_P_IPV6):
  5179. vlan_macip_lens |= skb_network_header_len(skb);
  5180. l4_hdr = ipv6_hdr(skb)->nexthdr;
  5181. break;
  5182. default:
  5183. if (unlikely(net_ratelimit())) {
  5184. dev_warn(tx_ring->dev,
  5185. "partial checksum but proto=%x!\n",
  5186. first->protocol);
  5187. }
  5188. break;
  5189. }
  5190. switch (l4_hdr) {
  5191. case IPPROTO_TCP:
  5192. type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
  5193. mss_l4len_idx = tcp_hdrlen(skb) <<
  5194. IXGBE_ADVTXD_L4LEN_SHIFT;
  5195. break;
  5196. case IPPROTO_SCTP:
  5197. type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
  5198. mss_l4len_idx = sizeof(struct sctphdr) <<
  5199. IXGBE_ADVTXD_L4LEN_SHIFT;
  5200. break;
  5201. case IPPROTO_UDP:
  5202. mss_l4len_idx = sizeof(struct udphdr) <<
  5203. IXGBE_ADVTXD_L4LEN_SHIFT;
  5204. break;
  5205. default:
  5206. if (unlikely(net_ratelimit())) {
  5207. dev_warn(tx_ring->dev,
  5208. "partial checksum but l4 proto=%x!\n",
  5209. l4_hdr);
  5210. }
  5211. break;
  5212. }
  5213. /* update TX checksum flag */
  5214. first->tx_flags |= IXGBE_TX_FLAGS_CSUM;
  5215. }
  5216. /* vlan_macip_lens: MACLEN, VLAN tag */
  5217. vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
  5218. vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
  5219. ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
  5220. type_tucmd, mss_l4len_idx);
  5221. }
  5222. #define IXGBE_SET_FLAG(_input, _flag, _result) \
  5223. ((_flag <= _result) ? \
  5224. ((u32)(_input & _flag) * (_result / _flag)) : \
  5225. ((u32)(_input & _flag) / (_flag / _result)))
  5226. static u32 ixgbe_tx_cmd_type(struct sk_buff *skb, u32 tx_flags)
  5227. {
  5228. /* set type for advanced descriptor with frame checksum insertion */
  5229. u32 cmd_type = IXGBE_ADVTXD_DTYP_DATA |
  5230. IXGBE_ADVTXD_DCMD_DEXT |
  5231. IXGBE_ADVTXD_DCMD_IFCS;
  5232. /* set HW vlan bit if vlan is present */
  5233. cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_HW_VLAN,
  5234. IXGBE_ADVTXD_DCMD_VLE);
  5235. /* set segmentation enable bits for TSO/FSO */
  5236. cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSO,
  5237. IXGBE_ADVTXD_DCMD_TSE);
  5238. /* set timestamp bit if present */
  5239. cmd_type |= IXGBE_SET_FLAG(tx_flags, IXGBE_TX_FLAGS_TSTAMP,
  5240. IXGBE_ADVTXD_MAC_TSTAMP);
  5241. /* insert frame checksum */
  5242. cmd_type ^= IXGBE_SET_FLAG(skb->no_fcs, 1, IXGBE_ADVTXD_DCMD_IFCS);
  5243. return cmd_type;
  5244. }
  5245. static void ixgbe_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc,
  5246. u32 tx_flags, unsigned int paylen)
  5247. {
  5248. u32 olinfo_status = paylen << IXGBE_ADVTXD_PAYLEN_SHIFT;
  5249. /* enable L4 checksum for TSO and TX checksum offload */
  5250. olinfo_status |= IXGBE_SET_FLAG(tx_flags,
  5251. IXGBE_TX_FLAGS_CSUM,
  5252. IXGBE_ADVTXD_POPTS_TXSM);
  5253. /* enble IPv4 checksum for TSO */
  5254. olinfo_status |= IXGBE_SET_FLAG(tx_flags,
  5255. IXGBE_TX_FLAGS_IPV4,
  5256. IXGBE_ADVTXD_POPTS_IXSM);
  5257. /*
  5258. * Check Context must be set if Tx switch is enabled, which it
  5259. * always is for case where virtual functions are running
  5260. */
  5261. olinfo_status |= IXGBE_SET_FLAG(tx_flags,
  5262. IXGBE_TX_FLAGS_CC,
  5263. IXGBE_ADVTXD_CC);
  5264. tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
  5265. }
  5266. #define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
  5267. IXGBE_TXD_CMD_RS)
  5268. static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
  5269. struct ixgbe_tx_buffer *first,
  5270. const u8 hdr_len)
  5271. {
  5272. struct sk_buff *skb = first->skb;
  5273. struct ixgbe_tx_buffer *tx_buffer;
  5274. union ixgbe_adv_tx_desc *tx_desc;
  5275. struct skb_frag_struct *frag;
  5276. dma_addr_t dma;
  5277. unsigned int data_len, size;
  5278. u32 tx_flags = first->tx_flags;
  5279. u32 cmd_type = ixgbe_tx_cmd_type(skb, tx_flags);
  5280. u16 i = tx_ring->next_to_use;
  5281. tx_desc = IXGBE_TX_DESC(tx_ring, i);
  5282. ixgbe_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len);
  5283. size = skb_headlen(skb);
  5284. data_len = skb->data_len;
  5285. #ifdef IXGBE_FCOE
  5286. if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
  5287. if (data_len < sizeof(struct fcoe_crc_eof)) {
  5288. size -= sizeof(struct fcoe_crc_eof) - data_len;
  5289. data_len = 0;
  5290. } else {
  5291. data_len -= sizeof(struct fcoe_crc_eof);
  5292. }
  5293. }
  5294. #endif
  5295. dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE);
  5296. tx_buffer = first;
  5297. for (frag = &skb_shinfo(skb)->frags[0];; frag++) {
  5298. if (dma_mapping_error(tx_ring->dev, dma))
  5299. goto dma_error;
  5300. /* record length, and DMA address */
  5301. dma_unmap_len_set(tx_buffer, len, size);
  5302. dma_unmap_addr_set(tx_buffer, dma, dma);
  5303. tx_desc->read.buffer_addr = cpu_to_le64(dma);
  5304. while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) {
  5305. tx_desc->read.cmd_type_len =
  5306. cpu_to_le32(cmd_type ^ IXGBE_MAX_DATA_PER_TXD);
  5307. i++;
  5308. tx_desc++;
  5309. if (i == tx_ring->count) {
  5310. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  5311. i = 0;
  5312. }
  5313. tx_desc->read.olinfo_status = 0;
  5314. dma += IXGBE_MAX_DATA_PER_TXD;
  5315. size -= IXGBE_MAX_DATA_PER_TXD;
  5316. tx_desc->read.buffer_addr = cpu_to_le64(dma);
  5317. }
  5318. if (likely(!data_len))
  5319. break;
  5320. tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type ^ size);
  5321. i++;
  5322. tx_desc++;
  5323. if (i == tx_ring->count) {
  5324. tx_desc = IXGBE_TX_DESC(tx_ring, 0);
  5325. i = 0;
  5326. }
  5327. tx_desc->read.olinfo_status = 0;
  5328. #ifdef IXGBE_FCOE
  5329. size = min_t(unsigned int, data_len, skb_frag_size(frag));
  5330. #else
  5331. size = skb_frag_size(frag);
  5332. #endif
  5333. data_len -= size;
  5334. dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size,
  5335. DMA_TO_DEVICE);
  5336. tx_buffer = &tx_ring->tx_buffer_info[i];
  5337. }
  5338. /* write last descriptor with RS and EOP bits */
  5339. cmd_type |= size | IXGBE_TXD_CMD;
  5340. tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type);
  5341. netdev_tx_sent_queue(txring_txq(tx_ring), first->bytecount);
  5342. /* set the timestamp */
  5343. first->time_stamp = jiffies;
  5344. /*
  5345. * Force memory writes to complete before letting h/w know there
  5346. * are new descriptors to fetch. (Only applicable for weak-ordered
  5347. * memory model archs, such as IA-64).
  5348. *
  5349. * We also need this memory barrier to make certain all of the
  5350. * status bits have been updated before next_to_watch is written.
  5351. */
  5352. wmb();
  5353. /* set next_to_watch value indicating a packet is present */
  5354. first->next_to_watch = tx_desc;
  5355. i++;
  5356. if (i == tx_ring->count)
  5357. i = 0;
  5358. tx_ring->next_to_use = i;
  5359. /* notify HW of packet */
  5360. writel(i, tx_ring->tail);
  5361. return;
  5362. dma_error:
  5363. dev_err(tx_ring->dev, "TX DMA map failed\n");
  5364. /* clear dma mappings for failed tx_buffer_info map */
  5365. for (;;) {
  5366. tx_buffer = &tx_ring->tx_buffer_info[i];
  5367. ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer);
  5368. if (tx_buffer == first)
  5369. break;
  5370. if (i == 0)
  5371. i = tx_ring->count;
  5372. i--;
  5373. }
  5374. tx_ring->next_to_use = i;
  5375. }
  5376. static void ixgbe_atr(struct ixgbe_ring *ring,
  5377. struct ixgbe_tx_buffer *first)
  5378. {
  5379. struct ixgbe_q_vector *q_vector = ring->q_vector;
  5380. union ixgbe_atr_hash_dword input = { .dword = 0 };
  5381. union ixgbe_atr_hash_dword common = { .dword = 0 };
  5382. union {
  5383. unsigned char *network;
  5384. struct iphdr *ipv4;
  5385. struct ipv6hdr *ipv6;
  5386. } hdr;
  5387. struct tcphdr *th;
  5388. __be16 vlan_id;
  5389. /* if ring doesn't have a interrupt vector, cannot perform ATR */
  5390. if (!q_vector)
  5391. return;
  5392. /* do nothing if sampling is disabled */
  5393. if (!ring->atr_sample_rate)
  5394. return;
  5395. ring->atr_count++;
  5396. /* snag network header to get L4 type and address */
  5397. hdr.network = skb_network_header(first->skb);
  5398. /* Currently only IPv4/IPv6 with TCP is supported */
  5399. if ((first->protocol != __constant_htons(ETH_P_IPV6) ||
  5400. hdr.ipv6->nexthdr != IPPROTO_TCP) &&
  5401. (first->protocol != __constant_htons(ETH_P_IP) ||
  5402. hdr.ipv4->protocol != IPPROTO_TCP))
  5403. return;
  5404. th = tcp_hdr(first->skb);
  5405. /* skip this packet since it is invalid or the socket is closing */
  5406. if (!th || th->fin)
  5407. return;
  5408. /* sample on all syn packets or once every atr sample count */
  5409. if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
  5410. return;
  5411. /* reset sample count */
  5412. ring->atr_count = 0;
  5413. vlan_id = htons(first->tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
  5414. /*
  5415. * src and dst are inverted, think how the receiver sees them
  5416. *
  5417. * The input is broken into two sections, a non-compressed section
  5418. * containing vm_pool, vlan_id, and flow_type. The rest of the data
  5419. * is XORed together and stored in the compressed dword.
  5420. */
  5421. input.formatted.vlan_id = vlan_id;
  5422. /*
  5423. * since src port and flex bytes occupy the same word XOR them together
  5424. * and write the value to source port portion of compressed dword
  5425. */
  5426. if (first->tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
  5427. common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
  5428. else
  5429. common.port.src ^= th->dest ^ first->protocol;
  5430. common.port.dst ^= th->source;
  5431. if (first->protocol == __constant_htons(ETH_P_IP)) {
  5432. input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
  5433. common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
  5434. } else {
  5435. input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
  5436. common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
  5437. hdr.ipv6->saddr.s6_addr32[1] ^
  5438. hdr.ipv6->saddr.s6_addr32[2] ^
  5439. hdr.ipv6->saddr.s6_addr32[3] ^
  5440. hdr.ipv6->daddr.s6_addr32[0] ^
  5441. hdr.ipv6->daddr.s6_addr32[1] ^
  5442. hdr.ipv6->daddr.s6_addr32[2] ^
  5443. hdr.ipv6->daddr.s6_addr32[3];
  5444. }
  5445. /* This assumes the Rx queue and Tx queue are bound to the same CPU */
  5446. ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
  5447. input, common, ring->queue_index);
  5448. }
  5449. static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
  5450. {
  5451. netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
  5452. /* Herbert's original patch had:
  5453. * smp_mb__after_netif_stop_queue();
  5454. * but since that doesn't exist yet, just open code it. */
  5455. smp_mb();
  5456. /* We need to check again in a case another CPU has just
  5457. * made room available. */
  5458. if (likely(ixgbe_desc_unused(tx_ring) < size))
  5459. return -EBUSY;
  5460. /* A reprieve! - use start_queue because it doesn't call schedule */
  5461. netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
  5462. ++tx_ring->tx_stats.restart_queue;
  5463. return 0;
  5464. }
  5465. static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
  5466. {
  5467. if (likely(ixgbe_desc_unused(tx_ring) >= size))
  5468. return 0;
  5469. return __ixgbe_maybe_stop_tx(tx_ring, size);
  5470. }
  5471. #ifdef IXGBE_FCOE
  5472. static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
  5473. {
  5474. struct ixgbe_adapter *adapter;
  5475. struct ixgbe_ring_feature *f;
  5476. int txq;
  5477. /*
  5478. * only execute the code below if protocol is FCoE
  5479. * or FIP and we have FCoE enabled on the adapter
  5480. */
  5481. switch (vlan_get_protocol(skb)) {
  5482. case __constant_htons(ETH_P_FCOE):
  5483. case __constant_htons(ETH_P_FIP):
  5484. adapter = netdev_priv(dev);
  5485. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
  5486. break;
  5487. default:
  5488. return __netdev_pick_tx(dev, skb);
  5489. }
  5490. f = &adapter->ring_feature[RING_F_FCOE];
  5491. txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
  5492. smp_processor_id();
  5493. while (txq >= f->indices)
  5494. txq -= f->indices;
  5495. return txq + f->offset;
  5496. }
  5497. #endif
  5498. netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
  5499. struct ixgbe_adapter *adapter,
  5500. struct ixgbe_ring *tx_ring)
  5501. {
  5502. struct ixgbe_tx_buffer *first;
  5503. int tso;
  5504. u32 tx_flags = 0;
  5505. unsigned short f;
  5506. u16 count = TXD_USE_COUNT(skb_headlen(skb));
  5507. __be16 protocol = skb->protocol;
  5508. u8 hdr_len = 0;
  5509. /*
  5510. * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
  5511. * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
  5512. * + 2 desc gap to keep tail from touching head,
  5513. * + 1 desc for context descriptor,
  5514. * otherwise try next time
  5515. */
  5516. for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
  5517. count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
  5518. if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
  5519. tx_ring->tx_stats.tx_busy++;
  5520. return NETDEV_TX_BUSY;
  5521. }
  5522. /* record the location of the first descriptor for this packet */
  5523. first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
  5524. first->skb = skb;
  5525. first->bytecount = skb->len;
  5526. first->gso_segs = 1;
  5527. /* if we have a HW VLAN tag being added default to the HW one */
  5528. if (vlan_tx_tag_present(skb)) {
  5529. tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
  5530. tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
  5531. /* else if it is a SW VLAN check the next protocol and store the tag */
  5532. } else if (protocol == __constant_htons(ETH_P_8021Q)) {
  5533. struct vlan_hdr *vhdr, _vhdr;
  5534. vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
  5535. if (!vhdr)
  5536. goto out_drop;
  5537. protocol = vhdr->h_vlan_encapsulated_proto;
  5538. tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
  5539. IXGBE_TX_FLAGS_VLAN_SHIFT;
  5540. tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
  5541. }
  5542. skb_tx_timestamp(skb);
  5543. if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
  5544. skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
  5545. tx_flags |= IXGBE_TX_FLAGS_TSTAMP;
  5546. /* schedule check for Tx timestamp */
  5547. adapter->ptp_tx_skb = skb_get(skb);
  5548. adapter->ptp_tx_start = jiffies;
  5549. schedule_work(&adapter->ptp_tx_work);
  5550. }
  5551. #ifdef CONFIG_PCI_IOV
  5552. /*
  5553. * Use the l2switch_enable flag - would be false if the DMA
  5554. * Tx switch had been disabled.
  5555. */
  5556. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  5557. tx_flags |= IXGBE_TX_FLAGS_CC;
  5558. #endif
  5559. /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
  5560. if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
  5561. ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
  5562. (skb->priority != TC_PRIO_CONTROL))) {
  5563. tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
  5564. tx_flags |= (skb->priority & 0x7) <<
  5565. IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
  5566. if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
  5567. struct vlan_ethhdr *vhdr;
  5568. if (skb_header_cloned(skb) &&
  5569. pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
  5570. goto out_drop;
  5571. vhdr = (struct vlan_ethhdr *)skb->data;
  5572. vhdr->h_vlan_TCI = htons(tx_flags >>
  5573. IXGBE_TX_FLAGS_VLAN_SHIFT);
  5574. } else {
  5575. tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
  5576. }
  5577. }
  5578. /* record initial flags and protocol */
  5579. first->tx_flags = tx_flags;
  5580. first->protocol = protocol;
  5581. #ifdef IXGBE_FCOE
  5582. /* setup tx offload for FCoE */
  5583. if ((protocol == __constant_htons(ETH_P_FCOE)) &&
  5584. (tx_ring->netdev->features & (NETIF_F_FSO | NETIF_F_FCOE_CRC))) {
  5585. tso = ixgbe_fso(tx_ring, first, &hdr_len);
  5586. if (tso < 0)
  5587. goto out_drop;
  5588. goto xmit_fcoe;
  5589. }
  5590. #endif /* IXGBE_FCOE */
  5591. tso = ixgbe_tso(tx_ring, first, &hdr_len);
  5592. if (tso < 0)
  5593. goto out_drop;
  5594. else if (!tso)
  5595. ixgbe_tx_csum(tx_ring, first);
  5596. /* add the ATR filter if ATR is on */
  5597. if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
  5598. ixgbe_atr(tx_ring, first);
  5599. #ifdef IXGBE_FCOE
  5600. xmit_fcoe:
  5601. #endif /* IXGBE_FCOE */
  5602. ixgbe_tx_map(tx_ring, first, hdr_len);
  5603. ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
  5604. return NETDEV_TX_OK;
  5605. out_drop:
  5606. dev_kfree_skb_any(first->skb);
  5607. first->skb = NULL;
  5608. return NETDEV_TX_OK;
  5609. }
  5610. static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb,
  5611. struct net_device *netdev)
  5612. {
  5613. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5614. struct ixgbe_ring *tx_ring;
  5615. /*
  5616. * The minimum packet size for olinfo paylen is 17 so pad the skb
  5617. * in order to meet this minimum size requirement.
  5618. */
  5619. if (unlikely(skb->len < 17)) {
  5620. if (skb_pad(skb, 17 - skb->len))
  5621. return NETDEV_TX_OK;
  5622. skb->len = 17;
  5623. skb_set_tail_pointer(skb, 17);
  5624. }
  5625. tx_ring = adapter->tx_ring[skb->queue_mapping];
  5626. return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
  5627. }
  5628. /**
  5629. * ixgbe_set_mac - Change the Ethernet Address of the NIC
  5630. * @netdev: network interface device structure
  5631. * @p: pointer to an address structure
  5632. *
  5633. * Returns 0 on success, negative on failure
  5634. **/
  5635. static int ixgbe_set_mac(struct net_device *netdev, void *p)
  5636. {
  5637. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5638. struct ixgbe_hw *hw = &adapter->hw;
  5639. struct sockaddr *addr = p;
  5640. if (!is_valid_ether_addr(addr->sa_data))
  5641. return -EADDRNOTAVAIL;
  5642. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  5643. memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
  5644. hw->mac.ops.set_rar(hw, 0, hw->mac.addr, VMDQ_P(0), IXGBE_RAH_AV);
  5645. return 0;
  5646. }
  5647. static int
  5648. ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
  5649. {
  5650. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5651. struct ixgbe_hw *hw = &adapter->hw;
  5652. u16 value;
  5653. int rc;
  5654. if (prtad != hw->phy.mdio.prtad)
  5655. return -EINVAL;
  5656. rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
  5657. if (!rc)
  5658. rc = value;
  5659. return rc;
  5660. }
  5661. static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
  5662. u16 addr, u16 value)
  5663. {
  5664. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5665. struct ixgbe_hw *hw = &adapter->hw;
  5666. if (prtad != hw->phy.mdio.prtad)
  5667. return -EINVAL;
  5668. return hw->phy.ops.write_reg(hw, addr, devad, value);
  5669. }
  5670. static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
  5671. {
  5672. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5673. switch (cmd) {
  5674. case SIOCSHWTSTAMP:
  5675. return ixgbe_ptp_hwtstamp_ioctl(adapter, req, cmd);
  5676. default:
  5677. return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
  5678. }
  5679. }
  5680. /**
  5681. * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
  5682. * netdev->dev_addrs
  5683. * @netdev: network interface device structure
  5684. *
  5685. * Returns non-zero on failure
  5686. **/
  5687. static int ixgbe_add_sanmac_netdev(struct net_device *dev)
  5688. {
  5689. int err = 0;
  5690. struct ixgbe_adapter *adapter = netdev_priv(dev);
  5691. struct ixgbe_hw *hw = &adapter->hw;
  5692. if (is_valid_ether_addr(hw->mac.san_addr)) {
  5693. rtnl_lock();
  5694. err = dev_addr_add(dev, hw->mac.san_addr, NETDEV_HW_ADDR_T_SAN);
  5695. rtnl_unlock();
  5696. /* update SAN MAC vmdq pool selection */
  5697. hw->mac.ops.set_vmdq_san_mac(hw, VMDQ_P(0));
  5698. }
  5699. return err;
  5700. }
  5701. /**
  5702. * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
  5703. * netdev->dev_addrs
  5704. * @netdev: network interface device structure
  5705. *
  5706. * Returns non-zero on failure
  5707. **/
  5708. static int ixgbe_del_sanmac_netdev(struct net_device *dev)
  5709. {
  5710. int err = 0;
  5711. struct ixgbe_adapter *adapter = netdev_priv(dev);
  5712. struct ixgbe_mac_info *mac = &adapter->hw.mac;
  5713. if (is_valid_ether_addr(mac->san_addr)) {
  5714. rtnl_lock();
  5715. err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
  5716. rtnl_unlock();
  5717. }
  5718. return err;
  5719. }
  5720. #ifdef CONFIG_NET_POLL_CONTROLLER
  5721. /*
  5722. * Polling 'interrupt' - used by things like netconsole to send skbs
  5723. * without having to re-enable interrupts. It's not called while
  5724. * the interrupt routine is executing.
  5725. */
  5726. static void ixgbe_netpoll(struct net_device *netdev)
  5727. {
  5728. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5729. int i;
  5730. /* if interface is down do nothing */
  5731. if (test_bit(__IXGBE_DOWN, &adapter->state))
  5732. return;
  5733. adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
  5734. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  5735. for (i = 0; i < adapter->num_q_vectors; i++)
  5736. ixgbe_msix_clean_rings(0, adapter->q_vector[i]);
  5737. } else {
  5738. ixgbe_intr(adapter->pdev->irq, netdev);
  5739. }
  5740. adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
  5741. }
  5742. #endif
  5743. static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
  5744. struct rtnl_link_stats64 *stats)
  5745. {
  5746. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5747. int i;
  5748. rcu_read_lock();
  5749. for (i = 0; i < adapter->num_rx_queues; i++) {
  5750. struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
  5751. u64 bytes, packets;
  5752. unsigned int start;
  5753. if (ring) {
  5754. do {
  5755. start = u64_stats_fetch_begin_bh(&ring->syncp);
  5756. packets = ring->stats.packets;
  5757. bytes = ring->stats.bytes;
  5758. } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
  5759. stats->rx_packets += packets;
  5760. stats->rx_bytes += bytes;
  5761. }
  5762. }
  5763. for (i = 0; i < adapter->num_tx_queues; i++) {
  5764. struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
  5765. u64 bytes, packets;
  5766. unsigned int start;
  5767. if (ring) {
  5768. do {
  5769. start = u64_stats_fetch_begin_bh(&ring->syncp);
  5770. packets = ring->stats.packets;
  5771. bytes = ring->stats.bytes;
  5772. } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
  5773. stats->tx_packets += packets;
  5774. stats->tx_bytes += bytes;
  5775. }
  5776. }
  5777. rcu_read_unlock();
  5778. /* following stats updated by ixgbe_watchdog_task() */
  5779. stats->multicast = netdev->stats.multicast;
  5780. stats->rx_errors = netdev->stats.rx_errors;
  5781. stats->rx_length_errors = netdev->stats.rx_length_errors;
  5782. stats->rx_crc_errors = netdev->stats.rx_crc_errors;
  5783. stats->rx_missed_errors = netdev->stats.rx_missed_errors;
  5784. return stats;
  5785. }
  5786. #ifdef CONFIG_IXGBE_DCB
  5787. /**
  5788. * ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
  5789. * @adapter: pointer to ixgbe_adapter
  5790. * @tc: number of traffic classes currently enabled
  5791. *
  5792. * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
  5793. * 802.1Q priority maps to a packet buffer that exists.
  5794. */
  5795. static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
  5796. {
  5797. struct ixgbe_hw *hw = &adapter->hw;
  5798. u32 reg, rsave;
  5799. int i;
  5800. /* 82598 have a static priority to TC mapping that can not
  5801. * be changed so no validation is needed.
  5802. */
  5803. if (hw->mac.type == ixgbe_mac_82598EB)
  5804. return;
  5805. reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
  5806. rsave = reg;
  5807. for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
  5808. u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
  5809. /* If up2tc is out of bounds default to zero */
  5810. if (up2tc > tc)
  5811. reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
  5812. }
  5813. if (reg != rsave)
  5814. IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
  5815. return;
  5816. }
  5817. /**
  5818. * ixgbe_set_prio_tc_map - Configure netdev prio tc map
  5819. * @adapter: Pointer to adapter struct
  5820. *
  5821. * Populate the netdev user priority to tc map
  5822. */
  5823. static void ixgbe_set_prio_tc_map(struct ixgbe_adapter *adapter)
  5824. {
  5825. struct net_device *dev = adapter->netdev;
  5826. struct ixgbe_dcb_config *dcb_cfg = &adapter->dcb_cfg;
  5827. struct ieee_ets *ets = adapter->ixgbe_ieee_ets;
  5828. u8 prio;
  5829. for (prio = 0; prio < MAX_USER_PRIORITY; prio++) {
  5830. u8 tc = 0;
  5831. if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE)
  5832. tc = ixgbe_dcb_get_tc_from_up(dcb_cfg, 0, prio);
  5833. else if (ets)
  5834. tc = ets->prio_tc[prio];
  5835. netdev_set_prio_tc_map(dev, prio, tc);
  5836. }
  5837. }
  5838. #endif /* CONFIG_IXGBE_DCB */
  5839. /**
  5840. * ixgbe_setup_tc - configure net_device for multiple traffic classes
  5841. *
  5842. * @netdev: net device to configure
  5843. * @tc: number of traffic classes to enable
  5844. */
  5845. int ixgbe_setup_tc(struct net_device *dev, u8 tc)
  5846. {
  5847. struct ixgbe_adapter *adapter = netdev_priv(dev);
  5848. struct ixgbe_hw *hw = &adapter->hw;
  5849. /* Hardware supports up to 8 traffic classes */
  5850. if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
  5851. (hw->mac.type == ixgbe_mac_82598EB &&
  5852. tc < MAX_TRAFFIC_CLASS))
  5853. return -EINVAL;
  5854. /* Hardware has to reinitialize queues and interrupts to
  5855. * match packet buffer alignment. Unfortunately, the
  5856. * hardware is not flexible enough to do this dynamically.
  5857. */
  5858. if (netif_running(dev))
  5859. ixgbe_close(dev);
  5860. ixgbe_clear_interrupt_scheme(adapter);
  5861. #ifdef CONFIG_IXGBE_DCB
  5862. if (tc) {
  5863. netdev_set_num_tc(dev, tc);
  5864. ixgbe_set_prio_tc_map(adapter);
  5865. adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
  5866. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  5867. adapter->last_lfc_mode = adapter->hw.fc.requested_mode;
  5868. adapter->hw.fc.requested_mode = ixgbe_fc_none;
  5869. }
  5870. } else {
  5871. netdev_reset_tc(dev);
  5872. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  5873. adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
  5874. adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
  5875. adapter->temp_dcb_cfg.pfc_mode_enable = false;
  5876. adapter->dcb_cfg.pfc_mode_enable = false;
  5877. }
  5878. ixgbe_validate_rtr(adapter, tc);
  5879. #endif /* CONFIG_IXGBE_DCB */
  5880. ixgbe_init_interrupt_scheme(adapter);
  5881. if (netif_running(dev))
  5882. return ixgbe_open(dev);
  5883. return 0;
  5884. }
  5885. #ifdef CONFIG_PCI_IOV
  5886. void ixgbe_sriov_reinit(struct ixgbe_adapter *adapter)
  5887. {
  5888. struct net_device *netdev = adapter->netdev;
  5889. rtnl_lock();
  5890. ixgbe_setup_tc(netdev, netdev_get_num_tc(netdev));
  5891. rtnl_unlock();
  5892. }
  5893. #endif
  5894. void ixgbe_do_reset(struct net_device *netdev)
  5895. {
  5896. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5897. if (netif_running(netdev))
  5898. ixgbe_reinit_locked(adapter);
  5899. else
  5900. ixgbe_reset(adapter);
  5901. }
  5902. static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
  5903. netdev_features_t features)
  5904. {
  5905. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5906. /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
  5907. if (!(features & NETIF_F_RXCSUM))
  5908. features &= ~NETIF_F_LRO;
  5909. /* Turn off LRO if not RSC capable */
  5910. if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE))
  5911. features &= ~NETIF_F_LRO;
  5912. return features;
  5913. }
  5914. static int ixgbe_set_features(struct net_device *netdev,
  5915. netdev_features_t features)
  5916. {
  5917. struct ixgbe_adapter *adapter = netdev_priv(netdev);
  5918. netdev_features_t changed = netdev->features ^ features;
  5919. bool need_reset = false;
  5920. /* Make sure RSC matches LRO, reset if change */
  5921. if (!(features & NETIF_F_LRO)) {
  5922. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  5923. need_reset = true;
  5924. adapter->flags2 &= ~IXGBE_FLAG2_RSC_ENABLED;
  5925. } else if ((adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) &&
  5926. !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
  5927. if (adapter->rx_itr_setting == 1 ||
  5928. adapter->rx_itr_setting > IXGBE_MIN_RSC_ITR) {
  5929. adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
  5930. need_reset = true;
  5931. } else if ((changed ^ features) & NETIF_F_LRO) {
  5932. e_info(probe, "rx-usecs set too low, "
  5933. "disabling RSC\n");
  5934. }
  5935. }
  5936. /*
  5937. * Check if Flow Director n-tuple support was enabled or disabled. If
  5938. * the state changed, we need to reset.
  5939. */
  5940. switch (features & NETIF_F_NTUPLE) {
  5941. case NETIF_F_NTUPLE:
  5942. /* turn off ATR, enable perfect filters and reset */
  5943. if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
  5944. need_reset = true;
  5945. adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
  5946. adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  5947. break;
  5948. default:
  5949. /* turn off perfect filters, enable ATR and reset */
  5950. if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
  5951. need_reset = true;
  5952. adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
  5953. /* We cannot enable ATR if SR-IOV is enabled */
  5954. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
  5955. break;
  5956. /* We cannot enable ATR if we have 2 or more traffic classes */
  5957. if (netdev_get_num_tc(netdev) > 1)
  5958. break;
  5959. /* We cannot enable ATR if RSS is disabled */
  5960. if (adapter->ring_feature[RING_F_RSS].limit <= 1)
  5961. break;
  5962. /* A sample rate of 0 indicates ATR disabled */
  5963. if (!adapter->atr_sample_rate)
  5964. break;
  5965. adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
  5966. break;
  5967. }
  5968. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  5969. ixgbe_vlan_strip_enable(adapter);
  5970. else
  5971. ixgbe_vlan_strip_disable(adapter);
  5972. if (changed & NETIF_F_RXALL)
  5973. need_reset = true;
  5974. netdev->features = features;
  5975. if (need_reset)
  5976. ixgbe_do_reset(netdev);
  5977. return 0;
  5978. }
  5979. static int ixgbe_ndo_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
  5980. struct net_device *dev,
  5981. const unsigned char *addr,
  5982. u16 flags)
  5983. {
  5984. struct ixgbe_adapter *adapter = netdev_priv(dev);
  5985. int err;
  5986. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  5987. return ndo_dflt_fdb_add(ndm, tb, dev, addr, flags);
  5988. /* Hardware does not support aging addresses so if a
  5989. * ndm_state is given only allow permanent addresses
  5990. */
  5991. if (ndm->ndm_state && !(ndm->ndm_state & NUD_PERMANENT)) {
  5992. pr_info("%s: FDB only supports static addresses\n",
  5993. ixgbe_driver_name);
  5994. return -EINVAL;
  5995. }
  5996. if (is_unicast_ether_addr(addr) || is_link_local_ether_addr(addr)) {
  5997. u32 rar_uc_entries = IXGBE_MAX_PF_MACVLANS;
  5998. if (netdev_uc_count(dev) < rar_uc_entries)
  5999. err = dev_uc_add_excl(dev, addr);
  6000. else
  6001. err = -ENOMEM;
  6002. } else if (is_multicast_ether_addr(addr)) {
  6003. err = dev_mc_add_excl(dev, addr);
  6004. } else {
  6005. err = -EINVAL;
  6006. }
  6007. /* Only return duplicate errors if NLM_F_EXCL is set */
  6008. if (err == -EEXIST && !(flags & NLM_F_EXCL))
  6009. err = 0;
  6010. return err;
  6011. }
  6012. static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
  6013. struct nlmsghdr *nlh)
  6014. {
  6015. struct ixgbe_adapter *adapter = netdev_priv(dev);
  6016. struct nlattr *attr, *br_spec;
  6017. int rem;
  6018. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  6019. return -EOPNOTSUPP;
  6020. br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
  6021. nla_for_each_nested(attr, br_spec, rem) {
  6022. __u16 mode;
  6023. u32 reg = 0;
  6024. if (nla_type(attr) != IFLA_BRIDGE_MODE)
  6025. continue;
  6026. mode = nla_get_u16(attr);
  6027. if (mode == BRIDGE_MODE_VEPA) {
  6028. reg = 0;
  6029. adapter->flags2 &= ~IXGBE_FLAG2_BRIDGE_MODE_VEB;
  6030. } else if (mode == BRIDGE_MODE_VEB) {
  6031. reg = IXGBE_PFDTXGSWC_VT_LBEN;
  6032. adapter->flags2 |= IXGBE_FLAG2_BRIDGE_MODE_VEB;
  6033. } else
  6034. return -EINVAL;
  6035. IXGBE_WRITE_REG(&adapter->hw, IXGBE_PFDTXGSWC, reg);
  6036. e_info(drv, "enabling bridge mode: %s\n",
  6037. mode == BRIDGE_MODE_VEPA ? "VEPA" : "VEB");
  6038. }
  6039. return 0;
  6040. }
  6041. static int ixgbe_ndo_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
  6042. struct net_device *dev,
  6043. u32 filter_mask)
  6044. {
  6045. struct ixgbe_adapter *adapter = netdev_priv(dev);
  6046. u16 mode;
  6047. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  6048. return 0;
  6049. if (adapter->flags2 & IXGBE_FLAG2_BRIDGE_MODE_VEB)
  6050. mode = BRIDGE_MODE_VEB;
  6051. else
  6052. mode = BRIDGE_MODE_VEPA;
  6053. return ndo_dflt_bridge_getlink(skb, pid, seq, dev, mode);
  6054. }
  6055. static const struct net_device_ops ixgbe_netdev_ops = {
  6056. .ndo_open = ixgbe_open,
  6057. .ndo_stop = ixgbe_close,
  6058. .ndo_start_xmit = ixgbe_xmit_frame,
  6059. #ifdef IXGBE_FCOE
  6060. .ndo_select_queue = ixgbe_select_queue,
  6061. #endif
  6062. .ndo_set_rx_mode = ixgbe_set_rx_mode,
  6063. .ndo_validate_addr = eth_validate_addr,
  6064. .ndo_set_mac_address = ixgbe_set_mac,
  6065. .ndo_change_mtu = ixgbe_change_mtu,
  6066. .ndo_tx_timeout = ixgbe_tx_timeout,
  6067. .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
  6068. .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
  6069. .ndo_do_ioctl = ixgbe_ioctl,
  6070. .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
  6071. .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
  6072. .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
  6073. .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
  6074. .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
  6075. .ndo_get_stats64 = ixgbe_get_stats64,
  6076. #ifdef CONFIG_IXGBE_DCB
  6077. .ndo_setup_tc = ixgbe_setup_tc,
  6078. #endif
  6079. #ifdef CONFIG_NET_POLL_CONTROLLER
  6080. .ndo_poll_controller = ixgbe_netpoll,
  6081. #endif
  6082. #ifdef IXGBE_FCOE
  6083. .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
  6084. .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
  6085. .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
  6086. .ndo_fcoe_enable = ixgbe_fcoe_enable,
  6087. .ndo_fcoe_disable = ixgbe_fcoe_disable,
  6088. .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
  6089. .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
  6090. #endif /* IXGBE_FCOE */
  6091. .ndo_set_features = ixgbe_set_features,
  6092. .ndo_fix_features = ixgbe_fix_features,
  6093. .ndo_fdb_add = ixgbe_ndo_fdb_add,
  6094. .ndo_bridge_setlink = ixgbe_ndo_bridge_setlink,
  6095. .ndo_bridge_getlink = ixgbe_ndo_bridge_getlink,
  6096. };
  6097. /**
  6098. * ixgbe_wol_supported - Check whether device supports WoL
  6099. * @hw: hw specific details
  6100. * @device_id: the device ID
  6101. * @subdev_id: the subsystem device ID
  6102. *
  6103. * This function is used by probe and ethtool to determine
  6104. * which devices have WoL support
  6105. *
  6106. **/
  6107. int ixgbe_wol_supported(struct ixgbe_adapter *adapter, u16 device_id,
  6108. u16 subdevice_id)
  6109. {
  6110. struct ixgbe_hw *hw = &adapter->hw;
  6111. u16 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
  6112. int is_wol_supported = 0;
  6113. switch (device_id) {
  6114. case IXGBE_DEV_ID_82599_SFP:
  6115. /* Only these subdevices could supports WOL */
  6116. switch (subdevice_id) {
  6117. case IXGBE_SUBDEV_ID_82599_560FLR:
  6118. /* only support first port */
  6119. if (hw->bus.func != 0)
  6120. break;
  6121. case IXGBE_SUBDEV_ID_82599_SP_560FLR:
  6122. case IXGBE_SUBDEV_ID_82599_SFP:
  6123. case IXGBE_SUBDEV_ID_82599_RNDC:
  6124. case IXGBE_SUBDEV_ID_82599_ECNA_DP:
  6125. case IXGBE_SUBDEV_ID_82599_LOM_SFP:
  6126. is_wol_supported = 1;
  6127. break;
  6128. }
  6129. break;
  6130. case IXGBE_DEV_ID_82599EN_SFP:
  6131. /* Only this subdevice supports WOL */
  6132. switch (subdevice_id) {
  6133. case IXGBE_SUBDEV_ID_82599EN_SFP_OCP1:
  6134. is_wol_supported = 1;
  6135. break;
  6136. }
  6137. break;
  6138. case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
  6139. /* All except this subdevice support WOL */
  6140. if (subdevice_id != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
  6141. is_wol_supported = 1;
  6142. break;
  6143. case IXGBE_DEV_ID_82599_KX4:
  6144. is_wol_supported = 1;
  6145. break;
  6146. case IXGBE_DEV_ID_X540T:
  6147. case IXGBE_DEV_ID_X540T1:
  6148. /* check eeprom to see if enabled wol */
  6149. if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
  6150. ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
  6151. (hw->bus.func == 0))) {
  6152. is_wol_supported = 1;
  6153. }
  6154. break;
  6155. }
  6156. return is_wol_supported;
  6157. }
  6158. /**
  6159. * ixgbe_probe - Device Initialization Routine
  6160. * @pdev: PCI device information struct
  6161. * @ent: entry in ixgbe_pci_tbl
  6162. *
  6163. * Returns 0 on success, negative on failure
  6164. *
  6165. * ixgbe_probe initializes an adapter identified by a pci_dev structure.
  6166. * The OS initialization, configuring of the adapter private structure,
  6167. * and a hardware reset occur.
  6168. **/
  6169. static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  6170. {
  6171. struct net_device *netdev;
  6172. struct ixgbe_adapter *adapter = NULL;
  6173. struct ixgbe_hw *hw;
  6174. const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
  6175. static int cards_found;
  6176. int i, err, pci_using_dac;
  6177. unsigned int indices = MAX_TX_QUEUES;
  6178. u8 part_str[IXGBE_PBANUM_LENGTH];
  6179. #ifdef IXGBE_FCOE
  6180. u16 device_caps;
  6181. #endif
  6182. u32 eec;
  6183. /* Catch broken hardware that put the wrong VF device ID in
  6184. * the PCIe SR-IOV capability.
  6185. */
  6186. if (pdev->is_virtfn) {
  6187. WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
  6188. pci_name(pdev), pdev->vendor, pdev->device);
  6189. return -EINVAL;
  6190. }
  6191. err = pci_enable_device_mem(pdev);
  6192. if (err)
  6193. return err;
  6194. if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
  6195. !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
  6196. pci_using_dac = 1;
  6197. } else {
  6198. err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
  6199. if (err) {
  6200. err = dma_set_coherent_mask(&pdev->dev,
  6201. DMA_BIT_MASK(32));
  6202. if (err) {
  6203. dev_err(&pdev->dev,
  6204. "No usable DMA configuration, aborting\n");
  6205. goto err_dma;
  6206. }
  6207. }
  6208. pci_using_dac = 0;
  6209. }
  6210. err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
  6211. IORESOURCE_MEM), ixgbe_driver_name);
  6212. if (err) {
  6213. dev_err(&pdev->dev,
  6214. "pci_request_selected_regions failed 0x%x\n", err);
  6215. goto err_pci_reg;
  6216. }
  6217. pci_enable_pcie_error_reporting(pdev);
  6218. pci_set_master(pdev);
  6219. pci_save_state(pdev);
  6220. if (ii->mac == ixgbe_mac_82598EB) {
  6221. #ifdef CONFIG_IXGBE_DCB
  6222. /* 8 TC w/ 4 queues per TC */
  6223. indices = 4 * MAX_TRAFFIC_CLASS;
  6224. #else
  6225. indices = IXGBE_MAX_RSS_INDICES;
  6226. #endif
  6227. }
  6228. netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
  6229. if (!netdev) {
  6230. err = -ENOMEM;
  6231. goto err_alloc_etherdev;
  6232. }
  6233. SET_NETDEV_DEV(netdev, &pdev->dev);
  6234. adapter = netdev_priv(netdev);
  6235. pci_set_drvdata(pdev, adapter);
  6236. adapter->netdev = netdev;
  6237. adapter->pdev = pdev;
  6238. hw = &adapter->hw;
  6239. hw->back = adapter;
  6240. adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
  6241. hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
  6242. pci_resource_len(pdev, 0));
  6243. if (!hw->hw_addr) {
  6244. err = -EIO;
  6245. goto err_ioremap;
  6246. }
  6247. netdev->netdev_ops = &ixgbe_netdev_ops;
  6248. ixgbe_set_ethtool_ops(netdev);
  6249. netdev->watchdog_timeo = 5 * HZ;
  6250. strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
  6251. adapter->bd_number = cards_found;
  6252. /* Setup hw api */
  6253. memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
  6254. hw->mac.type = ii->mac;
  6255. /* EEPROM */
  6256. memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
  6257. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  6258. /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
  6259. if (!(eec & (1 << 8)))
  6260. hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
  6261. /* PHY */
  6262. memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
  6263. hw->phy.sfp_type = ixgbe_sfp_type_unknown;
  6264. /* ixgbe_identify_phy_generic will set prtad and mmds properly */
  6265. hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
  6266. hw->phy.mdio.mmds = 0;
  6267. hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  6268. hw->phy.mdio.dev = netdev;
  6269. hw->phy.mdio.mdio_read = ixgbe_mdio_read;
  6270. hw->phy.mdio.mdio_write = ixgbe_mdio_write;
  6271. ii->get_invariants(hw);
  6272. /* setup the private structure */
  6273. err = ixgbe_sw_init(adapter);
  6274. if (err)
  6275. goto err_sw_init;
  6276. /* Cache if MNG FW is up so we don't have to read the REG later */
  6277. if (hw->mac.ops.mng_fw_enabled)
  6278. hw->mng_fw_enabled = hw->mac.ops.mng_fw_enabled(hw);
  6279. /* Make it possible the adapter to be woken up via WOL */
  6280. switch (adapter->hw.mac.type) {
  6281. case ixgbe_mac_82599EB:
  6282. case ixgbe_mac_X540:
  6283. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  6284. break;
  6285. default:
  6286. break;
  6287. }
  6288. /*
  6289. * If there is a fan on this device and it has failed log the
  6290. * failure.
  6291. */
  6292. if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
  6293. u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  6294. if (esdp & IXGBE_ESDP_SDP1)
  6295. e_crit(probe, "Fan has stopped, replace the adapter\n");
  6296. }
  6297. if (allow_unsupported_sfp)
  6298. hw->allow_unsupported_sfp = allow_unsupported_sfp;
  6299. /* reset_hw fills in the perm_addr as well */
  6300. hw->phy.reset_if_overtemp = true;
  6301. err = hw->mac.ops.reset_hw(hw);
  6302. hw->phy.reset_if_overtemp = false;
  6303. if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
  6304. hw->mac.type == ixgbe_mac_82598EB) {
  6305. err = 0;
  6306. } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
  6307. e_dev_err("failed to load because an unsupported SFP+ "
  6308. "module type was detected.\n");
  6309. e_dev_err("Reload the driver after installing a supported "
  6310. "module.\n");
  6311. goto err_sw_init;
  6312. } else if (err) {
  6313. e_dev_err("HW Init failed: %d\n", err);
  6314. goto err_sw_init;
  6315. }
  6316. #ifdef CONFIG_PCI_IOV
  6317. /* SR-IOV not supported on the 82598 */
  6318. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  6319. goto skip_sriov;
  6320. /* Mailbox */
  6321. ixgbe_init_mbx_params_pf(hw);
  6322. memcpy(&hw->mbx.ops, ii->mbx_ops, sizeof(hw->mbx.ops));
  6323. ixgbe_enable_sriov(adapter);
  6324. pci_sriov_set_totalvfs(pdev, 63);
  6325. skip_sriov:
  6326. #endif
  6327. netdev->features = NETIF_F_SG |
  6328. NETIF_F_IP_CSUM |
  6329. NETIF_F_IPV6_CSUM |
  6330. NETIF_F_HW_VLAN_CTAG_TX |
  6331. NETIF_F_HW_VLAN_CTAG_RX |
  6332. NETIF_F_HW_VLAN_CTAG_FILTER |
  6333. NETIF_F_TSO |
  6334. NETIF_F_TSO6 |
  6335. NETIF_F_RXHASH |
  6336. NETIF_F_RXCSUM;
  6337. netdev->hw_features = netdev->features;
  6338. switch (adapter->hw.mac.type) {
  6339. case ixgbe_mac_82599EB:
  6340. case ixgbe_mac_X540:
  6341. netdev->features |= NETIF_F_SCTP_CSUM;
  6342. netdev->hw_features |= NETIF_F_SCTP_CSUM |
  6343. NETIF_F_NTUPLE;
  6344. break;
  6345. default:
  6346. break;
  6347. }
  6348. netdev->hw_features |= NETIF_F_RXALL;
  6349. netdev->vlan_features |= NETIF_F_TSO;
  6350. netdev->vlan_features |= NETIF_F_TSO6;
  6351. netdev->vlan_features |= NETIF_F_IP_CSUM;
  6352. netdev->vlan_features |= NETIF_F_IPV6_CSUM;
  6353. netdev->vlan_features |= NETIF_F_SG;
  6354. netdev->priv_flags |= IFF_UNICAST_FLT;
  6355. netdev->priv_flags |= IFF_SUPP_NOFCS;
  6356. #ifdef CONFIG_IXGBE_DCB
  6357. netdev->dcbnl_ops = &dcbnl_ops;
  6358. #endif
  6359. #ifdef IXGBE_FCOE
  6360. if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
  6361. unsigned int fcoe_l;
  6362. if (hw->mac.ops.get_device_caps) {
  6363. hw->mac.ops.get_device_caps(hw, &device_caps);
  6364. if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
  6365. adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
  6366. }
  6367. fcoe_l = min_t(int, IXGBE_FCRETA_SIZE, num_online_cpus());
  6368. adapter->ring_feature[RING_F_FCOE].limit = fcoe_l;
  6369. netdev->features |= NETIF_F_FSO |
  6370. NETIF_F_FCOE_CRC;
  6371. netdev->vlan_features |= NETIF_F_FSO |
  6372. NETIF_F_FCOE_CRC |
  6373. NETIF_F_FCOE_MTU;
  6374. }
  6375. #endif /* IXGBE_FCOE */
  6376. if (pci_using_dac) {
  6377. netdev->features |= NETIF_F_HIGHDMA;
  6378. netdev->vlan_features |= NETIF_F_HIGHDMA;
  6379. }
  6380. if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
  6381. netdev->hw_features |= NETIF_F_LRO;
  6382. if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
  6383. netdev->features |= NETIF_F_LRO;
  6384. /* make sure the EEPROM is good */
  6385. if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
  6386. e_dev_err("The EEPROM Checksum Is Not Valid\n");
  6387. err = -EIO;
  6388. goto err_sw_init;
  6389. }
  6390. memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
  6391. if (!is_valid_ether_addr(netdev->dev_addr)) {
  6392. e_dev_err("invalid MAC address\n");
  6393. err = -EIO;
  6394. goto err_sw_init;
  6395. }
  6396. setup_timer(&adapter->service_timer, &ixgbe_service_timer,
  6397. (unsigned long) adapter);
  6398. INIT_WORK(&adapter->service_task, ixgbe_service_task);
  6399. clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
  6400. err = ixgbe_init_interrupt_scheme(adapter);
  6401. if (err)
  6402. goto err_sw_init;
  6403. /* WOL not supported for all devices */
  6404. adapter->wol = 0;
  6405. hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
  6406. hw->wol_enabled = ixgbe_wol_supported(adapter, pdev->device,
  6407. pdev->subsystem_device);
  6408. if (hw->wol_enabled)
  6409. adapter->wol = IXGBE_WUFC_MAG;
  6410. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  6411. /* save off EEPROM version number */
  6412. hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
  6413. hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
  6414. /* pick up the PCI bus settings for reporting later */
  6415. hw->mac.ops.get_bus_info(hw);
  6416. if (hw->device_id == IXGBE_DEV_ID_82599_SFP_SF_QP)
  6417. ixgbe_get_parent_bus_info(adapter);
  6418. /* print bus type/speed/width info */
  6419. e_dev_info("(PCI Express:%s:%s) %pM\n",
  6420. (hw->bus.speed == ixgbe_bus_speed_8000 ? "8.0GT/s" :
  6421. hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
  6422. hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
  6423. "Unknown"),
  6424. (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
  6425. hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
  6426. hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
  6427. "Unknown"),
  6428. netdev->dev_addr);
  6429. err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
  6430. if (err)
  6431. strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
  6432. if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
  6433. e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
  6434. hw->mac.type, hw->phy.type, hw->phy.sfp_type,
  6435. part_str);
  6436. else
  6437. e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
  6438. hw->mac.type, hw->phy.type, part_str);
  6439. if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
  6440. e_dev_warn("PCI-Express bandwidth available for this card is "
  6441. "not sufficient for optimal performance.\n");
  6442. e_dev_warn("For optimal performance a x8 PCI-Express slot "
  6443. "is required.\n");
  6444. }
  6445. /* reset the hardware with the new settings */
  6446. err = hw->mac.ops.start_hw(hw);
  6447. if (err == IXGBE_ERR_EEPROM_VERSION) {
  6448. /* We are running on a pre-production device, log a warning */
  6449. e_dev_warn("This device is a pre-production adapter/LOM. "
  6450. "Please be aware there may be issues associated "
  6451. "with your hardware. If you are experiencing "
  6452. "problems please contact your Intel or hardware "
  6453. "representative who provided you with this "
  6454. "hardware.\n");
  6455. }
  6456. strcpy(netdev->name, "eth%d");
  6457. err = register_netdev(netdev);
  6458. if (err)
  6459. goto err_register;
  6460. /* power down the optics for 82599 SFP+ fiber */
  6461. if (hw->mac.ops.disable_tx_laser)
  6462. hw->mac.ops.disable_tx_laser(hw);
  6463. /* carrier off reporting is important to ethtool even BEFORE open */
  6464. netif_carrier_off(netdev);
  6465. #ifdef CONFIG_IXGBE_DCA
  6466. if (dca_add_requester(&pdev->dev) == 0) {
  6467. adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
  6468. ixgbe_setup_dca(adapter);
  6469. }
  6470. #endif
  6471. if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
  6472. e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
  6473. for (i = 0; i < adapter->num_vfs; i++)
  6474. ixgbe_vf_configuration(pdev, (i | 0x10000000));
  6475. }
  6476. /* firmware requires driver version to be 0xFFFFFFFF
  6477. * since os does not support feature
  6478. */
  6479. if (hw->mac.ops.set_fw_drv_ver)
  6480. hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
  6481. 0xFF);
  6482. /* add san mac addr to netdev */
  6483. ixgbe_add_sanmac_netdev(netdev);
  6484. e_dev_info("%s\n", ixgbe_default_device_descr);
  6485. cards_found++;
  6486. #ifdef CONFIG_IXGBE_HWMON
  6487. if (ixgbe_sysfs_init(adapter))
  6488. e_err(probe, "failed to allocate sysfs resources\n");
  6489. #endif /* CONFIG_IXGBE_HWMON */
  6490. ixgbe_dbg_adapter_init(adapter);
  6491. /* Need link setup for MNG FW, else wait for IXGBE_UP */
  6492. if (hw->mng_fw_enabled && hw->mac.ops.setup_link)
  6493. hw->mac.ops.setup_link(hw,
  6494. IXGBE_LINK_SPEED_10GB_FULL | IXGBE_LINK_SPEED_1GB_FULL,
  6495. true);
  6496. return 0;
  6497. err_register:
  6498. ixgbe_release_hw_control(adapter);
  6499. ixgbe_clear_interrupt_scheme(adapter);
  6500. err_sw_init:
  6501. ixgbe_disable_sriov(adapter);
  6502. adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
  6503. iounmap(hw->hw_addr);
  6504. err_ioremap:
  6505. free_netdev(netdev);
  6506. err_alloc_etherdev:
  6507. pci_release_selected_regions(pdev,
  6508. pci_select_bars(pdev, IORESOURCE_MEM));
  6509. err_pci_reg:
  6510. err_dma:
  6511. pci_disable_device(pdev);
  6512. return err;
  6513. }
  6514. /**
  6515. * ixgbe_remove - Device Removal Routine
  6516. * @pdev: PCI device information struct
  6517. *
  6518. * ixgbe_remove is called by the PCI subsystem to alert the driver
  6519. * that it should release a PCI device. The could be caused by a
  6520. * Hot-Plug event, or because the driver is going to be removed from
  6521. * memory.
  6522. **/
  6523. static void ixgbe_remove(struct pci_dev *pdev)
  6524. {
  6525. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  6526. struct net_device *netdev = adapter->netdev;
  6527. ixgbe_dbg_adapter_exit(adapter);
  6528. set_bit(__IXGBE_DOWN, &adapter->state);
  6529. cancel_work_sync(&adapter->service_task);
  6530. #ifdef CONFIG_IXGBE_DCA
  6531. if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
  6532. adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
  6533. dca_remove_requester(&pdev->dev);
  6534. IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
  6535. }
  6536. #endif
  6537. #ifdef CONFIG_IXGBE_HWMON
  6538. ixgbe_sysfs_exit(adapter);
  6539. #endif /* CONFIG_IXGBE_HWMON */
  6540. /* remove the added san mac */
  6541. ixgbe_del_sanmac_netdev(netdev);
  6542. if (netdev->reg_state == NETREG_REGISTERED)
  6543. unregister_netdev(netdev);
  6544. #ifdef CONFIG_PCI_IOV
  6545. /*
  6546. * Only disable SR-IOV on unload if the user specified the now
  6547. * deprecated max_vfs module parameter.
  6548. */
  6549. if (max_vfs)
  6550. ixgbe_disable_sriov(adapter);
  6551. #endif
  6552. ixgbe_clear_interrupt_scheme(adapter);
  6553. ixgbe_release_hw_control(adapter);
  6554. #ifdef CONFIG_DCB
  6555. kfree(adapter->ixgbe_ieee_pfc);
  6556. kfree(adapter->ixgbe_ieee_ets);
  6557. #endif
  6558. iounmap(adapter->hw.hw_addr);
  6559. pci_release_selected_regions(pdev, pci_select_bars(pdev,
  6560. IORESOURCE_MEM));
  6561. e_dev_info("complete\n");
  6562. free_netdev(netdev);
  6563. pci_disable_pcie_error_reporting(pdev);
  6564. pci_disable_device(pdev);
  6565. }
  6566. /**
  6567. * ixgbe_io_error_detected - called when PCI error is detected
  6568. * @pdev: Pointer to PCI device
  6569. * @state: The current pci connection state
  6570. *
  6571. * This function is called after a PCI bus error affecting
  6572. * this device has been detected.
  6573. */
  6574. static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
  6575. pci_channel_state_t state)
  6576. {
  6577. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  6578. struct net_device *netdev = adapter->netdev;
  6579. #ifdef CONFIG_PCI_IOV
  6580. struct pci_dev *bdev, *vfdev;
  6581. u32 dw0, dw1, dw2, dw3;
  6582. int vf, pos;
  6583. u16 req_id, pf_func;
  6584. if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
  6585. adapter->num_vfs == 0)
  6586. goto skip_bad_vf_detection;
  6587. bdev = pdev->bus->self;
  6588. while (bdev && (pci_pcie_type(bdev) != PCI_EXP_TYPE_ROOT_PORT))
  6589. bdev = bdev->bus->self;
  6590. if (!bdev)
  6591. goto skip_bad_vf_detection;
  6592. pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
  6593. if (!pos)
  6594. goto skip_bad_vf_detection;
  6595. pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
  6596. pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
  6597. pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
  6598. pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
  6599. req_id = dw1 >> 16;
  6600. /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
  6601. if (!(req_id & 0x0080))
  6602. goto skip_bad_vf_detection;
  6603. pf_func = req_id & 0x01;
  6604. if ((pf_func & 1) == (pdev->devfn & 1)) {
  6605. unsigned int device_id;
  6606. vf = (req_id & 0x7F) >> 1;
  6607. e_dev_err("VF %d has caused a PCIe error\n", vf);
  6608. e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
  6609. "%8.8x\tdw3: %8.8x\n",
  6610. dw0, dw1, dw2, dw3);
  6611. switch (adapter->hw.mac.type) {
  6612. case ixgbe_mac_82599EB:
  6613. device_id = IXGBE_82599_VF_DEVICE_ID;
  6614. break;
  6615. case ixgbe_mac_X540:
  6616. device_id = IXGBE_X540_VF_DEVICE_ID;
  6617. break;
  6618. default:
  6619. device_id = 0;
  6620. break;
  6621. }
  6622. /* Find the pci device of the offending VF */
  6623. vfdev = pci_get_device(PCI_VENDOR_ID_INTEL, device_id, NULL);
  6624. while (vfdev) {
  6625. if (vfdev->devfn == (req_id & 0xFF))
  6626. break;
  6627. vfdev = pci_get_device(PCI_VENDOR_ID_INTEL,
  6628. device_id, vfdev);
  6629. }
  6630. /*
  6631. * There's a slim chance the VF could have been hot plugged,
  6632. * so if it is no longer present we don't need to issue the
  6633. * VFLR. Just clean up the AER in that case.
  6634. */
  6635. if (vfdev) {
  6636. e_dev_err("Issuing VFLR to VF %d\n", vf);
  6637. pci_write_config_dword(vfdev, 0xA8, 0x00008000);
  6638. /* Free device reference count */
  6639. pci_dev_put(vfdev);
  6640. }
  6641. pci_cleanup_aer_uncorrect_error_status(pdev);
  6642. }
  6643. /*
  6644. * Even though the error may have occurred on the other port
  6645. * we still need to increment the vf error reference count for
  6646. * both ports because the I/O resume function will be called
  6647. * for both of them.
  6648. */
  6649. adapter->vferr_refcount++;
  6650. return PCI_ERS_RESULT_RECOVERED;
  6651. skip_bad_vf_detection:
  6652. #endif /* CONFIG_PCI_IOV */
  6653. netif_device_detach(netdev);
  6654. if (state == pci_channel_io_perm_failure)
  6655. return PCI_ERS_RESULT_DISCONNECT;
  6656. if (netif_running(netdev))
  6657. ixgbe_down(adapter);
  6658. pci_disable_device(pdev);
  6659. /* Request a slot reset. */
  6660. return PCI_ERS_RESULT_NEED_RESET;
  6661. }
  6662. /**
  6663. * ixgbe_io_slot_reset - called after the pci bus has been reset.
  6664. * @pdev: Pointer to PCI device
  6665. *
  6666. * Restart the card from scratch, as if from a cold-boot.
  6667. */
  6668. static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
  6669. {
  6670. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  6671. pci_ers_result_t result;
  6672. int err;
  6673. if (pci_enable_device_mem(pdev)) {
  6674. e_err(probe, "Cannot re-enable PCI device after reset.\n");
  6675. result = PCI_ERS_RESULT_DISCONNECT;
  6676. } else {
  6677. pci_set_master(pdev);
  6678. pci_restore_state(pdev);
  6679. pci_save_state(pdev);
  6680. pci_wake_from_d3(pdev, false);
  6681. ixgbe_reset(adapter);
  6682. IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
  6683. result = PCI_ERS_RESULT_RECOVERED;
  6684. }
  6685. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  6686. if (err) {
  6687. e_dev_err("pci_cleanup_aer_uncorrect_error_status "
  6688. "failed 0x%0x\n", err);
  6689. /* non-fatal, continue */
  6690. }
  6691. return result;
  6692. }
  6693. /**
  6694. * ixgbe_io_resume - called when traffic can start flowing again.
  6695. * @pdev: Pointer to PCI device
  6696. *
  6697. * This callback is called when the error recovery driver tells us that
  6698. * its OK to resume normal operation.
  6699. */
  6700. static void ixgbe_io_resume(struct pci_dev *pdev)
  6701. {
  6702. struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
  6703. struct net_device *netdev = adapter->netdev;
  6704. #ifdef CONFIG_PCI_IOV
  6705. if (adapter->vferr_refcount) {
  6706. e_info(drv, "Resuming after VF err\n");
  6707. adapter->vferr_refcount--;
  6708. return;
  6709. }
  6710. #endif
  6711. if (netif_running(netdev))
  6712. ixgbe_up(adapter);
  6713. netif_device_attach(netdev);
  6714. }
  6715. static const struct pci_error_handlers ixgbe_err_handler = {
  6716. .error_detected = ixgbe_io_error_detected,
  6717. .slot_reset = ixgbe_io_slot_reset,
  6718. .resume = ixgbe_io_resume,
  6719. };
  6720. static struct pci_driver ixgbe_driver = {
  6721. .name = ixgbe_driver_name,
  6722. .id_table = ixgbe_pci_tbl,
  6723. .probe = ixgbe_probe,
  6724. .remove = ixgbe_remove,
  6725. #ifdef CONFIG_PM
  6726. .suspend = ixgbe_suspend,
  6727. .resume = ixgbe_resume,
  6728. #endif
  6729. .shutdown = ixgbe_shutdown,
  6730. .sriov_configure = ixgbe_pci_sriov_configure,
  6731. .err_handler = &ixgbe_err_handler
  6732. };
  6733. /**
  6734. * ixgbe_init_module - Driver Registration Routine
  6735. *
  6736. * ixgbe_init_module is the first routine called when the driver is
  6737. * loaded. All it does is register with the PCI subsystem.
  6738. **/
  6739. static int __init ixgbe_init_module(void)
  6740. {
  6741. int ret;
  6742. pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
  6743. pr_info("%s\n", ixgbe_copyright);
  6744. ixgbe_dbg_init();
  6745. ret = pci_register_driver(&ixgbe_driver);
  6746. if (ret) {
  6747. ixgbe_dbg_exit();
  6748. return ret;
  6749. }
  6750. #ifdef CONFIG_IXGBE_DCA
  6751. dca_register_notify(&dca_notifier);
  6752. #endif
  6753. return 0;
  6754. }
  6755. module_init(ixgbe_init_module);
  6756. /**
  6757. * ixgbe_exit_module - Driver Exit Cleanup Routine
  6758. *
  6759. * ixgbe_exit_module is called just before the driver is removed
  6760. * from memory.
  6761. **/
  6762. static void __exit ixgbe_exit_module(void)
  6763. {
  6764. #ifdef CONFIG_IXGBE_DCA
  6765. dca_unregister_notify(&dca_notifier);
  6766. #endif
  6767. pci_unregister_driver(&ixgbe_driver);
  6768. ixgbe_dbg_exit();
  6769. rcu_barrier(); /* Wait for completion of call_rcu()'s */
  6770. }
  6771. #ifdef CONFIG_IXGBE_DCA
  6772. static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
  6773. void *p)
  6774. {
  6775. int ret_val;
  6776. ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
  6777. __ixgbe_notify_dca);
  6778. return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
  6779. }
  6780. #endif /* CONFIG_IXGBE_DCA */
  6781. module_exit(ixgbe_exit_module);
  6782. /* ixgbe_main.c */