ixgbe_main.c 212 KB

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