netdev.c 166 KB

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