ixgbe_main.c 178 KB

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