ixgbe_main.c 216 KB

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