netdev.c 214 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625
  1. /* Intel PRO/1000 Linux driver
  2. * Copyright(c) 1999 - 2015 Intel Corporation.
  3. *
  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. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * The full GNU General Public License is included in this distribution in
  14. * the file called "COPYING".
  15. *
  16. * Contact Information:
  17. * Linux NICS <linux.nics@intel.com>
  18. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. */
  21. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  22. #include <linux/module.h>
  23. #include <linux/types.h>
  24. #include <linux/init.h>
  25. #include <linux/pci.h>
  26. #include <linux/vmalloc.h>
  27. #include <linux/pagemap.h>
  28. #include <linux/delay.h>
  29. #include <linux/netdevice.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/tcp.h>
  32. #include <linux/ipv6.h>
  33. #include <linux/slab.h>
  34. #include <net/checksum.h>
  35. #include <net/ip6_checksum.h>
  36. #include <linux/ethtool.h>
  37. #include <linux/if_vlan.h>
  38. #include <linux/cpu.h>
  39. #include <linux/smp.h>
  40. #include <linux/pm_qos.h>
  41. #include <linux/pm_runtime.h>
  42. #include <linux/aer.h>
  43. #include <linux/prefetch.h>
  44. #include "e1000.h"
  45. #define DRV_EXTRAVERSION "-k"
  46. #define DRV_VERSION "3.2.6" DRV_EXTRAVERSION
  47. char e1000e_driver_name[] = "e1000e";
  48. const char e1000e_driver_version[] = DRV_VERSION;
  49. #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK)
  50. static int debug = -1;
  51. module_param(debug, int, 0);
  52. MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
  53. static const struct e1000_info *e1000_info_tbl[] = {
  54. [board_82571] = &e1000_82571_info,
  55. [board_82572] = &e1000_82572_info,
  56. [board_82573] = &e1000_82573_info,
  57. [board_82574] = &e1000_82574_info,
  58. [board_82583] = &e1000_82583_info,
  59. [board_80003es2lan] = &e1000_es2_info,
  60. [board_ich8lan] = &e1000_ich8_info,
  61. [board_ich9lan] = &e1000_ich9_info,
  62. [board_ich10lan] = &e1000_ich10_info,
  63. [board_pchlan] = &e1000_pch_info,
  64. [board_pch2lan] = &e1000_pch2_info,
  65. [board_pch_lpt] = &e1000_pch_lpt_info,
  66. [board_pch_spt] = &e1000_pch_spt_info,
  67. [board_pch_cnp] = &e1000_pch_cnp_info,
  68. };
  69. struct e1000_reg_info {
  70. u32 ofs;
  71. char *name;
  72. };
  73. static const struct e1000_reg_info e1000_reg_info_tbl[] = {
  74. /* General Registers */
  75. {E1000_CTRL, "CTRL"},
  76. {E1000_STATUS, "STATUS"},
  77. {E1000_CTRL_EXT, "CTRL_EXT"},
  78. /* Interrupt Registers */
  79. {E1000_ICR, "ICR"},
  80. /* Rx Registers */
  81. {E1000_RCTL, "RCTL"},
  82. {E1000_RDLEN(0), "RDLEN"},
  83. {E1000_RDH(0), "RDH"},
  84. {E1000_RDT(0), "RDT"},
  85. {E1000_RDTR, "RDTR"},
  86. {E1000_RXDCTL(0), "RXDCTL"},
  87. {E1000_ERT, "ERT"},
  88. {E1000_RDBAL(0), "RDBAL"},
  89. {E1000_RDBAH(0), "RDBAH"},
  90. {E1000_RDFH, "RDFH"},
  91. {E1000_RDFT, "RDFT"},
  92. {E1000_RDFHS, "RDFHS"},
  93. {E1000_RDFTS, "RDFTS"},
  94. {E1000_RDFPC, "RDFPC"},
  95. /* Tx Registers */
  96. {E1000_TCTL, "TCTL"},
  97. {E1000_TDBAL(0), "TDBAL"},
  98. {E1000_TDBAH(0), "TDBAH"},
  99. {E1000_TDLEN(0), "TDLEN"},
  100. {E1000_TDH(0), "TDH"},
  101. {E1000_TDT(0), "TDT"},
  102. {E1000_TIDV, "TIDV"},
  103. {E1000_TXDCTL(0), "TXDCTL"},
  104. {E1000_TADV, "TADV"},
  105. {E1000_TARC(0), "TARC"},
  106. {E1000_TDFH, "TDFH"},
  107. {E1000_TDFT, "TDFT"},
  108. {E1000_TDFHS, "TDFHS"},
  109. {E1000_TDFTS, "TDFTS"},
  110. {E1000_TDFPC, "TDFPC"},
  111. /* List Terminator */
  112. {0, NULL}
  113. };
  114. /**
  115. * __ew32_prepare - prepare to write to MAC CSR register on certain parts
  116. * @hw: pointer to the HW structure
  117. *
  118. * When updating the MAC CSR registers, the Manageability Engine (ME) could
  119. * be accessing the registers at the same time. Normally, this is handled in
  120. * h/w by an arbiter but on some parts there is a bug that acknowledges Host
  121. * accesses later than it should which could result in the register to have
  122. * an incorrect value. Workaround this by checking the FWSM register which
  123. * has bit 24 set while ME is accessing MAC CSR registers, wait if it is set
  124. * and try again a number of times.
  125. **/
  126. s32 __ew32_prepare(struct e1000_hw *hw)
  127. {
  128. s32 i = E1000_ICH_FWSM_PCIM2PCI_COUNT;
  129. while ((er32(FWSM) & E1000_ICH_FWSM_PCIM2PCI) && --i)
  130. udelay(50);
  131. return i;
  132. }
  133. void __ew32(struct e1000_hw *hw, unsigned long reg, u32 val)
  134. {
  135. if (hw->adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
  136. __ew32_prepare(hw);
  137. writel(val, hw->hw_addr + reg);
  138. }
  139. /**
  140. * e1000_regdump - register printout routine
  141. * @hw: pointer to the HW structure
  142. * @reginfo: pointer to the register info table
  143. **/
  144. static void e1000_regdump(struct e1000_hw *hw, struct e1000_reg_info *reginfo)
  145. {
  146. int n = 0;
  147. char rname[16];
  148. u32 regs[8];
  149. switch (reginfo->ofs) {
  150. case E1000_RXDCTL(0):
  151. for (n = 0; n < 2; n++)
  152. regs[n] = __er32(hw, E1000_RXDCTL(n));
  153. break;
  154. case E1000_TXDCTL(0):
  155. for (n = 0; n < 2; n++)
  156. regs[n] = __er32(hw, E1000_TXDCTL(n));
  157. break;
  158. case E1000_TARC(0):
  159. for (n = 0; n < 2; n++)
  160. regs[n] = __er32(hw, E1000_TARC(n));
  161. break;
  162. default:
  163. pr_info("%-15s %08x\n",
  164. reginfo->name, __er32(hw, reginfo->ofs));
  165. return;
  166. }
  167. snprintf(rname, 16, "%s%s", reginfo->name, "[0-1]");
  168. pr_info("%-15s %08x %08x\n", rname, regs[0], regs[1]);
  169. }
  170. static void e1000e_dump_ps_pages(struct e1000_adapter *adapter,
  171. struct e1000_buffer *bi)
  172. {
  173. int i;
  174. struct e1000_ps_page *ps_page;
  175. for (i = 0; i < adapter->rx_ps_pages; i++) {
  176. ps_page = &bi->ps_pages[i];
  177. if (ps_page->page) {
  178. pr_info("packet dump for ps_page %d:\n", i);
  179. print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
  180. 16, 1, page_address(ps_page->page),
  181. PAGE_SIZE, true);
  182. }
  183. }
  184. }
  185. /**
  186. * e1000e_dump - Print registers, Tx-ring and Rx-ring
  187. * @adapter: board private structure
  188. **/
  189. static void e1000e_dump(struct e1000_adapter *adapter)
  190. {
  191. struct net_device *netdev = adapter->netdev;
  192. struct e1000_hw *hw = &adapter->hw;
  193. struct e1000_reg_info *reginfo;
  194. struct e1000_ring *tx_ring = adapter->tx_ring;
  195. struct e1000_tx_desc *tx_desc;
  196. struct my_u0 {
  197. __le64 a;
  198. __le64 b;
  199. } *u0;
  200. struct e1000_buffer *buffer_info;
  201. struct e1000_ring *rx_ring = adapter->rx_ring;
  202. union e1000_rx_desc_packet_split *rx_desc_ps;
  203. union e1000_rx_desc_extended *rx_desc;
  204. struct my_u1 {
  205. __le64 a;
  206. __le64 b;
  207. __le64 c;
  208. __le64 d;
  209. } *u1;
  210. u32 staterr;
  211. int i = 0;
  212. if (!netif_msg_hw(adapter))
  213. return;
  214. /* Print netdevice Info */
  215. if (netdev) {
  216. dev_info(&adapter->pdev->dev, "Net device Info\n");
  217. pr_info("Device Name state trans_start\n");
  218. pr_info("%-15s %016lX %016lX\n", netdev->name,
  219. netdev->state, dev_trans_start(netdev));
  220. }
  221. /* Print Registers */
  222. dev_info(&adapter->pdev->dev, "Register Dump\n");
  223. pr_info(" Register Name Value\n");
  224. for (reginfo = (struct e1000_reg_info *)e1000_reg_info_tbl;
  225. reginfo->name; reginfo++) {
  226. e1000_regdump(hw, reginfo);
  227. }
  228. /* Print Tx Ring Summary */
  229. if (!netdev || !netif_running(netdev))
  230. return;
  231. dev_info(&adapter->pdev->dev, "Tx Ring Summary\n");
  232. pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
  233. buffer_info = &tx_ring->buffer_info[tx_ring->next_to_clean];
  234. pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
  235. 0, tx_ring->next_to_use, tx_ring->next_to_clean,
  236. (unsigned long long)buffer_info->dma,
  237. buffer_info->length,
  238. buffer_info->next_to_watch,
  239. (unsigned long long)buffer_info->time_stamp);
  240. /* Print Tx Ring */
  241. if (!netif_msg_tx_done(adapter))
  242. goto rx_ring_summary;
  243. dev_info(&adapter->pdev->dev, "Tx Ring Dump\n");
  244. /* Transmit Descriptor Formats - DEXT[29] is 0 (Legacy) or 1 (Extended)
  245. *
  246. * Legacy Transmit Descriptor
  247. * +--------------------------------------------------------------+
  248. * 0 | Buffer Address [63:0] (Reserved on Write Back) |
  249. * +--------------------------------------------------------------+
  250. * 8 | Special | CSS | Status | CMD | CSO | Length |
  251. * +--------------------------------------------------------------+
  252. * 63 48 47 36 35 32 31 24 23 16 15 0
  253. *
  254. * Extended Context Descriptor (DTYP=0x0) for TSO or checksum offload
  255. * 63 48 47 40 39 32 31 16 15 8 7 0
  256. * +----------------------------------------------------------------+
  257. * 0 | TUCSE | TUCS0 | TUCSS | IPCSE | IPCS0 | IPCSS |
  258. * +----------------------------------------------------------------+
  259. * 8 | MSS | HDRLEN | RSV | STA | TUCMD | DTYP | PAYLEN |
  260. * +----------------------------------------------------------------+
  261. * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
  262. *
  263. * Extended Data Descriptor (DTYP=0x1)
  264. * +----------------------------------------------------------------+
  265. * 0 | Buffer Address [63:0] |
  266. * +----------------------------------------------------------------+
  267. * 8 | VLAN tag | POPTS | Rsvd | Status | Command | DTYP | DTALEN |
  268. * +----------------------------------------------------------------+
  269. * 63 48 47 40 39 36 35 32 31 24 23 20 19 0
  270. */
  271. pr_info("Tl[desc] [address 63:0 ] [SpeCssSCmCsLen] [bi->dma ] leng ntw timestamp bi->skb <-- Legacy format\n");
  272. pr_info("Tc[desc] [Ce CoCsIpceCoS] [MssHlRSCm0Plen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Context format\n");
  273. pr_info("Td[desc] [address 63:0 ] [VlaPoRSCm1Dlen] [bi->dma ] leng ntw timestamp bi->skb <-- Ext Data format\n");
  274. for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
  275. const char *next_desc;
  276. tx_desc = E1000_TX_DESC(*tx_ring, i);
  277. buffer_info = &tx_ring->buffer_info[i];
  278. u0 = (struct my_u0 *)tx_desc;
  279. if (i == tx_ring->next_to_use && i == tx_ring->next_to_clean)
  280. next_desc = " NTC/U";
  281. else if (i == tx_ring->next_to_use)
  282. next_desc = " NTU";
  283. else if (i == tx_ring->next_to_clean)
  284. next_desc = " NTC";
  285. else
  286. next_desc = "";
  287. pr_info("T%c[0x%03X] %016llX %016llX %016llX %04X %3X %016llX %p%s\n",
  288. (!(le64_to_cpu(u0->b) & BIT(29)) ? 'l' :
  289. ((le64_to_cpu(u0->b) & BIT(20)) ? 'd' : 'c')),
  290. i,
  291. (unsigned long long)le64_to_cpu(u0->a),
  292. (unsigned long long)le64_to_cpu(u0->b),
  293. (unsigned long long)buffer_info->dma,
  294. buffer_info->length, buffer_info->next_to_watch,
  295. (unsigned long long)buffer_info->time_stamp,
  296. buffer_info->skb, next_desc);
  297. if (netif_msg_pktdata(adapter) && buffer_info->skb)
  298. print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS,
  299. 16, 1, buffer_info->skb->data,
  300. buffer_info->skb->len, true);
  301. }
  302. /* Print Rx Ring Summary */
  303. rx_ring_summary:
  304. dev_info(&adapter->pdev->dev, "Rx Ring Summary\n");
  305. pr_info("Queue [NTU] [NTC]\n");
  306. pr_info(" %5d %5X %5X\n",
  307. 0, rx_ring->next_to_use, rx_ring->next_to_clean);
  308. /* Print Rx Ring */
  309. if (!netif_msg_rx_status(adapter))
  310. return;
  311. dev_info(&adapter->pdev->dev, "Rx Ring Dump\n");
  312. switch (adapter->rx_ps_pages) {
  313. case 1:
  314. case 2:
  315. case 3:
  316. /* [Extended] Packet Split Receive Descriptor Format
  317. *
  318. * +-----------------------------------------------------+
  319. * 0 | Buffer Address 0 [63:0] |
  320. * +-----------------------------------------------------+
  321. * 8 | Buffer Address 1 [63:0] |
  322. * +-----------------------------------------------------+
  323. * 16 | Buffer Address 2 [63:0] |
  324. * +-----------------------------------------------------+
  325. * 24 | Buffer Address 3 [63:0] |
  326. * +-----------------------------------------------------+
  327. */
  328. pr_info("R [desc] [buffer 0 63:0 ] [buffer 1 63:0 ] [buffer 2 63:0 ] [buffer 3 63:0 ] [bi->dma ] [bi->skb] <-- Ext Pkt Split format\n");
  329. /* [Extended] Receive Descriptor (Write-Back) Format
  330. *
  331. * 63 48 47 32 31 13 12 8 7 4 3 0
  332. * +------------------------------------------------------+
  333. * 0 | Packet | IP | Rsvd | MRQ | Rsvd | MRQ RSS |
  334. * | Checksum | Ident | | Queue | | Type |
  335. * +------------------------------------------------------+
  336. * 8 | VLAN Tag | Length | Extended Error | Extended Status |
  337. * +------------------------------------------------------+
  338. * 63 48 47 32 31 20 19 0
  339. */
  340. pr_info("RWB[desc] [ck ipid mrqhsh] [vl l0 ee es] [ l3 l2 l1 hs] [reserved ] ---------------- [bi->skb] <-- Ext Rx Write-Back format\n");
  341. for (i = 0; i < rx_ring->count; i++) {
  342. const char *next_desc;
  343. buffer_info = &rx_ring->buffer_info[i];
  344. rx_desc_ps = E1000_RX_DESC_PS(*rx_ring, i);
  345. u1 = (struct my_u1 *)rx_desc_ps;
  346. staterr =
  347. le32_to_cpu(rx_desc_ps->wb.middle.status_error);
  348. if (i == rx_ring->next_to_use)
  349. next_desc = " NTU";
  350. else if (i == rx_ring->next_to_clean)
  351. next_desc = " NTC";
  352. else
  353. next_desc = "";
  354. if (staterr & E1000_RXD_STAT_DD) {
  355. /* Descriptor Done */
  356. pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX ---------------- %p%s\n",
  357. "RWB", i,
  358. (unsigned long long)le64_to_cpu(u1->a),
  359. (unsigned long long)le64_to_cpu(u1->b),
  360. (unsigned long long)le64_to_cpu(u1->c),
  361. (unsigned long long)le64_to_cpu(u1->d),
  362. buffer_info->skb, next_desc);
  363. } else {
  364. pr_info("%s[0x%03X] %016llX %016llX %016llX %016llX %016llX %p%s\n",
  365. "R ", i,
  366. (unsigned long long)le64_to_cpu(u1->a),
  367. (unsigned long long)le64_to_cpu(u1->b),
  368. (unsigned long long)le64_to_cpu(u1->c),
  369. (unsigned long long)le64_to_cpu(u1->d),
  370. (unsigned long long)buffer_info->dma,
  371. buffer_info->skb, next_desc);
  372. if (netif_msg_pktdata(adapter))
  373. e1000e_dump_ps_pages(adapter,
  374. buffer_info);
  375. }
  376. }
  377. break;
  378. default:
  379. case 0:
  380. /* Extended Receive Descriptor (Read) Format
  381. *
  382. * +-----------------------------------------------------+
  383. * 0 | Buffer Address [63:0] |
  384. * +-----------------------------------------------------+
  385. * 8 | Reserved |
  386. * +-----------------------------------------------------+
  387. */
  388. pr_info("R [desc] [buf addr 63:0 ] [reserved 63:0 ] [bi->dma ] [bi->skb] <-- Ext (Read) format\n");
  389. /* Extended Receive Descriptor (Write-Back) Format
  390. *
  391. * 63 48 47 32 31 24 23 4 3 0
  392. * +------------------------------------------------------+
  393. * | RSS Hash | | | |
  394. * 0 +-------------------+ Rsvd | Reserved | MRQ RSS |
  395. * | Packet | IP | | | Type |
  396. * | Checksum | Ident | | | |
  397. * +------------------------------------------------------+
  398. * 8 | VLAN Tag | Length | Extended Error | Extended Status |
  399. * +------------------------------------------------------+
  400. * 63 48 47 32 31 20 19 0
  401. */
  402. pr_info("RWB[desc] [cs ipid mrq] [vt ln xe xs] [bi->skb] <-- Ext (Write-Back) format\n");
  403. for (i = 0; i < rx_ring->count; i++) {
  404. const char *next_desc;
  405. buffer_info = &rx_ring->buffer_info[i];
  406. rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
  407. u1 = (struct my_u1 *)rx_desc;
  408. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  409. if (i == rx_ring->next_to_use)
  410. next_desc = " NTU";
  411. else if (i == rx_ring->next_to_clean)
  412. next_desc = " NTC";
  413. else
  414. next_desc = "";
  415. if (staterr & E1000_RXD_STAT_DD) {
  416. /* Descriptor Done */
  417. pr_info("%s[0x%03X] %016llX %016llX ---------------- %p%s\n",
  418. "RWB", i,
  419. (unsigned long long)le64_to_cpu(u1->a),
  420. (unsigned long long)le64_to_cpu(u1->b),
  421. buffer_info->skb, next_desc);
  422. } else {
  423. pr_info("%s[0x%03X] %016llX %016llX %016llX %p%s\n",
  424. "R ", i,
  425. (unsigned long long)le64_to_cpu(u1->a),
  426. (unsigned long long)le64_to_cpu(u1->b),
  427. (unsigned long long)buffer_info->dma,
  428. buffer_info->skb, next_desc);
  429. if (netif_msg_pktdata(adapter) &&
  430. buffer_info->skb)
  431. print_hex_dump(KERN_INFO, "",
  432. DUMP_PREFIX_ADDRESS, 16,
  433. 1,
  434. buffer_info->skb->data,
  435. adapter->rx_buffer_len,
  436. true);
  437. }
  438. }
  439. }
  440. }
  441. /**
  442. * e1000_desc_unused - calculate if we have unused descriptors
  443. **/
  444. static int e1000_desc_unused(struct e1000_ring *ring)
  445. {
  446. if (ring->next_to_clean > ring->next_to_use)
  447. return ring->next_to_clean - ring->next_to_use - 1;
  448. return ring->count + ring->next_to_clean - ring->next_to_use - 1;
  449. }
  450. /**
  451. * e1000e_systim_to_hwtstamp - convert system time value to hw time stamp
  452. * @adapter: board private structure
  453. * @hwtstamps: time stamp structure to update
  454. * @systim: unsigned 64bit system time value.
  455. *
  456. * Convert the system time value stored in the RX/TXSTMP registers into a
  457. * hwtstamp which can be used by the upper level time stamping functions.
  458. *
  459. * The 'systim_lock' spinlock is used to protect the consistency of the
  460. * system time value. This is needed because reading the 64 bit time
  461. * value involves reading two 32 bit registers. The first read latches the
  462. * value.
  463. **/
  464. static void e1000e_systim_to_hwtstamp(struct e1000_adapter *adapter,
  465. struct skb_shared_hwtstamps *hwtstamps,
  466. u64 systim)
  467. {
  468. u64 ns;
  469. unsigned long flags;
  470. spin_lock_irqsave(&adapter->systim_lock, flags);
  471. ns = timecounter_cyc2time(&adapter->tc, systim);
  472. spin_unlock_irqrestore(&adapter->systim_lock, flags);
  473. memset(hwtstamps, 0, sizeof(*hwtstamps));
  474. hwtstamps->hwtstamp = ns_to_ktime(ns);
  475. }
  476. /**
  477. * e1000e_rx_hwtstamp - utility function which checks for Rx time stamp
  478. * @adapter: board private structure
  479. * @status: descriptor extended error and status field
  480. * @skb: particular skb to include time stamp
  481. *
  482. * If the time stamp is valid, convert it into the timecounter ns value
  483. * and store that result into the shhwtstamps structure which is passed
  484. * up the network stack.
  485. **/
  486. static void e1000e_rx_hwtstamp(struct e1000_adapter *adapter, u32 status,
  487. struct sk_buff *skb)
  488. {
  489. struct e1000_hw *hw = &adapter->hw;
  490. u64 rxstmp;
  491. if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP) ||
  492. !(status & E1000_RXDEXT_STATERR_TST) ||
  493. !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID))
  494. return;
  495. /* The Rx time stamp registers contain the time stamp. No other
  496. * received packet will be time stamped until the Rx time stamp
  497. * registers are read. Because only one packet can be time stamped
  498. * at a time, the register values must belong to this packet and
  499. * therefore none of the other additional attributes need to be
  500. * compared.
  501. */
  502. rxstmp = (u64)er32(RXSTMPL);
  503. rxstmp |= (u64)er32(RXSTMPH) << 32;
  504. e1000e_systim_to_hwtstamp(adapter, skb_hwtstamps(skb), rxstmp);
  505. adapter->flags2 &= ~FLAG2_CHECK_RX_HWTSTAMP;
  506. }
  507. /**
  508. * e1000_receive_skb - helper function to handle Rx indications
  509. * @adapter: board private structure
  510. * @staterr: descriptor extended error and status field as written by hardware
  511. * @vlan: descriptor vlan field as written by hardware (no le/be conversion)
  512. * @skb: pointer to sk_buff to be indicated to stack
  513. **/
  514. static void e1000_receive_skb(struct e1000_adapter *adapter,
  515. struct net_device *netdev, struct sk_buff *skb,
  516. u32 staterr, __le16 vlan)
  517. {
  518. u16 tag = le16_to_cpu(vlan);
  519. e1000e_rx_hwtstamp(adapter, staterr, skb);
  520. skb->protocol = eth_type_trans(skb, netdev);
  521. if (staterr & E1000_RXD_STAT_VP)
  522. __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag);
  523. napi_gro_receive(&adapter->napi, skb);
  524. }
  525. /**
  526. * e1000_rx_checksum - Receive Checksum Offload
  527. * @adapter: board private structure
  528. * @status_err: receive descriptor status and error fields
  529. * @csum: receive descriptor csum field
  530. * @sk_buff: socket buffer with received data
  531. **/
  532. static void e1000_rx_checksum(struct e1000_adapter *adapter, u32 status_err,
  533. struct sk_buff *skb)
  534. {
  535. u16 status = (u16)status_err;
  536. u8 errors = (u8)(status_err >> 24);
  537. skb_checksum_none_assert(skb);
  538. /* Rx checksum disabled */
  539. if (!(adapter->netdev->features & NETIF_F_RXCSUM))
  540. return;
  541. /* Ignore Checksum bit is set */
  542. if (status & E1000_RXD_STAT_IXSM)
  543. return;
  544. /* TCP/UDP checksum error bit or IP checksum error bit is set */
  545. if (errors & (E1000_RXD_ERR_TCPE | E1000_RXD_ERR_IPE)) {
  546. /* let the stack verify checksum errors */
  547. adapter->hw_csum_err++;
  548. return;
  549. }
  550. /* TCP/UDP Checksum has not been calculated */
  551. if (!(status & (E1000_RXD_STAT_TCPCS | E1000_RXD_STAT_UDPCS)))
  552. return;
  553. /* It must be a TCP or UDP packet with a valid checksum */
  554. skb->ip_summed = CHECKSUM_UNNECESSARY;
  555. adapter->hw_csum_good++;
  556. }
  557. static void e1000e_update_rdt_wa(struct e1000_ring *rx_ring, unsigned int i)
  558. {
  559. struct e1000_adapter *adapter = rx_ring->adapter;
  560. struct e1000_hw *hw = &adapter->hw;
  561. s32 ret_val = __ew32_prepare(hw);
  562. writel(i, rx_ring->tail);
  563. if (unlikely(!ret_val && (i != readl(rx_ring->tail)))) {
  564. u32 rctl = er32(RCTL);
  565. ew32(RCTL, rctl & ~E1000_RCTL_EN);
  566. e_err("ME firmware caused invalid RDT - resetting\n");
  567. schedule_work(&adapter->reset_task);
  568. }
  569. }
  570. static void e1000e_update_tdt_wa(struct e1000_ring *tx_ring, unsigned int i)
  571. {
  572. struct e1000_adapter *adapter = tx_ring->adapter;
  573. struct e1000_hw *hw = &adapter->hw;
  574. s32 ret_val = __ew32_prepare(hw);
  575. writel(i, tx_ring->tail);
  576. if (unlikely(!ret_val && (i != readl(tx_ring->tail)))) {
  577. u32 tctl = er32(TCTL);
  578. ew32(TCTL, tctl & ~E1000_TCTL_EN);
  579. e_err("ME firmware caused invalid TDT - resetting\n");
  580. schedule_work(&adapter->reset_task);
  581. }
  582. }
  583. /**
  584. * e1000_alloc_rx_buffers - Replace used receive buffers
  585. * @rx_ring: Rx descriptor ring
  586. **/
  587. static void e1000_alloc_rx_buffers(struct e1000_ring *rx_ring,
  588. int cleaned_count, gfp_t gfp)
  589. {
  590. struct e1000_adapter *adapter = rx_ring->adapter;
  591. struct net_device *netdev = adapter->netdev;
  592. struct pci_dev *pdev = adapter->pdev;
  593. union e1000_rx_desc_extended *rx_desc;
  594. struct e1000_buffer *buffer_info;
  595. struct sk_buff *skb;
  596. unsigned int i;
  597. unsigned int bufsz = adapter->rx_buffer_len;
  598. i = rx_ring->next_to_use;
  599. buffer_info = &rx_ring->buffer_info[i];
  600. while (cleaned_count--) {
  601. skb = buffer_info->skb;
  602. if (skb) {
  603. skb_trim(skb, 0);
  604. goto map_skb;
  605. }
  606. skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
  607. if (!skb) {
  608. /* Better luck next round */
  609. adapter->alloc_rx_buff_failed++;
  610. break;
  611. }
  612. buffer_info->skb = skb;
  613. map_skb:
  614. buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
  615. adapter->rx_buffer_len,
  616. DMA_FROM_DEVICE);
  617. if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
  618. dev_err(&pdev->dev, "Rx DMA map failed\n");
  619. adapter->rx_dma_failed++;
  620. break;
  621. }
  622. rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
  623. rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
  624. if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
  625. /* Force memory writes to complete before letting h/w
  626. * know there are new descriptors to fetch. (Only
  627. * applicable for weak-ordered memory model archs,
  628. * such as IA-64).
  629. */
  630. wmb();
  631. if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
  632. e1000e_update_rdt_wa(rx_ring, i);
  633. else
  634. writel(i, rx_ring->tail);
  635. }
  636. i++;
  637. if (i == rx_ring->count)
  638. i = 0;
  639. buffer_info = &rx_ring->buffer_info[i];
  640. }
  641. rx_ring->next_to_use = i;
  642. }
  643. /**
  644. * e1000_alloc_rx_buffers_ps - Replace used receive buffers; packet split
  645. * @rx_ring: Rx descriptor ring
  646. **/
  647. static void e1000_alloc_rx_buffers_ps(struct e1000_ring *rx_ring,
  648. int cleaned_count, gfp_t gfp)
  649. {
  650. struct e1000_adapter *adapter = rx_ring->adapter;
  651. struct net_device *netdev = adapter->netdev;
  652. struct pci_dev *pdev = adapter->pdev;
  653. union e1000_rx_desc_packet_split *rx_desc;
  654. struct e1000_buffer *buffer_info;
  655. struct e1000_ps_page *ps_page;
  656. struct sk_buff *skb;
  657. unsigned int i, j;
  658. i = rx_ring->next_to_use;
  659. buffer_info = &rx_ring->buffer_info[i];
  660. while (cleaned_count--) {
  661. rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
  662. for (j = 0; j < PS_PAGE_BUFFERS; j++) {
  663. ps_page = &buffer_info->ps_pages[j];
  664. if (j >= adapter->rx_ps_pages) {
  665. /* all unused desc entries get hw null ptr */
  666. rx_desc->read.buffer_addr[j + 1] =
  667. ~cpu_to_le64(0);
  668. continue;
  669. }
  670. if (!ps_page->page) {
  671. ps_page->page = alloc_page(gfp);
  672. if (!ps_page->page) {
  673. adapter->alloc_rx_buff_failed++;
  674. goto no_buffers;
  675. }
  676. ps_page->dma = dma_map_page(&pdev->dev,
  677. ps_page->page,
  678. 0, PAGE_SIZE,
  679. DMA_FROM_DEVICE);
  680. if (dma_mapping_error(&pdev->dev,
  681. ps_page->dma)) {
  682. dev_err(&adapter->pdev->dev,
  683. "Rx DMA page map failed\n");
  684. adapter->rx_dma_failed++;
  685. goto no_buffers;
  686. }
  687. }
  688. /* Refresh the desc even if buffer_addrs
  689. * didn't change because each write-back
  690. * erases this info.
  691. */
  692. rx_desc->read.buffer_addr[j + 1] =
  693. cpu_to_le64(ps_page->dma);
  694. }
  695. skb = __netdev_alloc_skb_ip_align(netdev, adapter->rx_ps_bsize0,
  696. gfp);
  697. if (!skb) {
  698. adapter->alloc_rx_buff_failed++;
  699. break;
  700. }
  701. buffer_info->skb = skb;
  702. buffer_info->dma = dma_map_single(&pdev->dev, skb->data,
  703. adapter->rx_ps_bsize0,
  704. DMA_FROM_DEVICE);
  705. if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
  706. dev_err(&pdev->dev, "Rx DMA map failed\n");
  707. adapter->rx_dma_failed++;
  708. /* cleanup skb */
  709. dev_kfree_skb_any(skb);
  710. buffer_info->skb = NULL;
  711. break;
  712. }
  713. rx_desc->read.buffer_addr[0] = cpu_to_le64(buffer_info->dma);
  714. if (unlikely(!(i & (E1000_RX_BUFFER_WRITE - 1)))) {
  715. /* Force memory writes to complete before letting h/w
  716. * know there are new descriptors to fetch. (Only
  717. * applicable for weak-ordered memory model archs,
  718. * such as IA-64).
  719. */
  720. wmb();
  721. if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
  722. e1000e_update_rdt_wa(rx_ring, i << 1);
  723. else
  724. writel(i << 1, rx_ring->tail);
  725. }
  726. i++;
  727. if (i == rx_ring->count)
  728. i = 0;
  729. buffer_info = &rx_ring->buffer_info[i];
  730. }
  731. no_buffers:
  732. rx_ring->next_to_use = i;
  733. }
  734. /**
  735. * e1000_alloc_jumbo_rx_buffers - Replace used jumbo receive buffers
  736. * @rx_ring: Rx descriptor ring
  737. * @cleaned_count: number of buffers to allocate this pass
  738. **/
  739. static void e1000_alloc_jumbo_rx_buffers(struct e1000_ring *rx_ring,
  740. int cleaned_count, gfp_t gfp)
  741. {
  742. struct e1000_adapter *adapter = rx_ring->adapter;
  743. struct net_device *netdev = adapter->netdev;
  744. struct pci_dev *pdev = adapter->pdev;
  745. union e1000_rx_desc_extended *rx_desc;
  746. struct e1000_buffer *buffer_info;
  747. struct sk_buff *skb;
  748. unsigned int i;
  749. unsigned int bufsz = 256 - 16; /* for skb_reserve */
  750. i = rx_ring->next_to_use;
  751. buffer_info = &rx_ring->buffer_info[i];
  752. while (cleaned_count--) {
  753. skb = buffer_info->skb;
  754. if (skb) {
  755. skb_trim(skb, 0);
  756. goto check_page;
  757. }
  758. skb = __netdev_alloc_skb_ip_align(netdev, bufsz, gfp);
  759. if (unlikely(!skb)) {
  760. /* Better luck next round */
  761. adapter->alloc_rx_buff_failed++;
  762. break;
  763. }
  764. buffer_info->skb = skb;
  765. check_page:
  766. /* allocate a new page if necessary */
  767. if (!buffer_info->page) {
  768. buffer_info->page = alloc_page(gfp);
  769. if (unlikely(!buffer_info->page)) {
  770. adapter->alloc_rx_buff_failed++;
  771. break;
  772. }
  773. }
  774. if (!buffer_info->dma) {
  775. buffer_info->dma = dma_map_page(&pdev->dev,
  776. buffer_info->page, 0,
  777. PAGE_SIZE,
  778. DMA_FROM_DEVICE);
  779. if (dma_mapping_error(&pdev->dev, buffer_info->dma)) {
  780. adapter->alloc_rx_buff_failed++;
  781. break;
  782. }
  783. }
  784. rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
  785. rx_desc->read.buffer_addr = cpu_to_le64(buffer_info->dma);
  786. if (unlikely(++i == rx_ring->count))
  787. i = 0;
  788. buffer_info = &rx_ring->buffer_info[i];
  789. }
  790. if (likely(rx_ring->next_to_use != i)) {
  791. rx_ring->next_to_use = i;
  792. if (unlikely(i-- == 0))
  793. i = (rx_ring->count - 1);
  794. /* Force memory writes to complete before letting h/w
  795. * know there are new descriptors to fetch. (Only
  796. * applicable for weak-ordered memory model archs,
  797. * such as IA-64).
  798. */
  799. wmb();
  800. if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
  801. e1000e_update_rdt_wa(rx_ring, i);
  802. else
  803. writel(i, rx_ring->tail);
  804. }
  805. }
  806. static inline void e1000_rx_hash(struct net_device *netdev, __le32 rss,
  807. struct sk_buff *skb)
  808. {
  809. if (netdev->features & NETIF_F_RXHASH)
  810. skb_set_hash(skb, le32_to_cpu(rss), PKT_HASH_TYPE_L3);
  811. }
  812. /**
  813. * e1000_clean_rx_irq - Send received data up the network stack
  814. * @rx_ring: Rx descriptor ring
  815. *
  816. * the return value indicates whether actual cleaning was done, there
  817. * is no guarantee that everything was cleaned
  818. **/
  819. static bool e1000_clean_rx_irq(struct e1000_ring *rx_ring, int *work_done,
  820. int work_to_do)
  821. {
  822. struct e1000_adapter *adapter = rx_ring->adapter;
  823. struct net_device *netdev = adapter->netdev;
  824. struct pci_dev *pdev = adapter->pdev;
  825. struct e1000_hw *hw = &adapter->hw;
  826. union e1000_rx_desc_extended *rx_desc, *next_rxd;
  827. struct e1000_buffer *buffer_info, *next_buffer;
  828. u32 length, staterr;
  829. unsigned int i;
  830. int cleaned_count = 0;
  831. bool cleaned = false;
  832. unsigned int total_rx_bytes = 0, total_rx_packets = 0;
  833. i = rx_ring->next_to_clean;
  834. rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
  835. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  836. buffer_info = &rx_ring->buffer_info[i];
  837. while (staterr & E1000_RXD_STAT_DD) {
  838. struct sk_buff *skb;
  839. if (*work_done >= work_to_do)
  840. break;
  841. (*work_done)++;
  842. dma_rmb(); /* read descriptor and rx_buffer_info after status DD */
  843. skb = buffer_info->skb;
  844. buffer_info->skb = NULL;
  845. prefetch(skb->data - NET_IP_ALIGN);
  846. i++;
  847. if (i == rx_ring->count)
  848. i = 0;
  849. next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
  850. prefetch(next_rxd);
  851. next_buffer = &rx_ring->buffer_info[i];
  852. cleaned = true;
  853. cleaned_count++;
  854. dma_unmap_single(&pdev->dev, buffer_info->dma,
  855. adapter->rx_buffer_len, DMA_FROM_DEVICE);
  856. buffer_info->dma = 0;
  857. length = le16_to_cpu(rx_desc->wb.upper.length);
  858. /* !EOP means multiple descriptors were used to store a single
  859. * packet, if that's the case we need to toss it. In fact, we
  860. * need to toss every packet with the EOP bit clear and the
  861. * next frame that _does_ have the EOP bit set, as it is by
  862. * definition only a frame fragment
  863. */
  864. if (unlikely(!(staterr & E1000_RXD_STAT_EOP)))
  865. adapter->flags2 |= FLAG2_IS_DISCARDING;
  866. if (adapter->flags2 & FLAG2_IS_DISCARDING) {
  867. /* All receives must fit into a single buffer */
  868. e_dbg("Receive packet consumed multiple buffers\n");
  869. /* recycle */
  870. buffer_info->skb = skb;
  871. if (staterr & E1000_RXD_STAT_EOP)
  872. adapter->flags2 &= ~FLAG2_IS_DISCARDING;
  873. goto next_desc;
  874. }
  875. if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
  876. !(netdev->features & NETIF_F_RXALL))) {
  877. /* recycle */
  878. buffer_info->skb = skb;
  879. goto next_desc;
  880. }
  881. /* adjust length to remove Ethernet CRC */
  882. if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
  883. /* If configured to store CRC, don't subtract FCS,
  884. * but keep the FCS bytes out of the total_rx_bytes
  885. * counter
  886. */
  887. if (netdev->features & NETIF_F_RXFCS)
  888. total_rx_bytes -= 4;
  889. else
  890. length -= 4;
  891. }
  892. total_rx_bytes += length;
  893. total_rx_packets++;
  894. /* code added for copybreak, this should improve
  895. * performance for small packets with large amounts
  896. * of reassembly being done in the stack
  897. */
  898. if (length < copybreak) {
  899. struct sk_buff *new_skb =
  900. napi_alloc_skb(&adapter->napi, length);
  901. if (new_skb) {
  902. skb_copy_to_linear_data_offset(new_skb,
  903. -NET_IP_ALIGN,
  904. (skb->data -
  905. NET_IP_ALIGN),
  906. (length +
  907. NET_IP_ALIGN));
  908. /* save the skb in buffer_info as good */
  909. buffer_info->skb = skb;
  910. skb = new_skb;
  911. }
  912. /* else just continue with the old one */
  913. }
  914. /* end copybreak code */
  915. skb_put(skb, length);
  916. /* Receive Checksum Offload */
  917. e1000_rx_checksum(adapter, staterr, skb);
  918. e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
  919. e1000_receive_skb(adapter, netdev, skb, staterr,
  920. rx_desc->wb.upper.vlan);
  921. next_desc:
  922. rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
  923. /* return some buffers to hardware, one at a time is too slow */
  924. if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
  925. adapter->alloc_rx_buf(rx_ring, cleaned_count,
  926. GFP_ATOMIC);
  927. cleaned_count = 0;
  928. }
  929. /* use prefetched values */
  930. rx_desc = next_rxd;
  931. buffer_info = next_buffer;
  932. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  933. }
  934. rx_ring->next_to_clean = i;
  935. cleaned_count = e1000_desc_unused(rx_ring);
  936. if (cleaned_count)
  937. adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
  938. adapter->total_rx_bytes += total_rx_bytes;
  939. adapter->total_rx_packets += total_rx_packets;
  940. return cleaned;
  941. }
  942. static void e1000_put_txbuf(struct e1000_ring *tx_ring,
  943. struct e1000_buffer *buffer_info,
  944. bool drop)
  945. {
  946. struct e1000_adapter *adapter = tx_ring->adapter;
  947. if (buffer_info->dma) {
  948. if (buffer_info->mapped_as_page)
  949. dma_unmap_page(&adapter->pdev->dev, buffer_info->dma,
  950. buffer_info->length, DMA_TO_DEVICE);
  951. else
  952. dma_unmap_single(&adapter->pdev->dev, buffer_info->dma,
  953. buffer_info->length, DMA_TO_DEVICE);
  954. buffer_info->dma = 0;
  955. }
  956. if (buffer_info->skb) {
  957. if (drop)
  958. dev_kfree_skb_any(buffer_info->skb);
  959. else
  960. dev_consume_skb_any(buffer_info->skb);
  961. buffer_info->skb = NULL;
  962. }
  963. buffer_info->time_stamp = 0;
  964. }
  965. static void e1000_print_hw_hang(struct work_struct *work)
  966. {
  967. struct e1000_adapter *adapter = container_of(work,
  968. struct e1000_adapter,
  969. print_hang_task);
  970. struct net_device *netdev = adapter->netdev;
  971. struct e1000_ring *tx_ring = adapter->tx_ring;
  972. unsigned int i = tx_ring->next_to_clean;
  973. unsigned int eop = tx_ring->buffer_info[i].next_to_watch;
  974. struct e1000_tx_desc *eop_desc = E1000_TX_DESC(*tx_ring, eop);
  975. struct e1000_hw *hw = &adapter->hw;
  976. u16 phy_status, phy_1000t_status, phy_ext_status;
  977. u16 pci_status;
  978. if (test_bit(__E1000_DOWN, &adapter->state))
  979. return;
  980. if (!adapter->tx_hang_recheck && (adapter->flags2 & FLAG2_DMA_BURST)) {
  981. /* May be block on write-back, flush and detect again
  982. * flush pending descriptor writebacks to memory
  983. */
  984. ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
  985. /* execute the writes immediately */
  986. e1e_flush();
  987. /* Due to rare timing issues, write to TIDV again to ensure
  988. * the write is successful
  989. */
  990. ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
  991. /* execute the writes immediately */
  992. e1e_flush();
  993. adapter->tx_hang_recheck = true;
  994. return;
  995. }
  996. adapter->tx_hang_recheck = false;
  997. if (er32(TDH(0)) == er32(TDT(0))) {
  998. e_dbg("false hang detected, ignoring\n");
  999. return;
  1000. }
  1001. /* Real hang detected */
  1002. netif_stop_queue(netdev);
  1003. e1e_rphy(hw, MII_BMSR, &phy_status);
  1004. e1e_rphy(hw, MII_STAT1000, &phy_1000t_status);
  1005. e1e_rphy(hw, MII_ESTATUS, &phy_ext_status);
  1006. pci_read_config_word(adapter->pdev, PCI_STATUS, &pci_status);
  1007. /* detected Hardware unit hang */
  1008. e_err("Detected Hardware Unit Hang:\n"
  1009. " TDH <%x>\n"
  1010. " TDT <%x>\n"
  1011. " next_to_use <%x>\n"
  1012. " next_to_clean <%x>\n"
  1013. "buffer_info[next_to_clean]:\n"
  1014. " time_stamp <%lx>\n"
  1015. " next_to_watch <%x>\n"
  1016. " jiffies <%lx>\n"
  1017. " next_to_watch.status <%x>\n"
  1018. "MAC Status <%x>\n"
  1019. "PHY Status <%x>\n"
  1020. "PHY 1000BASE-T Status <%x>\n"
  1021. "PHY Extended Status <%x>\n"
  1022. "PCI Status <%x>\n",
  1023. readl(tx_ring->head), readl(tx_ring->tail), tx_ring->next_to_use,
  1024. tx_ring->next_to_clean, tx_ring->buffer_info[eop].time_stamp,
  1025. eop, jiffies, eop_desc->upper.fields.status, er32(STATUS),
  1026. phy_status, phy_1000t_status, phy_ext_status, pci_status);
  1027. e1000e_dump(adapter);
  1028. /* Suggest workaround for known h/w issue */
  1029. if ((hw->mac.type == e1000_pchlan) && (er32(CTRL) & E1000_CTRL_TFCE))
  1030. e_err("Try turning off Tx pause (flow control) via ethtool\n");
  1031. }
  1032. /**
  1033. * e1000e_tx_hwtstamp_work - check for Tx time stamp
  1034. * @work: pointer to work struct
  1035. *
  1036. * This work function polls the TSYNCTXCTL valid bit to determine when a
  1037. * timestamp has been taken for the current stored skb. The timestamp must
  1038. * be for this skb because only one such packet is allowed in the queue.
  1039. */
  1040. static void e1000e_tx_hwtstamp_work(struct work_struct *work)
  1041. {
  1042. struct e1000_adapter *adapter = container_of(work, struct e1000_adapter,
  1043. tx_hwtstamp_work);
  1044. struct e1000_hw *hw = &adapter->hw;
  1045. if (er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID) {
  1046. struct sk_buff *skb = adapter->tx_hwtstamp_skb;
  1047. struct skb_shared_hwtstamps shhwtstamps;
  1048. u64 txstmp;
  1049. txstmp = er32(TXSTMPL);
  1050. txstmp |= (u64)er32(TXSTMPH) << 32;
  1051. e1000e_systim_to_hwtstamp(adapter, &shhwtstamps, txstmp);
  1052. /* Clear the global tx_hwtstamp_skb pointer and force writes
  1053. * prior to notifying the stack of a Tx timestamp.
  1054. */
  1055. adapter->tx_hwtstamp_skb = NULL;
  1056. wmb(); /* force write prior to skb_tstamp_tx */
  1057. skb_tstamp_tx(skb, &shhwtstamps);
  1058. dev_consume_skb_any(skb);
  1059. } else if (time_after(jiffies, adapter->tx_hwtstamp_start
  1060. + adapter->tx_timeout_factor * HZ)) {
  1061. dev_kfree_skb_any(adapter->tx_hwtstamp_skb);
  1062. adapter->tx_hwtstamp_skb = NULL;
  1063. adapter->tx_hwtstamp_timeouts++;
  1064. e_warn("clearing Tx timestamp hang\n");
  1065. } else {
  1066. /* reschedule to check later */
  1067. schedule_work(&adapter->tx_hwtstamp_work);
  1068. }
  1069. }
  1070. /**
  1071. * e1000_clean_tx_irq - Reclaim resources after transmit completes
  1072. * @tx_ring: Tx descriptor ring
  1073. *
  1074. * the return value indicates whether actual cleaning was done, there
  1075. * is no guarantee that everything was cleaned
  1076. **/
  1077. static bool e1000_clean_tx_irq(struct e1000_ring *tx_ring)
  1078. {
  1079. struct e1000_adapter *adapter = tx_ring->adapter;
  1080. struct net_device *netdev = adapter->netdev;
  1081. struct e1000_hw *hw = &adapter->hw;
  1082. struct e1000_tx_desc *tx_desc, *eop_desc;
  1083. struct e1000_buffer *buffer_info;
  1084. unsigned int i, eop;
  1085. unsigned int count = 0;
  1086. unsigned int total_tx_bytes = 0, total_tx_packets = 0;
  1087. unsigned int bytes_compl = 0, pkts_compl = 0;
  1088. i = tx_ring->next_to_clean;
  1089. eop = tx_ring->buffer_info[i].next_to_watch;
  1090. eop_desc = E1000_TX_DESC(*tx_ring, eop);
  1091. while ((eop_desc->upper.data & cpu_to_le32(E1000_TXD_STAT_DD)) &&
  1092. (count < tx_ring->count)) {
  1093. bool cleaned = false;
  1094. dma_rmb(); /* read buffer_info after eop_desc */
  1095. for (; !cleaned; count++) {
  1096. tx_desc = E1000_TX_DESC(*tx_ring, i);
  1097. buffer_info = &tx_ring->buffer_info[i];
  1098. cleaned = (i == eop);
  1099. if (cleaned) {
  1100. total_tx_packets += buffer_info->segs;
  1101. total_tx_bytes += buffer_info->bytecount;
  1102. if (buffer_info->skb) {
  1103. bytes_compl += buffer_info->skb->len;
  1104. pkts_compl++;
  1105. }
  1106. }
  1107. e1000_put_txbuf(tx_ring, buffer_info, false);
  1108. tx_desc->upper.data = 0;
  1109. i++;
  1110. if (i == tx_ring->count)
  1111. i = 0;
  1112. }
  1113. if (i == tx_ring->next_to_use)
  1114. break;
  1115. eop = tx_ring->buffer_info[i].next_to_watch;
  1116. eop_desc = E1000_TX_DESC(*tx_ring, eop);
  1117. }
  1118. tx_ring->next_to_clean = i;
  1119. netdev_completed_queue(netdev, pkts_compl, bytes_compl);
  1120. #define TX_WAKE_THRESHOLD 32
  1121. if (count && netif_carrier_ok(netdev) &&
  1122. e1000_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD) {
  1123. /* Make sure that anybody stopping the queue after this
  1124. * sees the new next_to_clean.
  1125. */
  1126. smp_mb();
  1127. if (netif_queue_stopped(netdev) &&
  1128. !(test_bit(__E1000_DOWN, &adapter->state))) {
  1129. netif_wake_queue(netdev);
  1130. ++adapter->restart_queue;
  1131. }
  1132. }
  1133. if (adapter->detect_tx_hung) {
  1134. /* Detect a transmit hang in hardware, this serializes the
  1135. * check with the clearing of time_stamp and movement of i
  1136. */
  1137. adapter->detect_tx_hung = false;
  1138. if (tx_ring->buffer_info[i].time_stamp &&
  1139. time_after(jiffies, tx_ring->buffer_info[i].time_stamp
  1140. + (adapter->tx_timeout_factor * HZ)) &&
  1141. !(er32(STATUS) & E1000_STATUS_TXOFF))
  1142. schedule_work(&adapter->print_hang_task);
  1143. else
  1144. adapter->tx_hang_recheck = false;
  1145. }
  1146. adapter->total_tx_bytes += total_tx_bytes;
  1147. adapter->total_tx_packets += total_tx_packets;
  1148. return count < tx_ring->count;
  1149. }
  1150. /**
  1151. * e1000_clean_rx_irq_ps - Send received data up the network stack; packet split
  1152. * @rx_ring: Rx descriptor ring
  1153. *
  1154. * the return value indicates whether actual cleaning was done, there
  1155. * is no guarantee that everything was cleaned
  1156. **/
  1157. static bool e1000_clean_rx_irq_ps(struct e1000_ring *rx_ring, int *work_done,
  1158. int work_to_do)
  1159. {
  1160. struct e1000_adapter *adapter = rx_ring->adapter;
  1161. struct e1000_hw *hw = &adapter->hw;
  1162. union e1000_rx_desc_packet_split *rx_desc, *next_rxd;
  1163. struct net_device *netdev = adapter->netdev;
  1164. struct pci_dev *pdev = adapter->pdev;
  1165. struct e1000_buffer *buffer_info, *next_buffer;
  1166. struct e1000_ps_page *ps_page;
  1167. struct sk_buff *skb;
  1168. unsigned int i, j;
  1169. u32 length, staterr;
  1170. int cleaned_count = 0;
  1171. bool cleaned = false;
  1172. unsigned int total_rx_bytes = 0, total_rx_packets = 0;
  1173. i = rx_ring->next_to_clean;
  1174. rx_desc = E1000_RX_DESC_PS(*rx_ring, i);
  1175. staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
  1176. buffer_info = &rx_ring->buffer_info[i];
  1177. while (staterr & E1000_RXD_STAT_DD) {
  1178. if (*work_done >= work_to_do)
  1179. break;
  1180. (*work_done)++;
  1181. skb = buffer_info->skb;
  1182. dma_rmb(); /* read descriptor and rx_buffer_info after status DD */
  1183. /* in the packet split case this is header only */
  1184. prefetch(skb->data - NET_IP_ALIGN);
  1185. i++;
  1186. if (i == rx_ring->count)
  1187. i = 0;
  1188. next_rxd = E1000_RX_DESC_PS(*rx_ring, i);
  1189. prefetch(next_rxd);
  1190. next_buffer = &rx_ring->buffer_info[i];
  1191. cleaned = true;
  1192. cleaned_count++;
  1193. dma_unmap_single(&pdev->dev, buffer_info->dma,
  1194. adapter->rx_ps_bsize0, DMA_FROM_DEVICE);
  1195. buffer_info->dma = 0;
  1196. /* see !EOP comment in other Rx routine */
  1197. if (!(staterr & E1000_RXD_STAT_EOP))
  1198. adapter->flags2 |= FLAG2_IS_DISCARDING;
  1199. if (adapter->flags2 & FLAG2_IS_DISCARDING) {
  1200. e_dbg("Packet Split buffers didn't pick up the full packet\n");
  1201. dev_kfree_skb_irq(skb);
  1202. if (staterr & E1000_RXD_STAT_EOP)
  1203. adapter->flags2 &= ~FLAG2_IS_DISCARDING;
  1204. goto next_desc;
  1205. }
  1206. if (unlikely((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
  1207. !(netdev->features & NETIF_F_RXALL))) {
  1208. dev_kfree_skb_irq(skb);
  1209. goto next_desc;
  1210. }
  1211. length = le16_to_cpu(rx_desc->wb.middle.length0);
  1212. if (!length) {
  1213. e_dbg("Last part of the packet spanning multiple descriptors\n");
  1214. dev_kfree_skb_irq(skb);
  1215. goto next_desc;
  1216. }
  1217. /* Good Receive */
  1218. skb_put(skb, length);
  1219. {
  1220. /* this looks ugly, but it seems compiler issues make
  1221. * it more efficient than reusing j
  1222. */
  1223. int l1 = le16_to_cpu(rx_desc->wb.upper.length[0]);
  1224. /* page alloc/put takes too long and effects small
  1225. * packet throughput, so unsplit small packets and
  1226. * save the alloc/put only valid in softirq (napi)
  1227. * context to call kmap_*
  1228. */
  1229. if (l1 && (l1 <= copybreak) &&
  1230. ((length + l1) <= adapter->rx_ps_bsize0)) {
  1231. u8 *vaddr;
  1232. ps_page = &buffer_info->ps_pages[0];
  1233. /* there is no documentation about how to call
  1234. * kmap_atomic, so we can't hold the mapping
  1235. * very long
  1236. */
  1237. dma_sync_single_for_cpu(&pdev->dev,
  1238. ps_page->dma,
  1239. PAGE_SIZE,
  1240. DMA_FROM_DEVICE);
  1241. vaddr = kmap_atomic(ps_page->page);
  1242. memcpy(skb_tail_pointer(skb), vaddr, l1);
  1243. kunmap_atomic(vaddr);
  1244. dma_sync_single_for_device(&pdev->dev,
  1245. ps_page->dma,
  1246. PAGE_SIZE,
  1247. DMA_FROM_DEVICE);
  1248. /* remove the CRC */
  1249. if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
  1250. if (!(netdev->features & NETIF_F_RXFCS))
  1251. l1 -= 4;
  1252. }
  1253. skb_put(skb, l1);
  1254. goto copydone;
  1255. } /* if */
  1256. }
  1257. for (j = 0; j < PS_PAGE_BUFFERS; j++) {
  1258. length = le16_to_cpu(rx_desc->wb.upper.length[j]);
  1259. if (!length)
  1260. break;
  1261. ps_page = &buffer_info->ps_pages[j];
  1262. dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
  1263. DMA_FROM_DEVICE);
  1264. ps_page->dma = 0;
  1265. skb_fill_page_desc(skb, j, ps_page->page, 0, length);
  1266. ps_page->page = NULL;
  1267. skb->len += length;
  1268. skb->data_len += length;
  1269. skb->truesize += PAGE_SIZE;
  1270. }
  1271. /* strip the ethernet crc, problem is we're using pages now so
  1272. * this whole operation can get a little cpu intensive
  1273. */
  1274. if (!(adapter->flags2 & FLAG2_CRC_STRIPPING)) {
  1275. if (!(netdev->features & NETIF_F_RXFCS))
  1276. pskb_trim(skb, skb->len - 4);
  1277. }
  1278. copydone:
  1279. total_rx_bytes += skb->len;
  1280. total_rx_packets++;
  1281. e1000_rx_checksum(adapter, staterr, skb);
  1282. e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
  1283. if (rx_desc->wb.upper.header_status &
  1284. cpu_to_le16(E1000_RXDPS_HDRSTAT_HDRSP))
  1285. adapter->rx_hdr_split++;
  1286. e1000_receive_skb(adapter, netdev, skb, staterr,
  1287. rx_desc->wb.middle.vlan);
  1288. next_desc:
  1289. rx_desc->wb.middle.status_error &= cpu_to_le32(~0xFF);
  1290. buffer_info->skb = NULL;
  1291. /* return some buffers to hardware, one at a time is too slow */
  1292. if (cleaned_count >= E1000_RX_BUFFER_WRITE) {
  1293. adapter->alloc_rx_buf(rx_ring, cleaned_count,
  1294. GFP_ATOMIC);
  1295. cleaned_count = 0;
  1296. }
  1297. /* use prefetched values */
  1298. rx_desc = next_rxd;
  1299. buffer_info = next_buffer;
  1300. staterr = le32_to_cpu(rx_desc->wb.middle.status_error);
  1301. }
  1302. rx_ring->next_to_clean = i;
  1303. cleaned_count = e1000_desc_unused(rx_ring);
  1304. if (cleaned_count)
  1305. adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
  1306. adapter->total_rx_bytes += total_rx_bytes;
  1307. adapter->total_rx_packets += total_rx_packets;
  1308. return cleaned;
  1309. }
  1310. /**
  1311. * e1000_consume_page - helper function
  1312. **/
  1313. static void e1000_consume_page(struct e1000_buffer *bi, struct sk_buff *skb,
  1314. u16 length)
  1315. {
  1316. bi->page = NULL;
  1317. skb->len += length;
  1318. skb->data_len += length;
  1319. skb->truesize += PAGE_SIZE;
  1320. }
  1321. /**
  1322. * e1000_clean_jumbo_rx_irq - Send received data up the network stack; legacy
  1323. * @adapter: board private structure
  1324. *
  1325. * the return value indicates whether actual cleaning was done, there
  1326. * is no guarantee that everything was cleaned
  1327. **/
  1328. static bool e1000_clean_jumbo_rx_irq(struct e1000_ring *rx_ring, int *work_done,
  1329. int work_to_do)
  1330. {
  1331. struct e1000_adapter *adapter = rx_ring->adapter;
  1332. struct net_device *netdev = adapter->netdev;
  1333. struct pci_dev *pdev = adapter->pdev;
  1334. union e1000_rx_desc_extended *rx_desc, *next_rxd;
  1335. struct e1000_buffer *buffer_info, *next_buffer;
  1336. u32 length, staterr;
  1337. unsigned int i;
  1338. int cleaned_count = 0;
  1339. bool cleaned = false;
  1340. unsigned int total_rx_bytes = 0, total_rx_packets = 0;
  1341. struct skb_shared_info *shinfo;
  1342. i = rx_ring->next_to_clean;
  1343. rx_desc = E1000_RX_DESC_EXT(*rx_ring, i);
  1344. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  1345. buffer_info = &rx_ring->buffer_info[i];
  1346. while (staterr & E1000_RXD_STAT_DD) {
  1347. struct sk_buff *skb;
  1348. if (*work_done >= work_to_do)
  1349. break;
  1350. (*work_done)++;
  1351. dma_rmb(); /* read descriptor and rx_buffer_info after status DD */
  1352. skb = buffer_info->skb;
  1353. buffer_info->skb = NULL;
  1354. ++i;
  1355. if (i == rx_ring->count)
  1356. i = 0;
  1357. next_rxd = E1000_RX_DESC_EXT(*rx_ring, i);
  1358. prefetch(next_rxd);
  1359. next_buffer = &rx_ring->buffer_info[i];
  1360. cleaned = true;
  1361. cleaned_count++;
  1362. dma_unmap_page(&pdev->dev, buffer_info->dma, PAGE_SIZE,
  1363. DMA_FROM_DEVICE);
  1364. buffer_info->dma = 0;
  1365. length = le16_to_cpu(rx_desc->wb.upper.length);
  1366. /* errors is only valid for DD + EOP descriptors */
  1367. if (unlikely((staterr & E1000_RXD_STAT_EOP) &&
  1368. ((staterr & E1000_RXDEXT_ERR_FRAME_ERR_MASK) &&
  1369. !(netdev->features & NETIF_F_RXALL)))) {
  1370. /* recycle both page and skb */
  1371. buffer_info->skb = skb;
  1372. /* an error means any chain goes out the window too */
  1373. if (rx_ring->rx_skb_top)
  1374. dev_kfree_skb_irq(rx_ring->rx_skb_top);
  1375. rx_ring->rx_skb_top = NULL;
  1376. goto next_desc;
  1377. }
  1378. #define rxtop (rx_ring->rx_skb_top)
  1379. if (!(staterr & E1000_RXD_STAT_EOP)) {
  1380. /* this descriptor is only the beginning (or middle) */
  1381. if (!rxtop) {
  1382. /* this is the beginning of a chain */
  1383. rxtop = skb;
  1384. skb_fill_page_desc(rxtop, 0, buffer_info->page,
  1385. 0, length);
  1386. } else {
  1387. /* this is the middle of a chain */
  1388. shinfo = skb_shinfo(rxtop);
  1389. skb_fill_page_desc(rxtop, shinfo->nr_frags,
  1390. buffer_info->page, 0,
  1391. length);
  1392. /* re-use the skb, only consumed the page */
  1393. buffer_info->skb = skb;
  1394. }
  1395. e1000_consume_page(buffer_info, rxtop, length);
  1396. goto next_desc;
  1397. } else {
  1398. if (rxtop) {
  1399. /* end of the chain */
  1400. shinfo = skb_shinfo(rxtop);
  1401. skb_fill_page_desc(rxtop, shinfo->nr_frags,
  1402. buffer_info->page, 0,
  1403. length);
  1404. /* re-use the current skb, we only consumed the
  1405. * page
  1406. */
  1407. buffer_info->skb = skb;
  1408. skb = rxtop;
  1409. rxtop = NULL;
  1410. e1000_consume_page(buffer_info, skb, length);
  1411. } else {
  1412. /* no chain, got EOP, this buf is the packet
  1413. * copybreak to save the put_page/alloc_page
  1414. */
  1415. if (length <= copybreak &&
  1416. skb_tailroom(skb) >= length) {
  1417. u8 *vaddr;
  1418. vaddr = kmap_atomic(buffer_info->page);
  1419. memcpy(skb_tail_pointer(skb), vaddr,
  1420. length);
  1421. kunmap_atomic(vaddr);
  1422. /* re-use the page, so don't erase
  1423. * buffer_info->page
  1424. */
  1425. skb_put(skb, length);
  1426. } else {
  1427. skb_fill_page_desc(skb, 0,
  1428. buffer_info->page, 0,
  1429. length);
  1430. e1000_consume_page(buffer_info, skb,
  1431. length);
  1432. }
  1433. }
  1434. }
  1435. /* Receive Checksum Offload */
  1436. e1000_rx_checksum(adapter, staterr, skb);
  1437. e1000_rx_hash(netdev, rx_desc->wb.lower.hi_dword.rss, skb);
  1438. /* probably a little skewed due to removing CRC */
  1439. total_rx_bytes += skb->len;
  1440. total_rx_packets++;
  1441. /* eth type trans needs skb->data to point to something */
  1442. if (!pskb_may_pull(skb, ETH_HLEN)) {
  1443. e_err("pskb_may_pull failed.\n");
  1444. dev_kfree_skb_irq(skb);
  1445. goto next_desc;
  1446. }
  1447. e1000_receive_skb(adapter, netdev, skb, staterr,
  1448. rx_desc->wb.upper.vlan);
  1449. next_desc:
  1450. rx_desc->wb.upper.status_error &= cpu_to_le32(~0xFF);
  1451. /* return some buffers to hardware, one at a time is too slow */
  1452. if (unlikely(cleaned_count >= E1000_RX_BUFFER_WRITE)) {
  1453. adapter->alloc_rx_buf(rx_ring, cleaned_count,
  1454. GFP_ATOMIC);
  1455. cleaned_count = 0;
  1456. }
  1457. /* use prefetched values */
  1458. rx_desc = next_rxd;
  1459. buffer_info = next_buffer;
  1460. staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
  1461. }
  1462. rx_ring->next_to_clean = i;
  1463. cleaned_count = e1000_desc_unused(rx_ring);
  1464. if (cleaned_count)
  1465. adapter->alloc_rx_buf(rx_ring, cleaned_count, GFP_ATOMIC);
  1466. adapter->total_rx_bytes += total_rx_bytes;
  1467. adapter->total_rx_packets += total_rx_packets;
  1468. return cleaned;
  1469. }
  1470. /**
  1471. * e1000_clean_rx_ring - Free Rx Buffers per Queue
  1472. * @rx_ring: Rx descriptor ring
  1473. **/
  1474. static void e1000_clean_rx_ring(struct e1000_ring *rx_ring)
  1475. {
  1476. struct e1000_adapter *adapter = rx_ring->adapter;
  1477. struct e1000_buffer *buffer_info;
  1478. struct e1000_ps_page *ps_page;
  1479. struct pci_dev *pdev = adapter->pdev;
  1480. unsigned int i, j;
  1481. /* Free all the Rx ring sk_buffs */
  1482. for (i = 0; i < rx_ring->count; i++) {
  1483. buffer_info = &rx_ring->buffer_info[i];
  1484. if (buffer_info->dma) {
  1485. if (adapter->clean_rx == e1000_clean_rx_irq)
  1486. dma_unmap_single(&pdev->dev, buffer_info->dma,
  1487. adapter->rx_buffer_len,
  1488. DMA_FROM_DEVICE);
  1489. else if (adapter->clean_rx == e1000_clean_jumbo_rx_irq)
  1490. dma_unmap_page(&pdev->dev, buffer_info->dma,
  1491. PAGE_SIZE, DMA_FROM_DEVICE);
  1492. else if (adapter->clean_rx == e1000_clean_rx_irq_ps)
  1493. dma_unmap_single(&pdev->dev, buffer_info->dma,
  1494. adapter->rx_ps_bsize0,
  1495. DMA_FROM_DEVICE);
  1496. buffer_info->dma = 0;
  1497. }
  1498. if (buffer_info->page) {
  1499. put_page(buffer_info->page);
  1500. buffer_info->page = NULL;
  1501. }
  1502. if (buffer_info->skb) {
  1503. dev_kfree_skb(buffer_info->skb);
  1504. buffer_info->skb = NULL;
  1505. }
  1506. for (j = 0; j < PS_PAGE_BUFFERS; j++) {
  1507. ps_page = &buffer_info->ps_pages[j];
  1508. if (!ps_page->page)
  1509. break;
  1510. dma_unmap_page(&pdev->dev, ps_page->dma, PAGE_SIZE,
  1511. DMA_FROM_DEVICE);
  1512. ps_page->dma = 0;
  1513. put_page(ps_page->page);
  1514. ps_page->page = NULL;
  1515. }
  1516. }
  1517. /* there also may be some cached data from a chained receive */
  1518. if (rx_ring->rx_skb_top) {
  1519. dev_kfree_skb(rx_ring->rx_skb_top);
  1520. rx_ring->rx_skb_top = NULL;
  1521. }
  1522. /* Zero out the descriptor ring */
  1523. memset(rx_ring->desc, 0, rx_ring->size);
  1524. rx_ring->next_to_clean = 0;
  1525. rx_ring->next_to_use = 0;
  1526. adapter->flags2 &= ~FLAG2_IS_DISCARDING;
  1527. }
  1528. static void e1000e_downshift_workaround(struct work_struct *work)
  1529. {
  1530. struct e1000_adapter *adapter = container_of(work,
  1531. struct e1000_adapter,
  1532. downshift_task);
  1533. if (test_bit(__E1000_DOWN, &adapter->state))
  1534. return;
  1535. e1000e_gig_downshift_workaround_ich8lan(&adapter->hw);
  1536. }
  1537. /**
  1538. * e1000_intr_msi - Interrupt Handler
  1539. * @irq: interrupt number
  1540. * @data: pointer to a network interface device structure
  1541. **/
  1542. static irqreturn_t e1000_intr_msi(int __always_unused irq, void *data)
  1543. {
  1544. struct net_device *netdev = data;
  1545. struct e1000_adapter *adapter = netdev_priv(netdev);
  1546. struct e1000_hw *hw = &adapter->hw;
  1547. u32 icr = er32(ICR);
  1548. /* read ICR disables interrupts using IAM */
  1549. if (icr & E1000_ICR_LSC) {
  1550. hw->mac.get_link_status = true;
  1551. /* ICH8 workaround-- Call gig speed drop workaround on cable
  1552. * disconnect (LSC) before accessing any PHY registers
  1553. */
  1554. if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
  1555. (!(er32(STATUS) & E1000_STATUS_LU)))
  1556. schedule_work(&adapter->downshift_task);
  1557. /* 80003ES2LAN workaround-- For packet buffer work-around on
  1558. * link down event; disable receives here in the ISR and reset
  1559. * adapter in watchdog
  1560. */
  1561. if (netif_carrier_ok(netdev) &&
  1562. adapter->flags & FLAG_RX_NEEDS_RESTART) {
  1563. /* disable receives */
  1564. u32 rctl = er32(RCTL);
  1565. ew32(RCTL, rctl & ~E1000_RCTL_EN);
  1566. adapter->flags |= FLAG_RESTART_NOW;
  1567. }
  1568. /* guard against interrupt when we're going down */
  1569. if (!test_bit(__E1000_DOWN, &adapter->state))
  1570. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  1571. }
  1572. /* Reset on uncorrectable ECC error */
  1573. if ((icr & E1000_ICR_ECCER) && (hw->mac.type >= e1000_pch_lpt)) {
  1574. u32 pbeccsts = er32(PBECCSTS);
  1575. adapter->corr_errors +=
  1576. pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
  1577. adapter->uncorr_errors +=
  1578. (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
  1579. E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
  1580. /* Do the reset outside of interrupt context */
  1581. schedule_work(&adapter->reset_task);
  1582. /* return immediately since reset is imminent */
  1583. return IRQ_HANDLED;
  1584. }
  1585. if (napi_schedule_prep(&adapter->napi)) {
  1586. adapter->total_tx_bytes = 0;
  1587. adapter->total_tx_packets = 0;
  1588. adapter->total_rx_bytes = 0;
  1589. adapter->total_rx_packets = 0;
  1590. __napi_schedule(&adapter->napi);
  1591. }
  1592. return IRQ_HANDLED;
  1593. }
  1594. /**
  1595. * e1000_intr - Interrupt Handler
  1596. * @irq: interrupt number
  1597. * @data: pointer to a network interface device structure
  1598. **/
  1599. static irqreturn_t e1000_intr(int __always_unused irq, void *data)
  1600. {
  1601. struct net_device *netdev = data;
  1602. struct e1000_adapter *adapter = netdev_priv(netdev);
  1603. struct e1000_hw *hw = &adapter->hw;
  1604. u32 rctl, icr = er32(ICR);
  1605. if (!icr || test_bit(__E1000_DOWN, &adapter->state))
  1606. return IRQ_NONE; /* Not our interrupt */
  1607. /* IMS will not auto-mask if INT_ASSERTED is not set, and if it is
  1608. * not set, then the adapter didn't send an interrupt
  1609. */
  1610. if (!(icr & E1000_ICR_INT_ASSERTED))
  1611. return IRQ_NONE;
  1612. /* Interrupt Auto-Mask...upon reading ICR,
  1613. * interrupts are masked. No need for the
  1614. * IMC write
  1615. */
  1616. if (icr & E1000_ICR_LSC) {
  1617. hw->mac.get_link_status = true;
  1618. /* ICH8 workaround-- Call gig speed drop workaround on cable
  1619. * disconnect (LSC) before accessing any PHY registers
  1620. */
  1621. if ((adapter->flags & FLAG_LSC_GIG_SPEED_DROP) &&
  1622. (!(er32(STATUS) & E1000_STATUS_LU)))
  1623. schedule_work(&adapter->downshift_task);
  1624. /* 80003ES2LAN workaround--
  1625. * For packet buffer work-around on link down event;
  1626. * disable receives here in the ISR and
  1627. * reset adapter in watchdog
  1628. */
  1629. if (netif_carrier_ok(netdev) &&
  1630. (adapter->flags & FLAG_RX_NEEDS_RESTART)) {
  1631. /* disable receives */
  1632. rctl = er32(RCTL);
  1633. ew32(RCTL, rctl & ~E1000_RCTL_EN);
  1634. adapter->flags |= FLAG_RESTART_NOW;
  1635. }
  1636. /* guard against interrupt when we're going down */
  1637. if (!test_bit(__E1000_DOWN, &adapter->state))
  1638. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  1639. }
  1640. /* Reset on uncorrectable ECC error */
  1641. if ((icr & E1000_ICR_ECCER) && (hw->mac.type >= e1000_pch_lpt)) {
  1642. u32 pbeccsts = er32(PBECCSTS);
  1643. adapter->corr_errors +=
  1644. pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
  1645. adapter->uncorr_errors +=
  1646. (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
  1647. E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
  1648. /* Do the reset outside of interrupt context */
  1649. schedule_work(&adapter->reset_task);
  1650. /* return immediately since reset is imminent */
  1651. return IRQ_HANDLED;
  1652. }
  1653. if (napi_schedule_prep(&adapter->napi)) {
  1654. adapter->total_tx_bytes = 0;
  1655. adapter->total_tx_packets = 0;
  1656. adapter->total_rx_bytes = 0;
  1657. adapter->total_rx_packets = 0;
  1658. __napi_schedule(&adapter->napi);
  1659. }
  1660. return IRQ_HANDLED;
  1661. }
  1662. static irqreturn_t e1000_msix_other(int __always_unused irq, void *data)
  1663. {
  1664. struct net_device *netdev = data;
  1665. struct e1000_adapter *adapter = netdev_priv(netdev);
  1666. struct e1000_hw *hw = &adapter->hw;
  1667. u32 icr;
  1668. bool enable = true;
  1669. icr = er32(ICR);
  1670. if (icr & E1000_ICR_RXO) {
  1671. ew32(ICR, E1000_ICR_RXO);
  1672. enable = false;
  1673. /* napi poll will re-enable Other, make sure it runs */
  1674. if (napi_schedule_prep(&adapter->napi)) {
  1675. adapter->total_rx_bytes = 0;
  1676. adapter->total_rx_packets = 0;
  1677. __napi_schedule(&adapter->napi);
  1678. }
  1679. }
  1680. if (icr & E1000_ICR_LSC) {
  1681. ew32(ICR, E1000_ICR_LSC);
  1682. hw->mac.get_link_status = true;
  1683. /* guard against interrupt when we're going down */
  1684. if (!test_bit(__E1000_DOWN, &adapter->state))
  1685. mod_timer(&adapter->watchdog_timer, jiffies + 1);
  1686. }
  1687. if (enable && !test_bit(__E1000_DOWN, &adapter->state))
  1688. ew32(IMS, E1000_IMS_OTHER);
  1689. return IRQ_HANDLED;
  1690. }
  1691. static irqreturn_t e1000_intr_msix_tx(int __always_unused irq, void *data)
  1692. {
  1693. struct net_device *netdev = data;
  1694. struct e1000_adapter *adapter = netdev_priv(netdev);
  1695. struct e1000_hw *hw = &adapter->hw;
  1696. struct e1000_ring *tx_ring = adapter->tx_ring;
  1697. adapter->total_tx_bytes = 0;
  1698. adapter->total_tx_packets = 0;
  1699. if (!e1000_clean_tx_irq(tx_ring))
  1700. /* Ring was not completely cleaned, so fire another interrupt */
  1701. ew32(ICS, tx_ring->ims_val);
  1702. if (!test_bit(__E1000_DOWN, &adapter->state))
  1703. ew32(IMS, adapter->tx_ring->ims_val);
  1704. return IRQ_HANDLED;
  1705. }
  1706. static irqreturn_t e1000_intr_msix_rx(int __always_unused irq, void *data)
  1707. {
  1708. struct net_device *netdev = data;
  1709. struct e1000_adapter *adapter = netdev_priv(netdev);
  1710. struct e1000_ring *rx_ring = adapter->rx_ring;
  1711. /* Write the ITR value calculated at the end of the
  1712. * previous interrupt.
  1713. */
  1714. if (rx_ring->set_itr) {
  1715. u32 itr = rx_ring->itr_val ?
  1716. 1000000000 / (rx_ring->itr_val * 256) : 0;
  1717. writel(itr, rx_ring->itr_register);
  1718. rx_ring->set_itr = 0;
  1719. }
  1720. if (napi_schedule_prep(&adapter->napi)) {
  1721. adapter->total_rx_bytes = 0;
  1722. adapter->total_rx_packets = 0;
  1723. __napi_schedule(&adapter->napi);
  1724. }
  1725. return IRQ_HANDLED;
  1726. }
  1727. /**
  1728. * e1000_configure_msix - Configure MSI-X hardware
  1729. *
  1730. * e1000_configure_msix sets up the hardware to properly
  1731. * generate MSI-X interrupts.
  1732. **/
  1733. static void e1000_configure_msix(struct e1000_adapter *adapter)
  1734. {
  1735. struct e1000_hw *hw = &adapter->hw;
  1736. struct e1000_ring *rx_ring = adapter->rx_ring;
  1737. struct e1000_ring *tx_ring = adapter->tx_ring;
  1738. int vector = 0;
  1739. u32 ctrl_ext, ivar = 0;
  1740. adapter->eiac_mask = 0;
  1741. /* Workaround issue with spurious interrupts on 82574 in MSI-X mode */
  1742. if (hw->mac.type == e1000_82574) {
  1743. u32 rfctl = er32(RFCTL);
  1744. rfctl |= E1000_RFCTL_ACK_DIS;
  1745. ew32(RFCTL, rfctl);
  1746. }
  1747. /* Configure Rx vector */
  1748. rx_ring->ims_val = E1000_IMS_RXQ0;
  1749. adapter->eiac_mask |= rx_ring->ims_val;
  1750. if (rx_ring->itr_val)
  1751. writel(1000000000 / (rx_ring->itr_val * 256),
  1752. rx_ring->itr_register);
  1753. else
  1754. writel(1, rx_ring->itr_register);
  1755. ivar = E1000_IVAR_INT_ALLOC_VALID | vector;
  1756. /* Configure Tx vector */
  1757. tx_ring->ims_val = E1000_IMS_TXQ0;
  1758. vector++;
  1759. if (tx_ring->itr_val)
  1760. writel(1000000000 / (tx_ring->itr_val * 256),
  1761. tx_ring->itr_register);
  1762. else
  1763. writel(1, tx_ring->itr_register);
  1764. adapter->eiac_mask |= tx_ring->ims_val;
  1765. ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 8);
  1766. /* set vector for Other Causes, e.g. link changes */
  1767. vector++;
  1768. ivar |= ((E1000_IVAR_INT_ALLOC_VALID | vector) << 16);
  1769. if (rx_ring->itr_val)
  1770. writel(1000000000 / (rx_ring->itr_val * 256),
  1771. hw->hw_addr + E1000_EITR_82574(vector));
  1772. else
  1773. writel(1, hw->hw_addr + E1000_EITR_82574(vector));
  1774. adapter->eiac_mask |= E1000_IMS_OTHER;
  1775. /* Cause Tx interrupts on every write back */
  1776. ivar |= BIT(31);
  1777. ew32(IVAR, ivar);
  1778. /* enable MSI-X PBA support */
  1779. ctrl_ext = er32(CTRL_EXT) & ~E1000_CTRL_EXT_IAME;
  1780. ctrl_ext |= E1000_CTRL_EXT_PBA_CLR | E1000_CTRL_EXT_EIAME;
  1781. ew32(CTRL_EXT, ctrl_ext);
  1782. e1e_flush();
  1783. }
  1784. void e1000e_reset_interrupt_capability(struct e1000_adapter *adapter)
  1785. {
  1786. if (adapter->msix_entries) {
  1787. pci_disable_msix(adapter->pdev);
  1788. kfree(adapter->msix_entries);
  1789. adapter->msix_entries = NULL;
  1790. } else if (adapter->flags & FLAG_MSI_ENABLED) {
  1791. pci_disable_msi(adapter->pdev);
  1792. adapter->flags &= ~FLAG_MSI_ENABLED;
  1793. }
  1794. }
  1795. /**
  1796. * e1000e_set_interrupt_capability - set MSI or MSI-X if supported
  1797. *
  1798. * Attempt to configure interrupts using the best available
  1799. * capabilities of the hardware and kernel.
  1800. **/
  1801. void e1000e_set_interrupt_capability(struct e1000_adapter *adapter)
  1802. {
  1803. int err;
  1804. int i;
  1805. switch (adapter->int_mode) {
  1806. case E1000E_INT_MODE_MSIX:
  1807. if (adapter->flags & FLAG_HAS_MSIX) {
  1808. adapter->num_vectors = 3; /* RxQ0, TxQ0 and other */
  1809. adapter->msix_entries = kcalloc(adapter->num_vectors,
  1810. sizeof(struct
  1811. msix_entry),
  1812. GFP_KERNEL);
  1813. if (adapter->msix_entries) {
  1814. struct e1000_adapter *a = adapter;
  1815. for (i = 0; i < adapter->num_vectors; i++)
  1816. adapter->msix_entries[i].entry = i;
  1817. err = pci_enable_msix_range(a->pdev,
  1818. a->msix_entries,
  1819. a->num_vectors,
  1820. a->num_vectors);
  1821. if (err > 0)
  1822. return;
  1823. }
  1824. /* MSI-X failed, so fall through and try MSI */
  1825. e_err("Failed to initialize MSI-X interrupts. Falling back to MSI interrupts.\n");
  1826. e1000e_reset_interrupt_capability(adapter);
  1827. }
  1828. adapter->int_mode = E1000E_INT_MODE_MSI;
  1829. /* Fall through */
  1830. case E1000E_INT_MODE_MSI:
  1831. if (!pci_enable_msi(adapter->pdev)) {
  1832. adapter->flags |= FLAG_MSI_ENABLED;
  1833. } else {
  1834. adapter->int_mode = E1000E_INT_MODE_LEGACY;
  1835. e_err("Failed to initialize MSI interrupts. Falling back to legacy interrupts.\n");
  1836. }
  1837. /* Fall through */
  1838. case E1000E_INT_MODE_LEGACY:
  1839. /* Don't do anything; this is the system default */
  1840. break;
  1841. }
  1842. /* store the number of vectors being used */
  1843. adapter->num_vectors = 1;
  1844. }
  1845. /**
  1846. * e1000_request_msix - Initialize MSI-X interrupts
  1847. *
  1848. * e1000_request_msix allocates MSI-X vectors and requests interrupts from the
  1849. * kernel.
  1850. **/
  1851. static int e1000_request_msix(struct e1000_adapter *adapter)
  1852. {
  1853. struct net_device *netdev = adapter->netdev;
  1854. int err = 0, vector = 0;
  1855. if (strlen(netdev->name) < (IFNAMSIZ - 5))
  1856. snprintf(adapter->rx_ring->name,
  1857. sizeof(adapter->rx_ring->name) - 1,
  1858. "%s-rx-0", netdev->name);
  1859. else
  1860. memcpy(adapter->rx_ring->name, netdev->name, IFNAMSIZ);
  1861. err = request_irq(adapter->msix_entries[vector].vector,
  1862. e1000_intr_msix_rx, 0, adapter->rx_ring->name,
  1863. netdev);
  1864. if (err)
  1865. return err;
  1866. adapter->rx_ring->itr_register = adapter->hw.hw_addr +
  1867. E1000_EITR_82574(vector);
  1868. adapter->rx_ring->itr_val = adapter->itr;
  1869. vector++;
  1870. if (strlen(netdev->name) < (IFNAMSIZ - 5))
  1871. snprintf(adapter->tx_ring->name,
  1872. sizeof(adapter->tx_ring->name) - 1,
  1873. "%s-tx-0", netdev->name);
  1874. else
  1875. memcpy(adapter->tx_ring->name, netdev->name, IFNAMSIZ);
  1876. err = request_irq(adapter->msix_entries[vector].vector,
  1877. e1000_intr_msix_tx, 0, adapter->tx_ring->name,
  1878. netdev);
  1879. if (err)
  1880. return err;
  1881. adapter->tx_ring->itr_register = adapter->hw.hw_addr +
  1882. E1000_EITR_82574(vector);
  1883. adapter->tx_ring->itr_val = adapter->itr;
  1884. vector++;
  1885. err = request_irq(adapter->msix_entries[vector].vector,
  1886. e1000_msix_other, 0, netdev->name, netdev);
  1887. if (err)
  1888. return err;
  1889. e1000_configure_msix(adapter);
  1890. return 0;
  1891. }
  1892. /**
  1893. * e1000_request_irq - initialize interrupts
  1894. *
  1895. * Attempts to configure interrupts using the best available
  1896. * capabilities of the hardware and kernel.
  1897. **/
  1898. static int e1000_request_irq(struct e1000_adapter *adapter)
  1899. {
  1900. struct net_device *netdev = adapter->netdev;
  1901. int err;
  1902. if (adapter->msix_entries) {
  1903. err = e1000_request_msix(adapter);
  1904. if (!err)
  1905. return err;
  1906. /* fall back to MSI */
  1907. e1000e_reset_interrupt_capability(adapter);
  1908. adapter->int_mode = E1000E_INT_MODE_MSI;
  1909. e1000e_set_interrupt_capability(adapter);
  1910. }
  1911. if (adapter->flags & FLAG_MSI_ENABLED) {
  1912. err = request_irq(adapter->pdev->irq, e1000_intr_msi, 0,
  1913. netdev->name, netdev);
  1914. if (!err)
  1915. return err;
  1916. /* fall back to legacy interrupt */
  1917. e1000e_reset_interrupt_capability(adapter);
  1918. adapter->int_mode = E1000E_INT_MODE_LEGACY;
  1919. }
  1920. err = request_irq(adapter->pdev->irq, e1000_intr, IRQF_SHARED,
  1921. netdev->name, netdev);
  1922. if (err)
  1923. e_err("Unable to allocate interrupt, Error: %d\n", err);
  1924. return err;
  1925. }
  1926. static void e1000_free_irq(struct e1000_adapter *adapter)
  1927. {
  1928. struct net_device *netdev = adapter->netdev;
  1929. if (adapter->msix_entries) {
  1930. int vector = 0;
  1931. free_irq(adapter->msix_entries[vector].vector, netdev);
  1932. vector++;
  1933. free_irq(adapter->msix_entries[vector].vector, netdev);
  1934. vector++;
  1935. /* Other Causes interrupt vector */
  1936. free_irq(adapter->msix_entries[vector].vector, netdev);
  1937. return;
  1938. }
  1939. free_irq(adapter->pdev->irq, netdev);
  1940. }
  1941. /**
  1942. * e1000_irq_disable - Mask off interrupt generation on the NIC
  1943. **/
  1944. static void e1000_irq_disable(struct e1000_adapter *adapter)
  1945. {
  1946. struct e1000_hw *hw = &adapter->hw;
  1947. ew32(IMC, ~0);
  1948. if (adapter->msix_entries)
  1949. ew32(EIAC_82574, 0);
  1950. e1e_flush();
  1951. if (adapter->msix_entries) {
  1952. int i;
  1953. for (i = 0; i < adapter->num_vectors; i++)
  1954. synchronize_irq(adapter->msix_entries[i].vector);
  1955. } else {
  1956. synchronize_irq(adapter->pdev->irq);
  1957. }
  1958. }
  1959. /**
  1960. * e1000_irq_enable - Enable default interrupt generation settings
  1961. **/
  1962. static void e1000_irq_enable(struct e1000_adapter *adapter)
  1963. {
  1964. struct e1000_hw *hw = &adapter->hw;
  1965. if (adapter->msix_entries) {
  1966. ew32(EIAC_82574, adapter->eiac_mask & E1000_EIAC_MASK_82574);
  1967. ew32(IMS, adapter->eiac_mask | E1000_IMS_LSC);
  1968. } else if (hw->mac.type >= e1000_pch_lpt) {
  1969. ew32(IMS, IMS_ENABLE_MASK | E1000_IMS_ECCER);
  1970. } else {
  1971. ew32(IMS, IMS_ENABLE_MASK);
  1972. }
  1973. e1e_flush();
  1974. }
  1975. /**
  1976. * e1000e_get_hw_control - get control of the h/w from f/w
  1977. * @adapter: address of board private structure
  1978. *
  1979. * e1000e_get_hw_control sets {CTRL_EXT|SWSM}:DRV_LOAD bit.
  1980. * For ASF and Pass Through versions of f/w this means that
  1981. * the driver is loaded. For AMT version (only with 82573)
  1982. * of the f/w this means that the network i/f is open.
  1983. **/
  1984. void e1000e_get_hw_control(struct e1000_adapter *adapter)
  1985. {
  1986. struct e1000_hw *hw = &adapter->hw;
  1987. u32 ctrl_ext;
  1988. u32 swsm;
  1989. /* Let firmware know the driver has taken over */
  1990. if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
  1991. swsm = er32(SWSM);
  1992. ew32(SWSM, swsm | E1000_SWSM_DRV_LOAD);
  1993. } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
  1994. ctrl_ext = er32(CTRL_EXT);
  1995. ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_DRV_LOAD);
  1996. }
  1997. }
  1998. /**
  1999. * e1000e_release_hw_control - release control of the h/w to f/w
  2000. * @adapter: address of board private structure
  2001. *
  2002. * e1000e_release_hw_control resets {CTRL_EXT|SWSM}:DRV_LOAD bit.
  2003. * For ASF and Pass Through versions of f/w this means that the
  2004. * driver is no longer loaded. For AMT version (only with 82573) i
  2005. * of the f/w this means that the network i/f is closed.
  2006. *
  2007. **/
  2008. void e1000e_release_hw_control(struct e1000_adapter *adapter)
  2009. {
  2010. struct e1000_hw *hw = &adapter->hw;
  2011. u32 ctrl_ext;
  2012. u32 swsm;
  2013. /* Let firmware taken over control of h/w */
  2014. if (adapter->flags & FLAG_HAS_SWSM_ON_LOAD) {
  2015. swsm = er32(SWSM);
  2016. ew32(SWSM, swsm & ~E1000_SWSM_DRV_LOAD);
  2017. } else if (adapter->flags & FLAG_HAS_CTRLEXT_ON_LOAD) {
  2018. ctrl_ext = er32(CTRL_EXT);
  2019. ew32(CTRL_EXT, ctrl_ext & ~E1000_CTRL_EXT_DRV_LOAD);
  2020. }
  2021. }
  2022. /**
  2023. * e1000_alloc_ring_dma - allocate memory for a ring structure
  2024. **/
  2025. static int e1000_alloc_ring_dma(struct e1000_adapter *adapter,
  2026. struct e1000_ring *ring)
  2027. {
  2028. struct pci_dev *pdev = adapter->pdev;
  2029. ring->desc = dma_alloc_coherent(&pdev->dev, ring->size, &ring->dma,
  2030. GFP_KERNEL);
  2031. if (!ring->desc)
  2032. return -ENOMEM;
  2033. return 0;
  2034. }
  2035. /**
  2036. * e1000e_setup_tx_resources - allocate Tx resources (Descriptors)
  2037. * @tx_ring: Tx descriptor ring
  2038. *
  2039. * Return 0 on success, negative on failure
  2040. **/
  2041. int e1000e_setup_tx_resources(struct e1000_ring *tx_ring)
  2042. {
  2043. struct e1000_adapter *adapter = tx_ring->adapter;
  2044. int err = -ENOMEM, size;
  2045. size = sizeof(struct e1000_buffer) * tx_ring->count;
  2046. tx_ring->buffer_info = vzalloc(size);
  2047. if (!tx_ring->buffer_info)
  2048. goto err;
  2049. /* round up to nearest 4K */
  2050. tx_ring->size = tx_ring->count * sizeof(struct e1000_tx_desc);
  2051. tx_ring->size = ALIGN(tx_ring->size, 4096);
  2052. err = e1000_alloc_ring_dma(adapter, tx_ring);
  2053. if (err)
  2054. goto err;
  2055. tx_ring->next_to_use = 0;
  2056. tx_ring->next_to_clean = 0;
  2057. return 0;
  2058. err:
  2059. vfree(tx_ring->buffer_info);
  2060. e_err("Unable to allocate memory for the transmit descriptor ring\n");
  2061. return err;
  2062. }
  2063. /**
  2064. * e1000e_setup_rx_resources - allocate Rx resources (Descriptors)
  2065. * @rx_ring: Rx descriptor ring
  2066. *
  2067. * Returns 0 on success, negative on failure
  2068. **/
  2069. int e1000e_setup_rx_resources(struct e1000_ring *rx_ring)
  2070. {
  2071. struct e1000_adapter *adapter = rx_ring->adapter;
  2072. struct e1000_buffer *buffer_info;
  2073. int i, size, desc_len, err = -ENOMEM;
  2074. size = sizeof(struct e1000_buffer) * rx_ring->count;
  2075. rx_ring->buffer_info = vzalloc(size);
  2076. if (!rx_ring->buffer_info)
  2077. goto err;
  2078. for (i = 0; i < rx_ring->count; i++) {
  2079. buffer_info = &rx_ring->buffer_info[i];
  2080. buffer_info->ps_pages = kcalloc(PS_PAGE_BUFFERS,
  2081. sizeof(struct e1000_ps_page),
  2082. GFP_KERNEL);
  2083. if (!buffer_info->ps_pages)
  2084. goto err_pages;
  2085. }
  2086. desc_len = sizeof(union e1000_rx_desc_packet_split);
  2087. /* Round up to nearest 4K */
  2088. rx_ring->size = rx_ring->count * desc_len;
  2089. rx_ring->size = ALIGN(rx_ring->size, 4096);
  2090. err = e1000_alloc_ring_dma(adapter, rx_ring);
  2091. if (err)
  2092. goto err_pages;
  2093. rx_ring->next_to_clean = 0;
  2094. rx_ring->next_to_use = 0;
  2095. rx_ring->rx_skb_top = NULL;
  2096. return 0;
  2097. err_pages:
  2098. for (i = 0; i < rx_ring->count; i++) {
  2099. buffer_info = &rx_ring->buffer_info[i];
  2100. kfree(buffer_info->ps_pages);
  2101. }
  2102. err:
  2103. vfree(rx_ring->buffer_info);
  2104. e_err("Unable to allocate memory for the receive descriptor ring\n");
  2105. return err;
  2106. }
  2107. /**
  2108. * e1000_clean_tx_ring - Free Tx Buffers
  2109. * @tx_ring: Tx descriptor ring
  2110. **/
  2111. static void e1000_clean_tx_ring(struct e1000_ring *tx_ring)
  2112. {
  2113. struct e1000_adapter *adapter = tx_ring->adapter;
  2114. struct e1000_buffer *buffer_info;
  2115. unsigned long size;
  2116. unsigned int i;
  2117. for (i = 0; i < tx_ring->count; i++) {
  2118. buffer_info = &tx_ring->buffer_info[i];
  2119. e1000_put_txbuf(tx_ring, buffer_info, false);
  2120. }
  2121. netdev_reset_queue(adapter->netdev);
  2122. size = sizeof(struct e1000_buffer) * tx_ring->count;
  2123. memset(tx_ring->buffer_info, 0, size);
  2124. memset(tx_ring->desc, 0, tx_ring->size);
  2125. tx_ring->next_to_use = 0;
  2126. tx_ring->next_to_clean = 0;
  2127. }
  2128. /**
  2129. * e1000e_free_tx_resources - Free Tx Resources per Queue
  2130. * @tx_ring: Tx descriptor ring
  2131. *
  2132. * Free all transmit software resources
  2133. **/
  2134. void e1000e_free_tx_resources(struct e1000_ring *tx_ring)
  2135. {
  2136. struct e1000_adapter *adapter = tx_ring->adapter;
  2137. struct pci_dev *pdev = adapter->pdev;
  2138. e1000_clean_tx_ring(tx_ring);
  2139. vfree(tx_ring->buffer_info);
  2140. tx_ring->buffer_info = NULL;
  2141. dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc,
  2142. tx_ring->dma);
  2143. tx_ring->desc = NULL;
  2144. }
  2145. /**
  2146. * e1000e_free_rx_resources - Free Rx Resources
  2147. * @rx_ring: Rx descriptor ring
  2148. *
  2149. * Free all receive software resources
  2150. **/
  2151. void e1000e_free_rx_resources(struct e1000_ring *rx_ring)
  2152. {
  2153. struct e1000_adapter *adapter = rx_ring->adapter;
  2154. struct pci_dev *pdev = adapter->pdev;
  2155. int i;
  2156. e1000_clean_rx_ring(rx_ring);
  2157. for (i = 0; i < rx_ring->count; i++)
  2158. kfree(rx_ring->buffer_info[i].ps_pages);
  2159. vfree(rx_ring->buffer_info);
  2160. rx_ring->buffer_info = NULL;
  2161. dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc,
  2162. rx_ring->dma);
  2163. rx_ring->desc = NULL;
  2164. }
  2165. /**
  2166. * e1000_update_itr - update the dynamic ITR value based on statistics
  2167. * @adapter: pointer to adapter
  2168. * @itr_setting: current adapter->itr
  2169. * @packets: the number of packets during this measurement interval
  2170. * @bytes: the number of bytes during this measurement interval
  2171. *
  2172. * Stores a new ITR value based on packets and byte
  2173. * counts during the last interrupt. The advantage of per interrupt
  2174. * computation is faster updates and more accurate ITR for the current
  2175. * traffic pattern. Constants in this function were computed
  2176. * based on theoretical maximum wire speed and thresholds were set based
  2177. * on testing data as well as attempting to minimize response time
  2178. * while increasing bulk throughput. This functionality is controlled
  2179. * by the InterruptThrottleRate module parameter.
  2180. **/
  2181. static unsigned int e1000_update_itr(u16 itr_setting, int packets, int bytes)
  2182. {
  2183. unsigned int retval = itr_setting;
  2184. if (packets == 0)
  2185. return itr_setting;
  2186. switch (itr_setting) {
  2187. case lowest_latency:
  2188. /* handle TSO and jumbo frames */
  2189. if (bytes / packets > 8000)
  2190. retval = bulk_latency;
  2191. else if ((packets < 5) && (bytes > 512))
  2192. retval = low_latency;
  2193. break;
  2194. case low_latency: /* 50 usec aka 20000 ints/s */
  2195. if (bytes > 10000) {
  2196. /* this if handles the TSO accounting */
  2197. if (bytes / packets > 8000)
  2198. retval = bulk_latency;
  2199. else if ((packets < 10) || ((bytes / packets) > 1200))
  2200. retval = bulk_latency;
  2201. else if ((packets > 35))
  2202. retval = lowest_latency;
  2203. } else if (bytes / packets > 2000) {
  2204. retval = bulk_latency;
  2205. } else if (packets <= 2 && bytes < 512) {
  2206. retval = lowest_latency;
  2207. }
  2208. break;
  2209. case bulk_latency: /* 250 usec aka 4000 ints/s */
  2210. if (bytes > 25000) {
  2211. if (packets > 35)
  2212. retval = low_latency;
  2213. } else if (bytes < 6000) {
  2214. retval = low_latency;
  2215. }
  2216. break;
  2217. }
  2218. return retval;
  2219. }
  2220. static void e1000_set_itr(struct e1000_adapter *adapter)
  2221. {
  2222. u16 current_itr;
  2223. u32 new_itr = adapter->itr;
  2224. /* for non-gigabit speeds, just fix the interrupt rate at 4000 */
  2225. if (adapter->link_speed != SPEED_1000) {
  2226. current_itr = 0;
  2227. new_itr = 4000;
  2228. goto set_itr_now;
  2229. }
  2230. if (adapter->flags2 & FLAG2_DISABLE_AIM) {
  2231. new_itr = 0;
  2232. goto set_itr_now;
  2233. }
  2234. adapter->tx_itr = e1000_update_itr(adapter->tx_itr,
  2235. adapter->total_tx_packets,
  2236. adapter->total_tx_bytes);
  2237. /* conservative mode (itr 3) eliminates the lowest_latency setting */
  2238. if (adapter->itr_setting == 3 && adapter->tx_itr == lowest_latency)
  2239. adapter->tx_itr = low_latency;
  2240. adapter->rx_itr = e1000_update_itr(adapter->rx_itr,
  2241. adapter->total_rx_packets,
  2242. adapter->total_rx_bytes);
  2243. /* conservative mode (itr 3) eliminates the lowest_latency setting */
  2244. if (adapter->itr_setting == 3 && adapter->rx_itr == lowest_latency)
  2245. adapter->rx_itr = low_latency;
  2246. current_itr = max(adapter->rx_itr, adapter->tx_itr);
  2247. /* counts and packets in update_itr are dependent on these numbers */
  2248. switch (current_itr) {
  2249. case lowest_latency:
  2250. new_itr = 70000;
  2251. break;
  2252. case low_latency:
  2253. new_itr = 20000; /* aka hwitr = ~200 */
  2254. break;
  2255. case bulk_latency:
  2256. new_itr = 4000;
  2257. break;
  2258. default:
  2259. break;
  2260. }
  2261. set_itr_now:
  2262. if (new_itr != adapter->itr) {
  2263. /* this attempts to bias the interrupt rate towards Bulk
  2264. * by adding intermediate steps when interrupt rate is
  2265. * increasing
  2266. */
  2267. new_itr = new_itr > adapter->itr ?
  2268. min(adapter->itr + (new_itr >> 2), new_itr) : new_itr;
  2269. adapter->itr = new_itr;
  2270. adapter->rx_ring->itr_val = new_itr;
  2271. if (adapter->msix_entries)
  2272. adapter->rx_ring->set_itr = 1;
  2273. else
  2274. e1000e_write_itr(adapter, new_itr);
  2275. }
  2276. }
  2277. /**
  2278. * e1000e_write_itr - write the ITR value to the appropriate registers
  2279. * @adapter: address of board private structure
  2280. * @itr: new ITR value to program
  2281. *
  2282. * e1000e_write_itr determines if the adapter is in MSI-X mode
  2283. * and, if so, writes the EITR registers with the ITR value.
  2284. * Otherwise, it writes the ITR value into the ITR register.
  2285. **/
  2286. void e1000e_write_itr(struct e1000_adapter *adapter, u32 itr)
  2287. {
  2288. struct e1000_hw *hw = &adapter->hw;
  2289. u32 new_itr = itr ? 1000000000 / (itr * 256) : 0;
  2290. if (adapter->msix_entries) {
  2291. int vector;
  2292. for (vector = 0; vector < adapter->num_vectors; vector++)
  2293. writel(new_itr, hw->hw_addr + E1000_EITR_82574(vector));
  2294. } else {
  2295. ew32(ITR, new_itr);
  2296. }
  2297. }
  2298. /**
  2299. * e1000_alloc_queues - Allocate memory for all rings
  2300. * @adapter: board private structure to initialize
  2301. **/
  2302. static int e1000_alloc_queues(struct e1000_adapter *adapter)
  2303. {
  2304. int size = sizeof(struct e1000_ring);
  2305. adapter->tx_ring = kzalloc(size, GFP_KERNEL);
  2306. if (!adapter->tx_ring)
  2307. goto err;
  2308. adapter->tx_ring->count = adapter->tx_ring_count;
  2309. adapter->tx_ring->adapter = adapter;
  2310. adapter->rx_ring = kzalloc(size, GFP_KERNEL);
  2311. if (!adapter->rx_ring)
  2312. goto err;
  2313. adapter->rx_ring->count = adapter->rx_ring_count;
  2314. adapter->rx_ring->adapter = adapter;
  2315. return 0;
  2316. err:
  2317. e_err("Unable to allocate memory for queues\n");
  2318. kfree(adapter->rx_ring);
  2319. kfree(adapter->tx_ring);
  2320. return -ENOMEM;
  2321. }
  2322. /**
  2323. * e1000e_poll - NAPI Rx polling callback
  2324. * @napi: struct associated with this polling callback
  2325. * @weight: number of packets driver is allowed to process this poll
  2326. **/
  2327. static int e1000e_poll(struct napi_struct *napi, int weight)
  2328. {
  2329. struct e1000_adapter *adapter = container_of(napi, struct e1000_adapter,
  2330. napi);
  2331. struct e1000_hw *hw = &adapter->hw;
  2332. struct net_device *poll_dev = adapter->netdev;
  2333. int tx_cleaned = 1, work_done = 0;
  2334. adapter = netdev_priv(poll_dev);
  2335. if (!adapter->msix_entries ||
  2336. (adapter->rx_ring->ims_val & adapter->tx_ring->ims_val))
  2337. tx_cleaned = e1000_clean_tx_irq(adapter->tx_ring);
  2338. adapter->clean_rx(adapter->rx_ring, &work_done, weight);
  2339. if (!tx_cleaned)
  2340. work_done = weight;
  2341. /* If weight not fully consumed, exit the polling mode */
  2342. if (work_done < weight) {
  2343. if (adapter->itr_setting & 3)
  2344. e1000_set_itr(adapter);
  2345. napi_complete_done(napi, work_done);
  2346. if (!test_bit(__E1000_DOWN, &adapter->state)) {
  2347. if (adapter->msix_entries)
  2348. ew32(IMS, adapter->rx_ring->ims_val |
  2349. E1000_IMS_OTHER);
  2350. else
  2351. e1000_irq_enable(adapter);
  2352. }
  2353. }
  2354. return work_done;
  2355. }
  2356. static int e1000_vlan_rx_add_vid(struct net_device *netdev,
  2357. __always_unused __be16 proto, u16 vid)
  2358. {
  2359. struct e1000_adapter *adapter = netdev_priv(netdev);
  2360. struct e1000_hw *hw = &adapter->hw;
  2361. u32 vfta, index;
  2362. /* don't update vlan cookie if already programmed */
  2363. if ((adapter->hw.mng_cookie.status &
  2364. E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
  2365. (vid == adapter->mng_vlan_id))
  2366. return 0;
  2367. /* add VID to filter table */
  2368. if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
  2369. index = (vid >> 5) & 0x7F;
  2370. vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
  2371. vfta |= BIT((vid & 0x1F));
  2372. hw->mac.ops.write_vfta(hw, index, vfta);
  2373. }
  2374. set_bit(vid, adapter->active_vlans);
  2375. return 0;
  2376. }
  2377. static int e1000_vlan_rx_kill_vid(struct net_device *netdev,
  2378. __always_unused __be16 proto, u16 vid)
  2379. {
  2380. struct e1000_adapter *adapter = netdev_priv(netdev);
  2381. struct e1000_hw *hw = &adapter->hw;
  2382. u32 vfta, index;
  2383. if ((adapter->hw.mng_cookie.status &
  2384. E1000_MNG_DHCP_COOKIE_STATUS_VLAN) &&
  2385. (vid == adapter->mng_vlan_id)) {
  2386. /* release control to f/w */
  2387. e1000e_release_hw_control(adapter);
  2388. return 0;
  2389. }
  2390. /* remove VID from filter table */
  2391. if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
  2392. index = (vid >> 5) & 0x7F;
  2393. vfta = E1000_READ_REG_ARRAY(hw, E1000_VFTA, index);
  2394. vfta &= ~BIT((vid & 0x1F));
  2395. hw->mac.ops.write_vfta(hw, index, vfta);
  2396. }
  2397. clear_bit(vid, adapter->active_vlans);
  2398. return 0;
  2399. }
  2400. /**
  2401. * e1000e_vlan_filter_disable - helper to disable hw VLAN filtering
  2402. * @adapter: board private structure to initialize
  2403. **/
  2404. static void e1000e_vlan_filter_disable(struct e1000_adapter *adapter)
  2405. {
  2406. struct net_device *netdev = adapter->netdev;
  2407. struct e1000_hw *hw = &adapter->hw;
  2408. u32 rctl;
  2409. if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
  2410. /* disable VLAN receive filtering */
  2411. rctl = er32(RCTL);
  2412. rctl &= ~(E1000_RCTL_VFE | E1000_RCTL_CFIEN);
  2413. ew32(RCTL, rctl);
  2414. if (adapter->mng_vlan_id != (u16)E1000_MNG_VLAN_NONE) {
  2415. e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
  2416. adapter->mng_vlan_id);
  2417. adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
  2418. }
  2419. }
  2420. }
  2421. /**
  2422. * e1000e_vlan_filter_enable - helper to enable HW VLAN filtering
  2423. * @adapter: board private structure to initialize
  2424. **/
  2425. static void e1000e_vlan_filter_enable(struct e1000_adapter *adapter)
  2426. {
  2427. struct e1000_hw *hw = &adapter->hw;
  2428. u32 rctl;
  2429. if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER) {
  2430. /* enable VLAN receive filtering */
  2431. rctl = er32(RCTL);
  2432. rctl |= E1000_RCTL_VFE;
  2433. rctl &= ~E1000_RCTL_CFIEN;
  2434. ew32(RCTL, rctl);
  2435. }
  2436. }
  2437. /**
  2438. * e1000e_vlan_strip_disable - helper to disable HW VLAN stripping
  2439. * @adapter: board private structure to initialize
  2440. **/
  2441. static void e1000e_vlan_strip_disable(struct e1000_adapter *adapter)
  2442. {
  2443. struct e1000_hw *hw = &adapter->hw;
  2444. u32 ctrl;
  2445. /* disable VLAN tag insert/strip */
  2446. ctrl = er32(CTRL);
  2447. ctrl &= ~E1000_CTRL_VME;
  2448. ew32(CTRL, ctrl);
  2449. }
  2450. /**
  2451. * e1000e_vlan_strip_enable - helper to enable HW VLAN stripping
  2452. * @adapter: board private structure to initialize
  2453. **/
  2454. static void e1000e_vlan_strip_enable(struct e1000_adapter *adapter)
  2455. {
  2456. struct e1000_hw *hw = &adapter->hw;
  2457. u32 ctrl;
  2458. /* enable VLAN tag insert/strip */
  2459. ctrl = er32(CTRL);
  2460. ctrl |= E1000_CTRL_VME;
  2461. ew32(CTRL, ctrl);
  2462. }
  2463. static void e1000_update_mng_vlan(struct e1000_adapter *adapter)
  2464. {
  2465. struct net_device *netdev = adapter->netdev;
  2466. u16 vid = adapter->hw.mng_cookie.vlan_id;
  2467. u16 old_vid = adapter->mng_vlan_id;
  2468. if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN) {
  2469. e1000_vlan_rx_add_vid(netdev, htons(ETH_P_8021Q), vid);
  2470. adapter->mng_vlan_id = vid;
  2471. }
  2472. if ((old_vid != (u16)E1000_MNG_VLAN_NONE) && (vid != old_vid))
  2473. e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q), old_vid);
  2474. }
  2475. static void e1000_restore_vlan(struct e1000_adapter *adapter)
  2476. {
  2477. u16 vid;
  2478. e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), 0);
  2479. for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
  2480. e1000_vlan_rx_add_vid(adapter->netdev, htons(ETH_P_8021Q), vid);
  2481. }
  2482. static void e1000_init_manageability_pt(struct e1000_adapter *adapter)
  2483. {
  2484. struct e1000_hw *hw = &adapter->hw;
  2485. u32 manc, manc2h, mdef, i, j;
  2486. if (!(adapter->flags & FLAG_MNG_PT_ENABLED))
  2487. return;
  2488. manc = er32(MANC);
  2489. /* enable receiving management packets to the host. this will probably
  2490. * generate destination unreachable messages from the host OS, but
  2491. * the packets will be handled on SMBUS
  2492. */
  2493. manc |= E1000_MANC_EN_MNG2HOST;
  2494. manc2h = er32(MANC2H);
  2495. switch (hw->mac.type) {
  2496. default:
  2497. manc2h |= (E1000_MANC2H_PORT_623 | E1000_MANC2H_PORT_664);
  2498. break;
  2499. case e1000_82574:
  2500. case e1000_82583:
  2501. /* Check if IPMI pass-through decision filter already exists;
  2502. * if so, enable it.
  2503. */
  2504. for (i = 0, j = 0; i < 8; i++) {
  2505. mdef = er32(MDEF(i));
  2506. /* Ignore filters with anything other than IPMI ports */
  2507. if (mdef & ~(E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
  2508. continue;
  2509. /* Enable this decision filter in MANC2H */
  2510. if (mdef)
  2511. manc2h |= BIT(i);
  2512. j |= mdef;
  2513. }
  2514. if (j == (E1000_MDEF_PORT_623 | E1000_MDEF_PORT_664))
  2515. break;
  2516. /* Create new decision filter in an empty filter */
  2517. for (i = 0, j = 0; i < 8; i++)
  2518. if (er32(MDEF(i)) == 0) {
  2519. ew32(MDEF(i), (E1000_MDEF_PORT_623 |
  2520. E1000_MDEF_PORT_664));
  2521. manc2h |= BIT(1);
  2522. j++;
  2523. break;
  2524. }
  2525. if (!j)
  2526. e_warn("Unable to create IPMI pass-through filter\n");
  2527. break;
  2528. }
  2529. ew32(MANC2H, manc2h);
  2530. ew32(MANC, manc);
  2531. }
  2532. /**
  2533. * e1000_configure_tx - Configure Transmit Unit after Reset
  2534. * @adapter: board private structure
  2535. *
  2536. * Configure the Tx unit of the MAC after a reset.
  2537. **/
  2538. static void e1000_configure_tx(struct e1000_adapter *adapter)
  2539. {
  2540. struct e1000_hw *hw = &adapter->hw;
  2541. struct e1000_ring *tx_ring = adapter->tx_ring;
  2542. u64 tdba;
  2543. u32 tdlen, tctl, tarc;
  2544. /* Setup the HW Tx Head and Tail descriptor pointers */
  2545. tdba = tx_ring->dma;
  2546. tdlen = tx_ring->count * sizeof(struct e1000_tx_desc);
  2547. ew32(TDBAL(0), (tdba & DMA_BIT_MASK(32)));
  2548. ew32(TDBAH(0), (tdba >> 32));
  2549. ew32(TDLEN(0), tdlen);
  2550. ew32(TDH(0), 0);
  2551. ew32(TDT(0), 0);
  2552. tx_ring->head = adapter->hw.hw_addr + E1000_TDH(0);
  2553. tx_ring->tail = adapter->hw.hw_addr + E1000_TDT(0);
  2554. writel(0, tx_ring->head);
  2555. if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
  2556. e1000e_update_tdt_wa(tx_ring, 0);
  2557. else
  2558. writel(0, tx_ring->tail);
  2559. /* Set the Tx Interrupt Delay register */
  2560. ew32(TIDV, adapter->tx_int_delay);
  2561. /* Tx irq moderation */
  2562. ew32(TADV, adapter->tx_abs_int_delay);
  2563. if (adapter->flags2 & FLAG2_DMA_BURST) {
  2564. u32 txdctl = er32(TXDCTL(0));
  2565. txdctl &= ~(E1000_TXDCTL_PTHRESH | E1000_TXDCTL_HTHRESH |
  2566. E1000_TXDCTL_WTHRESH);
  2567. /* set up some performance related parameters to encourage the
  2568. * hardware to use the bus more efficiently in bursts, depends
  2569. * on the tx_int_delay to be enabled,
  2570. * wthresh = 1 ==> burst write is disabled to avoid Tx stalls
  2571. * hthresh = 1 ==> prefetch when one or more available
  2572. * pthresh = 0x1f ==> prefetch if internal cache 31 or less
  2573. * BEWARE: this seems to work but should be considered first if
  2574. * there are Tx hangs or other Tx related bugs
  2575. */
  2576. txdctl |= E1000_TXDCTL_DMA_BURST_ENABLE;
  2577. ew32(TXDCTL(0), txdctl);
  2578. }
  2579. /* erratum work around: set txdctl the same for both queues */
  2580. ew32(TXDCTL(1), er32(TXDCTL(0)));
  2581. /* Program the Transmit Control Register */
  2582. tctl = er32(TCTL);
  2583. tctl &= ~E1000_TCTL_CT;
  2584. tctl |= E1000_TCTL_PSP | E1000_TCTL_RTLC |
  2585. (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
  2586. if (adapter->flags & FLAG_TARC_SPEED_MODE_BIT) {
  2587. tarc = er32(TARC(0));
  2588. /* set the speed mode bit, we'll clear it if we're not at
  2589. * gigabit link later
  2590. */
  2591. #define SPEED_MODE_BIT BIT(21)
  2592. tarc |= SPEED_MODE_BIT;
  2593. ew32(TARC(0), tarc);
  2594. }
  2595. /* errata: program both queues to unweighted RR */
  2596. if (adapter->flags & FLAG_TARC_SET_BIT_ZERO) {
  2597. tarc = er32(TARC(0));
  2598. tarc |= 1;
  2599. ew32(TARC(0), tarc);
  2600. tarc = er32(TARC(1));
  2601. tarc |= 1;
  2602. ew32(TARC(1), tarc);
  2603. }
  2604. /* Setup Transmit Descriptor Settings for eop descriptor */
  2605. adapter->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
  2606. /* only set IDE if we are delaying interrupts using the timers */
  2607. if (adapter->tx_int_delay)
  2608. adapter->txd_cmd |= E1000_TXD_CMD_IDE;
  2609. /* enable Report Status bit */
  2610. adapter->txd_cmd |= E1000_TXD_CMD_RS;
  2611. ew32(TCTL, tctl);
  2612. hw->mac.ops.config_collision_dist(hw);
  2613. /* SPT and KBL Si errata workaround to avoid data corruption */
  2614. if (hw->mac.type == e1000_pch_spt) {
  2615. u32 reg_val;
  2616. reg_val = er32(IOSFPC);
  2617. reg_val |= E1000_RCTL_RDMTS_HEX;
  2618. ew32(IOSFPC, reg_val);
  2619. reg_val = er32(TARC(0));
  2620. /* SPT and KBL Si errata workaround to avoid Tx hang */
  2621. reg_val &= ~BIT(28);
  2622. reg_val |= BIT(29);
  2623. ew32(TARC(0), reg_val);
  2624. }
  2625. }
  2626. /**
  2627. * e1000_setup_rctl - configure the receive control registers
  2628. * @adapter: Board private structure
  2629. **/
  2630. #define PAGE_USE_COUNT(S) (((S) >> PAGE_SHIFT) + \
  2631. (((S) & (PAGE_SIZE - 1)) ? 1 : 0))
  2632. static void e1000_setup_rctl(struct e1000_adapter *adapter)
  2633. {
  2634. struct e1000_hw *hw = &adapter->hw;
  2635. u32 rctl, rfctl;
  2636. u32 pages = 0;
  2637. /* Workaround Si errata on PCHx - configure jumbo frame flow.
  2638. * If jumbo frames not set, program related MAC/PHY registers
  2639. * to h/w defaults
  2640. */
  2641. if (hw->mac.type >= e1000_pch2lan) {
  2642. s32 ret_val;
  2643. if (adapter->netdev->mtu > ETH_DATA_LEN)
  2644. ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, true);
  2645. else
  2646. ret_val = e1000_lv_jumbo_workaround_ich8lan(hw, false);
  2647. if (ret_val)
  2648. e_dbg("failed to enable|disable jumbo frame workaround mode\n");
  2649. }
  2650. /* Program MC offset vector base */
  2651. rctl = er32(RCTL);
  2652. rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
  2653. rctl |= E1000_RCTL_EN | E1000_RCTL_BAM |
  2654. E1000_RCTL_LBM_NO | E1000_RCTL_RDMTS_HALF |
  2655. (adapter->hw.mac.mc_filter_type << E1000_RCTL_MO_SHIFT);
  2656. /* Do not Store bad packets */
  2657. rctl &= ~E1000_RCTL_SBP;
  2658. /* Enable Long Packet receive */
  2659. if (adapter->netdev->mtu <= ETH_DATA_LEN)
  2660. rctl &= ~E1000_RCTL_LPE;
  2661. else
  2662. rctl |= E1000_RCTL_LPE;
  2663. /* Some systems expect that the CRC is included in SMBUS traffic. The
  2664. * hardware strips the CRC before sending to both SMBUS (BMC) and to
  2665. * host memory when this is enabled
  2666. */
  2667. if (adapter->flags2 & FLAG2_CRC_STRIPPING)
  2668. rctl |= E1000_RCTL_SECRC;
  2669. /* Workaround Si errata on 82577 PHY - configure IPG for jumbos */
  2670. if ((hw->phy.type == e1000_phy_82577) && (rctl & E1000_RCTL_LPE)) {
  2671. u16 phy_data;
  2672. e1e_rphy(hw, PHY_REG(770, 26), &phy_data);
  2673. phy_data &= 0xfff8;
  2674. phy_data |= BIT(2);
  2675. e1e_wphy(hw, PHY_REG(770, 26), phy_data);
  2676. e1e_rphy(hw, 22, &phy_data);
  2677. phy_data &= 0x0fff;
  2678. phy_data |= BIT(14);
  2679. e1e_wphy(hw, 0x10, 0x2823);
  2680. e1e_wphy(hw, 0x11, 0x0003);
  2681. e1e_wphy(hw, 22, phy_data);
  2682. }
  2683. /* Setup buffer sizes */
  2684. rctl &= ~E1000_RCTL_SZ_4096;
  2685. rctl |= E1000_RCTL_BSEX;
  2686. switch (adapter->rx_buffer_len) {
  2687. case 2048:
  2688. default:
  2689. rctl |= E1000_RCTL_SZ_2048;
  2690. rctl &= ~E1000_RCTL_BSEX;
  2691. break;
  2692. case 4096:
  2693. rctl |= E1000_RCTL_SZ_4096;
  2694. break;
  2695. case 8192:
  2696. rctl |= E1000_RCTL_SZ_8192;
  2697. break;
  2698. case 16384:
  2699. rctl |= E1000_RCTL_SZ_16384;
  2700. break;
  2701. }
  2702. /* Enable Extended Status in all Receive Descriptors */
  2703. rfctl = er32(RFCTL);
  2704. rfctl |= E1000_RFCTL_EXTEN;
  2705. ew32(RFCTL, rfctl);
  2706. /* 82571 and greater support packet-split where the protocol
  2707. * header is placed in skb->data and the packet data is
  2708. * placed in pages hanging off of skb_shinfo(skb)->nr_frags.
  2709. * In the case of a non-split, skb->data is linearly filled,
  2710. * followed by the page buffers. Therefore, skb->data is
  2711. * sized to hold the largest protocol header.
  2712. *
  2713. * allocations using alloc_page take too long for regular MTU
  2714. * so only enable packet split for jumbo frames
  2715. *
  2716. * Using pages when the page size is greater than 16k wastes
  2717. * a lot of memory, since we allocate 3 pages at all times
  2718. * per packet.
  2719. */
  2720. pages = PAGE_USE_COUNT(adapter->netdev->mtu);
  2721. if ((pages <= 3) && (PAGE_SIZE <= 16384) && (rctl & E1000_RCTL_LPE))
  2722. adapter->rx_ps_pages = pages;
  2723. else
  2724. adapter->rx_ps_pages = 0;
  2725. if (adapter->rx_ps_pages) {
  2726. u32 psrctl = 0;
  2727. /* Enable Packet split descriptors */
  2728. rctl |= E1000_RCTL_DTYP_PS;
  2729. psrctl |= adapter->rx_ps_bsize0 >> E1000_PSRCTL_BSIZE0_SHIFT;
  2730. switch (adapter->rx_ps_pages) {
  2731. case 3:
  2732. psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE3_SHIFT;
  2733. /* fall-through */
  2734. case 2:
  2735. psrctl |= PAGE_SIZE << E1000_PSRCTL_BSIZE2_SHIFT;
  2736. /* fall-through */
  2737. case 1:
  2738. psrctl |= PAGE_SIZE >> E1000_PSRCTL_BSIZE1_SHIFT;
  2739. break;
  2740. }
  2741. ew32(PSRCTL, psrctl);
  2742. }
  2743. /* This is useful for sniffing bad packets. */
  2744. if (adapter->netdev->features & NETIF_F_RXALL) {
  2745. /* UPE and MPE will be handled by normal PROMISC logic
  2746. * in e1000e_set_rx_mode
  2747. */
  2748. rctl |= (E1000_RCTL_SBP | /* Receive bad packets */
  2749. E1000_RCTL_BAM | /* RX All Bcast Pkts */
  2750. E1000_RCTL_PMCF); /* RX All MAC Ctrl Pkts */
  2751. rctl &= ~(E1000_RCTL_VFE | /* Disable VLAN filter */
  2752. E1000_RCTL_DPF | /* Allow filtered pause */
  2753. E1000_RCTL_CFIEN); /* Dis VLAN CFIEN Filter */
  2754. /* Do not mess with E1000_CTRL_VME, it affects transmit as well,
  2755. * and that breaks VLANs.
  2756. */
  2757. }
  2758. ew32(RCTL, rctl);
  2759. /* just started the receive unit, no need to restart */
  2760. adapter->flags &= ~FLAG_RESTART_NOW;
  2761. }
  2762. /**
  2763. * e1000_configure_rx - Configure Receive Unit after Reset
  2764. * @adapter: board private structure
  2765. *
  2766. * Configure the Rx unit of the MAC after a reset.
  2767. **/
  2768. static void e1000_configure_rx(struct e1000_adapter *adapter)
  2769. {
  2770. struct e1000_hw *hw = &adapter->hw;
  2771. struct e1000_ring *rx_ring = adapter->rx_ring;
  2772. u64 rdba;
  2773. u32 rdlen, rctl, rxcsum, ctrl_ext;
  2774. if (adapter->rx_ps_pages) {
  2775. /* this is a 32 byte descriptor */
  2776. rdlen = rx_ring->count *
  2777. sizeof(union e1000_rx_desc_packet_split);
  2778. adapter->clean_rx = e1000_clean_rx_irq_ps;
  2779. adapter->alloc_rx_buf = e1000_alloc_rx_buffers_ps;
  2780. } else if (adapter->netdev->mtu > ETH_FRAME_LEN + ETH_FCS_LEN) {
  2781. rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
  2782. adapter->clean_rx = e1000_clean_jumbo_rx_irq;
  2783. adapter->alloc_rx_buf = e1000_alloc_jumbo_rx_buffers;
  2784. } else {
  2785. rdlen = rx_ring->count * sizeof(union e1000_rx_desc_extended);
  2786. adapter->clean_rx = e1000_clean_rx_irq;
  2787. adapter->alloc_rx_buf = e1000_alloc_rx_buffers;
  2788. }
  2789. /* disable receives while setting up the descriptors */
  2790. rctl = er32(RCTL);
  2791. if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
  2792. ew32(RCTL, rctl & ~E1000_RCTL_EN);
  2793. e1e_flush();
  2794. usleep_range(10000, 20000);
  2795. if (adapter->flags2 & FLAG2_DMA_BURST) {
  2796. /* set the writeback threshold (only takes effect if the RDTR
  2797. * is set). set GRAN=1 and write back up to 0x4 worth, and
  2798. * enable prefetching of 0x20 Rx descriptors
  2799. * granularity = 01
  2800. * wthresh = 04,
  2801. * hthresh = 04,
  2802. * pthresh = 0x20
  2803. */
  2804. ew32(RXDCTL(0), E1000_RXDCTL_DMA_BURST_ENABLE);
  2805. ew32(RXDCTL(1), E1000_RXDCTL_DMA_BURST_ENABLE);
  2806. }
  2807. /* set the Receive Delay Timer Register */
  2808. ew32(RDTR, adapter->rx_int_delay);
  2809. /* irq moderation */
  2810. ew32(RADV, adapter->rx_abs_int_delay);
  2811. if ((adapter->itr_setting != 0) && (adapter->itr != 0))
  2812. e1000e_write_itr(adapter, adapter->itr);
  2813. ctrl_ext = er32(CTRL_EXT);
  2814. /* Auto-Mask interrupts upon ICR access */
  2815. ctrl_ext |= E1000_CTRL_EXT_IAME;
  2816. ew32(IAM, 0xffffffff);
  2817. ew32(CTRL_EXT, ctrl_ext);
  2818. e1e_flush();
  2819. /* Setup the HW Rx Head and Tail Descriptor Pointers and
  2820. * the Base and Length of the Rx Descriptor Ring
  2821. */
  2822. rdba = rx_ring->dma;
  2823. ew32(RDBAL(0), (rdba & DMA_BIT_MASK(32)));
  2824. ew32(RDBAH(0), (rdba >> 32));
  2825. ew32(RDLEN(0), rdlen);
  2826. ew32(RDH(0), 0);
  2827. ew32(RDT(0), 0);
  2828. rx_ring->head = adapter->hw.hw_addr + E1000_RDH(0);
  2829. rx_ring->tail = adapter->hw.hw_addr + E1000_RDT(0);
  2830. writel(0, rx_ring->head);
  2831. if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
  2832. e1000e_update_rdt_wa(rx_ring, 0);
  2833. else
  2834. writel(0, rx_ring->tail);
  2835. /* Enable Receive Checksum Offload for TCP and UDP */
  2836. rxcsum = er32(RXCSUM);
  2837. if (adapter->netdev->features & NETIF_F_RXCSUM)
  2838. rxcsum |= E1000_RXCSUM_TUOFL;
  2839. else
  2840. rxcsum &= ~E1000_RXCSUM_TUOFL;
  2841. ew32(RXCSUM, rxcsum);
  2842. /* With jumbo frames, excessive C-state transition latencies result
  2843. * in dropped transactions.
  2844. */
  2845. if (adapter->netdev->mtu > ETH_DATA_LEN) {
  2846. u32 lat =
  2847. ((er32(PBA) & E1000_PBA_RXA_MASK) * 1024 -
  2848. adapter->max_frame_size) * 8 / 1000;
  2849. if (adapter->flags & FLAG_IS_ICH) {
  2850. u32 rxdctl = er32(RXDCTL(0));
  2851. ew32(RXDCTL(0), rxdctl | 0x3);
  2852. }
  2853. pm_qos_update_request(&adapter->pm_qos_req, lat);
  2854. } else {
  2855. pm_qos_update_request(&adapter->pm_qos_req,
  2856. PM_QOS_DEFAULT_VALUE);
  2857. }
  2858. /* Enable Receives */
  2859. ew32(RCTL, rctl);
  2860. }
  2861. /**
  2862. * e1000e_write_mc_addr_list - write multicast addresses to MTA
  2863. * @netdev: network interface device structure
  2864. *
  2865. * Writes multicast address list to the MTA hash table.
  2866. * Returns: -ENOMEM on failure
  2867. * 0 on no addresses written
  2868. * X on writing X addresses to MTA
  2869. */
  2870. static int e1000e_write_mc_addr_list(struct net_device *netdev)
  2871. {
  2872. struct e1000_adapter *adapter = netdev_priv(netdev);
  2873. struct e1000_hw *hw = &adapter->hw;
  2874. struct netdev_hw_addr *ha;
  2875. u8 *mta_list;
  2876. int i;
  2877. if (netdev_mc_empty(netdev)) {
  2878. /* nothing to program, so clear mc list */
  2879. hw->mac.ops.update_mc_addr_list(hw, NULL, 0);
  2880. return 0;
  2881. }
  2882. mta_list = kzalloc(netdev_mc_count(netdev) * ETH_ALEN, GFP_ATOMIC);
  2883. if (!mta_list)
  2884. return -ENOMEM;
  2885. /* update_mc_addr_list expects a packed array of only addresses. */
  2886. i = 0;
  2887. netdev_for_each_mc_addr(ha, netdev)
  2888. memcpy(mta_list + (i++ * ETH_ALEN), ha->addr, ETH_ALEN);
  2889. hw->mac.ops.update_mc_addr_list(hw, mta_list, i);
  2890. kfree(mta_list);
  2891. return netdev_mc_count(netdev);
  2892. }
  2893. /**
  2894. * e1000e_write_uc_addr_list - write unicast addresses to RAR table
  2895. * @netdev: network interface device structure
  2896. *
  2897. * Writes unicast address list to the RAR table.
  2898. * Returns: -ENOMEM on failure/insufficient address space
  2899. * 0 on no addresses written
  2900. * X on writing X addresses to the RAR table
  2901. **/
  2902. static int e1000e_write_uc_addr_list(struct net_device *netdev)
  2903. {
  2904. struct e1000_adapter *adapter = netdev_priv(netdev);
  2905. struct e1000_hw *hw = &adapter->hw;
  2906. unsigned int rar_entries;
  2907. int count = 0;
  2908. rar_entries = hw->mac.ops.rar_get_count(hw);
  2909. /* save a rar entry for our hardware address */
  2910. rar_entries--;
  2911. /* save a rar entry for the LAA workaround */
  2912. if (adapter->flags & FLAG_RESET_OVERWRITES_LAA)
  2913. rar_entries--;
  2914. /* return ENOMEM indicating insufficient memory for addresses */
  2915. if (netdev_uc_count(netdev) > rar_entries)
  2916. return -ENOMEM;
  2917. if (!netdev_uc_empty(netdev) && rar_entries) {
  2918. struct netdev_hw_addr *ha;
  2919. /* write the addresses in reverse order to avoid write
  2920. * combining
  2921. */
  2922. netdev_for_each_uc_addr(ha, netdev) {
  2923. int ret_val;
  2924. if (!rar_entries)
  2925. break;
  2926. ret_val = hw->mac.ops.rar_set(hw, ha->addr, rar_entries--);
  2927. if (ret_val < 0)
  2928. return -ENOMEM;
  2929. count++;
  2930. }
  2931. }
  2932. /* zero out the remaining RAR entries not used above */
  2933. for (; rar_entries > 0; rar_entries--) {
  2934. ew32(RAH(rar_entries), 0);
  2935. ew32(RAL(rar_entries), 0);
  2936. }
  2937. e1e_flush();
  2938. return count;
  2939. }
  2940. /**
  2941. * e1000e_set_rx_mode - secondary unicast, Multicast and Promiscuous mode set
  2942. * @netdev: network interface device structure
  2943. *
  2944. * The ndo_set_rx_mode entry point is called whenever the unicast or multicast
  2945. * address list or the network interface flags are updated. This routine is
  2946. * responsible for configuring the hardware for proper unicast, multicast,
  2947. * promiscuous mode, and all-multi behavior.
  2948. **/
  2949. static void e1000e_set_rx_mode(struct net_device *netdev)
  2950. {
  2951. struct e1000_adapter *adapter = netdev_priv(netdev);
  2952. struct e1000_hw *hw = &adapter->hw;
  2953. u32 rctl;
  2954. if (pm_runtime_suspended(netdev->dev.parent))
  2955. return;
  2956. /* Check for Promiscuous and All Multicast modes */
  2957. rctl = er32(RCTL);
  2958. /* clear the affected bits */
  2959. rctl &= ~(E1000_RCTL_UPE | E1000_RCTL_MPE);
  2960. if (netdev->flags & IFF_PROMISC) {
  2961. rctl |= (E1000_RCTL_UPE | E1000_RCTL_MPE);
  2962. /* Do not hardware filter VLANs in promisc mode */
  2963. e1000e_vlan_filter_disable(adapter);
  2964. } else {
  2965. int count;
  2966. if (netdev->flags & IFF_ALLMULTI) {
  2967. rctl |= E1000_RCTL_MPE;
  2968. } else {
  2969. /* Write addresses to the MTA, if the attempt fails
  2970. * then we should just turn on promiscuous mode so
  2971. * that we can at least receive multicast traffic
  2972. */
  2973. count = e1000e_write_mc_addr_list(netdev);
  2974. if (count < 0)
  2975. rctl |= E1000_RCTL_MPE;
  2976. }
  2977. e1000e_vlan_filter_enable(adapter);
  2978. /* Write addresses to available RAR registers, if there is not
  2979. * sufficient space to store all the addresses then enable
  2980. * unicast promiscuous mode
  2981. */
  2982. count = e1000e_write_uc_addr_list(netdev);
  2983. if (count < 0)
  2984. rctl |= E1000_RCTL_UPE;
  2985. }
  2986. ew32(RCTL, rctl);
  2987. if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX)
  2988. e1000e_vlan_strip_enable(adapter);
  2989. else
  2990. e1000e_vlan_strip_disable(adapter);
  2991. }
  2992. static void e1000e_setup_rss_hash(struct e1000_adapter *adapter)
  2993. {
  2994. struct e1000_hw *hw = &adapter->hw;
  2995. u32 mrqc, rxcsum;
  2996. u32 rss_key[10];
  2997. int i;
  2998. netdev_rss_key_fill(rss_key, sizeof(rss_key));
  2999. for (i = 0; i < 10; i++)
  3000. ew32(RSSRK(i), rss_key[i]);
  3001. /* Direct all traffic to queue 0 */
  3002. for (i = 0; i < 32; i++)
  3003. ew32(RETA(i), 0);
  3004. /* Disable raw packet checksumming so that RSS hash is placed in
  3005. * descriptor on writeback.
  3006. */
  3007. rxcsum = er32(RXCSUM);
  3008. rxcsum |= E1000_RXCSUM_PCSD;
  3009. ew32(RXCSUM, rxcsum);
  3010. mrqc = (E1000_MRQC_RSS_FIELD_IPV4 |
  3011. E1000_MRQC_RSS_FIELD_IPV4_TCP |
  3012. E1000_MRQC_RSS_FIELD_IPV6 |
  3013. E1000_MRQC_RSS_FIELD_IPV6_TCP |
  3014. E1000_MRQC_RSS_FIELD_IPV6_TCP_EX);
  3015. ew32(MRQC, mrqc);
  3016. }
  3017. /**
  3018. * e1000e_get_base_timinca - get default SYSTIM time increment attributes
  3019. * @adapter: board private structure
  3020. * @timinca: pointer to returned time increment attributes
  3021. *
  3022. * Get attributes for incrementing the System Time Register SYSTIML/H at
  3023. * the default base frequency, and set the cyclecounter shift value.
  3024. **/
  3025. s32 e1000e_get_base_timinca(struct e1000_adapter *adapter, u32 *timinca)
  3026. {
  3027. struct e1000_hw *hw = &adapter->hw;
  3028. u32 incvalue, incperiod, shift;
  3029. /* Make sure clock is enabled on I217/I218/I219 before checking
  3030. * the frequency
  3031. */
  3032. if ((hw->mac.type >= e1000_pch_lpt) &&
  3033. !(er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) &&
  3034. !(er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_ENABLED)) {
  3035. u32 fextnvm7 = er32(FEXTNVM7);
  3036. if (!(fextnvm7 & BIT(0))) {
  3037. ew32(FEXTNVM7, fextnvm7 | BIT(0));
  3038. e1e_flush();
  3039. }
  3040. }
  3041. switch (hw->mac.type) {
  3042. case e1000_pch2lan:
  3043. /* Stable 96MHz frequency */
  3044. incperiod = INCPERIOD_96MHZ;
  3045. incvalue = INCVALUE_96MHZ;
  3046. shift = INCVALUE_SHIFT_96MHZ;
  3047. adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHZ;
  3048. break;
  3049. case e1000_pch_lpt:
  3050. if (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI) {
  3051. /* Stable 96MHz frequency */
  3052. incperiod = INCPERIOD_96MHZ;
  3053. incvalue = INCVALUE_96MHZ;
  3054. shift = INCVALUE_SHIFT_96MHZ;
  3055. adapter->cc.shift = shift + INCPERIOD_SHIFT_96MHZ;
  3056. } else {
  3057. /* Stable 25MHz frequency */
  3058. incperiod = INCPERIOD_25MHZ;
  3059. incvalue = INCVALUE_25MHZ;
  3060. shift = INCVALUE_SHIFT_25MHZ;
  3061. adapter->cc.shift = shift;
  3062. }
  3063. break;
  3064. case e1000_pch_spt:
  3065. if (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI) {
  3066. /* Stable 24MHz frequency */
  3067. incperiod = INCPERIOD_24MHZ;
  3068. incvalue = INCVALUE_24MHZ;
  3069. shift = INCVALUE_SHIFT_24MHZ;
  3070. adapter->cc.shift = shift;
  3071. break;
  3072. }
  3073. return -EINVAL;
  3074. case e1000_pch_cnp:
  3075. if (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI) {
  3076. /* Stable 24MHz frequency */
  3077. incperiod = INCPERIOD_24MHZ;
  3078. incvalue = INCVALUE_24MHZ;
  3079. shift = INCVALUE_SHIFT_24MHZ;
  3080. adapter->cc.shift = shift;
  3081. } else {
  3082. /* Stable 38400KHz frequency */
  3083. incperiod = INCPERIOD_38400KHZ;
  3084. incvalue = INCVALUE_38400KHZ;
  3085. shift = INCVALUE_SHIFT_38400KHZ;
  3086. adapter->cc.shift = shift;
  3087. }
  3088. break;
  3089. case e1000_82574:
  3090. case e1000_82583:
  3091. /* Stable 25MHz frequency */
  3092. incperiod = INCPERIOD_25MHZ;
  3093. incvalue = INCVALUE_25MHZ;
  3094. shift = INCVALUE_SHIFT_25MHZ;
  3095. adapter->cc.shift = shift;
  3096. break;
  3097. default:
  3098. return -EINVAL;
  3099. }
  3100. *timinca = ((incperiod << E1000_TIMINCA_INCPERIOD_SHIFT) |
  3101. ((incvalue << shift) & E1000_TIMINCA_INCVALUE_MASK));
  3102. return 0;
  3103. }
  3104. /**
  3105. * e1000e_config_hwtstamp - configure the hwtstamp registers and enable/disable
  3106. * @adapter: board private structure
  3107. *
  3108. * Outgoing time stamping can be enabled and disabled. Play nice and
  3109. * disable it when requested, although it shouldn't cause any overhead
  3110. * when no packet needs it. At most one packet in the queue may be
  3111. * marked for time stamping, otherwise it would be impossible to tell
  3112. * for sure to which packet the hardware time stamp belongs.
  3113. *
  3114. * Incoming time stamping has to be configured via the hardware filters.
  3115. * Not all combinations are supported, in particular event type has to be
  3116. * specified. Matching the kind of event packet is not supported, with the
  3117. * exception of "all V2 events regardless of level 2 or 4".
  3118. **/
  3119. static int e1000e_config_hwtstamp(struct e1000_adapter *adapter,
  3120. struct hwtstamp_config *config)
  3121. {
  3122. struct e1000_hw *hw = &adapter->hw;
  3123. u32 tsync_tx_ctl = E1000_TSYNCTXCTL_ENABLED;
  3124. u32 tsync_rx_ctl = E1000_TSYNCRXCTL_ENABLED;
  3125. u32 rxmtrl = 0;
  3126. u16 rxudp = 0;
  3127. bool is_l4 = false;
  3128. bool is_l2 = false;
  3129. u32 regval;
  3130. if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
  3131. return -EINVAL;
  3132. /* flags reserved for future extensions - must be zero */
  3133. if (config->flags)
  3134. return -EINVAL;
  3135. switch (config->tx_type) {
  3136. case HWTSTAMP_TX_OFF:
  3137. tsync_tx_ctl = 0;
  3138. break;
  3139. case HWTSTAMP_TX_ON:
  3140. break;
  3141. default:
  3142. return -ERANGE;
  3143. }
  3144. switch (config->rx_filter) {
  3145. case HWTSTAMP_FILTER_NONE:
  3146. tsync_rx_ctl = 0;
  3147. break;
  3148. case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
  3149. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
  3150. rxmtrl = E1000_RXMTRL_PTP_V1_SYNC_MESSAGE;
  3151. is_l4 = true;
  3152. break;
  3153. case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
  3154. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L4_V1;
  3155. rxmtrl = E1000_RXMTRL_PTP_V1_DELAY_REQ_MESSAGE;
  3156. is_l4 = true;
  3157. break;
  3158. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  3159. /* Also time stamps V2 L2 Path Delay Request/Response */
  3160. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
  3161. rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
  3162. is_l2 = true;
  3163. break;
  3164. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  3165. /* Also time stamps V2 L2 Path Delay Request/Response. */
  3166. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_V2;
  3167. rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
  3168. is_l2 = true;
  3169. break;
  3170. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  3171. /* Hardware cannot filter just V2 L4 Sync messages;
  3172. * fall-through to V2 (both L2 and L4) Sync.
  3173. */
  3174. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  3175. /* Also time stamps V2 Path Delay Request/Response. */
  3176. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
  3177. rxmtrl = E1000_RXMTRL_PTP_V2_SYNC_MESSAGE;
  3178. is_l2 = true;
  3179. is_l4 = true;
  3180. break;
  3181. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  3182. /* Hardware cannot filter just V2 L4 Delay Request messages;
  3183. * fall-through to V2 (both L2 and L4) Delay Request.
  3184. */
  3185. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  3186. /* Also time stamps V2 Path Delay Request/Response. */
  3187. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_L2_L4_V2;
  3188. rxmtrl = E1000_RXMTRL_PTP_V2_DELAY_REQ_MESSAGE;
  3189. is_l2 = true;
  3190. is_l4 = true;
  3191. break;
  3192. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  3193. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  3194. /* Hardware cannot filter just V2 L4 or L2 Event messages;
  3195. * fall-through to all V2 (both L2 and L4) Events.
  3196. */
  3197. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  3198. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_EVENT_V2;
  3199. config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
  3200. is_l2 = true;
  3201. is_l4 = true;
  3202. break;
  3203. case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
  3204. /* For V1, the hardware can only filter Sync messages or
  3205. * Delay Request messages but not both so fall-through to
  3206. * time stamp all packets.
  3207. */
  3208. case HWTSTAMP_FILTER_NTP_ALL:
  3209. case HWTSTAMP_FILTER_ALL:
  3210. is_l2 = true;
  3211. is_l4 = true;
  3212. tsync_rx_ctl |= E1000_TSYNCRXCTL_TYPE_ALL;
  3213. config->rx_filter = HWTSTAMP_FILTER_ALL;
  3214. break;
  3215. default:
  3216. return -ERANGE;
  3217. }
  3218. adapter->hwtstamp_config = *config;
  3219. /* enable/disable Tx h/w time stamping */
  3220. regval = er32(TSYNCTXCTL);
  3221. regval &= ~E1000_TSYNCTXCTL_ENABLED;
  3222. regval |= tsync_tx_ctl;
  3223. ew32(TSYNCTXCTL, regval);
  3224. if ((er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_ENABLED) !=
  3225. (regval & E1000_TSYNCTXCTL_ENABLED)) {
  3226. e_err("Timesync Tx Control register not set as expected\n");
  3227. return -EAGAIN;
  3228. }
  3229. /* enable/disable Rx h/w time stamping */
  3230. regval = er32(TSYNCRXCTL);
  3231. regval &= ~(E1000_TSYNCRXCTL_ENABLED | E1000_TSYNCRXCTL_TYPE_MASK);
  3232. regval |= tsync_rx_ctl;
  3233. ew32(TSYNCRXCTL, regval);
  3234. if ((er32(TSYNCRXCTL) & (E1000_TSYNCRXCTL_ENABLED |
  3235. E1000_TSYNCRXCTL_TYPE_MASK)) !=
  3236. (regval & (E1000_TSYNCRXCTL_ENABLED |
  3237. E1000_TSYNCRXCTL_TYPE_MASK))) {
  3238. e_err("Timesync Rx Control register not set as expected\n");
  3239. return -EAGAIN;
  3240. }
  3241. /* L2: define ethertype filter for time stamped packets */
  3242. if (is_l2)
  3243. rxmtrl |= ETH_P_1588;
  3244. /* define which PTP packets get time stamped */
  3245. ew32(RXMTRL, rxmtrl);
  3246. /* Filter by destination port */
  3247. if (is_l4) {
  3248. rxudp = PTP_EV_PORT;
  3249. cpu_to_be16s(&rxudp);
  3250. }
  3251. ew32(RXUDP, rxudp);
  3252. e1e_flush();
  3253. /* Clear TSYNCRXCTL_VALID & TSYNCTXCTL_VALID bit */
  3254. er32(RXSTMPH);
  3255. er32(TXSTMPH);
  3256. return 0;
  3257. }
  3258. /**
  3259. * e1000_configure - configure the hardware for Rx and Tx
  3260. * @adapter: private board structure
  3261. **/
  3262. static void e1000_configure(struct e1000_adapter *adapter)
  3263. {
  3264. struct e1000_ring *rx_ring = adapter->rx_ring;
  3265. e1000e_set_rx_mode(adapter->netdev);
  3266. e1000_restore_vlan(adapter);
  3267. e1000_init_manageability_pt(adapter);
  3268. e1000_configure_tx(adapter);
  3269. if (adapter->netdev->features & NETIF_F_RXHASH)
  3270. e1000e_setup_rss_hash(adapter);
  3271. e1000_setup_rctl(adapter);
  3272. e1000_configure_rx(adapter);
  3273. adapter->alloc_rx_buf(rx_ring, e1000_desc_unused(rx_ring), GFP_KERNEL);
  3274. }
  3275. /**
  3276. * e1000e_power_up_phy - restore link in case the phy was powered down
  3277. * @adapter: address of board private structure
  3278. *
  3279. * The phy may be powered down to save power and turn off link when the
  3280. * driver is unloaded and wake on lan is not enabled (among others)
  3281. * *** this routine MUST be followed by a call to e1000e_reset ***
  3282. **/
  3283. void e1000e_power_up_phy(struct e1000_adapter *adapter)
  3284. {
  3285. if (adapter->hw.phy.ops.power_up)
  3286. adapter->hw.phy.ops.power_up(&adapter->hw);
  3287. adapter->hw.mac.ops.setup_link(&adapter->hw);
  3288. }
  3289. /**
  3290. * e1000_power_down_phy - Power down the PHY
  3291. *
  3292. * Power down the PHY so no link is implied when interface is down.
  3293. * The PHY cannot be powered down if management or WoL is active.
  3294. */
  3295. static void e1000_power_down_phy(struct e1000_adapter *adapter)
  3296. {
  3297. if (adapter->hw.phy.ops.power_down)
  3298. adapter->hw.phy.ops.power_down(&adapter->hw);
  3299. }
  3300. /**
  3301. * e1000_flush_tx_ring - remove all descriptors from the tx_ring
  3302. *
  3303. * We want to clear all pending descriptors from the TX ring.
  3304. * zeroing happens when the HW reads the regs. We assign the ring itself as
  3305. * the data of the next descriptor. We don't care about the data we are about
  3306. * to reset the HW.
  3307. */
  3308. static void e1000_flush_tx_ring(struct e1000_adapter *adapter)
  3309. {
  3310. struct e1000_hw *hw = &adapter->hw;
  3311. struct e1000_ring *tx_ring = adapter->tx_ring;
  3312. struct e1000_tx_desc *tx_desc = NULL;
  3313. u32 tdt, tctl, txd_lower = E1000_TXD_CMD_IFCS;
  3314. u16 size = 512;
  3315. tctl = er32(TCTL);
  3316. ew32(TCTL, tctl | E1000_TCTL_EN);
  3317. tdt = er32(TDT(0));
  3318. BUG_ON(tdt != tx_ring->next_to_use);
  3319. tx_desc = E1000_TX_DESC(*tx_ring, tx_ring->next_to_use);
  3320. tx_desc->buffer_addr = tx_ring->dma;
  3321. tx_desc->lower.data = cpu_to_le32(txd_lower | size);
  3322. tx_desc->upper.data = 0;
  3323. /* flush descriptors to memory before notifying the HW */
  3324. wmb();
  3325. tx_ring->next_to_use++;
  3326. if (tx_ring->next_to_use == tx_ring->count)
  3327. tx_ring->next_to_use = 0;
  3328. ew32(TDT(0), tx_ring->next_to_use);
  3329. mmiowb();
  3330. usleep_range(200, 250);
  3331. }
  3332. /**
  3333. * e1000_flush_rx_ring - remove all descriptors from the rx_ring
  3334. *
  3335. * Mark all descriptors in the RX ring as consumed and disable the rx ring
  3336. */
  3337. static void e1000_flush_rx_ring(struct e1000_adapter *adapter)
  3338. {
  3339. u32 rctl, rxdctl;
  3340. struct e1000_hw *hw = &adapter->hw;
  3341. rctl = er32(RCTL);
  3342. ew32(RCTL, rctl & ~E1000_RCTL_EN);
  3343. e1e_flush();
  3344. usleep_range(100, 150);
  3345. rxdctl = er32(RXDCTL(0));
  3346. /* zero the lower 14 bits (prefetch and host thresholds) */
  3347. rxdctl &= 0xffffc000;
  3348. /* update thresholds: prefetch threshold to 31, host threshold to 1
  3349. * and make sure the granularity is "descriptors" and not "cache lines"
  3350. */
  3351. rxdctl |= (0x1F | BIT(8) | E1000_RXDCTL_THRESH_UNIT_DESC);
  3352. ew32(RXDCTL(0), rxdctl);
  3353. /* momentarily enable the RX ring for the changes to take effect */
  3354. ew32(RCTL, rctl | E1000_RCTL_EN);
  3355. e1e_flush();
  3356. usleep_range(100, 150);
  3357. ew32(RCTL, rctl & ~E1000_RCTL_EN);
  3358. }
  3359. /**
  3360. * e1000_flush_desc_rings - remove all descriptors from the descriptor rings
  3361. *
  3362. * In i219, the descriptor rings must be emptied before resetting the HW
  3363. * or before changing the device state to D3 during runtime (runtime PM).
  3364. *
  3365. * Failure to do this will cause the HW to enter a unit hang state which can
  3366. * only be released by PCI reset on the device
  3367. *
  3368. */
  3369. static void e1000_flush_desc_rings(struct e1000_adapter *adapter)
  3370. {
  3371. u16 hang_state;
  3372. u32 fext_nvm11, tdlen;
  3373. struct e1000_hw *hw = &adapter->hw;
  3374. /* First, disable MULR fix in FEXTNVM11 */
  3375. fext_nvm11 = er32(FEXTNVM11);
  3376. fext_nvm11 |= E1000_FEXTNVM11_DISABLE_MULR_FIX;
  3377. ew32(FEXTNVM11, fext_nvm11);
  3378. /* do nothing if we're not in faulty state, or if the queue is empty */
  3379. tdlen = er32(TDLEN(0));
  3380. pci_read_config_word(adapter->pdev, PCICFG_DESC_RING_STATUS,
  3381. &hang_state);
  3382. if (!(hang_state & FLUSH_DESC_REQUIRED) || !tdlen)
  3383. return;
  3384. e1000_flush_tx_ring(adapter);
  3385. /* recheck, maybe the fault is caused by the rx ring */
  3386. pci_read_config_word(adapter->pdev, PCICFG_DESC_RING_STATUS,
  3387. &hang_state);
  3388. if (hang_state & FLUSH_DESC_REQUIRED)
  3389. e1000_flush_rx_ring(adapter);
  3390. }
  3391. /**
  3392. * e1000e_systim_reset - reset the timesync registers after a hardware reset
  3393. * @adapter: board private structure
  3394. *
  3395. * When the MAC is reset, all hardware bits for timesync will be reset to the
  3396. * default values. This function will restore the settings last in place.
  3397. * Since the clock SYSTIME registers are reset, we will simply restore the
  3398. * cyclecounter to the kernel real clock time.
  3399. **/
  3400. static void e1000e_systim_reset(struct e1000_adapter *adapter)
  3401. {
  3402. struct ptp_clock_info *info = &adapter->ptp_clock_info;
  3403. struct e1000_hw *hw = &adapter->hw;
  3404. unsigned long flags;
  3405. u32 timinca;
  3406. s32 ret_val;
  3407. if (!(adapter->flags & FLAG_HAS_HW_TIMESTAMP))
  3408. return;
  3409. if (info->adjfreq) {
  3410. /* restore the previous ptp frequency delta */
  3411. ret_val = info->adjfreq(info, adapter->ptp_delta);
  3412. } else {
  3413. /* set the default base frequency if no adjustment possible */
  3414. ret_val = e1000e_get_base_timinca(adapter, &timinca);
  3415. if (!ret_val)
  3416. ew32(TIMINCA, timinca);
  3417. }
  3418. if (ret_val) {
  3419. dev_warn(&adapter->pdev->dev,
  3420. "Failed to restore TIMINCA clock rate delta: %d\n",
  3421. ret_val);
  3422. return;
  3423. }
  3424. /* reset the systim ns time counter */
  3425. spin_lock_irqsave(&adapter->systim_lock, flags);
  3426. timecounter_init(&adapter->tc, &adapter->cc,
  3427. ktime_to_ns(ktime_get_real()));
  3428. spin_unlock_irqrestore(&adapter->systim_lock, flags);
  3429. /* restore the previous hwtstamp configuration settings */
  3430. e1000e_config_hwtstamp(adapter, &adapter->hwtstamp_config);
  3431. }
  3432. /**
  3433. * e1000e_reset - bring the hardware into a known good state
  3434. *
  3435. * This function boots the hardware and enables some settings that
  3436. * require a configuration cycle of the hardware - those cannot be
  3437. * set/changed during runtime. After reset the device needs to be
  3438. * properly configured for Rx, Tx etc.
  3439. */
  3440. void e1000e_reset(struct e1000_adapter *adapter)
  3441. {
  3442. struct e1000_mac_info *mac = &adapter->hw.mac;
  3443. struct e1000_fc_info *fc = &adapter->hw.fc;
  3444. struct e1000_hw *hw = &adapter->hw;
  3445. u32 tx_space, min_tx_space, min_rx_space;
  3446. u32 pba = adapter->pba;
  3447. u16 hwm;
  3448. /* reset Packet Buffer Allocation to default */
  3449. ew32(PBA, pba);
  3450. if (adapter->max_frame_size > (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)) {
  3451. /* To maintain wire speed transmits, the Tx FIFO should be
  3452. * large enough to accommodate two full transmit packets,
  3453. * rounded up to the next 1KB and expressed in KB. Likewise,
  3454. * the Rx FIFO should be large enough to accommodate at least
  3455. * one full receive packet and is similarly rounded up and
  3456. * expressed in KB.
  3457. */
  3458. pba = er32(PBA);
  3459. /* upper 16 bits has Tx packet buffer allocation size in KB */
  3460. tx_space = pba >> 16;
  3461. /* lower 16 bits has Rx packet buffer allocation size in KB */
  3462. pba &= 0xffff;
  3463. /* the Tx fifo also stores 16 bytes of information about the Tx
  3464. * but don't include ethernet FCS because hardware appends it
  3465. */
  3466. min_tx_space = (adapter->max_frame_size +
  3467. sizeof(struct e1000_tx_desc) - ETH_FCS_LEN) * 2;
  3468. min_tx_space = ALIGN(min_tx_space, 1024);
  3469. min_tx_space >>= 10;
  3470. /* software strips receive CRC, so leave room for it */
  3471. min_rx_space = adapter->max_frame_size;
  3472. min_rx_space = ALIGN(min_rx_space, 1024);
  3473. min_rx_space >>= 10;
  3474. /* If current Tx allocation is less than the min Tx FIFO size,
  3475. * and the min Tx FIFO size is less than the current Rx FIFO
  3476. * allocation, take space away from current Rx allocation
  3477. */
  3478. if ((tx_space < min_tx_space) &&
  3479. ((min_tx_space - tx_space) < pba)) {
  3480. pba -= min_tx_space - tx_space;
  3481. /* if short on Rx space, Rx wins and must trump Tx
  3482. * adjustment
  3483. */
  3484. if (pba < min_rx_space)
  3485. pba = min_rx_space;
  3486. }
  3487. ew32(PBA, pba);
  3488. }
  3489. /* flow control settings
  3490. *
  3491. * The high water mark must be low enough to fit one full frame
  3492. * (or the size used for early receive) above it in the Rx FIFO.
  3493. * Set it to the lower of:
  3494. * - 90% of the Rx FIFO size, and
  3495. * - the full Rx FIFO size minus one full frame
  3496. */
  3497. if (adapter->flags & FLAG_DISABLE_FC_PAUSE_TIME)
  3498. fc->pause_time = 0xFFFF;
  3499. else
  3500. fc->pause_time = E1000_FC_PAUSE_TIME;
  3501. fc->send_xon = true;
  3502. fc->current_mode = fc->requested_mode;
  3503. switch (hw->mac.type) {
  3504. case e1000_ich9lan:
  3505. case e1000_ich10lan:
  3506. if (adapter->netdev->mtu > ETH_DATA_LEN) {
  3507. pba = 14;
  3508. ew32(PBA, pba);
  3509. fc->high_water = 0x2800;
  3510. fc->low_water = fc->high_water - 8;
  3511. break;
  3512. }
  3513. /* fall-through */
  3514. default:
  3515. hwm = min(((pba << 10) * 9 / 10),
  3516. ((pba << 10) - adapter->max_frame_size));
  3517. fc->high_water = hwm & E1000_FCRTH_RTH; /* 8-byte granularity */
  3518. fc->low_water = fc->high_water - 8;
  3519. break;
  3520. case e1000_pchlan:
  3521. /* Workaround PCH LOM adapter hangs with certain network
  3522. * loads. If hangs persist, try disabling Tx flow control.
  3523. */
  3524. if (adapter->netdev->mtu > ETH_DATA_LEN) {
  3525. fc->high_water = 0x3500;
  3526. fc->low_water = 0x1500;
  3527. } else {
  3528. fc->high_water = 0x5000;
  3529. fc->low_water = 0x3000;
  3530. }
  3531. fc->refresh_time = 0x1000;
  3532. break;
  3533. case e1000_pch2lan:
  3534. case e1000_pch_lpt:
  3535. case e1000_pch_spt:
  3536. case e1000_pch_cnp:
  3537. fc->refresh_time = 0x0400;
  3538. if (adapter->netdev->mtu <= ETH_DATA_LEN) {
  3539. fc->high_water = 0x05C20;
  3540. fc->low_water = 0x05048;
  3541. fc->pause_time = 0x0650;
  3542. break;
  3543. }
  3544. pba = 14;
  3545. ew32(PBA, pba);
  3546. fc->high_water = ((pba << 10) * 9 / 10) & E1000_FCRTH_RTH;
  3547. fc->low_water = ((pba << 10) * 8 / 10) & E1000_FCRTL_RTL;
  3548. break;
  3549. }
  3550. /* Alignment of Tx data is on an arbitrary byte boundary with the
  3551. * maximum size per Tx descriptor limited only to the transmit
  3552. * allocation of the packet buffer minus 96 bytes with an upper
  3553. * limit of 24KB due to receive synchronization limitations.
  3554. */
  3555. adapter->tx_fifo_limit = min_t(u32, ((er32(PBA) >> 16) << 10) - 96,
  3556. 24 << 10);
  3557. /* Disable Adaptive Interrupt Moderation if 2 full packets cannot
  3558. * fit in receive buffer.
  3559. */
  3560. if (adapter->itr_setting & 0x3) {
  3561. if ((adapter->max_frame_size * 2) > (pba << 10)) {
  3562. if (!(adapter->flags2 & FLAG2_DISABLE_AIM)) {
  3563. dev_info(&adapter->pdev->dev,
  3564. "Interrupt Throttle Rate off\n");
  3565. adapter->flags2 |= FLAG2_DISABLE_AIM;
  3566. e1000e_write_itr(adapter, 0);
  3567. }
  3568. } else if (adapter->flags2 & FLAG2_DISABLE_AIM) {
  3569. dev_info(&adapter->pdev->dev,
  3570. "Interrupt Throttle Rate on\n");
  3571. adapter->flags2 &= ~FLAG2_DISABLE_AIM;
  3572. adapter->itr = 20000;
  3573. e1000e_write_itr(adapter, adapter->itr);
  3574. }
  3575. }
  3576. if (hw->mac.type >= e1000_pch_spt)
  3577. e1000_flush_desc_rings(adapter);
  3578. /* Allow time for pending master requests to run */
  3579. mac->ops.reset_hw(hw);
  3580. /* For parts with AMT enabled, let the firmware know
  3581. * that the network interface is in control
  3582. */
  3583. if (adapter->flags & FLAG_HAS_AMT)
  3584. e1000e_get_hw_control(adapter);
  3585. ew32(WUC, 0);
  3586. if (mac->ops.init_hw(hw))
  3587. e_err("Hardware Error\n");
  3588. e1000_update_mng_vlan(adapter);
  3589. /* Enable h/w to recognize an 802.1Q VLAN Ethernet packet */
  3590. ew32(VET, ETH_P_8021Q);
  3591. e1000e_reset_adaptive(hw);
  3592. /* restore systim and hwtstamp settings */
  3593. e1000e_systim_reset(adapter);
  3594. /* Set EEE advertisement as appropriate */
  3595. if (adapter->flags2 & FLAG2_HAS_EEE) {
  3596. s32 ret_val;
  3597. u16 adv_addr;
  3598. switch (hw->phy.type) {
  3599. case e1000_phy_82579:
  3600. adv_addr = I82579_EEE_ADVERTISEMENT;
  3601. break;
  3602. case e1000_phy_i217:
  3603. adv_addr = I217_EEE_ADVERTISEMENT;
  3604. break;
  3605. default:
  3606. dev_err(&adapter->pdev->dev,
  3607. "Invalid PHY type setting EEE advertisement\n");
  3608. return;
  3609. }
  3610. ret_val = hw->phy.ops.acquire(hw);
  3611. if (ret_val) {
  3612. dev_err(&adapter->pdev->dev,
  3613. "EEE advertisement - unable to acquire PHY\n");
  3614. return;
  3615. }
  3616. e1000_write_emi_reg_locked(hw, adv_addr,
  3617. hw->dev_spec.ich8lan.eee_disable ?
  3618. 0 : adapter->eee_advert);
  3619. hw->phy.ops.release(hw);
  3620. }
  3621. if (!netif_running(adapter->netdev) &&
  3622. !test_bit(__E1000_TESTING, &adapter->state))
  3623. e1000_power_down_phy(adapter);
  3624. e1000_get_phy_info(hw);
  3625. if ((adapter->flags & FLAG_HAS_SMART_POWER_DOWN) &&
  3626. !(adapter->flags & FLAG_SMART_POWER_DOWN)) {
  3627. u16 phy_data = 0;
  3628. /* speed up time to link by disabling smart power down, ignore
  3629. * the return value of this function because there is nothing
  3630. * different we would do if it failed
  3631. */
  3632. e1e_rphy(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
  3633. phy_data &= ~IGP02E1000_PM_SPD;
  3634. e1e_wphy(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
  3635. }
  3636. if (hw->mac.type >= e1000_pch_spt && adapter->int_mode == 0) {
  3637. u32 reg;
  3638. /* Fextnvm7 @ 0xe4[2] = 1 */
  3639. reg = er32(FEXTNVM7);
  3640. reg |= E1000_FEXTNVM7_SIDE_CLK_UNGATE;
  3641. ew32(FEXTNVM7, reg);
  3642. /* Fextnvm9 @ 0x5bb4[13:12] = 11 */
  3643. reg = er32(FEXTNVM9);
  3644. reg |= E1000_FEXTNVM9_IOSFSB_CLKGATE_DIS |
  3645. E1000_FEXTNVM9_IOSFSB_CLKREQ_DIS;
  3646. ew32(FEXTNVM9, reg);
  3647. }
  3648. }
  3649. /**
  3650. * e1000e_trigger_lsc - trigger an LSC interrupt
  3651. * @adapter:
  3652. *
  3653. * Fire a link status change interrupt to start the watchdog.
  3654. **/
  3655. static void e1000e_trigger_lsc(struct e1000_adapter *adapter)
  3656. {
  3657. struct e1000_hw *hw = &adapter->hw;
  3658. if (adapter->msix_entries)
  3659. ew32(ICS, E1000_ICS_LSC | E1000_ICS_OTHER);
  3660. else
  3661. ew32(ICS, E1000_ICS_LSC);
  3662. }
  3663. void e1000e_up(struct e1000_adapter *adapter)
  3664. {
  3665. /* hardware has been reset, we need to reload some things */
  3666. e1000_configure(adapter);
  3667. clear_bit(__E1000_DOWN, &adapter->state);
  3668. if (adapter->msix_entries)
  3669. e1000_configure_msix(adapter);
  3670. e1000_irq_enable(adapter);
  3671. netif_start_queue(adapter->netdev);
  3672. e1000e_trigger_lsc(adapter);
  3673. }
  3674. static void e1000e_flush_descriptors(struct e1000_adapter *adapter)
  3675. {
  3676. struct e1000_hw *hw = &adapter->hw;
  3677. if (!(adapter->flags2 & FLAG2_DMA_BURST))
  3678. return;
  3679. /* flush pending descriptor writebacks to memory */
  3680. ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
  3681. ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
  3682. /* execute the writes immediately */
  3683. e1e_flush();
  3684. /* due to rare timing issues, write to TIDV/RDTR again to ensure the
  3685. * write is successful
  3686. */
  3687. ew32(TIDV, adapter->tx_int_delay | E1000_TIDV_FPD);
  3688. ew32(RDTR, adapter->rx_int_delay | E1000_RDTR_FPD);
  3689. /* execute the writes immediately */
  3690. e1e_flush();
  3691. }
  3692. static void e1000e_update_stats(struct e1000_adapter *adapter);
  3693. /**
  3694. * e1000e_down - quiesce the device and optionally reset the hardware
  3695. * @adapter: board private structure
  3696. * @reset: boolean flag to reset the hardware or not
  3697. */
  3698. void e1000e_down(struct e1000_adapter *adapter, bool reset)
  3699. {
  3700. struct net_device *netdev = adapter->netdev;
  3701. struct e1000_hw *hw = &adapter->hw;
  3702. u32 tctl, rctl;
  3703. /* signal that we're down so the interrupt handler does not
  3704. * reschedule our watchdog timer
  3705. */
  3706. set_bit(__E1000_DOWN, &adapter->state);
  3707. netif_carrier_off(netdev);
  3708. /* disable receives in the hardware */
  3709. rctl = er32(RCTL);
  3710. if (!(adapter->flags2 & FLAG2_NO_DISABLE_RX))
  3711. ew32(RCTL, rctl & ~E1000_RCTL_EN);
  3712. /* flush and sleep below */
  3713. netif_stop_queue(netdev);
  3714. /* disable transmits in the hardware */
  3715. tctl = er32(TCTL);
  3716. tctl &= ~E1000_TCTL_EN;
  3717. ew32(TCTL, tctl);
  3718. /* flush both disables and wait for them to finish */
  3719. e1e_flush();
  3720. usleep_range(10000, 20000);
  3721. e1000_irq_disable(adapter);
  3722. napi_synchronize(&adapter->napi);
  3723. del_timer_sync(&adapter->watchdog_timer);
  3724. del_timer_sync(&adapter->phy_info_timer);
  3725. spin_lock(&adapter->stats64_lock);
  3726. e1000e_update_stats(adapter);
  3727. spin_unlock(&adapter->stats64_lock);
  3728. e1000e_flush_descriptors(adapter);
  3729. adapter->link_speed = 0;
  3730. adapter->link_duplex = 0;
  3731. /* Disable Si errata workaround on PCHx for jumbo frame flow */
  3732. if ((hw->mac.type >= e1000_pch2lan) &&
  3733. (adapter->netdev->mtu > ETH_DATA_LEN) &&
  3734. e1000_lv_jumbo_workaround_ich8lan(hw, false))
  3735. e_dbg("failed to disable jumbo frame workaround mode\n");
  3736. if (!pci_channel_offline(adapter->pdev)) {
  3737. if (reset)
  3738. e1000e_reset(adapter);
  3739. else if (hw->mac.type >= e1000_pch_spt)
  3740. e1000_flush_desc_rings(adapter);
  3741. }
  3742. e1000_clean_tx_ring(adapter->tx_ring);
  3743. e1000_clean_rx_ring(adapter->rx_ring);
  3744. }
  3745. void e1000e_reinit_locked(struct e1000_adapter *adapter)
  3746. {
  3747. might_sleep();
  3748. while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
  3749. usleep_range(1000, 2000);
  3750. e1000e_down(adapter, true);
  3751. e1000e_up(adapter);
  3752. clear_bit(__E1000_RESETTING, &adapter->state);
  3753. }
  3754. /**
  3755. * e1000e_sanitize_systim - sanitize raw cycle counter reads
  3756. * @hw: pointer to the HW structure
  3757. * @systim: time value read, sanitized and returned
  3758. *
  3759. * Errata for 82574/82583 possible bad bits read from SYSTIMH/L:
  3760. * check to see that the time is incrementing at a reasonable
  3761. * rate and is a multiple of incvalue.
  3762. **/
  3763. static u64 e1000e_sanitize_systim(struct e1000_hw *hw, u64 systim)
  3764. {
  3765. u64 time_delta, rem, temp;
  3766. u64 systim_next;
  3767. u32 incvalue;
  3768. int i;
  3769. incvalue = er32(TIMINCA) & E1000_TIMINCA_INCVALUE_MASK;
  3770. for (i = 0; i < E1000_MAX_82574_SYSTIM_REREADS; i++) {
  3771. /* latch SYSTIMH on read of SYSTIML */
  3772. systim_next = (u64)er32(SYSTIML);
  3773. systim_next |= (u64)er32(SYSTIMH) << 32;
  3774. time_delta = systim_next - systim;
  3775. temp = time_delta;
  3776. /* VMWare users have seen incvalue of zero, don't div / 0 */
  3777. rem = incvalue ? do_div(temp, incvalue) : (time_delta != 0);
  3778. systim = systim_next;
  3779. if ((time_delta < E1000_82574_SYSTIM_EPSILON) && (rem == 0))
  3780. break;
  3781. }
  3782. return systim;
  3783. }
  3784. /**
  3785. * e1000e_cyclecounter_read - read raw cycle counter (used by time counter)
  3786. * @cc: cyclecounter structure
  3787. **/
  3788. static u64 e1000e_cyclecounter_read(const struct cyclecounter *cc)
  3789. {
  3790. struct e1000_adapter *adapter = container_of(cc, struct e1000_adapter,
  3791. cc);
  3792. struct e1000_hw *hw = &adapter->hw;
  3793. u32 systimel, systimeh;
  3794. u64 systim;
  3795. /* SYSTIMH latching upon SYSTIML read does not work well.
  3796. * This means that if SYSTIML overflows after we read it but before
  3797. * we read SYSTIMH, the value of SYSTIMH has been incremented and we
  3798. * will experience a huge non linear increment in the systime value
  3799. * to fix that we test for overflow and if true, we re-read systime.
  3800. */
  3801. systimel = er32(SYSTIML);
  3802. systimeh = er32(SYSTIMH);
  3803. /* Is systimel is so large that overflow is possible? */
  3804. if (systimel >= (u32)0xffffffff - E1000_TIMINCA_INCVALUE_MASK) {
  3805. u32 systimel_2 = er32(SYSTIML);
  3806. if (systimel > systimel_2) {
  3807. /* There was an overflow, read again SYSTIMH, and use
  3808. * systimel_2
  3809. */
  3810. systimeh = er32(SYSTIMH);
  3811. systimel = systimel_2;
  3812. }
  3813. }
  3814. systim = (u64)systimel;
  3815. systim |= (u64)systimeh << 32;
  3816. if (adapter->flags2 & FLAG2_CHECK_SYSTIM_OVERFLOW)
  3817. systim = e1000e_sanitize_systim(hw, systim);
  3818. return systim;
  3819. }
  3820. /**
  3821. * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
  3822. * @adapter: board private structure to initialize
  3823. *
  3824. * e1000_sw_init initializes the Adapter private data structure.
  3825. * Fields are initialized based on PCI device information and
  3826. * OS network device settings (MTU size).
  3827. **/
  3828. static int e1000_sw_init(struct e1000_adapter *adapter)
  3829. {
  3830. struct net_device *netdev = adapter->netdev;
  3831. adapter->rx_buffer_len = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN;
  3832. adapter->rx_ps_bsize0 = 128;
  3833. adapter->max_frame_size = netdev->mtu + VLAN_ETH_HLEN + ETH_FCS_LEN;
  3834. adapter->min_frame_size = ETH_ZLEN + ETH_FCS_LEN;
  3835. adapter->tx_ring_count = E1000_DEFAULT_TXD;
  3836. adapter->rx_ring_count = E1000_DEFAULT_RXD;
  3837. spin_lock_init(&adapter->stats64_lock);
  3838. e1000e_set_interrupt_capability(adapter);
  3839. if (e1000_alloc_queues(adapter))
  3840. return -ENOMEM;
  3841. /* Setup hardware time stamping cyclecounter */
  3842. if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
  3843. adapter->cc.read = e1000e_cyclecounter_read;
  3844. adapter->cc.mask = CYCLECOUNTER_MASK(64);
  3845. adapter->cc.mult = 1;
  3846. /* cc.shift set in e1000e_get_base_tininca() */
  3847. spin_lock_init(&adapter->systim_lock);
  3848. INIT_WORK(&adapter->tx_hwtstamp_work, e1000e_tx_hwtstamp_work);
  3849. }
  3850. /* Explicitly disable IRQ since the NIC can be in any state. */
  3851. e1000_irq_disable(adapter);
  3852. set_bit(__E1000_DOWN, &adapter->state);
  3853. return 0;
  3854. }
  3855. /**
  3856. * e1000_intr_msi_test - Interrupt Handler
  3857. * @irq: interrupt number
  3858. * @data: pointer to a network interface device structure
  3859. **/
  3860. static irqreturn_t e1000_intr_msi_test(int __always_unused irq, void *data)
  3861. {
  3862. struct net_device *netdev = data;
  3863. struct e1000_adapter *adapter = netdev_priv(netdev);
  3864. struct e1000_hw *hw = &adapter->hw;
  3865. u32 icr = er32(ICR);
  3866. e_dbg("icr is %08X\n", icr);
  3867. if (icr & E1000_ICR_RXSEQ) {
  3868. adapter->flags &= ~FLAG_MSI_TEST_FAILED;
  3869. /* Force memory writes to complete before acknowledging the
  3870. * interrupt is handled.
  3871. */
  3872. wmb();
  3873. }
  3874. return IRQ_HANDLED;
  3875. }
  3876. /**
  3877. * e1000_test_msi_interrupt - Returns 0 for successful test
  3878. * @adapter: board private struct
  3879. *
  3880. * code flow taken from tg3.c
  3881. **/
  3882. static int e1000_test_msi_interrupt(struct e1000_adapter *adapter)
  3883. {
  3884. struct net_device *netdev = adapter->netdev;
  3885. struct e1000_hw *hw = &adapter->hw;
  3886. int err;
  3887. /* poll_enable hasn't been called yet, so don't need disable */
  3888. /* clear any pending events */
  3889. er32(ICR);
  3890. /* free the real vector and request a test handler */
  3891. e1000_free_irq(adapter);
  3892. e1000e_reset_interrupt_capability(adapter);
  3893. /* Assume that the test fails, if it succeeds then the test
  3894. * MSI irq handler will unset this flag
  3895. */
  3896. adapter->flags |= FLAG_MSI_TEST_FAILED;
  3897. err = pci_enable_msi(adapter->pdev);
  3898. if (err)
  3899. goto msi_test_failed;
  3900. err = request_irq(adapter->pdev->irq, e1000_intr_msi_test, 0,
  3901. netdev->name, netdev);
  3902. if (err) {
  3903. pci_disable_msi(adapter->pdev);
  3904. goto msi_test_failed;
  3905. }
  3906. /* Force memory writes to complete before enabling and firing an
  3907. * interrupt.
  3908. */
  3909. wmb();
  3910. e1000_irq_enable(adapter);
  3911. /* fire an unusual interrupt on the test handler */
  3912. ew32(ICS, E1000_ICS_RXSEQ);
  3913. e1e_flush();
  3914. msleep(100);
  3915. e1000_irq_disable(adapter);
  3916. rmb(); /* read flags after interrupt has been fired */
  3917. if (adapter->flags & FLAG_MSI_TEST_FAILED) {
  3918. adapter->int_mode = E1000E_INT_MODE_LEGACY;
  3919. e_info("MSI interrupt test failed, using legacy interrupt.\n");
  3920. } else {
  3921. e_dbg("MSI interrupt test succeeded!\n");
  3922. }
  3923. free_irq(adapter->pdev->irq, netdev);
  3924. pci_disable_msi(adapter->pdev);
  3925. msi_test_failed:
  3926. e1000e_set_interrupt_capability(adapter);
  3927. return e1000_request_irq(adapter);
  3928. }
  3929. /**
  3930. * e1000_test_msi - Returns 0 if MSI test succeeds or INTx mode is restored
  3931. * @adapter: board private struct
  3932. *
  3933. * code flow taken from tg3.c, called with e1000 interrupts disabled.
  3934. **/
  3935. static int e1000_test_msi(struct e1000_adapter *adapter)
  3936. {
  3937. int err;
  3938. u16 pci_cmd;
  3939. if (!(adapter->flags & FLAG_MSI_ENABLED))
  3940. return 0;
  3941. /* disable SERR in case the MSI write causes a master abort */
  3942. pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
  3943. if (pci_cmd & PCI_COMMAND_SERR)
  3944. pci_write_config_word(adapter->pdev, PCI_COMMAND,
  3945. pci_cmd & ~PCI_COMMAND_SERR);
  3946. err = e1000_test_msi_interrupt(adapter);
  3947. /* re-enable SERR */
  3948. if (pci_cmd & PCI_COMMAND_SERR) {
  3949. pci_read_config_word(adapter->pdev, PCI_COMMAND, &pci_cmd);
  3950. pci_cmd |= PCI_COMMAND_SERR;
  3951. pci_write_config_word(adapter->pdev, PCI_COMMAND, pci_cmd);
  3952. }
  3953. return err;
  3954. }
  3955. /**
  3956. * e1000e_open - Called when a network interface is made active
  3957. * @netdev: network interface device structure
  3958. *
  3959. * Returns 0 on success, negative value on failure
  3960. *
  3961. * The open entry point is called when a network interface is made
  3962. * active by the system (IFF_UP). At this point all resources needed
  3963. * for transmit and receive operations are allocated, the interrupt
  3964. * handler is registered with the OS, the watchdog timer is started,
  3965. * and the stack is notified that the interface is ready.
  3966. **/
  3967. int e1000e_open(struct net_device *netdev)
  3968. {
  3969. struct e1000_adapter *adapter = netdev_priv(netdev);
  3970. struct e1000_hw *hw = &adapter->hw;
  3971. struct pci_dev *pdev = adapter->pdev;
  3972. int err;
  3973. /* disallow open during test */
  3974. if (test_bit(__E1000_TESTING, &adapter->state))
  3975. return -EBUSY;
  3976. pm_runtime_get_sync(&pdev->dev);
  3977. netif_carrier_off(netdev);
  3978. /* allocate transmit descriptors */
  3979. err = e1000e_setup_tx_resources(adapter->tx_ring);
  3980. if (err)
  3981. goto err_setup_tx;
  3982. /* allocate receive descriptors */
  3983. err = e1000e_setup_rx_resources(adapter->rx_ring);
  3984. if (err)
  3985. goto err_setup_rx;
  3986. /* If AMT is enabled, let the firmware know that the network
  3987. * interface is now open and reset the part to a known state.
  3988. */
  3989. if (adapter->flags & FLAG_HAS_AMT) {
  3990. e1000e_get_hw_control(adapter);
  3991. e1000e_reset(adapter);
  3992. }
  3993. e1000e_power_up_phy(adapter);
  3994. adapter->mng_vlan_id = E1000_MNG_VLAN_NONE;
  3995. if ((adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN))
  3996. e1000_update_mng_vlan(adapter);
  3997. /* DMA latency requirement to workaround jumbo issue */
  3998. pm_qos_add_request(&adapter->pm_qos_req, PM_QOS_CPU_DMA_LATENCY,
  3999. PM_QOS_DEFAULT_VALUE);
  4000. /* before we allocate an interrupt, we must be ready to handle it.
  4001. * Setting DEBUG_SHIRQ in the kernel makes it fire an interrupt
  4002. * as soon as we call pci_request_irq, so we have to setup our
  4003. * clean_rx handler before we do so.
  4004. */
  4005. e1000_configure(adapter);
  4006. err = e1000_request_irq(adapter);
  4007. if (err)
  4008. goto err_req_irq;
  4009. /* Work around PCIe errata with MSI interrupts causing some chipsets to
  4010. * ignore e1000e MSI messages, which means we need to test our MSI
  4011. * interrupt now
  4012. */
  4013. if (adapter->int_mode != E1000E_INT_MODE_LEGACY) {
  4014. err = e1000_test_msi(adapter);
  4015. if (err) {
  4016. e_err("Interrupt allocation failed\n");
  4017. goto err_req_irq;
  4018. }
  4019. }
  4020. /* From here on the code is the same as e1000e_up() */
  4021. clear_bit(__E1000_DOWN, &adapter->state);
  4022. napi_enable(&adapter->napi);
  4023. e1000_irq_enable(adapter);
  4024. adapter->tx_hang_recheck = false;
  4025. netif_start_queue(netdev);
  4026. hw->mac.get_link_status = true;
  4027. pm_runtime_put(&pdev->dev);
  4028. e1000e_trigger_lsc(adapter);
  4029. return 0;
  4030. err_req_irq:
  4031. pm_qos_remove_request(&adapter->pm_qos_req);
  4032. e1000e_release_hw_control(adapter);
  4033. e1000_power_down_phy(adapter);
  4034. e1000e_free_rx_resources(adapter->rx_ring);
  4035. err_setup_rx:
  4036. e1000e_free_tx_resources(adapter->tx_ring);
  4037. err_setup_tx:
  4038. e1000e_reset(adapter);
  4039. pm_runtime_put_sync(&pdev->dev);
  4040. return err;
  4041. }
  4042. /**
  4043. * e1000e_close - Disables a network interface
  4044. * @netdev: network interface device structure
  4045. *
  4046. * Returns 0, this is not allowed to fail
  4047. *
  4048. * The close entry point is called when an interface is de-activated
  4049. * by the OS. The hardware is still under the drivers control, but
  4050. * needs to be disabled. A global MAC reset is issued to stop the
  4051. * hardware, and all transmit and receive resources are freed.
  4052. **/
  4053. int e1000e_close(struct net_device *netdev)
  4054. {
  4055. struct e1000_adapter *adapter = netdev_priv(netdev);
  4056. struct pci_dev *pdev = adapter->pdev;
  4057. int count = E1000_CHECK_RESET_COUNT;
  4058. while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
  4059. usleep_range(10000, 20000);
  4060. WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
  4061. pm_runtime_get_sync(&pdev->dev);
  4062. if (!test_bit(__E1000_DOWN, &adapter->state)) {
  4063. e1000e_down(adapter, true);
  4064. e1000_free_irq(adapter);
  4065. /* Link status message must follow this format */
  4066. pr_info("%s NIC Link is Down\n", adapter->netdev->name);
  4067. }
  4068. napi_disable(&adapter->napi);
  4069. e1000e_free_tx_resources(adapter->tx_ring);
  4070. e1000e_free_rx_resources(adapter->rx_ring);
  4071. /* kill manageability vlan ID if supported, but not if a vlan with
  4072. * the same ID is registered on the host OS (let 8021q kill it)
  4073. */
  4074. if (adapter->hw.mng_cookie.status & E1000_MNG_DHCP_COOKIE_STATUS_VLAN)
  4075. e1000_vlan_rx_kill_vid(netdev, htons(ETH_P_8021Q),
  4076. adapter->mng_vlan_id);
  4077. /* If AMT is enabled, let the firmware know that the network
  4078. * interface is now closed
  4079. */
  4080. if ((adapter->flags & FLAG_HAS_AMT) &&
  4081. !test_bit(__E1000_TESTING, &adapter->state))
  4082. e1000e_release_hw_control(adapter);
  4083. pm_qos_remove_request(&adapter->pm_qos_req);
  4084. pm_runtime_put_sync(&pdev->dev);
  4085. return 0;
  4086. }
  4087. /**
  4088. * e1000_set_mac - Change the Ethernet Address of the NIC
  4089. * @netdev: network interface device structure
  4090. * @p: pointer to an address structure
  4091. *
  4092. * Returns 0 on success, negative on failure
  4093. **/
  4094. static int e1000_set_mac(struct net_device *netdev, void *p)
  4095. {
  4096. struct e1000_adapter *adapter = netdev_priv(netdev);
  4097. struct e1000_hw *hw = &adapter->hw;
  4098. struct sockaddr *addr = p;
  4099. if (!is_valid_ether_addr(addr->sa_data))
  4100. return -EADDRNOTAVAIL;
  4101. memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
  4102. memcpy(adapter->hw.mac.addr, addr->sa_data, netdev->addr_len);
  4103. hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr, 0);
  4104. if (adapter->flags & FLAG_RESET_OVERWRITES_LAA) {
  4105. /* activate the work around */
  4106. e1000e_set_laa_state_82571(&adapter->hw, 1);
  4107. /* Hold a copy of the LAA in RAR[14] This is done so that
  4108. * between the time RAR[0] gets clobbered and the time it
  4109. * gets fixed (in e1000_watchdog), the actual LAA is in one
  4110. * of the RARs and no incoming packets directed to this port
  4111. * are dropped. Eventually the LAA will be in RAR[0] and
  4112. * RAR[14]
  4113. */
  4114. hw->mac.ops.rar_set(&adapter->hw, adapter->hw.mac.addr,
  4115. adapter->hw.mac.rar_entry_count - 1);
  4116. }
  4117. return 0;
  4118. }
  4119. /**
  4120. * e1000e_update_phy_task - work thread to update phy
  4121. * @work: pointer to our work struct
  4122. *
  4123. * this worker thread exists because we must acquire a
  4124. * semaphore to read the phy, which we could msleep while
  4125. * waiting for it, and we can't msleep in a timer.
  4126. **/
  4127. static void e1000e_update_phy_task(struct work_struct *work)
  4128. {
  4129. struct e1000_adapter *adapter = container_of(work,
  4130. struct e1000_adapter,
  4131. update_phy_task);
  4132. struct e1000_hw *hw = &adapter->hw;
  4133. if (test_bit(__E1000_DOWN, &adapter->state))
  4134. return;
  4135. e1000_get_phy_info(hw);
  4136. /* Enable EEE on 82579 after link up */
  4137. if (hw->phy.type >= e1000_phy_82579)
  4138. e1000_set_eee_pchlan(hw);
  4139. }
  4140. /**
  4141. * e1000_update_phy_info - timre call-back to update PHY info
  4142. * @data: pointer to adapter cast into an unsigned long
  4143. *
  4144. * Need to wait a few seconds after link up to get diagnostic information from
  4145. * the phy
  4146. **/
  4147. static void e1000_update_phy_info(struct timer_list *t)
  4148. {
  4149. struct e1000_adapter *adapter = from_timer(adapter, t, phy_info_timer);
  4150. if (test_bit(__E1000_DOWN, &adapter->state))
  4151. return;
  4152. schedule_work(&adapter->update_phy_task);
  4153. }
  4154. /**
  4155. * e1000e_update_phy_stats - Update the PHY statistics counters
  4156. * @adapter: board private structure
  4157. *
  4158. * Read/clear the upper 16-bit PHY registers and read/accumulate lower
  4159. **/
  4160. static void e1000e_update_phy_stats(struct e1000_adapter *adapter)
  4161. {
  4162. struct e1000_hw *hw = &adapter->hw;
  4163. s32 ret_val;
  4164. u16 phy_data;
  4165. ret_val = hw->phy.ops.acquire(hw);
  4166. if (ret_val)
  4167. return;
  4168. /* A page set is expensive so check if already on desired page.
  4169. * If not, set to the page with the PHY status registers.
  4170. */
  4171. hw->phy.addr = 1;
  4172. ret_val = e1000e_read_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT,
  4173. &phy_data);
  4174. if (ret_val)
  4175. goto release;
  4176. if (phy_data != (HV_STATS_PAGE << IGP_PAGE_SHIFT)) {
  4177. ret_val = hw->phy.ops.set_page(hw,
  4178. HV_STATS_PAGE << IGP_PAGE_SHIFT);
  4179. if (ret_val)
  4180. goto release;
  4181. }
  4182. /* Single Collision Count */
  4183. hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
  4184. ret_val = hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
  4185. if (!ret_val)
  4186. adapter->stats.scc += phy_data;
  4187. /* Excessive Collision Count */
  4188. hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
  4189. ret_val = hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
  4190. if (!ret_val)
  4191. adapter->stats.ecol += phy_data;
  4192. /* Multiple Collision Count */
  4193. hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
  4194. ret_val = hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
  4195. if (!ret_val)
  4196. adapter->stats.mcc += phy_data;
  4197. /* Late Collision Count */
  4198. hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
  4199. ret_val = hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
  4200. if (!ret_val)
  4201. adapter->stats.latecol += phy_data;
  4202. /* Collision Count - also used for adaptive IFS */
  4203. hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
  4204. ret_val = hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
  4205. if (!ret_val)
  4206. hw->mac.collision_delta = phy_data;
  4207. /* Defer Count */
  4208. hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
  4209. ret_val = hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
  4210. if (!ret_val)
  4211. adapter->stats.dc += phy_data;
  4212. /* Transmit with no CRS */
  4213. hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
  4214. ret_val = hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
  4215. if (!ret_val)
  4216. adapter->stats.tncrs += phy_data;
  4217. release:
  4218. hw->phy.ops.release(hw);
  4219. }
  4220. /**
  4221. * e1000e_update_stats - Update the board statistics counters
  4222. * @adapter: board private structure
  4223. **/
  4224. static void e1000e_update_stats(struct e1000_adapter *adapter)
  4225. {
  4226. struct net_device *netdev = adapter->netdev;
  4227. struct e1000_hw *hw = &adapter->hw;
  4228. struct pci_dev *pdev = adapter->pdev;
  4229. /* Prevent stats update while adapter is being reset, or if the pci
  4230. * connection is down.
  4231. */
  4232. if (adapter->link_speed == 0)
  4233. return;
  4234. if (pci_channel_offline(pdev))
  4235. return;
  4236. adapter->stats.crcerrs += er32(CRCERRS);
  4237. adapter->stats.gprc += er32(GPRC);
  4238. adapter->stats.gorc += er32(GORCL);
  4239. er32(GORCH); /* Clear gorc */
  4240. adapter->stats.bprc += er32(BPRC);
  4241. adapter->stats.mprc += er32(MPRC);
  4242. adapter->stats.roc += er32(ROC);
  4243. adapter->stats.mpc += er32(MPC);
  4244. /* Half-duplex statistics */
  4245. if (adapter->link_duplex == HALF_DUPLEX) {
  4246. if (adapter->flags2 & FLAG2_HAS_PHY_STATS) {
  4247. e1000e_update_phy_stats(adapter);
  4248. } else {
  4249. adapter->stats.scc += er32(SCC);
  4250. adapter->stats.ecol += er32(ECOL);
  4251. adapter->stats.mcc += er32(MCC);
  4252. adapter->stats.latecol += er32(LATECOL);
  4253. adapter->stats.dc += er32(DC);
  4254. hw->mac.collision_delta = er32(COLC);
  4255. if ((hw->mac.type != e1000_82574) &&
  4256. (hw->mac.type != e1000_82583))
  4257. adapter->stats.tncrs += er32(TNCRS);
  4258. }
  4259. adapter->stats.colc += hw->mac.collision_delta;
  4260. }
  4261. adapter->stats.xonrxc += er32(XONRXC);
  4262. adapter->stats.xontxc += er32(XONTXC);
  4263. adapter->stats.xoffrxc += er32(XOFFRXC);
  4264. adapter->stats.xofftxc += er32(XOFFTXC);
  4265. adapter->stats.gptc += er32(GPTC);
  4266. adapter->stats.gotc += er32(GOTCL);
  4267. er32(GOTCH); /* Clear gotc */
  4268. adapter->stats.rnbc += er32(RNBC);
  4269. adapter->stats.ruc += er32(RUC);
  4270. adapter->stats.mptc += er32(MPTC);
  4271. adapter->stats.bptc += er32(BPTC);
  4272. /* used for adaptive IFS */
  4273. hw->mac.tx_packet_delta = er32(TPT);
  4274. adapter->stats.tpt += hw->mac.tx_packet_delta;
  4275. adapter->stats.algnerrc += er32(ALGNERRC);
  4276. adapter->stats.rxerrc += er32(RXERRC);
  4277. adapter->stats.cexterr += er32(CEXTERR);
  4278. adapter->stats.tsctc += er32(TSCTC);
  4279. adapter->stats.tsctfc += er32(TSCTFC);
  4280. /* Fill out the OS statistics structure */
  4281. netdev->stats.multicast = adapter->stats.mprc;
  4282. netdev->stats.collisions = adapter->stats.colc;
  4283. /* Rx Errors */
  4284. /* RLEC on some newer hardware can be incorrect so build
  4285. * our own version based on RUC and ROC
  4286. */
  4287. netdev->stats.rx_errors = adapter->stats.rxerrc +
  4288. adapter->stats.crcerrs + adapter->stats.algnerrc +
  4289. adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
  4290. netdev->stats.rx_length_errors = adapter->stats.ruc +
  4291. adapter->stats.roc;
  4292. netdev->stats.rx_crc_errors = adapter->stats.crcerrs;
  4293. netdev->stats.rx_frame_errors = adapter->stats.algnerrc;
  4294. netdev->stats.rx_missed_errors = adapter->stats.mpc;
  4295. /* Tx Errors */
  4296. netdev->stats.tx_errors = adapter->stats.ecol + adapter->stats.latecol;
  4297. netdev->stats.tx_aborted_errors = adapter->stats.ecol;
  4298. netdev->stats.tx_window_errors = adapter->stats.latecol;
  4299. netdev->stats.tx_carrier_errors = adapter->stats.tncrs;
  4300. /* Tx Dropped needs to be maintained elsewhere */
  4301. /* Management Stats */
  4302. adapter->stats.mgptc += er32(MGTPTC);
  4303. adapter->stats.mgprc += er32(MGTPRC);
  4304. adapter->stats.mgpdc += er32(MGTPDC);
  4305. /* Correctable ECC Errors */
  4306. if (hw->mac.type >= e1000_pch_lpt) {
  4307. u32 pbeccsts = er32(PBECCSTS);
  4308. adapter->corr_errors +=
  4309. pbeccsts & E1000_PBECCSTS_CORR_ERR_CNT_MASK;
  4310. adapter->uncorr_errors +=
  4311. (pbeccsts & E1000_PBECCSTS_UNCORR_ERR_CNT_MASK) >>
  4312. E1000_PBECCSTS_UNCORR_ERR_CNT_SHIFT;
  4313. }
  4314. }
  4315. /**
  4316. * e1000_phy_read_status - Update the PHY register status snapshot
  4317. * @adapter: board private structure
  4318. **/
  4319. static void e1000_phy_read_status(struct e1000_adapter *adapter)
  4320. {
  4321. struct e1000_hw *hw = &adapter->hw;
  4322. struct e1000_phy_regs *phy = &adapter->phy_regs;
  4323. if (!pm_runtime_suspended((&adapter->pdev->dev)->parent) &&
  4324. (er32(STATUS) & E1000_STATUS_LU) &&
  4325. (adapter->hw.phy.media_type == e1000_media_type_copper)) {
  4326. int ret_val;
  4327. ret_val = e1e_rphy(hw, MII_BMCR, &phy->bmcr);
  4328. ret_val |= e1e_rphy(hw, MII_BMSR, &phy->bmsr);
  4329. ret_val |= e1e_rphy(hw, MII_ADVERTISE, &phy->advertise);
  4330. ret_val |= e1e_rphy(hw, MII_LPA, &phy->lpa);
  4331. ret_val |= e1e_rphy(hw, MII_EXPANSION, &phy->expansion);
  4332. ret_val |= e1e_rphy(hw, MII_CTRL1000, &phy->ctrl1000);
  4333. ret_val |= e1e_rphy(hw, MII_STAT1000, &phy->stat1000);
  4334. ret_val |= e1e_rphy(hw, MII_ESTATUS, &phy->estatus);
  4335. if (ret_val)
  4336. e_warn("Error reading PHY register\n");
  4337. } else {
  4338. /* Do not read PHY registers if link is not up
  4339. * Set values to typical power-on defaults
  4340. */
  4341. phy->bmcr = (BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_FULLDPLX);
  4342. phy->bmsr = (BMSR_100FULL | BMSR_100HALF | BMSR_10FULL |
  4343. BMSR_10HALF | BMSR_ESTATEN | BMSR_ANEGCAPABLE |
  4344. BMSR_ERCAP);
  4345. phy->advertise = (ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP |
  4346. ADVERTISE_ALL | ADVERTISE_CSMA);
  4347. phy->lpa = 0;
  4348. phy->expansion = EXPANSION_ENABLENPAGE;
  4349. phy->ctrl1000 = ADVERTISE_1000FULL;
  4350. phy->stat1000 = 0;
  4351. phy->estatus = (ESTATUS_1000_TFULL | ESTATUS_1000_THALF);
  4352. }
  4353. }
  4354. static void e1000_print_link_info(struct e1000_adapter *adapter)
  4355. {
  4356. struct e1000_hw *hw = &adapter->hw;
  4357. u32 ctrl = er32(CTRL);
  4358. /* Link status message must follow this format for user tools */
  4359. pr_info("%s NIC Link is Up %d Mbps %s Duplex, Flow Control: %s\n",
  4360. adapter->netdev->name, adapter->link_speed,
  4361. adapter->link_duplex == FULL_DUPLEX ? "Full" : "Half",
  4362. (ctrl & E1000_CTRL_TFCE) && (ctrl & E1000_CTRL_RFCE) ? "Rx/Tx" :
  4363. (ctrl & E1000_CTRL_RFCE) ? "Rx" :
  4364. (ctrl & E1000_CTRL_TFCE) ? "Tx" : "None");
  4365. }
  4366. static bool e1000e_has_link(struct e1000_adapter *adapter)
  4367. {
  4368. struct e1000_hw *hw = &adapter->hw;
  4369. bool link_active = false;
  4370. s32 ret_val = 0;
  4371. /* get_link_status is set on LSC (link status) interrupt or
  4372. * Rx sequence error interrupt. get_link_status will stay
  4373. * true until the check_for_link establishes link
  4374. * for copper adapters ONLY
  4375. */
  4376. switch (hw->phy.media_type) {
  4377. case e1000_media_type_copper:
  4378. if (hw->mac.get_link_status) {
  4379. ret_val = hw->mac.ops.check_for_link(hw);
  4380. link_active = ret_val > 0;
  4381. } else {
  4382. link_active = true;
  4383. }
  4384. break;
  4385. case e1000_media_type_fiber:
  4386. ret_val = hw->mac.ops.check_for_link(hw);
  4387. link_active = !!(er32(STATUS) & E1000_STATUS_LU);
  4388. break;
  4389. case e1000_media_type_internal_serdes:
  4390. ret_val = hw->mac.ops.check_for_link(hw);
  4391. link_active = hw->mac.serdes_has_link;
  4392. break;
  4393. default:
  4394. case e1000_media_type_unknown:
  4395. break;
  4396. }
  4397. if ((ret_val == -E1000_ERR_PHY) && (hw->phy.type == e1000_phy_igp_3) &&
  4398. (er32(CTRL) & E1000_PHY_CTRL_GBE_DISABLE)) {
  4399. /* See e1000_kmrn_lock_loss_workaround_ich8lan() */
  4400. e_info("Gigabit has been disabled, downgrading speed\n");
  4401. }
  4402. return link_active;
  4403. }
  4404. static void e1000e_enable_receives(struct e1000_adapter *adapter)
  4405. {
  4406. /* make sure the receive unit is started */
  4407. if ((adapter->flags & FLAG_RX_NEEDS_RESTART) &&
  4408. (adapter->flags & FLAG_RESTART_NOW)) {
  4409. struct e1000_hw *hw = &adapter->hw;
  4410. u32 rctl = er32(RCTL);
  4411. ew32(RCTL, rctl | E1000_RCTL_EN);
  4412. adapter->flags &= ~FLAG_RESTART_NOW;
  4413. }
  4414. }
  4415. static void e1000e_check_82574_phy_workaround(struct e1000_adapter *adapter)
  4416. {
  4417. struct e1000_hw *hw = &adapter->hw;
  4418. /* With 82574 controllers, PHY needs to be checked periodically
  4419. * for hung state and reset, if two calls return true
  4420. */
  4421. if (e1000_check_phy_82574(hw))
  4422. adapter->phy_hang_count++;
  4423. else
  4424. adapter->phy_hang_count = 0;
  4425. if (adapter->phy_hang_count > 1) {
  4426. adapter->phy_hang_count = 0;
  4427. e_dbg("PHY appears hung - resetting\n");
  4428. schedule_work(&adapter->reset_task);
  4429. }
  4430. }
  4431. /**
  4432. * e1000_watchdog - Timer Call-back
  4433. * @data: pointer to adapter cast into an unsigned long
  4434. **/
  4435. static void e1000_watchdog(struct timer_list *t)
  4436. {
  4437. struct e1000_adapter *adapter = from_timer(adapter, t, watchdog_timer);
  4438. /* Do the rest outside of interrupt context */
  4439. schedule_work(&adapter->watchdog_task);
  4440. /* TODO: make this use queue_delayed_work() */
  4441. }
  4442. static void e1000_watchdog_task(struct work_struct *work)
  4443. {
  4444. struct e1000_adapter *adapter = container_of(work,
  4445. struct e1000_adapter,
  4446. watchdog_task);
  4447. struct net_device *netdev = adapter->netdev;
  4448. struct e1000_mac_info *mac = &adapter->hw.mac;
  4449. struct e1000_phy_info *phy = &adapter->hw.phy;
  4450. struct e1000_ring *tx_ring = adapter->tx_ring;
  4451. struct e1000_hw *hw = &adapter->hw;
  4452. u32 link, tctl;
  4453. if (test_bit(__E1000_DOWN, &adapter->state))
  4454. return;
  4455. link = e1000e_has_link(adapter);
  4456. if ((netif_carrier_ok(netdev)) && link) {
  4457. /* Cancel scheduled suspend requests. */
  4458. pm_runtime_resume(netdev->dev.parent);
  4459. e1000e_enable_receives(adapter);
  4460. goto link_up;
  4461. }
  4462. if ((e1000e_enable_tx_pkt_filtering(hw)) &&
  4463. (adapter->mng_vlan_id != adapter->hw.mng_cookie.vlan_id))
  4464. e1000_update_mng_vlan(adapter);
  4465. if (link) {
  4466. if (!netif_carrier_ok(netdev)) {
  4467. bool txb2b = true;
  4468. /* Cancel scheduled suspend requests. */
  4469. pm_runtime_resume(netdev->dev.parent);
  4470. /* update snapshot of PHY registers on LSC */
  4471. e1000_phy_read_status(adapter);
  4472. mac->ops.get_link_up_info(&adapter->hw,
  4473. &adapter->link_speed,
  4474. &adapter->link_duplex);
  4475. e1000_print_link_info(adapter);
  4476. /* check if SmartSpeed worked */
  4477. e1000e_check_downshift(hw);
  4478. if (phy->speed_downgraded)
  4479. netdev_warn(netdev,
  4480. "Link Speed was downgraded by SmartSpeed\n");
  4481. /* On supported PHYs, check for duplex mismatch only
  4482. * if link has autonegotiated at 10/100 half
  4483. */
  4484. if ((hw->phy.type == e1000_phy_igp_3 ||
  4485. hw->phy.type == e1000_phy_bm) &&
  4486. hw->mac.autoneg &&
  4487. (adapter->link_speed == SPEED_10 ||
  4488. adapter->link_speed == SPEED_100) &&
  4489. (adapter->link_duplex == HALF_DUPLEX)) {
  4490. u16 autoneg_exp;
  4491. e1e_rphy(hw, MII_EXPANSION, &autoneg_exp);
  4492. if (!(autoneg_exp & EXPANSION_NWAY))
  4493. e_info("Autonegotiated half duplex but link partner cannot autoneg. Try forcing full duplex if link gets many collisions.\n");
  4494. }
  4495. /* adjust timeout factor according to speed/duplex */
  4496. adapter->tx_timeout_factor = 1;
  4497. switch (adapter->link_speed) {
  4498. case SPEED_10:
  4499. txb2b = false;
  4500. adapter->tx_timeout_factor = 16;
  4501. break;
  4502. case SPEED_100:
  4503. txb2b = false;
  4504. adapter->tx_timeout_factor = 10;
  4505. break;
  4506. }
  4507. /* workaround: re-program speed mode bit after
  4508. * link-up event
  4509. */
  4510. if ((adapter->flags & FLAG_TARC_SPEED_MODE_BIT) &&
  4511. !txb2b) {
  4512. u32 tarc0;
  4513. tarc0 = er32(TARC(0));
  4514. tarc0 &= ~SPEED_MODE_BIT;
  4515. ew32(TARC(0), tarc0);
  4516. }
  4517. /* disable TSO for pcie and 10/100 speeds, to avoid
  4518. * some hardware issues
  4519. */
  4520. if (!(adapter->flags & FLAG_TSO_FORCE)) {
  4521. switch (adapter->link_speed) {
  4522. case SPEED_10:
  4523. case SPEED_100:
  4524. e_info("10/100 speed: disabling TSO\n");
  4525. netdev->features &= ~NETIF_F_TSO;
  4526. netdev->features &= ~NETIF_F_TSO6;
  4527. break;
  4528. case SPEED_1000:
  4529. netdev->features |= NETIF_F_TSO;
  4530. netdev->features |= NETIF_F_TSO6;
  4531. break;
  4532. default:
  4533. /* oops */
  4534. break;
  4535. }
  4536. }
  4537. /* enable transmits in the hardware, need to do this
  4538. * after setting TARC(0)
  4539. */
  4540. tctl = er32(TCTL);
  4541. tctl |= E1000_TCTL_EN;
  4542. ew32(TCTL, tctl);
  4543. /* Perform any post-link-up configuration before
  4544. * reporting link up.
  4545. */
  4546. if (phy->ops.cfg_on_link_up)
  4547. phy->ops.cfg_on_link_up(hw);
  4548. netif_carrier_on(netdev);
  4549. if (!test_bit(__E1000_DOWN, &adapter->state))
  4550. mod_timer(&adapter->phy_info_timer,
  4551. round_jiffies(jiffies + 2 * HZ));
  4552. }
  4553. } else {
  4554. if (netif_carrier_ok(netdev)) {
  4555. adapter->link_speed = 0;
  4556. adapter->link_duplex = 0;
  4557. /* Link status message must follow this format */
  4558. pr_info("%s NIC Link is Down\n", adapter->netdev->name);
  4559. netif_carrier_off(netdev);
  4560. if (!test_bit(__E1000_DOWN, &adapter->state))
  4561. mod_timer(&adapter->phy_info_timer,
  4562. round_jiffies(jiffies + 2 * HZ));
  4563. /* 8000ES2LAN requires a Rx packet buffer work-around
  4564. * on link down event; reset the controller to flush
  4565. * the Rx packet buffer.
  4566. */
  4567. if (adapter->flags & FLAG_RX_NEEDS_RESTART)
  4568. adapter->flags |= FLAG_RESTART_NOW;
  4569. else
  4570. pm_schedule_suspend(netdev->dev.parent,
  4571. LINK_TIMEOUT);
  4572. }
  4573. }
  4574. link_up:
  4575. spin_lock(&adapter->stats64_lock);
  4576. e1000e_update_stats(adapter);
  4577. mac->tx_packet_delta = adapter->stats.tpt - adapter->tpt_old;
  4578. adapter->tpt_old = adapter->stats.tpt;
  4579. mac->collision_delta = adapter->stats.colc - adapter->colc_old;
  4580. adapter->colc_old = adapter->stats.colc;
  4581. adapter->gorc = adapter->stats.gorc - adapter->gorc_old;
  4582. adapter->gorc_old = adapter->stats.gorc;
  4583. adapter->gotc = adapter->stats.gotc - adapter->gotc_old;
  4584. adapter->gotc_old = adapter->stats.gotc;
  4585. spin_unlock(&adapter->stats64_lock);
  4586. /* If the link is lost the controller stops DMA, but
  4587. * if there is queued Tx work it cannot be done. So
  4588. * reset the controller to flush the Tx packet buffers.
  4589. */
  4590. if (!netif_carrier_ok(netdev) &&
  4591. (e1000_desc_unused(tx_ring) + 1 < tx_ring->count))
  4592. adapter->flags |= FLAG_RESTART_NOW;
  4593. /* If reset is necessary, do it outside of interrupt context. */
  4594. if (adapter->flags & FLAG_RESTART_NOW) {
  4595. schedule_work(&adapter->reset_task);
  4596. /* return immediately since reset is imminent */
  4597. return;
  4598. }
  4599. e1000e_update_adaptive(&adapter->hw);
  4600. /* Simple mode for Interrupt Throttle Rate (ITR) */
  4601. if (adapter->itr_setting == 4) {
  4602. /* Symmetric Tx/Rx gets a reduced ITR=2000;
  4603. * Total asymmetrical Tx or Rx gets ITR=8000;
  4604. * everyone else is between 2000-8000.
  4605. */
  4606. u32 goc = (adapter->gotc + adapter->gorc) / 10000;
  4607. u32 dif = (adapter->gotc > adapter->gorc ?
  4608. adapter->gotc - adapter->gorc :
  4609. adapter->gorc - adapter->gotc) / 10000;
  4610. u32 itr = goc > 0 ? (dif * 6000 / goc + 2000) : 8000;
  4611. e1000e_write_itr(adapter, itr);
  4612. }
  4613. /* Cause software interrupt to ensure Rx ring is cleaned */
  4614. if (adapter->msix_entries)
  4615. ew32(ICS, adapter->rx_ring->ims_val);
  4616. else
  4617. ew32(ICS, E1000_ICS_RXDMT0);
  4618. /* flush pending descriptors to memory before detecting Tx hang */
  4619. e1000e_flush_descriptors(adapter);
  4620. /* Force detection of hung controller every watchdog period */
  4621. adapter->detect_tx_hung = true;
  4622. /* With 82571 controllers, LAA may be overwritten due to controller
  4623. * reset from the other port. Set the appropriate LAA in RAR[0]
  4624. */
  4625. if (e1000e_get_laa_state_82571(hw))
  4626. hw->mac.ops.rar_set(hw, adapter->hw.mac.addr, 0);
  4627. if (adapter->flags2 & FLAG2_CHECK_PHY_HANG)
  4628. e1000e_check_82574_phy_workaround(adapter);
  4629. /* Clear valid timestamp stuck in RXSTMPL/H due to a Rx error */
  4630. if (adapter->hwtstamp_config.rx_filter != HWTSTAMP_FILTER_NONE) {
  4631. if ((adapter->flags2 & FLAG2_CHECK_RX_HWTSTAMP) &&
  4632. (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_VALID)) {
  4633. er32(RXSTMPH);
  4634. adapter->rx_hwtstamp_cleared++;
  4635. } else {
  4636. adapter->flags2 |= FLAG2_CHECK_RX_HWTSTAMP;
  4637. }
  4638. }
  4639. /* Reset the timer */
  4640. if (!test_bit(__E1000_DOWN, &adapter->state))
  4641. mod_timer(&adapter->watchdog_timer,
  4642. round_jiffies(jiffies + 2 * HZ));
  4643. }
  4644. #define E1000_TX_FLAGS_CSUM 0x00000001
  4645. #define E1000_TX_FLAGS_VLAN 0x00000002
  4646. #define E1000_TX_FLAGS_TSO 0x00000004
  4647. #define E1000_TX_FLAGS_IPV4 0x00000008
  4648. #define E1000_TX_FLAGS_NO_FCS 0x00000010
  4649. #define E1000_TX_FLAGS_HWTSTAMP 0x00000020
  4650. #define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
  4651. #define E1000_TX_FLAGS_VLAN_SHIFT 16
  4652. static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb,
  4653. __be16 protocol)
  4654. {
  4655. struct e1000_context_desc *context_desc;
  4656. struct e1000_buffer *buffer_info;
  4657. unsigned int i;
  4658. u32 cmd_length = 0;
  4659. u16 ipcse = 0, mss;
  4660. u8 ipcss, ipcso, tucss, tucso, hdr_len;
  4661. int err;
  4662. if (!skb_is_gso(skb))
  4663. return 0;
  4664. err = skb_cow_head(skb, 0);
  4665. if (err < 0)
  4666. return err;
  4667. hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
  4668. mss = skb_shinfo(skb)->gso_size;
  4669. if (protocol == htons(ETH_P_IP)) {
  4670. struct iphdr *iph = ip_hdr(skb);
  4671. iph->tot_len = 0;
  4672. iph->check = 0;
  4673. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr,
  4674. 0, IPPROTO_TCP, 0);
  4675. cmd_length = E1000_TXD_CMD_IP;
  4676. ipcse = skb_transport_offset(skb) - 1;
  4677. } else if (skb_is_gso_v6(skb)) {
  4678. ipv6_hdr(skb)->payload_len = 0;
  4679. tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  4680. &ipv6_hdr(skb)->daddr,
  4681. 0, IPPROTO_TCP, 0);
  4682. ipcse = 0;
  4683. }
  4684. ipcss = skb_network_offset(skb);
  4685. ipcso = (void *)&(ip_hdr(skb)->check) - (void *)skb->data;
  4686. tucss = skb_transport_offset(skb);
  4687. tucso = (void *)&(tcp_hdr(skb)->check) - (void *)skb->data;
  4688. cmd_length |= (E1000_TXD_CMD_DEXT | E1000_TXD_CMD_TSE |
  4689. E1000_TXD_CMD_TCP | (skb->len - (hdr_len)));
  4690. i = tx_ring->next_to_use;
  4691. context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
  4692. buffer_info = &tx_ring->buffer_info[i];
  4693. context_desc->lower_setup.ip_fields.ipcss = ipcss;
  4694. context_desc->lower_setup.ip_fields.ipcso = ipcso;
  4695. context_desc->lower_setup.ip_fields.ipcse = cpu_to_le16(ipcse);
  4696. context_desc->upper_setup.tcp_fields.tucss = tucss;
  4697. context_desc->upper_setup.tcp_fields.tucso = tucso;
  4698. context_desc->upper_setup.tcp_fields.tucse = 0;
  4699. context_desc->tcp_seg_setup.fields.mss = cpu_to_le16(mss);
  4700. context_desc->tcp_seg_setup.fields.hdr_len = hdr_len;
  4701. context_desc->cmd_and_length = cpu_to_le32(cmd_length);
  4702. buffer_info->time_stamp = jiffies;
  4703. buffer_info->next_to_watch = i;
  4704. i++;
  4705. if (i == tx_ring->count)
  4706. i = 0;
  4707. tx_ring->next_to_use = i;
  4708. return 1;
  4709. }
  4710. static bool e1000_tx_csum(struct e1000_ring *tx_ring, struct sk_buff *skb,
  4711. __be16 protocol)
  4712. {
  4713. struct e1000_adapter *adapter = tx_ring->adapter;
  4714. struct e1000_context_desc *context_desc;
  4715. struct e1000_buffer *buffer_info;
  4716. unsigned int i;
  4717. u8 css;
  4718. u32 cmd_len = E1000_TXD_CMD_DEXT;
  4719. if (skb->ip_summed != CHECKSUM_PARTIAL)
  4720. return false;
  4721. switch (protocol) {
  4722. case cpu_to_be16(ETH_P_IP):
  4723. if (ip_hdr(skb)->protocol == IPPROTO_TCP)
  4724. cmd_len |= E1000_TXD_CMD_TCP;
  4725. break;
  4726. case cpu_to_be16(ETH_P_IPV6):
  4727. /* XXX not handling all IPV6 headers */
  4728. if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
  4729. cmd_len |= E1000_TXD_CMD_TCP;
  4730. break;
  4731. default:
  4732. if (unlikely(net_ratelimit()))
  4733. e_warn("checksum_partial proto=%x!\n",
  4734. be16_to_cpu(protocol));
  4735. break;
  4736. }
  4737. css = skb_checksum_start_offset(skb);
  4738. i = tx_ring->next_to_use;
  4739. buffer_info = &tx_ring->buffer_info[i];
  4740. context_desc = E1000_CONTEXT_DESC(*tx_ring, i);
  4741. context_desc->lower_setup.ip_config = 0;
  4742. context_desc->upper_setup.tcp_fields.tucss = css;
  4743. context_desc->upper_setup.tcp_fields.tucso = css + skb->csum_offset;
  4744. context_desc->upper_setup.tcp_fields.tucse = 0;
  4745. context_desc->tcp_seg_setup.data = 0;
  4746. context_desc->cmd_and_length = cpu_to_le32(cmd_len);
  4747. buffer_info->time_stamp = jiffies;
  4748. buffer_info->next_to_watch = i;
  4749. i++;
  4750. if (i == tx_ring->count)
  4751. i = 0;
  4752. tx_ring->next_to_use = i;
  4753. return true;
  4754. }
  4755. static int e1000_tx_map(struct e1000_ring *tx_ring, struct sk_buff *skb,
  4756. unsigned int first, unsigned int max_per_txd,
  4757. unsigned int nr_frags)
  4758. {
  4759. struct e1000_adapter *adapter = tx_ring->adapter;
  4760. struct pci_dev *pdev = adapter->pdev;
  4761. struct e1000_buffer *buffer_info;
  4762. unsigned int len = skb_headlen(skb);
  4763. unsigned int offset = 0, size, count = 0, i;
  4764. unsigned int f, bytecount, segs;
  4765. i = tx_ring->next_to_use;
  4766. while (len) {
  4767. buffer_info = &tx_ring->buffer_info[i];
  4768. size = min(len, max_per_txd);
  4769. buffer_info->length = size;
  4770. buffer_info->time_stamp = jiffies;
  4771. buffer_info->next_to_watch = i;
  4772. buffer_info->dma = dma_map_single(&pdev->dev,
  4773. skb->data + offset,
  4774. size, DMA_TO_DEVICE);
  4775. buffer_info->mapped_as_page = false;
  4776. if (dma_mapping_error(&pdev->dev, buffer_info->dma))
  4777. goto dma_error;
  4778. len -= size;
  4779. offset += size;
  4780. count++;
  4781. if (len) {
  4782. i++;
  4783. if (i == tx_ring->count)
  4784. i = 0;
  4785. }
  4786. }
  4787. for (f = 0; f < nr_frags; f++) {
  4788. const struct skb_frag_struct *frag;
  4789. frag = &skb_shinfo(skb)->frags[f];
  4790. len = skb_frag_size(frag);
  4791. offset = 0;
  4792. while (len) {
  4793. i++;
  4794. if (i == tx_ring->count)
  4795. i = 0;
  4796. buffer_info = &tx_ring->buffer_info[i];
  4797. size = min(len, max_per_txd);
  4798. buffer_info->length = size;
  4799. buffer_info->time_stamp = jiffies;
  4800. buffer_info->next_to_watch = i;
  4801. buffer_info->dma = skb_frag_dma_map(&pdev->dev, frag,
  4802. offset, size,
  4803. DMA_TO_DEVICE);
  4804. buffer_info->mapped_as_page = true;
  4805. if (dma_mapping_error(&pdev->dev, buffer_info->dma))
  4806. goto dma_error;
  4807. len -= size;
  4808. offset += size;
  4809. count++;
  4810. }
  4811. }
  4812. segs = skb_shinfo(skb)->gso_segs ? : 1;
  4813. /* multiply data chunks by size of headers */
  4814. bytecount = ((segs - 1) * skb_headlen(skb)) + skb->len;
  4815. tx_ring->buffer_info[i].skb = skb;
  4816. tx_ring->buffer_info[i].segs = segs;
  4817. tx_ring->buffer_info[i].bytecount = bytecount;
  4818. tx_ring->buffer_info[first].next_to_watch = i;
  4819. return count;
  4820. dma_error:
  4821. dev_err(&pdev->dev, "Tx DMA map failed\n");
  4822. buffer_info->dma = 0;
  4823. if (count)
  4824. count--;
  4825. while (count--) {
  4826. if (i == 0)
  4827. i += tx_ring->count;
  4828. i--;
  4829. buffer_info = &tx_ring->buffer_info[i];
  4830. e1000_put_txbuf(tx_ring, buffer_info, true);
  4831. }
  4832. return 0;
  4833. }
  4834. static void e1000_tx_queue(struct e1000_ring *tx_ring, int tx_flags, int count)
  4835. {
  4836. struct e1000_adapter *adapter = tx_ring->adapter;
  4837. struct e1000_tx_desc *tx_desc = NULL;
  4838. struct e1000_buffer *buffer_info;
  4839. u32 txd_upper = 0, txd_lower = E1000_TXD_CMD_IFCS;
  4840. unsigned int i;
  4841. if (tx_flags & E1000_TX_FLAGS_TSO) {
  4842. txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D |
  4843. E1000_TXD_CMD_TSE;
  4844. txd_upper |= E1000_TXD_POPTS_TXSM << 8;
  4845. if (tx_flags & E1000_TX_FLAGS_IPV4)
  4846. txd_upper |= E1000_TXD_POPTS_IXSM << 8;
  4847. }
  4848. if (tx_flags & E1000_TX_FLAGS_CSUM) {
  4849. txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
  4850. txd_upper |= E1000_TXD_POPTS_TXSM << 8;
  4851. }
  4852. if (tx_flags & E1000_TX_FLAGS_VLAN) {
  4853. txd_lower |= E1000_TXD_CMD_VLE;
  4854. txd_upper |= (tx_flags & E1000_TX_FLAGS_VLAN_MASK);
  4855. }
  4856. if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
  4857. txd_lower &= ~(E1000_TXD_CMD_IFCS);
  4858. if (unlikely(tx_flags & E1000_TX_FLAGS_HWTSTAMP)) {
  4859. txd_lower |= E1000_TXD_CMD_DEXT | E1000_TXD_DTYP_D;
  4860. txd_upper |= E1000_TXD_EXTCMD_TSTAMP;
  4861. }
  4862. i = tx_ring->next_to_use;
  4863. do {
  4864. buffer_info = &tx_ring->buffer_info[i];
  4865. tx_desc = E1000_TX_DESC(*tx_ring, i);
  4866. tx_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
  4867. tx_desc->lower.data = cpu_to_le32(txd_lower |
  4868. buffer_info->length);
  4869. tx_desc->upper.data = cpu_to_le32(txd_upper);
  4870. i++;
  4871. if (i == tx_ring->count)
  4872. i = 0;
  4873. } while (--count > 0);
  4874. tx_desc->lower.data |= cpu_to_le32(adapter->txd_cmd);
  4875. /* txd_cmd re-enables FCS, so we'll re-disable it here as desired. */
  4876. if (unlikely(tx_flags & E1000_TX_FLAGS_NO_FCS))
  4877. tx_desc->lower.data &= ~(cpu_to_le32(E1000_TXD_CMD_IFCS));
  4878. /* Force memory writes to complete before letting h/w
  4879. * know there are new descriptors to fetch. (Only
  4880. * applicable for weak-ordered memory model archs,
  4881. * such as IA-64).
  4882. */
  4883. wmb();
  4884. tx_ring->next_to_use = i;
  4885. }
  4886. #define MINIMUM_DHCP_PACKET_SIZE 282
  4887. static int e1000_transfer_dhcp_info(struct e1000_adapter *adapter,
  4888. struct sk_buff *skb)
  4889. {
  4890. struct e1000_hw *hw = &adapter->hw;
  4891. u16 length, offset;
  4892. if (skb_vlan_tag_present(skb) &&
  4893. !((skb_vlan_tag_get(skb) == adapter->hw.mng_cookie.vlan_id) &&
  4894. (adapter->hw.mng_cookie.status &
  4895. E1000_MNG_DHCP_COOKIE_STATUS_VLAN)))
  4896. return 0;
  4897. if (skb->len <= MINIMUM_DHCP_PACKET_SIZE)
  4898. return 0;
  4899. if (((struct ethhdr *)skb->data)->h_proto != htons(ETH_P_IP))
  4900. return 0;
  4901. {
  4902. const struct iphdr *ip = (struct iphdr *)((u8 *)skb->data + 14);
  4903. struct udphdr *udp;
  4904. if (ip->protocol != IPPROTO_UDP)
  4905. return 0;
  4906. udp = (struct udphdr *)((u8 *)ip + (ip->ihl << 2));
  4907. if (ntohs(udp->dest) != 67)
  4908. return 0;
  4909. offset = (u8 *)udp + 8 - skb->data;
  4910. length = skb->len - offset;
  4911. return e1000e_mng_write_dhcp_info(hw, (u8 *)udp + 8, length);
  4912. }
  4913. return 0;
  4914. }
  4915. static int __e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
  4916. {
  4917. struct e1000_adapter *adapter = tx_ring->adapter;
  4918. netif_stop_queue(adapter->netdev);
  4919. /* Herbert's original patch had:
  4920. * smp_mb__after_netif_stop_queue();
  4921. * but since that doesn't exist yet, just open code it.
  4922. */
  4923. smp_mb();
  4924. /* We need to check again in a case another CPU has just
  4925. * made room available.
  4926. */
  4927. if (e1000_desc_unused(tx_ring) < size)
  4928. return -EBUSY;
  4929. /* A reprieve! */
  4930. netif_start_queue(adapter->netdev);
  4931. ++adapter->restart_queue;
  4932. return 0;
  4933. }
  4934. static int e1000_maybe_stop_tx(struct e1000_ring *tx_ring, int size)
  4935. {
  4936. BUG_ON(size > tx_ring->count);
  4937. if (e1000_desc_unused(tx_ring) >= size)
  4938. return 0;
  4939. return __e1000_maybe_stop_tx(tx_ring, size);
  4940. }
  4941. static netdev_tx_t e1000_xmit_frame(struct sk_buff *skb,
  4942. struct net_device *netdev)
  4943. {
  4944. struct e1000_adapter *adapter = netdev_priv(netdev);
  4945. struct e1000_ring *tx_ring = adapter->tx_ring;
  4946. unsigned int first;
  4947. unsigned int tx_flags = 0;
  4948. unsigned int len = skb_headlen(skb);
  4949. unsigned int nr_frags;
  4950. unsigned int mss;
  4951. int count = 0;
  4952. int tso;
  4953. unsigned int f;
  4954. __be16 protocol = vlan_get_protocol(skb);
  4955. if (test_bit(__E1000_DOWN, &adapter->state)) {
  4956. dev_kfree_skb_any(skb);
  4957. return NETDEV_TX_OK;
  4958. }
  4959. if (skb->len <= 0) {
  4960. dev_kfree_skb_any(skb);
  4961. return NETDEV_TX_OK;
  4962. }
  4963. /* The minimum packet size with TCTL.PSP set is 17 bytes so
  4964. * pad skb in order to meet this minimum size requirement
  4965. */
  4966. if (skb_put_padto(skb, 17))
  4967. return NETDEV_TX_OK;
  4968. mss = skb_shinfo(skb)->gso_size;
  4969. if (mss) {
  4970. u8 hdr_len;
  4971. /* TSO Workaround for 82571/2/3 Controllers -- if skb->data
  4972. * points to just header, pull a few bytes of payload from
  4973. * frags into skb->data
  4974. */
  4975. hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
  4976. /* we do this workaround for ES2LAN, but it is un-necessary,
  4977. * avoiding it could save a lot of cycles
  4978. */
  4979. if (skb->data_len && (hdr_len == len)) {
  4980. unsigned int pull_size;
  4981. pull_size = min_t(unsigned int, 4, skb->data_len);
  4982. if (!__pskb_pull_tail(skb, pull_size)) {
  4983. e_err("__pskb_pull_tail failed.\n");
  4984. dev_kfree_skb_any(skb);
  4985. return NETDEV_TX_OK;
  4986. }
  4987. len = skb_headlen(skb);
  4988. }
  4989. }
  4990. /* reserve a descriptor for the offload context */
  4991. if ((mss) || (skb->ip_summed == CHECKSUM_PARTIAL))
  4992. count++;
  4993. count++;
  4994. count += DIV_ROUND_UP(len, adapter->tx_fifo_limit);
  4995. nr_frags = skb_shinfo(skb)->nr_frags;
  4996. for (f = 0; f < nr_frags; f++)
  4997. count += DIV_ROUND_UP(skb_frag_size(&skb_shinfo(skb)->frags[f]),
  4998. adapter->tx_fifo_limit);
  4999. if (adapter->hw.mac.tx_pkt_filtering)
  5000. e1000_transfer_dhcp_info(adapter, skb);
  5001. /* need: count + 2 desc gap to keep tail from touching
  5002. * head, otherwise try next time
  5003. */
  5004. if (e1000_maybe_stop_tx(tx_ring, count + 2))
  5005. return NETDEV_TX_BUSY;
  5006. if (skb_vlan_tag_present(skb)) {
  5007. tx_flags |= E1000_TX_FLAGS_VLAN;
  5008. tx_flags |= (skb_vlan_tag_get(skb) <<
  5009. E1000_TX_FLAGS_VLAN_SHIFT);
  5010. }
  5011. first = tx_ring->next_to_use;
  5012. tso = e1000_tso(tx_ring, skb, protocol);
  5013. if (tso < 0) {
  5014. dev_kfree_skb_any(skb);
  5015. return NETDEV_TX_OK;
  5016. }
  5017. if (tso)
  5018. tx_flags |= E1000_TX_FLAGS_TSO;
  5019. else if (e1000_tx_csum(tx_ring, skb, protocol))
  5020. tx_flags |= E1000_TX_FLAGS_CSUM;
  5021. /* Old method was to assume IPv4 packet by default if TSO was enabled.
  5022. * 82571 hardware supports TSO capabilities for IPv6 as well...
  5023. * no longer assume, we must.
  5024. */
  5025. if (protocol == htons(ETH_P_IP))
  5026. tx_flags |= E1000_TX_FLAGS_IPV4;
  5027. if (unlikely(skb->no_fcs))
  5028. tx_flags |= E1000_TX_FLAGS_NO_FCS;
  5029. /* if count is 0 then mapping error has occurred */
  5030. count = e1000_tx_map(tx_ring, skb, first, adapter->tx_fifo_limit,
  5031. nr_frags);
  5032. if (count) {
  5033. if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
  5034. (adapter->flags & FLAG_HAS_HW_TIMESTAMP)) {
  5035. if (!adapter->tx_hwtstamp_skb) {
  5036. skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
  5037. tx_flags |= E1000_TX_FLAGS_HWTSTAMP;
  5038. adapter->tx_hwtstamp_skb = skb_get(skb);
  5039. adapter->tx_hwtstamp_start = jiffies;
  5040. schedule_work(&adapter->tx_hwtstamp_work);
  5041. } else {
  5042. adapter->tx_hwtstamp_skipped++;
  5043. }
  5044. }
  5045. skb_tx_timestamp(skb);
  5046. netdev_sent_queue(netdev, skb->len);
  5047. e1000_tx_queue(tx_ring, tx_flags, count);
  5048. /* Make sure there is space in the ring for the next send. */
  5049. e1000_maybe_stop_tx(tx_ring,
  5050. (MAX_SKB_FRAGS *
  5051. DIV_ROUND_UP(PAGE_SIZE,
  5052. adapter->tx_fifo_limit) + 2));
  5053. if (!skb->xmit_more ||
  5054. netif_xmit_stopped(netdev_get_tx_queue(netdev, 0))) {
  5055. if (adapter->flags2 & FLAG2_PCIM2PCI_ARBITER_WA)
  5056. e1000e_update_tdt_wa(tx_ring,
  5057. tx_ring->next_to_use);
  5058. else
  5059. writel(tx_ring->next_to_use, tx_ring->tail);
  5060. /* we need this if more than one processor can write
  5061. * to our tail at a time, it synchronizes IO on
  5062. *IA64/Altix systems
  5063. */
  5064. mmiowb();
  5065. }
  5066. } else {
  5067. dev_kfree_skb_any(skb);
  5068. tx_ring->buffer_info[first].time_stamp = 0;
  5069. tx_ring->next_to_use = first;
  5070. }
  5071. return NETDEV_TX_OK;
  5072. }
  5073. /**
  5074. * e1000_tx_timeout - Respond to a Tx Hang
  5075. * @netdev: network interface device structure
  5076. **/
  5077. static void e1000_tx_timeout(struct net_device *netdev)
  5078. {
  5079. struct e1000_adapter *adapter = netdev_priv(netdev);
  5080. /* Do the reset outside of interrupt context */
  5081. adapter->tx_timeout_count++;
  5082. schedule_work(&adapter->reset_task);
  5083. }
  5084. static void e1000_reset_task(struct work_struct *work)
  5085. {
  5086. struct e1000_adapter *adapter;
  5087. adapter = container_of(work, struct e1000_adapter, reset_task);
  5088. /* don't run the task if already down */
  5089. if (test_bit(__E1000_DOWN, &adapter->state))
  5090. return;
  5091. if (!(adapter->flags & FLAG_RESTART_NOW)) {
  5092. e1000e_dump(adapter);
  5093. e_err("Reset adapter unexpectedly\n");
  5094. }
  5095. e1000e_reinit_locked(adapter);
  5096. }
  5097. /**
  5098. * e1000_get_stats64 - Get System Network Statistics
  5099. * @netdev: network interface device structure
  5100. * @stats: rtnl_link_stats64 pointer
  5101. *
  5102. * Returns the address of the device statistics structure.
  5103. **/
  5104. void e1000e_get_stats64(struct net_device *netdev,
  5105. struct rtnl_link_stats64 *stats)
  5106. {
  5107. struct e1000_adapter *adapter = netdev_priv(netdev);
  5108. spin_lock(&adapter->stats64_lock);
  5109. e1000e_update_stats(adapter);
  5110. /* Fill out the OS statistics structure */
  5111. stats->rx_bytes = adapter->stats.gorc;
  5112. stats->rx_packets = adapter->stats.gprc;
  5113. stats->tx_bytes = adapter->stats.gotc;
  5114. stats->tx_packets = adapter->stats.gptc;
  5115. stats->multicast = adapter->stats.mprc;
  5116. stats->collisions = adapter->stats.colc;
  5117. /* Rx Errors */
  5118. /* RLEC on some newer hardware can be incorrect so build
  5119. * our own version based on RUC and ROC
  5120. */
  5121. stats->rx_errors = adapter->stats.rxerrc +
  5122. adapter->stats.crcerrs + adapter->stats.algnerrc +
  5123. adapter->stats.ruc + adapter->stats.roc + adapter->stats.cexterr;
  5124. stats->rx_length_errors = adapter->stats.ruc + adapter->stats.roc;
  5125. stats->rx_crc_errors = adapter->stats.crcerrs;
  5126. stats->rx_frame_errors = adapter->stats.algnerrc;
  5127. stats->rx_missed_errors = adapter->stats.mpc;
  5128. /* Tx Errors */
  5129. stats->tx_errors = adapter->stats.ecol + adapter->stats.latecol;
  5130. stats->tx_aborted_errors = adapter->stats.ecol;
  5131. stats->tx_window_errors = adapter->stats.latecol;
  5132. stats->tx_carrier_errors = adapter->stats.tncrs;
  5133. /* Tx Dropped needs to be maintained elsewhere */
  5134. spin_unlock(&adapter->stats64_lock);
  5135. }
  5136. /**
  5137. * e1000_change_mtu - Change the Maximum Transfer Unit
  5138. * @netdev: network interface device structure
  5139. * @new_mtu: new value for maximum frame size
  5140. *
  5141. * Returns 0 on success, negative on failure
  5142. **/
  5143. static int e1000_change_mtu(struct net_device *netdev, int new_mtu)
  5144. {
  5145. struct e1000_adapter *adapter = netdev_priv(netdev);
  5146. int max_frame = new_mtu + VLAN_ETH_HLEN + ETH_FCS_LEN;
  5147. /* Jumbo frame support */
  5148. if ((new_mtu > ETH_DATA_LEN) &&
  5149. !(adapter->flags & FLAG_HAS_JUMBO_FRAMES)) {
  5150. e_err("Jumbo Frames not supported.\n");
  5151. return -EINVAL;
  5152. }
  5153. /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
  5154. if ((adapter->hw.mac.type >= e1000_pch2lan) &&
  5155. !(adapter->flags2 & FLAG2_CRC_STRIPPING) &&
  5156. (new_mtu > ETH_DATA_LEN)) {
  5157. e_err("Jumbo Frames not supported on this device when CRC stripping is disabled.\n");
  5158. return -EINVAL;
  5159. }
  5160. while (test_and_set_bit(__E1000_RESETTING, &adapter->state))
  5161. usleep_range(1000, 2000);
  5162. /* e1000e_down -> e1000e_reset dependent on max_frame_size & mtu */
  5163. adapter->max_frame_size = max_frame;
  5164. e_info("changing MTU from %d to %d\n", netdev->mtu, new_mtu);
  5165. netdev->mtu = new_mtu;
  5166. pm_runtime_get_sync(netdev->dev.parent);
  5167. if (netif_running(netdev))
  5168. e1000e_down(adapter, true);
  5169. /* NOTE: netdev_alloc_skb reserves 16 bytes, and typically NET_IP_ALIGN
  5170. * means we reserve 2 more, this pushes us to allocate from the next
  5171. * larger slab size.
  5172. * i.e. RXBUFFER_2048 --> size-4096 slab
  5173. * However with the new *_jumbo_rx* routines, jumbo receives will use
  5174. * fragmented skbs
  5175. */
  5176. if (max_frame <= 2048)
  5177. adapter->rx_buffer_len = 2048;
  5178. else
  5179. adapter->rx_buffer_len = 4096;
  5180. /* adjust allocation if LPE protects us, and we aren't using SBP */
  5181. if (max_frame <= (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN))
  5182. adapter->rx_buffer_len = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN;
  5183. if (netif_running(netdev))
  5184. e1000e_up(adapter);
  5185. else
  5186. e1000e_reset(adapter);
  5187. pm_runtime_put_sync(netdev->dev.parent);
  5188. clear_bit(__E1000_RESETTING, &adapter->state);
  5189. return 0;
  5190. }
  5191. static int e1000_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
  5192. int cmd)
  5193. {
  5194. struct e1000_adapter *adapter = netdev_priv(netdev);
  5195. struct mii_ioctl_data *data = if_mii(ifr);
  5196. if (adapter->hw.phy.media_type != e1000_media_type_copper)
  5197. return -EOPNOTSUPP;
  5198. switch (cmd) {
  5199. case SIOCGMIIPHY:
  5200. data->phy_id = adapter->hw.phy.addr;
  5201. break;
  5202. case SIOCGMIIREG:
  5203. e1000_phy_read_status(adapter);
  5204. switch (data->reg_num & 0x1F) {
  5205. case MII_BMCR:
  5206. data->val_out = adapter->phy_regs.bmcr;
  5207. break;
  5208. case MII_BMSR:
  5209. data->val_out = adapter->phy_regs.bmsr;
  5210. break;
  5211. case MII_PHYSID1:
  5212. data->val_out = (adapter->hw.phy.id >> 16);
  5213. break;
  5214. case MII_PHYSID2:
  5215. data->val_out = (adapter->hw.phy.id & 0xFFFF);
  5216. break;
  5217. case MII_ADVERTISE:
  5218. data->val_out = adapter->phy_regs.advertise;
  5219. break;
  5220. case MII_LPA:
  5221. data->val_out = adapter->phy_regs.lpa;
  5222. break;
  5223. case MII_EXPANSION:
  5224. data->val_out = adapter->phy_regs.expansion;
  5225. break;
  5226. case MII_CTRL1000:
  5227. data->val_out = adapter->phy_regs.ctrl1000;
  5228. break;
  5229. case MII_STAT1000:
  5230. data->val_out = adapter->phy_regs.stat1000;
  5231. break;
  5232. case MII_ESTATUS:
  5233. data->val_out = adapter->phy_regs.estatus;
  5234. break;
  5235. default:
  5236. return -EIO;
  5237. }
  5238. break;
  5239. case SIOCSMIIREG:
  5240. default:
  5241. return -EOPNOTSUPP;
  5242. }
  5243. return 0;
  5244. }
  5245. /**
  5246. * e1000e_hwtstamp_ioctl - control hardware time stamping
  5247. * @netdev: network interface device structure
  5248. * @ifreq: interface request
  5249. *
  5250. * Outgoing time stamping can be enabled and disabled. Play nice and
  5251. * disable it when requested, although it shouldn't cause any overhead
  5252. * when no packet needs it. At most one packet in the queue may be
  5253. * marked for time stamping, otherwise it would be impossible to tell
  5254. * for sure to which packet the hardware time stamp belongs.
  5255. *
  5256. * Incoming time stamping has to be configured via the hardware filters.
  5257. * Not all combinations are supported, in particular event type has to be
  5258. * specified. Matching the kind of event packet is not supported, with the
  5259. * exception of "all V2 events regardless of level 2 or 4".
  5260. **/
  5261. static int e1000e_hwtstamp_set(struct net_device *netdev, struct ifreq *ifr)
  5262. {
  5263. struct e1000_adapter *adapter = netdev_priv(netdev);
  5264. struct hwtstamp_config config;
  5265. int ret_val;
  5266. if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
  5267. return -EFAULT;
  5268. ret_val = e1000e_config_hwtstamp(adapter, &config);
  5269. if (ret_val)
  5270. return ret_val;
  5271. switch (config.rx_filter) {
  5272. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  5273. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  5274. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  5275. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  5276. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  5277. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  5278. /* With V2 type filters which specify a Sync or Delay Request,
  5279. * Path Delay Request/Response messages are also time stamped
  5280. * by hardware so notify the caller the requested packets plus
  5281. * some others are time stamped.
  5282. */
  5283. config.rx_filter = HWTSTAMP_FILTER_SOME;
  5284. break;
  5285. default:
  5286. break;
  5287. }
  5288. return copy_to_user(ifr->ifr_data, &config,
  5289. sizeof(config)) ? -EFAULT : 0;
  5290. }
  5291. static int e1000e_hwtstamp_get(struct net_device *netdev, struct ifreq *ifr)
  5292. {
  5293. struct e1000_adapter *adapter = netdev_priv(netdev);
  5294. return copy_to_user(ifr->ifr_data, &adapter->hwtstamp_config,
  5295. sizeof(adapter->hwtstamp_config)) ? -EFAULT : 0;
  5296. }
  5297. static int e1000_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
  5298. {
  5299. switch (cmd) {
  5300. case SIOCGMIIPHY:
  5301. case SIOCGMIIREG:
  5302. case SIOCSMIIREG:
  5303. return e1000_mii_ioctl(netdev, ifr, cmd);
  5304. case SIOCSHWTSTAMP:
  5305. return e1000e_hwtstamp_set(netdev, ifr);
  5306. case SIOCGHWTSTAMP:
  5307. return e1000e_hwtstamp_get(netdev, ifr);
  5308. default:
  5309. return -EOPNOTSUPP;
  5310. }
  5311. }
  5312. static int e1000_init_phy_wakeup(struct e1000_adapter *adapter, u32 wufc)
  5313. {
  5314. struct e1000_hw *hw = &adapter->hw;
  5315. u32 i, mac_reg, wuc;
  5316. u16 phy_reg, wuc_enable;
  5317. int retval;
  5318. /* copy MAC RARs to PHY RARs */
  5319. e1000_copy_rx_addrs_to_phy_ich8lan(hw);
  5320. retval = hw->phy.ops.acquire(hw);
  5321. if (retval) {
  5322. e_err("Could not acquire PHY\n");
  5323. return retval;
  5324. }
  5325. /* Enable access to wakeup registers on and set page to BM_WUC_PAGE */
  5326. retval = e1000_enable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
  5327. if (retval)
  5328. goto release;
  5329. /* copy MAC MTA to PHY MTA - only needed for pchlan */
  5330. for (i = 0; i < adapter->hw.mac.mta_reg_count; i++) {
  5331. mac_reg = E1000_READ_REG_ARRAY(hw, E1000_MTA, i);
  5332. hw->phy.ops.write_reg_page(hw, BM_MTA(i),
  5333. (u16)(mac_reg & 0xFFFF));
  5334. hw->phy.ops.write_reg_page(hw, BM_MTA(i) + 1,
  5335. (u16)((mac_reg >> 16) & 0xFFFF));
  5336. }
  5337. /* configure PHY Rx Control register */
  5338. hw->phy.ops.read_reg_page(&adapter->hw, BM_RCTL, &phy_reg);
  5339. mac_reg = er32(RCTL);
  5340. if (mac_reg & E1000_RCTL_UPE)
  5341. phy_reg |= BM_RCTL_UPE;
  5342. if (mac_reg & E1000_RCTL_MPE)
  5343. phy_reg |= BM_RCTL_MPE;
  5344. phy_reg &= ~(BM_RCTL_MO_MASK);
  5345. if (mac_reg & E1000_RCTL_MO_3)
  5346. phy_reg |= (((mac_reg & E1000_RCTL_MO_3) >> E1000_RCTL_MO_SHIFT)
  5347. << BM_RCTL_MO_SHIFT);
  5348. if (mac_reg & E1000_RCTL_BAM)
  5349. phy_reg |= BM_RCTL_BAM;
  5350. if (mac_reg & E1000_RCTL_PMCF)
  5351. phy_reg |= BM_RCTL_PMCF;
  5352. mac_reg = er32(CTRL);
  5353. if (mac_reg & E1000_CTRL_RFCE)
  5354. phy_reg |= BM_RCTL_RFCE;
  5355. hw->phy.ops.write_reg_page(&adapter->hw, BM_RCTL, phy_reg);
  5356. wuc = E1000_WUC_PME_EN;
  5357. if (wufc & (E1000_WUFC_MAG | E1000_WUFC_LNKC))
  5358. wuc |= E1000_WUC_APME;
  5359. /* enable PHY wakeup in MAC register */
  5360. ew32(WUFC, wufc);
  5361. ew32(WUC, (E1000_WUC_PHY_WAKE | E1000_WUC_APMPME |
  5362. E1000_WUC_PME_STATUS | wuc));
  5363. /* configure and enable PHY wakeup in PHY registers */
  5364. hw->phy.ops.write_reg_page(&adapter->hw, BM_WUFC, wufc);
  5365. hw->phy.ops.write_reg_page(&adapter->hw, BM_WUC, wuc);
  5366. /* activate PHY wakeup */
  5367. wuc_enable |= BM_WUC_ENABLE_BIT | BM_WUC_HOST_WU_BIT;
  5368. retval = e1000_disable_phy_wakeup_reg_access_bm(hw, &wuc_enable);
  5369. if (retval)
  5370. e_err("Could not set PHY Host Wakeup bit\n");
  5371. release:
  5372. hw->phy.ops.release(hw);
  5373. return retval;
  5374. }
  5375. static void e1000e_flush_lpic(struct pci_dev *pdev)
  5376. {
  5377. struct net_device *netdev = pci_get_drvdata(pdev);
  5378. struct e1000_adapter *adapter = netdev_priv(netdev);
  5379. struct e1000_hw *hw = &adapter->hw;
  5380. u32 ret_val;
  5381. pm_runtime_get_sync(netdev->dev.parent);
  5382. ret_val = hw->phy.ops.acquire(hw);
  5383. if (ret_val)
  5384. goto fl_out;
  5385. pr_info("EEE TX LPI TIMER: %08X\n",
  5386. er32(LPIC) >> E1000_LPIC_LPIET_SHIFT);
  5387. hw->phy.ops.release(hw);
  5388. fl_out:
  5389. pm_runtime_put_sync(netdev->dev.parent);
  5390. }
  5391. static int e1000e_pm_freeze(struct device *dev)
  5392. {
  5393. struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev));
  5394. struct e1000_adapter *adapter = netdev_priv(netdev);
  5395. netif_device_detach(netdev);
  5396. if (netif_running(netdev)) {
  5397. int count = E1000_CHECK_RESET_COUNT;
  5398. while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
  5399. usleep_range(10000, 20000);
  5400. WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
  5401. /* Quiesce the device without resetting the hardware */
  5402. e1000e_down(adapter, false);
  5403. e1000_free_irq(adapter);
  5404. }
  5405. e1000e_reset_interrupt_capability(adapter);
  5406. /* Allow time for pending master requests to run */
  5407. e1000e_disable_pcie_master(&adapter->hw);
  5408. return 0;
  5409. }
  5410. static int __e1000_shutdown(struct pci_dev *pdev, bool runtime)
  5411. {
  5412. struct net_device *netdev = pci_get_drvdata(pdev);
  5413. struct e1000_adapter *adapter = netdev_priv(netdev);
  5414. struct e1000_hw *hw = &adapter->hw;
  5415. u32 ctrl, ctrl_ext, rctl, status;
  5416. /* Runtime suspend should only enable wakeup for link changes */
  5417. u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
  5418. int retval = 0;
  5419. status = er32(STATUS);
  5420. if (status & E1000_STATUS_LU)
  5421. wufc &= ~E1000_WUFC_LNKC;
  5422. if (wufc) {
  5423. e1000_setup_rctl(adapter);
  5424. e1000e_set_rx_mode(netdev);
  5425. /* turn on all-multi mode if wake on multicast is enabled */
  5426. if (wufc & E1000_WUFC_MC) {
  5427. rctl = er32(RCTL);
  5428. rctl |= E1000_RCTL_MPE;
  5429. ew32(RCTL, rctl);
  5430. }
  5431. ctrl = er32(CTRL);
  5432. ctrl |= E1000_CTRL_ADVD3WUC;
  5433. if (!(adapter->flags2 & FLAG2_HAS_PHY_WAKEUP))
  5434. ctrl |= E1000_CTRL_EN_PHY_PWR_MGMT;
  5435. ew32(CTRL, ctrl);
  5436. if (adapter->hw.phy.media_type == e1000_media_type_fiber ||
  5437. adapter->hw.phy.media_type ==
  5438. e1000_media_type_internal_serdes) {
  5439. /* keep the laser running in D3 */
  5440. ctrl_ext = er32(CTRL_EXT);
  5441. ctrl_ext |= E1000_CTRL_EXT_SDP3_DATA;
  5442. ew32(CTRL_EXT, ctrl_ext);
  5443. }
  5444. if (!runtime)
  5445. e1000e_power_up_phy(adapter);
  5446. if (adapter->flags & FLAG_IS_ICH)
  5447. e1000_suspend_workarounds_ich8lan(&adapter->hw);
  5448. if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
  5449. /* enable wakeup by the PHY */
  5450. retval = e1000_init_phy_wakeup(adapter, wufc);
  5451. if (retval)
  5452. return retval;
  5453. } else {
  5454. /* enable wakeup by the MAC */
  5455. ew32(WUFC, wufc);
  5456. ew32(WUC, E1000_WUC_PME_EN);
  5457. }
  5458. } else {
  5459. ew32(WUC, 0);
  5460. ew32(WUFC, 0);
  5461. e1000_power_down_phy(adapter);
  5462. }
  5463. if (adapter->hw.phy.type == e1000_phy_igp_3) {
  5464. e1000e_igp3_phy_powerdown_workaround_ich8lan(&adapter->hw);
  5465. } else if (hw->mac.type >= e1000_pch_lpt) {
  5466. if (!(wufc & (E1000_WUFC_EX | E1000_WUFC_MC | E1000_WUFC_BC)))
  5467. /* ULP does not support wake from unicast, multicast
  5468. * or broadcast.
  5469. */
  5470. retval = e1000_enable_ulp_lpt_lp(hw, !runtime);
  5471. if (retval)
  5472. return retval;
  5473. }
  5474. /* Ensure that the appropriate bits are set in LPI_CTRL
  5475. * for EEE in Sx
  5476. */
  5477. if ((hw->phy.type >= e1000_phy_i217) &&
  5478. adapter->eee_advert && hw->dev_spec.ich8lan.eee_lp_ability) {
  5479. u16 lpi_ctrl = 0;
  5480. retval = hw->phy.ops.acquire(hw);
  5481. if (!retval) {
  5482. retval = e1e_rphy_locked(hw, I82579_LPI_CTRL,
  5483. &lpi_ctrl);
  5484. if (!retval) {
  5485. if (adapter->eee_advert &
  5486. hw->dev_spec.ich8lan.eee_lp_ability &
  5487. I82579_EEE_100_SUPPORTED)
  5488. lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE;
  5489. if (adapter->eee_advert &
  5490. hw->dev_spec.ich8lan.eee_lp_ability &
  5491. I82579_EEE_1000_SUPPORTED)
  5492. lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE;
  5493. retval = e1e_wphy_locked(hw, I82579_LPI_CTRL,
  5494. lpi_ctrl);
  5495. }
  5496. }
  5497. hw->phy.ops.release(hw);
  5498. }
  5499. /* Release control of h/w to f/w. If f/w is AMT enabled, this
  5500. * would have already happened in close and is redundant.
  5501. */
  5502. e1000e_release_hw_control(adapter);
  5503. pci_clear_master(pdev);
  5504. /* The pci-e switch on some quad port adapters will report a
  5505. * correctable error when the MAC transitions from D0 to D3. To
  5506. * prevent this we need to mask off the correctable errors on the
  5507. * downstream port of the pci-e switch.
  5508. *
  5509. * We don't have the associated upstream bridge while assigning
  5510. * the PCI device into guest. For example, the KVM on power is
  5511. * one of the cases.
  5512. */
  5513. if (adapter->flags & FLAG_IS_QUAD_PORT) {
  5514. struct pci_dev *us_dev = pdev->bus->self;
  5515. u16 devctl;
  5516. if (!us_dev)
  5517. return 0;
  5518. pcie_capability_read_word(us_dev, PCI_EXP_DEVCTL, &devctl);
  5519. pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL,
  5520. (devctl & ~PCI_EXP_DEVCTL_CERE));
  5521. pci_save_state(pdev);
  5522. pci_prepare_to_sleep(pdev);
  5523. pcie_capability_write_word(us_dev, PCI_EXP_DEVCTL, devctl);
  5524. }
  5525. return 0;
  5526. }
  5527. /**
  5528. * __e1000e_disable_aspm - Disable ASPM states
  5529. * @pdev: pointer to PCI device struct
  5530. * @state: bit-mask of ASPM states to disable
  5531. * @locked: indication if this context holds pci_bus_sem locked.
  5532. *
  5533. * Some devices *must* have certain ASPM states disabled per hardware errata.
  5534. **/
  5535. static void __e1000e_disable_aspm(struct pci_dev *pdev, u16 state, int locked)
  5536. {
  5537. struct pci_dev *parent = pdev->bus->self;
  5538. u16 aspm_dis_mask = 0;
  5539. u16 pdev_aspmc, parent_aspmc;
  5540. switch (state) {
  5541. case PCIE_LINK_STATE_L0S:
  5542. case PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1:
  5543. aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L0S;
  5544. /* fall-through - can't have L1 without L0s */
  5545. case PCIE_LINK_STATE_L1:
  5546. aspm_dis_mask |= PCI_EXP_LNKCTL_ASPM_L1;
  5547. break;
  5548. default:
  5549. return;
  5550. }
  5551. pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc);
  5552. pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC;
  5553. if (parent) {
  5554. pcie_capability_read_word(parent, PCI_EXP_LNKCTL,
  5555. &parent_aspmc);
  5556. parent_aspmc &= PCI_EXP_LNKCTL_ASPMC;
  5557. }
  5558. /* Nothing to do if the ASPM states to be disabled already are */
  5559. if (!(pdev_aspmc & aspm_dis_mask) &&
  5560. (!parent || !(parent_aspmc & aspm_dis_mask)))
  5561. return;
  5562. dev_info(&pdev->dev, "Disabling ASPM %s %s\n",
  5563. (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L0S) ?
  5564. "L0s" : "",
  5565. (aspm_dis_mask & pdev_aspmc & PCI_EXP_LNKCTL_ASPM_L1) ?
  5566. "L1" : "");
  5567. #ifdef CONFIG_PCIEASPM
  5568. if (locked)
  5569. pci_disable_link_state_locked(pdev, state);
  5570. else
  5571. pci_disable_link_state(pdev, state);
  5572. /* Double-check ASPM control. If not disabled by the above, the
  5573. * BIOS is preventing that from happening (or CONFIG_PCIEASPM is
  5574. * not enabled); override by writing PCI config space directly.
  5575. */
  5576. pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &pdev_aspmc);
  5577. pdev_aspmc &= PCI_EXP_LNKCTL_ASPMC;
  5578. if (!(aspm_dis_mask & pdev_aspmc))
  5579. return;
  5580. #endif
  5581. /* Both device and parent should have the same ASPM setting.
  5582. * Disable ASPM in downstream component first and then upstream.
  5583. */
  5584. pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, aspm_dis_mask);
  5585. if (parent)
  5586. pcie_capability_clear_word(parent, PCI_EXP_LNKCTL,
  5587. aspm_dis_mask);
  5588. }
  5589. /**
  5590. * e1000e_disable_aspm - Disable ASPM states.
  5591. * @pdev: pointer to PCI device struct
  5592. * @state: bit-mask of ASPM states to disable
  5593. *
  5594. * This function acquires the pci_bus_sem!
  5595. * Some devices *must* have certain ASPM states disabled per hardware errata.
  5596. **/
  5597. static void e1000e_disable_aspm(struct pci_dev *pdev, u16 state)
  5598. {
  5599. __e1000e_disable_aspm(pdev, state, 0);
  5600. }
  5601. /**
  5602. * e1000e_disable_aspm_locked Disable ASPM states.
  5603. * @pdev: pointer to PCI device struct
  5604. * @state: bit-mask of ASPM states to disable
  5605. *
  5606. * This function must be called with pci_bus_sem acquired!
  5607. * Some devices *must* have certain ASPM states disabled per hardware errata.
  5608. **/
  5609. static void e1000e_disable_aspm_locked(struct pci_dev *pdev, u16 state)
  5610. {
  5611. __e1000e_disable_aspm(pdev, state, 1);
  5612. }
  5613. #ifdef CONFIG_PM
  5614. static int __e1000_resume(struct pci_dev *pdev)
  5615. {
  5616. struct net_device *netdev = pci_get_drvdata(pdev);
  5617. struct e1000_adapter *adapter = netdev_priv(netdev);
  5618. struct e1000_hw *hw = &adapter->hw;
  5619. u16 aspm_disable_flag = 0;
  5620. if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
  5621. aspm_disable_flag = PCIE_LINK_STATE_L0S;
  5622. if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
  5623. aspm_disable_flag |= PCIE_LINK_STATE_L1;
  5624. if (aspm_disable_flag)
  5625. e1000e_disable_aspm(pdev, aspm_disable_flag);
  5626. pci_set_master(pdev);
  5627. if (hw->mac.type >= e1000_pch2lan)
  5628. e1000_resume_workarounds_pchlan(&adapter->hw);
  5629. e1000e_power_up_phy(adapter);
  5630. /* report the system wakeup cause from S3/S4 */
  5631. if (adapter->flags2 & FLAG2_HAS_PHY_WAKEUP) {
  5632. u16 phy_data;
  5633. e1e_rphy(&adapter->hw, BM_WUS, &phy_data);
  5634. if (phy_data) {
  5635. e_info("PHY Wakeup cause - %s\n",
  5636. phy_data & E1000_WUS_EX ? "Unicast Packet" :
  5637. phy_data & E1000_WUS_MC ? "Multicast Packet" :
  5638. phy_data & E1000_WUS_BC ? "Broadcast Packet" :
  5639. phy_data & E1000_WUS_MAG ? "Magic Packet" :
  5640. phy_data & E1000_WUS_LNKC ?
  5641. "Link Status Change" : "other");
  5642. }
  5643. e1e_wphy(&adapter->hw, BM_WUS, ~0);
  5644. } else {
  5645. u32 wus = er32(WUS);
  5646. if (wus) {
  5647. e_info("MAC Wakeup cause - %s\n",
  5648. wus & E1000_WUS_EX ? "Unicast Packet" :
  5649. wus & E1000_WUS_MC ? "Multicast Packet" :
  5650. wus & E1000_WUS_BC ? "Broadcast Packet" :
  5651. wus & E1000_WUS_MAG ? "Magic Packet" :
  5652. wus & E1000_WUS_LNKC ? "Link Status Change" :
  5653. "other");
  5654. }
  5655. ew32(WUS, ~0);
  5656. }
  5657. e1000e_reset(adapter);
  5658. e1000_init_manageability_pt(adapter);
  5659. /* If the controller has AMT, do not set DRV_LOAD until the interface
  5660. * is up. For all other cases, let the f/w know that the h/w is now
  5661. * under the control of the driver.
  5662. */
  5663. if (!(adapter->flags & FLAG_HAS_AMT))
  5664. e1000e_get_hw_control(adapter);
  5665. return 0;
  5666. }
  5667. #ifdef CONFIG_PM_SLEEP
  5668. static int e1000e_pm_thaw(struct device *dev)
  5669. {
  5670. struct net_device *netdev = pci_get_drvdata(to_pci_dev(dev));
  5671. struct e1000_adapter *adapter = netdev_priv(netdev);
  5672. e1000e_set_interrupt_capability(adapter);
  5673. if (netif_running(netdev)) {
  5674. u32 err = e1000_request_irq(adapter);
  5675. if (err)
  5676. return err;
  5677. e1000e_up(adapter);
  5678. }
  5679. netif_device_attach(netdev);
  5680. return 0;
  5681. }
  5682. static int e1000e_pm_suspend(struct device *dev)
  5683. {
  5684. struct pci_dev *pdev = to_pci_dev(dev);
  5685. int rc;
  5686. e1000e_flush_lpic(pdev);
  5687. e1000e_pm_freeze(dev);
  5688. rc = __e1000_shutdown(pdev, false);
  5689. if (rc)
  5690. e1000e_pm_thaw(dev);
  5691. return rc;
  5692. }
  5693. static int e1000e_pm_resume(struct device *dev)
  5694. {
  5695. struct pci_dev *pdev = to_pci_dev(dev);
  5696. int rc;
  5697. rc = __e1000_resume(pdev);
  5698. if (rc)
  5699. return rc;
  5700. return e1000e_pm_thaw(dev);
  5701. }
  5702. #endif /* CONFIG_PM_SLEEP */
  5703. static int e1000e_pm_runtime_idle(struct device *dev)
  5704. {
  5705. struct pci_dev *pdev = to_pci_dev(dev);
  5706. struct net_device *netdev = pci_get_drvdata(pdev);
  5707. struct e1000_adapter *adapter = netdev_priv(netdev);
  5708. u16 eee_lp;
  5709. eee_lp = adapter->hw.dev_spec.ich8lan.eee_lp_ability;
  5710. if (!e1000e_has_link(adapter)) {
  5711. adapter->hw.dev_spec.ich8lan.eee_lp_ability = eee_lp;
  5712. pm_schedule_suspend(dev, 5 * MSEC_PER_SEC);
  5713. }
  5714. return -EBUSY;
  5715. }
  5716. static int e1000e_pm_runtime_resume(struct device *dev)
  5717. {
  5718. struct pci_dev *pdev = to_pci_dev(dev);
  5719. struct net_device *netdev = pci_get_drvdata(pdev);
  5720. struct e1000_adapter *adapter = netdev_priv(netdev);
  5721. int rc;
  5722. rc = __e1000_resume(pdev);
  5723. if (rc)
  5724. return rc;
  5725. if (netdev->flags & IFF_UP)
  5726. e1000e_up(adapter);
  5727. return rc;
  5728. }
  5729. static int e1000e_pm_runtime_suspend(struct device *dev)
  5730. {
  5731. struct pci_dev *pdev = to_pci_dev(dev);
  5732. struct net_device *netdev = pci_get_drvdata(pdev);
  5733. struct e1000_adapter *adapter = netdev_priv(netdev);
  5734. if (netdev->flags & IFF_UP) {
  5735. int count = E1000_CHECK_RESET_COUNT;
  5736. while (test_bit(__E1000_RESETTING, &adapter->state) && count--)
  5737. usleep_range(10000, 20000);
  5738. WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
  5739. /* Down the device without resetting the hardware */
  5740. e1000e_down(adapter, false);
  5741. }
  5742. if (__e1000_shutdown(pdev, true)) {
  5743. e1000e_pm_runtime_resume(dev);
  5744. return -EBUSY;
  5745. }
  5746. return 0;
  5747. }
  5748. #endif /* CONFIG_PM */
  5749. static void e1000_shutdown(struct pci_dev *pdev)
  5750. {
  5751. e1000e_flush_lpic(pdev);
  5752. e1000e_pm_freeze(&pdev->dev);
  5753. __e1000_shutdown(pdev, false);
  5754. }
  5755. #ifdef CONFIG_NET_POLL_CONTROLLER
  5756. static irqreturn_t e1000_intr_msix(int __always_unused irq, void *data)
  5757. {
  5758. struct net_device *netdev = data;
  5759. struct e1000_adapter *adapter = netdev_priv(netdev);
  5760. if (adapter->msix_entries) {
  5761. int vector, msix_irq;
  5762. vector = 0;
  5763. msix_irq = adapter->msix_entries[vector].vector;
  5764. if (disable_hardirq(msix_irq))
  5765. e1000_intr_msix_rx(msix_irq, netdev);
  5766. enable_irq(msix_irq);
  5767. vector++;
  5768. msix_irq = adapter->msix_entries[vector].vector;
  5769. if (disable_hardirq(msix_irq))
  5770. e1000_intr_msix_tx(msix_irq, netdev);
  5771. enable_irq(msix_irq);
  5772. vector++;
  5773. msix_irq = adapter->msix_entries[vector].vector;
  5774. if (disable_hardirq(msix_irq))
  5775. e1000_msix_other(msix_irq, netdev);
  5776. enable_irq(msix_irq);
  5777. }
  5778. return IRQ_HANDLED;
  5779. }
  5780. /**
  5781. * e1000_netpoll
  5782. * @netdev: network interface device structure
  5783. *
  5784. * Polling 'interrupt' - used by things like netconsole to send skbs
  5785. * without having to re-enable interrupts. It's not called while
  5786. * the interrupt routine is executing.
  5787. */
  5788. static void e1000_netpoll(struct net_device *netdev)
  5789. {
  5790. struct e1000_adapter *adapter = netdev_priv(netdev);
  5791. switch (adapter->int_mode) {
  5792. case E1000E_INT_MODE_MSIX:
  5793. e1000_intr_msix(adapter->pdev->irq, netdev);
  5794. break;
  5795. case E1000E_INT_MODE_MSI:
  5796. if (disable_hardirq(adapter->pdev->irq))
  5797. e1000_intr_msi(adapter->pdev->irq, netdev);
  5798. enable_irq(adapter->pdev->irq);
  5799. break;
  5800. default: /* E1000E_INT_MODE_LEGACY */
  5801. if (disable_hardirq(adapter->pdev->irq))
  5802. e1000_intr(adapter->pdev->irq, netdev);
  5803. enable_irq(adapter->pdev->irq);
  5804. break;
  5805. }
  5806. }
  5807. #endif
  5808. /**
  5809. * e1000_io_error_detected - called when PCI error is detected
  5810. * @pdev: Pointer to PCI device
  5811. * @state: The current pci connection state
  5812. *
  5813. * This function is called after a PCI bus error affecting
  5814. * this device has been detected.
  5815. */
  5816. static pci_ers_result_t e1000_io_error_detected(struct pci_dev *pdev,
  5817. pci_channel_state_t state)
  5818. {
  5819. struct net_device *netdev = pci_get_drvdata(pdev);
  5820. struct e1000_adapter *adapter = netdev_priv(netdev);
  5821. netif_device_detach(netdev);
  5822. if (state == pci_channel_io_perm_failure)
  5823. return PCI_ERS_RESULT_DISCONNECT;
  5824. if (netif_running(netdev))
  5825. e1000e_down(adapter, true);
  5826. pci_disable_device(pdev);
  5827. /* Request a slot slot reset. */
  5828. return PCI_ERS_RESULT_NEED_RESET;
  5829. }
  5830. /**
  5831. * e1000_io_slot_reset - called after the pci bus has been reset.
  5832. * @pdev: Pointer to PCI device
  5833. *
  5834. * Restart the card from scratch, as if from a cold-boot. Implementation
  5835. * resembles the first-half of the e1000e_pm_resume routine.
  5836. */
  5837. static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
  5838. {
  5839. struct net_device *netdev = pci_get_drvdata(pdev);
  5840. struct e1000_adapter *adapter = netdev_priv(netdev);
  5841. struct e1000_hw *hw = &adapter->hw;
  5842. u16 aspm_disable_flag = 0;
  5843. int err;
  5844. pci_ers_result_t result;
  5845. if (adapter->flags2 & FLAG2_DISABLE_ASPM_L0S)
  5846. aspm_disable_flag = PCIE_LINK_STATE_L0S;
  5847. if (adapter->flags2 & FLAG2_DISABLE_ASPM_L1)
  5848. aspm_disable_flag |= PCIE_LINK_STATE_L1;
  5849. if (aspm_disable_flag)
  5850. e1000e_disable_aspm_locked(pdev, aspm_disable_flag);
  5851. err = pci_enable_device_mem(pdev);
  5852. if (err) {
  5853. dev_err(&pdev->dev,
  5854. "Cannot re-enable PCI device after reset.\n");
  5855. result = PCI_ERS_RESULT_DISCONNECT;
  5856. } else {
  5857. pdev->state_saved = true;
  5858. pci_restore_state(pdev);
  5859. pci_set_master(pdev);
  5860. pci_enable_wake(pdev, PCI_D3hot, 0);
  5861. pci_enable_wake(pdev, PCI_D3cold, 0);
  5862. e1000e_reset(adapter);
  5863. ew32(WUS, ~0);
  5864. result = PCI_ERS_RESULT_RECOVERED;
  5865. }
  5866. pci_cleanup_aer_uncorrect_error_status(pdev);
  5867. return result;
  5868. }
  5869. /**
  5870. * e1000_io_resume - called when traffic can start flowing again.
  5871. * @pdev: Pointer to PCI device
  5872. *
  5873. * This callback is called when the error recovery driver tells us that
  5874. * its OK to resume normal operation. Implementation resembles the
  5875. * second-half of the e1000e_pm_resume routine.
  5876. */
  5877. static void e1000_io_resume(struct pci_dev *pdev)
  5878. {
  5879. struct net_device *netdev = pci_get_drvdata(pdev);
  5880. struct e1000_adapter *adapter = netdev_priv(netdev);
  5881. e1000_init_manageability_pt(adapter);
  5882. if (netif_running(netdev))
  5883. e1000e_up(adapter);
  5884. netif_device_attach(netdev);
  5885. /* If the controller has AMT, do not set DRV_LOAD until the interface
  5886. * is up. For all other cases, let the f/w know that the h/w is now
  5887. * under the control of the driver.
  5888. */
  5889. if (!(adapter->flags & FLAG_HAS_AMT))
  5890. e1000e_get_hw_control(adapter);
  5891. }
  5892. static void e1000_print_device_info(struct e1000_adapter *adapter)
  5893. {
  5894. struct e1000_hw *hw = &adapter->hw;
  5895. struct net_device *netdev = adapter->netdev;
  5896. u32 ret_val;
  5897. u8 pba_str[E1000_PBANUM_LENGTH];
  5898. /* print bus type/speed/width info */
  5899. e_info("(PCI Express:2.5GT/s:%s) %pM\n",
  5900. /* bus width */
  5901. ((hw->bus.width == e1000_bus_width_pcie_x4) ? "Width x4" :
  5902. "Width x1"),
  5903. /* MAC address */
  5904. netdev->dev_addr);
  5905. e_info("Intel(R) PRO/%s Network Connection\n",
  5906. (hw->phy.type == e1000_phy_ife) ? "10/100" : "1000");
  5907. ret_val = e1000_read_pba_string_generic(hw, pba_str,
  5908. E1000_PBANUM_LENGTH);
  5909. if (ret_val)
  5910. strlcpy((char *)pba_str, "Unknown", sizeof(pba_str));
  5911. e_info("MAC: %d, PHY: %d, PBA No: %s\n",
  5912. hw->mac.type, hw->phy.type, pba_str);
  5913. }
  5914. static void e1000_eeprom_checks(struct e1000_adapter *adapter)
  5915. {
  5916. struct e1000_hw *hw = &adapter->hw;
  5917. int ret_val;
  5918. u16 buf = 0;
  5919. if (hw->mac.type != e1000_82573)
  5920. return;
  5921. ret_val = e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &buf);
  5922. le16_to_cpus(&buf);
  5923. if (!ret_val && (!(buf & BIT(0)))) {
  5924. /* Deep Smart Power Down (DSPD) */
  5925. dev_warn(&adapter->pdev->dev,
  5926. "Warning: detected DSPD enabled in EEPROM\n");
  5927. }
  5928. }
  5929. static netdev_features_t e1000_fix_features(struct net_device *netdev,
  5930. netdev_features_t features)
  5931. {
  5932. struct e1000_adapter *adapter = netdev_priv(netdev);
  5933. struct e1000_hw *hw = &adapter->hw;
  5934. /* Jumbo frame workaround on 82579 and newer requires CRC be stripped */
  5935. if ((hw->mac.type >= e1000_pch2lan) && (netdev->mtu > ETH_DATA_LEN))
  5936. features &= ~NETIF_F_RXFCS;
  5937. /* Since there is no support for separate Rx/Tx vlan accel
  5938. * enable/disable make sure Tx flag is always in same state as Rx.
  5939. */
  5940. if (features & NETIF_F_HW_VLAN_CTAG_RX)
  5941. features |= NETIF_F_HW_VLAN_CTAG_TX;
  5942. else
  5943. features &= ~NETIF_F_HW_VLAN_CTAG_TX;
  5944. return features;
  5945. }
  5946. static int e1000_set_features(struct net_device *netdev,
  5947. netdev_features_t features)
  5948. {
  5949. struct e1000_adapter *adapter = netdev_priv(netdev);
  5950. netdev_features_t changed = features ^ netdev->features;
  5951. if (changed & (NETIF_F_TSO | NETIF_F_TSO6))
  5952. adapter->flags |= FLAG_TSO_FORCE;
  5953. if (!(changed & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX |
  5954. NETIF_F_RXCSUM | NETIF_F_RXHASH | NETIF_F_RXFCS |
  5955. NETIF_F_RXALL)))
  5956. return 0;
  5957. if (changed & NETIF_F_RXFCS) {
  5958. if (features & NETIF_F_RXFCS) {
  5959. adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
  5960. } else {
  5961. /* We need to take it back to defaults, which might mean
  5962. * stripping is still disabled at the adapter level.
  5963. */
  5964. if (adapter->flags2 & FLAG2_DFLT_CRC_STRIPPING)
  5965. adapter->flags2 |= FLAG2_CRC_STRIPPING;
  5966. else
  5967. adapter->flags2 &= ~FLAG2_CRC_STRIPPING;
  5968. }
  5969. }
  5970. netdev->features = features;
  5971. if (netif_running(netdev))
  5972. e1000e_reinit_locked(adapter);
  5973. else
  5974. e1000e_reset(adapter);
  5975. return 0;
  5976. }
  5977. static const struct net_device_ops e1000e_netdev_ops = {
  5978. .ndo_open = e1000e_open,
  5979. .ndo_stop = e1000e_close,
  5980. .ndo_start_xmit = e1000_xmit_frame,
  5981. .ndo_get_stats64 = e1000e_get_stats64,
  5982. .ndo_set_rx_mode = e1000e_set_rx_mode,
  5983. .ndo_set_mac_address = e1000_set_mac,
  5984. .ndo_change_mtu = e1000_change_mtu,
  5985. .ndo_do_ioctl = e1000_ioctl,
  5986. .ndo_tx_timeout = e1000_tx_timeout,
  5987. .ndo_validate_addr = eth_validate_addr,
  5988. .ndo_vlan_rx_add_vid = e1000_vlan_rx_add_vid,
  5989. .ndo_vlan_rx_kill_vid = e1000_vlan_rx_kill_vid,
  5990. #ifdef CONFIG_NET_POLL_CONTROLLER
  5991. .ndo_poll_controller = e1000_netpoll,
  5992. #endif
  5993. .ndo_set_features = e1000_set_features,
  5994. .ndo_fix_features = e1000_fix_features,
  5995. .ndo_features_check = passthru_features_check,
  5996. };
  5997. /**
  5998. * e1000_probe - Device Initialization Routine
  5999. * @pdev: PCI device information struct
  6000. * @ent: entry in e1000_pci_tbl
  6001. *
  6002. * Returns 0 on success, negative on failure
  6003. *
  6004. * e1000_probe initializes an adapter identified by a pci_dev structure.
  6005. * The OS initialization, configuring of the adapter private structure,
  6006. * and a hardware reset occur.
  6007. **/
  6008. static int e1000_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  6009. {
  6010. struct net_device *netdev;
  6011. struct e1000_adapter *adapter;
  6012. struct e1000_hw *hw;
  6013. const struct e1000_info *ei = e1000_info_tbl[ent->driver_data];
  6014. resource_size_t mmio_start, mmio_len;
  6015. resource_size_t flash_start, flash_len;
  6016. static int cards_found;
  6017. u16 aspm_disable_flag = 0;
  6018. int bars, i, err, pci_using_dac;
  6019. u16 eeprom_data = 0;
  6020. u16 eeprom_apme_mask = E1000_EEPROM_APME;
  6021. s32 ret_val = 0;
  6022. if (ei->flags2 & FLAG2_DISABLE_ASPM_L0S)
  6023. aspm_disable_flag = PCIE_LINK_STATE_L0S;
  6024. if (ei->flags2 & FLAG2_DISABLE_ASPM_L1)
  6025. aspm_disable_flag |= PCIE_LINK_STATE_L1;
  6026. if (aspm_disable_flag)
  6027. e1000e_disable_aspm(pdev, aspm_disable_flag);
  6028. err = pci_enable_device_mem(pdev);
  6029. if (err)
  6030. return err;
  6031. pci_using_dac = 0;
  6032. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  6033. if (!err) {
  6034. pci_using_dac = 1;
  6035. } else {
  6036. err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
  6037. if (err) {
  6038. dev_err(&pdev->dev,
  6039. "No usable DMA configuration, aborting\n");
  6040. goto err_dma;
  6041. }
  6042. }
  6043. bars = pci_select_bars(pdev, IORESOURCE_MEM);
  6044. err = pci_request_selected_regions_exclusive(pdev, bars,
  6045. e1000e_driver_name);
  6046. if (err)
  6047. goto err_pci_reg;
  6048. /* AER (Advanced Error Reporting) hooks */
  6049. pci_enable_pcie_error_reporting(pdev);
  6050. pci_set_master(pdev);
  6051. /* PCI config space info */
  6052. err = pci_save_state(pdev);
  6053. if (err)
  6054. goto err_alloc_etherdev;
  6055. err = -ENOMEM;
  6056. netdev = alloc_etherdev(sizeof(struct e1000_adapter));
  6057. if (!netdev)
  6058. goto err_alloc_etherdev;
  6059. SET_NETDEV_DEV(netdev, &pdev->dev);
  6060. netdev->irq = pdev->irq;
  6061. pci_set_drvdata(pdev, netdev);
  6062. adapter = netdev_priv(netdev);
  6063. hw = &adapter->hw;
  6064. adapter->netdev = netdev;
  6065. adapter->pdev = pdev;
  6066. adapter->ei = ei;
  6067. adapter->pba = ei->pba;
  6068. adapter->flags = ei->flags;
  6069. adapter->flags2 = ei->flags2;
  6070. adapter->hw.adapter = adapter;
  6071. adapter->hw.mac.type = ei->mac;
  6072. adapter->max_hw_frame_size = ei->max_hw_frame_size;
  6073. adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
  6074. mmio_start = pci_resource_start(pdev, 0);
  6075. mmio_len = pci_resource_len(pdev, 0);
  6076. err = -EIO;
  6077. adapter->hw.hw_addr = ioremap(mmio_start, mmio_len);
  6078. if (!adapter->hw.hw_addr)
  6079. goto err_ioremap;
  6080. if ((adapter->flags & FLAG_HAS_FLASH) &&
  6081. (pci_resource_flags(pdev, 1) & IORESOURCE_MEM) &&
  6082. (hw->mac.type < e1000_pch_spt)) {
  6083. flash_start = pci_resource_start(pdev, 1);
  6084. flash_len = pci_resource_len(pdev, 1);
  6085. adapter->hw.flash_address = ioremap(flash_start, flash_len);
  6086. if (!adapter->hw.flash_address)
  6087. goto err_flashmap;
  6088. }
  6089. /* Set default EEE advertisement */
  6090. if (adapter->flags2 & FLAG2_HAS_EEE)
  6091. adapter->eee_advert = MDIO_EEE_100TX | MDIO_EEE_1000T;
  6092. /* construct the net_device struct */
  6093. netdev->netdev_ops = &e1000e_netdev_ops;
  6094. e1000e_set_ethtool_ops(netdev);
  6095. netdev->watchdog_timeo = 5 * HZ;
  6096. netif_napi_add(netdev, &adapter->napi, e1000e_poll, 64);
  6097. strlcpy(netdev->name, pci_name(pdev), sizeof(netdev->name));
  6098. netdev->mem_start = mmio_start;
  6099. netdev->mem_end = mmio_start + mmio_len;
  6100. adapter->bd_number = cards_found++;
  6101. e1000e_check_options(adapter);
  6102. /* setup adapter struct */
  6103. err = e1000_sw_init(adapter);
  6104. if (err)
  6105. goto err_sw_init;
  6106. memcpy(&hw->mac.ops, ei->mac_ops, sizeof(hw->mac.ops));
  6107. memcpy(&hw->nvm.ops, ei->nvm_ops, sizeof(hw->nvm.ops));
  6108. memcpy(&hw->phy.ops, ei->phy_ops, sizeof(hw->phy.ops));
  6109. err = ei->get_variants(adapter);
  6110. if (err)
  6111. goto err_hw_init;
  6112. if ((adapter->flags & FLAG_IS_ICH) &&
  6113. (adapter->flags & FLAG_READ_ONLY_NVM) &&
  6114. (hw->mac.type < e1000_pch_spt))
  6115. e1000e_write_protect_nvm_ich8lan(&adapter->hw);
  6116. hw->mac.ops.get_bus_info(&adapter->hw);
  6117. adapter->hw.phy.autoneg_wait_to_complete = 0;
  6118. /* Copper options */
  6119. if (adapter->hw.phy.media_type == e1000_media_type_copper) {
  6120. adapter->hw.phy.mdix = AUTO_ALL_MODES;
  6121. adapter->hw.phy.disable_polarity_correction = 0;
  6122. adapter->hw.phy.ms_type = e1000_ms_hw_default;
  6123. }
  6124. if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw))
  6125. dev_info(&pdev->dev,
  6126. "PHY reset is blocked due to SOL/IDER session.\n");
  6127. /* Set initial default active device features */
  6128. netdev->features = (NETIF_F_SG |
  6129. NETIF_F_HW_VLAN_CTAG_RX |
  6130. NETIF_F_HW_VLAN_CTAG_TX |
  6131. NETIF_F_TSO |
  6132. NETIF_F_TSO6 |
  6133. NETIF_F_RXHASH |
  6134. NETIF_F_RXCSUM |
  6135. NETIF_F_HW_CSUM);
  6136. /* Set user-changeable features (subset of all device features) */
  6137. netdev->hw_features = netdev->features;
  6138. netdev->hw_features |= NETIF_F_RXFCS;
  6139. netdev->priv_flags |= IFF_SUPP_NOFCS;
  6140. netdev->hw_features |= NETIF_F_RXALL;
  6141. if (adapter->flags & FLAG_HAS_HW_VLAN_FILTER)
  6142. netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
  6143. netdev->vlan_features |= (NETIF_F_SG |
  6144. NETIF_F_TSO |
  6145. NETIF_F_TSO6 |
  6146. NETIF_F_HW_CSUM);
  6147. netdev->priv_flags |= IFF_UNICAST_FLT;
  6148. if (pci_using_dac) {
  6149. netdev->features |= NETIF_F_HIGHDMA;
  6150. netdev->vlan_features |= NETIF_F_HIGHDMA;
  6151. }
  6152. /* MTU range: 68 - max_hw_frame_size */
  6153. netdev->min_mtu = ETH_MIN_MTU;
  6154. netdev->max_mtu = adapter->max_hw_frame_size -
  6155. (VLAN_ETH_HLEN + ETH_FCS_LEN);
  6156. if (e1000e_enable_mng_pass_thru(&adapter->hw))
  6157. adapter->flags |= FLAG_MNG_PT_ENABLED;
  6158. /* before reading the NVM, reset the controller to
  6159. * put the device in a known good starting state
  6160. */
  6161. adapter->hw.mac.ops.reset_hw(&adapter->hw);
  6162. /* systems with ASPM and others may see the checksum fail on the first
  6163. * attempt. Let's give it a few tries
  6164. */
  6165. for (i = 0;; i++) {
  6166. if (e1000_validate_nvm_checksum(&adapter->hw) >= 0)
  6167. break;
  6168. if (i == 2) {
  6169. dev_err(&pdev->dev, "The NVM Checksum Is Not Valid\n");
  6170. err = -EIO;
  6171. goto err_eeprom;
  6172. }
  6173. }
  6174. e1000_eeprom_checks(adapter);
  6175. /* copy the MAC address */
  6176. if (e1000e_read_mac_addr(&adapter->hw))
  6177. dev_err(&pdev->dev,
  6178. "NVM Read Error while reading MAC address\n");
  6179. memcpy(netdev->dev_addr, adapter->hw.mac.addr, netdev->addr_len);
  6180. if (!is_valid_ether_addr(netdev->dev_addr)) {
  6181. dev_err(&pdev->dev, "Invalid MAC Address: %pM\n",
  6182. netdev->dev_addr);
  6183. err = -EIO;
  6184. goto err_eeprom;
  6185. }
  6186. timer_setup(&adapter->watchdog_timer, e1000_watchdog, 0);
  6187. timer_setup(&adapter->phy_info_timer, e1000_update_phy_info, 0);
  6188. INIT_WORK(&adapter->reset_task, e1000_reset_task);
  6189. INIT_WORK(&adapter->watchdog_task, e1000_watchdog_task);
  6190. INIT_WORK(&adapter->downshift_task, e1000e_downshift_workaround);
  6191. INIT_WORK(&adapter->update_phy_task, e1000e_update_phy_task);
  6192. INIT_WORK(&adapter->print_hang_task, e1000_print_hw_hang);
  6193. /* Initialize link parameters. User can change them with ethtool */
  6194. adapter->hw.mac.autoneg = 1;
  6195. adapter->fc_autoneg = true;
  6196. adapter->hw.fc.requested_mode = e1000_fc_default;
  6197. adapter->hw.fc.current_mode = e1000_fc_default;
  6198. adapter->hw.phy.autoneg_advertised = 0x2f;
  6199. /* Initial Wake on LAN setting - If APM wake is enabled in
  6200. * the EEPROM, enable the ACPI Magic Packet filter
  6201. */
  6202. if (adapter->flags & FLAG_APME_IN_WUC) {
  6203. /* APME bit in EEPROM is mapped to WUC.APME */
  6204. eeprom_data = er32(WUC);
  6205. eeprom_apme_mask = E1000_WUC_APME;
  6206. if ((hw->mac.type > e1000_ich10lan) &&
  6207. (eeprom_data & E1000_WUC_PHY_WAKE))
  6208. adapter->flags2 |= FLAG2_HAS_PHY_WAKEUP;
  6209. } else if (adapter->flags & FLAG_APME_IN_CTRL3) {
  6210. if (adapter->flags & FLAG_APME_CHECK_PORT_B &&
  6211. (adapter->hw.bus.func == 1))
  6212. ret_val = e1000_read_nvm(&adapter->hw,
  6213. NVM_INIT_CONTROL3_PORT_B,
  6214. 1, &eeprom_data);
  6215. else
  6216. ret_val = e1000_read_nvm(&adapter->hw,
  6217. NVM_INIT_CONTROL3_PORT_A,
  6218. 1, &eeprom_data);
  6219. }
  6220. /* fetch WoL from EEPROM */
  6221. if (ret_val)
  6222. e_dbg("NVM read error getting WoL initial values: %d\n", ret_val);
  6223. else if (eeprom_data & eeprom_apme_mask)
  6224. adapter->eeprom_wol |= E1000_WUFC_MAG;
  6225. /* now that we have the eeprom settings, apply the special cases
  6226. * where the eeprom may be wrong or the board simply won't support
  6227. * wake on lan on a particular port
  6228. */
  6229. if (!(adapter->flags & FLAG_HAS_WOL))
  6230. adapter->eeprom_wol = 0;
  6231. /* initialize the wol settings based on the eeprom settings */
  6232. adapter->wol = adapter->eeprom_wol;
  6233. /* make sure adapter isn't asleep if manageability is enabled */
  6234. if (adapter->wol || (adapter->flags & FLAG_MNG_PT_ENABLED) ||
  6235. (hw->mac.ops.check_mng_mode(hw)))
  6236. device_wakeup_enable(&pdev->dev);
  6237. /* save off EEPROM version number */
  6238. ret_val = e1000_read_nvm(&adapter->hw, 5, 1, &adapter->eeprom_vers);
  6239. if (ret_val) {
  6240. e_dbg("NVM read error getting EEPROM version: %d\n", ret_val);
  6241. adapter->eeprom_vers = 0;
  6242. }
  6243. /* init PTP hardware clock */
  6244. e1000e_ptp_init(adapter);
  6245. /* reset the hardware with the new settings */
  6246. e1000e_reset(adapter);
  6247. /* If the controller has AMT, do not set DRV_LOAD until the interface
  6248. * is up. For all other cases, let the f/w know that the h/w is now
  6249. * under the control of the driver.
  6250. */
  6251. if (!(adapter->flags & FLAG_HAS_AMT))
  6252. e1000e_get_hw_control(adapter);
  6253. strlcpy(netdev->name, "eth%d", sizeof(netdev->name));
  6254. err = register_netdev(netdev);
  6255. if (err)
  6256. goto err_register;
  6257. /* carrier off reporting is important to ethtool even BEFORE open */
  6258. netif_carrier_off(netdev);
  6259. e1000_print_device_info(adapter);
  6260. if (pci_dev_run_wake(pdev))
  6261. pm_runtime_put_noidle(&pdev->dev);
  6262. return 0;
  6263. err_register:
  6264. if (!(adapter->flags & FLAG_HAS_AMT))
  6265. e1000e_release_hw_control(adapter);
  6266. err_eeprom:
  6267. if (hw->phy.ops.check_reset_block && !hw->phy.ops.check_reset_block(hw))
  6268. e1000_phy_hw_reset(&adapter->hw);
  6269. err_hw_init:
  6270. kfree(adapter->tx_ring);
  6271. kfree(adapter->rx_ring);
  6272. err_sw_init:
  6273. if ((adapter->hw.flash_address) && (hw->mac.type < e1000_pch_spt))
  6274. iounmap(adapter->hw.flash_address);
  6275. e1000e_reset_interrupt_capability(adapter);
  6276. err_flashmap:
  6277. iounmap(adapter->hw.hw_addr);
  6278. err_ioremap:
  6279. free_netdev(netdev);
  6280. err_alloc_etherdev:
  6281. pci_release_mem_regions(pdev);
  6282. err_pci_reg:
  6283. err_dma:
  6284. pci_disable_device(pdev);
  6285. return err;
  6286. }
  6287. /**
  6288. * e1000_remove - Device Removal Routine
  6289. * @pdev: PCI device information struct
  6290. *
  6291. * e1000_remove is called by the PCI subsystem to alert the driver
  6292. * that it should release a PCI device. The could be caused by a
  6293. * Hot-Plug event, or because the driver is going to be removed from
  6294. * memory.
  6295. **/
  6296. static void e1000_remove(struct pci_dev *pdev)
  6297. {
  6298. struct net_device *netdev = pci_get_drvdata(pdev);
  6299. struct e1000_adapter *adapter = netdev_priv(netdev);
  6300. bool down = test_bit(__E1000_DOWN, &adapter->state);
  6301. e1000e_ptp_remove(adapter);
  6302. /* The timers may be rescheduled, so explicitly disable them
  6303. * from being rescheduled.
  6304. */
  6305. if (!down)
  6306. set_bit(__E1000_DOWN, &adapter->state);
  6307. del_timer_sync(&adapter->watchdog_timer);
  6308. del_timer_sync(&adapter->phy_info_timer);
  6309. cancel_work_sync(&adapter->reset_task);
  6310. cancel_work_sync(&adapter->watchdog_task);
  6311. cancel_work_sync(&adapter->downshift_task);
  6312. cancel_work_sync(&adapter->update_phy_task);
  6313. cancel_work_sync(&adapter->print_hang_task);
  6314. if (adapter->flags & FLAG_HAS_HW_TIMESTAMP) {
  6315. cancel_work_sync(&adapter->tx_hwtstamp_work);
  6316. if (adapter->tx_hwtstamp_skb) {
  6317. dev_consume_skb_any(adapter->tx_hwtstamp_skb);
  6318. adapter->tx_hwtstamp_skb = NULL;
  6319. }
  6320. }
  6321. /* Don't lie to e1000_close() down the road. */
  6322. if (!down)
  6323. clear_bit(__E1000_DOWN, &adapter->state);
  6324. unregister_netdev(netdev);
  6325. if (pci_dev_run_wake(pdev))
  6326. pm_runtime_get_noresume(&pdev->dev);
  6327. /* Release control of h/w to f/w. If f/w is AMT enabled, this
  6328. * would have already happened in close and is redundant.
  6329. */
  6330. e1000e_release_hw_control(adapter);
  6331. e1000e_reset_interrupt_capability(adapter);
  6332. kfree(adapter->tx_ring);
  6333. kfree(adapter->rx_ring);
  6334. iounmap(adapter->hw.hw_addr);
  6335. if ((adapter->hw.flash_address) &&
  6336. (adapter->hw.mac.type < e1000_pch_spt))
  6337. iounmap(adapter->hw.flash_address);
  6338. pci_release_mem_regions(pdev);
  6339. free_netdev(netdev);
  6340. /* AER disable */
  6341. pci_disable_pcie_error_reporting(pdev);
  6342. pci_disable_device(pdev);
  6343. }
  6344. /* PCI Error Recovery (ERS) */
  6345. static const struct pci_error_handlers e1000_err_handler = {
  6346. .error_detected = e1000_io_error_detected,
  6347. .slot_reset = e1000_io_slot_reset,
  6348. .resume = e1000_io_resume,
  6349. };
  6350. static const struct pci_device_id e1000_pci_tbl[] = {
  6351. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_COPPER), board_82571 },
  6352. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_FIBER), board_82571 },
  6353. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER), board_82571 },
  6354. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_COPPER_LP),
  6355. board_82571 },
  6356. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_QUAD_FIBER), board_82571 },
  6357. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES), board_82571 },
  6358. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_DUAL), board_82571 },
  6359. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571EB_SERDES_QUAD), board_82571 },
  6360. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82571PT_QUAD_COPPER), board_82571 },
  6361. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI), board_82572 },
  6362. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_COPPER), board_82572 },
  6363. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_FIBER), board_82572 },
  6364. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82572EI_SERDES), board_82572 },
  6365. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E), board_82573 },
  6366. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573E_IAMT), board_82573 },
  6367. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82573L), board_82573 },
  6368. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574L), board_82574 },
  6369. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82574LA), board_82574 },
  6370. { PCI_VDEVICE(INTEL, E1000_DEV_ID_82583V), board_82583 },
  6371. { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_DPT),
  6372. board_80003es2lan },
  6373. { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_COPPER_SPT),
  6374. board_80003es2lan },
  6375. { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_DPT),
  6376. board_80003es2lan },
  6377. { PCI_VDEVICE(INTEL, E1000_DEV_ID_80003ES2LAN_SERDES_SPT),
  6378. board_80003es2lan },
  6379. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE), board_ich8lan },
  6380. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_G), board_ich8lan },
  6381. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IFE_GT), board_ich8lan },
  6382. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_AMT), board_ich8lan },
  6383. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_C), board_ich8lan },
  6384. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M), board_ich8lan },
  6385. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_IGP_M_AMT), board_ich8lan },
  6386. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH8_82567V_3), board_ich8lan },
  6387. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE), board_ich9lan },
  6388. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_G), board_ich9lan },
  6389. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IFE_GT), board_ich9lan },
  6390. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_AMT), board_ich9lan },
  6391. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_C), board_ich9lan },
  6392. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_BM), board_ich9lan },
  6393. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M), board_ich9lan },
  6394. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_AMT), board_ich9lan },
  6395. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH9_IGP_M_V), board_ich9lan },
  6396. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LM), board_ich9lan },
  6397. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_LF), board_ich9lan },
  6398. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_R_BM_V), board_ich9lan },
  6399. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LM), board_ich10lan },
  6400. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_LF), board_ich10lan },
  6401. { PCI_VDEVICE(INTEL, E1000_DEV_ID_ICH10_D_BM_V), board_ich10lan },
  6402. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LM), board_pchlan },
  6403. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_M_HV_LC), board_pchlan },
  6404. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DM), board_pchlan },
  6405. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_D_HV_DC), board_pchlan },
  6406. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_LM), board_pch2lan },
  6407. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH2_LV_V), board_pch2lan },
  6408. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_LM), board_pch_lpt },
  6409. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPT_I217_V), board_pch_lpt },
  6410. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_LM), board_pch_lpt },
  6411. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LPTLP_I218_V), board_pch_lpt },
  6412. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM2), board_pch_lpt },
  6413. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V2), board_pch_lpt },
  6414. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_LM3), board_pch_lpt },
  6415. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_I218_V3), board_pch_lpt },
  6416. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM), board_pch_spt },
  6417. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V), board_pch_spt },
  6418. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM2), board_pch_spt },
  6419. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V2), board_pch_spt },
  6420. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_LBG_I219_LM3), board_pch_spt },
  6421. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM4), board_pch_spt },
  6422. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V4), board_pch_spt },
  6423. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_LM5), board_pch_spt },
  6424. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_SPT_I219_V5), board_pch_spt },
  6425. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_LM6), board_pch_cnp },
  6426. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_V6), board_pch_cnp },
  6427. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_LM7), board_pch_cnp },
  6428. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_CNP_I219_V7), board_pch_cnp },
  6429. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_LM8), board_pch_cnp },
  6430. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_V8), board_pch_cnp },
  6431. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_LM9), board_pch_cnp },
  6432. { PCI_VDEVICE(INTEL, E1000_DEV_ID_PCH_ICP_I219_V9), board_pch_cnp },
  6433. { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
  6434. };
  6435. MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
  6436. static const struct dev_pm_ops e1000_pm_ops = {
  6437. #ifdef CONFIG_PM_SLEEP
  6438. .suspend = e1000e_pm_suspend,
  6439. .resume = e1000e_pm_resume,
  6440. .freeze = e1000e_pm_freeze,
  6441. .thaw = e1000e_pm_thaw,
  6442. .poweroff = e1000e_pm_suspend,
  6443. .restore = e1000e_pm_resume,
  6444. #endif
  6445. SET_RUNTIME_PM_OPS(e1000e_pm_runtime_suspend, e1000e_pm_runtime_resume,
  6446. e1000e_pm_runtime_idle)
  6447. };
  6448. /* PCI Device API Driver */
  6449. static struct pci_driver e1000_driver = {
  6450. .name = e1000e_driver_name,
  6451. .id_table = e1000_pci_tbl,
  6452. .probe = e1000_probe,
  6453. .remove = e1000_remove,
  6454. .driver = {
  6455. .pm = &e1000_pm_ops,
  6456. },
  6457. .shutdown = e1000_shutdown,
  6458. .err_handler = &e1000_err_handler
  6459. };
  6460. /**
  6461. * e1000_init_module - Driver Registration Routine
  6462. *
  6463. * e1000_init_module is the first routine called when the driver is
  6464. * loaded. All it does is register with the PCI subsystem.
  6465. **/
  6466. static int __init e1000_init_module(void)
  6467. {
  6468. pr_info("Intel(R) PRO/1000 Network Driver - %s\n",
  6469. e1000e_driver_version);
  6470. pr_info("Copyright(c) 1999 - 2015 Intel Corporation.\n");
  6471. return pci_register_driver(&e1000_driver);
  6472. }
  6473. module_init(e1000_init_module);
  6474. /**
  6475. * e1000_exit_module - Driver Exit Cleanup Routine
  6476. *
  6477. * e1000_exit_module is called just before the driver is removed
  6478. * from memory.
  6479. **/
  6480. static void __exit e1000_exit_module(void)
  6481. {
  6482. pci_unregister_driver(&e1000_driver);
  6483. }
  6484. module_exit(e1000_exit_module);
  6485. MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
  6486. MODULE_DESCRIPTION("Intel(R) PRO/1000 Network Driver");
  6487. MODULE_LICENSE("GPL");
  6488. MODULE_VERSION(DRV_VERSION);
  6489. /* netdev.c */