ixgbe_main.c 216 KB

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