netdev.c 183 KB

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