netdev.c 213 KB

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