ixgbe_main.c 216 KB

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