ixgbe_main.c 177 KB

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