ixgbe_main.c 206 KB

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