ixgbe_main.c 217 KB

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