netdev.c 182 KB

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