ixgbe_main.c 204 KB

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