igb_main.c 189 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890
  1. /*******************************************************************************
  2. Intel(R) Gigabit Ethernet Linux driver
  3. Copyright(c) 2007-2011 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  18. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  19. *******************************************************************************/
  20. #include <linux/module.h>
  21. #include <linux/types.h>
  22. #include <linux/init.h>
  23. #include <linux/bitops.h>
  24. #include <linux/vmalloc.h>
  25. #include <linux/pagemap.h>
  26. #include <linux/netdevice.h>
  27. #include <linux/ipv6.h>
  28. #include <linux/slab.h>
  29. #include <net/checksum.h>
  30. #include <net/ip6_checksum.h>
  31. #include <linux/net_tstamp.h>
  32. #include <linux/mii.h>
  33. #include <linux/ethtool.h>
  34. #include <linux/if_vlan.h>
  35. #include <linux/pci.h>
  36. #include <linux/pci-aspm.h>
  37. #include <linux/delay.h>
  38. #include <linux/interrupt.h>
  39. #include <linux/if_ether.h>
  40. #include <linux/aer.h>
  41. #include <linux/prefetch.h>
  42. #ifdef CONFIG_IGB_DCA
  43. #include <linux/dca.h>
  44. #endif
  45. #include "igb.h"
  46. #define MAJ 3
  47. #define MIN 0
  48. #define BUILD 6
  49. #define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
  50. __stringify(BUILD) "-k"
  51. char igb_driver_name[] = "igb";
  52. char igb_driver_version[] = DRV_VERSION;
  53. static const char igb_driver_string[] =
  54. "Intel(R) Gigabit Ethernet Network Driver";
  55. static const char igb_copyright[] = "Copyright (c) 2007-2011 Intel Corporation.";
  56. static const struct e1000_info *igb_info_tbl[] = {
  57. [board_82575] = &e1000_82575_info,
  58. };
  59. static DEFINE_PCI_DEVICE_TABLE(igb_pci_tbl) = {
  60. { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_COPPER), board_82575 },
  61. { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_FIBER), board_82575 },
  62. { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_SERDES), board_82575 },
  63. { PCI_VDEVICE(INTEL, E1000_DEV_ID_I350_SGMII), board_82575 },
  64. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_COPPER), board_82575 },
  65. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_FIBER), board_82575 },
  66. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_QUAD_FIBER), board_82575 },
  67. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_SERDES), board_82575 },
  68. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_SGMII), board_82575 },
  69. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82580_COPPER_DUAL), board_82575 },
  70. { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SGMII), board_82575 },
  71. { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SERDES), board_82575 },
  72. { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_BACKPLANE), board_82575 },
  73. { PCI_VDEVICE(INTEL, E1000_DEV_ID_DH89XXCC_SFP), board_82575 },
  74. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576), board_82575 },
  75. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS), board_82575 },
  76. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_NS_SERDES), board_82575 },
  77. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_FIBER), board_82575 },
  78. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES), board_82575 },
  79. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_SERDES_QUAD), board_82575 },
  80. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER_ET2), board_82575 },
  81. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82576_QUAD_COPPER), board_82575 },
  82. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_COPPER), board_82575 },
  83. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575EB_FIBER_SERDES), board_82575 },
  84. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82575GB_QUAD_COPPER), board_82575 },
  85. /* required last entry */
  86. {0, }
  87. };
  88. MODULE_DEVICE_TABLE(pci, igb_pci_tbl);
  89. void igb_reset(struct igb_adapter *);
  90. static int igb_setup_all_tx_resources(struct igb_adapter *);
  91. static int igb_setup_all_rx_resources(struct igb_adapter *);
  92. static void igb_free_all_tx_resources(struct igb_adapter *);
  93. static void igb_free_all_rx_resources(struct igb_adapter *);
  94. static void igb_setup_mrqc(struct igb_adapter *);
  95. static int igb_probe(struct pci_dev *, const struct pci_device_id *);
  96. static void __devexit igb_remove(struct pci_dev *pdev);
  97. static void igb_init_hw_timer(struct igb_adapter *adapter);
  98. static int igb_sw_init(struct igb_adapter *);
  99. static int igb_open(struct net_device *);
  100. static int igb_close(struct net_device *);
  101. static void igb_configure_tx(struct igb_adapter *);
  102. static void igb_configure_rx(struct igb_adapter *);
  103. static void igb_clean_all_tx_rings(struct igb_adapter *);
  104. static void igb_clean_all_rx_rings(struct igb_adapter *);
  105. static void igb_clean_tx_ring(struct igb_ring *);
  106. static void igb_clean_rx_ring(struct igb_ring *);
  107. static void igb_set_rx_mode(struct net_device *);
  108. static void igb_update_phy_info(unsigned long);
  109. static void igb_watchdog(unsigned long);
  110. static void igb_watchdog_task(struct work_struct *);
  111. static netdev_tx_t igb_xmit_frame_adv(struct sk_buff *skb, struct net_device *);
  112. static struct rtnl_link_stats64 *igb_get_stats64(struct net_device *dev,
  113. struct rtnl_link_stats64 *stats);
  114. static int igb_change_mtu(struct net_device *, int);
  115. static int igb_set_mac(struct net_device *, void *);
  116. static void igb_set_uta(struct igb_adapter *adapter);
  117. static irqreturn_t igb_intr(int irq, void *);
  118. static irqreturn_t igb_intr_msi(int irq, void *);
  119. static irqreturn_t igb_msix_other(int irq, void *);
  120. static irqreturn_t igb_msix_ring(int irq, void *);
  121. #ifdef CONFIG_IGB_DCA
  122. static void igb_update_dca(struct igb_q_vector *);
  123. static void igb_setup_dca(struct igb_adapter *);
  124. #endif /* CONFIG_IGB_DCA */
  125. static bool igb_clean_tx_irq(struct igb_q_vector *);
  126. static int igb_poll(struct napi_struct *, int);
  127. static bool igb_clean_rx_irq_adv(struct igb_q_vector *, int *, int);
  128. static int igb_ioctl(struct net_device *, struct ifreq *, int cmd);
  129. static void igb_tx_timeout(struct net_device *);
  130. static void igb_reset_task(struct work_struct *);
  131. static void igb_vlan_mode(struct net_device *netdev, u32 features);
  132. static void igb_vlan_rx_add_vid(struct net_device *, u16);
  133. static void igb_vlan_rx_kill_vid(struct net_device *, u16);
  134. static void igb_restore_vlan(struct igb_adapter *);
  135. static void igb_rar_set_qsel(struct igb_adapter *, u8 *, u32 , u8);
  136. static void igb_ping_all_vfs(struct igb_adapter *);
  137. static void igb_msg_task(struct igb_adapter *);
  138. static void igb_vmm_control(struct igb_adapter *);
  139. static int igb_set_vf_mac(struct igb_adapter *, int, unsigned char *);
  140. static void igb_restore_vf_multicasts(struct igb_adapter *adapter);
  141. static int igb_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac);
  142. static int igb_ndo_set_vf_vlan(struct net_device *netdev,
  143. int vf, u16 vlan, u8 qos);
  144. static int igb_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate);
  145. static int igb_ndo_get_vf_config(struct net_device *netdev, int vf,
  146. struct ifla_vf_info *ivi);
  147. static void igb_check_vf_rate_limit(struct igb_adapter *);
  148. #ifdef CONFIG_PM
  149. static int igb_suspend(struct pci_dev *, pm_message_t);
  150. static int igb_resume(struct pci_dev *);
  151. #endif
  152. static void igb_shutdown(struct pci_dev *);
  153. #ifdef CONFIG_IGB_DCA
  154. static int igb_notify_dca(struct notifier_block *, unsigned long, void *);
  155. static struct notifier_block dca_notifier = {
  156. .notifier_call = igb_notify_dca,
  157. .next = NULL,
  158. .priority = 0
  159. };
  160. #endif
  161. #ifdef CONFIG_NET_POLL_CONTROLLER
  162. /* for netdump / net console */
  163. static void igb_netpoll(struct net_device *);
  164. #endif
  165. #ifdef CONFIG_PCI_IOV
  166. static unsigned int max_vfs = 0;
  167. module_param(max_vfs, uint, 0);
  168. MODULE_PARM_DESC(max_vfs, "Maximum number of virtual functions to allocate "
  169. "per physical function");
  170. #endif /* CONFIG_PCI_IOV */
  171. static pci_ers_result_t igb_io_error_detected(struct pci_dev *,
  172. pci_channel_state_t);
  173. static pci_ers_result_t igb_io_slot_reset(struct pci_dev *);
  174. static void igb_io_resume(struct pci_dev *);
  175. static struct pci_error_handlers igb_err_handler = {
  176. .error_detected = igb_io_error_detected,
  177. .slot_reset = igb_io_slot_reset,
  178. .resume = igb_io_resume,
  179. };
  180. static struct pci_driver igb_driver = {
  181. .name = igb_driver_name,
  182. .id_table = igb_pci_tbl,
  183. .probe = igb_probe,
  184. .remove = __devexit_p(igb_remove),
  185. #ifdef CONFIG_PM
  186. /* Power Management Hooks */
  187. .suspend = igb_suspend,
  188. .resume = igb_resume,
  189. #endif
  190. .shutdown = igb_shutdown,
  191. .err_handler = &igb_err_handler
  192. };
  193. MODULE_AUTHOR("Intel Corporation, <e1000-devel@lists.sourceforge.net>");
  194. MODULE_DESCRIPTION("Intel(R) Gigabit Ethernet Network Driver");
  195. MODULE_LICENSE("GPL");
  196. MODULE_VERSION(DRV_VERSION);
  197. struct igb_reg_info {
  198. u32 ofs;
  199. char *name;
  200. };
  201. static const struct igb_reg_info igb_reg_info_tbl[] = {
  202. /* General Registers */
  203. {E1000_CTRL, "CTRL"},
  204. {E1000_STATUS, "STATUS"},
  205. {E1000_CTRL_EXT, "CTRL_EXT"},
  206. /* Interrupt Registers */
  207. {E1000_ICR, "ICR"},
  208. /* RX Registers */
  209. {E1000_RCTL, "RCTL"},
  210. {E1000_RDLEN(0), "RDLEN"},
  211. {E1000_RDH(0), "RDH"},
  212. {E1000_RDT(0), "RDT"},
  213. {E1000_RXDCTL(0), "RXDCTL"},
  214. {E1000_RDBAL(0), "RDBAL"},
  215. {E1000_RDBAH(0), "RDBAH"},
  216. /* TX Registers */
  217. {E1000_TCTL, "TCTL"},
  218. {E1000_TDBAL(0), "TDBAL"},
  219. {E1000_TDBAH(0), "TDBAH"},
  220. {E1000_TDLEN(0), "TDLEN"},
  221. {E1000_TDH(0), "TDH"},
  222. {E1000_TDT(0), "TDT"},
  223. {E1000_TXDCTL(0), "TXDCTL"},
  224. {E1000_TDFH, "TDFH"},
  225. {E1000_TDFT, "TDFT"},
  226. {E1000_TDFHS, "TDFHS"},
  227. {E1000_TDFPC, "TDFPC"},
  228. /* List Terminator */
  229. {}
  230. };
  231. /*
  232. * igb_regdump - register printout routine
  233. */
  234. static void igb_regdump(struct e1000_hw *hw, struct igb_reg_info *reginfo)
  235. {
  236. int n = 0;
  237. char rname[16];
  238. u32 regs[8];
  239. switch (reginfo->ofs) {
  240. case E1000_RDLEN(0):
  241. for (n = 0; n < 4; n++)
  242. regs[n] = rd32(E1000_RDLEN(n));
  243. break;
  244. case E1000_RDH(0):
  245. for (n = 0; n < 4; n++)
  246. regs[n] = rd32(E1000_RDH(n));
  247. break;
  248. case E1000_RDT(0):
  249. for (n = 0; n < 4; n++)
  250. regs[n] = rd32(E1000_RDT(n));
  251. break;
  252. case E1000_RXDCTL(0):
  253. for (n = 0; n < 4; n++)
  254. regs[n] = rd32(E1000_RXDCTL(n));
  255. break;
  256. case E1000_RDBAL(0):
  257. for (n = 0; n < 4; n++)
  258. regs[n] = rd32(E1000_RDBAL(n));
  259. break;
  260. case E1000_RDBAH(0):
  261. for (n = 0; n < 4; n++)
  262. regs[n] = rd32(E1000_RDBAH(n));
  263. break;
  264. case E1000_TDBAL(0):
  265. for (n = 0; n < 4; n++)
  266. regs[n] = rd32(E1000_RDBAL(n));
  267. break;
  268. case E1000_TDBAH(0):
  269. for (n = 0; n < 4; n++)
  270. regs[n] = rd32(E1000_TDBAH(n));
  271. break;
  272. case E1000_TDLEN(0):
  273. for (n = 0; n < 4; n++)
  274. regs[n] = rd32(E1000_TDLEN(n));
  275. break;
  276. case E1000_TDH(0):
  277. for (n = 0; n < 4; n++)
  278. regs[n] = rd32(E1000_TDH(n));
  279. break;
  280. case E1000_TDT(0):
  281. for (n = 0; n < 4; n++)
  282. regs[n] = rd32(E1000_TDT(n));
  283. break;
  284. case E1000_TXDCTL(0):
  285. for (n = 0; n < 4; n++)
  286. regs[n] = rd32(E1000_TXDCTL(n));
  287. break;
  288. default:
  289. printk(KERN_INFO "%-15s %08x\n",
  290. reginfo->name, rd32(reginfo->ofs));
  291. return;
  292. }
  293. snprintf(rname, 16, "%s%s", reginfo->name, "[0-3]");
  294. printk(KERN_INFO "%-15s ", rname);
  295. for (n = 0; n < 4; n++)
  296. printk(KERN_CONT "%08x ", regs[n]);
  297. printk(KERN_CONT "\n");
  298. }
  299. /*
  300. * igb_dump - Print registers, tx-rings and rx-rings
  301. */
  302. static void igb_dump(struct igb_adapter *adapter)
  303. {
  304. struct net_device *netdev = adapter->netdev;
  305. struct e1000_hw *hw = &adapter->hw;
  306. struct igb_reg_info *reginfo;
  307. int n = 0;
  308. struct igb_ring *tx_ring;
  309. union e1000_adv_tx_desc *tx_desc;
  310. struct my_u0 { u64 a; u64 b; } *u0;
  311. struct igb_buffer *buffer_info;
  312. struct igb_ring *rx_ring;
  313. union e1000_adv_rx_desc *rx_desc;
  314. u32 staterr;
  315. int i = 0;
  316. if (!netif_msg_hw(adapter))
  317. return;
  318. /* Print netdevice Info */
  319. if (netdev) {
  320. dev_info(&adapter->pdev->dev, "Net device Info\n");
  321. printk(KERN_INFO "Device Name state "
  322. "trans_start last_rx\n");
  323. printk(KERN_INFO "%-15s %016lX %016lX %016lX\n",
  324. netdev->name,
  325. netdev->state,
  326. netdev->trans_start,
  327. netdev->last_rx);
  328. }
  329. /* Print Registers */
  330. dev_info(&adapter->pdev->dev, "Register Dump\n");
  331. printk(KERN_INFO " Register Name Value\n");
  332. for (reginfo = (struct igb_reg_info *)igb_reg_info_tbl;
  333. reginfo->name; reginfo++) {
  334. igb_regdump(hw, reginfo);
  335. }
  336. /* Print TX Ring Summary */
  337. if (!netdev || !netif_running(netdev))
  338. goto exit;
  339. dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
  340. printk(KERN_INFO "Queue [NTU] [NTC] [bi(ntc)->dma ]"
  341. " leng ntw timestamp\n");
  342. for (n = 0; n < adapter->num_tx_queues; n++) {
  343. tx_ring = adapter->tx_ring[n];
  344. buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
  345. printk(KERN_INFO " %5d %5X %5X %016llX %04X %3X %016llX\n",
  346. n, tx_ring->next_to_use, tx_ring->next_to_clean,
  347. (u64)buffer_info->dma,
  348. buffer_info->length,
  349. buffer_info->next_to_watch,
  350. (u64)buffer_info->time_stamp);
  351. }
  352. /* Print TX Rings */
  353. if (!netif_msg_tx_done(adapter))
  354. goto rx_ring_summary;
  355. dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
  356. /* Transmit Descriptor Formats
  357. *
  358. * Advanced Transmit Descriptor
  359. * +--------------------------------------------------------------+
  360. * 0 | Buffer Address [63:0] |
  361. * +--------------------------------------------------------------+
  362. * 8 | PAYLEN | PORTS |CC|IDX | STA | DCMD |DTYP|MAC|RSV| DTALEN |
  363. * +--------------------------------------------------------------+
  364. * 63 46 45 40 39 38 36 35 32 31 24 15 0
  365. */
  366. for (n = 0; n < adapter->num_tx_queues; n++) {
  367. tx_ring = adapter->tx_ring[n];
  368. printk(KERN_INFO "------------------------------------\n");
  369. printk(KERN_INFO "TX QUEUE INDEX = %d\n", tx_ring->queue_index);
  370. printk(KERN_INFO "------------------------------------\n");
  371. printk(KERN_INFO "T [desc] [address 63:0 ] "
  372. "[PlPOCIStDDM Ln] [bi->dma ] "
  373. "leng ntw timestamp bi->skb\n");
  374. for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
  375. tx_desc = E1000_TX_DESC_ADV(*tx_ring, i);
  376. buffer_info = &tx_ring->buffer_info[i];
  377. u0 = (struct my_u0 *)tx_desc;
  378. printk(KERN_INFO "T [0x%03X] %016llX %016llX %016llX"
  379. " %04X %3X %016llX %p", i,
  380. le64_to_cpu(u0->a),
  381. le64_to_cpu(u0->b),
  382. (u64)buffer_info->dma,
  383. buffer_info->length,
  384. buffer_info->next_to_watch,
  385. (u64)buffer_info->time_stamp,
  386. buffer_info->skb);
  387. if (i == tx_ring->next_to_use &&
  388. i == tx_ring->next_to_clean)
  389. printk(KERN_CONT " NTC/U\n");
  390. else if (i == tx_ring->next_to_use)
  391. printk(KERN_CONT " NTU\n");
  392. else if (i == tx_ring->next_to_clean)
  393. printk(KERN_CONT " NTC\n");
  394. else
  395. printk(KERN_CONT "\n");
  396. if (netif_msg_pktdata(adapter) && buffer_info->dma != 0)
  397. print_hex_dump(KERN_INFO, "",
  398. DUMP_PREFIX_ADDRESS,
  399. 16, 1, phys_to_virt(buffer_info->dma),
  400. buffer_info->length, true);
  401. }
  402. }
  403. /* Print RX Rings Summary */
  404. rx_ring_summary:
  405. dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
  406. printk(KERN_INFO "Queue [NTU] [NTC]\n");
  407. for (n = 0; n < adapter->num_rx_queues; n++) {
  408. rx_ring = adapter->rx_ring[n];
  409. printk(KERN_INFO " %5d %5X %5X\n", n,
  410. rx_ring->next_to_use, rx_ring->next_to_clean);
  411. }
  412. /* Print RX Rings */
  413. if (!netif_msg_rx_status(adapter))
  414. goto exit;
  415. dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
  416. /* Advanced Receive Descriptor (Read) Format
  417. * 63 1 0
  418. * +-----------------------------------------------------+
  419. * 0 | Packet Buffer Address [63:1] |A0/NSE|
  420. * +----------------------------------------------+------+
  421. * 8 | Header Buffer Address [63:1] | DD |
  422. * +-----------------------------------------------------+
  423. *
  424. *
  425. * Advanced Receive Descriptor (Write-Back) Format
  426. *
  427. * 63 48 47 32 31 30 21 20 17 16 4 3 0
  428. * +------------------------------------------------------+
  429. * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
  430. * | Checksum Ident | | | | Type | Type |
  431. * +------------------------------------------------------+
  432. * 8 | VLAN Tag | Length | Extended Error | Extended Status |
  433. * +------------------------------------------------------+
  434. * 63 48 47 32 31 20 19 0
  435. */
  436. for (n = 0; n < adapter->num_rx_queues; n++) {
  437. rx_ring = adapter->rx_ring[n];
  438. printk(KERN_INFO "------------------------------------\n");
  439. printk(KERN_INFO "RX QUEUE INDEX = %d\n", rx_ring->queue_index);
  440. printk(KERN_INFO "------------------------------------\n");
  441. printk(KERN_INFO "R [desc] [ PktBuf A0] "
  442. "[ HeadBuf DD] [bi->dma ] [bi->skb] "
  443. "<-- Adv Rx Read format\n");
  444. printk(KERN_INFO "RWB[desc] [PcsmIpSHl PtRs] "
  445. "[vl er S cks ln] ---------------- [bi->skb] "
  446. "<-- Adv Rx Write-Back format\n");
  447. for (i = 0; i < rx_ring->count; i++) {
  448. buffer_info = &rx_ring->buffer_info[i];
  449. rx_desc = E1000_RX_DESC_ADV(*rx_ring, i);
  450. u0 = (struct my_u0 *)rx_desc;
  451. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  452. if (staterr & E1000_RXD_STAT_DD) {
  453. /* Descriptor Done */
  454. printk(KERN_INFO "RWB[0x%03X] %016llX "
  455. "%016llX ---------------- %p", i,
  456. le64_to_cpu(u0->a),
  457. le64_to_cpu(u0->b),
  458. buffer_info->skb);
  459. } else {
  460. printk(KERN_INFO "R [0x%03X] %016llX "
  461. "%016llX %016llX %p", i,
  462. le64_to_cpu(u0->a),
  463. le64_to_cpu(u0->b),
  464. (u64)buffer_info->dma,
  465. buffer_info->skb);
  466. if (netif_msg_pktdata(adapter)) {
  467. print_hex_dump(KERN_INFO, "",
  468. DUMP_PREFIX_ADDRESS,
  469. 16, 1,
  470. phys_to_virt(buffer_info->dma),
  471. rx_ring->rx_buffer_len, true);
  472. if (rx_ring->rx_buffer_len
  473. < IGB_RXBUFFER_1024)
  474. print_hex_dump(KERN_INFO, "",
  475. DUMP_PREFIX_ADDRESS,
  476. 16, 1,
  477. phys_to_virt(
  478. buffer_info->page_dma +
  479. buffer_info->page_offset),
  480. PAGE_SIZE/2, true);
  481. }
  482. }
  483. if (i == rx_ring->next_to_use)
  484. printk(KERN_CONT " NTU\n");
  485. else if (i == rx_ring->next_to_clean)
  486. printk(KERN_CONT " NTC\n");
  487. else
  488. printk(KERN_CONT "\n");
  489. }
  490. }
  491. exit:
  492. return;
  493. }
  494. /**
  495. * igb_read_clock - read raw cycle counter (to be used by time counter)
  496. */
  497. static cycle_t igb_read_clock(const struct cyclecounter *tc)
  498. {
  499. struct igb_adapter *adapter =
  500. container_of(tc, struct igb_adapter, cycles);
  501. struct e1000_hw *hw = &adapter->hw;
  502. u64 stamp = 0;
  503. int shift = 0;
  504. /*
  505. * The timestamp latches on lowest register read. For the 82580
  506. * the lowest register is SYSTIMR instead of SYSTIML. However we never
  507. * adjusted TIMINCA so SYSTIMR will just read as all 0s so ignore it.
  508. */
  509. if (hw->mac.type == e1000_82580) {
  510. stamp = rd32(E1000_SYSTIMR) >> 8;
  511. shift = IGB_82580_TSYNC_SHIFT;
  512. }
  513. stamp |= (u64)rd32(E1000_SYSTIML) << shift;
  514. stamp |= (u64)rd32(E1000_SYSTIMH) << (shift + 32);
  515. return stamp;
  516. }
  517. /**
  518. * igb_get_hw_dev - return device
  519. * used by hardware layer to print debugging information
  520. **/
  521. struct net_device *igb_get_hw_dev(struct e1000_hw *hw)
  522. {
  523. struct igb_adapter *adapter = hw->back;
  524. return adapter->netdev;
  525. }
  526. /**
  527. * igb_init_module - Driver Registration Routine
  528. *
  529. * igb_init_module is the first routine called when the driver is
  530. * loaded. All it does is register with the PCI subsystem.
  531. **/
  532. static int __init igb_init_module(void)
  533. {
  534. int ret;
  535. printk(KERN_INFO "%s - version %s\n",
  536. igb_driver_string, igb_driver_version);
  537. printk(KERN_INFO "%s\n", igb_copyright);
  538. #ifdef CONFIG_IGB_DCA
  539. dca_register_notify(&dca_notifier);
  540. #endif
  541. ret = pci_register_driver(&igb_driver);
  542. return ret;
  543. }
  544. module_init(igb_init_module);
  545. /**
  546. * igb_exit_module - Driver Exit Cleanup Routine
  547. *
  548. * igb_exit_module is called just before the driver is removed
  549. * from memory.
  550. **/
  551. static void __exit igb_exit_module(void)
  552. {
  553. #ifdef CONFIG_IGB_DCA
  554. dca_unregister_notify(&dca_notifier);
  555. #endif
  556. pci_unregister_driver(&igb_driver);
  557. }
  558. module_exit(igb_exit_module);
  559. #define Q_IDX_82576(i) (((i & 0x1) << 3) + (i >> 1))
  560. /**
  561. * igb_cache_ring_register - Descriptor ring to register mapping
  562. * @adapter: board private structure to initialize
  563. *
  564. * Once we know the feature-set enabled for the device, we'll cache
  565. * the register offset the descriptor ring is assigned to.
  566. **/
  567. static void igb_cache_ring_register(struct igb_adapter *adapter)
  568. {
  569. int i = 0, j = 0;
  570. u32 rbase_offset = adapter->vfs_allocated_count;
  571. switch (adapter->hw.mac.type) {
  572. case e1000_82576:
  573. /* The queues are allocated for virtualization such that VF 0
  574. * is allocated queues 0 and 8, VF 1 queues 1 and 9, etc.
  575. * In order to avoid collision we start at the first free queue
  576. * and continue consuming queues in the same sequence
  577. */
  578. if (adapter->vfs_allocated_count) {
  579. for (; i < adapter->rss_queues; i++)
  580. adapter->rx_ring[i]->reg_idx = rbase_offset +
  581. Q_IDX_82576(i);
  582. }
  583. case e1000_82575:
  584. case e1000_82580:
  585. case e1000_i350:
  586. default:
  587. for (; i < adapter->num_rx_queues; i++)
  588. adapter->rx_ring[i]->reg_idx = rbase_offset + i;
  589. for (; j < adapter->num_tx_queues; j++)
  590. adapter->tx_ring[j]->reg_idx = rbase_offset + j;
  591. break;
  592. }
  593. }
  594. static void igb_free_queues(struct igb_adapter *adapter)
  595. {
  596. int i;
  597. for (i = 0; i < adapter->num_tx_queues; i++) {
  598. kfree(adapter->tx_ring[i]);
  599. adapter->tx_ring[i] = NULL;
  600. }
  601. for (i = 0; i < adapter->num_rx_queues; i++) {
  602. kfree(adapter->rx_ring[i]);
  603. adapter->rx_ring[i] = NULL;
  604. }
  605. adapter->num_rx_queues = 0;
  606. adapter->num_tx_queues = 0;
  607. }
  608. /**
  609. * igb_alloc_queues - Allocate memory for all rings
  610. * @adapter: board private structure to initialize
  611. *
  612. * We allocate one ring per queue at run-time since we don't know the
  613. * number of queues at compile-time.
  614. **/
  615. static int igb_alloc_queues(struct igb_adapter *adapter)
  616. {
  617. struct igb_ring *ring;
  618. int i;
  619. for (i = 0; i < adapter->num_tx_queues; i++) {
  620. ring = kzalloc(sizeof(struct igb_ring), GFP_KERNEL);
  621. if (!ring)
  622. goto err;
  623. ring->count = adapter->tx_ring_count;
  624. ring->queue_index = i;
  625. ring->dev = &adapter->pdev->dev;
  626. ring->netdev = adapter->netdev;
  627. /* For 82575, context index must be unique per ring. */
  628. if (adapter->hw.mac.type == e1000_82575)
  629. ring->flags = IGB_RING_FLAG_TX_CTX_IDX;
  630. adapter->tx_ring[i] = ring;
  631. }
  632. for (i = 0; i < adapter->num_rx_queues; i++) {
  633. ring = kzalloc(sizeof(struct igb_ring), GFP_KERNEL);
  634. if (!ring)
  635. goto err;
  636. ring->count = adapter->rx_ring_count;
  637. ring->queue_index = i;
  638. ring->dev = &adapter->pdev->dev;
  639. ring->netdev = adapter->netdev;
  640. ring->rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
  641. ring->flags = IGB_RING_FLAG_RX_CSUM; /* enable rx checksum */
  642. /* set flag indicating ring supports SCTP checksum offload */
  643. if (adapter->hw.mac.type >= e1000_82576)
  644. ring->flags |= IGB_RING_FLAG_RX_SCTP_CSUM;
  645. adapter->rx_ring[i] = ring;
  646. }
  647. igb_cache_ring_register(adapter);
  648. return 0;
  649. err:
  650. igb_free_queues(adapter);
  651. return -ENOMEM;
  652. }
  653. #define IGB_N0_QUEUE -1
  654. static void igb_assign_vector(struct igb_q_vector *q_vector, int msix_vector)
  655. {
  656. u32 msixbm = 0;
  657. struct igb_adapter *adapter = q_vector->adapter;
  658. struct e1000_hw *hw = &adapter->hw;
  659. u32 ivar, index;
  660. int rx_queue = IGB_N0_QUEUE;
  661. int tx_queue = IGB_N0_QUEUE;
  662. if (q_vector->rx_ring)
  663. rx_queue = q_vector->rx_ring->reg_idx;
  664. if (q_vector->tx_ring)
  665. tx_queue = q_vector->tx_ring->reg_idx;
  666. switch (hw->mac.type) {
  667. case e1000_82575:
  668. /* The 82575 assigns vectors using a bitmask, which matches the
  669. bitmask for the EICR/EIMS/EIMC registers. To assign one
  670. or more queues to a vector, we write the appropriate bits
  671. into the MSIXBM register for that vector. */
  672. if (rx_queue > IGB_N0_QUEUE)
  673. msixbm = E1000_EICR_RX_QUEUE0 << rx_queue;
  674. if (tx_queue > IGB_N0_QUEUE)
  675. msixbm |= E1000_EICR_TX_QUEUE0 << tx_queue;
  676. if (!adapter->msix_entries && msix_vector == 0)
  677. msixbm |= E1000_EIMS_OTHER;
  678. array_wr32(E1000_MSIXBM(0), msix_vector, msixbm);
  679. q_vector->eims_value = msixbm;
  680. break;
  681. case e1000_82576:
  682. /* 82576 uses a table-based method for assigning vectors.
  683. Each queue has a single entry in the table to which we write
  684. a vector number along with a "valid" bit. Sadly, the layout
  685. of the table is somewhat counterintuitive. */
  686. if (rx_queue > IGB_N0_QUEUE) {
  687. index = (rx_queue & 0x7);
  688. ivar = array_rd32(E1000_IVAR0, index);
  689. if (rx_queue < 8) {
  690. /* vector goes into low byte of register */
  691. ivar = ivar & 0xFFFFFF00;
  692. ivar |= msix_vector | E1000_IVAR_VALID;
  693. } else {
  694. /* vector goes into third byte of register */
  695. ivar = ivar & 0xFF00FFFF;
  696. ivar |= (msix_vector | E1000_IVAR_VALID) << 16;
  697. }
  698. array_wr32(E1000_IVAR0, index, ivar);
  699. }
  700. if (tx_queue > IGB_N0_QUEUE) {
  701. index = (tx_queue & 0x7);
  702. ivar = array_rd32(E1000_IVAR0, index);
  703. if (tx_queue < 8) {
  704. /* vector goes into second byte of register */
  705. ivar = ivar & 0xFFFF00FF;
  706. ivar |= (msix_vector | E1000_IVAR_VALID) << 8;
  707. } else {
  708. /* vector goes into high byte of register */
  709. ivar = ivar & 0x00FFFFFF;
  710. ivar |= (msix_vector | E1000_IVAR_VALID) << 24;
  711. }
  712. array_wr32(E1000_IVAR0, index, ivar);
  713. }
  714. q_vector->eims_value = 1 << msix_vector;
  715. break;
  716. case e1000_82580:
  717. case e1000_i350:
  718. /* 82580 uses the same table-based approach as 82576 but has fewer
  719. entries as a result we carry over for queues greater than 4. */
  720. if (rx_queue > IGB_N0_QUEUE) {
  721. index = (rx_queue >> 1);
  722. ivar = array_rd32(E1000_IVAR0, index);
  723. if (rx_queue & 0x1) {
  724. /* vector goes into third byte of register */
  725. ivar = ivar & 0xFF00FFFF;
  726. ivar |= (msix_vector | E1000_IVAR_VALID) << 16;
  727. } else {
  728. /* vector goes into low byte of register */
  729. ivar = ivar & 0xFFFFFF00;
  730. ivar |= msix_vector | E1000_IVAR_VALID;
  731. }
  732. array_wr32(E1000_IVAR0, index, ivar);
  733. }
  734. if (tx_queue > IGB_N0_QUEUE) {
  735. index = (tx_queue >> 1);
  736. ivar = array_rd32(E1000_IVAR0, index);
  737. if (tx_queue & 0x1) {
  738. /* vector goes into high byte of register */
  739. ivar = ivar & 0x00FFFFFF;
  740. ivar |= (msix_vector | E1000_IVAR_VALID) << 24;
  741. } else {
  742. /* vector goes into second byte of register */
  743. ivar = ivar & 0xFFFF00FF;
  744. ivar |= (msix_vector | E1000_IVAR_VALID) << 8;
  745. }
  746. array_wr32(E1000_IVAR0, index, ivar);
  747. }
  748. q_vector->eims_value = 1 << msix_vector;
  749. break;
  750. default:
  751. BUG();
  752. break;
  753. }
  754. /* add q_vector eims value to global eims_enable_mask */
  755. adapter->eims_enable_mask |= q_vector->eims_value;
  756. /* configure q_vector to set itr on first interrupt */
  757. q_vector->set_itr = 1;
  758. }
  759. /**
  760. * igb_configure_msix - Configure MSI-X hardware
  761. *
  762. * igb_configure_msix sets up the hardware to properly
  763. * generate MSI-X interrupts.
  764. **/
  765. static void igb_configure_msix(struct igb_adapter *adapter)
  766. {
  767. u32 tmp;
  768. int i, vector = 0;
  769. struct e1000_hw *hw = &adapter->hw;
  770. adapter->eims_enable_mask = 0;
  771. /* set vector for other causes, i.e. link changes */
  772. switch (hw->mac.type) {
  773. case e1000_82575:
  774. tmp = rd32(E1000_CTRL_EXT);
  775. /* enable MSI-X PBA support*/
  776. tmp |= E1000_CTRL_EXT_PBA_CLR;
  777. /* Auto-Mask interrupts upon ICR read. */
  778. tmp |= E1000_CTRL_EXT_EIAME;
  779. tmp |= E1000_CTRL_EXT_IRCA;
  780. wr32(E1000_CTRL_EXT, tmp);
  781. /* enable msix_other interrupt */
  782. array_wr32(E1000_MSIXBM(0), vector++,
  783. E1000_EIMS_OTHER);
  784. adapter->eims_other = E1000_EIMS_OTHER;
  785. break;
  786. case e1000_82576:
  787. case e1000_82580:
  788. case e1000_i350:
  789. /* Turn on MSI-X capability first, or our settings
  790. * won't stick. And it will take days to debug. */
  791. wr32(E1000_GPIE, E1000_GPIE_MSIX_MODE |
  792. E1000_GPIE_PBA | E1000_GPIE_EIAME |
  793. E1000_GPIE_NSICR);
  794. /* enable msix_other interrupt */
  795. adapter->eims_other = 1 << vector;
  796. tmp = (vector++ | E1000_IVAR_VALID) << 8;
  797. wr32(E1000_IVAR_MISC, tmp);
  798. break;
  799. default:
  800. /* do nothing, since nothing else supports MSI-X */
  801. break;
  802. } /* switch (hw->mac.type) */
  803. adapter->eims_enable_mask |= adapter->eims_other;
  804. for (i = 0; i < adapter->num_q_vectors; i++)
  805. igb_assign_vector(adapter->q_vector[i], vector++);
  806. wrfl();
  807. }
  808. /**
  809. * igb_request_msix - Initialize MSI-X interrupts
  810. *
  811. * igb_request_msix allocates MSI-X vectors and requests interrupts from the
  812. * kernel.
  813. **/
  814. static int igb_request_msix(struct igb_adapter *adapter)
  815. {
  816. struct net_device *netdev = adapter->netdev;
  817. struct e1000_hw *hw = &adapter->hw;
  818. int i, err = 0, vector = 0;
  819. err = request_irq(adapter->msix_entries[vector].vector,
  820. igb_msix_other, 0, netdev->name, adapter);
  821. if (err)
  822. goto out;
  823. vector++;
  824. for (i = 0; i < adapter->num_q_vectors; i++) {
  825. struct igb_q_vector *q_vector = adapter->q_vector[i];
  826. q_vector->itr_register = hw->hw_addr + E1000_EITR(vector);
  827. if (q_vector->rx_ring && q_vector->tx_ring)
  828. sprintf(q_vector->name, "%s-TxRx-%u", netdev->name,
  829. q_vector->rx_ring->queue_index);
  830. else if (q_vector->tx_ring)
  831. sprintf(q_vector->name, "%s-tx-%u", netdev->name,
  832. q_vector->tx_ring->queue_index);
  833. else if (q_vector->rx_ring)
  834. sprintf(q_vector->name, "%s-rx-%u", netdev->name,
  835. q_vector->rx_ring->queue_index);
  836. else
  837. sprintf(q_vector->name, "%s-unused", netdev->name);
  838. err = request_irq(adapter->msix_entries[vector].vector,
  839. igb_msix_ring, 0, q_vector->name,
  840. q_vector);
  841. if (err)
  842. goto out;
  843. vector++;
  844. }
  845. igb_configure_msix(adapter);
  846. return 0;
  847. out:
  848. return err;
  849. }
  850. static void igb_reset_interrupt_capability(struct igb_adapter *adapter)
  851. {
  852. if (adapter->msix_entries) {
  853. pci_disable_msix(adapter->pdev);
  854. kfree(adapter->msix_entries);
  855. adapter->msix_entries = NULL;
  856. } else if (adapter->flags & IGB_FLAG_HAS_MSI) {
  857. pci_disable_msi(adapter->pdev);
  858. }
  859. }
  860. /**
  861. * igb_free_q_vectors - Free memory allocated for interrupt vectors
  862. * @adapter: board private structure to initialize
  863. *
  864. * This function frees the memory allocated to the q_vectors. In addition if
  865. * NAPI is enabled it will delete any references to the NAPI struct prior
  866. * to freeing the q_vector.
  867. **/
  868. static void igb_free_q_vectors(struct igb_adapter *adapter)
  869. {
  870. int v_idx;
  871. for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
  872. struct igb_q_vector *q_vector = adapter->q_vector[v_idx];
  873. adapter->q_vector[v_idx] = NULL;
  874. if (!q_vector)
  875. continue;
  876. netif_napi_del(&q_vector->napi);
  877. kfree(q_vector);
  878. }
  879. adapter->num_q_vectors = 0;
  880. }
  881. /**
  882. * igb_clear_interrupt_scheme - reset the device to a state of no interrupts
  883. *
  884. * This function resets the device so that it has 0 rx queues, tx queues, and
  885. * MSI-X interrupts allocated.
  886. */
  887. static void igb_clear_interrupt_scheme(struct igb_adapter *adapter)
  888. {
  889. igb_free_queues(adapter);
  890. igb_free_q_vectors(adapter);
  891. igb_reset_interrupt_capability(adapter);
  892. }
  893. /**
  894. * igb_set_interrupt_capability - set MSI or MSI-X if supported
  895. *
  896. * Attempt to configure interrupts using the best available
  897. * capabilities of the hardware and kernel.
  898. **/
  899. static int igb_set_interrupt_capability(struct igb_adapter *adapter)
  900. {
  901. int err;
  902. int numvecs, i;
  903. /* Number of supported queues. */
  904. adapter->num_rx_queues = adapter->rss_queues;
  905. if (adapter->vfs_allocated_count)
  906. adapter->num_tx_queues = 1;
  907. else
  908. adapter->num_tx_queues = adapter->rss_queues;
  909. /* start with one vector for every rx queue */
  910. numvecs = adapter->num_rx_queues;
  911. /* if tx handler is separate add 1 for every tx queue */
  912. if (!(adapter->flags & IGB_FLAG_QUEUE_PAIRS))
  913. numvecs += adapter->num_tx_queues;
  914. /* store the number of vectors reserved for queues */
  915. adapter->num_q_vectors = numvecs;
  916. /* add 1 vector for link status interrupts */
  917. numvecs++;
  918. adapter->msix_entries = kcalloc(numvecs, sizeof(struct msix_entry),
  919. GFP_KERNEL);
  920. if (!adapter->msix_entries)
  921. goto msi_only;
  922. for (i = 0; i < numvecs; i++)
  923. adapter->msix_entries[i].entry = i;
  924. err = pci_enable_msix(adapter->pdev,
  925. adapter->msix_entries,
  926. numvecs);
  927. if (err == 0)
  928. goto out;
  929. igb_reset_interrupt_capability(adapter);
  930. /* If we can't do MSI-X, try MSI */
  931. msi_only:
  932. #ifdef CONFIG_PCI_IOV
  933. /* disable SR-IOV for non MSI-X configurations */
  934. if (adapter->vf_data) {
  935. struct e1000_hw *hw = &adapter->hw;
  936. /* disable iov and allow time for transactions to clear */
  937. pci_disable_sriov(adapter->pdev);
  938. msleep(500);
  939. kfree(adapter->vf_data);
  940. adapter->vf_data = NULL;
  941. wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ);
  942. wrfl();
  943. msleep(100);
  944. dev_info(&adapter->pdev->dev, "IOV Disabled\n");
  945. }
  946. #endif
  947. adapter->vfs_allocated_count = 0;
  948. adapter->rss_queues = 1;
  949. adapter->flags |= IGB_FLAG_QUEUE_PAIRS;
  950. adapter->num_rx_queues = 1;
  951. adapter->num_tx_queues = 1;
  952. adapter->num_q_vectors = 1;
  953. if (!pci_enable_msi(adapter->pdev))
  954. adapter->flags |= IGB_FLAG_HAS_MSI;
  955. out:
  956. /* Notify the stack of the (possibly) reduced queue counts. */
  957. netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
  958. return netif_set_real_num_rx_queues(adapter->netdev,
  959. adapter->num_rx_queues);
  960. }
  961. /**
  962. * igb_alloc_q_vectors - Allocate memory for interrupt vectors
  963. * @adapter: board private structure to initialize
  964. *
  965. * We allocate one q_vector per queue interrupt. If allocation fails we
  966. * return -ENOMEM.
  967. **/
  968. static int igb_alloc_q_vectors(struct igb_adapter *adapter)
  969. {
  970. struct igb_q_vector *q_vector;
  971. struct e1000_hw *hw = &adapter->hw;
  972. int v_idx;
  973. for (v_idx = 0; v_idx < adapter->num_q_vectors; v_idx++) {
  974. q_vector = kzalloc(sizeof(struct igb_q_vector), GFP_KERNEL);
  975. if (!q_vector)
  976. goto err_out;
  977. q_vector->adapter = adapter;
  978. q_vector->itr_register = hw->hw_addr + E1000_EITR(0);
  979. q_vector->itr_val = IGB_START_ITR;
  980. netif_napi_add(adapter->netdev, &q_vector->napi, igb_poll, 64);
  981. adapter->q_vector[v_idx] = q_vector;
  982. }
  983. return 0;
  984. err_out:
  985. igb_free_q_vectors(adapter);
  986. return -ENOMEM;
  987. }
  988. static void igb_map_rx_ring_to_vector(struct igb_adapter *adapter,
  989. int ring_idx, int v_idx)
  990. {
  991. struct igb_q_vector *q_vector = adapter->q_vector[v_idx];
  992. q_vector->rx_ring = adapter->rx_ring[ring_idx];
  993. q_vector->rx_ring->q_vector = q_vector;
  994. q_vector->itr_val = adapter->rx_itr_setting;
  995. if (q_vector->itr_val && q_vector->itr_val <= 3)
  996. q_vector->itr_val = IGB_START_ITR;
  997. }
  998. static void igb_map_tx_ring_to_vector(struct igb_adapter *adapter,
  999. int ring_idx, int v_idx)
  1000. {
  1001. struct igb_q_vector *q_vector = adapter->q_vector[v_idx];
  1002. q_vector->tx_ring = adapter->tx_ring[ring_idx];
  1003. q_vector->tx_ring->q_vector = q_vector;
  1004. q_vector->itr_val = adapter->tx_itr_setting;
  1005. if (q_vector->itr_val && q_vector->itr_val <= 3)
  1006. q_vector->itr_val = IGB_START_ITR;
  1007. }
  1008. /**
  1009. * igb_map_ring_to_vector - maps allocated queues to vectors
  1010. *
  1011. * This function maps the recently allocated queues to vectors.
  1012. **/
  1013. static int igb_map_ring_to_vector(struct igb_adapter *adapter)
  1014. {
  1015. int i;
  1016. int v_idx = 0;
  1017. if ((adapter->num_q_vectors < adapter->num_rx_queues) ||
  1018. (adapter->num_q_vectors < adapter->num_tx_queues))
  1019. return -ENOMEM;
  1020. if (adapter->num_q_vectors >=
  1021. (adapter->num_rx_queues + adapter->num_tx_queues)) {
  1022. for (i = 0; i < adapter->num_rx_queues; i++)
  1023. igb_map_rx_ring_to_vector(adapter, i, v_idx++);
  1024. for (i = 0; i < adapter->num_tx_queues; i++)
  1025. igb_map_tx_ring_to_vector(adapter, i, v_idx++);
  1026. } else {
  1027. for (i = 0; i < adapter->num_rx_queues; i++) {
  1028. if (i < adapter->num_tx_queues)
  1029. igb_map_tx_ring_to_vector(adapter, i, v_idx);
  1030. igb_map_rx_ring_to_vector(adapter, i, v_idx++);
  1031. }
  1032. for (; i < adapter->num_tx_queues; i++)
  1033. igb_map_tx_ring_to_vector(adapter, i, v_idx++);
  1034. }
  1035. return 0;
  1036. }
  1037. /**
  1038. * igb_init_interrupt_scheme - initialize interrupts, allocate queues/vectors
  1039. *
  1040. * This function initializes the interrupts and allocates all of the queues.
  1041. **/
  1042. static int igb_init_interrupt_scheme(struct igb_adapter *adapter)
  1043. {
  1044. struct pci_dev *pdev = adapter->pdev;
  1045. int err;
  1046. err = igb_set_interrupt_capability(adapter);
  1047. if (err)
  1048. return err;
  1049. err = igb_alloc_q_vectors(adapter);
  1050. if (err) {
  1051. dev_err(&pdev->dev, "Unable to allocate memory for vectors\n");
  1052. goto err_alloc_q_vectors;
  1053. }
  1054. err = igb_alloc_queues(adapter);
  1055. if (err) {
  1056. dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
  1057. goto err_alloc_queues;
  1058. }
  1059. err = igb_map_ring_to_vector(adapter);
  1060. if (err) {
  1061. dev_err(&pdev->dev, "Invalid q_vector to ring mapping\n");
  1062. goto err_map_queues;
  1063. }
  1064. return 0;
  1065. err_map_queues:
  1066. igb_free_queues(adapter);
  1067. err_alloc_queues:
  1068. igb_free_q_vectors(adapter);
  1069. err_alloc_q_vectors:
  1070. igb_reset_interrupt_capability(adapter);
  1071. return err;
  1072. }
  1073. /**
  1074. * igb_request_irq - initialize interrupts
  1075. *
  1076. * Attempts to configure interrupts using the best available
  1077. * capabilities of the hardware and kernel.
  1078. **/
  1079. static int igb_request_irq(struct igb_adapter *adapter)
  1080. {
  1081. struct net_device *netdev = adapter->netdev;
  1082. struct pci_dev *pdev = adapter->pdev;
  1083. int err = 0;
  1084. if (adapter->msix_entries) {
  1085. err = igb_request_msix(adapter);
  1086. if (!err)
  1087. goto request_done;
  1088. /* fall back to MSI */
  1089. igb_clear_interrupt_scheme(adapter);
  1090. if (!pci_enable_msi(adapter->pdev))
  1091. adapter->flags |= IGB_FLAG_HAS_MSI;
  1092. igb_free_all_tx_resources(adapter);
  1093. igb_free_all_rx_resources(adapter);
  1094. adapter->num_tx_queues = 1;
  1095. adapter->num_rx_queues = 1;
  1096. adapter->num_q_vectors = 1;
  1097. err = igb_alloc_q_vectors(adapter);
  1098. if (err) {
  1099. dev_err(&pdev->dev,
  1100. "Unable to allocate memory for vectors\n");
  1101. goto request_done;
  1102. }
  1103. err = igb_alloc_queues(adapter);
  1104. if (err) {
  1105. dev_err(&pdev->dev,
  1106. "Unable to allocate memory for queues\n");
  1107. igb_free_q_vectors(adapter);
  1108. goto request_done;
  1109. }
  1110. igb_setup_all_tx_resources(adapter);
  1111. igb_setup_all_rx_resources(adapter);
  1112. } else {
  1113. igb_assign_vector(adapter->q_vector[0], 0);
  1114. }
  1115. if (adapter->flags & IGB_FLAG_HAS_MSI) {
  1116. err = request_irq(adapter->pdev->irq, igb_intr_msi, 0,
  1117. netdev->name, adapter);
  1118. if (!err)
  1119. goto request_done;
  1120. /* fall back to legacy interrupts */
  1121. igb_reset_interrupt_capability(adapter);
  1122. adapter->flags &= ~IGB_FLAG_HAS_MSI;
  1123. }
  1124. err = request_irq(adapter->pdev->irq, igb_intr, IRQF_SHARED,
  1125. netdev->name, adapter);
  1126. if (err)
  1127. dev_err(&adapter->pdev->dev, "Error %d getting interrupt\n",
  1128. err);
  1129. request_done:
  1130. return err;
  1131. }
  1132. static void igb_free_irq(struct igb_adapter *adapter)
  1133. {
  1134. if (adapter->msix_entries) {
  1135. int vector = 0, i;
  1136. free_irq(adapter->msix_entries[vector++].vector, adapter);
  1137. for (i = 0; i < adapter->num_q_vectors; i++) {
  1138. struct igb_q_vector *q_vector = adapter->q_vector[i];
  1139. free_irq(adapter->msix_entries[vector++].vector,
  1140. q_vector);
  1141. }
  1142. } else {
  1143. free_irq(adapter->pdev->irq, adapter);
  1144. }
  1145. }
  1146. /**
  1147. * igb_irq_disable - Mask off interrupt generation on the NIC
  1148. * @adapter: board private structure
  1149. **/
  1150. static void igb_irq_disable(struct igb_adapter *adapter)
  1151. {
  1152. struct e1000_hw *hw = &adapter->hw;
  1153. /*
  1154. * we need to be careful when disabling interrupts. The VFs are also
  1155. * mapped into these registers and so clearing the bits can cause
  1156. * issues on the VF drivers so we only need to clear what we set
  1157. */
  1158. if (adapter->msix_entries) {
  1159. u32 regval = rd32(E1000_EIAM);
  1160. wr32(E1000_EIAM, regval & ~adapter->eims_enable_mask);
  1161. wr32(E1000_EIMC, adapter->eims_enable_mask);
  1162. regval = rd32(E1000_EIAC);
  1163. wr32(E1000_EIAC, regval & ~adapter->eims_enable_mask);
  1164. }
  1165. wr32(E1000_IAM, 0);
  1166. wr32(E1000_IMC, ~0);
  1167. wrfl();
  1168. if (adapter->msix_entries) {
  1169. int i;
  1170. for (i = 0; i < adapter->num_q_vectors; i++)
  1171. synchronize_irq(adapter->msix_entries[i].vector);
  1172. } else {
  1173. synchronize_irq(adapter->pdev->irq);
  1174. }
  1175. }
  1176. /**
  1177. * igb_irq_enable - Enable default interrupt generation settings
  1178. * @adapter: board private structure
  1179. **/
  1180. static void igb_irq_enable(struct igb_adapter *adapter)
  1181. {
  1182. struct e1000_hw *hw = &adapter->hw;
  1183. if (adapter->msix_entries) {
  1184. u32 ims = E1000_IMS_LSC | E1000_IMS_DOUTSYNC;
  1185. u32 regval = rd32(E1000_EIAC);
  1186. wr32(E1000_EIAC, regval | adapter->eims_enable_mask);
  1187. regval = rd32(E1000_EIAM);
  1188. wr32(E1000_EIAM, regval | adapter->eims_enable_mask);
  1189. wr32(E1000_EIMS, adapter->eims_enable_mask);
  1190. if (adapter->vfs_allocated_count) {
  1191. wr32(E1000_MBVFIMR, 0xFF);
  1192. ims |= E1000_IMS_VMMB;
  1193. }
  1194. if (adapter->hw.mac.type == e1000_82580)
  1195. ims |= E1000_IMS_DRSTA;
  1196. wr32(E1000_IMS, ims);
  1197. } else {
  1198. wr32(E1000_IMS, IMS_ENABLE_MASK |
  1199. E1000_IMS_DRSTA);
  1200. wr32(E1000_IAM, IMS_ENABLE_MASK |
  1201. E1000_IMS_DRSTA);
  1202. }
  1203. }
  1204. static void igb_update_mng_vlan(struct igb_adapter *adapter)
  1205. {
  1206. struct e1000_hw *hw = &adapter->hw;
  1207. u16 vid = adapter->hw.mng_cookie.vlan_id;
  1208. u16 old_vid = adapter->mng_vlan_id;
  1209. if (hw->mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
  1210. /* add VID to filter table */
  1211. igb_vfta_set(hw, vid, true);
  1212. adapter->mng_vlan_id = vid;
  1213. } else {
  1214. adapter->mng_vlan_id = IGB_MNG_VLAN_NONE;
  1215. }
  1216. if ((old_vid != (u16)IGB_MNG_VLAN_NONE) &&
  1217. (vid != old_vid) &&
  1218. !test_bit(old_vid, adapter->active_vlans)) {
  1219. /* remove VID from filter table */
  1220. igb_vfta_set(hw, old_vid, false);
  1221. }
  1222. }
  1223. /**
  1224. * igb_release_hw_control - release control of the h/w to f/w
  1225. * @adapter: address of board private structure
  1226. *
  1227. * igb_release_hw_control resets CTRL_EXT:DRV_LOAD bit.
  1228. * For ASF and Pass Through versions of f/w this means that the
  1229. * driver is no longer loaded.
  1230. *
  1231. **/
  1232. static void igb_release_hw_control(struct igb_adapter *adapter)
  1233. {
  1234. struct e1000_hw *hw = &adapter->hw;
  1235. u32 ctrl_ext;
  1236. /* Let firmware take over control of h/w */
  1237. ctrl_ext = rd32(E1000_CTRL_EXT);
  1238. wr32(E1000_CTRL_EXT,
  1239. ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
  1240. }
  1241. /**
  1242. * igb_get_hw_control - get control of the h/w from f/w
  1243. * @adapter: address of board private structure
  1244. *
  1245. * igb_get_hw_control sets CTRL_EXT:DRV_LOAD bit.
  1246. * For ASF and Pass Through versions of f/w this means that
  1247. * the driver is loaded.
  1248. *
  1249. **/
  1250. static void igb_get_hw_control(struct igb_adapter *adapter)
  1251. {
  1252. struct e1000_hw *hw = &adapter->hw;
  1253. u32 ctrl_ext;
  1254. /* Let firmware know the driver has taken over */
  1255. ctrl_ext = rd32(E1000_CTRL_EXT);
  1256. wr32(E1000_CTRL_EXT,
  1257. ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
  1258. }
  1259. /**
  1260. * igb_configure - configure the hardware for RX and TX
  1261. * @adapter: private board structure
  1262. **/
  1263. static void igb_configure(struct igb_adapter *adapter)
  1264. {
  1265. struct net_device *netdev = adapter->netdev;
  1266. int i;
  1267. igb_get_hw_control(adapter);
  1268. igb_set_rx_mode(netdev);
  1269. igb_restore_vlan(adapter);
  1270. igb_setup_tctl(adapter);
  1271. igb_setup_mrqc(adapter);
  1272. igb_setup_rctl(adapter);
  1273. igb_configure_tx(adapter);
  1274. igb_configure_rx(adapter);
  1275. igb_rx_fifo_flush_82575(&adapter->hw);
  1276. /* call igb_desc_unused which always leaves
  1277. * at least 1 descriptor unused to make sure
  1278. * next_to_use != next_to_clean */
  1279. for (i = 0; i < adapter->num_rx_queues; i++) {
  1280. struct igb_ring *ring = adapter->rx_ring[i];
  1281. igb_alloc_rx_buffers_adv(ring, igb_desc_unused(ring));
  1282. }
  1283. }
  1284. /**
  1285. * igb_power_up_link - Power up the phy/serdes link
  1286. * @adapter: address of board private structure
  1287. **/
  1288. void igb_power_up_link(struct igb_adapter *adapter)
  1289. {
  1290. if (adapter->hw.phy.media_type == e1000_media_type_copper)
  1291. igb_power_up_phy_copper(&adapter->hw);
  1292. else
  1293. igb_power_up_serdes_link_82575(&adapter->hw);
  1294. }
  1295. /**
  1296. * igb_power_down_link - Power down the phy/serdes link
  1297. * @adapter: address of board private structure
  1298. */
  1299. static void igb_power_down_link(struct igb_adapter *adapter)
  1300. {
  1301. if (adapter->hw.phy.media_type == e1000_media_type_copper)
  1302. igb_power_down_phy_copper_82575(&adapter->hw);
  1303. else
  1304. igb_shutdown_serdes_link_82575(&adapter->hw);
  1305. }
  1306. /**
  1307. * igb_up - Open the interface and prepare it to handle traffic
  1308. * @adapter: board private structure
  1309. **/
  1310. int igb_up(struct igb_adapter *adapter)
  1311. {
  1312. struct e1000_hw *hw = &adapter->hw;
  1313. int i;
  1314. /* hardware has been reset, we need to reload some things */
  1315. igb_configure(adapter);
  1316. clear_bit(__IGB_DOWN, &adapter->state);
  1317. for (i = 0; i < adapter->num_q_vectors; i++) {
  1318. struct igb_q_vector *q_vector = adapter->q_vector[i];
  1319. napi_enable(&q_vector->napi);
  1320. }
  1321. if (adapter->msix_entries)
  1322. igb_configure_msix(adapter);
  1323. else
  1324. igb_assign_vector(adapter->q_vector[0], 0);
  1325. /* Clear any pending interrupts. */
  1326. rd32(E1000_ICR);
  1327. igb_irq_enable(adapter);
  1328. /* notify VFs that reset has been completed */
  1329. if (adapter->vfs_allocated_count) {
  1330. u32 reg_data = rd32(E1000_CTRL_EXT);
  1331. reg_data |= E1000_CTRL_EXT_PFRSTD;
  1332. wr32(E1000_CTRL_EXT, reg_data);
  1333. }
  1334. netif_tx_start_all_queues(adapter->netdev);
  1335. /* start the watchdog. */
  1336. hw->mac.get_link_status = 1;
  1337. schedule_work(&adapter->watchdog_task);
  1338. return 0;
  1339. }
  1340. void igb_down(struct igb_adapter *adapter)
  1341. {
  1342. struct net_device *netdev = adapter->netdev;
  1343. struct e1000_hw *hw = &adapter->hw;
  1344. u32 tctl, rctl;
  1345. int i;
  1346. /* signal that we're down so the interrupt handler does not
  1347. * reschedule our watchdog timer */
  1348. set_bit(__IGB_DOWN, &adapter->state);
  1349. /* disable receives in the hardware */
  1350. rctl = rd32(E1000_RCTL);
  1351. wr32(E1000_RCTL, rctl & ~E1000_RCTL_EN);
  1352. /* flush and sleep below */
  1353. netif_tx_stop_all_queues(netdev);
  1354. /* disable transmits in the hardware */
  1355. tctl = rd32(E1000_TCTL);
  1356. tctl &= ~E1000_TCTL_EN;
  1357. wr32(E1000_TCTL, tctl);
  1358. /* flush both disables and wait for them to finish */
  1359. wrfl();
  1360. msleep(10);
  1361. for (i = 0; i < adapter->num_q_vectors; i++) {
  1362. struct igb_q_vector *q_vector = adapter->q_vector[i];
  1363. napi_disable(&q_vector->napi);
  1364. }
  1365. igb_irq_disable(adapter);
  1366. del_timer_sync(&adapter->watchdog_timer);
  1367. del_timer_sync(&adapter->phy_info_timer);
  1368. netif_carrier_off(netdev);
  1369. /* record the stats before reset*/
  1370. spin_lock(&adapter->stats64_lock);
  1371. igb_update_stats(adapter, &adapter->stats64);
  1372. spin_unlock(&adapter->stats64_lock);
  1373. adapter->link_speed = 0;
  1374. adapter->link_duplex = 0;
  1375. if (!pci_channel_offline(adapter->pdev))
  1376. igb_reset(adapter);
  1377. igb_clean_all_tx_rings(adapter);
  1378. igb_clean_all_rx_rings(adapter);
  1379. #ifdef CONFIG_IGB_DCA
  1380. /* since we reset the hardware DCA settings were cleared */
  1381. igb_setup_dca(adapter);
  1382. #endif
  1383. }
  1384. void igb_reinit_locked(struct igb_adapter *adapter)
  1385. {
  1386. WARN_ON(in_interrupt());
  1387. while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
  1388. msleep(1);
  1389. igb_down(adapter);
  1390. igb_up(adapter);
  1391. clear_bit(__IGB_RESETTING, &adapter->state);
  1392. }
  1393. void igb_reset(struct igb_adapter *adapter)
  1394. {
  1395. struct pci_dev *pdev = adapter->pdev;
  1396. struct e1000_hw *hw = &adapter->hw;
  1397. struct e1000_mac_info *mac = &hw->mac;
  1398. struct e1000_fc_info *fc = &hw->fc;
  1399. u32 pba = 0, tx_space, min_tx_space, min_rx_space;
  1400. u16 hwm;
  1401. /* Repartition Pba for greater than 9k mtu
  1402. * To take effect CTRL.RST is required.
  1403. */
  1404. switch (mac->type) {
  1405. case e1000_i350:
  1406. case e1000_82580:
  1407. pba = rd32(E1000_RXPBS);
  1408. pba = igb_rxpbs_adjust_82580(pba);
  1409. break;
  1410. case e1000_82576:
  1411. pba = rd32(E1000_RXPBS);
  1412. pba &= E1000_RXPBS_SIZE_MASK_82576;
  1413. break;
  1414. case e1000_82575:
  1415. default:
  1416. pba = E1000_PBA_34K;
  1417. break;
  1418. }
  1419. if ((adapter->max_frame_size > ETH_FRAME_LEN + ETH_FCS_LEN) &&
  1420. (mac->type < e1000_82576)) {
  1421. /* adjust PBA for jumbo frames */
  1422. wr32(E1000_PBA, pba);
  1423. /* To maintain wire speed transmits, the Tx FIFO should be
  1424. * large enough to accommodate two full transmit packets,
  1425. * rounded up to the next 1KB and expressed in KB. Likewise,
  1426. * the Rx FIFO should be large enough to accommodate at least
  1427. * one full receive packet and is similarly rounded up and
  1428. * expressed in KB. */
  1429. pba = rd32(E1000_PBA);
  1430. /* upper 16 bits has Tx packet buffer allocation size in KB */
  1431. tx_space = pba >> 16;
  1432. /* lower 16 bits has Rx packet buffer allocation size in KB */
  1433. pba &= 0xffff;
  1434. /* the tx fifo also stores 16 bytes of information about the tx
  1435. * but don't include ethernet FCS because hardware appends it */
  1436. min_tx_space = (adapter->max_frame_size +
  1437. sizeof(union e1000_adv_tx_desc) -
  1438. ETH_FCS_LEN) * 2;
  1439. min_tx_space = ALIGN(min_tx_space, 1024);
  1440. min_tx_space >>= 10;
  1441. /* software strips receive CRC, so leave room for it */
  1442. min_rx_space = adapter->max_frame_size;
  1443. min_rx_space = ALIGN(min_rx_space, 1024);
  1444. min_rx_space >>= 10;
  1445. /* If current Tx allocation is less than the min Tx FIFO size,
  1446. * and the min Tx FIFO size is less than the current Rx FIFO
  1447. * allocation, take space away from current Rx allocation */
  1448. if (tx_space < min_tx_space &&
  1449. ((min_tx_space - tx_space) < pba)) {
  1450. pba = pba - (min_tx_space - tx_space);
  1451. /* if short on rx space, rx wins and must trump tx
  1452. * adjustment */
  1453. if (pba < min_rx_space)
  1454. pba = min_rx_space;
  1455. }
  1456. wr32(E1000_PBA, pba);
  1457. }
  1458. /* flow control settings */
  1459. /* The high water mark must be low enough to fit one full frame
  1460. * (or the size used for early receive) above it in the Rx FIFO.
  1461. * Set it to the lower of:
  1462. * - 90% of the Rx FIFO size, or
  1463. * - the full Rx FIFO size minus one full frame */
  1464. hwm = min(((pba << 10) * 9 / 10),
  1465. ((pba << 10) - 2 * adapter->max_frame_size));
  1466. fc->high_water = hwm & 0xFFF0; /* 16-byte granularity */
  1467. fc->low_water = fc->high_water - 16;
  1468. fc->pause_time = 0xFFFF;
  1469. fc->send_xon = 1;
  1470. fc->current_mode = fc->requested_mode;
  1471. /* disable receive for all VFs and wait one second */
  1472. if (adapter->vfs_allocated_count) {
  1473. int i;
  1474. for (i = 0 ; i < adapter->vfs_allocated_count; i++)
  1475. adapter->vf_data[i].flags &= IGB_VF_FLAG_PF_SET_MAC;
  1476. /* ping all the active vfs to let them know we are going down */
  1477. igb_ping_all_vfs(adapter);
  1478. /* disable transmits and receives */
  1479. wr32(E1000_VFRE, 0);
  1480. wr32(E1000_VFTE, 0);
  1481. }
  1482. /* Allow time for pending master requests to run */
  1483. hw->mac.ops.reset_hw(hw);
  1484. wr32(E1000_WUC, 0);
  1485. if (hw->mac.ops.init_hw(hw))
  1486. dev_err(&pdev->dev, "Hardware Error\n");
  1487. if (hw->mac.type > e1000_82580) {
  1488. if (adapter->flags & IGB_FLAG_DMAC) {
  1489. u32 reg;
  1490. /*
  1491. * DMA Coalescing high water mark needs to be higher
  1492. * than * the * Rx threshold. The Rx threshold is
  1493. * currently * pba - 6, so we * should use a high water
  1494. * mark of pba * - 4. */
  1495. hwm = (pba - 4) << 10;
  1496. reg = (((pba-6) << E1000_DMACR_DMACTHR_SHIFT)
  1497. & E1000_DMACR_DMACTHR_MASK);
  1498. /* transition to L0x or L1 if available..*/
  1499. reg |= (E1000_DMACR_DMAC_EN | E1000_DMACR_DMAC_LX_MASK);
  1500. /* watchdog timer= +-1000 usec in 32usec intervals */
  1501. reg |= (1000 >> 5);
  1502. wr32(E1000_DMACR, reg);
  1503. /* no lower threshold to disable coalescing(smart fifb)
  1504. * -UTRESH=0*/
  1505. wr32(E1000_DMCRTRH, 0);
  1506. /* set hwm to PBA - 2 * max frame size */
  1507. wr32(E1000_FCRTC, hwm);
  1508. /*
  1509. * This sets the time to wait before requesting tran-
  1510. * sition to * low power state to number of usecs needed
  1511. * to receive 1 512 * byte frame at gigabit line rate
  1512. */
  1513. reg = rd32(E1000_DMCTLX);
  1514. reg |= IGB_DMCTLX_DCFLUSH_DIS;
  1515. /* Delay 255 usec before entering Lx state. */
  1516. reg |= 0xFF;
  1517. wr32(E1000_DMCTLX, reg);
  1518. /* free space in Tx packet buffer to wake from DMAC */
  1519. wr32(E1000_DMCTXTH,
  1520. (IGB_MIN_TXPBSIZE -
  1521. (IGB_TX_BUF_4096 + adapter->max_frame_size))
  1522. >> 6);
  1523. /* make low power state decision controlled by DMAC */
  1524. reg = rd32(E1000_PCIEMISC);
  1525. reg |= E1000_PCIEMISC_LX_DECISION;
  1526. wr32(E1000_PCIEMISC, reg);
  1527. } /* end if IGB_FLAG_DMAC set */
  1528. }
  1529. if (hw->mac.type == e1000_82580) {
  1530. u32 reg = rd32(E1000_PCIEMISC);
  1531. wr32(E1000_PCIEMISC,
  1532. reg & ~E1000_PCIEMISC_LX_DECISION);
  1533. }
  1534. if (!netif_running(adapter->netdev))
  1535. igb_power_down_link(adapter);
  1536. igb_update_mng_vlan(adapter);
  1537. /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
  1538. wr32(E1000_VET, ETHERNET_IEEE_VLAN_TYPE);
  1539. igb_get_phy_info(hw);
  1540. }
  1541. static u32 igb_fix_features(struct net_device *netdev, u32 features)
  1542. {
  1543. /*
  1544. * Since there is no support for separate rx/tx vlan accel
  1545. * enable/disable make sure tx flag is always in same state as rx.
  1546. */
  1547. if (features & NETIF_F_HW_VLAN_RX)
  1548. features |= NETIF_F_HW_VLAN_TX;
  1549. else
  1550. features &= ~NETIF_F_HW_VLAN_TX;
  1551. return features;
  1552. }
  1553. static int igb_set_features(struct net_device *netdev, u32 features)
  1554. {
  1555. struct igb_adapter *adapter = netdev_priv(netdev);
  1556. int i;
  1557. u32 changed = netdev->features ^ features;
  1558. for (i = 0; i < adapter->num_rx_queues; i++) {
  1559. if (features & NETIF_F_RXCSUM)
  1560. adapter->rx_ring[i]->flags |= IGB_RING_FLAG_RX_CSUM;
  1561. else
  1562. adapter->rx_ring[i]->flags &= ~IGB_RING_FLAG_RX_CSUM;
  1563. }
  1564. if (changed & NETIF_F_HW_VLAN_RX)
  1565. igb_vlan_mode(netdev, features);
  1566. return 0;
  1567. }
  1568. static const struct net_device_ops igb_netdev_ops = {
  1569. .ndo_open = igb_open,
  1570. .ndo_stop = igb_close,
  1571. .ndo_start_xmit = igb_xmit_frame_adv,
  1572. .ndo_get_stats64 = igb_get_stats64,
  1573. .ndo_set_rx_mode = igb_set_rx_mode,
  1574. .ndo_set_multicast_list = igb_set_rx_mode,
  1575. .ndo_set_mac_address = igb_set_mac,
  1576. .ndo_change_mtu = igb_change_mtu,
  1577. .ndo_do_ioctl = igb_ioctl,
  1578. .ndo_tx_timeout = igb_tx_timeout,
  1579. .ndo_validate_addr = eth_validate_addr,
  1580. .ndo_vlan_rx_add_vid = igb_vlan_rx_add_vid,
  1581. .ndo_vlan_rx_kill_vid = igb_vlan_rx_kill_vid,
  1582. .ndo_set_vf_mac = igb_ndo_set_vf_mac,
  1583. .ndo_set_vf_vlan = igb_ndo_set_vf_vlan,
  1584. .ndo_set_vf_tx_rate = igb_ndo_set_vf_bw,
  1585. .ndo_get_vf_config = igb_ndo_get_vf_config,
  1586. #ifdef CONFIG_NET_POLL_CONTROLLER
  1587. .ndo_poll_controller = igb_netpoll,
  1588. #endif
  1589. .ndo_fix_features = igb_fix_features,
  1590. .ndo_set_features = igb_set_features,
  1591. };
  1592. /**
  1593. * igb_probe - Device Initialization Routine
  1594. * @pdev: PCI device information struct
  1595. * @ent: entry in igb_pci_tbl
  1596. *
  1597. * Returns 0 on success, negative on failure
  1598. *
  1599. * igb_probe initializes an adapter identified by a pci_dev structure.
  1600. * The OS initialization, configuring of the adapter private structure,
  1601. * and a hardware reset occur.
  1602. **/
  1603. static int __devinit igb_probe(struct pci_dev *pdev,
  1604. const struct pci_device_id *ent)
  1605. {
  1606. struct net_device *netdev;
  1607. struct igb_adapter *adapter;
  1608. struct e1000_hw *hw;
  1609. u16 eeprom_data = 0;
  1610. s32 ret_val;
  1611. static int global_quad_port_a; /* global quad port a indication */
  1612. const struct e1000_info *ei = igb_info_tbl[ent->driver_data];
  1613. unsigned long mmio_start, mmio_len;
  1614. int err, pci_using_dac;
  1615. u16 eeprom_apme_mask = IGB_EEPROM_APME;
  1616. u8 part_str[E1000_PBANUM_LENGTH];
  1617. /* Catch broken hardware that put the wrong VF device ID in
  1618. * the PCIe SR-IOV capability.
  1619. */
  1620. if (pdev->is_virtfn) {
  1621. WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
  1622. pci_name(pdev), pdev->vendor, pdev->device);
  1623. return -EINVAL;
  1624. }
  1625. err = pci_enable_device_mem(pdev);
  1626. if (err)
  1627. return err;
  1628. pci_using_dac = 0;
  1629. err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
  1630. if (!err) {
  1631. err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
  1632. if (!err)
  1633. pci_using_dac = 1;
  1634. } else {
  1635. err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
  1636. if (err) {
  1637. err = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  1638. if (err) {
  1639. dev_err(&pdev->dev, "No usable DMA "
  1640. "configuration, aborting\n");
  1641. goto err_dma;
  1642. }
  1643. }
  1644. }
  1645. err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
  1646. IORESOURCE_MEM),
  1647. igb_driver_name);
  1648. if (err)
  1649. goto err_pci_reg;
  1650. pci_enable_pcie_error_reporting(pdev);
  1651. pci_set_master(pdev);
  1652. pci_save_state(pdev);
  1653. err = -ENOMEM;
  1654. netdev = alloc_etherdev_mq(sizeof(struct igb_adapter),
  1655. IGB_ABS_MAX_TX_QUEUES);
  1656. if (!netdev)
  1657. goto err_alloc_etherdev;
  1658. SET_NETDEV_DEV(netdev, &pdev->dev);
  1659. pci_set_drvdata(pdev, netdev);
  1660. adapter = netdev_priv(netdev);
  1661. adapter->netdev = netdev;
  1662. adapter->pdev = pdev;
  1663. hw = &adapter->hw;
  1664. hw->back = adapter;
  1665. adapter->msg_enable = NETIF_MSG_DRV | NETIF_MSG_PROBE;
  1666. mmio_start = pci_resource_start(pdev, 0);
  1667. mmio_len = pci_resource_len(pdev, 0);
  1668. err = -EIO;
  1669. hw->hw_addr = ioremap(mmio_start, mmio_len);
  1670. if (!hw->hw_addr)
  1671. goto err_ioremap;
  1672. netdev->netdev_ops = &igb_netdev_ops;
  1673. igb_set_ethtool_ops(netdev);
  1674. netdev->watchdog_timeo = 5 * HZ;
  1675. strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
  1676. netdev->mem_start = mmio_start;
  1677. netdev->mem_end = mmio_start + mmio_len;
  1678. /* PCI config space info */
  1679. hw->vendor_id = pdev->vendor;
  1680. hw->device_id = pdev->device;
  1681. hw->revision_id = pdev->revision;
  1682. hw->subsystem_vendor_id = pdev->subsystem_vendor;
  1683. hw->subsystem_device_id = pdev->subsystem_device;
  1684. /* Copy the default MAC, PHY and NVM function pointers */
  1685. memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
  1686. memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
  1687. memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
  1688. /* Initialize skew-specific constants */
  1689. err = ei->get_invariants(hw);
  1690. if (err)
  1691. goto err_sw_init;
  1692. /* setup the private structure */
  1693. err = igb_sw_init(adapter);
  1694. if (err)
  1695. goto err_sw_init;
  1696. igb_get_bus_info_pcie(hw);
  1697. hw->phy.autoneg_wait_to_complete = false;
  1698. /* Copper options */
  1699. if (hw->phy.media_type == e1000_media_type_copper) {
  1700. hw->phy.mdix = AUTO_ALL_MODES;
  1701. hw->phy.disable_polarity_correction = false;
  1702. hw->phy.ms_type = e1000_ms_hw_default;
  1703. }
  1704. if (igb_check_reset_block(hw))
  1705. dev_info(&pdev->dev,
  1706. "PHY reset is blocked due to SOL/IDER session.\n");
  1707. netdev->hw_features = NETIF_F_SG |
  1708. NETIF_F_IP_CSUM |
  1709. NETIF_F_IPV6_CSUM |
  1710. NETIF_F_TSO |
  1711. NETIF_F_TSO6 |
  1712. NETIF_F_RXCSUM |
  1713. NETIF_F_HW_VLAN_RX;
  1714. netdev->features = netdev->hw_features |
  1715. NETIF_F_HW_VLAN_TX |
  1716. NETIF_F_HW_VLAN_FILTER;
  1717. netdev->vlan_features |= NETIF_F_TSO;
  1718. netdev->vlan_features |= NETIF_F_TSO6;
  1719. netdev->vlan_features |= NETIF_F_IP_CSUM;
  1720. netdev->vlan_features |= NETIF_F_IPV6_CSUM;
  1721. netdev->vlan_features |= NETIF_F_SG;
  1722. if (pci_using_dac) {
  1723. netdev->features |= NETIF_F_HIGHDMA;
  1724. netdev->vlan_features |= NETIF_F_HIGHDMA;
  1725. }
  1726. if (hw->mac.type >= e1000_82576) {
  1727. netdev->hw_features |= NETIF_F_SCTP_CSUM;
  1728. netdev->features |= NETIF_F_SCTP_CSUM;
  1729. }
  1730. adapter->en_mng_pt = igb_enable_mng_pass_thru(hw);
  1731. /* before reading the NVM, reset the controller to put the device in a
  1732. * known good starting state */
  1733. hw->mac.ops.reset_hw(hw);
  1734. /* make sure the NVM is good */
  1735. if (hw->nvm.ops.validate(hw) < 0) {
  1736. dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
  1737. err = -EIO;
  1738. goto err_eeprom;
  1739. }
  1740. /* copy the MAC address out of the NVM */
  1741. if (hw->mac.ops.read_mac_addr(hw))
  1742. dev_err(&pdev->dev, "NVM Read Error\n");
  1743. memcpy(netdev->dev_addr, hw->mac.addr, netdev->addr_len);
  1744. memcpy(netdev->perm_addr, hw->mac.addr, netdev->addr_len);
  1745. if (!is_valid_ether_addr(netdev->perm_addr)) {
  1746. dev_err(&pdev->dev, "Invalid MAC Address\n");
  1747. err = -EIO;
  1748. goto err_eeprom;
  1749. }
  1750. setup_timer(&adapter->watchdog_timer, igb_watchdog,
  1751. (unsigned long) adapter);
  1752. setup_timer(&adapter->phy_info_timer, igb_update_phy_info,
  1753. (unsigned long) adapter);
  1754. INIT_WORK(&adapter->reset_task, igb_reset_task);
  1755. INIT_WORK(&adapter->watchdog_task, igb_watchdog_task);
  1756. /* Initialize link properties that are user-changeable */
  1757. adapter->fc_autoneg = true;
  1758. hw->mac.autoneg = true;
  1759. hw->phy.autoneg_advertised = 0x2f;
  1760. hw->fc.requested_mode = e1000_fc_default;
  1761. hw->fc.current_mode = e1000_fc_default;
  1762. igb_validate_mdi_setting(hw);
  1763. /* Initial Wake on LAN setting If APM wake is enabled in the EEPROM,
  1764. * enable the ACPI Magic Packet filter
  1765. */
  1766. if (hw->bus.func == 0)
  1767. hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A, 1, &eeprom_data);
  1768. else if (hw->mac.type >= e1000_82580)
  1769. hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_A +
  1770. NVM_82580_LAN_FUNC_OFFSET(hw->bus.func), 1,
  1771. &eeprom_data);
  1772. else if (hw->bus.func == 1)
  1773. hw->nvm.ops.read(hw, NVM_INIT_CONTROL3_PORT_B, 1, &eeprom_data);
  1774. if (eeprom_data & eeprom_apme_mask)
  1775. adapter->eeprom_wol |= E1000_WUFC_MAG;
  1776. /* now that we have the eeprom settings, apply the special cases where
  1777. * the eeprom may be wrong or the board simply won't support wake on
  1778. * lan on a particular port */
  1779. switch (pdev->device) {
  1780. case E1000_DEV_ID_82575GB_QUAD_COPPER:
  1781. adapter->eeprom_wol = 0;
  1782. break;
  1783. case E1000_DEV_ID_82575EB_FIBER_SERDES:
  1784. case E1000_DEV_ID_82576_FIBER:
  1785. case E1000_DEV_ID_82576_SERDES:
  1786. /* Wake events only supported on port A for dual fiber
  1787. * regardless of eeprom setting */
  1788. if (rd32(E1000_STATUS) & E1000_STATUS_FUNC_1)
  1789. adapter->eeprom_wol = 0;
  1790. break;
  1791. case E1000_DEV_ID_82576_QUAD_COPPER:
  1792. case E1000_DEV_ID_82576_QUAD_COPPER_ET2:
  1793. /* if quad port adapter, disable WoL on all but port A */
  1794. if (global_quad_port_a != 0)
  1795. adapter->eeprom_wol = 0;
  1796. else
  1797. adapter->flags |= IGB_FLAG_QUAD_PORT_A;
  1798. /* Reset for multiple quad port adapters */
  1799. if (++global_quad_port_a == 4)
  1800. global_quad_port_a = 0;
  1801. break;
  1802. }
  1803. /* initialize the wol settings based on the eeprom settings */
  1804. adapter->wol = adapter->eeprom_wol;
  1805. device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
  1806. /* reset the hardware with the new settings */
  1807. igb_reset(adapter);
  1808. /* let the f/w know that the h/w is now under the control of the
  1809. * driver. */
  1810. igb_get_hw_control(adapter);
  1811. strcpy(netdev->name, "eth%d");
  1812. err = register_netdev(netdev);
  1813. if (err)
  1814. goto err_register;
  1815. igb_vlan_mode(netdev, netdev->features);
  1816. /* carrier off reporting is important to ethtool even BEFORE open */
  1817. netif_carrier_off(netdev);
  1818. #ifdef CONFIG_IGB_DCA
  1819. if (dca_add_requester(&pdev->dev) == 0) {
  1820. adapter->flags |= IGB_FLAG_DCA_ENABLED;
  1821. dev_info(&pdev->dev, "DCA enabled\n");
  1822. igb_setup_dca(adapter);
  1823. }
  1824. #endif
  1825. /* do hw tstamp init after resetting */
  1826. igb_init_hw_timer(adapter);
  1827. dev_info(&pdev->dev, "Intel(R) Gigabit Ethernet Network Connection\n");
  1828. /* print bus type/speed/width info */
  1829. dev_info(&pdev->dev, "%s: (PCIe:%s:%s) %pM\n",
  1830. netdev->name,
  1831. ((hw->bus.speed == e1000_bus_speed_2500) ? "2.5Gb/s" :
  1832. (hw->bus.speed == e1000_bus_speed_5000) ? "5.0Gb/s" :
  1833. "unknown"),
  1834. ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
  1835. (hw->bus.width == e1000_bus_width_pcie_x2) ? "Width x2" :
  1836. (hw->bus.width == e1000_bus_width_pcie_x1) ? "Width x1" :
  1837. "unknown"),
  1838. netdev->dev_addr);
  1839. ret_val = igb_read_part_string(hw, part_str, E1000_PBANUM_LENGTH);
  1840. if (ret_val)
  1841. strcpy(part_str, "Unknown");
  1842. dev_info(&pdev->dev, "%s: PBA No: %s\n", netdev->name, part_str);
  1843. dev_info(&pdev->dev,
  1844. "Using %s interrupts. %d rx queue(s), %d tx queue(s)\n",
  1845. adapter->msix_entries ? "MSI-X" :
  1846. (adapter->flags & IGB_FLAG_HAS_MSI) ? "MSI" : "legacy",
  1847. adapter->num_rx_queues, adapter->num_tx_queues);
  1848. switch (hw->mac.type) {
  1849. case e1000_i350:
  1850. igb_set_eee_i350(hw);
  1851. break;
  1852. default:
  1853. break;
  1854. }
  1855. return 0;
  1856. err_register:
  1857. igb_release_hw_control(adapter);
  1858. err_eeprom:
  1859. if (!igb_check_reset_block(hw))
  1860. igb_reset_phy(hw);
  1861. if (hw->flash_address)
  1862. iounmap(hw->flash_address);
  1863. err_sw_init:
  1864. igb_clear_interrupt_scheme(adapter);
  1865. iounmap(hw->hw_addr);
  1866. err_ioremap:
  1867. free_netdev(netdev);
  1868. err_alloc_etherdev:
  1869. pci_release_selected_regions(pdev,
  1870. pci_select_bars(pdev, IORESOURCE_MEM));
  1871. err_pci_reg:
  1872. err_dma:
  1873. pci_disable_device(pdev);
  1874. return err;
  1875. }
  1876. /**
  1877. * igb_remove - Device Removal Routine
  1878. * @pdev: PCI device information struct
  1879. *
  1880. * igb_remove is called by the PCI subsystem to alert the driver
  1881. * that it should release a PCI device. The could be caused by a
  1882. * Hot-Plug event, or because the driver is going to be removed from
  1883. * memory.
  1884. **/
  1885. static void __devexit igb_remove(struct pci_dev *pdev)
  1886. {
  1887. struct net_device *netdev = pci_get_drvdata(pdev);
  1888. struct igb_adapter *adapter = netdev_priv(netdev);
  1889. struct e1000_hw *hw = &adapter->hw;
  1890. /*
  1891. * The watchdog timer may be rescheduled, so explicitly
  1892. * disable watchdog from being rescheduled.
  1893. */
  1894. set_bit(__IGB_DOWN, &adapter->state);
  1895. del_timer_sync(&adapter->watchdog_timer);
  1896. del_timer_sync(&adapter->phy_info_timer);
  1897. cancel_work_sync(&adapter->reset_task);
  1898. cancel_work_sync(&adapter->watchdog_task);
  1899. #ifdef CONFIG_IGB_DCA
  1900. if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
  1901. dev_info(&pdev->dev, "DCA disabled\n");
  1902. dca_remove_requester(&pdev->dev);
  1903. adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
  1904. wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE);
  1905. }
  1906. #endif
  1907. /* Release control of h/w to f/w. If f/w is AMT enabled, this
  1908. * would have already happened in close and is redundant. */
  1909. igb_release_hw_control(adapter);
  1910. unregister_netdev(netdev);
  1911. igb_clear_interrupt_scheme(adapter);
  1912. #ifdef CONFIG_PCI_IOV
  1913. /* reclaim resources allocated to VFs */
  1914. if (adapter->vf_data) {
  1915. /* disable iov and allow time for transactions to clear */
  1916. pci_disable_sriov(pdev);
  1917. msleep(500);
  1918. kfree(adapter->vf_data);
  1919. adapter->vf_data = NULL;
  1920. wr32(E1000_IOVCTL, E1000_IOVCTL_REUSE_VFQ);
  1921. wrfl();
  1922. msleep(100);
  1923. dev_info(&pdev->dev, "IOV Disabled\n");
  1924. }
  1925. #endif
  1926. iounmap(hw->hw_addr);
  1927. if (hw->flash_address)
  1928. iounmap(hw->flash_address);
  1929. pci_release_selected_regions(pdev,
  1930. pci_select_bars(pdev, IORESOURCE_MEM));
  1931. free_netdev(netdev);
  1932. pci_disable_pcie_error_reporting(pdev);
  1933. pci_disable_device(pdev);
  1934. }
  1935. /**
  1936. * igb_probe_vfs - Initialize vf data storage and add VFs to pci config space
  1937. * @adapter: board private structure to initialize
  1938. *
  1939. * This function initializes the vf specific data storage and then attempts to
  1940. * allocate the VFs. The reason for ordering it this way is because it is much
  1941. * mor expensive time wise to disable SR-IOV than it is to allocate and free
  1942. * the memory for the VFs.
  1943. **/
  1944. static void __devinit igb_probe_vfs(struct igb_adapter * adapter)
  1945. {
  1946. #ifdef CONFIG_PCI_IOV
  1947. struct pci_dev *pdev = adapter->pdev;
  1948. if (adapter->vfs_allocated_count) {
  1949. adapter->vf_data = kcalloc(adapter->vfs_allocated_count,
  1950. sizeof(struct vf_data_storage),
  1951. GFP_KERNEL);
  1952. /* if allocation failed then we do not support SR-IOV */
  1953. if (!adapter->vf_data) {
  1954. adapter->vfs_allocated_count = 0;
  1955. dev_err(&pdev->dev, "Unable to allocate memory for VF "
  1956. "Data Storage\n");
  1957. }
  1958. }
  1959. if (pci_enable_sriov(pdev, adapter->vfs_allocated_count)) {
  1960. kfree(adapter->vf_data);
  1961. adapter->vf_data = NULL;
  1962. #endif /* CONFIG_PCI_IOV */
  1963. adapter->vfs_allocated_count = 0;
  1964. #ifdef CONFIG_PCI_IOV
  1965. } else {
  1966. unsigned char mac_addr[ETH_ALEN];
  1967. int i;
  1968. dev_info(&pdev->dev, "%d vfs allocated\n",
  1969. adapter->vfs_allocated_count);
  1970. for (i = 0; i < adapter->vfs_allocated_count; i++) {
  1971. random_ether_addr(mac_addr);
  1972. igb_set_vf_mac(adapter, i, mac_addr);
  1973. }
  1974. /* DMA Coalescing is not supported in IOV mode. */
  1975. if (adapter->flags & IGB_FLAG_DMAC)
  1976. adapter->flags &= ~IGB_FLAG_DMAC;
  1977. }
  1978. #endif /* CONFIG_PCI_IOV */
  1979. }
  1980. /**
  1981. * igb_init_hw_timer - Initialize hardware timer used with IEEE 1588 timestamp
  1982. * @adapter: board private structure to initialize
  1983. *
  1984. * igb_init_hw_timer initializes the function pointer and values for the hw
  1985. * timer found in hardware.
  1986. **/
  1987. static void igb_init_hw_timer(struct igb_adapter *adapter)
  1988. {
  1989. struct e1000_hw *hw = &adapter->hw;
  1990. switch (hw->mac.type) {
  1991. case e1000_i350:
  1992. case e1000_82580:
  1993. memset(&adapter->cycles, 0, sizeof(adapter->cycles));
  1994. adapter->cycles.read = igb_read_clock;
  1995. adapter->cycles.mask = CLOCKSOURCE_MASK(64);
  1996. adapter->cycles.mult = 1;
  1997. /*
  1998. * The 82580 timesync updates the system timer every 8ns by 8ns
  1999. * and the value cannot be shifted. Instead we need to shift
  2000. * the registers to generate a 64bit timer value. As a result
  2001. * SYSTIMR/L/H, TXSTMPL/H, RXSTMPL/H all have to be shifted by
  2002. * 24 in order to generate a larger value for synchronization.
  2003. */
  2004. adapter->cycles.shift = IGB_82580_TSYNC_SHIFT;
  2005. /* disable system timer temporarily by setting bit 31 */
  2006. wr32(E1000_TSAUXC, 0x80000000);
  2007. wrfl();
  2008. /* Set registers so that rollover occurs soon to test this. */
  2009. wr32(E1000_SYSTIMR, 0x00000000);
  2010. wr32(E1000_SYSTIML, 0x80000000);
  2011. wr32(E1000_SYSTIMH, 0x000000FF);
  2012. wrfl();
  2013. /* enable system timer by clearing bit 31 */
  2014. wr32(E1000_TSAUXC, 0x0);
  2015. wrfl();
  2016. timecounter_init(&adapter->clock,
  2017. &adapter->cycles,
  2018. ktime_to_ns(ktime_get_real()));
  2019. /*
  2020. * Synchronize our NIC clock against system wall clock. NIC
  2021. * time stamp reading requires ~3us per sample, each sample
  2022. * was pretty stable even under load => only require 10
  2023. * samples for each offset comparison.
  2024. */
  2025. memset(&adapter->compare, 0, sizeof(adapter->compare));
  2026. adapter->compare.source = &adapter->clock;
  2027. adapter->compare.target = ktime_get_real;
  2028. adapter->compare.num_samples = 10;
  2029. timecompare_update(&adapter->compare, 0);
  2030. break;
  2031. case e1000_82576:
  2032. /*
  2033. * Initialize hardware timer: we keep it running just in case
  2034. * that some program needs it later on.
  2035. */
  2036. memset(&adapter->cycles, 0, sizeof(adapter->cycles));
  2037. adapter->cycles.read = igb_read_clock;
  2038. adapter->cycles.mask = CLOCKSOURCE_MASK(64);
  2039. adapter->cycles.mult = 1;
  2040. /**
  2041. * Scale the NIC clock cycle by a large factor so that
  2042. * relatively small clock corrections can be added or
  2043. * subtracted at each clock tick. The drawbacks of a large
  2044. * factor are a) that the clock register overflows more quickly
  2045. * (not such a big deal) and b) that the increment per tick has
  2046. * to fit into 24 bits. As a result we need to use a shift of
  2047. * 19 so we can fit a value of 16 into the TIMINCA register.
  2048. */
  2049. adapter->cycles.shift = IGB_82576_TSYNC_SHIFT;
  2050. wr32(E1000_TIMINCA,
  2051. (1 << E1000_TIMINCA_16NS_SHIFT) |
  2052. (16 << IGB_82576_TSYNC_SHIFT));
  2053. /* Set registers so that rollover occurs soon to test this. */
  2054. wr32(E1000_SYSTIML, 0x00000000);
  2055. wr32(E1000_SYSTIMH, 0xFF800000);
  2056. wrfl();
  2057. timecounter_init(&adapter->clock,
  2058. &adapter->cycles,
  2059. ktime_to_ns(ktime_get_real()));
  2060. /*
  2061. * Synchronize our NIC clock against system wall clock. NIC
  2062. * time stamp reading requires ~3us per sample, each sample
  2063. * was pretty stable even under load => only require 10
  2064. * samples for each offset comparison.
  2065. */
  2066. memset(&adapter->compare, 0, sizeof(adapter->compare));
  2067. adapter->compare.source = &adapter->clock;
  2068. adapter->compare.target = ktime_get_real;
  2069. adapter->compare.num_samples = 10;
  2070. timecompare_update(&adapter->compare, 0);
  2071. break;
  2072. case e1000_82575:
  2073. /* 82575 does not support timesync */
  2074. default:
  2075. break;
  2076. }
  2077. }
  2078. /**
  2079. * igb_sw_init - Initialize general software structures (struct igb_adapter)
  2080. * @adapter: board private structure to initialize
  2081. *
  2082. * igb_sw_init initializes the Adapter private data structure.
  2083. * Fields are initialized based on PCI device information and
  2084. * OS network device settings (MTU size).
  2085. **/
  2086. static int __devinit igb_sw_init(struct igb_adapter *adapter)
  2087. {
  2088. struct e1000_hw *hw = &adapter->hw;
  2089. struct net_device *netdev = adapter->netdev;
  2090. struct pci_dev *pdev = adapter->pdev;
  2091. pci_read_config_word(pdev, PCI_COMMAND, &hw->bus.pci_cmd_word);
  2092. adapter->tx_ring_count = IGB_DEFAULT_TXD;
  2093. adapter->rx_ring_count = IGB_DEFAULT_RXD;
  2094. adapter->rx_itr_setting = IGB_DEFAULT_ITR;
  2095. adapter->tx_itr_setting = IGB_DEFAULT_ITR;
  2096. adapter->max_frame_size = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
  2097. adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
  2098. spin_lock_init(&adapter->stats64_lock);
  2099. #ifdef CONFIG_PCI_IOV
  2100. switch (hw->mac.type) {
  2101. case e1000_82576:
  2102. case e1000_i350:
  2103. if (max_vfs > 7) {
  2104. dev_warn(&pdev->dev,
  2105. "Maximum of 7 VFs per PF, using max\n");
  2106. adapter->vfs_allocated_count = 7;
  2107. } else
  2108. adapter->vfs_allocated_count = max_vfs;
  2109. break;
  2110. default:
  2111. break;
  2112. }
  2113. #endif /* CONFIG_PCI_IOV */
  2114. adapter->rss_queues = min_t(u32, IGB_MAX_RX_QUEUES, num_online_cpus());
  2115. /* i350 cannot do RSS and SR-IOV at the same time */
  2116. if (hw->mac.type == e1000_i350 && adapter->vfs_allocated_count)
  2117. adapter->rss_queues = 1;
  2118. /*
  2119. * if rss_queues > 4 or vfs are going to be allocated with rss_queues
  2120. * then we should combine the queues into a queue pair in order to
  2121. * conserve interrupts due to limited supply
  2122. */
  2123. if ((adapter->rss_queues > 4) ||
  2124. ((adapter->rss_queues > 1) && (adapter->vfs_allocated_count > 6)))
  2125. adapter->flags |= IGB_FLAG_QUEUE_PAIRS;
  2126. /* This call may decrease the number of queues */
  2127. if (igb_init_interrupt_scheme(adapter)) {
  2128. dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
  2129. return -ENOMEM;
  2130. }
  2131. igb_probe_vfs(adapter);
  2132. /* Explicitly disable IRQ since the NIC can be in any state. */
  2133. igb_irq_disable(adapter);
  2134. if (hw->mac.type == e1000_i350)
  2135. adapter->flags &= ~IGB_FLAG_DMAC;
  2136. set_bit(__IGB_DOWN, &adapter->state);
  2137. return 0;
  2138. }
  2139. /**
  2140. * igb_open - Called when a network interface is made active
  2141. * @netdev: network interface device structure
  2142. *
  2143. * Returns 0 on success, negative value on failure
  2144. *
  2145. * The open entry point is called when a network interface is made
  2146. * active by the system (IFF_UP). At this point all resources needed
  2147. * for transmit and receive operations are allocated, the interrupt
  2148. * handler is registered with the OS, the watchdog timer is started,
  2149. * and the stack is notified that the interface is ready.
  2150. **/
  2151. static int igb_open(struct net_device *netdev)
  2152. {
  2153. struct igb_adapter *adapter = netdev_priv(netdev);
  2154. struct e1000_hw *hw = &adapter->hw;
  2155. int err;
  2156. int i;
  2157. /* disallow open during test */
  2158. if (test_bit(__IGB_TESTING, &adapter->state))
  2159. return -EBUSY;
  2160. netif_carrier_off(netdev);
  2161. /* allocate transmit descriptors */
  2162. err = igb_setup_all_tx_resources(adapter);
  2163. if (err)
  2164. goto err_setup_tx;
  2165. /* allocate receive descriptors */
  2166. err = igb_setup_all_rx_resources(adapter);
  2167. if (err)
  2168. goto err_setup_rx;
  2169. igb_power_up_link(adapter);
  2170. /* before we allocate an interrupt, we must be ready to handle it.
  2171. * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
  2172. * as soon as we call pci_request_irq, so we have to setup our
  2173. * clean_rx handler before we do so. */
  2174. igb_configure(adapter);
  2175. err = igb_request_irq(adapter);
  2176. if (err)
  2177. goto err_req_irq;
  2178. /* From here on the code is the same as igb_up() */
  2179. clear_bit(__IGB_DOWN, &adapter->state);
  2180. for (i = 0; i < adapter->num_q_vectors; i++) {
  2181. struct igb_q_vector *q_vector = adapter->q_vector[i];
  2182. napi_enable(&q_vector->napi);
  2183. }
  2184. /* Clear any pending interrupts. */
  2185. rd32(E1000_ICR);
  2186. igb_irq_enable(adapter);
  2187. /* notify VFs that reset has been completed */
  2188. if (adapter->vfs_allocated_count) {
  2189. u32 reg_data = rd32(E1000_CTRL_EXT);
  2190. reg_data |= E1000_CTRL_EXT_PFRSTD;
  2191. wr32(E1000_CTRL_EXT, reg_data);
  2192. }
  2193. netif_tx_start_all_queues(netdev);
  2194. /* start the watchdog. */
  2195. hw->mac.get_link_status = 1;
  2196. schedule_work(&adapter->watchdog_task);
  2197. return 0;
  2198. err_req_irq:
  2199. igb_release_hw_control(adapter);
  2200. igb_power_down_link(adapter);
  2201. igb_free_all_rx_resources(adapter);
  2202. err_setup_rx:
  2203. igb_free_all_tx_resources(adapter);
  2204. err_setup_tx:
  2205. igb_reset(adapter);
  2206. return err;
  2207. }
  2208. /**
  2209. * igb_close - Disables a network interface
  2210. * @netdev: network interface device structure
  2211. *
  2212. * Returns 0, this is not allowed to fail
  2213. *
  2214. * The close entry point is called when an interface is de-activated
  2215. * by the OS. The hardware is still under the driver's control, but
  2216. * needs to be disabled. A global MAC reset is issued to stop the
  2217. * hardware, and all transmit and receive resources are freed.
  2218. **/
  2219. static int igb_close(struct net_device *netdev)
  2220. {
  2221. struct igb_adapter *adapter = netdev_priv(netdev);
  2222. WARN_ON(test_bit(__IGB_RESETTING, &adapter->state));
  2223. igb_down(adapter);
  2224. igb_free_irq(adapter);
  2225. igb_free_all_tx_resources(adapter);
  2226. igb_free_all_rx_resources(adapter);
  2227. return 0;
  2228. }
  2229. /**
  2230. * igb_setup_tx_resources - allocate Tx resources (Descriptors)
  2231. * @tx_ring: tx descriptor ring (for a specific queue) to setup
  2232. *
  2233. * Return 0 on success, negative on failure
  2234. **/
  2235. int igb_setup_tx_resources(struct igb_ring *tx_ring)
  2236. {
  2237. struct device *dev = tx_ring->dev;
  2238. int size;
  2239. size = sizeof(struct igb_buffer) * tx_ring->count;
  2240. tx_ring->buffer_info = vzalloc(size);
  2241. if (!tx_ring->buffer_info)
  2242. goto err;
  2243. /* round up to nearest 4K */
  2244. tx_ring->size = tx_ring->count * sizeof(union e1000_adv_tx_desc);
  2245. tx_ring->size = ALIGN(tx_ring->size, 4096);
  2246. tx_ring->desc = dma_alloc_coherent(dev,
  2247. tx_ring->size,
  2248. &tx_ring->dma,
  2249. GFP_KERNEL);
  2250. if (!tx_ring->desc)
  2251. goto err;
  2252. tx_ring->next_to_use = 0;
  2253. tx_ring->next_to_clean = 0;
  2254. return 0;
  2255. err:
  2256. vfree(tx_ring->buffer_info);
  2257. dev_err(dev,
  2258. "Unable to allocate memory for the transmit descriptor ring\n");
  2259. return -ENOMEM;
  2260. }
  2261. /**
  2262. * igb_setup_all_tx_resources - wrapper to allocate Tx resources
  2263. * (Descriptors) for all queues
  2264. * @adapter: board private structure
  2265. *
  2266. * Return 0 on success, negative on failure
  2267. **/
  2268. static int igb_setup_all_tx_resources(struct igb_adapter *adapter)
  2269. {
  2270. struct pci_dev *pdev = adapter->pdev;
  2271. int i, err = 0;
  2272. for (i = 0; i < adapter->num_tx_queues; i++) {
  2273. err = igb_setup_tx_resources(adapter->tx_ring[i]);
  2274. if (err) {
  2275. dev_err(&pdev->dev,
  2276. "Allocation for Tx Queue %u failed\n", i);
  2277. for (i--; i >= 0; i--)
  2278. igb_free_tx_resources(adapter->tx_ring[i]);
  2279. break;
  2280. }
  2281. }
  2282. for (i = 0; i < IGB_ABS_MAX_TX_QUEUES; i++) {
  2283. int r_idx = i % adapter->num_tx_queues;
  2284. adapter->multi_tx_table[i] = adapter->tx_ring[r_idx];
  2285. }
  2286. return err;
  2287. }
  2288. /**
  2289. * igb_setup_tctl - configure the transmit control registers
  2290. * @adapter: Board private structure
  2291. **/
  2292. void igb_setup_tctl(struct igb_adapter *adapter)
  2293. {
  2294. struct e1000_hw *hw = &adapter->hw;
  2295. u32 tctl;
  2296. /* disable queue 0 which is enabled by default on 82575 and 82576 */
  2297. wr32(E1000_TXDCTL(0), 0);
  2298. /* Program the Transmit Control Register */
  2299. tctl = rd32(E1000_TCTL);
  2300. tctl &= ~E1000_TCTL_CT;
  2301. tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
  2302. (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
  2303. igb_config_collision_dist(hw);
  2304. /* Enable transmits */
  2305. tctl |= E1000_TCTL_EN;
  2306. wr32(E1000_TCTL, tctl);
  2307. }
  2308. /**
  2309. * igb_configure_tx_ring - Configure transmit ring after Reset
  2310. * @adapter: board private structure
  2311. * @ring: tx ring to configure
  2312. *
  2313. * Configure a transmit ring after a reset.
  2314. **/
  2315. void igb_configure_tx_ring(struct igb_adapter *adapter,
  2316. struct igb_ring *ring)
  2317. {
  2318. struct e1000_hw *hw = &adapter->hw;
  2319. u32 txdctl;
  2320. u64 tdba = ring->dma;
  2321. int reg_idx = ring->reg_idx;
  2322. /* disable the queue */
  2323. txdctl = rd32(E1000_TXDCTL(reg_idx));
  2324. wr32(E1000_TXDCTL(reg_idx),
  2325. txdctl & ~E1000_TXDCTL_QUEUE_ENABLE);
  2326. wrfl();
  2327. mdelay(10);
  2328. wr32(E1000_TDLEN(reg_idx),
  2329. ring->count * sizeof(union e1000_adv_tx_desc));
  2330. wr32(E1000_TDBAL(reg_idx),
  2331. tdba & 0x00000000ffffffffULL);
  2332. wr32(E1000_TDBAH(reg_idx), tdba >> 32);
  2333. ring->head = hw->hw_addr + E1000_TDH(reg_idx);
  2334. ring->tail = hw->hw_addr + E1000_TDT(reg_idx);
  2335. writel(0, ring->head);
  2336. writel(0, ring->tail);
  2337. txdctl |= IGB_TX_PTHRESH;
  2338. txdctl |= IGB_TX_HTHRESH << 8;
  2339. txdctl |= IGB_TX_WTHRESH << 16;
  2340. txdctl |= E1000_TXDCTL_QUEUE_ENABLE;
  2341. wr32(E1000_TXDCTL(reg_idx), txdctl);
  2342. }
  2343. /**
  2344. * igb_configure_tx - Configure transmit Unit after Reset
  2345. * @adapter: board private structure
  2346. *
  2347. * Configure the Tx unit of the MAC after a reset.
  2348. **/
  2349. static void igb_configure_tx(struct igb_adapter *adapter)
  2350. {
  2351. int i;
  2352. for (i = 0; i < adapter->num_tx_queues; i++)
  2353. igb_configure_tx_ring(adapter, adapter->tx_ring[i]);
  2354. }
  2355. /**
  2356. * igb_setup_rx_resources - allocate Rx resources (Descriptors)
  2357. * @rx_ring: rx descriptor ring (for a specific queue) to setup
  2358. *
  2359. * Returns 0 on success, negative on failure
  2360. **/
  2361. int igb_setup_rx_resources(struct igb_ring *rx_ring)
  2362. {
  2363. struct device *dev = rx_ring->dev;
  2364. int size, desc_len;
  2365. size = sizeof(struct igb_buffer) * rx_ring->count;
  2366. rx_ring->buffer_info = vzalloc(size);
  2367. if (!rx_ring->buffer_info)
  2368. goto err;
  2369. desc_len = sizeof(union e1000_adv_rx_desc);
  2370. /* Round up to nearest 4K */
  2371. rx_ring->size = rx_ring->count * desc_len;
  2372. rx_ring->size = ALIGN(rx_ring->size, 4096);
  2373. rx_ring->desc = dma_alloc_coherent(dev,
  2374. rx_ring->size,
  2375. &rx_ring->dma,
  2376. GFP_KERNEL);
  2377. if (!rx_ring->desc)
  2378. goto err;
  2379. rx_ring->next_to_clean = 0;
  2380. rx_ring->next_to_use = 0;
  2381. return 0;
  2382. err:
  2383. vfree(rx_ring->buffer_info);
  2384. rx_ring->buffer_info = NULL;
  2385. dev_err(dev, "Unable to allocate memory for the receive descriptor"
  2386. " ring\n");
  2387. return -ENOMEM;
  2388. }
  2389. /**
  2390. * igb_setup_all_rx_resources - wrapper to allocate Rx resources
  2391. * (Descriptors) for all queues
  2392. * @adapter: board private structure
  2393. *
  2394. * Return 0 on success, negative on failure
  2395. **/
  2396. static int igb_setup_all_rx_resources(struct igb_adapter *adapter)
  2397. {
  2398. struct pci_dev *pdev = adapter->pdev;
  2399. int i, err = 0;
  2400. for (i = 0; i < adapter->num_rx_queues; i++) {
  2401. err = igb_setup_rx_resources(adapter->rx_ring[i]);
  2402. if (err) {
  2403. dev_err(&pdev->dev,
  2404. "Allocation for Rx Queue %u failed\n", i);
  2405. for (i--; i >= 0; i--)
  2406. igb_free_rx_resources(adapter->rx_ring[i]);
  2407. break;
  2408. }
  2409. }
  2410. return err;
  2411. }
  2412. /**
  2413. * igb_setup_mrqc - configure the multiple receive queue control registers
  2414. * @adapter: Board private structure
  2415. **/
  2416. static void igb_setup_mrqc(struct igb_adapter *adapter)
  2417. {
  2418. struct e1000_hw *hw = &adapter->hw;
  2419. u32 mrqc, rxcsum;
  2420. u32 j, num_rx_queues, shift = 0, shift2 = 0;
  2421. union e1000_reta {
  2422. u32 dword;
  2423. u8 bytes[4];
  2424. } reta;
  2425. static const u8 rsshash[40] = {
  2426. 0x6d, 0x5a, 0x56, 0xda, 0x25, 0x5b, 0x0e, 0xc2, 0x41, 0x67,
  2427. 0x25, 0x3d, 0x43, 0xa3, 0x8f, 0xb0, 0xd0, 0xca, 0x2b, 0xcb,
  2428. 0xae, 0x7b, 0x30, 0xb4, 0x77, 0xcb, 0x2d, 0xa3, 0x80, 0x30,
  2429. 0xf2, 0x0c, 0x6a, 0x42, 0xb7, 0x3b, 0xbe, 0xac, 0x01, 0xfa };
  2430. /* Fill out hash function seeds */
  2431. for (j = 0; j < 10; j++) {
  2432. u32 rsskey = rsshash[(j * 4)];
  2433. rsskey |= rsshash[(j * 4) + 1] << 8;
  2434. rsskey |= rsshash[(j * 4) + 2] << 16;
  2435. rsskey |= rsshash[(j * 4) + 3] << 24;
  2436. array_wr32(E1000_RSSRK(0), j, rsskey);
  2437. }
  2438. num_rx_queues = adapter->rss_queues;
  2439. if (adapter->vfs_allocated_count) {
  2440. /* 82575 and 82576 supports 2 RSS queues for VMDq */
  2441. switch (hw->mac.type) {
  2442. case e1000_i350:
  2443. case e1000_82580:
  2444. num_rx_queues = 1;
  2445. shift = 0;
  2446. break;
  2447. case e1000_82576:
  2448. shift = 3;
  2449. num_rx_queues = 2;
  2450. break;
  2451. case e1000_82575:
  2452. shift = 2;
  2453. shift2 = 6;
  2454. default:
  2455. break;
  2456. }
  2457. } else {
  2458. if (hw->mac.type == e1000_82575)
  2459. shift = 6;
  2460. }
  2461. for (j = 0; j < (32 * 4); j++) {
  2462. reta.bytes[j & 3] = (j % num_rx_queues) << shift;
  2463. if (shift2)
  2464. reta.bytes[j & 3] |= num_rx_queues << shift2;
  2465. if ((j & 3) == 3)
  2466. wr32(E1000_RETA(j >> 2), reta.dword);
  2467. }
  2468. /*
  2469. * Disable raw packet checksumming so that RSS hash is placed in
  2470. * descriptor on writeback. No need to enable TCP/UDP/IP checksum
  2471. * offloads as they are enabled by default
  2472. */
  2473. rxcsum = rd32(E1000_RXCSUM);
  2474. rxcsum |= E1000_RXCSUM_PCSD;
  2475. if (adapter->hw.mac.type >= e1000_82576)
  2476. /* Enable Receive Checksum Offload for SCTP */
  2477. rxcsum |= E1000_RXCSUM_CRCOFL;
  2478. /* Don't need to set TUOFL or IPOFL, they default to 1 */
  2479. wr32(E1000_RXCSUM, rxcsum);
  2480. /* If VMDq is enabled then we set the appropriate mode for that, else
  2481. * we default to RSS so that an RSS hash is calculated per packet even
  2482. * if we are only using one queue */
  2483. if (adapter->vfs_allocated_count) {
  2484. if (hw->mac.type > e1000_82575) {
  2485. /* Set the default pool for the PF's first queue */
  2486. u32 vtctl = rd32(E1000_VT_CTL);
  2487. vtctl &= ~(E1000_VT_CTL_DEFAULT_POOL_MASK |
  2488. E1000_VT_CTL_DISABLE_DEF_POOL);
  2489. vtctl |= adapter->vfs_allocated_count <<
  2490. E1000_VT_CTL_DEFAULT_POOL_SHIFT;
  2491. wr32(E1000_VT_CTL, vtctl);
  2492. }
  2493. if (adapter->rss_queues > 1)
  2494. mrqc = E1000_MRQC_ENABLE_VMDQ_RSS_2Q;
  2495. else
  2496. mrqc = E1000_MRQC_ENABLE_VMDQ;
  2497. } else {
  2498. mrqc = E1000_MRQC_ENABLE_RSS_4Q;
  2499. }
  2500. igb_vmm_control(adapter);
  2501. /*
  2502. * Generate RSS hash based on TCP port numbers and/or
  2503. * IPv4/v6 src and dst addresses since UDP cannot be
  2504. * hashed reliably due to IP fragmentation
  2505. */
  2506. mrqc |= E1000_MRQC_RSS_FIELD_IPV4 |
  2507. E1000_MRQC_RSS_FIELD_IPV4_TCP |
  2508. E1000_MRQC_RSS_FIELD_IPV6 |
  2509. E1000_MRQC_RSS_FIELD_IPV6_TCP |
  2510. E1000_MRQC_RSS_FIELD_IPV6_TCP_EX;
  2511. wr32(E1000_MRQC, mrqc);
  2512. }
  2513. /**
  2514. * igb_setup_rctl - configure the receive control registers
  2515. * @adapter: Board private structure
  2516. **/
  2517. void igb_setup_rctl(struct igb_adapter *adapter)
  2518. {
  2519. struct e1000_hw *hw = &adapter->hw;
  2520. u32 rctl;
  2521. rctl = rd32(E1000_RCTL);
  2522. rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
  2523. rctl &= ~(E1000_RCTL_LBM_TCVR | E1000_RCTL_LBM_MAC);
  2524. rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_RDMTS_HALF |
  2525. (hw->mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
  2526. /*
  2527. * enable stripping of CRC. It's unlikely this will break BMC
  2528. * redirection as it did with e1000. Newer features require
  2529. * that the HW strips the CRC.
  2530. */
  2531. rctl |= E1000_RCTL_SECRC;
  2532. /* disable store bad packets and clear size bits. */
  2533. rctl &= ~(E1000_RCTL_SBP | E1000_RCTL_SZ_256);
  2534. /* enable LPE to prevent packets larger than max_frame_size */
  2535. rctl |= E1000_RCTL_LPE;
  2536. /* disable queue 0 to prevent tail write w/o re-config */
  2537. wr32(E1000_RXDCTL(0), 0);
  2538. /* Attention!!! For SR-IOV PF driver operations you must enable
  2539. * queue drop for all VF and PF queues to prevent head of line blocking
  2540. * if an un-trusted VF does not provide descriptors to hardware.
  2541. */
  2542. if (adapter->vfs_allocated_count) {
  2543. /* set all queue drop enable bits */
  2544. wr32(E1000_QDE, ALL_QUEUES);
  2545. }
  2546. wr32(E1000_RCTL, rctl);
  2547. }
  2548. static inline int igb_set_vf_rlpml(struct igb_adapter *adapter, int size,
  2549. int vfn)
  2550. {
  2551. struct e1000_hw *hw = &adapter->hw;
  2552. u32 vmolr;
  2553. /* if it isn't the PF check to see if VFs are enabled and
  2554. * increase the size to support vlan tags */
  2555. if (vfn < adapter->vfs_allocated_count &&
  2556. adapter->vf_data[vfn].vlans_enabled)
  2557. size += VLAN_TAG_SIZE;
  2558. vmolr = rd32(E1000_VMOLR(vfn));
  2559. vmolr &= ~E1000_VMOLR_RLPML_MASK;
  2560. vmolr |= size | E1000_VMOLR_LPE;
  2561. wr32(E1000_VMOLR(vfn), vmolr);
  2562. return 0;
  2563. }
  2564. /**
  2565. * igb_rlpml_set - set maximum receive packet size
  2566. * @adapter: board private structure
  2567. *
  2568. * Configure maximum receivable packet size.
  2569. **/
  2570. static void igb_rlpml_set(struct igb_adapter *adapter)
  2571. {
  2572. u32 max_frame_size;
  2573. struct e1000_hw *hw = &adapter->hw;
  2574. u16 pf_id = adapter->vfs_allocated_count;
  2575. max_frame_size = adapter->max_frame_size + VLAN_TAG_SIZE;
  2576. /* if vfs are enabled we set RLPML to the largest possible request
  2577. * size and set the VMOLR RLPML to the size we need */
  2578. if (pf_id) {
  2579. igb_set_vf_rlpml(adapter, max_frame_size, pf_id);
  2580. max_frame_size = MAX_JUMBO_FRAME_SIZE;
  2581. }
  2582. wr32(E1000_RLPML, max_frame_size);
  2583. }
  2584. static inline void igb_set_vmolr(struct igb_adapter *adapter,
  2585. int vfn, bool aupe)
  2586. {
  2587. struct e1000_hw *hw = &adapter->hw;
  2588. u32 vmolr;
  2589. /*
  2590. * This register exists only on 82576 and newer so if we are older then
  2591. * we should exit and do nothing
  2592. */
  2593. if (hw->mac.type < e1000_82576)
  2594. return;
  2595. vmolr = rd32(E1000_VMOLR(vfn));
  2596. vmolr |= E1000_VMOLR_STRVLAN; /* Strip vlan tags */
  2597. if (aupe)
  2598. vmolr |= E1000_VMOLR_AUPE; /* Accept untagged packets */
  2599. else
  2600. vmolr &= ~(E1000_VMOLR_AUPE); /* Tagged packets ONLY */
  2601. /* clear all bits that might not be set */
  2602. vmolr &= ~(E1000_VMOLR_BAM | E1000_VMOLR_RSSE);
  2603. if (adapter->rss_queues > 1 && vfn == adapter->vfs_allocated_count)
  2604. vmolr |= E1000_VMOLR_RSSE; /* enable RSS */
  2605. /*
  2606. * for VMDq only allow the VFs and pool 0 to accept broadcast and
  2607. * multicast packets
  2608. */
  2609. if (vfn <= adapter->vfs_allocated_count)
  2610. vmolr |= E1000_VMOLR_BAM; /* Accept broadcast */
  2611. wr32(E1000_VMOLR(vfn), vmolr);
  2612. }
  2613. /**
  2614. * igb_configure_rx_ring - Configure a receive ring after Reset
  2615. * @adapter: board private structure
  2616. * @ring: receive ring to be configured
  2617. *
  2618. * Configure the Rx unit of the MAC after a reset.
  2619. **/
  2620. void igb_configure_rx_ring(struct igb_adapter *adapter,
  2621. struct igb_ring *ring)
  2622. {
  2623. struct e1000_hw *hw = &adapter->hw;
  2624. u64 rdba = ring->dma;
  2625. int reg_idx = ring->reg_idx;
  2626. u32 srrctl, rxdctl;
  2627. /* disable the queue */
  2628. rxdctl = rd32(E1000_RXDCTL(reg_idx));
  2629. wr32(E1000_RXDCTL(reg_idx),
  2630. rxdctl & ~E1000_RXDCTL_QUEUE_ENABLE);
  2631. /* Set DMA base address registers */
  2632. wr32(E1000_RDBAL(reg_idx),
  2633. rdba & 0x00000000ffffffffULL);
  2634. wr32(E1000_RDBAH(reg_idx), rdba >> 32);
  2635. wr32(E1000_RDLEN(reg_idx),
  2636. ring->count * sizeof(union e1000_adv_rx_desc));
  2637. /* initialize head and tail */
  2638. ring->head = hw->hw_addr + E1000_RDH(reg_idx);
  2639. ring->tail = hw->hw_addr + E1000_RDT(reg_idx);
  2640. writel(0, ring->head);
  2641. writel(0, ring->tail);
  2642. /* set descriptor configuration */
  2643. if (ring->rx_buffer_len < IGB_RXBUFFER_1024) {
  2644. srrctl = ALIGN(ring->rx_buffer_len, 64) <<
  2645. E1000_SRRCTL_BSIZEHDRSIZE_SHIFT;
  2646. #if (PAGE_SIZE / 2) > IGB_RXBUFFER_16384
  2647. srrctl |= IGB_RXBUFFER_16384 >>
  2648. E1000_SRRCTL_BSIZEPKT_SHIFT;
  2649. #else
  2650. srrctl |= (PAGE_SIZE / 2) >>
  2651. E1000_SRRCTL_BSIZEPKT_SHIFT;
  2652. #endif
  2653. srrctl |= E1000_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
  2654. } else {
  2655. srrctl = ALIGN(ring->rx_buffer_len, 1024) >>
  2656. E1000_SRRCTL_BSIZEPKT_SHIFT;
  2657. srrctl |= E1000_SRRCTL_DESCTYPE_ADV_ONEBUF;
  2658. }
  2659. if (hw->mac.type == e1000_82580)
  2660. srrctl |= E1000_SRRCTL_TIMESTAMP;
  2661. /* Only set Drop Enable if we are supporting multiple queues */
  2662. if (adapter->vfs_allocated_count || adapter->num_rx_queues > 1)
  2663. srrctl |= E1000_SRRCTL_DROP_EN;
  2664. wr32(E1000_SRRCTL(reg_idx), srrctl);
  2665. /* set filtering for VMDQ pools */
  2666. igb_set_vmolr(adapter, reg_idx & 0x7, true);
  2667. /* enable receive descriptor fetching */
  2668. rxdctl = rd32(E1000_RXDCTL(reg_idx));
  2669. rxdctl |= E1000_RXDCTL_QUEUE_ENABLE;
  2670. rxdctl &= 0xFFF00000;
  2671. rxdctl |= IGB_RX_PTHRESH;
  2672. rxdctl |= IGB_RX_HTHRESH << 8;
  2673. rxdctl |= IGB_RX_WTHRESH << 16;
  2674. wr32(E1000_RXDCTL(reg_idx), rxdctl);
  2675. }
  2676. /**
  2677. * igb_configure_rx - Configure receive Unit after Reset
  2678. * @adapter: board private structure
  2679. *
  2680. * Configure the Rx unit of the MAC after a reset.
  2681. **/
  2682. static void igb_configure_rx(struct igb_adapter *adapter)
  2683. {
  2684. int i;
  2685. /* set UTA to appropriate mode */
  2686. igb_set_uta(adapter);
  2687. /* set the correct pool for the PF default MAC address in entry 0 */
  2688. igb_rar_set_qsel(adapter, adapter->hw.mac.addr, 0,
  2689. adapter->vfs_allocated_count);
  2690. /* Setup the HW Rx Head and Tail Descriptor Pointers and
  2691. * the Base and Length of the Rx Descriptor Ring */
  2692. for (i = 0; i < adapter->num_rx_queues; i++)
  2693. igb_configure_rx_ring(adapter, adapter->rx_ring[i]);
  2694. }
  2695. /**
  2696. * igb_free_tx_resources - Free Tx Resources per Queue
  2697. * @tx_ring: Tx descriptor ring for a specific queue
  2698. *
  2699. * Free all transmit software resources
  2700. **/
  2701. void igb_free_tx_resources(struct igb_ring *tx_ring)
  2702. {
  2703. igb_clean_tx_ring(tx_ring);
  2704. vfree(tx_ring->buffer_info);
  2705. tx_ring->buffer_info = NULL;
  2706. /* if not set, then don't free */
  2707. if (!tx_ring->desc)
  2708. return;
  2709. dma_free_coherent(tx_ring->dev, tx_ring->size,
  2710. tx_ring->desc, tx_ring->dma);
  2711. tx_ring->desc = NULL;
  2712. }
  2713. /**
  2714. * igb_free_all_tx_resources - Free Tx Resources for All Queues
  2715. * @adapter: board private structure
  2716. *
  2717. * Free all transmit software resources
  2718. **/
  2719. static void igb_free_all_tx_resources(struct igb_adapter *adapter)
  2720. {
  2721. int i;
  2722. for (i = 0; i < adapter->num_tx_queues; i++)
  2723. igb_free_tx_resources(adapter->tx_ring[i]);
  2724. }
  2725. void igb_unmap_and_free_tx_resource(struct igb_ring *tx_ring,
  2726. struct igb_buffer *buffer_info)
  2727. {
  2728. if (buffer_info->dma) {
  2729. if (buffer_info->mapped_as_page)
  2730. dma_unmap_page(tx_ring->dev,
  2731. buffer_info->dma,
  2732. buffer_info->length,
  2733. DMA_TO_DEVICE);
  2734. else
  2735. dma_unmap_single(tx_ring->dev,
  2736. buffer_info->dma,
  2737. buffer_info->length,
  2738. DMA_TO_DEVICE);
  2739. buffer_info->dma = 0;
  2740. }
  2741. if (buffer_info->skb) {
  2742. dev_kfree_skb_any(buffer_info->skb);
  2743. buffer_info->skb = NULL;
  2744. }
  2745. buffer_info->time_stamp = 0;
  2746. buffer_info->length = 0;
  2747. buffer_info->next_to_watch = 0;
  2748. buffer_info->mapped_as_page = false;
  2749. }
  2750. /**
  2751. * igb_clean_tx_ring - Free Tx Buffers
  2752. * @tx_ring: ring to be cleaned
  2753. **/
  2754. static void igb_clean_tx_ring(struct igb_ring *tx_ring)
  2755. {
  2756. struct igb_buffer *buffer_info;
  2757. unsigned long size;
  2758. unsigned int i;
  2759. if (!tx_ring->buffer_info)
  2760. return;
  2761. /* Free all the Tx ring sk_buffs */
  2762. for (i = 0; i < tx_ring->count; i++) {
  2763. buffer_info = &tx_ring->buffer_info[i];
  2764. igb_unmap_and_free_tx_resource(tx_ring, buffer_info);
  2765. }
  2766. size = sizeof(struct igb_buffer) * tx_ring->count;
  2767. memset(tx_ring->buffer_info, 0, size);
  2768. /* Zero out the descriptor ring */
  2769. memset(tx_ring->desc, 0, tx_ring->size);
  2770. tx_ring->next_to_use = 0;
  2771. tx_ring->next_to_clean = 0;
  2772. }
  2773. /**
  2774. * igb_clean_all_tx_rings - Free Tx Buffers for all queues
  2775. * @adapter: board private structure
  2776. **/
  2777. static void igb_clean_all_tx_rings(struct igb_adapter *adapter)
  2778. {
  2779. int i;
  2780. for (i = 0; i < adapter->num_tx_queues; i++)
  2781. igb_clean_tx_ring(adapter->tx_ring[i]);
  2782. }
  2783. /**
  2784. * igb_free_rx_resources - Free Rx Resources
  2785. * @rx_ring: ring to clean the resources from
  2786. *
  2787. * Free all receive software resources
  2788. **/
  2789. void igb_free_rx_resources(struct igb_ring *rx_ring)
  2790. {
  2791. igb_clean_rx_ring(rx_ring);
  2792. vfree(rx_ring->buffer_info);
  2793. rx_ring->buffer_info = NULL;
  2794. /* if not set, then don't free */
  2795. if (!rx_ring->desc)
  2796. return;
  2797. dma_free_coherent(rx_ring->dev, rx_ring->size,
  2798. rx_ring->desc, rx_ring->dma);
  2799. rx_ring->desc = NULL;
  2800. }
  2801. /**
  2802. * igb_free_all_rx_resources - Free Rx Resources for All Queues
  2803. * @adapter: board private structure
  2804. *
  2805. * Free all receive software resources
  2806. **/
  2807. static void igb_free_all_rx_resources(struct igb_adapter *adapter)
  2808. {
  2809. int i;
  2810. for (i = 0; i < adapter->num_rx_queues; i++)
  2811. igb_free_rx_resources(adapter->rx_ring[i]);
  2812. }
  2813. /**
  2814. * igb_clean_rx_ring - Free Rx Buffers per Queue
  2815. * @rx_ring: ring to free buffers from
  2816. **/
  2817. static void igb_clean_rx_ring(struct igb_ring *rx_ring)
  2818. {
  2819. struct igb_buffer *buffer_info;
  2820. unsigned long size;
  2821. unsigned int i;
  2822. if (!rx_ring->buffer_info)
  2823. return;
  2824. /* Free all the Rx ring sk_buffs */
  2825. for (i = 0; i < rx_ring->count; i++) {
  2826. buffer_info = &rx_ring->buffer_info[i];
  2827. if (buffer_info->dma) {
  2828. dma_unmap_single(rx_ring->dev,
  2829. buffer_info->dma,
  2830. rx_ring->rx_buffer_len,
  2831. DMA_FROM_DEVICE);
  2832. buffer_info->dma = 0;
  2833. }
  2834. if (buffer_info->skb) {
  2835. dev_kfree_skb(buffer_info->skb);
  2836. buffer_info->skb = NULL;
  2837. }
  2838. if (buffer_info->page_dma) {
  2839. dma_unmap_page(rx_ring->dev,
  2840. buffer_info->page_dma,
  2841. PAGE_SIZE / 2,
  2842. DMA_FROM_DEVICE);
  2843. buffer_info->page_dma = 0;
  2844. }
  2845. if (buffer_info->page) {
  2846. put_page(buffer_info->page);
  2847. buffer_info->page = NULL;
  2848. buffer_info->page_offset = 0;
  2849. }
  2850. }
  2851. size = sizeof(struct igb_buffer) * rx_ring->count;
  2852. memset(rx_ring->buffer_info, 0, size);
  2853. /* Zero out the descriptor ring */
  2854. memset(rx_ring->desc, 0, rx_ring->size);
  2855. rx_ring->next_to_clean = 0;
  2856. rx_ring->next_to_use = 0;
  2857. }
  2858. /**
  2859. * igb_clean_all_rx_rings - Free Rx Buffers for all queues
  2860. * @adapter: board private structure
  2861. **/
  2862. static void igb_clean_all_rx_rings(struct igb_adapter *adapter)
  2863. {
  2864. int i;
  2865. for (i = 0; i < adapter->num_rx_queues; i++)
  2866. igb_clean_rx_ring(adapter->rx_ring[i]);
  2867. }
  2868. /**
  2869. * igb_set_mac - Change the Ethernet Address of the NIC
  2870. * @netdev: network interface device structure
  2871. * @p: pointer to an address structure
  2872. *
  2873. * Returns 0 on success, negative on failure
  2874. **/
  2875. static int igb_set_mac(struct net_device *netdev, void *p)
  2876. {
  2877. struct igb_adapter *adapter = netdev_priv(netdev);
  2878. struct e1000_hw *hw = &adapter->hw;
  2879. struct sockaddr *addr = p;
  2880. if (!is_valid_ether_addr(addr->sa_data))
  2881. return -EADDRNOTAVAIL;
  2882. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  2883. memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
  2884. /* set the correct pool for the new PF MAC address in entry 0 */
  2885. igb_rar_set_qsel(adapter, hw->mac.addr, 0,
  2886. adapter->vfs_allocated_count);
  2887. return 0;
  2888. }
  2889. /**
  2890. * igb_write_mc_addr_list - write multicast addresses to MTA
  2891. * @netdev: network interface device structure
  2892. *
  2893. * Writes multicast address list to the MTA hash table.
  2894. * Returns: -ENOMEM on failure
  2895. * 0 on no addresses written
  2896. * X on writing X addresses to MTA
  2897. **/
  2898. static int igb_write_mc_addr_list(struct net_device *netdev)
  2899. {
  2900. struct igb_adapter *adapter = netdev_priv(netdev);
  2901. struct e1000_hw *hw = &adapter->hw;
  2902. struct netdev_hw_addr *ha;
  2903. u8 *mta_list;
  2904. int i;
  2905. if (netdev_mc_empty(netdev)) {
  2906. /* nothing to program, so clear mc list */
  2907. igb_update_mc_addr_list(hw, NULL, 0);
  2908. igb_restore_vf_multicasts(adapter);
  2909. return 0;
  2910. }
  2911. mta_list = kzalloc(netdev_mc_count(netdev) * 6, GFP_ATOMIC);
  2912. if (!mta_list)
  2913. return -ENOMEM;
  2914. /* The shared function expects a packed array of only addresses. */
  2915. i = 0;
  2916. netdev_for_each_mc_addr(ha, netdev)
  2917. memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
  2918. igb_update_mc_addr_list(hw, mta_list, i);
  2919. kfree(mta_list);
  2920. return netdev_mc_count(netdev);
  2921. }
  2922. /**
  2923. * igb_write_uc_addr_list - write unicast addresses to RAR table
  2924. * @netdev: network interface device structure
  2925. *
  2926. * Writes unicast address list to the RAR table.
  2927. * Returns: -ENOMEM on failure/insufficient address space
  2928. * 0 on no addresses written
  2929. * X on writing X addresses to the RAR table
  2930. **/
  2931. static int igb_write_uc_addr_list(struct net_device *netdev)
  2932. {
  2933. struct igb_adapter *adapter = netdev_priv(netdev);
  2934. struct e1000_hw *hw = &adapter->hw;
  2935. unsigned int vfn = adapter->vfs_allocated_count;
  2936. unsigned int rar_entries = hw->mac.rar_entry_count - (vfn + 1);
  2937. int count = 0;
  2938. /* return ENOMEM indicating insufficient memory for addresses */
  2939. if (netdev_uc_count(netdev) > rar_entries)
  2940. return -ENOMEM;
  2941. if (!netdev_uc_empty(netdev) && rar_entries) {
  2942. struct netdev_hw_addr *ha;
  2943. netdev_for_each_uc_addr(ha, netdev) {
  2944. if (!rar_entries)
  2945. break;
  2946. igb_rar_set_qsel(adapter, ha->addr,
  2947. rar_entries--,
  2948. vfn);
  2949. count++;
  2950. }
  2951. }
  2952. /* write the addresses in reverse order to avoid write combining */
  2953. for (; rar_entries > 0 ; rar_entries--) {
  2954. wr32(E1000_RAH(rar_entries), 0);
  2955. wr32(E1000_RAL(rar_entries), 0);
  2956. }
  2957. wrfl();
  2958. return count;
  2959. }
  2960. /**
  2961. * igb_set_rx_mode - Secondary Unicast, Multicast and Promiscuous mode set
  2962. * @netdev: network interface device structure
  2963. *
  2964. * The set_rx_mode entry point is called whenever the unicast or multicast
  2965. * address lists or the network interface flags are updated. This routine is
  2966. * responsible for configuring the hardware for proper unicast, multicast,
  2967. * promiscuous mode, and all-multi behavior.
  2968. **/
  2969. static void igb_set_rx_mode(struct net_device *netdev)
  2970. {
  2971. struct igb_adapter *adapter = netdev_priv(netdev);
  2972. struct e1000_hw *hw = &adapter->hw;
  2973. unsigned int vfn = adapter->vfs_allocated_count;
  2974. u32 rctl, vmolr = 0;
  2975. int count;
  2976. /* Check for Promiscuous and All Multicast modes */
  2977. rctl = rd32(E1000_RCTL);
  2978. /* clear the effected bits */
  2979. rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE | E1000_RCTL_VFE);
  2980. if (netdev->flags & IFF_PROMISC) {
  2981. rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
  2982. vmolr |= (E1000_VMOLR_ROPE | E1000_VMOLR_MPME);
  2983. } else {
  2984. if (netdev->flags & IFF_ALLMULTI) {
  2985. rctl |= E1000_RCTL_MPE;
  2986. vmolr |= E1000_VMOLR_MPME;
  2987. } else {
  2988. /*
  2989. * Write addresses to the MTA, if the attempt fails
  2990. * then we should just turn on promiscuous mode so
  2991. * that we can at least receive multicast traffic
  2992. */
  2993. count = igb_write_mc_addr_list(netdev);
  2994. if (count < 0) {
  2995. rctl |= E1000_RCTL_MPE;
  2996. vmolr |= E1000_VMOLR_MPME;
  2997. } else if (count) {
  2998. vmolr |= E1000_VMOLR_ROMPE;
  2999. }
  3000. }
  3001. /*
  3002. * Write addresses to available RAR registers, if there is not
  3003. * sufficient space to store all the addresses then enable
  3004. * unicast promiscuous mode
  3005. */
  3006. count = igb_write_uc_addr_list(netdev);
  3007. if (count < 0) {
  3008. rctl |= E1000_RCTL_UPE;
  3009. vmolr |= E1000_VMOLR_ROPE;
  3010. }
  3011. rctl |= E1000_RCTL_VFE;
  3012. }
  3013. wr32(E1000_RCTL, rctl);
  3014. /*
  3015. * In order to support SR-IOV and eventually VMDq it is necessary to set
  3016. * the VMOLR to enable the appropriate modes. Without this workaround
  3017. * we will have issues with VLAN tag stripping not being done for frames
  3018. * that are only arriving because we are the default pool
  3019. */
  3020. if (hw->mac.type < e1000_82576)
  3021. return;
  3022. vmolr |= rd32(E1000_VMOLR(vfn)) &
  3023. ~(E1000_VMOLR_ROPE | E1000_VMOLR_MPME | E1000_VMOLR_ROMPE);
  3024. wr32(E1000_VMOLR(vfn), vmolr);
  3025. igb_restore_vf_multicasts(adapter);
  3026. }
  3027. static void igb_check_wvbr(struct igb_adapter *adapter)
  3028. {
  3029. struct e1000_hw *hw = &adapter->hw;
  3030. u32 wvbr = 0;
  3031. switch (hw->mac.type) {
  3032. case e1000_82576:
  3033. case e1000_i350:
  3034. if (!(wvbr = rd32(E1000_WVBR)))
  3035. return;
  3036. break;
  3037. default:
  3038. break;
  3039. }
  3040. adapter->wvbr |= wvbr;
  3041. }
  3042. #define IGB_STAGGERED_QUEUE_OFFSET 8
  3043. static void igb_spoof_check(struct igb_adapter *adapter)
  3044. {
  3045. int j;
  3046. if (!adapter->wvbr)
  3047. return;
  3048. for(j = 0; j < adapter->vfs_allocated_count; j++) {
  3049. if (adapter->wvbr & (1 << j) ||
  3050. adapter->wvbr & (1 << (j + IGB_STAGGERED_QUEUE_OFFSET))) {
  3051. dev_warn(&adapter->pdev->dev,
  3052. "Spoof event(s) detected on VF %d\n", j);
  3053. adapter->wvbr &=
  3054. ~((1 << j) |
  3055. (1 << (j + IGB_STAGGERED_QUEUE_OFFSET)));
  3056. }
  3057. }
  3058. }
  3059. /* Need to wait a few seconds after link up to get diagnostic information from
  3060. * the phy */
  3061. static void igb_update_phy_info(unsigned long data)
  3062. {
  3063. struct igb_adapter *adapter = (struct igb_adapter *) data;
  3064. igb_get_phy_info(&adapter->hw);
  3065. }
  3066. /**
  3067. * igb_has_link - check shared code for link and determine up/down
  3068. * @adapter: pointer to driver private info
  3069. **/
  3070. bool igb_has_link(struct igb_adapter *adapter)
  3071. {
  3072. struct e1000_hw *hw = &adapter->hw;
  3073. bool link_active = false;
  3074. s32 ret_val = 0;
  3075. /* get_link_status is set on LSC (link status) interrupt or
  3076. * rx sequence error interrupt. get_link_status will stay
  3077. * false until the e1000_check_for_link establishes link
  3078. * for copper adapters ONLY
  3079. */
  3080. switch (hw->phy.media_type) {
  3081. case e1000_media_type_copper:
  3082. if (hw->mac.get_link_status) {
  3083. ret_val = hw->mac.ops.check_for_link(hw);
  3084. link_active = !hw->mac.get_link_status;
  3085. } else {
  3086. link_active = true;
  3087. }
  3088. break;
  3089. case e1000_media_type_internal_serdes:
  3090. ret_val = hw->mac.ops.check_for_link(hw);
  3091. link_active = hw->mac.serdes_has_link;
  3092. break;
  3093. default:
  3094. case e1000_media_type_unknown:
  3095. break;
  3096. }
  3097. return link_active;
  3098. }
  3099. static bool igb_thermal_sensor_event(struct e1000_hw *hw, u32 event)
  3100. {
  3101. bool ret = false;
  3102. u32 ctrl_ext, thstat;
  3103. /* check for thermal sensor event on i350, copper only */
  3104. if (hw->mac.type == e1000_i350) {
  3105. thstat = rd32(E1000_THSTAT);
  3106. ctrl_ext = rd32(E1000_CTRL_EXT);
  3107. if ((hw->phy.media_type == e1000_media_type_copper) &&
  3108. !(ctrl_ext & E1000_CTRL_EXT_LINK_MODE_SGMII)) {
  3109. ret = !!(thstat & event);
  3110. }
  3111. }
  3112. return ret;
  3113. }
  3114. /**
  3115. * igb_watchdog - Timer Call-back
  3116. * @data: pointer to adapter cast into an unsigned long
  3117. **/
  3118. static void igb_watchdog(unsigned long data)
  3119. {
  3120. struct igb_adapter *adapter = (struct igb_adapter *)data;
  3121. /* Do the rest outside of interrupt context */
  3122. schedule_work(&adapter->watchdog_task);
  3123. }
  3124. static void igb_watchdog_task(struct work_struct *work)
  3125. {
  3126. struct igb_adapter *adapter = container_of(work,
  3127. struct igb_adapter,
  3128. watchdog_task);
  3129. struct e1000_hw *hw = &adapter->hw;
  3130. struct net_device *netdev = adapter->netdev;
  3131. u32 link;
  3132. int i;
  3133. link = igb_has_link(adapter);
  3134. if (link) {
  3135. if (!netif_carrier_ok(netdev)) {
  3136. u32 ctrl;
  3137. hw->mac.ops.get_speed_and_duplex(hw,
  3138. &adapter->link_speed,
  3139. &adapter->link_duplex);
  3140. ctrl = rd32(E1000_CTRL);
  3141. /* Links status message must follow this format */
  3142. printk(KERN_INFO "igb: %s NIC Link is Up %d Mbps %s, "
  3143. "Flow Control: %s\n",
  3144. netdev->name,
  3145. adapter->link_speed,
  3146. adapter->link_duplex == FULL_DUPLEX ?
  3147. "Full Duplex" : "Half Duplex",
  3148. ((ctrl & E1000_CTRL_TFCE) &&
  3149. (ctrl & E1000_CTRL_RFCE)) ? "RX/TX" :
  3150. ((ctrl & E1000_CTRL_RFCE) ? "RX" :
  3151. ((ctrl & E1000_CTRL_TFCE) ? "TX" : "None")));
  3152. /* check for thermal sensor event */
  3153. if (igb_thermal_sensor_event(hw, E1000_THSTAT_LINK_THROTTLE)) {
  3154. printk(KERN_INFO "igb: %s The network adapter "
  3155. "link speed was downshifted "
  3156. "because it overheated.\n",
  3157. netdev->name);
  3158. }
  3159. /* adjust timeout factor according to speed/duplex */
  3160. adapter->tx_timeout_factor = 1;
  3161. switch (adapter->link_speed) {
  3162. case SPEED_10:
  3163. adapter->tx_timeout_factor = 14;
  3164. break;
  3165. case SPEED_100:
  3166. /* maybe add some timeout factor ? */
  3167. break;
  3168. }
  3169. netif_carrier_on(netdev);
  3170. igb_ping_all_vfs(adapter);
  3171. igb_check_vf_rate_limit(adapter);
  3172. /* link state has changed, schedule phy info update */
  3173. if (!test_bit(__IGB_DOWN, &adapter->state))
  3174. mod_timer(&adapter->phy_info_timer,
  3175. round_jiffies(jiffies + 2 * HZ));
  3176. }
  3177. } else {
  3178. if (netif_carrier_ok(netdev)) {
  3179. adapter->link_speed = 0;
  3180. adapter->link_duplex = 0;
  3181. /* check for thermal sensor event */
  3182. if (igb_thermal_sensor_event(hw, E1000_THSTAT_PWR_DOWN)) {
  3183. printk(KERN_ERR "igb: %s The network adapter "
  3184. "was stopped because it "
  3185. "overheated.\n",
  3186. netdev->name);
  3187. }
  3188. /* Links status message must follow this format */
  3189. printk(KERN_INFO "igb: %s NIC Link is Down\n",
  3190. netdev->name);
  3191. netif_carrier_off(netdev);
  3192. igb_ping_all_vfs(adapter);
  3193. /* link state has changed, schedule phy info update */
  3194. if (!test_bit(__IGB_DOWN, &adapter->state))
  3195. mod_timer(&adapter->phy_info_timer,
  3196. round_jiffies(jiffies + 2 * HZ));
  3197. }
  3198. }
  3199. spin_lock(&adapter->stats64_lock);
  3200. igb_update_stats(adapter, &adapter->stats64);
  3201. spin_unlock(&adapter->stats64_lock);
  3202. for (i = 0; i < adapter->num_tx_queues; i++) {
  3203. struct igb_ring *tx_ring = adapter->tx_ring[i];
  3204. if (!netif_carrier_ok(netdev)) {
  3205. /* We've lost link, so the controller stops DMA,
  3206. * but we've got queued Tx work that's never going
  3207. * to get done, so reset controller to flush Tx.
  3208. * (Do the reset outside of interrupt context). */
  3209. if (igb_desc_unused(tx_ring) + 1 < tx_ring->count) {
  3210. adapter->tx_timeout_count++;
  3211. schedule_work(&adapter->reset_task);
  3212. /* return immediately since reset is imminent */
  3213. return;
  3214. }
  3215. }
  3216. /* Force detection of hung controller every watchdog period */
  3217. tx_ring->detect_tx_hung = true;
  3218. }
  3219. /* Cause software interrupt to ensure rx ring is cleaned */
  3220. if (adapter->msix_entries) {
  3221. u32 eics = 0;
  3222. for (i = 0; i < adapter->num_q_vectors; i++) {
  3223. struct igb_q_vector *q_vector = adapter->q_vector[i];
  3224. eics |= q_vector->eims_value;
  3225. }
  3226. wr32(E1000_EICS, eics);
  3227. } else {
  3228. wr32(E1000_ICS, E1000_ICS_RXDMT0);
  3229. }
  3230. igb_spoof_check(adapter);
  3231. /* Reset the timer */
  3232. if (!test_bit(__IGB_DOWN, &adapter->state))
  3233. mod_timer(&adapter->watchdog_timer,
  3234. round_jiffies(jiffies + 2 * HZ));
  3235. }
  3236. enum latency_range {
  3237. lowest_latency = 0,
  3238. low_latency = 1,
  3239. bulk_latency = 2,
  3240. latency_invalid = 255
  3241. };
  3242. /**
  3243. * igb_update_ring_itr - update the dynamic ITR value based on packet size
  3244. *
  3245. * Stores a new ITR value based on strictly on packet size. This
  3246. * algorithm is less sophisticated than that used in igb_update_itr,
  3247. * due to the difficulty of synchronizing statistics across multiple
  3248. * receive rings. The divisors and thresholds used by this function
  3249. * were determined based on theoretical maximum wire speed and testing
  3250. * data, in order to minimize response time while increasing bulk
  3251. * throughput.
  3252. * This functionality is controlled by the InterruptThrottleRate module
  3253. * parameter (see igb_param.c)
  3254. * NOTE: This function is called only when operating in a multiqueue
  3255. * receive environment.
  3256. * @q_vector: pointer to q_vector
  3257. **/
  3258. static void igb_update_ring_itr(struct igb_q_vector *q_vector)
  3259. {
  3260. int new_val = q_vector->itr_val;
  3261. int avg_wire_size = 0;
  3262. struct igb_adapter *adapter = q_vector->adapter;
  3263. struct igb_ring *ring;
  3264. unsigned int packets;
  3265. /* For non-gigabit speeds, just fix the interrupt rate at 4000
  3266. * ints/sec - ITR timer value of 120 ticks.
  3267. */
  3268. if (adapter->link_speed != SPEED_1000) {
  3269. new_val = 976;
  3270. goto set_itr_val;
  3271. }
  3272. ring = q_vector->rx_ring;
  3273. if (ring) {
  3274. packets = ACCESS_ONCE(ring->total_packets);
  3275. if (packets)
  3276. avg_wire_size = ring->total_bytes / packets;
  3277. }
  3278. ring = q_vector->tx_ring;
  3279. if (ring) {
  3280. packets = ACCESS_ONCE(ring->total_packets);
  3281. if (packets)
  3282. avg_wire_size = max_t(u32, avg_wire_size,
  3283. ring->total_bytes / packets);
  3284. }
  3285. /* if avg_wire_size isn't set no work was done */
  3286. if (!avg_wire_size)
  3287. goto clear_counts;
  3288. /* Add 24 bytes to size to account for CRC, preamble, and gap */
  3289. avg_wire_size += 24;
  3290. /* Don't starve jumbo frames */
  3291. avg_wire_size = min(avg_wire_size, 3000);
  3292. /* Give a little boost to mid-size frames */
  3293. if ((avg_wire_size > 300) && (avg_wire_size < 1200))
  3294. new_val = avg_wire_size / 3;
  3295. else
  3296. new_val = avg_wire_size / 2;
  3297. /* when in itr mode 3 do not exceed 20K ints/sec */
  3298. if (adapter->rx_itr_setting == 3 && new_val < 196)
  3299. new_val = 196;
  3300. set_itr_val:
  3301. if (new_val != q_vector->itr_val) {
  3302. q_vector->itr_val = new_val;
  3303. q_vector->set_itr = 1;
  3304. }
  3305. clear_counts:
  3306. if (q_vector->rx_ring) {
  3307. q_vector->rx_ring->total_bytes = 0;
  3308. q_vector->rx_ring->total_packets = 0;
  3309. }
  3310. if (q_vector->tx_ring) {
  3311. q_vector->tx_ring->total_bytes = 0;
  3312. q_vector->tx_ring->total_packets = 0;
  3313. }
  3314. }
  3315. /**
  3316. * igb_update_itr - update the dynamic ITR value based on statistics
  3317. * Stores a new ITR value based on packets and byte
  3318. * counts during the last interrupt. The advantage of per interrupt
  3319. * computation is faster updates and more accurate ITR for the current
  3320. * traffic pattern. Constants in this function were computed
  3321. * based on theoretical maximum wire speed and thresholds were set based
  3322. * on testing data as well as attempting to minimize response time
  3323. * while increasing bulk throughput.
  3324. * this functionality is controlled by the InterruptThrottleRate module
  3325. * parameter (see igb_param.c)
  3326. * NOTE: These calculations are only valid when operating in a single-
  3327. * queue environment.
  3328. * @adapter: pointer to adapter
  3329. * @itr_setting: current q_vector->itr_val
  3330. * @packets: the number of packets during this measurement interval
  3331. * @bytes: the number of bytes during this measurement interval
  3332. **/
  3333. static unsigned int igb_update_itr(struct igb_adapter *adapter, u16 itr_setting,
  3334. int packets, int bytes)
  3335. {
  3336. unsigned int retval = itr_setting;
  3337. if (packets == 0)
  3338. goto update_itr_done;
  3339. switch (itr_setting) {
  3340. case lowest_latency:
  3341. /* handle TSO and jumbo frames */
  3342. if (bytes/packets > 8000)
  3343. retval = bulk_latency;
  3344. else if ((packets < 5) && (bytes > 512))
  3345. retval = low_latency;
  3346. break;
  3347. case low_latency: /* 50 usec aka 20000 ints/s */
  3348. if (bytes > 10000) {
  3349. /* this if handles the TSO accounting */
  3350. if (bytes/packets > 8000) {
  3351. retval = bulk_latency;
  3352. } else if ((packets < 10) || ((bytes/packets) > 1200)) {
  3353. retval = bulk_latency;
  3354. } else if ((packets > 35)) {
  3355. retval = lowest_latency;
  3356. }
  3357. } else if (bytes/packets > 2000) {
  3358. retval = bulk_latency;
  3359. } else if (packets <= 2 && bytes < 512) {
  3360. retval = lowest_latency;
  3361. }
  3362. break;
  3363. case bulk_latency: /* 250 usec aka 4000 ints/s */
  3364. if (bytes > 25000) {
  3365. if (packets > 35)
  3366. retval = low_latency;
  3367. } else if (bytes < 1500) {
  3368. retval = low_latency;
  3369. }
  3370. break;
  3371. }
  3372. update_itr_done:
  3373. return retval;
  3374. }
  3375. static void igb_set_itr(struct igb_adapter *adapter)
  3376. {
  3377. struct igb_q_vector *q_vector = adapter->q_vector[0];
  3378. u16 current_itr;
  3379. u32 new_itr = q_vector->itr_val;
  3380. /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
  3381. if (adapter->link_speed != SPEED_1000) {
  3382. current_itr = 0;
  3383. new_itr = 4000;
  3384. goto set_itr_now;
  3385. }
  3386. adapter->rx_itr = igb_update_itr(adapter,
  3387. adapter->rx_itr,
  3388. q_vector->rx_ring->total_packets,
  3389. q_vector->rx_ring->total_bytes);
  3390. adapter->tx_itr = igb_update_itr(adapter,
  3391. adapter->tx_itr,
  3392. q_vector->tx_ring->total_packets,
  3393. q_vector->tx_ring->total_bytes);
  3394. current_itr = max(adapter->rx_itr, adapter->tx_itr);
  3395. /* conservative mode (itr 3) eliminates the lowest_latency setting */
  3396. if (adapter->rx_itr_setting == 3 && current_itr == lowest_latency)
  3397. current_itr = low_latency;
  3398. switch (current_itr) {
  3399. /* counts and packets in update_itr are dependent on these numbers */
  3400. case lowest_latency:
  3401. new_itr = 56; /* aka 70,000 ints/sec */
  3402. break;
  3403. case low_latency:
  3404. new_itr = 196; /* aka 20,000 ints/sec */
  3405. break;
  3406. case bulk_latency:
  3407. new_itr = 980; /* aka 4,000 ints/sec */
  3408. break;
  3409. default:
  3410. break;
  3411. }
  3412. set_itr_now:
  3413. q_vector->rx_ring->total_bytes = 0;
  3414. q_vector->rx_ring->total_packets = 0;
  3415. q_vector->tx_ring->total_bytes = 0;
  3416. q_vector->tx_ring->total_packets = 0;
  3417. if (new_itr != q_vector->itr_val) {
  3418. /* this attempts to bias the interrupt rate towards Bulk
  3419. * by adding intermediate steps when interrupt rate is
  3420. * increasing */
  3421. new_itr = new_itr > q_vector->itr_val ?
  3422. max((new_itr * q_vector->itr_val) /
  3423. (new_itr + (q_vector->itr_val >> 2)),
  3424. new_itr) :
  3425. new_itr;
  3426. /* Don't write the value here; it resets the adapter's
  3427. * internal timer, and causes us to delay far longer than
  3428. * we should between interrupts. Instead, we write the ITR
  3429. * value at the beginning of the next interrupt so the timing
  3430. * ends up being correct.
  3431. */
  3432. q_vector->itr_val = new_itr;
  3433. q_vector->set_itr = 1;
  3434. }
  3435. }
  3436. #define IGB_TX_FLAGS_CSUM 0x00000001
  3437. #define IGB_TX_FLAGS_VLAN 0x00000002
  3438. #define IGB_TX_FLAGS_TSO 0x00000004
  3439. #define IGB_TX_FLAGS_IPV4 0x00000008
  3440. #define IGB_TX_FLAGS_TSTAMP 0x00000010
  3441. #define IGB_TX_FLAGS_VLAN_MASK 0xffff0000
  3442. #define IGB_TX_FLAGS_VLAN_SHIFT 16
  3443. static inline int igb_tso_adv(struct igb_ring *tx_ring,
  3444. struct sk_buff *skb, u32 tx_flags, u8 *hdr_len)
  3445. {
  3446. struct e1000_adv_tx_context_desc *context_desc;
  3447. unsigned int i;
  3448. int err;
  3449. struct igb_buffer *buffer_info;
  3450. u32 info = 0, tu_cmd = 0;
  3451. u32 mss_l4len_idx;
  3452. u8 l4len;
  3453. if (skb_header_cloned(skb)) {
  3454. err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
  3455. if (err)
  3456. return err;
  3457. }
  3458. l4len = tcp_hdrlen(skb);
  3459. *hdr_len += l4len;
  3460. if (skb->protocol == htons(ETH_P_IP)) {
  3461. struct iphdr *iph = ip_hdr(skb);
  3462. iph->tot_len = 0;
  3463. iph->check = 0;
  3464. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
  3465. iph->daddr, 0,
  3466. IPPROTO_TCP,
  3467. 0);
  3468. } else if (skb_is_gso_v6(skb)) {
  3469. ipv6_hdr(skb)->payload_len = 0;
  3470. tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  3471. &ipv6_hdr(skb)->daddr,
  3472. 0, IPPROTO_TCP, 0);
  3473. }
  3474. i = tx_ring->next_to_use;
  3475. buffer_info = &tx_ring->buffer_info[i];
  3476. context_desc = E1000_TX_CTXTDESC_ADV(*tx_ring, i);
  3477. /* VLAN MACLEN IPLEN */
  3478. if (tx_flags & IGB_TX_FLAGS_VLAN)
  3479. info |= (tx_flags & IGB_TX_FLAGS_VLAN_MASK);
  3480. info |= (skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT);
  3481. *hdr_len += skb_network_offset(skb);
  3482. info |= skb_network_header_len(skb);
  3483. *hdr_len += skb_network_header_len(skb);
  3484. context_desc->vlan_macip_lens = cpu_to_le32(info);
  3485. /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
  3486. tu_cmd |= (E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT);
  3487. if (skb->protocol == htons(ETH_P_IP))
  3488. tu_cmd |= E1000_ADVTXD_TUCMD_IPV4;
  3489. tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
  3490. context_desc->type_tucmd_mlhl = cpu_to_le32(tu_cmd);
  3491. /* MSS L4LEN IDX */
  3492. mss_l4len_idx = (skb_shinfo(skb)->gso_size << E1000_ADVTXD_MSS_SHIFT);
  3493. mss_l4len_idx |= (l4len << E1000_ADVTXD_L4LEN_SHIFT);
  3494. /* For 82575, context index must be unique per ring. */
  3495. if (tx_ring->flags & IGB_RING_FLAG_TX_CTX_IDX)
  3496. mss_l4len_idx |= tx_ring->reg_idx << 4;
  3497. context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
  3498. context_desc->seqnum_seed = 0;
  3499. buffer_info->time_stamp = jiffies;
  3500. buffer_info->next_to_watch = i;
  3501. buffer_info->dma = 0;
  3502. i++;
  3503. if (i == tx_ring->count)
  3504. i = 0;
  3505. tx_ring->next_to_use = i;
  3506. return true;
  3507. }
  3508. static inline bool igb_tx_csum_adv(struct igb_ring *tx_ring,
  3509. struct sk_buff *skb, u32 tx_flags)
  3510. {
  3511. struct e1000_adv_tx_context_desc *context_desc;
  3512. struct device *dev = tx_ring->dev;
  3513. struct igb_buffer *buffer_info;
  3514. u32 info = 0, tu_cmd = 0;
  3515. unsigned int i;
  3516. if ((skb->ip_summed == CHECKSUM_PARTIAL) ||
  3517. (tx_flags & IGB_TX_FLAGS_VLAN)) {
  3518. i = tx_ring->next_to_use;
  3519. buffer_info = &tx_ring->buffer_info[i];
  3520. context_desc = E1000_TX_CTXTDESC_ADV(*tx_ring, i);
  3521. if (tx_flags & IGB_TX_FLAGS_VLAN)
  3522. info |= (tx_flags & IGB_TX_FLAGS_VLAN_MASK);
  3523. info |= (skb_network_offset(skb) << E1000_ADVTXD_MACLEN_SHIFT);
  3524. if (skb->ip_summed == CHECKSUM_PARTIAL)
  3525. info |= skb_network_header_len(skb);
  3526. context_desc->vlan_macip_lens = cpu_to_le32(info);
  3527. tu_cmd |= (E1000_TXD_CMD_DEXT | E1000_ADVTXD_DTYP_CTXT);
  3528. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  3529. __be16 protocol;
  3530. if (skb->protocol == cpu_to_be16(ETH_P_8021Q)) {
  3531. const struct vlan_ethhdr *vhdr =
  3532. (const struct vlan_ethhdr*)skb->data;
  3533. protocol = vhdr->h_vlan_encapsulated_proto;
  3534. } else {
  3535. protocol = skb->protocol;
  3536. }
  3537. switch (protocol) {
  3538. case cpu_to_be16(ETH_P_IP):
  3539. tu_cmd |= E1000_ADVTXD_TUCMD_IPV4;
  3540. if (ip_hdr(skb)->protocol == IPPROTO_TCP)
  3541. tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
  3542. else if (ip_hdr(skb)->protocol == IPPROTO_SCTP)
  3543. tu_cmd |= E1000_ADVTXD_TUCMD_L4T_SCTP;
  3544. break;
  3545. case cpu_to_be16(ETH_P_IPV6):
  3546. /* XXX what about other V6 headers?? */
  3547. if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
  3548. tu_cmd |= E1000_ADVTXD_TUCMD_L4T_TCP;
  3549. else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP)
  3550. tu_cmd |= E1000_ADVTXD_TUCMD_L4T_SCTP;
  3551. break;
  3552. default:
  3553. if (unlikely(net_ratelimit()))
  3554. dev_warn(dev,
  3555. "partial checksum but proto=%x!\n",
  3556. skb->protocol);
  3557. break;
  3558. }
  3559. }
  3560. context_desc->type_tucmd_mlhl = cpu_to_le32(tu_cmd);
  3561. context_desc->seqnum_seed = 0;
  3562. if (tx_ring->flags & IGB_RING_FLAG_TX_CTX_IDX)
  3563. context_desc->mss_l4len_idx =
  3564. cpu_to_le32(tx_ring->reg_idx << 4);
  3565. buffer_info->time_stamp = jiffies;
  3566. buffer_info->next_to_watch = i;
  3567. buffer_info->dma = 0;
  3568. i++;
  3569. if (i == tx_ring->count)
  3570. i = 0;
  3571. tx_ring->next_to_use = i;
  3572. return true;
  3573. }
  3574. return false;
  3575. }
  3576. #define IGB_MAX_TXD_PWR 16
  3577. #define IGB_MAX_DATA_PER_TXD (1<<IGB_MAX_TXD_PWR)
  3578. static inline int igb_tx_map_adv(struct igb_ring *tx_ring, struct sk_buff *skb,
  3579. unsigned int first)
  3580. {
  3581. struct igb_buffer *buffer_info;
  3582. struct device *dev = tx_ring->dev;
  3583. unsigned int hlen = skb_headlen(skb);
  3584. unsigned int count = 0, i;
  3585. unsigned int f;
  3586. u16 gso_segs = skb_shinfo(skb)->gso_segs ?: 1;
  3587. i = tx_ring->next_to_use;
  3588. buffer_info = &tx_ring->buffer_info[i];
  3589. BUG_ON(hlen >= IGB_MAX_DATA_PER_TXD);
  3590. buffer_info->length = hlen;
  3591. /* set time_stamp *before* dma to help avoid a possible race */
  3592. buffer_info->time_stamp = jiffies;
  3593. buffer_info->next_to_watch = i;
  3594. buffer_info->dma = dma_map_single(dev, skb->data, hlen,
  3595. DMA_TO_DEVICE);
  3596. if (dma_mapping_error(dev, buffer_info->dma))
  3597. goto dma_error;
  3598. for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) {
  3599. struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[f];
  3600. unsigned int len = frag->size;
  3601. count++;
  3602. i++;
  3603. if (i == tx_ring->count)
  3604. i = 0;
  3605. buffer_info = &tx_ring->buffer_info[i];
  3606. BUG_ON(len >= IGB_MAX_DATA_PER_TXD);
  3607. buffer_info->length = len;
  3608. buffer_info->time_stamp = jiffies;
  3609. buffer_info->next_to_watch = i;
  3610. buffer_info->mapped_as_page = true;
  3611. buffer_info->dma = dma_map_page(dev,
  3612. frag->page,
  3613. frag->page_offset,
  3614. len,
  3615. DMA_TO_DEVICE);
  3616. if (dma_mapping_error(dev, buffer_info->dma))
  3617. goto dma_error;
  3618. }
  3619. tx_ring->buffer_info[i].skb = skb;
  3620. tx_ring->buffer_info[i].tx_flags = skb_shinfo(skb)->tx_flags;
  3621. /* multiply data chunks by size of headers */
  3622. tx_ring->buffer_info[i].bytecount = ((gso_segs - 1) * hlen) + skb->len;
  3623. tx_ring->buffer_info[i].gso_segs = gso_segs;
  3624. tx_ring->buffer_info[first].next_to_watch = i;
  3625. return ++count;
  3626. dma_error:
  3627. dev_err(dev, "TX DMA map failed\n");
  3628. /* clear timestamp and dma mappings for failed buffer_info mapping */
  3629. buffer_info->dma = 0;
  3630. buffer_info->time_stamp = 0;
  3631. buffer_info->length = 0;
  3632. buffer_info->next_to_watch = 0;
  3633. buffer_info->mapped_as_page = false;
  3634. /* clear timestamp and dma mappings for remaining portion of packet */
  3635. while (count--) {
  3636. if (i == 0)
  3637. i = tx_ring->count;
  3638. i--;
  3639. buffer_info = &tx_ring->buffer_info[i];
  3640. igb_unmap_and_free_tx_resource(tx_ring, buffer_info);
  3641. }
  3642. return 0;
  3643. }
  3644. static inline void igb_tx_queue_adv(struct igb_ring *tx_ring,
  3645. u32 tx_flags, int count, u32 paylen,
  3646. u8 hdr_len)
  3647. {
  3648. union e1000_adv_tx_desc *tx_desc;
  3649. struct igb_buffer *buffer_info;
  3650. u32 olinfo_status = 0, cmd_type_len;
  3651. unsigned int i = tx_ring->next_to_use;
  3652. cmd_type_len = (E1000_ADVTXD_DTYP_DATA | E1000_ADVTXD_DCMD_IFCS |
  3653. E1000_ADVTXD_DCMD_DEXT);
  3654. if (tx_flags & IGB_TX_FLAGS_VLAN)
  3655. cmd_type_len |= E1000_ADVTXD_DCMD_VLE;
  3656. if (tx_flags & IGB_TX_FLAGS_TSTAMP)
  3657. cmd_type_len |= E1000_ADVTXD_MAC_TSTAMP;
  3658. if (tx_flags & IGB_TX_FLAGS_TSO) {
  3659. cmd_type_len |= E1000_ADVTXD_DCMD_TSE;
  3660. /* insert tcp checksum */
  3661. olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
  3662. /* insert ip checksum */
  3663. if (tx_flags & IGB_TX_FLAGS_IPV4)
  3664. olinfo_status |= E1000_TXD_POPTS_IXSM << 8;
  3665. } else if (tx_flags & IGB_TX_FLAGS_CSUM) {
  3666. olinfo_status |= E1000_TXD_POPTS_TXSM << 8;
  3667. }
  3668. if ((tx_ring->flags & IGB_RING_FLAG_TX_CTX_IDX) &&
  3669. (tx_flags & (IGB_TX_FLAGS_CSUM |
  3670. IGB_TX_FLAGS_TSO |
  3671. IGB_TX_FLAGS_VLAN)))
  3672. olinfo_status |= tx_ring->reg_idx << 4;
  3673. olinfo_status |= ((paylen - hdr_len) << E1000_ADVTXD_PAYLEN_SHIFT);
  3674. do {
  3675. buffer_info = &tx_ring->buffer_info[i];
  3676. tx_desc = E1000_TX_DESC_ADV(*tx_ring, i);
  3677. tx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
  3678. tx_desc->read.cmd_type_len =
  3679. cpu_to_le32(cmd_type_len | buffer_info->length);
  3680. tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
  3681. count--;
  3682. i++;
  3683. if (i == tx_ring->count)
  3684. i = 0;
  3685. } while (count > 0);
  3686. tx_desc->read.cmd_type_len |= cpu_to_le32(IGB_ADVTXD_DCMD);
  3687. /* Force memory writes to complete before letting h/w
  3688. * know there are new descriptors to fetch. (Only
  3689. * applicable for weak-ordered memory model archs,
  3690. * such as IA-64). */
  3691. wmb();
  3692. tx_ring->next_to_use = i;
  3693. writel(i, tx_ring->tail);
  3694. /* we need this if more than one processor can write to our tail
  3695. * at a time, it syncronizes IO on IA64/Altix systems */
  3696. mmiowb();
  3697. }
  3698. static int __igb_maybe_stop_tx(struct igb_ring *tx_ring, int size)
  3699. {
  3700. struct net_device *netdev = tx_ring->netdev;
  3701. netif_stop_subqueue(netdev, tx_ring->queue_index);
  3702. /* Herbert's original patch had:
  3703. * smp_mb__after_netif_stop_queue();
  3704. * but since that doesn't exist yet, just open code it. */
  3705. smp_mb();
  3706. /* We need to check again in a case another CPU has just
  3707. * made room available. */
  3708. if (igb_desc_unused(tx_ring) < size)
  3709. return -EBUSY;
  3710. /* A reprieve! */
  3711. netif_wake_subqueue(netdev, tx_ring->queue_index);
  3712. u64_stats_update_begin(&tx_ring->tx_syncp2);
  3713. tx_ring->tx_stats.restart_queue2++;
  3714. u64_stats_update_end(&tx_ring->tx_syncp2);
  3715. return 0;
  3716. }
  3717. static inline int igb_maybe_stop_tx(struct igb_ring *tx_ring, int size)
  3718. {
  3719. if (igb_desc_unused(tx_ring) >= size)
  3720. return 0;
  3721. return __igb_maybe_stop_tx(tx_ring, size);
  3722. }
  3723. netdev_tx_t igb_xmit_frame_ring_adv(struct sk_buff *skb,
  3724. struct igb_ring *tx_ring)
  3725. {
  3726. int tso = 0, count;
  3727. u32 tx_flags = 0;
  3728. u16 first;
  3729. u8 hdr_len = 0;
  3730. /* need: 1 descriptor per page,
  3731. * + 2 desc gap to keep tail from touching head,
  3732. * + 1 desc for skb->data,
  3733. * + 1 desc for context descriptor,
  3734. * otherwise try next time */
  3735. if (igb_maybe_stop_tx(tx_ring, skb_shinfo(skb)->nr_frags + 4)) {
  3736. /* this is a hard error */
  3737. return NETDEV_TX_BUSY;
  3738. }
  3739. if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
  3740. skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
  3741. tx_flags |= IGB_TX_FLAGS_TSTAMP;
  3742. }
  3743. if (vlan_tx_tag_present(skb)) {
  3744. tx_flags |= IGB_TX_FLAGS_VLAN;
  3745. tx_flags |= (vlan_tx_tag_get(skb) << IGB_TX_FLAGS_VLAN_SHIFT);
  3746. }
  3747. if (skb->protocol == htons(ETH_P_IP))
  3748. tx_flags |= IGB_TX_FLAGS_IPV4;
  3749. first = tx_ring->next_to_use;
  3750. if (skb_is_gso(skb)) {
  3751. tso = igb_tso_adv(tx_ring, skb, tx_flags, &hdr_len);
  3752. if (tso < 0) {
  3753. dev_kfree_skb_any(skb);
  3754. return NETDEV_TX_OK;
  3755. }
  3756. }
  3757. if (tso)
  3758. tx_flags |= IGB_TX_FLAGS_TSO;
  3759. else if (igb_tx_csum_adv(tx_ring, skb, tx_flags) &&
  3760. (skb->ip_summed == CHECKSUM_PARTIAL))
  3761. tx_flags |= IGB_TX_FLAGS_CSUM;
  3762. /*
  3763. * count reflects descriptors mapped, if 0 or less then mapping error
  3764. * has occurred and we need to rewind the descriptor queue
  3765. */
  3766. count = igb_tx_map_adv(tx_ring, skb, first);
  3767. if (!count) {
  3768. dev_kfree_skb_any(skb);
  3769. tx_ring->buffer_info[first].time_stamp = 0;
  3770. tx_ring->next_to_use = first;
  3771. return NETDEV_TX_OK;
  3772. }
  3773. igb_tx_queue_adv(tx_ring, tx_flags, count, skb->len, hdr_len);
  3774. /* Make sure there is space in the ring for the next send. */
  3775. igb_maybe_stop_tx(tx_ring, MAX_SKB_FRAGS + 4);
  3776. return NETDEV_TX_OK;
  3777. }
  3778. static netdev_tx_t igb_xmit_frame_adv(struct sk_buff *skb,
  3779. struct net_device *netdev)
  3780. {
  3781. struct igb_adapter *adapter = netdev_priv(netdev);
  3782. struct igb_ring *tx_ring;
  3783. int r_idx = 0;
  3784. if (test_bit(__IGB_DOWN, &adapter->state)) {
  3785. dev_kfree_skb_any(skb);
  3786. return NETDEV_TX_OK;
  3787. }
  3788. if (skb->len <= 0) {
  3789. dev_kfree_skb_any(skb);
  3790. return NETDEV_TX_OK;
  3791. }
  3792. r_idx = skb->queue_mapping & (IGB_ABS_MAX_TX_QUEUES - 1);
  3793. tx_ring = adapter->multi_tx_table[r_idx];
  3794. /* This goes back to the question of how to logically map a tx queue
  3795. * to a flow. Right now, performance is impacted slightly negatively
  3796. * if using multiple tx queues. If the stack breaks away from a
  3797. * single qdisc implementation, we can look at this again. */
  3798. return igb_xmit_frame_ring_adv(skb, tx_ring);
  3799. }
  3800. /**
  3801. * igb_tx_timeout - Respond to a Tx Hang
  3802. * @netdev: network interface device structure
  3803. **/
  3804. static void igb_tx_timeout(struct net_device *netdev)
  3805. {
  3806. struct igb_adapter *adapter = netdev_priv(netdev);
  3807. struct e1000_hw *hw = &adapter->hw;
  3808. /* Do the reset outside of interrupt context */
  3809. adapter->tx_timeout_count++;
  3810. if (hw->mac.type == e1000_82580)
  3811. hw->dev_spec._82575.global_device_reset = true;
  3812. schedule_work(&adapter->reset_task);
  3813. wr32(E1000_EICS,
  3814. (adapter->eims_enable_mask & ~adapter->eims_other));
  3815. }
  3816. static void igb_reset_task(struct work_struct *work)
  3817. {
  3818. struct igb_adapter *adapter;
  3819. adapter = container_of(work, struct igb_adapter, reset_task);
  3820. igb_dump(adapter);
  3821. netdev_err(adapter->netdev, "Reset adapter\n");
  3822. igb_reinit_locked(adapter);
  3823. }
  3824. /**
  3825. * igb_get_stats64 - Get System Network Statistics
  3826. * @netdev: network interface device structure
  3827. * @stats: rtnl_link_stats64 pointer
  3828. *
  3829. **/
  3830. static struct rtnl_link_stats64 *igb_get_stats64(struct net_device *netdev,
  3831. struct rtnl_link_stats64 *stats)
  3832. {
  3833. struct igb_adapter *adapter = netdev_priv(netdev);
  3834. spin_lock(&adapter->stats64_lock);
  3835. igb_update_stats(adapter, &adapter->stats64);
  3836. memcpy(stats, &adapter->stats64, sizeof(*stats));
  3837. spin_unlock(&adapter->stats64_lock);
  3838. return stats;
  3839. }
  3840. /**
  3841. * igb_change_mtu - Change the Maximum Transfer Unit
  3842. * @netdev: network interface device structure
  3843. * @new_mtu: new value for maximum frame size
  3844. *
  3845. * Returns 0 on success, negative on failure
  3846. **/
  3847. static int igb_change_mtu(struct net_device *netdev, int new_mtu)
  3848. {
  3849. struct igb_adapter *adapter = netdev_priv(netdev);
  3850. struct pci_dev *pdev = adapter->pdev;
  3851. int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
  3852. u32 rx_buffer_len, i;
  3853. if ((new_mtu < 68) || (max_frame > MAX_JUMBO_FRAME_SIZE)) {
  3854. dev_err(&pdev->dev, "Invalid MTU setting\n");
  3855. return -EINVAL;
  3856. }
  3857. if (max_frame > MAX_STD_JUMBO_FRAME_SIZE) {
  3858. dev_err(&pdev->dev, "MTU > 9216 not supported.\n");
  3859. return -EINVAL;
  3860. }
  3861. while (test_and_set_bit(__IGB_RESETTING, &adapter->state))
  3862. msleep(1);
  3863. /* igb_down has a dependency on max_frame_size */
  3864. adapter->max_frame_size = max_frame;
  3865. /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
  3866. * means we reserve 2 more, this pushes us to allocate from the next
  3867. * larger slab size.
  3868. * i.e. RXBUFFER_2048 --> size-4096 slab
  3869. */
  3870. if (adapter->hw.mac.type == e1000_82580)
  3871. max_frame += IGB_TS_HDR_LEN;
  3872. if (max_frame <= IGB_RXBUFFER_1024)
  3873. rx_buffer_len = IGB_RXBUFFER_1024;
  3874. else if (max_frame <= MAXIMUM_ETHERNET_VLAN_SIZE)
  3875. rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE;
  3876. else
  3877. rx_buffer_len = IGB_RXBUFFER_128;
  3878. if ((max_frame == ETH_FRAME_LEN + ETH_FCS_LEN + IGB_TS_HDR_LEN) ||
  3879. (max_frame == MAXIMUM_ETHERNET_VLAN_SIZE + IGB_TS_HDR_LEN))
  3880. rx_buffer_len = MAXIMUM_ETHERNET_VLAN_SIZE + IGB_TS_HDR_LEN;
  3881. if ((adapter->hw.mac.type == e1000_82580) &&
  3882. (rx_buffer_len == IGB_RXBUFFER_128))
  3883. rx_buffer_len += IGB_RXBUFFER_64;
  3884. if (netif_running(netdev))
  3885. igb_down(adapter);
  3886. dev_info(&pdev->dev, "changing MTU from %d to %d\n",
  3887. netdev->mtu, new_mtu);
  3888. netdev->mtu = new_mtu;
  3889. for (i = 0; i < adapter->num_rx_queues; i++)
  3890. adapter->rx_ring[i]->rx_buffer_len = rx_buffer_len;
  3891. if (netif_running(netdev))
  3892. igb_up(adapter);
  3893. else
  3894. igb_reset(adapter);
  3895. clear_bit(__IGB_RESETTING, &adapter->state);
  3896. return 0;
  3897. }
  3898. /**
  3899. * igb_update_stats - Update the board statistics counters
  3900. * @adapter: board private structure
  3901. **/
  3902. void igb_update_stats(struct igb_adapter *adapter,
  3903. struct rtnl_link_stats64 *net_stats)
  3904. {
  3905. struct e1000_hw *hw = &adapter->hw;
  3906. struct pci_dev *pdev = adapter->pdev;
  3907. u32 reg, mpc;
  3908. u16 phy_tmp;
  3909. int i;
  3910. u64 bytes, packets;
  3911. unsigned int start;
  3912. u64 _bytes, _packets;
  3913. #define PHY_IDLE_ERROR_COUNT_MASK 0x00FF
  3914. /*
  3915. * Prevent stats update while adapter is being reset, or if the pci
  3916. * connection is down.
  3917. */
  3918. if (adapter->link_speed == 0)
  3919. return;
  3920. if (pci_channel_offline(pdev))
  3921. return;
  3922. bytes = 0;
  3923. packets = 0;
  3924. for (i = 0; i < adapter->num_rx_queues; i++) {
  3925. u32 rqdpc_tmp = rd32(E1000_RQDPC(i)) & 0x0FFF;
  3926. struct igb_ring *ring = adapter->rx_ring[i];
  3927. ring->rx_stats.drops += rqdpc_tmp;
  3928. net_stats->rx_fifo_errors += rqdpc_tmp;
  3929. do {
  3930. start = u64_stats_fetch_begin_bh(&ring->rx_syncp);
  3931. _bytes = ring->rx_stats.bytes;
  3932. _packets = ring->rx_stats.packets;
  3933. } while (u64_stats_fetch_retry_bh(&ring->rx_syncp, start));
  3934. bytes += _bytes;
  3935. packets += _packets;
  3936. }
  3937. net_stats->rx_bytes = bytes;
  3938. net_stats->rx_packets = packets;
  3939. bytes = 0;
  3940. packets = 0;
  3941. for (i = 0; i < adapter->num_tx_queues; i++) {
  3942. struct igb_ring *ring = adapter->tx_ring[i];
  3943. do {
  3944. start = u64_stats_fetch_begin_bh(&ring->tx_syncp);
  3945. _bytes = ring->tx_stats.bytes;
  3946. _packets = ring->tx_stats.packets;
  3947. } while (u64_stats_fetch_retry_bh(&ring->tx_syncp, start));
  3948. bytes += _bytes;
  3949. packets += _packets;
  3950. }
  3951. net_stats->tx_bytes = bytes;
  3952. net_stats->tx_packets = packets;
  3953. /* read stats registers */
  3954. adapter->stats.crcerrs += rd32(E1000_CRCERRS);
  3955. adapter->stats.gprc += rd32(E1000_GPRC);
  3956. adapter->stats.gorc += rd32(E1000_GORCL);
  3957. rd32(E1000_GORCH); /* clear GORCL */
  3958. adapter->stats.bprc += rd32(E1000_BPRC);
  3959. adapter->stats.mprc += rd32(E1000_MPRC);
  3960. adapter->stats.roc += rd32(E1000_ROC);
  3961. adapter->stats.prc64 += rd32(E1000_PRC64);
  3962. adapter->stats.prc127 += rd32(E1000_PRC127);
  3963. adapter->stats.prc255 += rd32(E1000_PRC255);
  3964. adapter->stats.prc511 += rd32(E1000_PRC511);
  3965. adapter->stats.prc1023 += rd32(E1000_PRC1023);
  3966. adapter->stats.prc1522 += rd32(E1000_PRC1522);
  3967. adapter->stats.symerrs += rd32(E1000_SYMERRS);
  3968. adapter->stats.sec += rd32(E1000_SEC);
  3969. mpc = rd32(E1000_MPC);
  3970. adapter->stats.mpc += mpc;
  3971. net_stats->rx_fifo_errors += mpc;
  3972. adapter->stats.scc += rd32(E1000_SCC);
  3973. adapter->stats.ecol += rd32(E1000_ECOL);
  3974. adapter->stats.mcc += rd32(E1000_MCC);
  3975. adapter->stats.latecol += rd32(E1000_LATECOL);
  3976. adapter->stats.dc += rd32(E1000_DC);
  3977. adapter->stats.rlec += rd32(E1000_RLEC);
  3978. adapter->stats.xonrxc += rd32(E1000_XONRXC);
  3979. adapter->stats.xontxc += rd32(E1000_XONTXC);
  3980. adapter->stats.xoffrxc += rd32(E1000_XOFFRXC);
  3981. adapter->stats.xofftxc += rd32(E1000_XOFFTXC);
  3982. adapter->stats.fcruc += rd32(E1000_FCRUC);
  3983. adapter->stats.gptc += rd32(E1000_GPTC);
  3984. adapter->stats.gotc += rd32(E1000_GOTCL);
  3985. rd32(E1000_GOTCH); /* clear GOTCL */
  3986. adapter->stats.rnbc += rd32(E1000_RNBC);
  3987. adapter->stats.ruc += rd32(E1000_RUC);
  3988. adapter->stats.rfc += rd32(E1000_RFC);
  3989. adapter->stats.rjc += rd32(E1000_RJC);
  3990. adapter->stats.tor += rd32(E1000_TORH);
  3991. adapter->stats.tot += rd32(E1000_TOTH);
  3992. adapter->stats.tpr += rd32(E1000_TPR);
  3993. adapter->stats.ptc64 += rd32(E1000_PTC64);
  3994. adapter->stats.ptc127 += rd32(E1000_PTC127);
  3995. adapter->stats.ptc255 += rd32(E1000_PTC255);
  3996. adapter->stats.ptc511 += rd32(E1000_PTC511);
  3997. adapter->stats.ptc1023 += rd32(E1000_PTC1023);
  3998. adapter->stats.ptc1522 += rd32(E1000_PTC1522);
  3999. adapter->stats.mptc += rd32(E1000_MPTC);
  4000. adapter->stats.bptc += rd32(E1000_BPTC);
  4001. adapter->stats.tpt += rd32(E1000_TPT);
  4002. adapter->stats.colc += rd32(E1000_COLC);
  4003. adapter->stats.algnerrc += rd32(E1000_ALGNERRC);
  4004. /* read internal phy specific stats */
  4005. reg = rd32(E1000_CTRL_EXT);
  4006. if (!(reg & E1000_CTRL_EXT_LINK_MODE_MASK)) {
  4007. adapter->stats.rxerrc += rd32(E1000_RXERRC);
  4008. adapter->stats.tncrs += rd32(E1000_TNCRS);
  4009. }
  4010. adapter->stats.tsctc += rd32(E1000_TSCTC);
  4011. adapter->stats.tsctfc += rd32(E1000_TSCTFC);
  4012. adapter->stats.iac += rd32(E1000_IAC);
  4013. adapter->stats.icrxoc += rd32(E1000_ICRXOC);
  4014. adapter->stats.icrxptc += rd32(E1000_ICRXPTC);
  4015. adapter->stats.icrxatc += rd32(E1000_ICRXATC);
  4016. adapter->stats.ictxptc += rd32(E1000_ICTXPTC);
  4017. adapter->stats.ictxatc += rd32(E1000_ICTXATC);
  4018. adapter->stats.ictxqec += rd32(E1000_ICTXQEC);
  4019. adapter->stats.ictxqmtc += rd32(E1000_ICTXQMTC);
  4020. adapter->stats.icrxdmtc += rd32(E1000_ICRXDMTC);
  4021. /* Fill out the OS statistics structure */
  4022. net_stats->multicast = adapter->stats.mprc;
  4023. net_stats->collisions = adapter->stats.colc;
  4024. /* Rx Errors */
  4025. /* RLEC on some newer hardware can be incorrect so build
  4026. * our own version based on RUC and ROC */
  4027. net_stats->rx_errors = adapter->stats.rxerrc +
  4028. adapter->stats.crcerrs + adapter->stats.algnerrc +
  4029. adapter->stats.ruc + adapter->stats.roc +
  4030. adapter->stats.cexterr;
  4031. net_stats->rx_length_errors = adapter->stats.ruc +
  4032. adapter->stats.roc;
  4033. net_stats->rx_crc_errors = adapter->stats.crcerrs;
  4034. net_stats->rx_frame_errors = adapter->stats.algnerrc;
  4035. net_stats->rx_missed_errors = adapter->stats.mpc;
  4036. /* Tx Errors */
  4037. net_stats->tx_errors = adapter->stats.ecol +
  4038. adapter->stats.latecol;
  4039. net_stats->tx_aborted_errors = adapter->stats.ecol;
  4040. net_stats->tx_window_errors = adapter->stats.latecol;
  4041. net_stats->tx_carrier_errors = adapter->stats.tncrs;
  4042. /* Tx Dropped needs to be maintained elsewhere */
  4043. /* Phy Stats */
  4044. if (hw->phy.media_type == e1000_media_type_copper) {
  4045. if ((adapter->link_speed == SPEED_1000) &&
  4046. (!igb_read_phy_reg(hw, PHY_1000T_STATUS, &phy_tmp))) {
  4047. phy_tmp &= PHY_IDLE_ERROR_COUNT_MASK;
  4048. adapter->phy_stats.idle_errors += phy_tmp;
  4049. }
  4050. }
  4051. /* Management Stats */
  4052. adapter->stats.mgptc += rd32(E1000_MGTPTC);
  4053. adapter->stats.mgprc += rd32(E1000_MGTPRC);
  4054. adapter->stats.mgpdc += rd32(E1000_MGTPDC);
  4055. /* OS2BMC Stats */
  4056. reg = rd32(E1000_MANC);
  4057. if (reg & E1000_MANC_EN_BMC2OS) {
  4058. adapter->stats.o2bgptc += rd32(E1000_O2BGPTC);
  4059. adapter->stats.o2bspc += rd32(E1000_O2BSPC);
  4060. adapter->stats.b2ospc += rd32(E1000_B2OSPC);
  4061. adapter->stats.b2ogprc += rd32(E1000_B2OGPRC);
  4062. }
  4063. }
  4064. static irqreturn_t igb_msix_other(int irq, void *data)
  4065. {
  4066. struct igb_adapter *adapter = data;
  4067. struct e1000_hw *hw = &adapter->hw;
  4068. u32 icr = rd32(E1000_ICR);
  4069. /* reading ICR causes bit 31 of EICR to be cleared */
  4070. if (icr & E1000_ICR_DRSTA)
  4071. schedule_work(&adapter->reset_task);
  4072. if (icr & E1000_ICR_DOUTSYNC) {
  4073. /* HW is reporting DMA is out of sync */
  4074. adapter->stats.doosync++;
  4075. /* The DMA Out of Sync is also indication of a spoof event
  4076. * in IOV mode. Check the Wrong VM Behavior register to
  4077. * see if it is really a spoof event. */
  4078. igb_check_wvbr(adapter);
  4079. }
  4080. /* Check for a mailbox event */
  4081. if (icr & E1000_ICR_VMMB)
  4082. igb_msg_task(adapter);
  4083. if (icr & E1000_ICR_LSC) {
  4084. hw->mac.get_link_status = 1;
  4085. /* guard against interrupt when we're going down */
  4086. if (!test_bit(__IGB_DOWN, &adapter->state))
  4087. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  4088. }
  4089. if (adapter->vfs_allocated_count)
  4090. wr32(E1000_IMS, E1000_IMS_LSC |
  4091. E1000_IMS_VMMB |
  4092. E1000_IMS_DOUTSYNC);
  4093. else
  4094. wr32(E1000_IMS, E1000_IMS_LSC | E1000_IMS_DOUTSYNC);
  4095. wr32(E1000_EIMS, adapter->eims_other);
  4096. return IRQ_HANDLED;
  4097. }
  4098. static void igb_write_itr(struct igb_q_vector *q_vector)
  4099. {
  4100. struct igb_adapter *adapter = q_vector->adapter;
  4101. u32 itr_val = q_vector->itr_val & 0x7FFC;
  4102. if (!q_vector->set_itr)
  4103. return;
  4104. if (!itr_val)
  4105. itr_val = 0x4;
  4106. if (adapter->hw.mac.type == e1000_82575)
  4107. itr_val |= itr_val << 16;
  4108. else
  4109. itr_val |= 0x8000000;
  4110. writel(itr_val, q_vector->itr_register);
  4111. q_vector->set_itr = 0;
  4112. }
  4113. static irqreturn_t igb_msix_ring(int irq, void *data)
  4114. {
  4115. struct igb_q_vector *q_vector = data;
  4116. /* Write the ITR value calculated from the previous interrupt. */
  4117. igb_write_itr(q_vector);
  4118. napi_schedule(&q_vector->napi);
  4119. return IRQ_HANDLED;
  4120. }
  4121. #ifdef CONFIG_IGB_DCA
  4122. static void igb_update_dca(struct igb_q_vector *q_vector)
  4123. {
  4124. struct igb_adapter *adapter = q_vector->adapter;
  4125. struct e1000_hw *hw = &adapter->hw;
  4126. int cpu = get_cpu();
  4127. if (q_vector->cpu == cpu)
  4128. goto out_no_update;
  4129. if (q_vector->tx_ring) {
  4130. int q = q_vector->tx_ring->reg_idx;
  4131. u32 dca_txctrl = rd32(E1000_DCA_TXCTRL(q));
  4132. if (hw->mac.type == e1000_82575) {
  4133. dca_txctrl &= ~E1000_DCA_TXCTRL_CPUID_MASK;
  4134. dca_txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
  4135. } else {
  4136. dca_txctrl &= ~E1000_DCA_TXCTRL_CPUID_MASK_82576;
  4137. dca_txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu) <<
  4138. E1000_DCA_TXCTRL_CPUID_SHIFT;
  4139. }
  4140. dca_txctrl |= E1000_DCA_TXCTRL_DESC_DCA_EN;
  4141. wr32(E1000_DCA_TXCTRL(q), dca_txctrl);
  4142. }
  4143. if (q_vector->rx_ring) {
  4144. int q = q_vector->rx_ring->reg_idx;
  4145. u32 dca_rxctrl = rd32(E1000_DCA_RXCTRL(q));
  4146. if (hw->mac.type == e1000_82575) {
  4147. dca_rxctrl &= ~E1000_DCA_RXCTRL_CPUID_MASK;
  4148. dca_rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
  4149. } else {
  4150. dca_rxctrl &= ~E1000_DCA_RXCTRL_CPUID_MASK_82576;
  4151. dca_rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu) <<
  4152. E1000_DCA_RXCTRL_CPUID_SHIFT;
  4153. }
  4154. dca_rxctrl |= E1000_DCA_RXCTRL_DESC_DCA_EN;
  4155. dca_rxctrl |= E1000_DCA_RXCTRL_HEAD_DCA_EN;
  4156. dca_rxctrl |= E1000_DCA_RXCTRL_DATA_DCA_EN;
  4157. wr32(E1000_DCA_RXCTRL(q), dca_rxctrl);
  4158. }
  4159. q_vector->cpu = cpu;
  4160. out_no_update:
  4161. put_cpu();
  4162. }
  4163. static void igb_setup_dca(struct igb_adapter *adapter)
  4164. {
  4165. struct e1000_hw *hw = &adapter->hw;
  4166. int i;
  4167. if (!(adapter->flags & IGB_FLAG_DCA_ENABLED))
  4168. return;
  4169. /* Always use CB2 mode, difference is masked in the CB driver. */
  4170. wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_CB2);
  4171. for (i = 0; i < adapter->num_q_vectors; i++) {
  4172. adapter->q_vector[i]->cpu = -1;
  4173. igb_update_dca(adapter->q_vector[i]);
  4174. }
  4175. }
  4176. static int __igb_notify_dca(struct device *dev, void *data)
  4177. {
  4178. struct net_device *netdev = dev_get_drvdata(dev);
  4179. struct igb_adapter *adapter = netdev_priv(netdev);
  4180. struct pci_dev *pdev = adapter->pdev;
  4181. struct e1000_hw *hw = &adapter->hw;
  4182. unsigned long event = *(unsigned long *)data;
  4183. switch (event) {
  4184. case DCA_PROVIDER_ADD:
  4185. /* if already enabled, don't do it again */
  4186. if (adapter->flags & IGB_FLAG_DCA_ENABLED)
  4187. break;
  4188. if (dca_add_requester(dev) == 0) {
  4189. adapter->flags |= IGB_FLAG_DCA_ENABLED;
  4190. dev_info(&pdev->dev, "DCA enabled\n");
  4191. igb_setup_dca(adapter);
  4192. break;
  4193. }
  4194. /* Fall Through since DCA is disabled. */
  4195. case DCA_PROVIDER_REMOVE:
  4196. if (adapter->flags & IGB_FLAG_DCA_ENABLED) {
  4197. /* without this a class_device is left
  4198. * hanging around in the sysfs model */
  4199. dca_remove_requester(dev);
  4200. dev_info(&pdev->dev, "DCA disabled\n");
  4201. adapter->flags &= ~IGB_FLAG_DCA_ENABLED;
  4202. wr32(E1000_DCA_CTRL, E1000_DCA_CTRL_DCA_MODE_DISABLE);
  4203. }
  4204. break;
  4205. }
  4206. return 0;
  4207. }
  4208. static int igb_notify_dca(struct notifier_block *nb, unsigned long event,
  4209. void *p)
  4210. {
  4211. int ret_val;
  4212. ret_val = driver_for_each_device(&igb_driver.driver, NULL, &event,
  4213. __igb_notify_dca);
  4214. return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
  4215. }
  4216. #endif /* CONFIG_IGB_DCA */
  4217. static void igb_ping_all_vfs(struct igb_adapter *adapter)
  4218. {
  4219. struct e1000_hw *hw = &adapter->hw;
  4220. u32 ping;
  4221. int i;
  4222. for (i = 0 ; i < adapter->vfs_allocated_count; i++) {
  4223. ping = E1000_PF_CONTROL_MSG;
  4224. if (adapter->vf_data[i].flags & IGB_VF_FLAG_CTS)
  4225. ping |= E1000_VT_MSGTYPE_CTS;
  4226. igb_write_mbx(hw, &ping, 1, i);
  4227. }
  4228. }
  4229. static int igb_set_vf_promisc(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
  4230. {
  4231. struct e1000_hw *hw = &adapter->hw;
  4232. u32 vmolr = rd32(E1000_VMOLR(vf));
  4233. struct vf_data_storage *vf_data = &adapter->vf_data[vf];
  4234. vf_data->flags &= ~(IGB_VF_FLAG_UNI_PROMISC |
  4235. IGB_VF_FLAG_MULTI_PROMISC);
  4236. vmolr &= ~(E1000_VMOLR_ROPE | E1000_VMOLR_ROMPE | E1000_VMOLR_MPME);
  4237. if (*msgbuf & E1000_VF_SET_PROMISC_MULTICAST) {
  4238. vmolr |= E1000_VMOLR_MPME;
  4239. vf_data->flags |= IGB_VF_FLAG_MULTI_PROMISC;
  4240. *msgbuf &= ~E1000_VF_SET_PROMISC_MULTICAST;
  4241. } else {
  4242. /*
  4243. * if we have hashes and we are clearing a multicast promisc
  4244. * flag we need to write the hashes to the MTA as this step
  4245. * was previously skipped
  4246. */
  4247. if (vf_data->num_vf_mc_hashes > 30) {
  4248. vmolr |= E1000_VMOLR_MPME;
  4249. } else if (vf_data->num_vf_mc_hashes) {
  4250. int j;
  4251. vmolr |= E1000_VMOLR_ROMPE;
  4252. for (j = 0; j < vf_data->num_vf_mc_hashes; j++)
  4253. igb_mta_set(hw, vf_data->vf_mc_hashes[j]);
  4254. }
  4255. }
  4256. wr32(E1000_VMOLR(vf), vmolr);
  4257. /* there are flags left unprocessed, likely not supported */
  4258. if (*msgbuf & E1000_VT_MSGINFO_MASK)
  4259. return -EINVAL;
  4260. return 0;
  4261. }
  4262. static int igb_set_vf_multicasts(struct igb_adapter *adapter,
  4263. u32 *msgbuf, u32 vf)
  4264. {
  4265. int n = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
  4266. u16 *hash_list = (u16 *)&msgbuf[1];
  4267. struct vf_data_storage *vf_data = &adapter->vf_data[vf];
  4268. int i;
  4269. /* salt away the number of multicast addresses assigned
  4270. * to this VF for later use to restore when the PF multi cast
  4271. * list changes
  4272. */
  4273. vf_data->num_vf_mc_hashes = n;
  4274. /* only up to 30 hash values supported */
  4275. if (n > 30)
  4276. n = 30;
  4277. /* store the hashes for later use */
  4278. for (i = 0; i < n; i++)
  4279. vf_data->vf_mc_hashes[i] = hash_list[i];
  4280. /* Flush and reset the mta with the new values */
  4281. igb_set_rx_mode(adapter->netdev);
  4282. return 0;
  4283. }
  4284. static void igb_restore_vf_multicasts(struct igb_adapter *adapter)
  4285. {
  4286. struct e1000_hw *hw = &adapter->hw;
  4287. struct vf_data_storage *vf_data;
  4288. int i, j;
  4289. for (i = 0; i < adapter->vfs_allocated_count; i++) {
  4290. u32 vmolr = rd32(E1000_VMOLR(i));
  4291. vmolr &= ~(E1000_VMOLR_ROMPE | E1000_VMOLR_MPME);
  4292. vf_data = &adapter->vf_data[i];
  4293. if ((vf_data->num_vf_mc_hashes > 30) ||
  4294. (vf_data->flags & IGB_VF_FLAG_MULTI_PROMISC)) {
  4295. vmolr |= E1000_VMOLR_MPME;
  4296. } else if (vf_data->num_vf_mc_hashes) {
  4297. vmolr |= E1000_VMOLR_ROMPE;
  4298. for (j = 0; j < vf_data->num_vf_mc_hashes; j++)
  4299. igb_mta_set(hw, vf_data->vf_mc_hashes[j]);
  4300. }
  4301. wr32(E1000_VMOLR(i), vmolr);
  4302. }
  4303. }
  4304. static void igb_clear_vf_vfta(struct igb_adapter *adapter, u32 vf)
  4305. {
  4306. struct e1000_hw *hw = &adapter->hw;
  4307. u32 pool_mask, reg, vid;
  4308. int i;
  4309. pool_mask = 1 << (E1000_VLVF_POOLSEL_SHIFT + vf);
  4310. /* Find the vlan filter for this id */
  4311. for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
  4312. reg = rd32(E1000_VLVF(i));
  4313. /* remove the vf from the pool */
  4314. reg &= ~pool_mask;
  4315. /* if pool is empty then remove entry from vfta */
  4316. if (!(reg & E1000_VLVF_POOLSEL_MASK) &&
  4317. (reg & E1000_VLVF_VLANID_ENABLE)) {
  4318. reg = 0;
  4319. vid = reg & E1000_VLVF_VLANID_MASK;
  4320. igb_vfta_set(hw, vid, false);
  4321. }
  4322. wr32(E1000_VLVF(i), reg);
  4323. }
  4324. adapter->vf_data[vf].vlans_enabled = 0;
  4325. }
  4326. static s32 igb_vlvf_set(struct igb_adapter *adapter, u32 vid, bool add, u32 vf)
  4327. {
  4328. struct e1000_hw *hw = &adapter->hw;
  4329. u32 reg, i;
  4330. /* The vlvf table only exists on 82576 hardware and newer */
  4331. if (hw->mac.type < e1000_82576)
  4332. return -1;
  4333. /* we only need to do this if VMDq is enabled */
  4334. if (!adapter->vfs_allocated_count)
  4335. return -1;
  4336. /* Find the vlan filter for this id */
  4337. for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
  4338. reg = rd32(E1000_VLVF(i));
  4339. if ((reg & E1000_VLVF_VLANID_ENABLE) &&
  4340. vid == (reg & E1000_VLVF_VLANID_MASK))
  4341. break;
  4342. }
  4343. if (add) {
  4344. if (i == E1000_VLVF_ARRAY_SIZE) {
  4345. /* Did not find a matching VLAN ID entry that was
  4346. * enabled. Search for a free filter entry, i.e.
  4347. * one without the enable bit set
  4348. */
  4349. for (i = 0; i < E1000_VLVF_ARRAY_SIZE; i++) {
  4350. reg = rd32(E1000_VLVF(i));
  4351. if (!(reg & E1000_VLVF_VLANID_ENABLE))
  4352. break;
  4353. }
  4354. }
  4355. if (i < E1000_VLVF_ARRAY_SIZE) {
  4356. /* Found an enabled/available entry */
  4357. reg |= 1 << (E1000_VLVF_POOLSEL_SHIFT + vf);
  4358. /* if !enabled we need to set this up in vfta */
  4359. if (!(reg & E1000_VLVF_VLANID_ENABLE)) {
  4360. /* add VID to filter table */
  4361. igb_vfta_set(hw, vid, true);
  4362. reg |= E1000_VLVF_VLANID_ENABLE;
  4363. }
  4364. reg &= ~E1000_VLVF_VLANID_MASK;
  4365. reg |= vid;
  4366. wr32(E1000_VLVF(i), reg);
  4367. /* do not modify RLPML for PF devices */
  4368. if (vf >= adapter->vfs_allocated_count)
  4369. return 0;
  4370. if (!adapter->vf_data[vf].vlans_enabled) {
  4371. u32 size;
  4372. reg = rd32(E1000_VMOLR(vf));
  4373. size = reg & E1000_VMOLR_RLPML_MASK;
  4374. size += 4;
  4375. reg &= ~E1000_VMOLR_RLPML_MASK;
  4376. reg |= size;
  4377. wr32(E1000_VMOLR(vf), reg);
  4378. }
  4379. adapter->vf_data[vf].vlans_enabled++;
  4380. return 0;
  4381. }
  4382. } else {
  4383. if (i < E1000_VLVF_ARRAY_SIZE) {
  4384. /* remove vf from the pool */
  4385. reg &= ~(1 << (E1000_VLVF_POOLSEL_SHIFT + vf));
  4386. /* if pool is empty then remove entry from vfta */
  4387. if (!(reg & E1000_VLVF_POOLSEL_MASK)) {
  4388. reg = 0;
  4389. igb_vfta_set(hw, vid, false);
  4390. }
  4391. wr32(E1000_VLVF(i), reg);
  4392. /* do not modify RLPML for PF devices */
  4393. if (vf >= adapter->vfs_allocated_count)
  4394. return 0;
  4395. adapter->vf_data[vf].vlans_enabled--;
  4396. if (!adapter->vf_data[vf].vlans_enabled) {
  4397. u32 size;
  4398. reg = rd32(E1000_VMOLR(vf));
  4399. size = reg & E1000_VMOLR_RLPML_MASK;
  4400. size -= 4;
  4401. reg &= ~E1000_VMOLR_RLPML_MASK;
  4402. reg |= size;
  4403. wr32(E1000_VMOLR(vf), reg);
  4404. }
  4405. }
  4406. }
  4407. return 0;
  4408. }
  4409. static void igb_set_vmvir(struct igb_adapter *adapter, u32 vid, u32 vf)
  4410. {
  4411. struct e1000_hw *hw = &adapter->hw;
  4412. if (vid)
  4413. wr32(E1000_VMVIR(vf), (vid | E1000_VMVIR_VLANA_DEFAULT));
  4414. else
  4415. wr32(E1000_VMVIR(vf), 0);
  4416. }
  4417. static int igb_ndo_set_vf_vlan(struct net_device *netdev,
  4418. int vf, u16 vlan, u8 qos)
  4419. {
  4420. int err = 0;
  4421. struct igb_adapter *adapter = netdev_priv(netdev);
  4422. if ((vf >= adapter->vfs_allocated_count) || (vlan > 4095) || (qos > 7))
  4423. return -EINVAL;
  4424. if (vlan || qos) {
  4425. err = igb_vlvf_set(adapter, vlan, !!vlan, vf);
  4426. if (err)
  4427. goto out;
  4428. igb_set_vmvir(adapter, vlan | (qos << VLAN_PRIO_SHIFT), vf);
  4429. igb_set_vmolr(adapter, vf, !vlan);
  4430. adapter->vf_data[vf].pf_vlan = vlan;
  4431. adapter->vf_data[vf].pf_qos = qos;
  4432. dev_info(&adapter->pdev->dev,
  4433. "Setting VLAN %d, QOS 0x%x on VF %d\n", vlan, qos, vf);
  4434. if (test_bit(__IGB_DOWN, &adapter->state)) {
  4435. dev_warn(&adapter->pdev->dev,
  4436. "The VF VLAN has been set,"
  4437. " but the PF device is not up.\n");
  4438. dev_warn(&adapter->pdev->dev,
  4439. "Bring the PF device up before"
  4440. " attempting to use the VF device.\n");
  4441. }
  4442. } else {
  4443. igb_vlvf_set(adapter, adapter->vf_data[vf].pf_vlan,
  4444. false, vf);
  4445. igb_set_vmvir(adapter, vlan, vf);
  4446. igb_set_vmolr(adapter, vf, true);
  4447. adapter->vf_data[vf].pf_vlan = 0;
  4448. adapter->vf_data[vf].pf_qos = 0;
  4449. }
  4450. out:
  4451. return err;
  4452. }
  4453. static int igb_set_vf_vlan(struct igb_adapter *adapter, u32 *msgbuf, u32 vf)
  4454. {
  4455. int add = (msgbuf[0] & E1000_VT_MSGINFO_MASK) >> E1000_VT_MSGINFO_SHIFT;
  4456. int vid = (msgbuf[1] & E1000_VLVF_VLANID_MASK);
  4457. return igb_vlvf_set(adapter, vid, add, vf);
  4458. }
  4459. static inline void igb_vf_reset(struct igb_adapter *adapter, u32 vf)
  4460. {
  4461. /* clear flags - except flag that indicates PF has set the MAC */
  4462. adapter->vf_data[vf].flags &= IGB_VF_FLAG_PF_SET_MAC;
  4463. adapter->vf_data[vf].last_nack = jiffies;
  4464. /* reset offloads to defaults */
  4465. igb_set_vmolr(adapter, vf, true);
  4466. /* reset vlans for device */
  4467. igb_clear_vf_vfta(adapter, vf);
  4468. if (adapter->vf_data[vf].pf_vlan)
  4469. igb_ndo_set_vf_vlan(adapter->netdev, vf,
  4470. adapter->vf_data[vf].pf_vlan,
  4471. adapter->vf_data[vf].pf_qos);
  4472. else
  4473. igb_clear_vf_vfta(adapter, vf);
  4474. /* reset multicast table array for vf */
  4475. adapter->vf_data[vf].num_vf_mc_hashes = 0;
  4476. /* Flush and reset the mta with the new values */
  4477. igb_set_rx_mode(adapter->netdev);
  4478. }
  4479. static void igb_vf_reset_event(struct igb_adapter *adapter, u32 vf)
  4480. {
  4481. unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
  4482. /* generate a new mac address as we were hotplug removed/added */
  4483. if (!(adapter->vf_data[vf].flags & IGB_VF_FLAG_PF_SET_MAC))
  4484. random_ether_addr(vf_mac);
  4485. /* process remaining reset events */
  4486. igb_vf_reset(adapter, vf);
  4487. }
  4488. static void igb_vf_reset_msg(struct igb_adapter *adapter, u32 vf)
  4489. {
  4490. struct e1000_hw *hw = &adapter->hw;
  4491. unsigned char *vf_mac = adapter->vf_data[vf].vf_mac_addresses;
  4492. int rar_entry = hw->mac.rar_entry_count - (vf + 1);
  4493. u32 reg, msgbuf[3];
  4494. u8 *addr = (u8 *)(&msgbuf[1]);
  4495. /* process all the same items cleared in a function level reset */
  4496. igb_vf_reset(adapter, vf);
  4497. /* set vf mac address */
  4498. igb_rar_set_qsel(adapter, vf_mac, rar_entry, vf);
  4499. /* enable transmit and receive for vf */
  4500. reg = rd32(E1000_VFTE);
  4501. wr32(E1000_VFTE, reg | (1 << vf));
  4502. reg = rd32(E1000_VFRE);
  4503. wr32(E1000_VFRE, reg | (1 << vf));
  4504. adapter->vf_data[vf].flags |= IGB_VF_FLAG_CTS;
  4505. /* reply to reset with ack and vf mac address */
  4506. msgbuf[0] = E1000_VF_RESET | E1000_VT_MSGTYPE_ACK;
  4507. memcpy(addr, vf_mac, 6);
  4508. igb_write_mbx(hw, msgbuf, 3, vf);
  4509. }
  4510. static int igb_set_vf_mac_addr(struct igb_adapter *adapter, u32 *msg, int vf)
  4511. {
  4512. /*
  4513. * The VF MAC Address is stored in a packed array of bytes
  4514. * starting at the second 32 bit word of the msg array
  4515. */
  4516. unsigned char *addr = (char *)&msg[1];
  4517. int err = -1;
  4518. if (is_valid_ether_addr(addr))
  4519. err = igb_set_vf_mac(adapter, vf, addr);
  4520. return err;
  4521. }
  4522. static void igb_rcv_ack_from_vf(struct igb_adapter *adapter, u32 vf)
  4523. {
  4524. struct e1000_hw *hw = &adapter->hw;
  4525. struct vf_data_storage *vf_data = &adapter->vf_data[vf];
  4526. u32 msg = E1000_VT_MSGTYPE_NACK;
  4527. /* if device isn't clear to send it shouldn't be reading either */
  4528. if (!(vf_data->flags & IGB_VF_FLAG_CTS) &&
  4529. time_after(jiffies, vf_data->last_nack + (2 * HZ))) {
  4530. igb_write_mbx(hw, &msg, 1, vf);
  4531. vf_data->last_nack = jiffies;
  4532. }
  4533. }
  4534. static void igb_rcv_msg_from_vf(struct igb_adapter *adapter, u32 vf)
  4535. {
  4536. struct pci_dev *pdev = adapter->pdev;
  4537. u32 msgbuf[E1000_VFMAILBOX_SIZE];
  4538. struct e1000_hw *hw = &adapter->hw;
  4539. struct vf_data_storage *vf_data = &adapter->vf_data[vf];
  4540. s32 retval;
  4541. retval = igb_read_mbx(hw, msgbuf, E1000_VFMAILBOX_SIZE, vf);
  4542. if (retval) {
  4543. /* if receive failed revoke VF CTS stats and restart init */
  4544. dev_err(&pdev->dev, "Error receiving message from VF\n");
  4545. vf_data->flags &= ~IGB_VF_FLAG_CTS;
  4546. if (!time_after(jiffies, vf_data->last_nack + (2 * HZ)))
  4547. return;
  4548. goto out;
  4549. }
  4550. /* this is a message we already processed, do nothing */
  4551. if (msgbuf[0] & (E1000_VT_MSGTYPE_ACK | E1000_VT_MSGTYPE_NACK))
  4552. return;
  4553. /*
  4554. * until the vf completes a reset it should not be
  4555. * allowed to start any configuration.
  4556. */
  4557. if (msgbuf[0] == E1000_VF_RESET) {
  4558. igb_vf_reset_msg(adapter, vf);
  4559. return;
  4560. }
  4561. if (!(vf_data->flags & IGB_VF_FLAG_CTS)) {
  4562. if (!time_after(jiffies, vf_data->last_nack + (2 * HZ)))
  4563. return;
  4564. retval = -1;
  4565. goto out;
  4566. }
  4567. switch ((msgbuf[0] & 0xFFFF)) {
  4568. case E1000_VF_SET_MAC_ADDR:
  4569. retval = -EINVAL;
  4570. if (!(vf_data->flags & IGB_VF_FLAG_PF_SET_MAC))
  4571. retval = igb_set_vf_mac_addr(adapter, msgbuf, vf);
  4572. else
  4573. dev_warn(&pdev->dev,
  4574. "VF %d attempted to override administratively "
  4575. "set MAC address\nReload the VF driver to "
  4576. "resume operations\n", vf);
  4577. break;
  4578. case E1000_VF_SET_PROMISC:
  4579. retval = igb_set_vf_promisc(adapter, msgbuf, vf);
  4580. break;
  4581. case E1000_VF_SET_MULTICAST:
  4582. retval = igb_set_vf_multicasts(adapter, msgbuf, vf);
  4583. break;
  4584. case E1000_VF_SET_LPE:
  4585. retval = igb_set_vf_rlpml(adapter, msgbuf[1], vf);
  4586. break;
  4587. case E1000_VF_SET_VLAN:
  4588. retval = -1;
  4589. if (vf_data->pf_vlan)
  4590. dev_warn(&pdev->dev,
  4591. "VF %d attempted to override administratively "
  4592. "set VLAN tag\nReload the VF driver to "
  4593. "resume operations\n", vf);
  4594. else
  4595. retval = igb_set_vf_vlan(adapter, msgbuf, vf);
  4596. break;
  4597. default:
  4598. dev_err(&pdev->dev, "Unhandled Msg %08x\n", msgbuf[0]);
  4599. retval = -1;
  4600. break;
  4601. }
  4602. msgbuf[0] |= E1000_VT_MSGTYPE_CTS;
  4603. out:
  4604. /* notify the VF of the results of what it sent us */
  4605. if (retval)
  4606. msgbuf[0] |= E1000_VT_MSGTYPE_NACK;
  4607. else
  4608. msgbuf[0] |= E1000_VT_MSGTYPE_ACK;
  4609. igb_write_mbx(hw, msgbuf, 1, vf);
  4610. }
  4611. static void igb_msg_task(struct igb_adapter *adapter)
  4612. {
  4613. struct e1000_hw *hw = &adapter->hw;
  4614. u32 vf;
  4615. for (vf = 0; vf < adapter->vfs_allocated_count; vf++) {
  4616. /* process any reset requests */
  4617. if (!igb_check_for_rst(hw, vf))
  4618. igb_vf_reset_event(adapter, vf);
  4619. /* process any messages pending */
  4620. if (!igb_check_for_msg(hw, vf))
  4621. igb_rcv_msg_from_vf(adapter, vf);
  4622. /* process any acks */
  4623. if (!igb_check_for_ack(hw, vf))
  4624. igb_rcv_ack_from_vf(adapter, vf);
  4625. }
  4626. }
  4627. /**
  4628. * igb_set_uta - Set unicast filter table address
  4629. * @adapter: board private structure
  4630. *
  4631. * The unicast table address is a register array of 32-bit registers.
  4632. * The table is meant to be used in a way similar to how the MTA is used
  4633. * however due to certain limitations in the hardware it is necessary to
  4634. * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
  4635. * enable bit to allow vlan tag stripping when promiscuous mode is enabled
  4636. **/
  4637. static void igb_set_uta(struct igb_adapter *adapter)
  4638. {
  4639. struct e1000_hw *hw = &adapter->hw;
  4640. int i;
  4641. /* The UTA table only exists on 82576 hardware and newer */
  4642. if (hw->mac.type < e1000_82576)
  4643. return;
  4644. /* we only need to do this if VMDq is enabled */
  4645. if (!adapter->vfs_allocated_count)
  4646. return;
  4647. for (i = 0; i < hw->mac.uta_reg_count; i++)
  4648. array_wr32(E1000_UTA, i, ~0);
  4649. }
  4650. /**
  4651. * igb_intr_msi - Interrupt Handler
  4652. * @irq: interrupt number
  4653. * @data: pointer to a network interface device structure
  4654. **/
  4655. static irqreturn_t igb_intr_msi(int irq, void *data)
  4656. {
  4657. struct igb_adapter *adapter = data;
  4658. struct igb_q_vector *q_vector = adapter->q_vector[0];
  4659. struct e1000_hw *hw = &adapter->hw;
  4660. /* read ICR disables interrupts using IAM */
  4661. u32 icr = rd32(E1000_ICR);
  4662. igb_write_itr(q_vector);
  4663. if (icr & E1000_ICR_DRSTA)
  4664. schedule_work(&adapter->reset_task);
  4665. if (icr & E1000_ICR_DOUTSYNC) {
  4666. /* HW is reporting DMA is out of sync */
  4667. adapter->stats.doosync++;
  4668. }
  4669. if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
  4670. hw->mac.get_link_status = 1;
  4671. if (!test_bit(__IGB_DOWN, &adapter->state))
  4672. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  4673. }
  4674. napi_schedule(&q_vector->napi);
  4675. return IRQ_HANDLED;
  4676. }
  4677. /**
  4678. * igb_intr - Legacy Interrupt Handler
  4679. * @irq: interrupt number
  4680. * @data: pointer to a network interface device structure
  4681. **/
  4682. static irqreturn_t igb_intr(int irq, void *data)
  4683. {
  4684. struct igb_adapter *adapter = data;
  4685. struct igb_q_vector *q_vector = adapter->q_vector[0];
  4686. struct e1000_hw *hw = &adapter->hw;
  4687. /* Interrupt Auto-Mask...upon reading ICR, interrupts are masked. No
  4688. * need for the IMC write */
  4689. u32 icr = rd32(E1000_ICR);
  4690. if (!icr)
  4691. return IRQ_NONE; /* Not our interrupt */
  4692. igb_write_itr(q_vector);
  4693. /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
  4694. * not set, then the adapter didn't send an interrupt */
  4695. if (!(icr & E1000_ICR_INT_ASSERTED))
  4696. return IRQ_NONE;
  4697. if (icr & E1000_ICR_DRSTA)
  4698. schedule_work(&adapter->reset_task);
  4699. if (icr & E1000_ICR_DOUTSYNC) {
  4700. /* HW is reporting DMA is out of sync */
  4701. adapter->stats.doosync++;
  4702. }
  4703. if (icr & (E1000_ICR_RXSEQ | E1000_ICR_LSC)) {
  4704. hw->mac.get_link_status = 1;
  4705. /* guard against interrupt when we're going down */
  4706. if (!test_bit(__IGB_DOWN, &adapter->state))
  4707. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  4708. }
  4709. napi_schedule(&q_vector->napi);
  4710. return IRQ_HANDLED;
  4711. }
  4712. static inline void igb_ring_irq_enable(struct igb_q_vector *q_vector)
  4713. {
  4714. struct igb_adapter *adapter = q_vector->adapter;
  4715. struct e1000_hw *hw = &adapter->hw;
  4716. if ((q_vector->rx_ring && (adapter->rx_itr_setting & 3)) ||
  4717. (!q_vector->rx_ring && (adapter->tx_itr_setting & 3))) {
  4718. if (!adapter->msix_entries)
  4719. igb_set_itr(adapter);
  4720. else
  4721. igb_update_ring_itr(q_vector);
  4722. }
  4723. if (!test_bit(__IGB_DOWN, &adapter->state)) {
  4724. if (adapter->msix_entries)
  4725. wr32(E1000_EIMS, q_vector->eims_value);
  4726. else
  4727. igb_irq_enable(adapter);
  4728. }
  4729. }
  4730. /**
  4731. * igb_poll - NAPI Rx polling callback
  4732. * @napi: napi polling structure
  4733. * @budget: count of how many packets we should handle
  4734. **/
  4735. static int igb_poll(struct napi_struct *napi, int budget)
  4736. {
  4737. struct igb_q_vector *q_vector = container_of(napi,
  4738. struct igb_q_vector,
  4739. napi);
  4740. int tx_clean_complete = 1, work_done = 0;
  4741. #ifdef CONFIG_IGB_DCA
  4742. if (q_vector->adapter->flags & IGB_FLAG_DCA_ENABLED)
  4743. igb_update_dca(q_vector);
  4744. #endif
  4745. if (q_vector->tx_ring)
  4746. tx_clean_complete = igb_clean_tx_irq(q_vector);
  4747. if (q_vector->rx_ring)
  4748. igb_clean_rx_irq_adv(q_vector, &work_done, budget);
  4749. if (!tx_clean_complete)
  4750. work_done = budget;
  4751. /* If not enough Rx work done, exit the polling mode */
  4752. if (work_done < budget) {
  4753. napi_complete(napi);
  4754. igb_ring_irq_enable(q_vector);
  4755. }
  4756. return work_done;
  4757. }
  4758. /**
  4759. * igb_systim_to_hwtstamp - convert system time value to hw timestamp
  4760. * @adapter: board private structure
  4761. * @shhwtstamps: timestamp structure to update
  4762. * @regval: unsigned 64bit system time value.
  4763. *
  4764. * We need to convert the system time value stored in the RX/TXSTMP registers
  4765. * into a hwtstamp which can be used by the upper level timestamping functions
  4766. */
  4767. static void igb_systim_to_hwtstamp(struct igb_adapter *adapter,
  4768. struct skb_shared_hwtstamps *shhwtstamps,
  4769. u64 regval)
  4770. {
  4771. u64 ns;
  4772. /*
  4773. * The 82580 starts with 1ns at bit 0 in RX/TXSTMPL, shift this up to
  4774. * 24 to match clock shift we setup earlier.
  4775. */
  4776. if (adapter->hw.mac.type == e1000_82580)
  4777. regval <<= IGB_82580_TSYNC_SHIFT;
  4778. ns = timecounter_cyc2time(&adapter->clock, regval);
  4779. timecompare_update(&adapter->compare, ns);
  4780. memset(shhwtstamps, 0, sizeof(struct skb_shared_hwtstamps));
  4781. shhwtstamps->hwtstamp = ns_to_ktime(ns);
  4782. shhwtstamps->syststamp = timecompare_transform(&adapter->compare, ns);
  4783. }
  4784. /**
  4785. * igb_tx_hwtstamp - utility function which checks for TX time stamp
  4786. * @q_vector: pointer to q_vector containing needed info
  4787. * @buffer: pointer to igb_buffer structure
  4788. *
  4789. * If we were asked to do hardware stamping and such a time stamp is
  4790. * available, then it must have been for this skb here because we only
  4791. * allow only one such packet into the queue.
  4792. */
  4793. static void igb_tx_hwtstamp(struct igb_q_vector *q_vector, struct igb_buffer *buffer_info)
  4794. {
  4795. struct igb_adapter *adapter = q_vector->adapter;
  4796. struct e1000_hw *hw = &adapter->hw;
  4797. struct skb_shared_hwtstamps shhwtstamps;
  4798. u64 regval;
  4799. /* if skb does not support hw timestamp or TX stamp not valid exit */
  4800. if (likely(!(buffer_info->tx_flags & SKBTX_HW_TSTAMP)) ||
  4801. !(rd32(E1000_TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID))
  4802. return;
  4803. regval = rd32(E1000_TXSTMPL);
  4804. regval |= (u64)rd32(E1000_TXSTMPH) << 32;
  4805. igb_systim_to_hwtstamp(adapter, &shhwtstamps, regval);
  4806. skb_tstamp_tx(buffer_info->skb, &shhwtstamps);
  4807. }
  4808. /**
  4809. * igb_clean_tx_irq - Reclaim resources after transmit completes
  4810. * @q_vector: pointer to q_vector containing needed info
  4811. * returns true if ring is completely cleaned
  4812. **/
  4813. static bool igb_clean_tx_irq(struct igb_q_vector *q_vector)
  4814. {
  4815. struct igb_adapter *adapter = q_vector->adapter;
  4816. struct igb_ring *tx_ring = q_vector->tx_ring;
  4817. struct net_device *netdev = tx_ring->netdev;
  4818. struct e1000_hw *hw = &adapter->hw;
  4819. struct igb_buffer *buffer_info;
  4820. union e1000_adv_tx_desc *tx_desc, *eop_desc;
  4821. unsigned int total_bytes = 0, total_packets = 0;
  4822. unsigned int i, eop, count = 0;
  4823. bool cleaned = false;
  4824. i = tx_ring->next_to_clean;
  4825. eop = tx_ring->buffer_info[i].next_to_watch;
  4826. eop_desc = E1000_TX_DESC_ADV(*tx_ring, eop);
  4827. while ((eop_desc->wb.status & cpu_to_le32(E1000_TXD_STAT_DD)) &&
  4828. (count < tx_ring->count)) {
  4829. rmb(); /* read buffer_info after eop_desc status */
  4830. for (cleaned = false; !cleaned; count++) {
  4831. tx_desc = E1000_TX_DESC_ADV(*tx_ring, i);
  4832. buffer_info = &tx_ring->buffer_info[i];
  4833. cleaned = (i == eop);
  4834. if (buffer_info->skb) {
  4835. total_bytes += buffer_info->bytecount;
  4836. /* gso_segs is currently only valid for tcp */
  4837. total_packets += buffer_info->gso_segs;
  4838. igb_tx_hwtstamp(q_vector, buffer_info);
  4839. }
  4840. igb_unmap_and_free_tx_resource(tx_ring, buffer_info);
  4841. tx_desc->wb.status = 0;
  4842. i++;
  4843. if (i == tx_ring->count)
  4844. i = 0;
  4845. }
  4846. eop = tx_ring->buffer_info[i].next_to_watch;
  4847. eop_desc = E1000_TX_DESC_ADV(*tx_ring, eop);
  4848. }
  4849. tx_ring->next_to_clean = i;
  4850. if (unlikely(count &&
  4851. netif_carrier_ok(netdev) &&
  4852. igb_desc_unused(tx_ring) >= IGB_TX_QUEUE_WAKE)) {
  4853. /* Make sure that anybody stopping the queue after this
  4854. * sees the new next_to_clean.
  4855. */
  4856. smp_mb();
  4857. if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) &&
  4858. !(test_bit(__IGB_DOWN, &adapter->state))) {
  4859. netif_wake_subqueue(netdev, tx_ring->queue_index);
  4860. u64_stats_update_begin(&tx_ring->tx_syncp);
  4861. tx_ring->tx_stats.restart_queue++;
  4862. u64_stats_update_end(&tx_ring->tx_syncp);
  4863. }
  4864. }
  4865. if (tx_ring->detect_tx_hung) {
  4866. /* Detect a transmit hang in hardware, this serializes the
  4867. * check with the clearing of time_stamp and movement of i */
  4868. tx_ring->detect_tx_hung = false;
  4869. if (tx_ring->buffer_info[i].time_stamp &&
  4870. time_after(jiffies, tx_ring->buffer_info[i].time_stamp +
  4871. (adapter->tx_timeout_factor * HZ)) &&
  4872. !(rd32(E1000_STATUS) & E1000_STATUS_TXOFF)) {
  4873. /* detected Tx unit hang */
  4874. dev_err(tx_ring->dev,
  4875. "Detected Tx Unit Hang\n"
  4876. " Tx Queue <%d>\n"
  4877. " TDH <%x>\n"
  4878. " TDT <%x>\n"
  4879. " next_to_use <%x>\n"
  4880. " next_to_clean <%x>\n"
  4881. "buffer_info[next_to_clean]\n"
  4882. " time_stamp <%lx>\n"
  4883. " next_to_watch <%x>\n"
  4884. " jiffies <%lx>\n"
  4885. " desc.status <%x>\n",
  4886. tx_ring->queue_index,
  4887. readl(tx_ring->head),
  4888. readl(tx_ring->tail),
  4889. tx_ring->next_to_use,
  4890. tx_ring->next_to_clean,
  4891. tx_ring->buffer_info[eop].time_stamp,
  4892. eop,
  4893. jiffies,
  4894. eop_desc->wb.status);
  4895. netif_stop_subqueue(netdev, tx_ring->queue_index);
  4896. }
  4897. }
  4898. tx_ring->total_bytes += total_bytes;
  4899. tx_ring->total_packets += total_packets;
  4900. u64_stats_update_begin(&tx_ring->tx_syncp);
  4901. tx_ring->tx_stats.bytes += total_bytes;
  4902. tx_ring->tx_stats.packets += total_packets;
  4903. u64_stats_update_end(&tx_ring->tx_syncp);
  4904. return count < tx_ring->count;
  4905. }
  4906. static inline void igb_rx_checksum_adv(struct igb_ring *ring,
  4907. u32 status_err, struct sk_buff *skb)
  4908. {
  4909. skb_checksum_none_assert(skb);
  4910. /* Ignore Checksum bit is set or checksum is disabled through ethtool */
  4911. if (!(ring->flags & IGB_RING_FLAG_RX_CSUM) ||
  4912. (status_err & E1000_RXD_STAT_IXSM))
  4913. return;
  4914. /* TCP/UDP checksum error bit is set */
  4915. if (status_err &
  4916. (E1000_RXDEXT_STATERR_TCPE | E1000_RXDEXT_STATERR_IPE)) {
  4917. /*
  4918. * work around errata with sctp packets where the TCPE aka
  4919. * L4E bit is set incorrectly on 64 byte (60 byte w/o crc)
  4920. * packets, (aka let the stack check the crc32c)
  4921. */
  4922. if ((skb->len == 60) &&
  4923. (ring->flags & IGB_RING_FLAG_RX_SCTP_CSUM)) {
  4924. u64_stats_update_begin(&ring->rx_syncp);
  4925. ring->rx_stats.csum_err++;
  4926. u64_stats_update_end(&ring->rx_syncp);
  4927. }
  4928. /* let the stack verify checksum errors */
  4929. return;
  4930. }
  4931. /* It must be a TCP or UDP packet with a valid checksum */
  4932. if (status_err & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS))
  4933. skb->ip_summed = CHECKSUM_UNNECESSARY;
  4934. dev_dbg(ring->dev, "cksum success: bits %08X\n", status_err);
  4935. }
  4936. static void igb_rx_hwtstamp(struct igb_q_vector *q_vector, u32 staterr,
  4937. struct sk_buff *skb)
  4938. {
  4939. struct igb_adapter *adapter = q_vector->adapter;
  4940. struct e1000_hw *hw = &adapter->hw;
  4941. u64 regval;
  4942. /*
  4943. * If this bit is set, then the RX registers contain the time stamp. No
  4944. * other packet will be time stamped until we read these registers, so
  4945. * read the registers to make them available again. Because only one
  4946. * packet can be time stamped at a time, we know that the register
  4947. * values must belong to this one here and therefore we don't need to
  4948. * compare any of the additional attributes stored for it.
  4949. *
  4950. * If nothing went wrong, then it should have a shared tx_flags that we
  4951. * can turn into a skb_shared_hwtstamps.
  4952. */
  4953. if (staterr & E1000_RXDADV_STAT_TSIP) {
  4954. u32 *stamp = (u32 *)skb->data;
  4955. regval = le32_to_cpu(*(stamp + 2));
  4956. regval |= (u64)le32_to_cpu(*(stamp + 3)) << 32;
  4957. skb_pull(skb, IGB_TS_HDR_LEN);
  4958. } else {
  4959. if(!(rd32(E1000_TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID))
  4960. return;
  4961. regval = rd32(E1000_RXSTMPL);
  4962. regval |= (u64)rd32(E1000_RXSTMPH) << 32;
  4963. }
  4964. igb_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), regval);
  4965. }
  4966. static inline u16 igb_get_hlen(struct igb_ring *rx_ring,
  4967. union e1000_adv_rx_desc *rx_desc)
  4968. {
  4969. /* HW will not DMA in data larger than the given buffer, even if it
  4970. * parses the (NFS, of course) header to be larger. In that case, it
  4971. * fills the header buffer and spills the rest into the page.
  4972. */
  4973. u16 hlen = (le16_to_cpu(rx_desc->wb.lower.lo_dword.hdr_info) &
  4974. E1000_RXDADV_HDRBUFLEN_MASK) >> E1000_RXDADV_HDRBUFLEN_SHIFT;
  4975. if (hlen > rx_ring->rx_buffer_len)
  4976. hlen = rx_ring->rx_buffer_len;
  4977. return hlen;
  4978. }
  4979. static bool igb_clean_rx_irq_adv(struct igb_q_vector *q_vector,
  4980. int *work_done, int budget)
  4981. {
  4982. struct igb_ring *rx_ring = q_vector->rx_ring;
  4983. struct net_device *netdev = rx_ring->netdev;
  4984. struct device *dev = rx_ring->dev;
  4985. union e1000_adv_rx_desc *rx_desc , *next_rxd;
  4986. struct igb_buffer *buffer_info , *next_buffer;
  4987. struct sk_buff *skb;
  4988. bool cleaned = false;
  4989. int cleaned_count = 0;
  4990. int current_node = numa_node_id();
  4991. unsigned int total_bytes = 0, total_packets = 0;
  4992. unsigned int i;
  4993. u32 staterr;
  4994. u16 length;
  4995. i = rx_ring->next_to_clean;
  4996. buffer_info = &rx_ring->buffer_info[i];
  4997. rx_desc = E1000_RX_DESC_ADV(*rx_ring, i);
  4998. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  4999. while (staterr & E1000_RXD_STAT_DD) {
  5000. if (*work_done >= budget)
  5001. break;
  5002. (*work_done)++;
  5003. rmb(); /* read descriptor and rx_buffer_info after status DD */
  5004. skb = buffer_info->skb;
  5005. prefetch(skb->data - NET_IP_ALIGN);
  5006. buffer_info->skb = NULL;
  5007. i++;
  5008. if (i == rx_ring->count)
  5009. i = 0;
  5010. next_rxd = E1000_RX_DESC_ADV(*rx_ring, i);
  5011. prefetch(next_rxd);
  5012. next_buffer = &rx_ring->buffer_info[i];
  5013. length = le16_to_cpu(rx_desc->wb.upper.length);
  5014. cleaned = true;
  5015. cleaned_count++;
  5016. if (buffer_info->dma) {
  5017. dma_unmap_single(dev, buffer_info->dma,
  5018. rx_ring->rx_buffer_len,
  5019. DMA_FROM_DEVICE);
  5020. buffer_info->dma = 0;
  5021. if (rx_ring->rx_buffer_len >= IGB_RXBUFFER_1024) {
  5022. skb_put(skb, length);
  5023. goto send_up;
  5024. }
  5025. skb_put(skb, igb_get_hlen(rx_ring, rx_desc));
  5026. }
  5027. if (length) {
  5028. dma_unmap_page(dev, buffer_info->page_dma,
  5029. PAGE_SIZE / 2, DMA_FROM_DEVICE);
  5030. buffer_info->page_dma = 0;
  5031. skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
  5032. buffer_info->page,
  5033. buffer_info->page_offset,
  5034. length);
  5035. if ((page_count(buffer_info->page) != 1) ||
  5036. (page_to_nid(buffer_info->page) != current_node))
  5037. buffer_info->page = NULL;
  5038. else
  5039. get_page(buffer_info->page);
  5040. skb->len += length;
  5041. skb->data_len += length;
  5042. skb->truesize += length;
  5043. }
  5044. if (!(staterr & E1000_RXD_STAT_EOP)) {
  5045. buffer_info->skb = next_buffer->skb;
  5046. buffer_info->dma = next_buffer->dma;
  5047. next_buffer->skb = skb;
  5048. next_buffer->dma = 0;
  5049. goto next_desc;
  5050. }
  5051. send_up:
  5052. if (staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) {
  5053. dev_kfree_skb_irq(skb);
  5054. goto next_desc;
  5055. }
  5056. if (staterr & (E1000_RXDADV_STAT_TSIP | E1000_RXDADV_STAT_TS))
  5057. igb_rx_hwtstamp(q_vector, staterr, skb);
  5058. total_bytes += skb->len;
  5059. total_packets++;
  5060. igb_rx_checksum_adv(rx_ring, staterr, skb);
  5061. skb->protocol = eth_type_trans(skb, netdev);
  5062. skb_record_rx_queue(skb, rx_ring->queue_index);
  5063. if (staterr & E1000_RXD_STAT_VP) {
  5064. u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
  5065. __vlan_hwaccel_put_tag(skb, vid);
  5066. }
  5067. napi_gro_receive(&q_vector->napi, skb);
  5068. next_desc:
  5069. rx_desc->wb.upper.status_error = 0;
  5070. /* return some buffers to hardware, one at a time is too slow */
  5071. if (cleaned_count >= IGB_RX_BUFFER_WRITE) {
  5072. igb_alloc_rx_buffers_adv(rx_ring, cleaned_count);
  5073. cleaned_count = 0;
  5074. }
  5075. /* use prefetched values */
  5076. rx_desc = next_rxd;
  5077. buffer_info = next_buffer;
  5078. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  5079. }
  5080. rx_ring->next_to_clean = i;
  5081. cleaned_count = igb_desc_unused(rx_ring);
  5082. if (cleaned_count)
  5083. igb_alloc_rx_buffers_adv(rx_ring, cleaned_count);
  5084. rx_ring->total_packets += total_packets;
  5085. rx_ring->total_bytes += total_bytes;
  5086. u64_stats_update_begin(&rx_ring->rx_syncp);
  5087. rx_ring->rx_stats.packets += total_packets;
  5088. rx_ring->rx_stats.bytes += total_bytes;
  5089. u64_stats_update_end(&rx_ring->rx_syncp);
  5090. return cleaned;
  5091. }
  5092. /**
  5093. * igb_alloc_rx_buffers_adv - Replace used receive buffers; packet split
  5094. * @adapter: address of board private structure
  5095. **/
  5096. void igb_alloc_rx_buffers_adv(struct igb_ring *rx_ring, int cleaned_count)
  5097. {
  5098. struct net_device *netdev = rx_ring->netdev;
  5099. union e1000_adv_rx_desc *rx_desc;
  5100. struct igb_buffer *buffer_info;
  5101. struct sk_buff *skb;
  5102. unsigned int i;
  5103. int bufsz;
  5104. i = rx_ring->next_to_use;
  5105. buffer_info = &rx_ring->buffer_info[i];
  5106. bufsz = rx_ring->rx_buffer_len;
  5107. while (cleaned_count--) {
  5108. rx_desc = E1000_RX_DESC_ADV(*rx_ring, i);
  5109. if ((bufsz < IGB_RXBUFFER_1024) && !buffer_info->page_dma) {
  5110. if (!buffer_info->page) {
  5111. buffer_info->page = netdev_alloc_page(netdev);
  5112. if (unlikely(!buffer_info->page)) {
  5113. u64_stats_update_begin(&rx_ring->rx_syncp);
  5114. rx_ring->rx_stats.alloc_failed++;
  5115. u64_stats_update_end(&rx_ring->rx_syncp);
  5116. goto no_buffers;
  5117. }
  5118. buffer_info->page_offset = 0;
  5119. } else {
  5120. buffer_info->page_offset ^= PAGE_SIZE / 2;
  5121. }
  5122. buffer_info->page_dma =
  5123. dma_map_page(rx_ring->dev, buffer_info->page,
  5124. buffer_info->page_offset,
  5125. PAGE_SIZE / 2,
  5126. DMA_FROM_DEVICE);
  5127. if (dma_mapping_error(rx_ring->dev,
  5128. buffer_info->page_dma)) {
  5129. buffer_info->page_dma = 0;
  5130. u64_stats_update_begin(&rx_ring->rx_syncp);
  5131. rx_ring->rx_stats.alloc_failed++;
  5132. u64_stats_update_end(&rx_ring->rx_syncp);
  5133. goto no_buffers;
  5134. }
  5135. }
  5136. skb = buffer_info->skb;
  5137. if (!skb) {
  5138. skb = netdev_alloc_skb_ip_align(netdev, bufsz);
  5139. if (unlikely(!skb)) {
  5140. u64_stats_update_begin(&rx_ring->rx_syncp);
  5141. rx_ring->rx_stats.alloc_failed++;
  5142. u64_stats_update_end(&rx_ring->rx_syncp);
  5143. goto no_buffers;
  5144. }
  5145. buffer_info->skb = skb;
  5146. }
  5147. if (!buffer_info->dma) {
  5148. buffer_info->dma = dma_map_single(rx_ring->dev,
  5149. skb->data,
  5150. bufsz,
  5151. DMA_FROM_DEVICE);
  5152. if (dma_mapping_error(rx_ring->dev,
  5153. buffer_info->dma)) {
  5154. buffer_info->dma = 0;
  5155. u64_stats_update_begin(&rx_ring->rx_syncp);
  5156. rx_ring->rx_stats.alloc_failed++;
  5157. u64_stats_update_end(&rx_ring->rx_syncp);
  5158. goto no_buffers;
  5159. }
  5160. }
  5161. /* Refresh the desc even if buffer_addrs didn't change because
  5162. * each write-back erases this info. */
  5163. if (bufsz < IGB_RXBUFFER_1024) {
  5164. rx_desc->read.pkt_addr =
  5165. cpu_to_le64(buffer_info->page_dma);
  5166. rx_desc->read.hdr_addr = cpu_to_le64(buffer_info->dma);
  5167. } else {
  5168. rx_desc->read.pkt_addr = cpu_to_le64(buffer_info->dma);
  5169. rx_desc->read.hdr_addr = 0;
  5170. }
  5171. i++;
  5172. if (i == rx_ring->count)
  5173. i = 0;
  5174. buffer_info = &rx_ring->buffer_info[i];
  5175. }
  5176. no_buffers:
  5177. if (rx_ring->next_to_use != i) {
  5178. rx_ring->next_to_use = i;
  5179. if (i == 0)
  5180. i = (rx_ring->count - 1);
  5181. else
  5182. i--;
  5183. /* Force memory writes to complete before letting h/w
  5184. * know there are new descriptors to fetch. (Only
  5185. * applicable for weak-ordered memory model archs,
  5186. * such as IA-64). */
  5187. wmb();
  5188. writel(i, rx_ring->tail);
  5189. }
  5190. }
  5191. /**
  5192. * igb_mii_ioctl -
  5193. * @netdev:
  5194. * @ifreq:
  5195. * @cmd:
  5196. **/
  5197. static int igb_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  5198. {
  5199. struct igb_adapter *adapter = netdev_priv(netdev);
  5200. struct mii_ioctl_data *data = if_mii(ifr);
  5201. if (adapter->hw.phy.media_type != e1000_media_type_copper)
  5202. return -EOPNOTSUPP;
  5203. switch (cmd) {
  5204. case SIOCGMIIPHY:
  5205. data->phy_id = adapter->hw.phy.addr;
  5206. break;
  5207. case SIOCGMIIREG:
  5208. if (igb_read_phy_reg(&adapter->hw, data->reg_num & 0x1F,
  5209. &data->val_out))
  5210. return -EIO;
  5211. break;
  5212. case SIOCSMIIREG:
  5213. default:
  5214. return -EOPNOTSUPP;
  5215. }
  5216. return 0;
  5217. }
  5218. /**
  5219. * igb_hwtstamp_ioctl - control hardware time stamping
  5220. * @netdev:
  5221. * @ifreq:
  5222. * @cmd:
  5223. *
  5224. * Outgoing time stamping can be enabled and disabled. Play nice and
  5225. * disable it when requested, although it shouldn't case any overhead
  5226. * when no packet needs it. At most one packet in the queue may be
  5227. * marked for time stamping, otherwise it would be impossible to tell
  5228. * for sure to which packet the hardware time stamp belongs.
  5229. *
  5230. * Incoming time stamping has to be configured via the hardware
  5231. * filters. Not all combinations are supported, in particular event
  5232. * type has to be specified. Matching the kind of event packet is
  5233. * not supported, with the exception of "all V2 events regardless of
  5234. * level 2 or 4".
  5235. *
  5236. **/
  5237. static int igb_hwtstamp_ioctl(struct net_device *netdev,
  5238. struct ifreq *ifr, int cmd)
  5239. {
  5240. struct igb_adapter *adapter = netdev_priv(netdev);
  5241. struct e1000_hw *hw = &adapter->hw;
  5242. struct hwtstamp_config config;
  5243. u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
  5244. u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
  5245. u32 tsync_rx_cfg = 0;
  5246. bool is_l4 = false;
  5247. bool is_l2 = false;
  5248. u32 regval;
  5249. if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
  5250. return -EFAULT;
  5251. /* reserved for future extensions */
  5252. if (config.flags)
  5253. return -EINVAL;
  5254. switch (config.tx_type) {
  5255. case HWTSTAMP_TX_OFF:
  5256. tsync_tx_ctl = 0;
  5257. case HWTSTAMP_TX_ON:
  5258. break;
  5259. default:
  5260. return -ERANGE;
  5261. }
  5262. switch (config.rx_filter) {
  5263. case HWTSTAMP_FILTER_NONE:
  5264. tsync_rx_ctl = 0;
  5265. break;
  5266. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  5267. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  5268. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  5269. case HWTSTAMP_FILTER_ALL:
  5270. /*
  5271. * register TSYNCRXCFG must be set, therefore it is not
  5272. * possible to time stamp both Sync and Delay_Req messages
  5273. * => fall back to time stamping all packets
  5274. */
  5275. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
  5276. config.rx_filter = HWTSTAMP_FILTER_ALL;
  5277. break;
  5278. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  5279. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
  5280. tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_SYNC_MESSAGE;
  5281. is_l4 = true;
  5282. break;
  5283. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  5284. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
  5285. tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V1_DELAY_REQ_MESSAGE;
  5286. is_l4 = true;
  5287. break;
  5288. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  5289. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  5290. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
  5291. tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V2_SYNC_MESSAGE;
  5292. is_l2 = true;
  5293. is_l4 = true;
  5294. config.rx_filter = HWTSTAMP_FILTER_SOME;
  5295. break;
  5296. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  5297. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  5298. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
  5299. tsync_rx_cfg = E1000_TSYNCRXCFG_PTP_V2_DELAY_REQ_MESSAGE;
  5300. is_l2 = true;
  5301. is_l4 = true;
  5302. config.rx_filter = HWTSTAMP_FILTER_SOME;
  5303. break;
  5304. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  5305. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  5306. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  5307. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
  5308. config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
  5309. is_l2 = true;
  5310. break;
  5311. default:
  5312. return -ERANGE;
  5313. }
  5314. if (hw->mac.type == e1000_82575) {
  5315. if (tsync_rx_ctl | tsync_tx_ctl)
  5316. return -EINVAL;
  5317. return 0;
  5318. }
  5319. /*
  5320. * Per-packet timestamping only works if all packets are
  5321. * timestamped, so enable timestamping in all packets as
  5322. * long as one rx filter was configured.
  5323. */
  5324. if ((hw->mac.type == e1000_82580) && tsync_rx_ctl) {
  5325. tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
  5326. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
  5327. }
  5328. /* enable/disable TX */
  5329. regval = rd32(E1000_TSYNCTXCTL);
  5330. regval &= ~E1000_TSYNCTXCTL_ENABLED;
  5331. regval |= tsync_tx_ctl;
  5332. wr32(E1000_TSYNCTXCTL, regval);
  5333. /* enable/disable RX */
  5334. regval = rd32(E1000_TSYNCRXCTL);
  5335. regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
  5336. regval |= tsync_rx_ctl;
  5337. wr32(E1000_TSYNCRXCTL, regval);
  5338. /* define which PTP packets are time stamped */
  5339. wr32(E1000_TSYNCRXCFG, tsync_rx_cfg);
  5340. /* define ethertype filter for timestamped packets */
  5341. if (is_l2)
  5342. wr32(E1000_ETQF(3),
  5343. (E1000_ETQF_FILTER_ENABLE | /* enable filter */
  5344. E1000_ETQF_1588 | /* enable timestamping */
  5345. ETH_P_1588)); /* 1588 eth protocol type */
  5346. else
  5347. wr32(E1000_ETQF(3), 0);
  5348. #define PTP_PORT 319
  5349. /* L4 Queue Filter[3]: filter by destination port and protocol */
  5350. if (is_l4) {
  5351. u32 ftqf = (IPPROTO_UDP /* UDP */
  5352. | E1000_FTQF_VF_BP /* VF not compared */
  5353. | E1000_FTQF_1588_TIME_STAMP /* Enable Timestamping */
  5354. | E1000_FTQF_MASK); /* mask all inputs */
  5355. ftqf &= ~E1000_FTQF_MASK_PROTO_BP; /* enable protocol check */
  5356. wr32(E1000_IMIR(3), htons(PTP_PORT));
  5357. wr32(E1000_IMIREXT(3),
  5358. (E1000_IMIREXT_SIZE_BP | E1000_IMIREXT_CTRL_BP));
  5359. if (hw->mac.type == e1000_82576) {
  5360. /* enable source port check */
  5361. wr32(E1000_SPQF(3), htons(PTP_PORT));
  5362. ftqf &= ~E1000_FTQF_MASK_SOURCE_PORT_BP;
  5363. }
  5364. wr32(E1000_FTQF(3), ftqf);
  5365. } else {
  5366. wr32(E1000_FTQF(3), E1000_FTQF_MASK);
  5367. }
  5368. wrfl();
  5369. adapter->hwtstamp_config = config;
  5370. /* clear TX/RX time stamp registers, just to be sure */
  5371. regval = rd32(E1000_TXSTMPH);
  5372. regval = rd32(E1000_RXSTMPH);
  5373. return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
  5374. -EFAULT : 0;
  5375. }
  5376. /**
  5377. * igb_ioctl -
  5378. * @netdev:
  5379. * @ifreq:
  5380. * @cmd:
  5381. **/
  5382. static int igb_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  5383. {
  5384. switch (cmd) {
  5385. case SIOCGMIIPHY:
  5386. case SIOCGMIIREG:
  5387. case SIOCSMIIREG:
  5388. return igb_mii_ioctl(netdev, ifr, cmd);
  5389. case SIOCSHWTSTAMP:
  5390. return igb_hwtstamp_ioctl(netdev, ifr, cmd);
  5391. default:
  5392. return -EOPNOTSUPP;
  5393. }
  5394. }
  5395. s32 igb_read_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
  5396. {
  5397. struct igb_adapter *adapter = hw->back;
  5398. u16 cap_offset;
  5399. cap_offset = adapter->pdev->pcie_cap;
  5400. if (!cap_offset)
  5401. return -E1000_ERR_CONFIG;
  5402. pci_read_config_word(adapter->pdev, cap_offset + reg, value);
  5403. return 0;
  5404. }
  5405. s32 igb_write_pcie_cap_reg(struct e1000_hw *hw, u32 reg, u16 *value)
  5406. {
  5407. struct igb_adapter *adapter = hw->back;
  5408. u16 cap_offset;
  5409. cap_offset = adapter->pdev->pcie_cap;
  5410. if (!cap_offset)
  5411. return -E1000_ERR_CONFIG;
  5412. pci_write_config_word(adapter->pdev, cap_offset + reg, *value);
  5413. return 0;
  5414. }
  5415. static void igb_vlan_mode(struct net_device *netdev, u32 features)
  5416. {
  5417. struct igb_adapter *adapter = netdev_priv(netdev);
  5418. struct e1000_hw *hw = &adapter->hw;
  5419. u32 ctrl, rctl;
  5420. igb_irq_disable(adapter);
  5421. if (features & NETIF_F_HW_VLAN_RX) {
  5422. /* enable VLAN tag insert/strip */
  5423. ctrl = rd32(E1000_CTRL);
  5424. ctrl |= E1000_CTRL_VME;
  5425. wr32(E1000_CTRL, ctrl);
  5426. /* Disable CFI check */
  5427. rctl = rd32(E1000_RCTL);
  5428. rctl &= ~E1000_RCTL_CFIEN;
  5429. wr32(E1000_RCTL, rctl);
  5430. } else {
  5431. /* disable VLAN tag insert/strip */
  5432. ctrl = rd32(E1000_CTRL);
  5433. ctrl &= ~E1000_CTRL_VME;
  5434. wr32(E1000_CTRL, ctrl);
  5435. }
  5436. igb_rlpml_set(adapter);
  5437. if (!test_bit(__IGB_DOWN, &adapter->state))
  5438. igb_irq_enable(adapter);
  5439. }
  5440. static void igb_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
  5441. {
  5442. struct igb_adapter *adapter = netdev_priv(netdev);
  5443. struct e1000_hw *hw = &adapter->hw;
  5444. int pf_id = adapter->vfs_allocated_count;
  5445. /* attempt to add filter to vlvf array */
  5446. igb_vlvf_set(adapter, vid, true, pf_id);
  5447. /* add the filter since PF can receive vlans w/o entry in vlvf */
  5448. igb_vfta_set(hw, vid, true);
  5449. set_bit(vid, adapter->active_vlans);
  5450. }
  5451. static void igb_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
  5452. {
  5453. struct igb_adapter *adapter = netdev_priv(netdev);
  5454. struct e1000_hw *hw = &adapter->hw;
  5455. int pf_id = adapter->vfs_allocated_count;
  5456. s32 err;
  5457. igb_irq_disable(adapter);
  5458. if (!test_bit(__IGB_DOWN, &adapter->state))
  5459. igb_irq_enable(adapter);
  5460. /* remove vlan from VLVF table array */
  5461. err = igb_vlvf_set(adapter, vid, false, pf_id);
  5462. /* if vid was not present in VLVF just remove it from table */
  5463. if (err)
  5464. igb_vfta_set(hw, vid, false);
  5465. clear_bit(vid, adapter->active_vlans);
  5466. }
  5467. static void igb_restore_vlan(struct igb_adapter *adapter)
  5468. {
  5469. u16 vid;
  5470. for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
  5471. igb_vlan_rx_add_vid(adapter->netdev, vid);
  5472. }
  5473. int igb_set_spd_dplx(struct igb_adapter *adapter, u32 spd, u8 dplx)
  5474. {
  5475. struct pci_dev *pdev = adapter->pdev;
  5476. struct e1000_mac_info *mac = &adapter->hw.mac;
  5477. mac->autoneg = 0;
  5478. /* Make sure dplx is at most 1 bit and lsb of speed is not set
  5479. * for the switch() below to work */
  5480. if ((spd & 1) || (dplx & ~1))
  5481. goto err_inval;
  5482. /* Fiber NIC's only allow 1000 Gbps Full duplex */
  5483. if ((adapter->hw.phy.media_type == e1000_media_type_internal_serdes) &&
  5484. spd != SPEED_1000 &&
  5485. dplx != DUPLEX_FULL)
  5486. goto err_inval;
  5487. switch (spd + dplx) {
  5488. case SPEED_10 + DUPLEX_HALF:
  5489. mac->forced_speed_duplex = ADVERTISE_10_HALF;
  5490. break;
  5491. case SPEED_10 + DUPLEX_FULL:
  5492. mac->forced_speed_duplex = ADVERTISE_10_FULL;
  5493. break;
  5494. case SPEED_100 + DUPLEX_HALF:
  5495. mac->forced_speed_duplex = ADVERTISE_100_HALF;
  5496. break;
  5497. case SPEED_100 + DUPLEX_FULL:
  5498. mac->forced_speed_duplex = ADVERTISE_100_FULL;
  5499. break;
  5500. case SPEED_1000 + DUPLEX_FULL:
  5501. mac->autoneg = 1;
  5502. adapter->hw.phy.autoneg_advertised = ADVERTISE_1000_FULL;
  5503. break;
  5504. case SPEED_1000 + DUPLEX_HALF: /* not supported */
  5505. default:
  5506. goto err_inval;
  5507. }
  5508. return 0;
  5509. err_inval:
  5510. dev_err(&pdev->dev, "Unsupported Speed/Duplex configuration\n");
  5511. return -EINVAL;
  5512. }
  5513. static int __igb_shutdown(struct pci_dev *pdev, bool *enable_wake)
  5514. {
  5515. struct net_device *netdev = pci_get_drvdata(pdev);
  5516. struct igb_adapter *adapter = netdev_priv(netdev);
  5517. struct e1000_hw *hw = &adapter->hw;
  5518. u32 ctrl, rctl, status;
  5519. u32 wufc = adapter->wol;
  5520. #ifdef CONFIG_PM
  5521. int retval = 0;
  5522. #endif
  5523. netif_device_detach(netdev);
  5524. if (netif_running(netdev))
  5525. igb_close(netdev);
  5526. igb_clear_interrupt_scheme(adapter);
  5527. #ifdef CONFIG_PM
  5528. retval = pci_save_state(pdev);
  5529. if (retval)
  5530. return retval;
  5531. #endif
  5532. status = rd32(E1000_STATUS);
  5533. if (status & E1000_STATUS_LU)
  5534. wufc &= ~E1000_WUFC_LNKC;
  5535. if (wufc) {
  5536. igb_setup_rctl(adapter);
  5537. igb_set_rx_mode(netdev);
  5538. /* turn on all-multi mode if wake on multicast is enabled */
  5539. if (wufc & E1000_WUFC_MC) {
  5540. rctl = rd32(E1000_RCTL);
  5541. rctl |= E1000_RCTL_MPE;
  5542. wr32(E1000_RCTL, rctl);
  5543. }
  5544. ctrl = rd32(E1000_CTRL);
  5545. /* advertise wake from D3Cold */
  5546. #define E1000_CTRL_ADVD3WUC 0x00100000
  5547. /* phy power management enable */
  5548. #define E1000_CTRL_EN_PHY_PWR_MGMT 0x00200000
  5549. ctrl |= E1000_CTRL_ADVD3WUC;
  5550. wr32(E1000_CTRL, ctrl);
  5551. /* Allow time for pending master requests to run */
  5552. igb_disable_pcie_master(hw);
  5553. wr32(E1000_WUC, E1000_WUC_PME_EN);
  5554. wr32(E1000_WUFC, wufc);
  5555. } else {
  5556. wr32(E1000_WUC, 0);
  5557. wr32(E1000_WUFC, 0);
  5558. }
  5559. *enable_wake = wufc || adapter->en_mng_pt;
  5560. if (!*enable_wake)
  5561. igb_power_down_link(adapter);
  5562. else
  5563. igb_power_up_link(adapter);
  5564. /* Release control of h/w to f/w. If f/w is AMT enabled, this
  5565. * would have already happened in close and is redundant. */
  5566. igb_release_hw_control(adapter);
  5567. pci_disable_device(pdev);
  5568. return 0;
  5569. }
  5570. #ifdef CONFIG_PM
  5571. static int igb_suspend(struct pci_dev *pdev, pm_message_t state)
  5572. {
  5573. int retval;
  5574. bool wake;
  5575. retval = __igb_shutdown(pdev, &wake);
  5576. if (retval)
  5577. return retval;
  5578. if (wake) {
  5579. pci_prepare_to_sleep(pdev);
  5580. } else {
  5581. pci_wake_from_d3(pdev, false);
  5582. pci_set_power_state(pdev, PCI_D3hot);
  5583. }
  5584. return 0;
  5585. }
  5586. static int igb_resume(struct pci_dev *pdev)
  5587. {
  5588. struct net_device *netdev = pci_get_drvdata(pdev);
  5589. struct igb_adapter *adapter = netdev_priv(netdev);
  5590. struct e1000_hw *hw = &adapter->hw;
  5591. u32 err;
  5592. pci_set_power_state(pdev, PCI_D0);
  5593. pci_restore_state(pdev);
  5594. pci_save_state(pdev);
  5595. err = pci_enable_device_mem(pdev);
  5596. if (err) {
  5597. dev_err(&pdev->dev,
  5598. "igb: Cannot enable PCI device from suspend\n");
  5599. return err;
  5600. }
  5601. pci_set_master(pdev);
  5602. pci_enable_wake(pdev, PCI_D3hot, 0);
  5603. pci_enable_wake(pdev, PCI_D3cold, 0);
  5604. if (igb_init_interrupt_scheme(adapter)) {
  5605. dev_err(&pdev->dev, "Unable to allocate memory for queues\n");
  5606. return -ENOMEM;
  5607. }
  5608. igb_reset(adapter);
  5609. /* let the f/w know that the h/w is now under the control of the
  5610. * driver. */
  5611. igb_get_hw_control(adapter);
  5612. wr32(E1000_WUS, ~0);
  5613. if (netif_running(netdev)) {
  5614. err = igb_open(netdev);
  5615. if (err)
  5616. return err;
  5617. }
  5618. netif_device_attach(netdev);
  5619. return 0;
  5620. }
  5621. #endif
  5622. static void igb_shutdown(struct pci_dev *pdev)
  5623. {
  5624. bool wake;
  5625. __igb_shutdown(pdev, &wake);
  5626. if (system_state == SYSTEM_POWER_OFF) {
  5627. pci_wake_from_d3(pdev, wake);
  5628. pci_set_power_state(pdev, PCI_D3hot);
  5629. }
  5630. }
  5631. #ifdef CONFIG_NET_POLL_CONTROLLER
  5632. /*
  5633. * Polling 'interrupt' - used by things like netconsole to send skbs
  5634. * without having to re-enable interrupts. It's not called while
  5635. * the interrupt routine is executing.
  5636. */
  5637. static void igb_netpoll(struct net_device *netdev)
  5638. {
  5639. struct igb_adapter *adapter = netdev_priv(netdev);
  5640. struct e1000_hw *hw = &adapter->hw;
  5641. int i;
  5642. if (!adapter->msix_entries) {
  5643. struct igb_q_vector *q_vector = adapter->q_vector[0];
  5644. igb_irq_disable(adapter);
  5645. napi_schedule(&q_vector->napi);
  5646. return;
  5647. }
  5648. for (i = 0; i < adapter->num_q_vectors; i++) {
  5649. struct igb_q_vector *q_vector = adapter->q_vector[i];
  5650. wr32(E1000_EIMC, q_vector->eims_value);
  5651. napi_schedule(&q_vector->napi);
  5652. }
  5653. }
  5654. #endif /* CONFIG_NET_POLL_CONTROLLER */
  5655. /**
  5656. * igb_io_error_detected - called when PCI error is detected
  5657. * @pdev: Pointer to PCI device
  5658. * @state: The current pci connection state
  5659. *
  5660. * This function is called after a PCI bus error affecting
  5661. * this device has been detected.
  5662. */
  5663. static pci_ers_result_t igb_io_error_detected(struct pci_dev *pdev,
  5664. pci_channel_state_t state)
  5665. {
  5666. struct net_device *netdev = pci_get_drvdata(pdev);
  5667. struct igb_adapter *adapter = netdev_priv(netdev);
  5668. netif_device_detach(netdev);
  5669. if (state == pci_channel_io_perm_failure)
  5670. return PCI_ERS_RESULT_DISCONNECT;
  5671. if (netif_running(netdev))
  5672. igb_down(adapter);
  5673. pci_disable_device(pdev);
  5674. /* Request a slot slot reset. */
  5675. return PCI_ERS_RESULT_NEED_RESET;
  5676. }
  5677. /**
  5678. * igb_io_slot_reset - called after the pci bus has been reset.
  5679. * @pdev: Pointer to PCI device
  5680. *
  5681. * Restart the card from scratch, as if from a cold-boot. Implementation
  5682. * resembles the first-half of the igb_resume routine.
  5683. */
  5684. static pci_ers_result_t igb_io_slot_reset(struct pci_dev *pdev)
  5685. {
  5686. struct net_device *netdev = pci_get_drvdata(pdev);
  5687. struct igb_adapter *adapter = netdev_priv(netdev);
  5688. struct e1000_hw *hw = &adapter->hw;
  5689. pci_ers_result_t result;
  5690. int err;
  5691. if (pci_enable_device_mem(pdev)) {
  5692. dev_err(&pdev->dev,
  5693. "Cannot re-enable PCI device after reset.\n");
  5694. result = PCI_ERS_RESULT_DISCONNECT;
  5695. } else {
  5696. pci_set_master(pdev);
  5697. pci_restore_state(pdev);
  5698. pci_save_state(pdev);
  5699. pci_enable_wake(pdev, PCI_D3hot, 0);
  5700. pci_enable_wake(pdev, PCI_D3cold, 0);
  5701. igb_reset(adapter);
  5702. wr32(E1000_WUS, ~0);
  5703. result = PCI_ERS_RESULT_RECOVERED;
  5704. }
  5705. err = pci_cleanup_aer_uncorrect_error_status(pdev);
  5706. if (err) {
  5707. dev_err(&pdev->dev, "pci_cleanup_aer_uncorrect_error_status "
  5708. "failed 0x%0x\n", err);
  5709. /* non-fatal, continue */
  5710. }
  5711. return result;
  5712. }
  5713. /**
  5714. * igb_io_resume - called when traffic can start flowing again.
  5715. * @pdev: Pointer to PCI device
  5716. *
  5717. * This callback is called when the error recovery driver tells us that
  5718. * its OK to resume normal operation. Implementation resembles the
  5719. * second-half of the igb_resume routine.
  5720. */
  5721. static void igb_io_resume(struct pci_dev *pdev)
  5722. {
  5723. struct net_device *netdev = pci_get_drvdata(pdev);
  5724. struct igb_adapter *adapter = netdev_priv(netdev);
  5725. if (netif_running(netdev)) {
  5726. if (igb_up(adapter)) {
  5727. dev_err(&pdev->dev, "igb_up failed after reset\n");
  5728. return;
  5729. }
  5730. }
  5731. netif_device_attach(netdev);
  5732. /* let the f/w know that the h/w is now under the control of the
  5733. * driver. */
  5734. igb_get_hw_control(adapter);
  5735. }
  5736. static void igb_rar_set_qsel(struct igb_adapter *adapter, u8 *addr, u32 index,
  5737. u8 qsel)
  5738. {
  5739. u32 rar_low, rar_high;
  5740. struct e1000_hw *hw = &adapter->hw;
  5741. /* HW expects these in little endian so we reverse the byte order
  5742. * from network order (big endian) to little endian
  5743. */
  5744. rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) |
  5745. ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
  5746. rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
  5747. /* Indicate to hardware the Address is Valid. */
  5748. rar_high |= E1000_RAH_AV;
  5749. if (hw->mac.type == e1000_82575)
  5750. rar_high |= E1000_RAH_POOL_1 * qsel;
  5751. else
  5752. rar_high |= E1000_RAH_POOL_1 << qsel;
  5753. wr32(E1000_RAL(index), rar_low);
  5754. wrfl();
  5755. wr32(E1000_RAH(index), rar_high);
  5756. wrfl();
  5757. }
  5758. static int igb_set_vf_mac(struct igb_adapter *adapter,
  5759. int vf, unsigned char *mac_addr)
  5760. {
  5761. struct e1000_hw *hw = &adapter->hw;
  5762. /* VF MAC addresses start at end of receive addresses and moves
  5763. * torwards the first, as a result a collision should not be possible */
  5764. int rar_entry = hw->mac.rar_entry_count - (vf + 1);
  5765. memcpy(adapter->vf_data[vf].vf_mac_addresses, mac_addr, ETH_ALEN);
  5766. igb_rar_set_qsel(adapter, mac_addr, rar_entry, vf);
  5767. return 0;
  5768. }
  5769. static int igb_ndo_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
  5770. {
  5771. struct igb_adapter *adapter = netdev_priv(netdev);
  5772. if (!is_valid_ether_addr(mac) || (vf >= adapter->vfs_allocated_count))
  5773. return -EINVAL;
  5774. adapter->vf_data[vf].flags |= IGB_VF_FLAG_PF_SET_MAC;
  5775. dev_info(&adapter->pdev->dev, "setting MAC %pM on VF %d\n", mac, vf);
  5776. dev_info(&adapter->pdev->dev, "Reload the VF driver to make this"
  5777. " change effective.");
  5778. if (test_bit(__IGB_DOWN, &adapter->state)) {
  5779. dev_warn(&adapter->pdev->dev, "The VF MAC address has been set,"
  5780. " but the PF device is not up.\n");
  5781. dev_warn(&adapter->pdev->dev, "Bring the PF device up before"
  5782. " attempting to use the VF device.\n");
  5783. }
  5784. return igb_set_vf_mac(adapter, vf, mac);
  5785. }
  5786. static int igb_link_mbps(int internal_link_speed)
  5787. {
  5788. switch (internal_link_speed) {
  5789. case SPEED_100:
  5790. return 100;
  5791. case SPEED_1000:
  5792. return 1000;
  5793. default:
  5794. return 0;
  5795. }
  5796. }
  5797. static void igb_set_vf_rate_limit(struct e1000_hw *hw, int vf, int tx_rate,
  5798. int link_speed)
  5799. {
  5800. int rf_dec, rf_int;
  5801. u32 bcnrc_val;
  5802. if (tx_rate != 0) {
  5803. /* Calculate the rate factor values to set */
  5804. rf_int = link_speed / tx_rate;
  5805. rf_dec = (link_speed - (rf_int * tx_rate));
  5806. rf_dec = (rf_dec * (1<<E1000_RTTBCNRC_RF_INT_SHIFT)) / tx_rate;
  5807. bcnrc_val = E1000_RTTBCNRC_RS_ENA;
  5808. bcnrc_val |= ((rf_int<<E1000_RTTBCNRC_RF_INT_SHIFT) &
  5809. E1000_RTTBCNRC_RF_INT_MASK);
  5810. bcnrc_val |= (rf_dec & E1000_RTTBCNRC_RF_DEC_MASK);
  5811. } else {
  5812. bcnrc_val = 0;
  5813. }
  5814. wr32(E1000_RTTDQSEL, vf); /* vf X uses queue X */
  5815. wr32(E1000_RTTBCNRC, bcnrc_val);
  5816. }
  5817. static void igb_check_vf_rate_limit(struct igb_adapter *adapter)
  5818. {
  5819. int actual_link_speed, i;
  5820. bool reset_rate = false;
  5821. /* VF TX rate limit was not set or not supported */
  5822. if ((adapter->vf_rate_link_speed == 0) ||
  5823. (adapter->hw.mac.type != e1000_82576))
  5824. return;
  5825. actual_link_speed = igb_link_mbps(adapter->link_speed);
  5826. if (actual_link_speed != adapter->vf_rate_link_speed) {
  5827. reset_rate = true;
  5828. adapter->vf_rate_link_speed = 0;
  5829. dev_info(&adapter->pdev->dev,
  5830. "Link speed has been changed. VF Transmit "
  5831. "rate is disabled\n");
  5832. }
  5833. for (i = 0; i < adapter->vfs_allocated_count; i++) {
  5834. if (reset_rate)
  5835. adapter->vf_data[i].tx_rate = 0;
  5836. igb_set_vf_rate_limit(&adapter->hw, i,
  5837. adapter->vf_data[i].tx_rate,
  5838. actual_link_speed);
  5839. }
  5840. }
  5841. static int igb_ndo_set_vf_bw(struct net_device *netdev, int vf, int tx_rate)
  5842. {
  5843. struct igb_adapter *adapter = netdev_priv(netdev);
  5844. struct e1000_hw *hw = &adapter->hw;
  5845. int actual_link_speed;
  5846. if (hw->mac.type != e1000_82576)
  5847. return -EOPNOTSUPP;
  5848. actual_link_speed = igb_link_mbps(adapter->link_speed);
  5849. if ((vf >= adapter->vfs_allocated_count) ||
  5850. (!(rd32(E1000_STATUS) & E1000_STATUS_LU)) ||
  5851. (tx_rate < 0) || (tx_rate > actual_link_speed))
  5852. return -EINVAL;
  5853. adapter->vf_rate_link_speed = actual_link_speed;
  5854. adapter->vf_data[vf].tx_rate = (u16)tx_rate;
  5855. igb_set_vf_rate_limit(hw, vf, tx_rate, actual_link_speed);
  5856. return 0;
  5857. }
  5858. static int igb_ndo_get_vf_config(struct net_device *netdev,
  5859. int vf, struct ifla_vf_info *ivi)
  5860. {
  5861. struct igb_adapter *adapter = netdev_priv(netdev);
  5862. if (vf >= adapter->vfs_allocated_count)
  5863. return -EINVAL;
  5864. ivi->vf = vf;
  5865. memcpy(&ivi->mac, adapter->vf_data[vf].vf_mac_addresses, ETH_ALEN);
  5866. ivi->tx_rate = adapter->vf_data[vf].tx_rate;
  5867. ivi->vlan = adapter->vf_data[vf].pf_vlan;
  5868. ivi->qos = adapter->vf_data[vf].pf_qos;
  5869. return 0;
  5870. }
  5871. static void igb_vmm_control(struct igb_adapter *adapter)
  5872. {
  5873. struct e1000_hw *hw = &adapter->hw;
  5874. u32 reg;
  5875. switch (hw->mac.type) {
  5876. case e1000_82575:
  5877. default:
  5878. /* replication is not supported for 82575 */
  5879. return;
  5880. case e1000_82576:
  5881. /* notify HW that the MAC is adding vlan tags */
  5882. reg = rd32(E1000_DTXCTL);
  5883. reg |= E1000_DTXCTL_VLAN_ADDED;
  5884. wr32(E1000_DTXCTL, reg);
  5885. case e1000_82580:
  5886. /* enable replication vlan tag stripping */
  5887. reg = rd32(E1000_RPLOLR);
  5888. reg |= E1000_RPLOLR_STRVLAN;
  5889. wr32(E1000_RPLOLR, reg);
  5890. case e1000_i350:
  5891. /* none of the above registers are supported by i350 */
  5892. break;
  5893. }
  5894. if (adapter->vfs_allocated_count) {
  5895. igb_vmdq_set_loopback_pf(hw, true);
  5896. igb_vmdq_set_replication_pf(hw, true);
  5897. igb_vmdq_set_anti_spoofing_pf(hw, true,
  5898. adapter->vfs_allocated_count);
  5899. } else {
  5900. igb_vmdq_set_loopback_pf(hw, false);
  5901. igb_vmdq_set_replication_pf(hw, false);
  5902. }
  5903. }
  5904. /* igb_main.c */