ixgbe_main.c 204 KB

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