ixgbe_main.c 209 KB

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