ixgbe_main.c 209 KB

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