netdev.c 204 KB

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