e1000.c 159 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504
  1. /**************************************************************************
  2. Intel Pro 1000 for ppcboot/das-u-boot
  3. Drivers are port from Intel's Linux driver e1000-4.3.15
  4. and from Etherboot pro 1000 driver by mrakes at vivato dot net
  5. tested on both gig copper and gig fiber boards
  6. ***************************************************************************/
  7. /*******************************************************************************
  8. Copyright(c) 1999 - 2002 Intel Corporation. All rights reserved.
  9. * SPDX-License-Identifier: GPL-2.0+
  10. Contact Information:
  11. Linux NICS <linux.nics@intel.com>
  12. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  13. *******************************************************************************/
  14. /*
  15. * Copyright (C) Archway Digital Solutions.
  16. *
  17. * written by Chrsitopher Li <cli at arcyway dot com> or <chrisl at gnuchina dot org>
  18. * 2/9/2002
  19. *
  20. * Copyright (C) Linux Networx.
  21. * Massive upgrade to work with the new intel gigabit NICs.
  22. * <ebiederman at lnxi dot com>
  23. *
  24. * Copyright 2011 Freescale Semiconductor, Inc.
  25. */
  26. #include "e1000.h"
  27. #define TOUT_LOOP 100000
  28. #define virt_to_bus(devno, v) pci_virt_to_mem(devno, (void *) (v))
  29. #define bus_to_phys(devno, a) pci_mem_to_phys(devno, a)
  30. #define E1000_DEFAULT_PCI_PBA 0x00000030
  31. #define E1000_DEFAULT_PCIE_PBA 0x000a0026
  32. /* NIC specific static variables go here */
  33. /* Intel i210 needs the DMA descriptor rings aligned to 128b */
  34. #define E1000_BUFFER_ALIGN 128
  35. DEFINE_ALIGN_BUFFER(struct e1000_tx_desc, tx_base, 16, E1000_BUFFER_ALIGN);
  36. DEFINE_ALIGN_BUFFER(struct e1000_rx_desc, rx_base, 16, E1000_BUFFER_ALIGN);
  37. DEFINE_ALIGN_BUFFER(unsigned char, packet, 4096, E1000_BUFFER_ALIGN);
  38. static int tx_tail;
  39. static int rx_tail, rx_last;
  40. static struct pci_device_id e1000_supported[] = {
  41. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82542},
  42. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_FIBER},
  43. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_COPPER},
  44. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_COPPER},
  45. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_FIBER},
  46. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_COPPER},
  47. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_LOM},
  48. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM},
  49. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_COPPER},
  50. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545GM_COPPER},
  51. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_COPPER},
  52. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_FIBER},
  53. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_FIBER},
  54. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546GB_COPPER},
  55. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM_LOM},
  56. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541ER},
  57. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541GI_LF},
  58. /* E1000 PCIe card */
  59. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_COPPER},
  60. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_FIBER },
  61. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES },
  62. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER},
  63. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571PT_QUAD_COPPER},
  64. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_FIBER},
  65. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER_LOWPROFILE},
  66. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES_DUAL},
  67. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES_QUAD},
  68. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_COPPER},
  69. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_FIBER},
  70. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_SERDES},
  71. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI},
  72. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573E},
  73. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573E_IAMT},
  74. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573L},
  75. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82574L},
  76. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546GB_QUAD_COPPER_KSP3},
  77. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_DPT},
  78. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_DPT},
  79. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_SPT},
  80. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_SPT},
  81. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_UNPROGRAMMED},
  82. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I211_UNPROGRAMMED},
  83. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_COPPER},
  84. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I211_COPPER},
  85. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_COPPER_FLASHLESS},
  86. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_SERDES},
  87. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_SERDES_FLASHLESS},
  88. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_1000BASEKX},
  89. {}
  90. };
  91. /* Function forward declarations */
  92. static int e1000_setup_link(struct eth_device *nic);
  93. static int e1000_setup_fiber_link(struct eth_device *nic);
  94. static int e1000_setup_copper_link(struct eth_device *nic);
  95. static int e1000_phy_setup_autoneg(struct e1000_hw *hw);
  96. static void e1000_config_collision_dist(struct e1000_hw *hw);
  97. static int e1000_config_mac_to_phy(struct e1000_hw *hw);
  98. static int e1000_config_fc_after_link_up(struct e1000_hw *hw);
  99. static int e1000_check_for_link(struct eth_device *nic);
  100. static int e1000_wait_autoneg(struct e1000_hw *hw);
  101. static int e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t * speed,
  102. uint16_t * duplex);
  103. static int e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
  104. uint16_t * phy_data);
  105. static int e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
  106. uint16_t phy_data);
  107. static int32_t e1000_phy_hw_reset(struct e1000_hw *hw);
  108. static int e1000_phy_reset(struct e1000_hw *hw);
  109. static int e1000_detect_gig_phy(struct e1000_hw *hw);
  110. static void e1000_set_media_type(struct e1000_hw *hw);
  111. static int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask);
  112. static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask);
  113. static int32_t e1000_check_phy_reset_block(struct e1000_hw *hw);
  114. #ifndef CONFIG_E1000_NO_NVM
  115. static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
  116. static int32_t e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset,
  117. uint16_t words,
  118. uint16_t *data);
  119. /******************************************************************************
  120. * Raises the EEPROM's clock input.
  121. *
  122. * hw - Struct containing variables accessed by shared code
  123. * eecd - EECD's current value
  124. *****************************************************************************/
  125. void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t * eecd)
  126. {
  127. /* Raise the clock input to the EEPROM (by setting the SK bit), and then
  128. * wait 50 microseconds.
  129. */
  130. *eecd = *eecd | E1000_EECD_SK;
  131. E1000_WRITE_REG(hw, EECD, *eecd);
  132. E1000_WRITE_FLUSH(hw);
  133. udelay(50);
  134. }
  135. /******************************************************************************
  136. * Lowers the EEPROM's clock input.
  137. *
  138. * hw - Struct containing variables accessed by shared code
  139. * eecd - EECD's current value
  140. *****************************************************************************/
  141. void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t * eecd)
  142. {
  143. /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
  144. * wait 50 microseconds.
  145. */
  146. *eecd = *eecd & ~E1000_EECD_SK;
  147. E1000_WRITE_REG(hw, EECD, *eecd);
  148. E1000_WRITE_FLUSH(hw);
  149. udelay(50);
  150. }
  151. /******************************************************************************
  152. * Shift data bits out to the EEPROM.
  153. *
  154. * hw - Struct containing variables accessed by shared code
  155. * data - data to send to the EEPROM
  156. * count - number of bits to shift out
  157. *****************************************************************************/
  158. static void
  159. e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data, uint16_t count)
  160. {
  161. uint32_t eecd;
  162. uint32_t mask;
  163. /* We need to shift "count" bits out to the EEPROM. So, value in the
  164. * "data" parameter will be shifted out to the EEPROM one bit at a time.
  165. * In order to do this, "data" must be broken down into bits.
  166. */
  167. mask = 0x01 << (count - 1);
  168. eecd = E1000_READ_REG(hw, EECD);
  169. eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
  170. do {
  171. /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
  172. * and then raising and then lowering the clock (the SK bit controls
  173. * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
  174. * by setting "DI" to "0" and then raising and then lowering the clock.
  175. */
  176. eecd &= ~E1000_EECD_DI;
  177. if (data & mask)
  178. eecd |= E1000_EECD_DI;
  179. E1000_WRITE_REG(hw, EECD, eecd);
  180. E1000_WRITE_FLUSH(hw);
  181. udelay(50);
  182. e1000_raise_ee_clk(hw, &eecd);
  183. e1000_lower_ee_clk(hw, &eecd);
  184. mask = mask >> 1;
  185. } while (mask);
  186. /* We leave the "DI" bit set to "0" when we leave this routine. */
  187. eecd &= ~E1000_EECD_DI;
  188. E1000_WRITE_REG(hw, EECD, eecd);
  189. }
  190. /******************************************************************************
  191. * Shift data bits in from the EEPROM
  192. *
  193. * hw - Struct containing variables accessed by shared code
  194. *****************************************************************************/
  195. static uint16_t
  196. e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count)
  197. {
  198. uint32_t eecd;
  199. uint32_t i;
  200. uint16_t data;
  201. /* In order to read a register from the EEPROM, we need to shift 'count'
  202. * bits in from the EEPROM. Bits are "shifted in" by raising the clock
  203. * input to the EEPROM (setting the SK bit), and then reading the
  204. * value of the "DO" bit. During this "shifting in" process the
  205. * "DI" bit should always be clear.
  206. */
  207. eecd = E1000_READ_REG(hw, EECD);
  208. eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
  209. data = 0;
  210. for (i = 0; i < count; i++) {
  211. data = data << 1;
  212. e1000_raise_ee_clk(hw, &eecd);
  213. eecd = E1000_READ_REG(hw, EECD);
  214. eecd &= ~(E1000_EECD_DI);
  215. if (eecd & E1000_EECD_DO)
  216. data |= 1;
  217. e1000_lower_ee_clk(hw, &eecd);
  218. }
  219. return data;
  220. }
  221. /******************************************************************************
  222. * Returns EEPROM to a "standby" state
  223. *
  224. * hw - Struct containing variables accessed by shared code
  225. *****************************************************************************/
  226. void e1000_standby_eeprom(struct e1000_hw *hw)
  227. {
  228. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  229. uint32_t eecd;
  230. eecd = E1000_READ_REG(hw, EECD);
  231. if (eeprom->type == e1000_eeprom_microwire) {
  232. eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
  233. E1000_WRITE_REG(hw, EECD, eecd);
  234. E1000_WRITE_FLUSH(hw);
  235. udelay(eeprom->delay_usec);
  236. /* Clock high */
  237. eecd |= E1000_EECD_SK;
  238. E1000_WRITE_REG(hw, EECD, eecd);
  239. E1000_WRITE_FLUSH(hw);
  240. udelay(eeprom->delay_usec);
  241. /* Select EEPROM */
  242. eecd |= E1000_EECD_CS;
  243. E1000_WRITE_REG(hw, EECD, eecd);
  244. E1000_WRITE_FLUSH(hw);
  245. udelay(eeprom->delay_usec);
  246. /* Clock low */
  247. eecd &= ~E1000_EECD_SK;
  248. E1000_WRITE_REG(hw, EECD, eecd);
  249. E1000_WRITE_FLUSH(hw);
  250. udelay(eeprom->delay_usec);
  251. } else if (eeprom->type == e1000_eeprom_spi) {
  252. /* Toggle CS to flush commands */
  253. eecd |= E1000_EECD_CS;
  254. E1000_WRITE_REG(hw, EECD, eecd);
  255. E1000_WRITE_FLUSH(hw);
  256. udelay(eeprom->delay_usec);
  257. eecd &= ~E1000_EECD_CS;
  258. E1000_WRITE_REG(hw, EECD, eecd);
  259. E1000_WRITE_FLUSH(hw);
  260. udelay(eeprom->delay_usec);
  261. }
  262. }
  263. /***************************************************************************
  264. * Description: Determines if the onboard NVM is FLASH or EEPROM.
  265. *
  266. * hw - Struct containing variables accessed by shared code
  267. ****************************************************************************/
  268. static bool e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
  269. {
  270. uint32_t eecd = 0;
  271. DEBUGFUNC();
  272. if (hw->mac_type == e1000_ich8lan)
  273. return false;
  274. if (hw->mac_type == e1000_82573 || hw->mac_type == e1000_82574) {
  275. eecd = E1000_READ_REG(hw, EECD);
  276. /* Isolate bits 15 & 16 */
  277. eecd = ((eecd >> 15) & 0x03);
  278. /* If both bits are set, device is Flash type */
  279. if (eecd == 0x03)
  280. return false;
  281. }
  282. return true;
  283. }
  284. /******************************************************************************
  285. * Prepares EEPROM for access
  286. *
  287. * hw - Struct containing variables accessed by shared code
  288. *
  289. * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
  290. * function should be called before issuing a command to the EEPROM.
  291. *****************************************************************************/
  292. int32_t e1000_acquire_eeprom(struct e1000_hw *hw)
  293. {
  294. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  295. uint32_t eecd, i = 0;
  296. DEBUGFUNC();
  297. if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
  298. return -E1000_ERR_SWFW_SYNC;
  299. eecd = E1000_READ_REG(hw, EECD);
  300. if (hw->mac_type != e1000_82573 && hw->mac_type != e1000_82574) {
  301. /* Request EEPROM Access */
  302. if (hw->mac_type > e1000_82544) {
  303. eecd |= E1000_EECD_REQ;
  304. E1000_WRITE_REG(hw, EECD, eecd);
  305. eecd = E1000_READ_REG(hw, EECD);
  306. while ((!(eecd & E1000_EECD_GNT)) &&
  307. (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
  308. i++;
  309. udelay(5);
  310. eecd = E1000_READ_REG(hw, EECD);
  311. }
  312. if (!(eecd & E1000_EECD_GNT)) {
  313. eecd &= ~E1000_EECD_REQ;
  314. E1000_WRITE_REG(hw, EECD, eecd);
  315. DEBUGOUT("Could not acquire EEPROM grant\n");
  316. return -E1000_ERR_EEPROM;
  317. }
  318. }
  319. }
  320. /* Setup EEPROM for Read/Write */
  321. if (eeprom->type == e1000_eeprom_microwire) {
  322. /* Clear SK and DI */
  323. eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
  324. E1000_WRITE_REG(hw, EECD, eecd);
  325. /* Set CS */
  326. eecd |= E1000_EECD_CS;
  327. E1000_WRITE_REG(hw, EECD, eecd);
  328. } else if (eeprom->type == e1000_eeprom_spi) {
  329. /* Clear SK and CS */
  330. eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
  331. E1000_WRITE_REG(hw, EECD, eecd);
  332. udelay(1);
  333. }
  334. return E1000_SUCCESS;
  335. }
  336. /******************************************************************************
  337. * Sets up eeprom variables in the hw struct. Must be called after mac_type
  338. * is configured. Additionally, if this is ICH8, the flash controller GbE
  339. * registers must be mapped, or this will crash.
  340. *
  341. * hw - Struct containing variables accessed by shared code
  342. *****************************************************************************/
  343. static int32_t e1000_init_eeprom_params(struct e1000_hw *hw)
  344. {
  345. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  346. uint32_t eecd;
  347. int32_t ret_val = E1000_SUCCESS;
  348. uint16_t eeprom_size;
  349. if (hw->mac_type == e1000_igb)
  350. eecd = E1000_READ_REG(hw, I210_EECD);
  351. else
  352. eecd = E1000_READ_REG(hw, EECD);
  353. DEBUGFUNC();
  354. switch (hw->mac_type) {
  355. case e1000_82542_rev2_0:
  356. case e1000_82542_rev2_1:
  357. case e1000_82543:
  358. case e1000_82544:
  359. eeprom->type = e1000_eeprom_microwire;
  360. eeprom->word_size = 64;
  361. eeprom->opcode_bits = 3;
  362. eeprom->address_bits = 6;
  363. eeprom->delay_usec = 50;
  364. eeprom->use_eerd = false;
  365. eeprom->use_eewr = false;
  366. break;
  367. case e1000_82540:
  368. case e1000_82545:
  369. case e1000_82545_rev_3:
  370. case e1000_82546:
  371. case e1000_82546_rev_3:
  372. eeprom->type = e1000_eeprom_microwire;
  373. eeprom->opcode_bits = 3;
  374. eeprom->delay_usec = 50;
  375. if (eecd & E1000_EECD_SIZE) {
  376. eeprom->word_size = 256;
  377. eeprom->address_bits = 8;
  378. } else {
  379. eeprom->word_size = 64;
  380. eeprom->address_bits = 6;
  381. }
  382. eeprom->use_eerd = false;
  383. eeprom->use_eewr = false;
  384. break;
  385. case e1000_82541:
  386. case e1000_82541_rev_2:
  387. case e1000_82547:
  388. case e1000_82547_rev_2:
  389. if (eecd & E1000_EECD_TYPE) {
  390. eeprom->type = e1000_eeprom_spi;
  391. eeprom->opcode_bits = 8;
  392. eeprom->delay_usec = 1;
  393. if (eecd & E1000_EECD_ADDR_BITS) {
  394. eeprom->page_size = 32;
  395. eeprom->address_bits = 16;
  396. } else {
  397. eeprom->page_size = 8;
  398. eeprom->address_bits = 8;
  399. }
  400. } else {
  401. eeprom->type = e1000_eeprom_microwire;
  402. eeprom->opcode_bits = 3;
  403. eeprom->delay_usec = 50;
  404. if (eecd & E1000_EECD_ADDR_BITS) {
  405. eeprom->word_size = 256;
  406. eeprom->address_bits = 8;
  407. } else {
  408. eeprom->word_size = 64;
  409. eeprom->address_bits = 6;
  410. }
  411. }
  412. eeprom->use_eerd = false;
  413. eeprom->use_eewr = false;
  414. break;
  415. case e1000_82571:
  416. case e1000_82572:
  417. eeprom->type = e1000_eeprom_spi;
  418. eeprom->opcode_bits = 8;
  419. eeprom->delay_usec = 1;
  420. if (eecd & E1000_EECD_ADDR_BITS) {
  421. eeprom->page_size = 32;
  422. eeprom->address_bits = 16;
  423. } else {
  424. eeprom->page_size = 8;
  425. eeprom->address_bits = 8;
  426. }
  427. eeprom->use_eerd = false;
  428. eeprom->use_eewr = false;
  429. break;
  430. case e1000_82573:
  431. case e1000_82574:
  432. eeprom->type = e1000_eeprom_spi;
  433. eeprom->opcode_bits = 8;
  434. eeprom->delay_usec = 1;
  435. if (eecd & E1000_EECD_ADDR_BITS) {
  436. eeprom->page_size = 32;
  437. eeprom->address_bits = 16;
  438. } else {
  439. eeprom->page_size = 8;
  440. eeprom->address_bits = 8;
  441. }
  442. if (e1000_is_onboard_nvm_eeprom(hw) == false) {
  443. eeprom->use_eerd = true;
  444. eeprom->use_eewr = true;
  445. eeprom->type = e1000_eeprom_flash;
  446. eeprom->word_size = 2048;
  447. /* Ensure that the Autonomous FLASH update bit is cleared due to
  448. * Flash update issue on parts which use a FLASH for NVM. */
  449. eecd &= ~E1000_EECD_AUPDEN;
  450. E1000_WRITE_REG(hw, EECD, eecd);
  451. }
  452. break;
  453. case e1000_80003es2lan:
  454. eeprom->type = e1000_eeprom_spi;
  455. eeprom->opcode_bits = 8;
  456. eeprom->delay_usec = 1;
  457. if (eecd & E1000_EECD_ADDR_BITS) {
  458. eeprom->page_size = 32;
  459. eeprom->address_bits = 16;
  460. } else {
  461. eeprom->page_size = 8;
  462. eeprom->address_bits = 8;
  463. }
  464. eeprom->use_eerd = true;
  465. eeprom->use_eewr = false;
  466. break;
  467. case e1000_igb:
  468. /* i210 has 4k of iNVM mapped as EEPROM */
  469. eeprom->type = e1000_eeprom_invm;
  470. eeprom->opcode_bits = 8;
  471. eeprom->delay_usec = 1;
  472. eeprom->page_size = 32;
  473. eeprom->address_bits = 16;
  474. eeprom->use_eerd = true;
  475. eeprom->use_eewr = false;
  476. break;
  477. /* ich8lan does not support currently. if needed, please
  478. * add corresponding code and functions.
  479. */
  480. #if 0
  481. case e1000_ich8lan:
  482. {
  483. int32_t i = 0;
  484. eeprom->type = e1000_eeprom_ich8;
  485. eeprom->use_eerd = false;
  486. eeprom->use_eewr = false;
  487. eeprom->word_size = E1000_SHADOW_RAM_WORDS;
  488. uint32_t flash_size = E1000_READ_ICH_FLASH_REG(hw,
  489. ICH_FLASH_GFPREG);
  490. /* Zero the shadow RAM structure. But don't load it from NVM
  491. * so as to save time for driver init */
  492. if (hw->eeprom_shadow_ram != NULL) {
  493. for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
  494. hw->eeprom_shadow_ram[i].modified = false;
  495. hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
  496. }
  497. }
  498. hw->flash_base_addr = (flash_size & ICH_GFPREG_BASE_MASK) *
  499. ICH_FLASH_SECTOR_SIZE;
  500. hw->flash_bank_size = ((flash_size >> 16)
  501. & ICH_GFPREG_BASE_MASK) + 1;
  502. hw->flash_bank_size -= (flash_size & ICH_GFPREG_BASE_MASK);
  503. hw->flash_bank_size *= ICH_FLASH_SECTOR_SIZE;
  504. hw->flash_bank_size /= 2 * sizeof(uint16_t);
  505. break;
  506. }
  507. #endif
  508. default:
  509. break;
  510. }
  511. if (eeprom->type == e1000_eeprom_spi ||
  512. eeprom->type == e1000_eeprom_invm) {
  513. /* eeprom_size will be an enum [0..8] that maps
  514. * to eeprom sizes 128B to
  515. * 32KB (incremented by powers of 2).
  516. */
  517. if (hw->mac_type <= e1000_82547_rev_2) {
  518. /* Set to default value for initial eeprom read. */
  519. eeprom->word_size = 64;
  520. ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1,
  521. &eeprom_size);
  522. if (ret_val)
  523. return ret_val;
  524. eeprom_size = (eeprom_size & EEPROM_SIZE_MASK)
  525. >> EEPROM_SIZE_SHIFT;
  526. /* 256B eeprom size was not supported in earlier
  527. * hardware, so we bump eeprom_size up one to
  528. * ensure that "1" (which maps to 256B) is never
  529. * the result used in the shifting logic below. */
  530. if (eeprom_size)
  531. eeprom_size++;
  532. } else {
  533. eeprom_size = (uint16_t)((eecd &
  534. E1000_EECD_SIZE_EX_MASK) >>
  535. E1000_EECD_SIZE_EX_SHIFT);
  536. }
  537. eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
  538. }
  539. return ret_val;
  540. }
  541. /******************************************************************************
  542. * Polls the status bit (bit 1) of the EERD to determine when the read is done.
  543. *
  544. * hw - Struct containing variables accessed by shared code
  545. *****************************************************************************/
  546. static int32_t
  547. e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
  548. {
  549. uint32_t attempts = 100000;
  550. uint32_t i, reg = 0;
  551. int32_t done = E1000_ERR_EEPROM;
  552. for (i = 0; i < attempts; i++) {
  553. if (eerd == E1000_EEPROM_POLL_READ) {
  554. if (hw->mac_type == e1000_igb)
  555. reg = E1000_READ_REG(hw, I210_EERD);
  556. else
  557. reg = E1000_READ_REG(hw, EERD);
  558. } else {
  559. if (hw->mac_type == e1000_igb)
  560. reg = E1000_READ_REG(hw, I210_EEWR);
  561. else
  562. reg = E1000_READ_REG(hw, EEWR);
  563. }
  564. if (reg & E1000_EEPROM_RW_REG_DONE) {
  565. done = E1000_SUCCESS;
  566. break;
  567. }
  568. udelay(5);
  569. }
  570. return done;
  571. }
  572. /******************************************************************************
  573. * Reads a 16 bit word from the EEPROM using the EERD register.
  574. *
  575. * hw - Struct containing variables accessed by shared code
  576. * offset - offset of word in the EEPROM to read
  577. * data - word read from the EEPROM
  578. * words - number of words to read
  579. *****************************************************************************/
  580. static int32_t
  581. e1000_read_eeprom_eerd(struct e1000_hw *hw,
  582. uint16_t offset,
  583. uint16_t words,
  584. uint16_t *data)
  585. {
  586. uint32_t i, eerd = 0;
  587. int32_t error = 0;
  588. for (i = 0; i < words; i++) {
  589. eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
  590. E1000_EEPROM_RW_REG_START;
  591. if (hw->mac_type == e1000_igb)
  592. E1000_WRITE_REG(hw, I210_EERD, eerd);
  593. else
  594. E1000_WRITE_REG(hw, EERD, eerd);
  595. error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
  596. if (error)
  597. break;
  598. if (hw->mac_type == e1000_igb) {
  599. data[i] = (E1000_READ_REG(hw, I210_EERD) >>
  600. E1000_EEPROM_RW_REG_DATA);
  601. } else {
  602. data[i] = (E1000_READ_REG(hw, EERD) >>
  603. E1000_EEPROM_RW_REG_DATA);
  604. }
  605. }
  606. return error;
  607. }
  608. void e1000_release_eeprom(struct e1000_hw *hw)
  609. {
  610. uint32_t eecd;
  611. DEBUGFUNC();
  612. eecd = E1000_READ_REG(hw, EECD);
  613. if (hw->eeprom.type == e1000_eeprom_spi) {
  614. eecd |= E1000_EECD_CS; /* Pull CS high */
  615. eecd &= ~E1000_EECD_SK; /* Lower SCK */
  616. E1000_WRITE_REG(hw, EECD, eecd);
  617. udelay(hw->eeprom.delay_usec);
  618. } else if (hw->eeprom.type == e1000_eeprom_microwire) {
  619. /* cleanup eeprom */
  620. /* CS on Microwire is active-high */
  621. eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
  622. E1000_WRITE_REG(hw, EECD, eecd);
  623. /* Rising edge of clock */
  624. eecd |= E1000_EECD_SK;
  625. E1000_WRITE_REG(hw, EECD, eecd);
  626. E1000_WRITE_FLUSH(hw);
  627. udelay(hw->eeprom.delay_usec);
  628. /* Falling edge of clock */
  629. eecd &= ~E1000_EECD_SK;
  630. E1000_WRITE_REG(hw, EECD, eecd);
  631. E1000_WRITE_FLUSH(hw);
  632. udelay(hw->eeprom.delay_usec);
  633. }
  634. /* Stop requesting EEPROM access */
  635. if (hw->mac_type > e1000_82544) {
  636. eecd &= ~E1000_EECD_REQ;
  637. E1000_WRITE_REG(hw, EECD, eecd);
  638. }
  639. e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
  640. }
  641. /******************************************************************************
  642. * Reads a 16 bit word from the EEPROM.
  643. *
  644. * hw - Struct containing variables accessed by shared code
  645. *****************************************************************************/
  646. static int32_t
  647. e1000_spi_eeprom_ready(struct e1000_hw *hw)
  648. {
  649. uint16_t retry_count = 0;
  650. uint8_t spi_stat_reg;
  651. DEBUGFUNC();
  652. /* Read "Status Register" repeatedly until the LSB is cleared. The
  653. * EEPROM will signal that the command has been completed by clearing
  654. * bit 0 of the internal status register. If it's not cleared within
  655. * 5 milliseconds, then error out.
  656. */
  657. retry_count = 0;
  658. do {
  659. e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
  660. hw->eeprom.opcode_bits);
  661. spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
  662. if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
  663. break;
  664. udelay(5);
  665. retry_count += 5;
  666. e1000_standby_eeprom(hw);
  667. } while (retry_count < EEPROM_MAX_RETRY_SPI);
  668. /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
  669. * only 0-5mSec on 5V devices)
  670. */
  671. if (retry_count >= EEPROM_MAX_RETRY_SPI) {
  672. DEBUGOUT("SPI EEPROM Status error\n");
  673. return -E1000_ERR_EEPROM;
  674. }
  675. return E1000_SUCCESS;
  676. }
  677. /******************************************************************************
  678. * Reads a 16 bit word from the EEPROM.
  679. *
  680. * hw - Struct containing variables accessed by shared code
  681. * offset - offset of word in the EEPROM to read
  682. * data - word read from the EEPROM
  683. *****************************************************************************/
  684. static int32_t
  685. e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset,
  686. uint16_t words, uint16_t *data)
  687. {
  688. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  689. uint32_t i = 0;
  690. DEBUGFUNC();
  691. /* If eeprom is not yet detected, do so now */
  692. if (eeprom->word_size == 0)
  693. e1000_init_eeprom_params(hw);
  694. /* A check for invalid values: offset too large, too many words,
  695. * and not enough words.
  696. */
  697. if ((offset >= eeprom->word_size) ||
  698. (words > eeprom->word_size - offset) ||
  699. (words == 0)) {
  700. DEBUGOUT("\"words\" parameter out of bounds."
  701. "Words = %d, size = %d\n", offset, eeprom->word_size);
  702. return -E1000_ERR_EEPROM;
  703. }
  704. /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
  705. * directly. In this case, we need to acquire the EEPROM so that
  706. * FW or other port software does not interrupt.
  707. */
  708. if (e1000_is_onboard_nvm_eeprom(hw) == true &&
  709. hw->eeprom.use_eerd == false) {
  710. /* Prepare the EEPROM for bit-bang reading */
  711. if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
  712. return -E1000_ERR_EEPROM;
  713. }
  714. /* Eerd register EEPROM access requires no eeprom aquire/release */
  715. if (eeprom->use_eerd == true)
  716. return e1000_read_eeprom_eerd(hw, offset, words, data);
  717. /* ich8lan does not support currently. if needed, please
  718. * add corresponding code and functions.
  719. */
  720. #if 0
  721. /* ICH EEPROM access is done via the ICH flash controller */
  722. if (eeprom->type == e1000_eeprom_ich8)
  723. return e1000_read_eeprom_ich8(hw, offset, words, data);
  724. #endif
  725. /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
  726. * acquired the EEPROM at this point, so any returns should relase it */
  727. if (eeprom->type == e1000_eeprom_spi) {
  728. uint16_t word_in;
  729. uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
  730. if (e1000_spi_eeprom_ready(hw)) {
  731. e1000_release_eeprom(hw);
  732. return -E1000_ERR_EEPROM;
  733. }
  734. e1000_standby_eeprom(hw);
  735. /* Some SPI eeproms use the 8th address bit embedded in
  736. * the opcode */
  737. if ((eeprom->address_bits == 8) && (offset >= 128))
  738. read_opcode |= EEPROM_A8_OPCODE_SPI;
  739. /* Send the READ command (opcode + addr) */
  740. e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
  741. e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2),
  742. eeprom->address_bits);
  743. /* Read the data. The address of the eeprom internally
  744. * increments with each byte (spi) being read, saving on the
  745. * overhead of eeprom setup and tear-down. The address
  746. * counter will roll over if reading beyond the size of
  747. * the eeprom, thus allowing the entire memory to be read
  748. * starting from any offset. */
  749. for (i = 0; i < words; i++) {
  750. word_in = e1000_shift_in_ee_bits(hw, 16);
  751. data[i] = (word_in >> 8) | (word_in << 8);
  752. }
  753. } else if (eeprom->type == e1000_eeprom_microwire) {
  754. for (i = 0; i < words; i++) {
  755. /* Send the READ command (opcode + addr) */
  756. e1000_shift_out_ee_bits(hw,
  757. EEPROM_READ_OPCODE_MICROWIRE,
  758. eeprom->opcode_bits);
  759. e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
  760. eeprom->address_bits);
  761. /* Read the data. For microwire, each word requires
  762. * the overhead of eeprom setup and tear-down. */
  763. data[i] = e1000_shift_in_ee_bits(hw, 16);
  764. e1000_standby_eeprom(hw);
  765. }
  766. }
  767. /* End this read operation */
  768. e1000_release_eeprom(hw);
  769. return E1000_SUCCESS;
  770. }
  771. /******************************************************************************
  772. * Verifies that the EEPROM has a valid checksum
  773. *
  774. * hw - Struct containing variables accessed by shared code
  775. *
  776. * Reads the first 64 16 bit words of the EEPROM and sums the values read.
  777. * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
  778. * valid.
  779. *****************************************************************************/
  780. static int e1000_validate_eeprom_checksum(struct e1000_hw *hw)
  781. {
  782. uint16_t i, checksum, checksum_reg, *buf;
  783. DEBUGFUNC();
  784. /* Allocate a temporary buffer */
  785. buf = malloc(sizeof(buf[0]) * (EEPROM_CHECKSUM_REG + 1));
  786. if (!buf) {
  787. E1000_ERR(hw->nic, "Unable to allocate EEPROM buffer!\n");
  788. return -E1000_ERR_EEPROM;
  789. }
  790. /* Read the EEPROM */
  791. if (e1000_read_eeprom(hw, 0, EEPROM_CHECKSUM_REG + 1, buf) < 0) {
  792. E1000_ERR(hw->nic, "Unable to read EEPROM!\n");
  793. return -E1000_ERR_EEPROM;
  794. }
  795. /* Compute the checksum */
  796. checksum = 0;
  797. for (i = 0; i < EEPROM_CHECKSUM_REG; i++)
  798. checksum += buf[i];
  799. checksum = ((uint16_t)EEPROM_SUM) - checksum;
  800. checksum_reg = buf[i];
  801. /* Verify it! */
  802. if (checksum == checksum_reg)
  803. return 0;
  804. /* Hrm, verification failed, print an error */
  805. E1000_ERR(hw->nic, "EEPROM checksum is incorrect!\n");
  806. E1000_ERR(hw->nic, " ...register was 0x%04hx, calculated 0x%04hx\n",
  807. checksum_reg, checksum);
  808. return -E1000_ERR_EEPROM;
  809. }
  810. #endif /* CONFIG_E1000_NO_NVM */
  811. /*****************************************************************************
  812. * Set PHY to class A mode
  813. * Assumes the following operations will follow to enable the new class mode.
  814. * 1. Do a PHY soft reset
  815. * 2. Restart auto-negotiation or force link.
  816. *
  817. * hw - Struct containing variables accessed by shared code
  818. ****************************************************************************/
  819. static int32_t
  820. e1000_set_phy_mode(struct e1000_hw *hw)
  821. {
  822. #ifndef CONFIG_E1000_NO_NVM
  823. int32_t ret_val;
  824. uint16_t eeprom_data;
  825. DEBUGFUNC();
  826. if ((hw->mac_type == e1000_82545_rev_3) &&
  827. (hw->media_type == e1000_media_type_copper)) {
  828. ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD,
  829. 1, &eeprom_data);
  830. if (ret_val)
  831. return ret_val;
  832. if ((eeprom_data != EEPROM_RESERVED_WORD) &&
  833. (eeprom_data & EEPROM_PHY_CLASS_A)) {
  834. ret_val = e1000_write_phy_reg(hw,
  835. M88E1000_PHY_PAGE_SELECT, 0x000B);
  836. if (ret_val)
  837. return ret_val;
  838. ret_val = e1000_write_phy_reg(hw,
  839. M88E1000_PHY_GEN_CONTROL, 0x8104);
  840. if (ret_val)
  841. return ret_val;
  842. hw->phy_reset_disable = false;
  843. }
  844. }
  845. #endif
  846. return E1000_SUCCESS;
  847. }
  848. #ifndef CONFIG_E1000_NO_NVM
  849. /***************************************************************************
  850. *
  851. * Obtaining software semaphore bit (SMBI) before resetting PHY.
  852. *
  853. * hw: Struct containing variables accessed by shared code
  854. *
  855. * returns: - E1000_ERR_RESET if fail to obtain semaphore.
  856. * E1000_SUCCESS at any other case.
  857. *
  858. ***************************************************************************/
  859. static int32_t
  860. e1000_get_software_semaphore(struct e1000_hw *hw)
  861. {
  862. int32_t timeout = hw->eeprom.word_size + 1;
  863. uint32_t swsm;
  864. DEBUGFUNC();
  865. if (hw->mac_type != e1000_80003es2lan)
  866. return E1000_SUCCESS;
  867. while (timeout) {
  868. swsm = E1000_READ_REG(hw, SWSM);
  869. /* If SMBI bit cleared, it is now set and we hold
  870. * the semaphore */
  871. if (!(swsm & E1000_SWSM_SMBI))
  872. break;
  873. mdelay(1);
  874. timeout--;
  875. }
  876. if (!timeout) {
  877. DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
  878. return -E1000_ERR_RESET;
  879. }
  880. return E1000_SUCCESS;
  881. }
  882. #endif
  883. /***************************************************************************
  884. * This function clears HW semaphore bits.
  885. *
  886. * hw: Struct containing variables accessed by shared code
  887. *
  888. * returns: - None.
  889. *
  890. ***************************************************************************/
  891. static void
  892. e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
  893. {
  894. #ifndef CONFIG_E1000_NO_NVM
  895. uint32_t swsm;
  896. DEBUGFUNC();
  897. if (!hw->eeprom_semaphore_present)
  898. return;
  899. swsm = E1000_READ_REG(hw, SWSM);
  900. if (hw->mac_type == e1000_80003es2lan) {
  901. /* Release both semaphores. */
  902. swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
  903. } else
  904. swsm &= ~(E1000_SWSM_SWESMBI);
  905. E1000_WRITE_REG(hw, SWSM, swsm);
  906. #endif
  907. }
  908. /***************************************************************************
  909. *
  910. * Using the combination of SMBI and SWESMBI semaphore bits when resetting
  911. * adapter or Eeprom access.
  912. *
  913. * hw: Struct containing variables accessed by shared code
  914. *
  915. * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
  916. * E1000_SUCCESS at any other case.
  917. *
  918. ***************************************************************************/
  919. static int32_t
  920. e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
  921. {
  922. #ifndef CONFIG_E1000_NO_NVM
  923. int32_t timeout;
  924. uint32_t swsm;
  925. DEBUGFUNC();
  926. if (!hw->eeprom_semaphore_present)
  927. return E1000_SUCCESS;
  928. if (hw->mac_type == e1000_80003es2lan) {
  929. /* Get the SW semaphore. */
  930. if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
  931. return -E1000_ERR_EEPROM;
  932. }
  933. /* Get the FW semaphore. */
  934. timeout = hw->eeprom.word_size + 1;
  935. while (timeout) {
  936. swsm = E1000_READ_REG(hw, SWSM);
  937. swsm |= E1000_SWSM_SWESMBI;
  938. E1000_WRITE_REG(hw, SWSM, swsm);
  939. /* if we managed to set the bit we got the semaphore. */
  940. swsm = E1000_READ_REG(hw, SWSM);
  941. if (swsm & E1000_SWSM_SWESMBI)
  942. break;
  943. udelay(50);
  944. timeout--;
  945. }
  946. if (!timeout) {
  947. /* Release semaphores */
  948. e1000_put_hw_eeprom_semaphore(hw);
  949. DEBUGOUT("Driver can't access the Eeprom - "
  950. "SWESMBI bit is set.\n");
  951. return -E1000_ERR_EEPROM;
  952. }
  953. #endif
  954. return E1000_SUCCESS;
  955. }
  956. /* Take ownership of the PHY */
  957. static int32_t
  958. e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
  959. {
  960. uint32_t swfw_sync = 0;
  961. uint32_t swmask = mask;
  962. uint32_t fwmask = mask << 16;
  963. int32_t timeout = 200;
  964. DEBUGFUNC();
  965. while (timeout) {
  966. if (e1000_get_hw_eeprom_semaphore(hw))
  967. return -E1000_ERR_SWFW_SYNC;
  968. swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
  969. if (!(swfw_sync & (fwmask | swmask)))
  970. break;
  971. /* firmware currently using resource (fwmask) */
  972. /* or other software thread currently using resource (swmask) */
  973. e1000_put_hw_eeprom_semaphore(hw);
  974. mdelay(5);
  975. timeout--;
  976. }
  977. if (!timeout) {
  978. DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
  979. return -E1000_ERR_SWFW_SYNC;
  980. }
  981. swfw_sync |= swmask;
  982. E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
  983. e1000_put_hw_eeprom_semaphore(hw);
  984. return E1000_SUCCESS;
  985. }
  986. static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
  987. {
  988. uint32_t swfw_sync = 0;
  989. DEBUGFUNC();
  990. while (e1000_get_hw_eeprom_semaphore(hw))
  991. ; /* Empty */
  992. swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
  993. swfw_sync &= ~mask;
  994. E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
  995. e1000_put_hw_eeprom_semaphore(hw);
  996. }
  997. static bool e1000_is_second_port(struct e1000_hw *hw)
  998. {
  999. switch (hw->mac_type) {
  1000. case e1000_80003es2lan:
  1001. case e1000_82546:
  1002. case e1000_82571:
  1003. if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
  1004. return true;
  1005. /* Fallthrough */
  1006. default:
  1007. return false;
  1008. }
  1009. }
  1010. #ifndef CONFIG_E1000_NO_NVM
  1011. /******************************************************************************
  1012. * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
  1013. * second function of dual function devices
  1014. *
  1015. * nic - Struct containing variables accessed by shared code
  1016. *****************************************************************************/
  1017. static int
  1018. e1000_read_mac_addr(struct eth_device *nic)
  1019. {
  1020. struct e1000_hw *hw = nic->priv;
  1021. uint16_t offset;
  1022. uint16_t eeprom_data;
  1023. uint32_t reg_data = 0;
  1024. int i;
  1025. DEBUGFUNC();
  1026. for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
  1027. offset = i >> 1;
  1028. if (hw->mac_type == e1000_igb) {
  1029. /* i210 preloads MAC address into RAL/RAH registers */
  1030. if (offset == 0)
  1031. reg_data = E1000_READ_REG_ARRAY(hw, RA, 0);
  1032. else if (offset == 1)
  1033. reg_data >>= 16;
  1034. else if (offset == 2)
  1035. reg_data = E1000_READ_REG_ARRAY(hw, RA, 1);
  1036. eeprom_data = reg_data & 0xffff;
  1037. } else if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
  1038. DEBUGOUT("EEPROM Read Error\n");
  1039. return -E1000_ERR_EEPROM;
  1040. }
  1041. nic->enetaddr[i] = eeprom_data & 0xff;
  1042. nic->enetaddr[i + 1] = (eeprom_data >> 8) & 0xff;
  1043. }
  1044. /* Invert the last bit if this is the second device */
  1045. if (e1000_is_second_port(hw))
  1046. nic->enetaddr[5] ^= 1;
  1047. #ifdef CONFIG_E1000_FALLBACK_MAC
  1048. if (!is_valid_ethaddr(nic->enetaddr)) {
  1049. unsigned char fb_mac[NODE_ADDRESS_SIZE] = CONFIG_E1000_FALLBACK_MAC;
  1050. memcpy (nic->enetaddr, fb_mac, NODE_ADDRESS_SIZE);
  1051. }
  1052. #endif
  1053. return 0;
  1054. }
  1055. #endif
  1056. /******************************************************************************
  1057. * Initializes receive address filters.
  1058. *
  1059. * hw - Struct containing variables accessed by shared code
  1060. *
  1061. * Places the MAC address in receive address register 0 and clears the rest
  1062. * of the receive addresss registers. Clears the multicast table. Assumes
  1063. * the receiver is in reset when the routine is called.
  1064. *****************************************************************************/
  1065. static void
  1066. e1000_init_rx_addrs(struct eth_device *nic)
  1067. {
  1068. struct e1000_hw *hw = nic->priv;
  1069. uint32_t i;
  1070. uint32_t addr_low;
  1071. uint32_t addr_high;
  1072. DEBUGFUNC();
  1073. /* Setup the receive address. */
  1074. DEBUGOUT("Programming MAC Address into RAR[0]\n");
  1075. addr_low = (nic->enetaddr[0] |
  1076. (nic->enetaddr[1] << 8) |
  1077. (nic->enetaddr[2] << 16) | (nic->enetaddr[3] << 24));
  1078. addr_high = (nic->enetaddr[4] | (nic->enetaddr[5] << 8) | E1000_RAH_AV);
  1079. E1000_WRITE_REG_ARRAY(hw, RA, 0, addr_low);
  1080. E1000_WRITE_REG_ARRAY(hw, RA, 1, addr_high);
  1081. /* Zero out the other 15 receive addresses. */
  1082. DEBUGOUT("Clearing RAR[1-15]\n");
  1083. for (i = 1; i < E1000_RAR_ENTRIES; i++) {
  1084. E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
  1085. E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
  1086. }
  1087. }
  1088. /******************************************************************************
  1089. * Clears the VLAN filer table
  1090. *
  1091. * hw - Struct containing variables accessed by shared code
  1092. *****************************************************************************/
  1093. static void
  1094. e1000_clear_vfta(struct e1000_hw *hw)
  1095. {
  1096. uint32_t offset;
  1097. for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++)
  1098. E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
  1099. }
  1100. /******************************************************************************
  1101. * Set the mac type member in the hw struct.
  1102. *
  1103. * hw - Struct containing variables accessed by shared code
  1104. *****************************************************************************/
  1105. int32_t
  1106. e1000_set_mac_type(struct e1000_hw *hw)
  1107. {
  1108. DEBUGFUNC();
  1109. switch (hw->device_id) {
  1110. case E1000_DEV_ID_82542:
  1111. switch (hw->revision_id) {
  1112. case E1000_82542_2_0_REV_ID:
  1113. hw->mac_type = e1000_82542_rev2_0;
  1114. break;
  1115. case E1000_82542_2_1_REV_ID:
  1116. hw->mac_type = e1000_82542_rev2_1;
  1117. break;
  1118. default:
  1119. /* Invalid 82542 revision ID */
  1120. return -E1000_ERR_MAC_TYPE;
  1121. }
  1122. break;
  1123. case E1000_DEV_ID_82543GC_FIBER:
  1124. case E1000_DEV_ID_82543GC_COPPER:
  1125. hw->mac_type = e1000_82543;
  1126. break;
  1127. case E1000_DEV_ID_82544EI_COPPER:
  1128. case E1000_DEV_ID_82544EI_FIBER:
  1129. case E1000_DEV_ID_82544GC_COPPER:
  1130. case E1000_DEV_ID_82544GC_LOM:
  1131. hw->mac_type = e1000_82544;
  1132. break;
  1133. case E1000_DEV_ID_82540EM:
  1134. case E1000_DEV_ID_82540EM_LOM:
  1135. case E1000_DEV_ID_82540EP:
  1136. case E1000_DEV_ID_82540EP_LOM:
  1137. case E1000_DEV_ID_82540EP_LP:
  1138. hw->mac_type = e1000_82540;
  1139. break;
  1140. case E1000_DEV_ID_82545EM_COPPER:
  1141. case E1000_DEV_ID_82545EM_FIBER:
  1142. hw->mac_type = e1000_82545;
  1143. break;
  1144. case E1000_DEV_ID_82545GM_COPPER:
  1145. case E1000_DEV_ID_82545GM_FIBER:
  1146. case E1000_DEV_ID_82545GM_SERDES:
  1147. hw->mac_type = e1000_82545_rev_3;
  1148. break;
  1149. case E1000_DEV_ID_82546EB_COPPER:
  1150. case E1000_DEV_ID_82546EB_FIBER:
  1151. case E1000_DEV_ID_82546EB_QUAD_COPPER:
  1152. hw->mac_type = e1000_82546;
  1153. break;
  1154. case E1000_DEV_ID_82546GB_COPPER:
  1155. case E1000_DEV_ID_82546GB_FIBER:
  1156. case E1000_DEV_ID_82546GB_SERDES:
  1157. case E1000_DEV_ID_82546GB_PCIE:
  1158. case E1000_DEV_ID_82546GB_QUAD_COPPER:
  1159. case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
  1160. hw->mac_type = e1000_82546_rev_3;
  1161. break;
  1162. case E1000_DEV_ID_82541EI:
  1163. case E1000_DEV_ID_82541EI_MOBILE:
  1164. case E1000_DEV_ID_82541ER_LOM:
  1165. hw->mac_type = e1000_82541;
  1166. break;
  1167. case E1000_DEV_ID_82541ER:
  1168. case E1000_DEV_ID_82541GI:
  1169. case E1000_DEV_ID_82541GI_LF:
  1170. case E1000_DEV_ID_82541GI_MOBILE:
  1171. hw->mac_type = e1000_82541_rev_2;
  1172. break;
  1173. case E1000_DEV_ID_82547EI:
  1174. case E1000_DEV_ID_82547EI_MOBILE:
  1175. hw->mac_type = e1000_82547;
  1176. break;
  1177. case E1000_DEV_ID_82547GI:
  1178. hw->mac_type = e1000_82547_rev_2;
  1179. break;
  1180. case E1000_DEV_ID_82571EB_COPPER:
  1181. case E1000_DEV_ID_82571EB_FIBER:
  1182. case E1000_DEV_ID_82571EB_SERDES:
  1183. case E1000_DEV_ID_82571EB_SERDES_DUAL:
  1184. case E1000_DEV_ID_82571EB_SERDES_QUAD:
  1185. case E1000_DEV_ID_82571EB_QUAD_COPPER:
  1186. case E1000_DEV_ID_82571PT_QUAD_COPPER:
  1187. case E1000_DEV_ID_82571EB_QUAD_FIBER:
  1188. case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
  1189. hw->mac_type = e1000_82571;
  1190. break;
  1191. case E1000_DEV_ID_82572EI_COPPER:
  1192. case E1000_DEV_ID_82572EI_FIBER:
  1193. case E1000_DEV_ID_82572EI_SERDES:
  1194. case E1000_DEV_ID_82572EI:
  1195. hw->mac_type = e1000_82572;
  1196. break;
  1197. case E1000_DEV_ID_82573E:
  1198. case E1000_DEV_ID_82573E_IAMT:
  1199. case E1000_DEV_ID_82573L:
  1200. hw->mac_type = e1000_82573;
  1201. break;
  1202. case E1000_DEV_ID_82574L:
  1203. hw->mac_type = e1000_82574;
  1204. break;
  1205. case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
  1206. case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
  1207. case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
  1208. case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
  1209. hw->mac_type = e1000_80003es2lan;
  1210. break;
  1211. case E1000_DEV_ID_ICH8_IGP_M_AMT:
  1212. case E1000_DEV_ID_ICH8_IGP_AMT:
  1213. case E1000_DEV_ID_ICH8_IGP_C:
  1214. case E1000_DEV_ID_ICH8_IFE:
  1215. case E1000_DEV_ID_ICH8_IFE_GT:
  1216. case E1000_DEV_ID_ICH8_IFE_G:
  1217. case E1000_DEV_ID_ICH8_IGP_M:
  1218. hw->mac_type = e1000_ich8lan;
  1219. break;
  1220. case PCI_DEVICE_ID_INTEL_I210_UNPROGRAMMED:
  1221. case PCI_DEVICE_ID_INTEL_I211_UNPROGRAMMED:
  1222. case PCI_DEVICE_ID_INTEL_I210_COPPER:
  1223. case PCI_DEVICE_ID_INTEL_I211_COPPER:
  1224. case PCI_DEVICE_ID_INTEL_I210_COPPER_FLASHLESS:
  1225. case PCI_DEVICE_ID_INTEL_I210_SERDES:
  1226. case PCI_DEVICE_ID_INTEL_I210_SERDES_FLASHLESS:
  1227. case PCI_DEVICE_ID_INTEL_I210_1000BASEKX:
  1228. hw->mac_type = e1000_igb;
  1229. break;
  1230. default:
  1231. /* Should never have loaded on this device */
  1232. return -E1000_ERR_MAC_TYPE;
  1233. }
  1234. return E1000_SUCCESS;
  1235. }
  1236. /******************************************************************************
  1237. * Reset the transmit and receive units; mask and clear all interrupts.
  1238. *
  1239. * hw - Struct containing variables accessed by shared code
  1240. *****************************************************************************/
  1241. void
  1242. e1000_reset_hw(struct e1000_hw *hw)
  1243. {
  1244. uint32_t ctrl;
  1245. uint32_t ctrl_ext;
  1246. uint32_t manc;
  1247. uint32_t pba = 0;
  1248. uint32_t reg;
  1249. DEBUGFUNC();
  1250. /* get the correct pba value for both PCI and PCIe*/
  1251. if (hw->mac_type < e1000_82571)
  1252. pba = E1000_DEFAULT_PCI_PBA;
  1253. else
  1254. pba = E1000_DEFAULT_PCIE_PBA;
  1255. /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
  1256. if (hw->mac_type == e1000_82542_rev2_0) {
  1257. DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
  1258. pci_write_config_word(hw->pdev, PCI_COMMAND,
  1259. hw->pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
  1260. }
  1261. /* Clear interrupt mask to stop board from generating interrupts */
  1262. DEBUGOUT("Masking off all interrupts\n");
  1263. if (hw->mac_type == e1000_igb)
  1264. E1000_WRITE_REG(hw, I210_IAM, 0);
  1265. E1000_WRITE_REG(hw, IMC, 0xffffffff);
  1266. /* Disable the Transmit and Receive units. Then delay to allow
  1267. * any pending transactions to complete before we hit the MAC with
  1268. * the global reset.
  1269. */
  1270. E1000_WRITE_REG(hw, RCTL, 0);
  1271. E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
  1272. E1000_WRITE_FLUSH(hw);
  1273. /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
  1274. hw->tbi_compatibility_on = false;
  1275. /* Delay to allow any outstanding PCI transactions to complete before
  1276. * resetting the device
  1277. */
  1278. mdelay(10);
  1279. /* Issue a global reset to the MAC. This will reset the chip's
  1280. * transmit, receive, DMA, and link units. It will not effect
  1281. * the current PCI configuration. The global reset bit is self-
  1282. * clearing, and should clear within a microsecond.
  1283. */
  1284. DEBUGOUT("Issuing a global reset to MAC\n");
  1285. ctrl = E1000_READ_REG(hw, CTRL);
  1286. E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
  1287. /* Force a reload from the EEPROM if necessary */
  1288. if (hw->mac_type == e1000_igb) {
  1289. mdelay(20);
  1290. reg = E1000_READ_REG(hw, STATUS);
  1291. if (reg & E1000_STATUS_PF_RST_DONE)
  1292. DEBUGOUT("PF OK\n");
  1293. reg = E1000_READ_REG(hw, I210_EECD);
  1294. if (reg & E1000_EECD_AUTO_RD)
  1295. DEBUGOUT("EEC OK\n");
  1296. } else if (hw->mac_type < e1000_82540) {
  1297. /* Wait for reset to complete */
  1298. udelay(10);
  1299. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  1300. ctrl_ext |= E1000_CTRL_EXT_EE_RST;
  1301. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  1302. E1000_WRITE_FLUSH(hw);
  1303. /* Wait for EEPROM reload */
  1304. mdelay(2);
  1305. } else {
  1306. /* Wait for EEPROM reload (it happens automatically) */
  1307. mdelay(4);
  1308. /* Dissable HW ARPs on ASF enabled adapters */
  1309. manc = E1000_READ_REG(hw, MANC);
  1310. manc &= ~(E1000_MANC_ARP_EN);
  1311. E1000_WRITE_REG(hw, MANC, manc);
  1312. }
  1313. /* Clear interrupt mask to stop board from generating interrupts */
  1314. DEBUGOUT("Masking off all interrupts\n");
  1315. if (hw->mac_type == e1000_igb)
  1316. E1000_WRITE_REG(hw, I210_IAM, 0);
  1317. E1000_WRITE_REG(hw, IMC, 0xffffffff);
  1318. /* Clear any pending interrupt events. */
  1319. E1000_READ_REG(hw, ICR);
  1320. /* If MWI was previously enabled, reenable it. */
  1321. if (hw->mac_type == e1000_82542_rev2_0) {
  1322. pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
  1323. }
  1324. if (hw->mac_type != e1000_igb)
  1325. E1000_WRITE_REG(hw, PBA, pba);
  1326. }
  1327. /******************************************************************************
  1328. *
  1329. * Initialize a number of hardware-dependent bits
  1330. *
  1331. * hw: Struct containing variables accessed by shared code
  1332. *
  1333. * This function contains hardware limitation workarounds for PCI-E adapters
  1334. *
  1335. *****************************************************************************/
  1336. static void
  1337. e1000_initialize_hardware_bits(struct e1000_hw *hw)
  1338. {
  1339. if ((hw->mac_type >= e1000_82571) &&
  1340. (!hw->initialize_hw_bits_disable)) {
  1341. /* Settings common to all PCI-express silicon */
  1342. uint32_t reg_ctrl, reg_ctrl_ext;
  1343. uint32_t reg_tarc0, reg_tarc1;
  1344. uint32_t reg_tctl;
  1345. uint32_t reg_txdctl, reg_txdctl1;
  1346. /* link autonegotiation/sync workarounds */
  1347. reg_tarc0 = E1000_READ_REG(hw, TARC0);
  1348. reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
  1349. /* Enable not-done TX descriptor counting */
  1350. reg_txdctl = E1000_READ_REG(hw, TXDCTL);
  1351. reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
  1352. E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
  1353. reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
  1354. reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
  1355. E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
  1356. /* IGB is cool */
  1357. if (hw->mac_type == e1000_igb)
  1358. return;
  1359. switch (hw->mac_type) {
  1360. case e1000_82571:
  1361. case e1000_82572:
  1362. /* Clear PHY TX compatible mode bits */
  1363. reg_tarc1 = E1000_READ_REG(hw, TARC1);
  1364. reg_tarc1 &= ~((1 << 30)|(1 << 29));
  1365. /* link autonegotiation/sync workarounds */
  1366. reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
  1367. /* TX ring control fixes */
  1368. reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
  1369. /* Multiple read bit is reversed polarity */
  1370. reg_tctl = E1000_READ_REG(hw, TCTL);
  1371. if (reg_tctl & E1000_TCTL_MULR)
  1372. reg_tarc1 &= ~(1 << 28);
  1373. else
  1374. reg_tarc1 |= (1 << 28);
  1375. E1000_WRITE_REG(hw, TARC1, reg_tarc1);
  1376. break;
  1377. case e1000_82573:
  1378. case e1000_82574:
  1379. reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  1380. reg_ctrl_ext &= ~(1 << 23);
  1381. reg_ctrl_ext |= (1 << 22);
  1382. /* TX byte count fix */
  1383. reg_ctrl = E1000_READ_REG(hw, CTRL);
  1384. reg_ctrl &= ~(1 << 29);
  1385. E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
  1386. E1000_WRITE_REG(hw, CTRL, reg_ctrl);
  1387. break;
  1388. case e1000_80003es2lan:
  1389. /* improve small packet performace for fiber/serdes */
  1390. if ((hw->media_type == e1000_media_type_fiber)
  1391. || (hw->media_type ==
  1392. e1000_media_type_internal_serdes)) {
  1393. reg_tarc0 &= ~(1 << 20);
  1394. }
  1395. /* Multiple read bit is reversed polarity */
  1396. reg_tctl = E1000_READ_REG(hw, TCTL);
  1397. reg_tarc1 = E1000_READ_REG(hw, TARC1);
  1398. if (reg_tctl & E1000_TCTL_MULR)
  1399. reg_tarc1 &= ~(1 << 28);
  1400. else
  1401. reg_tarc1 |= (1 << 28);
  1402. E1000_WRITE_REG(hw, TARC1, reg_tarc1);
  1403. break;
  1404. case e1000_ich8lan:
  1405. /* Reduce concurrent DMA requests to 3 from 4 */
  1406. if ((hw->revision_id < 3) ||
  1407. ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
  1408. (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
  1409. reg_tarc0 |= ((1 << 29)|(1 << 28));
  1410. reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  1411. reg_ctrl_ext |= (1 << 22);
  1412. E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
  1413. /* workaround TX hang with TSO=on */
  1414. reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
  1415. /* Multiple read bit is reversed polarity */
  1416. reg_tctl = E1000_READ_REG(hw, TCTL);
  1417. reg_tarc1 = E1000_READ_REG(hw, TARC1);
  1418. if (reg_tctl & E1000_TCTL_MULR)
  1419. reg_tarc1 &= ~(1 << 28);
  1420. else
  1421. reg_tarc1 |= (1 << 28);
  1422. /* workaround TX hang with TSO=on */
  1423. reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
  1424. E1000_WRITE_REG(hw, TARC1, reg_tarc1);
  1425. break;
  1426. default:
  1427. break;
  1428. }
  1429. E1000_WRITE_REG(hw, TARC0, reg_tarc0);
  1430. }
  1431. }
  1432. /******************************************************************************
  1433. * Performs basic configuration of the adapter.
  1434. *
  1435. * hw - Struct containing variables accessed by shared code
  1436. *
  1437. * Assumes that the controller has previously been reset and is in a
  1438. * post-reset uninitialized state. Initializes the receive address registers,
  1439. * multicast table, and VLAN filter table. Calls routines to setup link
  1440. * configuration and flow control settings. Clears all on-chip counters. Leaves
  1441. * the transmit and receive units disabled and uninitialized.
  1442. *****************************************************************************/
  1443. static int
  1444. e1000_init_hw(struct eth_device *nic)
  1445. {
  1446. struct e1000_hw *hw = nic->priv;
  1447. uint32_t ctrl;
  1448. uint32_t i;
  1449. int32_t ret_val;
  1450. uint16_t pcix_cmd_word;
  1451. uint16_t pcix_stat_hi_word;
  1452. uint16_t cmd_mmrbc;
  1453. uint16_t stat_mmrbc;
  1454. uint32_t mta_size;
  1455. uint32_t reg_data;
  1456. uint32_t ctrl_ext;
  1457. DEBUGFUNC();
  1458. /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
  1459. if ((hw->mac_type == e1000_ich8lan) &&
  1460. ((hw->revision_id < 3) ||
  1461. ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
  1462. (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
  1463. reg_data = E1000_READ_REG(hw, STATUS);
  1464. reg_data &= ~0x80000000;
  1465. E1000_WRITE_REG(hw, STATUS, reg_data);
  1466. }
  1467. /* Do not need initialize Identification LED */
  1468. /* Set the media type and TBI compatibility */
  1469. e1000_set_media_type(hw);
  1470. /* Must be called after e1000_set_media_type
  1471. * because media_type is used */
  1472. e1000_initialize_hardware_bits(hw);
  1473. /* Disabling VLAN filtering. */
  1474. DEBUGOUT("Initializing the IEEE VLAN\n");
  1475. /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
  1476. if (hw->mac_type != e1000_ich8lan) {
  1477. if (hw->mac_type < e1000_82545_rev_3)
  1478. E1000_WRITE_REG(hw, VET, 0);
  1479. e1000_clear_vfta(hw);
  1480. }
  1481. /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
  1482. if (hw->mac_type == e1000_82542_rev2_0) {
  1483. DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
  1484. pci_write_config_word(hw->pdev, PCI_COMMAND,
  1485. hw->
  1486. pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
  1487. E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
  1488. E1000_WRITE_FLUSH(hw);
  1489. mdelay(5);
  1490. }
  1491. /* Setup the receive address. This involves initializing all of the Receive
  1492. * Address Registers (RARs 0 - 15).
  1493. */
  1494. e1000_init_rx_addrs(nic);
  1495. /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
  1496. if (hw->mac_type == e1000_82542_rev2_0) {
  1497. E1000_WRITE_REG(hw, RCTL, 0);
  1498. E1000_WRITE_FLUSH(hw);
  1499. mdelay(1);
  1500. pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
  1501. }
  1502. /* Zero out the Multicast HASH table */
  1503. DEBUGOUT("Zeroing the MTA\n");
  1504. mta_size = E1000_MC_TBL_SIZE;
  1505. if (hw->mac_type == e1000_ich8lan)
  1506. mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
  1507. for (i = 0; i < mta_size; i++) {
  1508. E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
  1509. /* use write flush to prevent Memory Write Block (MWB) from
  1510. * occuring when accessing our register space */
  1511. E1000_WRITE_FLUSH(hw);
  1512. }
  1513. #if 0
  1514. /* Set the PCI priority bit correctly in the CTRL register. This
  1515. * determines if the adapter gives priority to receives, or if it
  1516. * gives equal priority to transmits and receives. Valid only on
  1517. * 82542 and 82543 silicon.
  1518. */
  1519. if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
  1520. ctrl = E1000_READ_REG(hw, CTRL);
  1521. E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
  1522. }
  1523. #endif
  1524. switch (hw->mac_type) {
  1525. case e1000_82545_rev_3:
  1526. case e1000_82546_rev_3:
  1527. case e1000_igb:
  1528. break;
  1529. default:
  1530. /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
  1531. if (hw->bus_type == e1000_bus_type_pcix) {
  1532. pci_read_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
  1533. &pcix_cmd_word);
  1534. pci_read_config_word(hw->pdev, PCIX_STATUS_REGISTER_HI,
  1535. &pcix_stat_hi_word);
  1536. cmd_mmrbc =
  1537. (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
  1538. PCIX_COMMAND_MMRBC_SHIFT;
  1539. stat_mmrbc =
  1540. (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
  1541. PCIX_STATUS_HI_MMRBC_SHIFT;
  1542. if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
  1543. stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
  1544. if (cmd_mmrbc > stat_mmrbc) {
  1545. pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
  1546. pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
  1547. pci_write_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
  1548. pcix_cmd_word);
  1549. }
  1550. }
  1551. break;
  1552. }
  1553. /* More time needed for PHY to initialize */
  1554. if (hw->mac_type == e1000_ich8lan)
  1555. mdelay(15);
  1556. if (hw->mac_type == e1000_igb)
  1557. mdelay(15);
  1558. /* Call a subroutine to configure the link and setup flow control. */
  1559. ret_val = e1000_setup_link(nic);
  1560. /* Set the transmit descriptor write-back policy */
  1561. if (hw->mac_type > e1000_82544) {
  1562. ctrl = E1000_READ_REG(hw, TXDCTL);
  1563. ctrl =
  1564. (ctrl & ~E1000_TXDCTL_WTHRESH) |
  1565. E1000_TXDCTL_FULL_TX_DESC_WB;
  1566. E1000_WRITE_REG(hw, TXDCTL, ctrl);
  1567. }
  1568. /* Set the receive descriptor write back policy */
  1569. if (hw->mac_type >= e1000_82571) {
  1570. ctrl = E1000_READ_REG(hw, RXDCTL);
  1571. ctrl =
  1572. (ctrl & ~E1000_RXDCTL_WTHRESH) |
  1573. E1000_RXDCTL_FULL_RX_DESC_WB;
  1574. E1000_WRITE_REG(hw, RXDCTL, ctrl);
  1575. }
  1576. switch (hw->mac_type) {
  1577. default:
  1578. break;
  1579. case e1000_80003es2lan:
  1580. /* Enable retransmit on late collisions */
  1581. reg_data = E1000_READ_REG(hw, TCTL);
  1582. reg_data |= E1000_TCTL_RTLC;
  1583. E1000_WRITE_REG(hw, TCTL, reg_data);
  1584. /* Configure Gigabit Carry Extend Padding */
  1585. reg_data = E1000_READ_REG(hw, TCTL_EXT);
  1586. reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
  1587. reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
  1588. E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
  1589. /* Configure Transmit Inter-Packet Gap */
  1590. reg_data = E1000_READ_REG(hw, TIPG);
  1591. reg_data &= ~E1000_TIPG_IPGT_MASK;
  1592. reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
  1593. E1000_WRITE_REG(hw, TIPG, reg_data);
  1594. reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
  1595. reg_data &= ~0x00100000;
  1596. E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
  1597. /* Fall through */
  1598. case e1000_82571:
  1599. case e1000_82572:
  1600. case e1000_ich8lan:
  1601. ctrl = E1000_READ_REG(hw, TXDCTL1);
  1602. ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH)
  1603. | E1000_TXDCTL_FULL_TX_DESC_WB;
  1604. E1000_WRITE_REG(hw, TXDCTL1, ctrl);
  1605. break;
  1606. case e1000_82573:
  1607. case e1000_82574:
  1608. reg_data = E1000_READ_REG(hw, GCR);
  1609. reg_data |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
  1610. E1000_WRITE_REG(hw, GCR, reg_data);
  1611. case e1000_igb:
  1612. break;
  1613. }
  1614. #if 0
  1615. /* Clear all of the statistics registers (clear on read). It is
  1616. * important that we do this after we have tried to establish link
  1617. * because the symbol error count will increment wildly if there
  1618. * is no link.
  1619. */
  1620. e1000_clear_hw_cntrs(hw);
  1621. /* ICH8 No-snoop bits are opposite polarity.
  1622. * Set to snoop by default after reset. */
  1623. if (hw->mac_type == e1000_ich8lan)
  1624. e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
  1625. #endif
  1626. if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
  1627. hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
  1628. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  1629. /* Relaxed ordering must be disabled to avoid a parity
  1630. * error crash in a PCI slot. */
  1631. ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
  1632. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  1633. }
  1634. return ret_val;
  1635. }
  1636. /******************************************************************************
  1637. * Configures flow control and link settings.
  1638. *
  1639. * hw - Struct containing variables accessed by shared code
  1640. *
  1641. * Determines which flow control settings to use. Calls the apropriate media-
  1642. * specific link configuration function. Configures the flow control settings.
  1643. * Assuming the adapter has a valid link partner, a valid link should be
  1644. * established. Assumes the hardware has previously been reset and the
  1645. * transmitter and receiver are not enabled.
  1646. *****************************************************************************/
  1647. static int
  1648. e1000_setup_link(struct eth_device *nic)
  1649. {
  1650. struct e1000_hw *hw = nic->priv;
  1651. int32_t ret_val;
  1652. #ifndef CONFIG_E1000_NO_NVM
  1653. uint32_t ctrl_ext;
  1654. uint16_t eeprom_data;
  1655. #endif
  1656. DEBUGFUNC();
  1657. /* In the case of the phy reset being blocked, we already have a link.
  1658. * We do not have to set it up again. */
  1659. if (e1000_check_phy_reset_block(hw))
  1660. return E1000_SUCCESS;
  1661. #ifndef CONFIG_E1000_NO_NVM
  1662. /* Read and store word 0x0F of the EEPROM. This word contains bits
  1663. * that determine the hardware's default PAUSE (flow control) mode,
  1664. * a bit that determines whether the HW defaults to enabling or
  1665. * disabling auto-negotiation, and the direction of the
  1666. * SW defined pins. If there is no SW over-ride of the flow
  1667. * control setting, then the variable hw->fc will
  1668. * be initialized based on a value in the EEPROM.
  1669. */
  1670. if (e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1,
  1671. &eeprom_data) < 0) {
  1672. DEBUGOUT("EEPROM Read Error\n");
  1673. return -E1000_ERR_EEPROM;
  1674. }
  1675. #endif
  1676. if (hw->fc == e1000_fc_default) {
  1677. switch (hw->mac_type) {
  1678. case e1000_ich8lan:
  1679. case e1000_82573:
  1680. case e1000_82574:
  1681. case e1000_igb:
  1682. hw->fc = e1000_fc_full;
  1683. break;
  1684. default:
  1685. #ifndef CONFIG_E1000_NO_NVM
  1686. ret_val = e1000_read_eeprom(hw,
  1687. EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
  1688. if (ret_val) {
  1689. DEBUGOUT("EEPROM Read Error\n");
  1690. return -E1000_ERR_EEPROM;
  1691. }
  1692. if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
  1693. hw->fc = e1000_fc_none;
  1694. else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
  1695. EEPROM_WORD0F_ASM_DIR)
  1696. hw->fc = e1000_fc_tx_pause;
  1697. else
  1698. #endif
  1699. hw->fc = e1000_fc_full;
  1700. break;
  1701. }
  1702. }
  1703. /* We want to save off the original Flow Control configuration just
  1704. * in case we get disconnected and then reconnected into a different
  1705. * hub or switch with different Flow Control capabilities.
  1706. */
  1707. if (hw->mac_type == e1000_82542_rev2_0)
  1708. hw->fc &= (~e1000_fc_tx_pause);
  1709. if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
  1710. hw->fc &= (~e1000_fc_rx_pause);
  1711. hw->original_fc = hw->fc;
  1712. DEBUGOUT("After fix-ups FlowControl is now = %x\n", hw->fc);
  1713. #ifndef CONFIG_E1000_NO_NVM
  1714. /* Take the 4 bits from EEPROM word 0x0F that determine the initial
  1715. * polarity value for the SW controlled pins, and setup the
  1716. * Extended Device Control reg with that info.
  1717. * This is needed because one of the SW controlled pins is used for
  1718. * signal detection. So this should be done before e1000_setup_pcs_link()
  1719. * or e1000_phy_setup() is called.
  1720. */
  1721. if (hw->mac_type == e1000_82543) {
  1722. ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
  1723. SWDPIO__EXT_SHIFT);
  1724. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  1725. }
  1726. #endif
  1727. /* Call the necessary subroutine to configure the link. */
  1728. ret_val = (hw->media_type == e1000_media_type_fiber) ?
  1729. e1000_setup_fiber_link(nic) : e1000_setup_copper_link(nic);
  1730. if (ret_val < 0) {
  1731. return ret_val;
  1732. }
  1733. /* Initialize the flow control address, type, and PAUSE timer
  1734. * registers to their default values. This is done even if flow
  1735. * control is disabled, because it does not hurt anything to
  1736. * initialize these registers.
  1737. */
  1738. DEBUGOUT("Initializing the Flow Control address, type"
  1739. "and timer regs\n");
  1740. /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
  1741. if (hw->mac_type != e1000_ich8lan) {
  1742. E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
  1743. E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
  1744. E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
  1745. }
  1746. E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
  1747. /* Set the flow control receive threshold registers. Normally,
  1748. * these registers will be set to a default threshold that may be
  1749. * adjusted later by the driver's runtime code. However, if the
  1750. * ability to transmit pause frames in not enabled, then these
  1751. * registers will be set to 0.
  1752. */
  1753. if (!(hw->fc & e1000_fc_tx_pause)) {
  1754. E1000_WRITE_REG(hw, FCRTL, 0);
  1755. E1000_WRITE_REG(hw, FCRTH, 0);
  1756. } else {
  1757. /* We need to set up the Receive Threshold high and low water marks
  1758. * as well as (optionally) enabling the transmission of XON frames.
  1759. */
  1760. if (hw->fc_send_xon) {
  1761. E1000_WRITE_REG(hw, FCRTL,
  1762. (hw->fc_low_water | E1000_FCRTL_XONE));
  1763. E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
  1764. } else {
  1765. E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
  1766. E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
  1767. }
  1768. }
  1769. return ret_val;
  1770. }
  1771. /******************************************************************************
  1772. * Sets up link for a fiber based adapter
  1773. *
  1774. * hw - Struct containing variables accessed by shared code
  1775. *
  1776. * Manipulates Physical Coding Sublayer functions in order to configure
  1777. * link. Assumes the hardware has been previously reset and the transmitter
  1778. * and receiver are not enabled.
  1779. *****************************************************************************/
  1780. static int
  1781. e1000_setup_fiber_link(struct eth_device *nic)
  1782. {
  1783. struct e1000_hw *hw = nic->priv;
  1784. uint32_t ctrl;
  1785. uint32_t status;
  1786. uint32_t txcw = 0;
  1787. uint32_t i;
  1788. uint32_t signal;
  1789. int32_t ret_val;
  1790. DEBUGFUNC();
  1791. /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
  1792. * set when the optics detect a signal. On older adapters, it will be
  1793. * cleared when there is a signal
  1794. */
  1795. ctrl = E1000_READ_REG(hw, CTRL);
  1796. if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
  1797. signal = E1000_CTRL_SWDPIN1;
  1798. else
  1799. signal = 0;
  1800. printf("signal for %s is %x (ctrl %08x)!!!!\n", nic->name, signal,
  1801. ctrl);
  1802. /* Take the link out of reset */
  1803. ctrl &= ~(E1000_CTRL_LRST);
  1804. e1000_config_collision_dist(hw);
  1805. /* Check for a software override of the flow control settings, and setup
  1806. * the device accordingly. If auto-negotiation is enabled, then software
  1807. * will have to set the "PAUSE" bits to the correct value in the Tranmsit
  1808. * Config Word Register (TXCW) and re-start auto-negotiation. However, if
  1809. * auto-negotiation is disabled, then software will have to manually
  1810. * configure the two flow control enable bits in the CTRL register.
  1811. *
  1812. * The possible values of the "fc" parameter are:
  1813. * 0: Flow control is completely disabled
  1814. * 1: Rx flow control is enabled (we can receive pause frames, but
  1815. * not send pause frames).
  1816. * 2: Tx flow control is enabled (we can send pause frames but we do
  1817. * not support receiving pause frames).
  1818. * 3: Both Rx and TX flow control (symmetric) are enabled.
  1819. */
  1820. switch (hw->fc) {
  1821. case e1000_fc_none:
  1822. /* Flow control is completely disabled by a software over-ride. */
  1823. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
  1824. break;
  1825. case e1000_fc_rx_pause:
  1826. /* RX Flow control is enabled and TX Flow control is disabled by a
  1827. * software over-ride. Since there really isn't a way to advertise
  1828. * that we are capable of RX Pause ONLY, we will advertise that we
  1829. * support both symmetric and asymmetric RX PAUSE. Later, we will
  1830. * disable the adapter's ability to send PAUSE frames.
  1831. */
  1832. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  1833. break;
  1834. case e1000_fc_tx_pause:
  1835. /* TX Flow control is enabled, and RX Flow control is disabled, by a
  1836. * software over-ride.
  1837. */
  1838. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
  1839. break;
  1840. case e1000_fc_full:
  1841. /* Flow control (both RX and TX) is enabled by a software over-ride. */
  1842. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  1843. break;
  1844. default:
  1845. DEBUGOUT("Flow control param set incorrectly\n");
  1846. return -E1000_ERR_CONFIG;
  1847. break;
  1848. }
  1849. /* Since auto-negotiation is enabled, take the link out of reset (the link
  1850. * will be in reset, because we previously reset the chip). This will
  1851. * restart auto-negotiation. If auto-neogtiation is successful then the
  1852. * link-up status bit will be set and the flow control enable bits (RFCE
  1853. * and TFCE) will be set according to their negotiated value.
  1854. */
  1855. DEBUGOUT("Auto-negotiation enabled (%#x)\n", txcw);
  1856. E1000_WRITE_REG(hw, TXCW, txcw);
  1857. E1000_WRITE_REG(hw, CTRL, ctrl);
  1858. E1000_WRITE_FLUSH(hw);
  1859. hw->txcw = txcw;
  1860. mdelay(1);
  1861. /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
  1862. * indication in the Device Status Register. Time-out if a link isn't
  1863. * seen in 500 milliseconds seconds (Auto-negotiation should complete in
  1864. * less than 500 milliseconds even if the other end is doing it in SW).
  1865. */
  1866. if ((E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
  1867. DEBUGOUT("Looking for Link\n");
  1868. for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
  1869. mdelay(10);
  1870. status = E1000_READ_REG(hw, STATUS);
  1871. if (status & E1000_STATUS_LU)
  1872. break;
  1873. }
  1874. if (i == (LINK_UP_TIMEOUT / 10)) {
  1875. /* AutoNeg failed to achieve a link, so we'll call
  1876. * e1000_check_for_link. This routine will force the link up if we
  1877. * detect a signal. This will allow us to communicate with
  1878. * non-autonegotiating link partners.
  1879. */
  1880. DEBUGOUT("Never got a valid link from auto-neg!!!\n");
  1881. hw->autoneg_failed = 1;
  1882. ret_val = e1000_check_for_link(nic);
  1883. if (ret_val < 0) {
  1884. DEBUGOUT("Error while checking for link\n");
  1885. return ret_val;
  1886. }
  1887. hw->autoneg_failed = 0;
  1888. } else {
  1889. hw->autoneg_failed = 0;
  1890. DEBUGOUT("Valid Link Found\n");
  1891. }
  1892. } else {
  1893. DEBUGOUT("No Signal Detected\n");
  1894. return -E1000_ERR_NOLINK;
  1895. }
  1896. return 0;
  1897. }
  1898. /******************************************************************************
  1899. * Make sure we have a valid PHY and change PHY mode before link setup.
  1900. *
  1901. * hw - Struct containing variables accessed by shared code
  1902. ******************************************************************************/
  1903. static int32_t
  1904. e1000_copper_link_preconfig(struct e1000_hw *hw)
  1905. {
  1906. uint32_t ctrl;
  1907. int32_t ret_val;
  1908. uint16_t phy_data;
  1909. DEBUGFUNC();
  1910. ctrl = E1000_READ_REG(hw, CTRL);
  1911. /* With 82543, we need to force speed and duplex on the MAC equal to what
  1912. * the PHY speed and duplex configuration is. In addition, we need to
  1913. * perform a hardware reset on the PHY to take it out of reset.
  1914. */
  1915. if (hw->mac_type > e1000_82543) {
  1916. ctrl |= E1000_CTRL_SLU;
  1917. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1918. E1000_WRITE_REG(hw, CTRL, ctrl);
  1919. } else {
  1920. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX
  1921. | E1000_CTRL_SLU);
  1922. E1000_WRITE_REG(hw, CTRL, ctrl);
  1923. ret_val = e1000_phy_hw_reset(hw);
  1924. if (ret_val)
  1925. return ret_val;
  1926. }
  1927. /* Make sure we have a valid PHY */
  1928. ret_val = e1000_detect_gig_phy(hw);
  1929. if (ret_val) {
  1930. DEBUGOUT("Error, did not detect valid phy.\n");
  1931. return ret_val;
  1932. }
  1933. DEBUGOUT("Phy ID = %x\n", hw->phy_id);
  1934. /* Set PHY to class A mode (if necessary) */
  1935. ret_val = e1000_set_phy_mode(hw);
  1936. if (ret_val)
  1937. return ret_val;
  1938. if ((hw->mac_type == e1000_82545_rev_3) ||
  1939. (hw->mac_type == e1000_82546_rev_3)) {
  1940. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
  1941. &phy_data);
  1942. phy_data |= 0x00000008;
  1943. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
  1944. phy_data);
  1945. }
  1946. if (hw->mac_type <= e1000_82543 ||
  1947. hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
  1948. hw->mac_type == e1000_82541_rev_2
  1949. || hw->mac_type == e1000_82547_rev_2)
  1950. hw->phy_reset_disable = false;
  1951. return E1000_SUCCESS;
  1952. }
  1953. /*****************************************************************************
  1954. *
  1955. * This function sets the lplu state according to the active flag. When
  1956. * activating lplu this function also disables smart speed and vise versa.
  1957. * lplu will not be activated unless the device autonegotiation advertisment
  1958. * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
  1959. * hw: Struct containing variables accessed by shared code
  1960. * active - true to enable lplu false to disable lplu.
  1961. *
  1962. * returns: - E1000_ERR_PHY if fail to read/write the PHY
  1963. * E1000_SUCCESS at any other case.
  1964. *
  1965. ****************************************************************************/
  1966. static int32_t
  1967. e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
  1968. {
  1969. uint32_t phy_ctrl = 0;
  1970. int32_t ret_val;
  1971. uint16_t phy_data;
  1972. DEBUGFUNC();
  1973. if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
  1974. && hw->phy_type != e1000_phy_igp_3)
  1975. return E1000_SUCCESS;
  1976. /* During driver activity LPLU should not be used or it will attain link
  1977. * from the lowest speeds starting from 10Mbps. The capability is used
  1978. * for Dx transitions and states */
  1979. if (hw->mac_type == e1000_82541_rev_2
  1980. || hw->mac_type == e1000_82547_rev_2) {
  1981. ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
  1982. &phy_data);
  1983. if (ret_val)
  1984. return ret_val;
  1985. } else if (hw->mac_type == e1000_ich8lan) {
  1986. /* MAC writes into PHY register based on the state transition
  1987. * and start auto-negotiation. SW driver can overwrite the
  1988. * settings in CSR PHY power control E1000_PHY_CTRL register. */
  1989. phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
  1990. } else {
  1991. ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  1992. &phy_data);
  1993. if (ret_val)
  1994. return ret_val;
  1995. }
  1996. if (!active) {
  1997. if (hw->mac_type == e1000_82541_rev_2 ||
  1998. hw->mac_type == e1000_82547_rev_2) {
  1999. phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
  2000. ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
  2001. phy_data);
  2002. if (ret_val)
  2003. return ret_val;
  2004. } else {
  2005. if (hw->mac_type == e1000_ich8lan) {
  2006. phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
  2007. E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
  2008. } else {
  2009. phy_data &= ~IGP02E1000_PM_D3_LPLU;
  2010. ret_val = e1000_write_phy_reg(hw,
  2011. IGP02E1000_PHY_POWER_MGMT, phy_data);
  2012. if (ret_val)
  2013. return ret_val;
  2014. }
  2015. }
  2016. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
  2017. * Dx states where the power conservation is most important. During
  2018. * driver activity we should enable SmartSpeed, so performance is
  2019. * maintained. */
  2020. if (hw->smart_speed == e1000_smart_speed_on) {
  2021. ret_val = e1000_read_phy_reg(hw,
  2022. IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  2023. if (ret_val)
  2024. return ret_val;
  2025. phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
  2026. ret_val = e1000_write_phy_reg(hw,
  2027. IGP01E1000_PHY_PORT_CONFIG, phy_data);
  2028. if (ret_val)
  2029. return ret_val;
  2030. } else if (hw->smart_speed == e1000_smart_speed_off) {
  2031. ret_val = e1000_read_phy_reg(hw,
  2032. IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  2033. if (ret_val)
  2034. return ret_val;
  2035. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2036. ret_val = e1000_write_phy_reg(hw,
  2037. IGP01E1000_PHY_PORT_CONFIG, phy_data);
  2038. if (ret_val)
  2039. return ret_val;
  2040. }
  2041. } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT)
  2042. || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL) ||
  2043. (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
  2044. if (hw->mac_type == e1000_82541_rev_2 ||
  2045. hw->mac_type == e1000_82547_rev_2) {
  2046. phy_data |= IGP01E1000_GMII_FLEX_SPD;
  2047. ret_val = e1000_write_phy_reg(hw,
  2048. IGP01E1000_GMII_FIFO, phy_data);
  2049. if (ret_val)
  2050. return ret_val;
  2051. } else {
  2052. if (hw->mac_type == e1000_ich8lan) {
  2053. phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
  2054. E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
  2055. } else {
  2056. phy_data |= IGP02E1000_PM_D3_LPLU;
  2057. ret_val = e1000_write_phy_reg(hw,
  2058. IGP02E1000_PHY_POWER_MGMT, phy_data);
  2059. if (ret_val)
  2060. return ret_val;
  2061. }
  2062. }
  2063. /* When LPLU is enabled we should disable SmartSpeed */
  2064. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  2065. &phy_data);
  2066. if (ret_val)
  2067. return ret_val;
  2068. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2069. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  2070. phy_data);
  2071. if (ret_val)
  2072. return ret_val;
  2073. }
  2074. return E1000_SUCCESS;
  2075. }
  2076. /*****************************************************************************
  2077. *
  2078. * This function sets the lplu d0 state according to the active flag. When
  2079. * activating lplu this function also disables smart speed and vise versa.
  2080. * lplu will not be activated unless the device autonegotiation advertisment
  2081. * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
  2082. * hw: Struct containing variables accessed by shared code
  2083. * active - true to enable lplu false to disable lplu.
  2084. *
  2085. * returns: - E1000_ERR_PHY if fail to read/write the PHY
  2086. * E1000_SUCCESS at any other case.
  2087. *
  2088. ****************************************************************************/
  2089. static int32_t
  2090. e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active)
  2091. {
  2092. uint32_t phy_ctrl = 0;
  2093. int32_t ret_val;
  2094. uint16_t phy_data;
  2095. DEBUGFUNC();
  2096. if (hw->mac_type <= e1000_82547_rev_2)
  2097. return E1000_SUCCESS;
  2098. if (hw->mac_type == e1000_ich8lan) {
  2099. phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
  2100. } else if (hw->mac_type == e1000_igb) {
  2101. phy_ctrl = E1000_READ_REG(hw, I210_PHY_CTRL);
  2102. } else {
  2103. ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  2104. &phy_data);
  2105. if (ret_val)
  2106. return ret_val;
  2107. }
  2108. if (!active) {
  2109. if (hw->mac_type == e1000_ich8lan) {
  2110. phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
  2111. E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
  2112. } else if (hw->mac_type == e1000_igb) {
  2113. phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
  2114. E1000_WRITE_REG(hw, I210_PHY_CTRL, phy_ctrl);
  2115. } else {
  2116. phy_data &= ~IGP02E1000_PM_D0_LPLU;
  2117. ret_val = e1000_write_phy_reg(hw,
  2118. IGP02E1000_PHY_POWER_MGMT, phy_data);
  2119. if (ret_val)
  2120. return ret_val;
  2121. }
  2122. if (hw->mac_type == e1000_igb)
  2123. return E1000_SUCCESS;
  2124. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
  2125. * Dx states where the power conservation is most important. During
  2126. * driver activity we should enable SmartSpeed, so performance is
  2127. * maintained. */
  2128. if (hw->smart_speed == e1000_smart_speed_on) {
  2129. ret_val = e1000_read_phy_reg(hw,
  2130. IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  2131. if (ret_val)
  2132. return ret_val;
  2133. phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
  2134. ret_val = e1000_write_phy_reg(hw,
  2135. IGP01E1000_PHY_PORT_CONFIG, phy_data);
  2136. if (ret_val)
  2137. return ret_val;
  2138. } else if (hw->smart_speed == e1000_smart_speed_off) {
  2139. ret_val = e1000_read_phy_reg(hw,
  2140. IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  2141. if (ret_val)
  2142. return ret_val;
  2143. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2144. ret_val = e1000_write_phy_reg(hw,
  2145. IGP01E1000_PHY_PORT_CONFIG, phy_data);
  2146. if (ret_val)
  2147. return ret_val;
  2148. }
  2149. } else {
  2150. if (hw->mac_type == e1000_ich8lan) {
  2151. phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
  2152. E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
  2153. } else if (hw->mac_type == e1000_igb) {
  2154. phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
  2155. E1000_WRITE_REG(hw, I210_PHY_CTRL, phy_ctrl);
  2156. } else {
  2157. phy_data |= IGP02E1000_PM_D0_LPLU;
  2158. ret_val = e1000_write_phy_reg(hw,
  2159. IGP02E1000_PHY_POWER_MGMT, phy_data);
  2160. if (ret_val)
  2161. return ret_val;
  2162. }
  2163. if (hw->mac_type == e1000_igb)
  2164. return E1000_SUCCESS;
  2165. /* When LPLU is enabled we should disable SmartSpeed */
  2166. ret_val = e1000_read_phy_reg(hw,
  2167. IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  2168. if (ret_val)
  2169. return ret_val;
  2170. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2171. ret_val = e1000_write_phy_reg(hw,
  2172. IGP01E1000_PHY_PORT_CONFIG, phy_data);
  2173. if (ret_val)
  2174. return ret_val;
  2175. }
  2176. return E1000_SUCCESS;
  2177. }
  2178. /********************************************************************
  2179. * Copper link setup for e1000_phy_igp series.
  2180. *
  2181. * hw - Struct containing variables accessed by shared code
  2182. *********************************************************************/
  2183. static int32_t
  2184. e1000_copper_link_igp_setup(struct e1000_hw *hw)
  2185. {
  2186. uint32_t led_ctrl;
  2187. int32_t ret_val;
  2188. uint16_t phy_data;
  2189. DEBUGFUNC();
  2190. if (hw->phy_reset_disable)
  2191. return E1000_SUCCESS;
  2192. ret_val = e1000_phy_reset(hw);
  2193. if (ret_val) {
  2194. DEBUGOUT("Error Resetting the PHY\n");
  2195. return ret_val;
  2196. }
  2197. /* Wait 15ms for MAC to configure PHY from eeprom settings */
  2198. mdelay(15);
  2199. if (hw->mac_type != e1000_ich8lan) {
  2200. /* Configure activity LED after PHY reset */
  2201. led_ctrl = E1000_READ_REG(hw, LEDCTL);
  2202. led_ctrl &= IGP_ACTIVITY_LED_MASK;
  2203. led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
  2204. E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
  2205. }
  2206. /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
  2207. if (hw->phy_type == e1000_phy_igp) {
  2208. /* disable lplu d3 during driver init */
  2209. ret_val = e1000_set_d3_lplu_state(hw, false);
  2210. if (ret_val) {
  2211. DEBUGOUT("Error Disabling LPLU D3\n");
  2212. return ret_val;
  2213. }
  2214. }
  2215. /* disable lplu d0 during driver init */
  2216. ret_val = e1000_set_d0_lplu_state(hw, false);
  2217. if (ret_val) {
  2218. DEBUGOUT("Error Disabling LPLU D0\n");
  2219. return ret_val;
  2220. }
  2221. /* Configure mdi-mdix settings */
  2222. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
  2223. if (ret_val)
  2224. return ret_val;
  2225. if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  2226. hw->dsp_config_state = e1000_dsp_config_disabled;
  2227. /* Force MDI for earlier revs of the IGP PHY */
  2228. phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX
  2229. | IGP01E1000_PSCR_FORCE_MDI_MDIX);
  2230. hw->mdix = 1;
  2231. } else {
  2232. hw->dsp_config_state = e1000_dsp_config_enabled;
  2233. phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  2234. switch (hw->mdix) {
  2235. case 1:
  2236. phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  2237. break;
  2238. case 2:
  2239. phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
  2240. break;
  2241. case 0:
  2242. default:
  2243. phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
  2244. break;
  2245. }
  2246. }
  2247. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
  2248. if (ret_val)
  2249. return ret_val;
  2250. /* set auto-master slave resolution settings */
  2251. if (hw->autoneg) {
  2252. e1000_ms_type phy_ms_setting = hw->master_slave;
  2253. if (hw->ffe_config_state == e1000_ffe_config_active)
  2254. hw->ffe_config_state = e1000_ffe_config_enabled;
  2255. if (hw->dsp_config_state == e1000_dsp_config_activated)
  2256. hw->dsp_config_state = e1000_dsp_config_enabled;
  2257. /* when autonegotiation advertisment is only 1000Mbps then we
  2258. * should disable SmartSpeed and enable Auto MasterSlave
  2259. * resolution as hardware default. */
  2260. if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
  2261. /* Disable SmartSpeed */
  2262. ret_val = e1000_read_phy_reg(hw,
  2263. IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  2264. if (ret_val)
  2265. return ret_val;
  2266. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2267. ret_val = e1000_write_phy_reg(hw,
  2268. IGP01E1000_PHY_PORT_CONFIG, phy_data);
  2269. if (ret_val)
  2270. return ret_val;
  2271. /* Set auto Master/Slave resolution process */
  2272. ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
  2273. &phy_data);
  2274. if (ret_val)
  2275. return ret_val;
  2276. phy_data &= ~CR_1000T_MS_ENABLE;
  2277. ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
  2278. phy_data);
  2279. if (ret_val)
  2280. return ret_val;
  2281. }
  2282. ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
  2283. if (ret_val)
  2284. return ret_val;
  2285. /* load defaults for future use */
  2286. hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
  2287. ((phy_data & CR_1000T_MS_VALUE) ?
  2288. e1000_ms_force_master :
  2289. e1000_ms_force_slave) :
  2290. e1000_ms_auto;
  2291. switch (phy_ms_setting) {
  2292. case e1000_ms_force_master:
  2293. phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
  2294. break;
  2295. case e1000_ms_force_slave:
  2296. phy_data |= CR_1000T_MS_ENABLE;
  2297. phy_data &= ~(CR_1000T_MS_VALUE);
  2298. break;
  2299. case e1000_ms_auto:
  2300. phy_data &= ~CR_1000T_MS_ENABLE;
  2301. default:
  2302. break;
  2303. }
  2304. ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
  2305. if (ret_val)
  2306. return ret_val;
  2307. }
  2308. return E1000_SUCCESS;
  2309. }
  2310. /*****************************************************************************
  2311. * This function checks the mode of the firmware.
  2312. *
  2313. * returns - true when the mode is IAMT or false.
  2314. ****************************************************************************/
  2315. bool
  2316. e1000_check_mng_mode(struct e1000_hw *hw)
  2317. {
  2318. uint32_t fwsm;
  2319. DEBUGFUNC();
  2320. fwsm = E1000_READ_REG(hw, FWSM);
  2321. if (hw->mac_type == e1000_ich8lan) {
  2322. if ((fwsm & E1000_FWSM_MODE_MASK) ==
  2323. (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
  2324. return true;
  2325. } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
  2326. (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
  2327. return true;
  2328. return false;
  2329. }
  2330. static int32_t
  2331. e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data)
  2332. {
  2333. uint16_t swfw = E1000_SWFW_PHY0_SM;
  2334. uint32_t reg_val;
  2335. DEBUGFUNC();
  2336. if (e1000_is_second_port(hw))
  2337. swfw = E1000_SWFW_PHY1_SM;
  2338. if (e1000_swfw_sync_acquire(hw, swfw))
  2339. return -E1000_ERR_SWFW_SYNC;
  2340. reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT)
  2341. & E1000_KUMCTRLSTA_OFFSET) | data;
  2342. E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
  2343. udelay(2);
  2344. return E1000_SUCCESS;
  2345. }
  2346. static int32_t
  2347. e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data)
  2348. {
  2349. uint16_t swfw = E1000_SWFW_PHY0_SM;
  2350. uint32_t reg_val;
  2351. DEBUGFUNC();
  2352. if (e1000_is_second_port(hw))
  2353. swfw = E1000_SWFW_PHY1_SM;
  2354. if (e1000_swfw_sync_acquire(hw, swfw)) {
  2355. debug("%s[%i]\n", __func__, __LINE__);
  2356. return -E1000_ERR_SWFW_SYNC;
  2357. }
  2358. /* Write register address */
  2359. reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
  2360. E1000_KUMCTRLSTA_OFFSET) | E1000_KUMCTRLSTA_REN;
  2361. E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
  2362. udelay(2);
  2363. /* Read the data returned */
  2364. reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
  2365. *data = (uint16_t)reg_val;
  2366. return E1000_SUCCESS;
  2367. }
  2368. /********************************************************************
  2369. * Copper link setup for e1000_phy_gg82563 series.
  2370. *
  2371. * hw - Struct containing variables accessed by shared code
  2372. *********************************************************************/
  2373. static int32_t
  2374. e1000_copper_link_ggp_setup(struct e1000_hw *hw)
  2375. {
  2376. int32_t ret_val;
  2377. uint16_t phy_data;
  2378. uint32_t reg_data;
  2379. DEBUGFUNC();
  2380. if (!hw->phy_reset_disable) {
  2381. /* Enable CRS on TX for half-duplex operation. */
  2382. ret_val = e1000_read_phy_reg(hw,
  2383. GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
  2384. if (ret_val)
  2385. return ret_val;
  2386. phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
  2387. /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
  2388. phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
  2389. ret_val = e1000_write_phy_reg(hw,
  2390. GG82563_PHY_MAC_SPEC_CTRL, phy_data);
  2391. if (ret_val)
  2392. return ret_val;
  2393. /* Options:
  2394. * MDI/MDI-X = 0 (default)
  2395. * 0 - Auto for all speeds
  2396. * 1 - MDI mode
  2397. * 2 - MDI-X mode
  2398. * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
  2399. */
  2400. ret_val = e1000_read_phy_reg(hw,
  2401. GG82563_PHY_SPEC_CTRL, &phy_data);
  2402. if (ret_val)
  2403. return ret_val;
  2404. phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
  2405. switch (hw->mdix) {
  2406. case 1:
  2407. phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
  2408. break;
  2409. case 2:
  2410. phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
  2411. break;
  2412. case 0:
  2413. default:
  2414. phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
  2415. break;
  2416. }
  2417. /* Options:
  2418. * disable_polarity_correction = 0 (default)
  2419. * Automatic Correction for Reversed Cable Polarity
  2420. * 0 - Disabled
  2421. * 1 - Enabled
  2422. */
  2423. phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
  2424. ret_val = e1000_write_phy_reg(hw,
  2425. GG82563_PHY_SPEC_CTRL, phy_data);
  2426. if (ret_val)
  2427. return ret_val;
  2428. /* SW Reset the PHY so all changes take effect */
  2429. ret_val = e1000_phy_reset(hw);
  2430. if (ret_val) {
  2431. DEBUGOUT("Error Resetting the PHY\n");
  2432. return ret_val;
  2433. }
  2434. } /* phy_reset_disable */
  2435. if (hw->mac_type == e1000_80003es2lan) {
  2436. /* Bypass RX and TX FIFO's */
  2437. ret_val = e1000_write_kmrn_reg(hw,
  2438. E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
  2439. E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS
  2440. | E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
  2441. if (ret_val)
  2442. return ret_val;
  2443. ret_val = e1000_read_phy_reg(hw,
  2444. GG82563_PHY_SPEC_CTRL_2, &phy_data);
  2445. if (ret_val)
  2446. return ret_val;
  2447. phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
  2448. ret_val = e1000_write_phy_reg(hw,
  2449. GG82563_PHY_SPEC_CTRL_2, phy_data);
  2450. if (ret_val)
  2451. return ret_val;
  2452. reg_data = E1000_READ_REG(hw, CTRL_EXT);
  2453. reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
  2454. E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
  2455. ret_val = e1000_read_phy_reg(hw,
  2456. GG82563_PHY_PWR_MGMT_CTRL, &phy_data);
  2457. if (ret_val)
  2458. return ret_val;
  2459. /* Do not init these registers when the HW is in IAMT mode, since the
  2460. * firmware will have already initialized them. We only initialize
  2461. * them if the HW is not in IAMT mode.
  2462. */
  2463. if (e1000_check_mng_mode(hw) == false) {
  2464. /* Enable Electrical Idle on the PHY */
  2465. phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
  2466. ret_val = e1000_write_phy_reg(hw,
  2467. GG82563_PHY_PWR_MGMT_CTRL, phy_data);
  2468. if (ret_val)
  2469. return ret_val;
  2470. ret_val = e1000_read_phy_reg(hw,
  2471. GG82563_PHY_KMRN_MODE_CTRL, &phy_data);
  2472. if (ret_val)
  2473. return ret_val;
  2474. phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
  2475. ret_val = e1000_write_phy_reg(hw,
  2476. GG82563_PHY_KMRN_MODE_CTRL, phy_data);
  2477. if (ret_val)
  2478. return ret_val;
  2479. }
  2480. /* Workaround: Disable padding in Kumeran interface in the MAC
  2481. * and in the PHY to avoid CRC errors.
  2482. */
  2483. ret_val = e1000_read_phy_reg(hw,
  2484. GG82563_PHY_INBAND_CTRL, &phy_data);
  2485. if (ret_val)
  2486. return ret_val;
  2487. phy_data |= GG82563_ICR_DIS_PADDING;
  2488. ret_val = e1000_write_phy_reg(hw,
  2489. GG82563_PHY_INBAND_CTRL, phy_data);
  2490. if (ret_val)
  2491. return ret_val;
  2492. }
  2493. return E1000_SUCCESS;
  2494. }
  2495. /********************************************************************
  2496. * Copper link setup for e1000_phy_m88 series.
  2497. *
  2498. * hw - Struct containing variables accessed by shared code
  2499. *********************************************************************/
  2500. static int32_t
  2501. e1000_copper_link_mgp_setup(struct e1000_hw *hw)
  2502. {
  2503. int32_t ret_val;
  2504. uint16_t phy_data;
  2505. DEBUGFUNC();
  2506. if (hw->phy_reset_disable)
  2507. return E1000_SUCCESS;
  2508. /* Enable CRS on TX. This must be set for half-duplex operation. */
  2509. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  2510. if (ret_val)
  2511. return ret_val;
  2512. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  2513. /* Options:
  2514. * MDI/MDI-X = 0 (default)
  2515. * 0 - Auto for all speeds
  2516. * 1 - MDI mode
  2517. * 2 - MDI-X mode
  2518. * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
  2519. */
  2520. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  2521. switch (hw->mdix) {
  2522. case 1:
  2523. phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
  2524. break;
  2525. case 2:
  2526. phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
  2527. break;
  2528. case 3:
  2529. phy_data |= M88E1000_PSCR_AUTO_X_1000T;
  2530. break;
  2531. case 0:
  2532. default:
  2533. phy_data |= M88E1000_PSCR_AUTO_X_MODE;
  2534. break;
  2535. }
  2536. /* Options:
  2537. * disable_polarity_correction = 0 (default)
  2538. * Automatic Correction for Reversed Cable Polarity
  2539. * 0 - Disabled
  2540. * 1 - Enabled
  2541. */
  2542. phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
  2543. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  2544. if (ret_val)
  2545. return ret_val;
  2546. if (hw->phy_revision < M88E1011_I_REV_4) {
  2547. /* Force TX_CLK in the Extended PHY Specific Control Register
  2548. * to 25MHz clock.
  2549. */
  2550. ret_val = e1000_read_phy_reg(hw,
  2551. M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
  2552. if (ret_val)
  2553. return ret_val;
  2554. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  2555. if ((hw->phy_revision == E1000_REVISION_2) &&
  2556. (hw->phy_id == M88E1111_I_PHY_ID)) {
  2557. /* Vidalia Phy, set the downshift counter to 5x */
  2558. phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
  2559. phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
  2560. ret_val = e1000_write_phy_reg(hw,
  2561. M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
  2562. if (ret_val)
  2563. return ret_val;
  2564. } else {
  2565. /* Configure Master and Slave downshift values */
  2566. phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK
  2567. | M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
  2568. phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X
  2569. | M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
  2570. ret_val = e1000_write_phy_reg(hw,
  2571. M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
  2572. if (ret_val)
  2573. return ret_val;
  2574. }
  2575. }
  2576. /* SW Reset the PHY so all changes take effect */
  2577. ret_val = e1000_phy_reset(hw);
  2578. if (ret_val) {
  2579. DEBUGOUT("Error Resetting the PHY\n");
  2580. return ret_val;
  2581. }
  2582. return E1000_SUCCESS;
  2583. }
  2584. /********************************************************************
  2585. * Setup auto-negotiation and flow control advertisements,
  2586. * and then perform auto-negotiation.
  2587. *
  2588. * hw - Struct containing variables accessed by shared code
  2589. *********************************************************************/
  2590. static int32_t
  2591. e1000_copper_link_autoneg(struct e1000_hw *hw)
  2592. {
  2593. int32_t ret_val;
  2594. uint16_t phy_data;
  2595. DEBUGFUNC();
  2596. /* Perform some bounds checking on the hw->autoneg_advertised
  2597. * parameter. If this variable is zero, then set it to the default.
  2598. */
  2599. hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
  2600. /* If autoneg_advertised is zero, we assume it was not defaulted
  2601. * by the calling code so we set to advertise full capability.
  2602. */
  2603. if (hw->autoneg_advertised == 0)
  2604. hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  2605. /* IFE phy only supports 10/100 */
  2606. if (hw->phy_type == e1000_phy_ife)
  2607. hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
  2608. DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
  2609. ret_val = e1000_phy_setup_autoneg(hw);
  2610. if (ret_val) {
  2611. DEBUGOUT("Error Setting up Auto-Negotiation\n");
  2612. return ret_val;
  2613. }
  2614. DEBUGOUT("Restarting Auto-Neg\n");
  2615. /* Restart auto-negotiation by setting the Auto Neg Enable bit and
  2616. * the Auto Neg Restart bit in the PHY control register.
  2617. */
  2618. ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
  2619. if (ret_val)
  2620. return ret_val;
  2621. phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
  2622. ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
  2623. if (ret_val)
  2624. return ret_val;
  2625. /* Does the user want to wait for Auto-Neg to complete here, or
  2626. * check at a later time (for example, callback routine).
  2627. */
  2628. /* If we do not wait for autonegtation to complete I
  2629. * do not see a valid link status.
  2630. * wait_autoneg_complete = 1 .
  2631. */
  2632. if (hw->wait_autoneg_complete) {
  2633. ret_val = e1000_wait_autoneg(hw);
  2634. if (ret_val) {
  2635. DEBUGOUT("Error while waiting for autoneg"
  2636. "to complete\n");
  2637. return ret_val;
  2638. }
  2639. }
  2640. hw->get_link_status = true;
  2641. return E1000_SUCCESS;
  2642. }
  2643. /******************************************************************************
  2644. * Config the MAC and the PHY after link is up.
  2645. * 1) Set up the MAC to the current PHY speed/duplex
  2646. * if we are on 82543. If we
  2647. * are on newer silicon, we only need to configure
  2648. * collision distance in the Transmit Control Register.
  2649. * 2) Set up flow control on the MAC to that established with
  2650. * the link partner.
  2651. * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
  2652. *
  2653. * hw - Struct containing variables accessed by shared code
  2654. ******************************************************************************/
  2655. static int32_t
  2656. e1000_copper_link_postconfig(struct e1000_hw *hw)
  2657. {
  2658. int32_t ret_val;
  2659. DEBUGFUNC();
  2660. if (hw->mac_type >= e1000_82544) {
  2661. e1000_config_collision_dist(hw);
  2662. } else {
  2663. ret_val = e1000_config_mac_to_phy(hw);
  2664. if (ret_val) {
  2665. DEBUGOUT("Error configuring MAC to PHY settings\n");
  2666. return ret_val;
  2667. }
  2668. }
  2669. ret_val = e1000_config_fc_after_link_up(hw);
  2670. if (ret_val) {
  2671. DEBUGOUT("Error Configuring Flow Control\n");
  2672. return ret_val;
  2673. }
  2674. return E1000_SUCCESS;
  2675. }
  2676. /******************************************************************************
  2677. * Detects which PHY is present and setup the speed and duplex
  2678. *
  2679. * hw - Struct containing variables accessed by shared code
  2680. ******************************************************************************/
  2681. static int
  2682. e1000_setup_copper_link(struct eth_device *nic)
  2683. {
  2684. struct e1000_hw *hw = nic->priv;
  2685. int32_t ret_val;
  2686. uint16_t i;
  2687. uint16_t phy_data;
  2688. uint16_t reg_data;
  2689. DEBUGFUNC();
  2690. switch (hw->mac_type) {
  2691. case e1000_80003es2lan:
  2692. case e1000_ich8lan:
  2693. /* Set the mac to wait the maximum time between each
  2694. * iteration and increase the max iterations when
  2695. * polling the phy; this fixes erroneous timeouts at 10Mbps. */
  2696. ret_val = e1000_write_kmrn_reg(hw,
  2697. GG82563_REG(0x34, 4), 0xFFFF);
  2698. if (ret_val)
  2699. return ret_val;
  2700. ret_val = e1000_read_kmrn_reg(hw,
  2701. GG82563_REG(0x34, 9), &reg_data);
  2702. if (ret_val)
  2703. return ret_val;
  2704. reg_data |= 0x3F;
  2705. ret_val = e1000_write_kmrn_reg(hw,
  2706. GG82563_REG(0x34, 9), reg_data);
  2707. if (ret_val)
  2708. return ret_val;
  2709. default:
  2710. break;
  2711. }
  2712. /* Check if it is a valid PHY and set PHY mode if necessary. */
  2713. ret_val = e1000_copper_link_preconfig(hw);
  2714. if (ret_val)
  2715. return ret_val;
  2716. switch (hw->mac_type) {
  2717. case e1000_80003es2lan:
  2718. /* Kumeran registers are written-only */
  2719. reg_data =
  2720. E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
  2721. reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
  2722. ret_val = e1000_write_kmrn_reg(hw,
  2723. E1000_KUMCTRLSTA_OFFSET_INB_CTRL, reg_data);
  2724. if (ret_val)
  2725. return ret_val;
  2726. break;
  2727. default:
  2728. break;
  2729. }
  2730. if (hw->phy_type == e1000_phy_igp ||
  2731. hw->phy_type == e1000_phy_igp_3 ||
  2732. hw->phy_type == e1000_phy_igp_2) {
  2733. ret_val = e1000_copper_link_igp_setup(hw);
  2734. if (ret_val)
  2735. return ret_val;
  2736. } else if (hw->phy_type == e1000_phy_m88 ||
  2737. hw->phy_type == e1000_phy_igb) {
  2738. ret_val = e1000_copper_link_mgp_setup(hw);
  2739. if (ret_val)
  2740. return ret_val;
  2741. } else if (hw->phy_type == e1000_phy_gg82563) {
  2742. ret_val = e1000_copper_link_ggp_setup(hw);
  2743. if (ret_val)
  2744. return ret_val;
  2745. }
  2746. /* always auto */
  2747. /* Setup autoneg and flow control advertisement
  2748. * and perform autonegotiation */
  2749. ret_val = e1000_copper_link_autoneg(hw);
  2750. if (ret_val)
  2751. return ret_val;
  2752. /* Check link status. Wait up to 100 microseconds for link to become
  2753. * valid.
  2754. */
  2755. for (i = 0; i < 10; i++) {
  2756. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2757. if (ret_val)
  2758. return ret_val;
  2759. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2760. if (ret_val)
  2761. return ret_val;
  2762. if (phy_data & MII_SR_LINK_STATUS) {
  2763. /* Config the MAC and PHY after link is up */
  2764. ret_val = e1000_copper_link_postconfig(hw);
  2765. if (ret_val)
  2766. return ret_val;
  2767. DEBUGOUT("Valid link established!!!\n");
  2768. return E1000_SUCCESS;
  2769. }
  2770. udelay(10);
  2771. }
  2772. DEBUGOUT("Unable to establish link!!!\n");
  2773. return E1000_SUCCESS;
  2774. }
  2775. /******************************************************************************
  2776. * Configures PHY autoneg and flow control advertisement settings
  2777. *
  2778. * hw - Struct containing variables accessed by shared code
  2779. ******************************************************************************/
  2780. int32_t
  2781. e1000_phy_setup_autoneg(struct e1000_hw *hw)
  2782. {
  2783. int32_t ret_val;
  2784. uint16_t mii_autoneg_adv_reg;
  2785. uint16_t mii_1000t_ctrl_reg;
  2786. DEBUGFUNC();
  2787. /* Read the MII Auto-Neg Advertisement Register (Address 4). */
  2788. ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
  2789. if (ret_val)
  2790. return ret_val;
  2791. if (hw->phy_type != e1000_phy_ife) {
  2792. /* Read the MII 1000Base-T Control Register (Address 9). */
  2793. ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
  2794. &mii_1000t_ctrl_reg);
  2795. if (ret_val)
  2796. return ret_val;
  2797. } else
  2798. mii_1000t_ctrl_reg = 0;
  2799. /* Need to parse both autoneg_advertised and fc and set up
  2800. * the appropriate PHY registers. First we will parse for
  2801. * autoneg_advertised software override. Since we can advertise
  2802. * a plethora of combinations, we need to check each bit
  2803. * individually.
  2804. */
  2805. /* First we clear all the 10/100 mb speed bits in the Auto-Neg
  2806. * Advertisement Register (Address 4) and the 1000 mb speed bits in
  2807. * the 1000Base-T Control Register (Address 9).
  2808. */
  2809. mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
  2810. mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
  2811. DEBUGOUT("autoneg_advertised %x\n", hw->autoneg_advertised);
  2812. /* Do we want to advertise 10 Mb Half Duplex? */
  2813. if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
  2814. DEBUGOUT("Advertise 10mb Half duplex\n");
  2815. mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
  2816. }
  2817. /* Do we want to advertise 10 Mb Full Duplex? */
  2818. if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
  2819. DEBUGOUT("Advertise 10mb Full duplex\n");
  2820. mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
  2821. }
  2822. /* Do we want to advertise 100 Mb Half Duplex? */
  2823. if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
  2824. DEBUGOUT("Advertise 100mb Half duplex\n");
  2825. mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
  2826. }
  2827. /* Do we want to advertise 100 Mb Full Duplex? */
  2828. if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
  2829. DEBUGOUT("Advertise 100mb Full duplex\n");
  2830. mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
  2831. }
  2832. /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
  2833. if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
  2834. DEBUGOUT
  2835. ("Advertise 1000mb Half duplex requested, request denied!\n");
  2836. }
  2837. /* Do we want to advertise 1000 Mb Full Duplex? */
  2838. if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
  2839. DEBUGOUT("Advertise 1000mb Full duplex\n");
  2840. mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
  2841. }
  2842. /* Check for a software override of the flow control settings, and
  2843. * setup the PHY advertisement registers accordingly. If
  2844. * auto-negotiation is enabled, then software will have to set the
  2845. * "PAUSE" bits to the correct value in the Auto-Negotiation
  2846. * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
  2847. *
  2848. * The possible values of the "fc" parameter are:
  2849. * 0: Flow control is completely disabled
  2850. * 1: Rx flow control is enabled (we can receive pause frames
  2851. * but not send pause frames).
  2852. * 2: Tx flow control is enabled (we can send pause frames
  2853. * but we do not support receiving pause frames).
  2854. * 3: Both Rx and TX flow control (symmetric) are enabled.
  2855. * other: No software override. The flow control configuration
  2856. * in the EEPROM is used.
  2857. */
  2858. switch (hw->fc) {
  2859. case e1000_fc_none: /* 0 */
  2860. /* Flow control (RX & TX) is completely disabled by a
  2861. * software over-ride.
  2862. */
  2863. mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  2864. break;
  2865. case e1000_fc_rx_pause: /* 1 */
  2866. /* RX Flow control is enabled, and TX Flow control is
  2867. * disabled, by a software over-ride.
  2868. */
  2869. /* Since there really isn't a way to advertise that we are
  2870. * capable of RX Pause ONLY, we will advertise that we
  2871. * support both symmetric and asymmetric RX PAUSE. Later
  2872. * (in e1000_config_fc_after_link_up) we will disable the
  2873. *hw's ability to send PAUSE frames.
  2874. */
  2875. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  2876. break;
  2877. case e1000_fc_tx_pause: /* 2 */
  2878. /* TX Flow control is enabled, and RX Flow control is
  2879. * disabled, by a software over-ride.
  2880. */
  2881. mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
  2882. mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
  2883. break;
  2884. case e1000_fc_full: /* 3 */
  2885. /* Flow control (both RX and TX) is enabled by a software
  2886. * over-ride.
  2887. */
  2888. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  2889. break;
  2890. default:
  2891. DEBUGOUT("Flow control param set incorrectly\n");
  2892. return -E1000_ERR_CONFIG;
  2893. }
  2894. ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
  2895. if (ret_val)
  2896. return ret_val;
  2897. DEBUGOUT("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
  2898. if (hw->phy_type != e1000_phy_ife) {
  2899. ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
  2900. mii_1000t_ctrl_reg);
  2901. if (ret_val)
  2902. return ret_val;
  2903. }
  2904. return E1000_SUCCESS;
  2905. }
  2906. /******************************************************************************
  2907. * Sets the collision distance in the Transmit Control register
  2908. *
  2909. * hw - Struct containing variables accessed by shared code
  2910. *
  2911. * Link should have been established previously. Reads the speed and duplex
  2912. * information from the Device Status register.
  2913. ******************************************************************************/
  2914. static void
  2915. e1000_config_collision_dist(struct e1000_hw *hw)
  2916. {
  2917. uint32_t tctl, coll_dist;
  2918. DEBUGFUNC();
  2919. if (hw->mac_type < e1000_82543)
  2920. coll_dist = E1000_COLLISION_DISTANCE_82542;
  2921. else
  2922. coll_dist = E1000_COLLISION_DISTANCE;
  2923. tctl = E1000_READ_REG(hw, TCTL);
  2924. tctl &= ~E1000_TCTL_COLD;
  2925. tctl |= coll_dist << E1000_COLD_SHIFT;
  2926. E1000_WRITE_REG(hw, TCTL, tctl);
  2927. E1000_WRITE_FLUSH(hw);
  2928. }
  2929. /******************************************************************************
  2930. * Sets MAC speed and duplex settings to reflect the those in the PHY
  2931. *
  2932. * hw - Struct containing variables accessed by shared code
  2933. * mii_reg - data to write to the MII control register
  2934. *
  2935. * The contents of the PHY register containing the needed information need to
  2936. * be passed in.
  2937. ******************************************************************************/
  2938. static int
  2939. e1000_config_mac_to_phy(struct e1000_hw *hw)
  2940. {
  2941. uint32_t ctrl;
  2942. uint16_t phy_data;
  2943. DEBUGFUNC();
  2944. /* Read the Device Control Register and set the bits to Force Speed
  2945. * and Duplex.
  2946. */
  2947. ctrl = E1000_READ_REG(hw, CTRL);
  2948. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  2949. ctrl &= ~(E1000_CTRL_ILOS);
  2950. ctrl |= (E1000_CTRL_SPD_SEL);
  2951. /* Set up duplex in the Device Control and Transmit Control
  2952. * registers depending on negotiated values.
  2953. */
  2954. if (e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data) < 0) {
  2955. DEBUGOUT("PHY Read Error\n");
  2956. return -E1000_ERR_PHY;
  2957. }
  2958. if (phy_data & M88E1000_PSSR_DPLX)
  2959. ctrl |= E1000_CTRL_FD;
  2960. else
  2961. ctrl &= ~E1000_CTRL_FD;
  2962. e1000_config_collision_dist(hw);
  2963. /* Set up speed in the Device Control register depending on
  2964. * negotiated values.
  2965. */
  2966. if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
  2967. ctrl |= E1000_CTRL_SPD_1000;
  2968. else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
  2969. ctrl |= E1000_CTRL_SPD_100;
  2970. /* Write the configured values back to the Device Control Reg. */
  2971. E1000_WRITE_REG(hw, CTRL, ctrl);
  2972. return 0;
  2973. }
  2974. /******************************************************************************
  2975. * Forces the MAC's flow control settings.
  2976. *
  2977. * hw - Struct containing variables accessed by shared code
  2978. *
  2979. * Sets the TFCE and RFCE bits in the device control register to reflect
  2980. * the adapter settings. TFCE and RFCE need to be explicitly set by
  2981. * software when a Copper PHY is used because autonegotiation is managed
  2982. * by the PHY rather than the MAC. Software must also configure these
  2983. * bits when link is forced on a fiber connection.
  2984. *****************************************************************************/
  2985. static int
  2986. e1000_force_mac_fc(struct e1000_hw *hw)
  2987. {
  2988. uint32_t ctrl;
  2989. DEBUGFUNC();
  2990. /* Get the current configuration of the Device Control Register */
  2991. ctrl = E1000_READ_REG(hw, CTRL);
  2992. /* Because we didn't get link via the internal auto-negotiation
  2993. * mechanism (we either forced link or we got link via PHY
  2994. * auto-neg), we have to manually enable/disable transmit an
  2995. * receive flow control.
  2996. *
  2997. * The "Case" statement below enables/disable flow control
  2998. * according to the "hw->fc" parameter.
  2999. *
  3000. * The possible values of the "fc" parameter are:
  3001. * 0: Flow control is completely disabled
  3002. * 1: Rx flow control is enabled (we can receive pause
  3003. * frames but not send pause frames).
  3004. * 2: Tx flow control is enabled (we can send pause frames
  3005. * frames but we do not receive pause frames).
  3006. * 3: Both Rx and TX flow control (symmetric) is enabled.
  3007. * other: No other values should be possible at this point.
  3008. */
  3009. switch (hw->fc) {
  3010. case e1000_fc_none:
  3011. ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
  3012. break;
  3013. case e1000_fc_rx_pause:
  3014. ctrl &= (~E1000_CTRL_TFCE);
  3015. ctrl |= E1000_CTRL_RFCE;
  3016. break;
  3017. case e1000_fc_tx_pause:
  3018. ctrl &= (~E1000_CTRL_RFCE);
  3019. ctrl |= E1000_CTRL_TFCE;
  3020. break;
  3021. case e1000_fc_full:
  3022. ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
  3023. break;
  3024. default:
  3025. DEBUGOUT("Flow control param set incorrectly\n");
  3026. return -E1000_ERR_CONFIG;
  3027. }
  3028. /* Disable TX Flow Control for 82542 (rev 2.0) */
  3029. if (hw->mac_type == e1000_82542_rev2_0)
  3030. ctrl &= (~E1000_CTRL_TFCE);
  3031. E1000_WRITE_REG(hw, CTRL, ctrl);
  3032. return 0;
  3033. }
  3034. /******************************************************************************
  3035. * Configures flow control settings after link is established
  3036. *
  3037. * hw - Struct containing variables accessed by shared code
  3038. *
  3039. * Should be called immediately after a valid link has been established.
  3040. * Forces MAC flow control settings if link was forced. When in MII/GMII mode
  3041. * and autonegotiation is enabled, the MAC flow control settings will be set
  3042. * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
  3043. * and RFCE bits will be automaticaly set to the negotiated flow control mode.
  3044. *****************************************************************************/
  3045. static int32_t
  3046. e1000_config_fc_after_link_up(struct e1000_hw *hw)
  3047. {
  3048. int32_t ret_val;
  3049. uint16_t mii_status_reg;
  3050. uint16_t mii_nway_adv_reg;
  3051. uint16_t mii_nway_lp_ability_reg;
  3052. uint16_t speed;
  3053. uint16_t duplex;
  3054. DEBUGFUNC();
  3055. /* Check for the case where we have fiber media and auto-neg failed
  3056. * so we had to force link. In this case, we need to force the
  3057. * configuration of the MAC to match the "fc" parameter.
  3058. */
  3059. if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed))
  3060. || ((hw->media_type == e1000_media_type_internal_serdes)
  3061. && (hw->autoneg_failed))
  3062. || ((hw->media_type == e1000_media_type_copper)
  3063. && (!hw->autoneg))) {
  3064. ret_val = e1000_force_mac_fc(hw);
  3065. if (ret_val < 0) {
  3066. DEBUGOUT("Error forcing flow control settings\n");
  3067. return ret_val;
  3068. }
  3069. }
  3070. /* Check for the case where we have copper media and auto-neg is
  3071. * enabled. In this case, we need to check and see if Auto-Neg
  3072. * has completed, and if so, how the PHY and link partner has
  3073. * flow control configured.
  3074. */
  3075. if (hw->media_type == e1000_media_type_copper) {
  3076. /* Read the MII Status Register and check to see if AutoNeg
  3077. * has completed. We read this twice because this reg has
  3078. * some "sticky" (latched) bits.
  3079. */
  3080. if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
  3081. DEBUGOUT("PHY Read Error\n");
  3082. return -E1000_ERR_PHY;
  3083. }
  3084. if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
  3085. DEBUGOUT("PHY Read Error\n");
  3086. return -E1000_ERR_PHY;
  3087. }
  3088. if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
  3089. /* The AutoNeg process has completed, so we now need to
  3090. * read both the Auto Negotiation Advertisement Register
  3091. * (Address 4) and the Auto_Negotiation Base Page Ability
  3092. * Register (Address 5) to determine how flow control was
  3093. * negotiated.
  3094. */
  3095. if (e1000_read_phy_reg
  3096. (hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg) < 0) {
  3097. DEBUGOUT("PHY Read Error\n");
  3098. return -E1000_ERR_PHY;
  3099. }
  3100. if (e1000_read_phy_reg
  3101. (hw, PHY_LP_ABILITY,
  3102. &mii_nway_lp_ability_reg) < 0) {
  3103. DEBUGOUT("PHY Read Error\n");
  3104. return -E1000_ERR_PHY;
  3105. }
  3106. /* Two bits in the Auto Negotiation Advertisement Register
  3107. * (Address 4) and two bits in the Auto Negotiation Base
  3108. * Page Ability Register (Address 5) determine flow control
  3109. * for both the PHY and the link partner. The following
  3110. * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
  3111. * 1999, describes these PAUSE resolution bits and how flow
  3112. * control is determined based upon these settings.
  3113. * NOTE: DC = Don't Care
  3114. *
  3115. * LOCAL DEVICE | LINK PARTNER
  3116. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
  3117. *-------|---------|-------|---------|--------------------
  3118. * 0 | 0 | DC | DC | e1000_fc_none
  3119. * 0 | 1 | 0 | DC | e1000_fc_none
  3120. * 0 | 1 | 1 | 0 | e1000_fc_none
  3121. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  3122. * 1 | 0 | 0 | DC | e1000_fc_none
  3123. * 1 | DC | 1 | DC | e1000_fc_full
  3124. * 1 | 1 | 0 | 0 | e1000_fc_none
  3125. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  3126. *
  3127. */
  3128. /* Are both PAUSE bits set to 1? If so, this implies
  3129. * Symmetric Flow Control is enabled at both ends. The
  3130. * ASM_DIR bits are irrelevant per the spec.
  3131. *
  3132. * For Symmetric Flow Control:
  3133. *
  3134. * LOCAL DEVICE | LINK PARTNER
  3135. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  3136. *-------|---------|-------|---------|--------------------
  3137. * 1 | DC | 1 | DC | e1000_fc_full
  3138. *
  3139. */
  3140. if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  3141. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
  3142. /* Now we need to check if the user selected RX ONLY
  3143. * of pause frames. In this case, we had to advertise
  3144. * FULL flow control because we could not advertise RX
  3145. * ONLY. Hence, we must now check to see if we need to
  3146. * turn OFF the TRANSMISSION of PAUSE frames.
  3147. */
  3148. if (hw->original_fc == e1000_fc_full) {
  3149. hw->fc = e1000_fc_full;
  3150. DEBUGOUT("Flow Control = FULL.\r\n");
  3151. } else {
  3152. hw->fc = e1000_fc_rx_pause;
  3153. DEBUGOUT
  3154. ("Flow Control = RX PAUSE frames only.\r\n");
  3155. }
  3156. }
  3157. /* For receiving PAUSE frames ONLY.
  3158. *
  3159. * LOCAL DEVICE | LINK PARTNER
  3160. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  3161. *-------|---------|-------|---------|--------------------
  3162. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  3163. *
  3164. */
  3165. else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  3166. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  3167. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  3168. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
  3169. {
  3170. hw->fc = e1000_fc_tx_pause;
  3171. DEBUGOUT
  3172. ("Flow Control = TX PAUSE frames only.\r\n");
  3173. }
  3174. /* For transmitting PAUSE frames ONLY.
  3175. *
  3176. * LOCAL DEVICE | LINK PARTNER
  3177. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  3178. *-------|---------|-------|---------|--------------------
  3179. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  3180. *
  3181. */
  3182. else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  3183. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  3184. !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  3185. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
  3186. {
  3187. hw->fc = e1000_fc_rx_pause;
  3188. DEBUGOUT
  3189. ("Flow Control = RX PAUSE frames only.\r\n");
  3190. }
  3191. /* Per the IEEE spec, at this point flow control should be
  3192. * disabled. However, we want to consider that we could
  3193. * be connected to a legacy switch that doesn't advertise
  3194. * desired flow control, but can be forced on the link
  3195. * partner. So if we advertised no flow control, that is
  3196. * what we will resolve to. If we advertised some kind of
  3197. * receive capability (Rx Pause Only or Full Flow Control)
  3198. * and the link partner advertised none, we will configure
  3199. * ourselves to enable Rx Flow Control only. We can do
  3200. * this safely for two reasons: If the link partner really
  3201. * didn't want flow control enabled, and we enable Rx, no
  3202. * harm done since we won't be receiving any PAUSE frames
  3203. * anyway. If the intent on the link partner was to have
  3204. * flow control enabled, then by us enabling RX only, we
  3205. * can at least receive pause frames and process them.
  3206. * This is a good idea because in most cases, since we are
  3207. * predominantly a server NIC, more times than not we will
  3208. * be asked to delay transmission of packets than asking
  3209. * our link partner to pause transmission of frames.
  3210. */
  3211. else if (hw->original_fc == e1000_fc_none ||
  3212. hw->original_fc == e1000_fc_tx_pause) {
  3213. hw->fc = e1000_fc_none;
  3214. DEBUGOUT("Flow Control = NONE.\r\n");
  3215. } else {
  3216. hw->fc = e1000_fc_rx_pause;
  3217. DEBUGOUT
  3218. ("Flow Control = RX PAUSE frames only.\r\n");
  3219. }
  3220. /* Now we need to do one last check... If we auto-
  3221. * negotiated to HALF DUPLEX, flow control should not be
  3222. * enabled per IEEE 802.3 spec.
  3223. */
  3224. e1000_get_speed_and_duplex(hw, &speed, &duplex);
  3225. if (duplex == HALF_DUPLEX)
  3226. hw->fc = e1000_fc_none;
  3227. /* Now we call a subroutine to actually force the MAC
  3228. * controller to use the correct flow control settings.
  3229. */
  3230. ret_val = e1000_force_mac_fc(hw);
  3231. if (ret_val < 0) {
  3232. DEBUGOUT
  3233. ("Error forcing flow control settings\n");
  3234. return ret_val;
  3235. }
  3236. } else {
  3237. DEBUGOUT
  3238. ("Copper PHY and Auto Neg has not completed.\r\n");
  3239. }
  3240. }
  3241. return E1000_SUCCESS;
  3242. }
  3243. /******************************************************************************
  3244. * Checks to see if the link status of the hardware has changed.
  3245. *
  3246. * hw - Struct containing variables accessed by shared code
  3247. *
  3248. * Called by any function that needs to check the link status of the adapter.
  3249. *****************************************************************************/
  3250. static int
  3251. e1000_check_for_link(struct eth_device *nic)
  3252. {
  3253. struct e1000_hw *hw = nic->priv;
  3254. uint32_t rxcw;
  3255. uint32_t ctrl;
  3256. uint32_t status;
  3257. uint32_t rctl;
  3258. uint32_t signal;
  3259. int32_t ret_val;
  3260. uint16_t phy_data;
  3261. uint16_t lp_capability;
  3262. DEBUGFUNC();
  3263. /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
  3264. * set when the optics detect a signal. On older adapters, it will be
  3265. * cleared when there is a signal
  3266. */
  3267. ctrl = E1000_READ_REG(hw, CTRL);
  3268. if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
  3269. signal = E1000_CTRL_SWDPIN1;
  3270. else
  3271. signal = 0;
  3272. status = E1000_READ_REG(hw, STATUS);
  3273. rxcw = E1000_READ_REG(hw, RXCW);
  3274. DEBUGOUT("ctrl: %#08x status %#08x rxcw %#08x\n", ctrl, status, rxcw);
  3275. /* If we have a copper PHY then we only want to go out to the PHY
  3276. * registers to see if Auto-Neg has completed and/or if our link
  3277. * status has changed. The get_link_status flag will be set if we
  3278. * receive a Link Status Change interrupt or we have Rx Sequence
  3279. * Errors.
  3280. */
  3281. if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
  3282. /* First we want to see if the MII Status Register reports
  3283. * link. If so, then we want to get the current speed/duplex
  3284. * of the PHY.
  3285. * Read the register twice since the link bit is sticky.
  3286. */
  3287. if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
  3288. DEBUGOUT("PHY Read Error\n");
  3289. return -E1000_ERR_PHY;
  3290. }
  3291. if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
  3292. DEBUGOUT("PHY Read Error\n");
  3293. return -E1000_ERR_PHY;
  3294. }
  3295. if (phy_data & MII_SR_LINK_STATUS) {
  3296. hw->get_link_status = false;
  3297. } else {
  3298. /* No link detected */
  3299. return -E1000_ERR_NOLINK;
  3300. }
  3301. /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
  3302. * have Si on board that is 82544 or newer, Auto
  3303. * Speed Detection takes care of MAC speed/duplex
  3304. * configuration. So we only need to configure Collision
  3305. * Distance in the MAC. Otherwise, we need to force
  3306. * speed/duplex on the MAC to the current PHY speed/duplex
  3307. * settings.
  3308. */
  3309. if (hw->mac_type >= e1000_82544)
  3310. e1000_config_collision_dist(hw);
  3311. else {
  3312. ret_val = e1000_config_mac_to_phy(hw);
  3313. if (ret_val < 0) {
  3314. DEBUGOUT
  3315. ("Error configuring MAC to PHY settings\n");
  3316. return ret_val;
  3317. }
  3318. }
  3319. /* Configure Flow Control now that Auto-Neg has completed. First, we
  3320. * need to restore the desired flow control settings because we may
  3321. * have had to re-autoneg with a different link partner.
  3322. */
  3323. ret_val = e1000_config_fc_after_link_up(hw);
  3324. if (ret_val < 0) {
  3325. DEBUGOUT("Error configuring flow control\n");
  3326. return ret_val;
  3327. }
  3328. /* At this point we know that we are on copper and we have
  3329. * auto-negotiated link. These are conditions for checking the link
  3330. * parter capability register. We use the link partner capability to
  3331. * determine if TBI Compatibility needs to be turned on or off. If
  3332. * the link partner advertises any speed in addition to Gigabit, then
  3333. * we assume that they are GMII-based, and TBI compatibility is not
  3334. * needed. If no other speeds are advertised, we assume the link
  3335. * partner is TBI-based, and we turn on TBI Compatibility.
  3336. */
  3337. if (hw->tbi_compatibility_en) {
  3338. if (e1000_read_phy_reg
  3339. (hw, PHY_LP_ABILITY, &lp_capability) < 0) {
  3340. DEBUGOUT("PHY Read Error\n");
  3341. return -E1000_ERR_PHY;
  3342. }
  3343. if (lp_capability & (NWAY_LPAR_10T_HD_CAPS |
  3344. NWAY_LPAR_10T_FD_CAPS |
  3345. NWAY_LPAR_100TX_HD_CAPS |
  3346. NWAY_LPAR_100TX_FD_CAPS |
  3347. NWAY_LPAR_100T4_CAPS)) {
  3348. /* If our link partner advertises anything in addition to
  3349. * gigabit, we do not need to enable TBI compatibility.
  3350. */
  3351. if (hw->tbi_compatibility_on) {
  3352. /* If we previously were in the mode, turn it off. */
  3353. rctl = E1000_READ_REG(hw, RCTL);
  3354. rctl &= ~E1000_RCTL_SBP;
  3355. E1000_WRITE_REG(hw, RCTL, rctl);
  3356. hw->tbi_compatibility_on = false;
  3357. }
  3358. } else {
  3359. /* If TBI compatibility is was previously off, turn it on. For
  3360. * compatibility with a TBI link partner, we will store bad
  3361. * packets. Some frames have an additional byte on the end and
  3362. * will look like CRC errors to to the hardware.
  3363. */
  3364. if (!hw->tbi_compatibility_on) {
  3365. hw->tbi_compatibility_on = true;
  3366. rctl = E1000_READ_REG(hw, RCTL);
  3367. rctl |= E1000_RCTL_SBP;
  3368. E1000_WRITE_REG(hw, RCTL, rctl);
  3369. }
  3370. }
  3371. }
  3372. }
  3373. /* If we don't have link (auto-negotiation failed or link partner cannot
  3374. * auto-negotiate), the cable is plugged in (we have signal), and our
  3375. * link partner is not trying to auto-negotiate with us (we are receiving
  3376. * idles or data), we need to force link up. We also need to give
  3377. * auto-negotiation time to complete, in case the cable was just plugged
  3378. * in. The autoneg_failed flag does this.
  3379. */
  3380. else if ((hw->media_type == e1000_media_type_fiber) &&
  3381. (!(status & E1000_STATUS_LU)) &&
  3382. ((ctrl & E1000_CTRL_SWDPIN1) == signal) &&
  3383. (!(rxcw & E1000_RXCW_C))) {
  3384. if (hw->autoneg_failed == 0) {
  3385. hw->autoneg_failed = 1;
  3386. return 0;
  3387. }
  3388. DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
  3389. /* Disable auto-negotiation in the TXCW register */
  3390. E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
  3391. /* Force link-up and also force full-duplex. */
  3392. ctrl = E1000_READ_REG(hw, CTRL);
  3393. ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
  3394. E1000_WRITE_REG(hw, CTRL, ctrl);
  3395. /* Configure Flow Control after forcing link up. */
  3396. ret_val = e1000_config_fc_after_link_up(hw);
  3397. if (ret_val < 0) {
  3398. DEBUGOUT("Error configuring flow control\n");
  3399. return ret_val;
  3400. }
  3401. }
  3402. /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
  3403. * auto-negotiation in the TXCW register and disable forced link in the
  3404. * Device Control register in an attempt to auto-negotiate with our link
  3405. * partner.
  3406. */
  3407. else if ((hw->media_type == e1000_media_type_fiber) &&
  3408. (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
  3409. DEBUGOUT
  3410. ("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
  3411. E1000_WRITE_REG(hw, TXCW, hw->txcw);
  3412. E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
  3413. }
  3414. return 0;
  3415. }
  3416. /******************************************************************************
  3417. * Configure the MAC-to-PHY interface for 10/100Mbps
  3418. *
  3419. * hw - Struct containing variables accessed by shared code
  3420. ******************************************************************************/
  3421. static int32_t
  3422. e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
  3423. {
  3424. int32_t ret_val = E1000_SUCCESS;
  3425. uint32_t tipg;
  3426. uint16_t reg_data;
  3427. DEBUGFUNC();
  3428. reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
  3429. ret_val = e1000_write_kmrn_reg(hw,
  3430. E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data);
  3431. if (ret_val)
  3432. return ret_val;
  3433. /* Configure Transmit Inter-Packet Gap */
  3434. tipg = E1000_READ_REG(hw, TIPG);
  3435. tipg &= ~E1000_TIPG_IPGT_MASK;
  3436. tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
  3437. E1000_WRITE_REG(hw, TIPG, tipg);
  3438. ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
  3439. if (ret_val)
  3440. return ret_val;
  3441. if (duplex == HALF_DUPLEX)
  3442. reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
  3443. else
  3444. reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
  3445. ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
  3446. return ret_val;
  3447. }
  3448. static int32_t
  3449. e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
  3450. {
  3451. int32_t ret_val = E1000_SUCCESS;
  3452. uint16_t reg_data;
  3453. uint32_t tipg;
  3454. DEBUGFUNC();
  3455. reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
  3456. ret_val = e1000_write_kmrn_reg(hw,
  3457. E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data);
  3458. if (ret_val)
  3459. return ret_val;
  3460. /* Configure Transmit Inter-Packet Gap */
  3461. tipg = E1000_READ_REG(hw, TIPG);
  3462. tipg &= ~E1000_TIPG_IPGT_MASK;
  3463. tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
  3464. E1000_WRITE_REG(hw, TIPG, tipg);
  3465. ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
  3466. if (ret_val)
  3467. return ret_val;
  3468. reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
  3469. ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
  3470. return ret_val;
  3471. }
  3472. /******************************************************************************
  3473. * Detects the current speed and duplex settings of the hardware.
  3474. *
  3475. * hw - Struct containing variables accessed by shared code
  3476. * speed - Speed of the connection
  3477. * duplex - Duplex setting of the connection
  3478. *****************************************************************************/
  3479. static int
  3480. e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t *speed,
  3481. uint16_t *duplex)
  3482. {
  3483. uint32_t status;
  3484. int32_t ret_val;
  3485. uint16_t phy_data;
  3486. DEBUGFUNC();
  3487. if (hw->mac_type >= e1000_82543) {
  3488. status = E1000_READ_REG(hw, STATUS);
  3489. if (status & E1000_STATUS_SPEED_1000) {
  3490. *speed = SPEED_1000;
  3491. DEBUGOUT("1000 Mbs, ");
  3492. } else if (status & E1000_STATUS_SPEED_100) {
  3493. *speed = SPEED_100;
  3494. DEBUGOUT("100 Mbs, ");
  3495. } else {
  3496. *speed = SPEED_10;
  3497. DEBUGOUT("10 Mbs, ");
  3498. }
  3499. if (status & E1000_STATUS_FD) {
  3500. *duplex = FULL_DUPLEX;
  3501. DEBUGOUT("Full Duplex\r\n");
  3502. } else {
  3503. *duplex = HALF_DUPLEX;
  3504. DEBUGOUT(" Half Duplex\r\n");
  3505. }
  3506. } else {
  3507. DEBUGOUT("1000 Mbs, Full Duplex\r\n");
  3508. *speed = SPEED_1000;
  3509. *duplex = FULL_DUPLEX;
  3510. }
  3511. /* IGP01 PHY may advertise full duplex operation after speed downgrade
  3512. * even if it is operating at half duplex. Here we set the duplex
  3513. * settings to match the duplex in the link partner's capabilities.
  3514. */
  3515. if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
  3516. ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
  3517. if (ret_val)
  3518. return ret_val;
  3519. if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
  3520. *duplex = HALF_DUPLEX;
  3521. else {
  3522. ret_val = e1000_read_phy_reg(hw,
  3523. PHY_LP_ABILITY, &phy_data);
  3524. if (ret_val)
  3525. return ret_val;
  3526. if ((*speed == SPEED_100 &&
  3527. !(phy_data & NWAY_LPAR_100TX_FD_CAPS))
  3528. || (*speed == SPEED_10
  3529. && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
  3530. *duplex = HALF_DUPLEX;
  3531. }
  3532. }
  3533. if ((hw->mac_type == e1000_80003es2lan) &&
  3534. (hw->media_type == e1000_media_type_copper)) {
  3535. if (*speed == SPEED_1000)
  3536. ret_val = e1000_configure_kmrn_for_1000(hw);
  3537. else
  3538. ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
  3539. if (ret_val)
  3540. return ret_val;
  3541. }
  3542. return E1000_SUCCESS;
  3543. }
  3544. /******************************************************************************
  3545. * Blocks until autoneg completes or times out (~4.5 seconds)
  3546. *
  3547. * hw - Struct containing variables accessed by shared code
  3548. ******************************************************************************/
  3549. static int
  3550. e1000_wait_autoneg(struct e1000_hw *hw)
  3551. {
  3552. uint16_t i;
  3553. uint16_t phy_data;
  3554. DEBUGFUNC();
  3555. DEBUGOUT("Waiting for Auto-Neg to complete.\n");
  3556. /* We will wait for autoneg to complete or timeout to expire. */
  3557. for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
  3558. /* Read the MII Status Register and wait for Auto-Neg
  3559. * Complete bit to be set.
  3560. */
  3561. if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
  3562. DEBUGOUT("PHY Read Error\n");
  3563. return -E1000_ERR_PHY;
  3564. }
  3565. if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
  3566. DEBUGOUT("PHY Read Error\n");
  3567. return -E1000_ERR_PHY;
  3568. }
  3569. if (phy_data & MII_SR_AUTONEG_COMPLETE) {
  3570. DEBUGOUT("Auto-Neg complete.\n");
  3571. return 0;
  3572. }
  3573. mdelay(100);
  3574. }
  3575. DEBUGOUT("Auto-Neg timedout.\n");
  3576. return -E1000_ERR_TIMEOUT;
  3577. }
  3578. /******************************************************************************
  3579. * Raises the Management Data Clock
  3580. *
  3581. * hw - Struct containing variables accessed by shared code
  3582. * ctrl - Device control register's current value
  3583. ******************************************************************************/
  3584. static void
  3585. e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
  3586. {
  3587. /* Raise the clock input to the Management Data Clock (by setting the MDC
  3588. * bit), and then delay 2 microseconds.
  3589. */
  3590. E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
  3591. E1000_WRITE_FLUSH(hw);
  3592. udelay(2);
  3593. }
  3594. /******************************************************************************
  3595. * Lowers the Management Data Clock
  3596. *
  3597. * hw - Struct containing variables accessed by shared code
  3598. * ctrl - Device control register's current value
  3599. ******************************************************************************/
  3600. static void
  3601. e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
  3602. {
  3603. /* Lower the clock input to the Management Data Clock (by clearing the MDC
  3604. * bit), and then delay 2 microseconds.
  3605. */
  3606. E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
  3607. E1000_WRITE_FLUSH(hw);
  3608. udelay(2);
  3609. }
  3610. /******************************************************************************
  3611. * Shifts data bits out to the PHY
  3612. *
  3613. * hw - Struct containing variables accessed by shared code
  3614. * data - Data to send out to the PHY
  3615. * count - Number of bits to shift out
  3616. *
  3617. * Bits are shifted out in MSB to LSB order.
  3618. ******************************************************************************/
  3619. static void
  3620. e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data, uint16_t count)
  3621. {
  3622. uint32_t ctrl;
  3623. uint32_t mask;
  3624. /* We need to shift "count" number of bits out to the PHY. So, the value
  3625. * in the "data" parameter will be shifted out to the PHY one bit at a
  3626. * time. In order to do this, "data" must be broken down into bits.
  3627. */
  3628. mask = 0x01;
  3629. mask <<= (count - 1);
  3630. ctrl = E1000_READ_REG(hw, CTRL);
  3631. /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
  3632. ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
  3633. while (mask) {
  3634. /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
  3635. * then raising and lowering the Management Data Clock. A "0" is
  3636. * shifted out to the PHY by setting the MDIO bit to "0" and then
  3637. * raising and lowering the clock.
  3638. */
  3639. if (data & mask)
  3640. ctrl |= E1000_CTRL_MDIO;
  3641. else
  3642. ctrl &= ~E1000_CTRL_MDIO;
  3643. E1000_WRITE_REG(hw, CTRL, ctrl);
  3644. E1000_WRITE_FLUSH(hw);
  3645. udelay(2);
  3646. e1000_raise_mdi_clk(hw, &ctrl);
  3647. e1000_lower_mdi_clk(hw, &ctrl);
  3648. mask = mask >> 1;
  3649. }
  3650. }
  3651. /******************************************************************************
  3652. * Shifts data bits in from the PHY
  3653. *
  3654. * hw - Struct containing variables accessed by shared code
  3655. *
  3656. * Bits are shifted in in MSB to LSB order.
  3657. ******************************************************************************/
  3658. static uint16_t
  3659. e1000_shift_in_mdi_bits(struct e1000_hw *hw)
  3660. {
  3661. uint32_t ctrl;
  3662. uint16_t data = 0;
  3663. uint8_t i;
  3664. /* In order to read a register from the PHY, we need to shift in a total
  3665. * of 18 bits from the PHY. The first two bit (turnaround) times are used
  3666. * to avoid contention on the MDIO pin when a read operation is performed.
  3667. * These two bits are ignored by us and thrown away. Bits are "shifted in"
  3668. * by raising the input to the Management Data Clock (setting the MDC bit),
  3669. * and then reading the value of the MDIO bit.
  3670. */
  3671. ctrl = E1000_READ_REG(hw, CTRL);
  3672. /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
  3673. ctrl &= ~E1000_CTRL_MDIO_DIR;
  3674. ctrl &= ~E1000_CTRL_MDIO;
  3675. E1000_WRITE_REG(hw, CTRL, ctrl);
  3676. E1000_WRITE_FLUSH(hw);
  3677. /* Raise and Lower the clock before reading in the data. This accounts for
  3678. * the turnaround bits. The first clock occurred when we clocked out the
  3679. * last bit of the Register Address.
  3680. */
  3681. e1000_raise_mdi_clk(hw, &ctrl);
  3682. e1000_lower_mdi_clk(hw, &ctrl);
  3683. for (data = 0, i = 0; i < 16; i++) {
  3684. data = data << 1;
  3685. e1000_raise_mdi_clk(hw, &ctrl);
  3686. ctrl = E1000_READ_REG(hw, CTRL);
  3687. /* Check to see if we shifted in a "1". */
  3688. if (ctrl & E1000_CTRL_MDIO)
  3689. data |= 1;
  3690. e1000_lower_mdi_clk(hw, &ctrl);
  3691. }
  3692. e1000_raise_mdi_clk(hw, &ctrl);
  3693. e1000_lower_mdi_clk(hw, &ctrl);
  3694. return data;
  3695. }
  3696. /*****************************************************************************
  3697. * Reads the value from a PHY register
  3698. *
  3699. * hw - Struct containing variables accessed by shared code
  3700. * reg_addr - address of the PHY register to read
  3701. ******************************************************************************/
  3702. static int
  3703. e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t * phy_data)
  3704. {
  3705. uint32_t i;
  3706. uint32_t mdic = 0;
  3707. const uint32_t phy_addr = 1;
  3708. if (reg_addr > MAX_PHY_REG_ADDRESS) {
  3709. DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
  3710. return -E1000_ERR_PARAM;
  3711. }
  3712. if (hw->mac_type > e1000_82543) {
  3713. /* Set up Op-code, Phy Address, and register address in the MDI
  3714. * Control register. The MAC will take care of interfacing with the
  3715. * PHY to retrieve the desired data.
  3716. */
  3717. mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
  3718. (phy_addr << E1000_MDIC_PHY_SHIFT) |
  3719. (E1000_MDIC_OP_READ));
  3720. E1000_WRITE_REG(hw, MDIC, mdic);
  3721. /* Poll the ready bit to see if the MDI read completed */
  3722. for (i = 0; i < 64; i++) {
  3723. udelay(10);
  3724. mdic = E1000_READ_REG(hw, MDIC);
  3725. if (mdic & E1000_MDIC_READY)
  3726. break;
  3727. }
  3728. if (!(mdic & E1000_MDIC_READY)) {
  3729. DEBUGOUT("MDI Read did not complete\n");
  3730. return -E1000_ERR_PHY;
  3731. }
  3732. if (mdic & E1000_MDIC_ERROR) {
  3733. DEBUGOUT("MDI Error\n");
  3734. return -E1000_ERR_PHY;
  3735. }
  3736. *phy_data = (uint16_t) mdic;
  3737. } else {
  3738. /* We must first send a preamble through the MDIO pin to signal the
  3739. * beginning of an MII instruction. This is done by sending 32
  3740. * consecutive "1" bits.
  3741. */
  3742. e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
  3743. /* Now combine the next few fields that are required for a read
  3744. * operation. We use this method instead of calling the
  3745. * e1000_shift_out_mdi_bits routine five different times. The format of
  3746. * a MII read instruction consists of a shift out of 14 bits and is
  3747. * defined as follows:
  3748. * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
  3749. * followed by a shift in of 18 bits. This first two bits shifted in
  3750. * are TurnAround bits used to avoid contention on the MDIO pin when a
  3751. * READ operation is performed. These two bits are thrown away
  3752. * followed by a shift in of 16 bits which contains the desired data.
  3753. */
  3754. mdic = ((reg_addr) | (phy_addr << 5) |
  3755. (PHY_OP_READ << 10) | (PHY_SOF << 12));
  3756. e1000_shift_out_mdi_bits(hw, mdic, 14);
  3757. /* Now that we've shifted out the read command to the MII, we need to
  3758. * "shift in" the 16-bit value (18 total bits) of the requested PHY
  3759. * register address.
  3760. */
  3761. *phy_data = e1000_shift_in_mdi_bits(hw);
  3762. }
  3763. return 0;
  3764. }
  3765. /******************************************************************************
  3766. * Writes a value to a PHY register
  3767. *
  3768. * hw - Struct containing variables accessed by shared code
  3769. * reg_addr - address of the PHY register to write
  3770. * data - data to write to the PHY
  3771. ******************************************************************************/
  3772. static int
  3773. e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t phy_data)
  3774. {
  3775. uint32_t i;
  3776. uint32_t mdic = 0;
  3777. const uint32_t phy_addr = 1;
  3778. if (reg_addr > MAX_PHY_REG_ADDRESS) {
  3779. DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
  3780. return -E1000_ERR_PARAM;
  3781. }
  3782. if (hw->mac_type > e1000_82543) {
  3783. /* Set up Op-code, Phy Address, register address, and data intended
  3784. * for the PHY register in the MDI Control register. The MAC will take
  3785. * care of interfacing with the PHY to send the desired data.
  3786. */
  3787. mdic = (((uint32_t) phy_data) |
  3788. (reg_addr << E1000_MDIC_REG_SHIFT) |
  3789. (phy_addr << E1000_MDIC_PHY_SHIFT) |
  3790. (E1000_MDIC_OP_WRITE));
  3791. E1000_WRITE_REG(hw, MDIC, mdic);
  3792. /* Poll the ready bit to see if the MDI read completed */
  3793. for (i = 0; i < 64; i++) {
  3794. udelay(10);
  3795. mdic = E1000_READ_REG(hw, MDIC);
  3796. if (mdic & E1000_MDIC_READY)
  3797. break;
  3798. }
  3799. if (!(mdic & E1000_MDIC_READY)) {
  3800. DEBUGOUT("MDI Write did not complete\n");
  3801. return -E1000_ERR_PHY;
  3802. }
  3803. } else {
  3804. /* We'll need to use the SW defined pins to shift the write command
  3805. * out to the PHY. We first send a preamble to the PHY to signal the
  3806. * beginning of the MII instruction. This is done by sending 32
  3807. * consecutive "1" bits.
  3808. */
  3809. e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
  3810. /* Now combine the remaining required fields that will indicate a
  3811. * write operation. We use this method instead of calling the
  3812. * e1000_shift_out_mdi_bits routine for each field in the command. The
  3813. * format of a MII write instruction is as follows:
  3814. * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
  3815. */
  3816. mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
  3817. (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
  3818. mdic <<= 16;
  3819. mdic |= (uint32_t) phy_data;
  3820. e1000_shift_out_mdi_bits(hw, mdic, 32);
  3821. }
  3822. return 0;
  3823. }
  3824. /******************************************************************************
  3825. * Checks if PHY reset is blocked due to SOL/IDER session, for example.
  3826. * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
  3827. * the caller to figure out how to deal with it.
  3828. *
  3829. * hw - Struct containing variables accessed by shared code
  3830. *
  3831. * returns: - E1000_BLK_PHY_RESET
  3832. * E1000_SUCCESS
  3833. *
  3834. *****************************************************************************/
  3835. int32_t
  3836. e1000_check_phy_reset_block(struct e1000_hw *hw)
  3837. {
  3838. uint32_t manc = 0;
  3839. uint32_t fwsm = 0;
  3840. if (hw->mac_type == e1000_ich8lan) {
  3841. fwsm = E1000_READ_REG(hw, FWSM);
  3842. return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
  3843. : E1000_BLK_PHY_RESET;
  3844. }
  3845. if (hw->mac_type > e1000_82547_rev_2)
  3846. manc = E1000_READ_REG(hw, MANC);
  3847. return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
  3848. E1000_BLK_PHY_RESET : E1000_SUCCESS;
  3849. }
  3850. /***************************************************************************
  3851. * Checks if the PHY configuration is done
  3852. *
  3853. * hw: Struct containing variables accessed by shared code
  3854. *
  3855. * returns: - E1000_ERR_RESET if fail to reset MAC
  3856. * E1000_SUCCESS at any other case.
  3857. *
  3858. ***************************************************************************/
  3859. static int32_t
  3860. e1000_get_phy_cfg_done(struct e1000_hw *hw)
  3861. {
  3862. int32_t timeout = PHY_CFG_TIMEOUT;
  3863. uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
  3864. DEBUGFUNC();
  3865. switch (hw->mac_type) {
  3866. default:
  3867. mdelay(10);
  3868. break;
  3869. case e1000_80003es2lan:
  3870. /* Separate *_CFG_DONE_* bit for each port */
  3871. if (e1000_is_second_port(hw))
  3872. cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
  3873. /* Fall Through */
  3874. case e1000_82571:
  3875. case e1000_82572:
  3876. case e1000_igb:
  3877. while (timeout) {
  3878. if (hw->mac_type == e1000_igb) {
  3879. if (E1000_READ_REG(hw, I210_EEMNGCTL) & cfg_mask)
  3880. break;
  3881. } else {
  3882. if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
  3883. break;
  3884. }
  3885. mdelay(1);
  3886. timeout--;
  3887. }
  3888. if (!timeout) {
  3889. DEBUGOUT("MNG configuration cycle has not "
  3890. "completed.\n");
  3891. return -E1000_ERR_RESET;
  3892. }
  3893. break;
  3894. }
  3895. return E1000_SUCCESS;
  3896. }
  3897. /******************************************************************************
  3898. * Returns the PHY to the power-on reset state
  3899. *
  3900. * hw - Struct containing variables accessed by shared code
  3901. ******************************************************************************/
  3902. int32_t
  3903. e1000_phy_hw_reset(struct e1000_hw *hw)
  3904. {
  3905. uint16_t swfw = E1000_SWFW_PHY0_SM;
  3906. uint32_t ctrl, ctrl_ext;
  3907. uint32_t led_ctrl;
  3908. int32_t ret_val;
  3909. DEBUGFUNC();
  3910. /* In the case of the phy reset being blocked, it's not an error, we
  3911. * simply return success without performing the reset. */
  3912. ret_val = e1000_check_phy_reset_block(hw);
  3913. if (ret_val)
  3914. return E1000_SUCCESS;
  3915. DEBUGOUT("Resetting Phy...\n");
  3916. if (hw->mac_type > e1000_82543) {
  3917. if (e1000_is_second_port(hw))
  3918. swfw = E1000_SWFW_PHY1_SM;
  3919. if (e1000_swfw_sync_acquire(hw, swfw)) {
  3920. DEBUGOUT("Unable to acquire swfw sync\n");
  3921. return -E1000_ERR_SWFW_SYNC;
  3922. }
  3923. /* Read the device control register and assert the E1000_CTRL_PHY_RST
  3924. * bit. Then, take it out of reset.
  3925. */
  3926. ctrl = E1000_READ_REG(hw, CTRL);
  3927. E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
  3928. E1000_WRITE_FLUSH(hw);
  3929. if (hw->mac_type < e1000_82571)
  3930. udelay(10);
  3931. else
  3932. udelay(100);
  3933. E1000_WRITE_REG(hw, CTRL, ctrl);
  3934. E1000_WRITE_FLUSH(hw);
  3935. if (hw->mac_type >= e1000_82571)
  3936. mdelay(10);
  3937. } else {
  3938. /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
  3939. * bit to put the PHY into reset. Then, take it out of reset.
  3940. */
  3941. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  3942. ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
  3943. ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
  3944. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  3945. E1000_WRITE_FLUSH(hw);
  3946. mdelay(10);
  3947. ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
  3948. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  3949. E1000_WRITE_FLUSH(hw);
  3950. }
  3951. udelay(150);
  3952. if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  3953. /* Configure activity LED after PHY reset */
  3954. led_ctrl = E1000_READ_REG(hw, LEDCTL);
  3955. led_ctrl &= IGP_ACTIVITY_LED_MASK;
  3956. led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
  3957. E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
  3958. }
  3959. e1000_swfw_sync_release(hw, swfw);
  3960. /* Wait for FW to finish PHY configuration. */
  3961. ret_val = e1000_get_phy_cfg_done(hw);
  3962. if (ret_val != E1000_SUCCESS)
  3963. return ret_val;
  3964. return ret_val;
  3965. }
  3966. /******************************************************************************
  3967. * IGP phy init script - initializes the GbE PHY
  3968. *
  3969. * hw - Struct containing variables accessed by shared code
  3970. *****************************************************************************/
  3971. static void
  3972. e1000_phy_init_script(struct e1000_hw *hw)
  3973. {
  3974. uint32_t ret_val;
  3975. uint16_t phy_saved_data;
  3976. DEBUGFUNC();
  3977. if (hw->phy_init_script) {
  3978. mdelay(20);
  3979. /* Save off the current value of register 0x2F5B to be
  3980. * restored at the end of this routine. */
  3981. ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
  3982. /* Disabled the PHY transmitter */
  3983. e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
  3984. mdelay(20);
  3985. e1000_write_phy_reg(hw, 0x0000, 0x0140);
  3986. mdelay(5);
  3987. switch (hw->mac_type) {
  3988. case e1000_82541:
  3989. case e1000_82547:
  3990. e1000_write_phy_reg(hw, 0x1F95, 0x0001);
  3991. e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
  3992. e1000_write_phy_reg(hw, 0x1F79, 0x0018);
  3993. e1000_write_phy_reg(hw, 0x1F30, 0x1600);
  3994. e1000_write_phy_reg(hw, 0x1F31, 0x0014);
  3995. e1000_write_phy_reg(hw, 0x1F32, 0x161C);
  3996. e1000_write_phy_reg(hw, 0x1F94, 0x0003);
  3997. e1000_write_phy_reg(hw, 0x1F96, 0x003F);
  3998. e1000_write_phy_reg(hw, 0x2010, 0x0008);
  3999. break;
  4000. case e1000_82541_rev_2:
  4001. case e1000_82547_rev_2:
  4002. e1000_write_phy_reg(hw, 0x1F73, 0x0099);
  4003. break;
  4004. default:
  4005. break;
  4006. }
  4007. e1000_write_phy_reg(hw, 0x0000, 0x3300);
  4008. mdelay(20);
  4009. /* Now enable the transmitter */
  4010. if (!ret_val)
  4011. e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
  4012. if (hw->mac_type == e1000_82547) {
  4013. uint16_t fused, fine, coarse;
  4014. /* Move to analog registers page */
  4015. e1000_read_phy_reg(hw,
  4016. IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
  4017. if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
  4018. e1000_read_phy_reg(hw,
  4019. IGP01E1000_ANALOG_FUSE_STATUS, &fused);
  4020. fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
  4021. coarse = fused
  4022. & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
  4023. if (coarse >
  4024. IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
  4025. coarse -=
  4026. IGP01E1000_ANALOG_FUSE_COARSE_10;
  4027. fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
  4028. } else if (coarse
  4029. == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
  4030. fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
  4031. fused = (fused
  4032. & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
  4033. (fine
  4034. & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
  4035. (coarse
  4036. & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
  4037. e1000_write_phy_reg(hw,
  4038. IGP01E1000_ANALOG_FUSE_CONTROL, fused);
  4039. e1000_write_phy_reg(hw,
  4040. IGP01E1000_ANALOG_FUSE_BYPASS,
  4041. IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
  4042. }
  4043. }
  4044. }
  4045. }
  4046. /******************************************************************************
  4047. * Resets the PHY
  4048. *
  4049. * hw - Struct containing variables accessed by shared code
  4050. *
  4051. * Sets bit 15 of the MII Control register
  4052. ******************************************************************************/
  4053. int32_t
  4054. e1000_phy_reset(struct e1000_hw *hw)
  4055. {
  4056. int32_t ret_val;
  4057. uint16_t phy_data;
  4058. DEBUGFUNC();
  4059. /* In the case of the phy reset being blocked, it's not an error, we
  4060. * simply return success without performing the reset. */
  4061. ret_val = e1000_check_phy_reset_block(hw);
  4062. if (ret_val)
  4063. return E1000_SUCCESS;
  4064. switch (hw->phy_type) {
  4065. case e1000_phy_igp:
  4066. case e1000_phy_igp_2:
  4067. case e1000_phy_igp_3:
  4068. case e1000_phy_ife:
  4069. case e1000_phy_igb:
  4070. ret_val = e1000_phy_hw_reset(hw);
  4071. if (ret_val)
  4072. return ret_val;
  4073. break;
  4074. default:
  4075. ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
  4076. if (ret_val)
  4077. return ret_val;
  4078. phy_data |= MII_CR_RESET;
  4079. ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
  4080. if (ret_val)
  4081. return ret_val;
  4082. udelay(1);
  4083. break;
  4084. }
  4085. if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
  4086. e1000_phy_init_script(hw);
  4087. return E1000_SUCCESS;
  4088. }
  4089. static int e1000_set_phy_type (struct e1000_hw *hw)
  4090. {
  4091. DEBUGFUNC ();
  4092. if (hw->mac_type == e1000_undefined)
  4093. return -E1000_ERR_PHY_TYPE;
  4094. switch (hw->phy_id) {
  4095. case M88E1000_E_PHY_ID:
  4096. case M88E1000_I_PHY_ID:
  4097. case M88E1011_I_PHY_ID:
  4098. case M88E1111_I_PHY_ID:
  4099. hw->phy_type = e1000_phy_m88;
  4100. break;
  4101. case IGP01E1000_I_PHY_ID:
  4102. if (hw->mac_type == e1000_82541 ||
  4103. hw->mac_type == e1000_82541_rev_2 ||
  4104. hw->mac_type == e1000_82547 ||
  4105. hw->mac_type == e1000_82547_rev_2) {
  4106. hw->phy_type = e1000_phy_igp;
  4107. break;
  4108. }
  4109. case IGP03E1000_E_PHY_ID:
  4110. hw->phy_type = e1000_phy_igp_3;
  4111. break;
  4112. case IFE_E_PHY_ID:
  4113. case IFE_PLUS_E_PHY_ID:
  4114. case IFE_C_E_PHY_ID:
  4115. hw->phy_type = e1000_phy_ife;
  4116. break;
  4117. case GG82563_E_PHY_ID:
  4118. if (hw->mac_type == e1000_80003es2lan) {
  4119. hw->phy_type = e1000_phy_gg82563;
  4120. break;
  4121. }
  4122. case BME1000_E_PHY_ID:
  4123. hw->phy_type = e1000_phy_bm;
  4124. break;
  4125. case I210_I_PHY_ID:
  4126. hw->phy_type = e1000_phy_igb;
  4127. break;
  4128. /* Fall Through */
  4129. default:
  4130. /* Should never have loaded on this device */
  4131. hw->phy_type = e1000_phy_undefined;
  4132. return -E1000_ERR_PHY_TYPE;
  4133. }
  4134. return E1000_SUCCESS;
  4135. }
  4136. /******************************************************************************
  4137. * Probes the expected PHY address for known PHY IDs
  4138. *
  4139. * hw - Struct containing variables accessed by shared code
  4140. ******************************************************************************/
  4141. static int32_t
  4142. e1000_detect_gig_phy(struct e1000_hw *hw)
  4143. {
  4144. int32_t phy_init_status, ret_val;
  4145. uint16_t phy_id_high, phy_id_low;
  4146. bool match = false;
  4147. DEBUGFUNC();
  4148. /* The 82571 firmware may still be configuring the PHY. In this
  4149. * case, we cannot access the PHY until the configuration is done. So
  4150. * we explicitly set the PHY values. */
  4151. if (hw->mac_type == e1000_82571 ||
  4152. hw->mac_type == e1000_82572) {
  4153. hw->phy_id = IGP01E1000_I_PHY_ID;
  4154. hw->phy_type = e1000_phy_igp_2;
  4155. return E1000_SUCCESS;
  4156. }
  4157. /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a
  4158. * work- around that forces PHY page 0 to be set or the reads fail.
  4159. * The rest of the code in this routine uses e1000_read_phy_reg to
  4160. * read the PHY ID. So for ESB-2 we need to have this set so our
  4161. * reads won't fail. If the attached PHY is not a e1000_phy_gg82563,
  4162. * the routines below will figure this out as well. */
  4163. if (hw->mac_type == e1000_80003es2lan)
  4164. hw->phy_type = e1000_phy_gg82563;
  4165. /* Read the PHY ID Registers to identify which PHY is onboard. */
  4166. ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
  4167. if (ret_val)
  4168. return ret_val;
  4169. hw->phy_id = (uint32_t) (phy_id_high << 16);
  4170. udelay(20);
  4171. ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
  4172. if (ret_val)
  4173. return ret_val;
  4174. hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
  4175. hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
  4176. switch (hw->mac_type) {
  4177. case e1000_82543:
  4178. if (hw->phy_id == M88E1000_E_PHY_ID)
  4179. match = true;
  4180. break;
  4181. case e1000_82544:
  4182. if (hw->phy_id == M88E1000_I_PHY_ID)
  4183. match = true;
  4184. break;
  4185. case e1000_82540:
  4186. case e1000_82545:
  4187. case e1000_82545_rev_3:
  4188. case e1000_82546:
  4189. case e1000_82546_rev_3:
  4190. if (hw->phy_id == M88E1011_I_PHY_ID)
  4191. match = true;
  4192. break;
  4193. case e1000_82541:
  4194. case e1000_82541_rev_2:
  4195. case e1000_82547:
  4196. case e1000_82547_rev_2:
  4197. if(hw->phy_id == IGP01E1000_I_PHY_ID)
  4198. match = true;
  4199. break;
  4200. case e1000_82573:
  4201. if (hw->phy_id == M88E1111_I_PHY_ID)
  4202. match = true;
  4203. break;
  4204. case e1000_82574:
  4205. if (hw->phy_id == BME1000_E_PHY_ID)
  4206. match = true;
  4207. break;
  4208. case e1000_80003es2lan:
  4209. if (hw->phy_id == GG82563_E_PHY_ID)
  4210. match = true;
  4211. break;
  4212. case e1000_ich8lan:
  4213. if (hw->phy_id == IGP03E1000_E_PHY_ID)
  4214. match = true;
  4215. if (hw->phy_id == IFE_E_PHY_ID)
  4216. match = true;
  4217. if (hw->phy_id == IFE_PLUS_E_PHY_ID)
  4218. match = true;
  4219. if (hw->phy_id == IFE_C_E_PHY_ID)
  4220. match = true;
  4221. break;
  4222. case e1000_igb:
  4223. if (hw->phy_id == I210_I_PHY_ID)
  4224. match = true;
  4225. break;
  4226. default:
  4227. DEBUGOUT("Invalid MAC type %d\n", hw->mac_type);
  4228. return -E1000_ERR_CONFIG;
  4229. }
  4230. phy_init_status = e1000_set_phy_type(hw);
  4231. if ((match) && (phy_init_status == E1000_SUCCESS)) {
  4232. DEBUGOUT("PHY ID 0x%X detected\n", hw->phy_id);
  4233. return 0;
  4234. }
  4235. DEBUGOUT("Invalid PHY ID 0x%X\n", hw->phy_id);
  4236. return -E1000_ERR_PHY;
  4237. }
  4238. /*****************************************************************************
  4239. * Set media type and TBI compatibility.
  4240. *
  4241. * hw - Struct containing variables accessed by shared code
  4242. * **************************************************************************/
  4243. void
  4244. e1000_set_media_type(struct e1000_hw *hw)
  4245. {
  4246. uint32_t status;
  4247. DEBUGFUNC();
  4248. if (hw->mac_type != e1000_82543) {
  4249. /* tbi_compatibility is only valid on 82543 */
  4250. hw->tbi_compatibility_en = false;
  4251. }
  4252. switch (hw->device_id) {
  4253. case E1000_DEV_ID_82545GM_SERDES:
  4254. case E1000_DEV_ID_82546GB_SERDES:
  4255. case E1000_DEV_ID_82571EB_SERDES:
  4256. case E1000_DEV_ID_82571EB_SERDES_DUAL:
  4257. case E1000_DEV_ID_82571EB_SERDES_QUAD:
  4258. case E1000_DEV_ID_82572EI_SERDES:
  4259. case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
  4260. hw->media_type = e1000_media_type_internal_serdes;
  4261. break;
  4262. default:
  4263. switch (hw->mac_type) {
  4264. case e1000_82542_rev2_0:
  4265. case e1000_82542_rev2_1:
  4266. hw->media_type = e1000_media_type_fiber;
  4267. break;
  4268. case e1000_ich8lan:
  4269. case e1000_82573:
  4270. case e1000_82574:
  4271. case e1000_igb:
  4272. /* The STATUS_TBIMODE bit is reserved or reused
  4273. * for the this device.
  4274. */
  4275. hw->media_type = e1000_media_type_copper;
  4276. break;
  4277. default:
  4278. status = E1000_READ_REG(hw, STATUS);
  4279. if (status & E1000_STATUS_TBIMODE) {
  4280. hw->media_type = e1000_media_type_fiber;
  4281. /* tbi_compatibility not valid on fiber */
  4282. hw->tbi_compatibility_en = false;
  4283. } else {
  4284. hw->media_type = e1000_media_type_copper;
  4285. }
  4286. break;
  4287. }
  4288. }
  4289. }
  4290. /**
  4291. * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
  4292. *
  4293. * e1000_sw_init initializes the Adapter private data structure.
  4294. * Fields are initialized based on PCI device information and
  4295. * OS network device settings (MTU size).
  4296. **/
  4297. static int
  4298. e1000_sw_init(struct eth_device *nic)
  4299. {
  4300. struct e1000_hw *hw = (typeof(hw)) nic->priv;
  4301. int result;
  4302. /* PCI config space info */
  4303. pci_read_config_word(hw->pdev, PCI_VENDOR_ID, &hw->vendor_id);
  4304. pci_read_config_word(hw->pdev, PCI_DEVICE_ID, &hw->device_id);
  4305. pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_VENDOR_ID,
  4306. &hw->subsystem_vendor_id);
  4307. pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_ID, &hw->subsystem_id);
  4308. pci_read_config_byte(hw->pdev, PCI_REVISION_ID, &hw->revision_id);
  4309. pci_read_config_word(hw->pdev, PCI_COMMAND, &hw->pci_cmd_word);
  4310. /* identify the MAC */
  4311. result = e1000_set_mac_type(hw);
  4312. if (result) {
  4313. E1000_ERR(hw->nic, "Unknown MAC Type\n");
  4314. return result;
  4315. }
  4316. switch (hw->mac_type) {
  4317. default:
  4318. break;
  4319. case e1000_82541:
  4320. case e1000_82547:
  4321. case e1000_82541_rev_2:
  4322. case e1000_82547_rev_2:
  4323. hw->phy_init_script = 1;
  4324. break;
  4325. }
  4326. /* flow control settings */
  4327. hw->fc_high_water = E1000_FC_HIGH_THRESH;
  4328. hw->fc_low_water = E1000_FC_LOW_THRESH;
  4329. hw->fc_pause_time = E1000_FC_PAUSE_TIME;
  4330. hw->fc_send_xon = 1;
  4331. /* Media type - copper or fiber */
  4332. hw->tbi_compatibility_en = true;
  4333. e1000_set_media_type(hw);
  4334. if (hw->mac_type >= e1000_82543) {
  4335. uint32_t status = E1000_READ_REG(hw, STATUS);
  4336. if (status & E1000_STATUS_TBIMODE) {
  4337. DEBUGOUT("fiber interface\n");
  4338. hw->media_type = e1000_media_type_fiber;
  4339. } else {
  4340. DEBUGOUT("copper interface\n");
  4341. hw->media_type = e1000_media_type_copper;
  4342. }
  4343. } else {
  4344. hw->media_type = e1000_media_type_fiber;
  4345. }
  4346. hw->wait_autoneg_complete = true;
  4347. if (hw->mac_type < e1000_82543)
  4348. hw->report_tx_early = 0;
  4349. else
  4350. hw->report_tx_early = 1;
  4351. return E1000_SUCCESS;
  4352. }
  4353. void
  4354. fill_rx(struct e1000_hw *hw)
  4355. {
  4356. struct e1000_rx_desc *rd;
  4357. unsigned long flush_start, flush_end;
  4358. rx_last = rx_tail;
  4359. rd = rx_base + rx_tail;
  4360. rx_tail = (rx_tail + 1) % 8;
  4361. memset(rd, 0, 16);
  4362. rd->buffer_addr = cpu_to_le64((unsigned long)packet);
  4363. /*
  4364. * Make sure there are no stale data in WB over this area, which
  4365. * might get written into the memory while the e1000 also writes
  4366. * into the same memory area.
  4367. */
  4368. invalidate_dcache_range((unsigned long)packet,
  4369. (unsigned long)packet + 4096);
  4370. /* Dump the DMA descriptor into RAM. */
  4371. flush_start = ((unsigned long)rd) & ~(ARCH_DMA_MINALIGN - 1);
  4372. flush_end = flush_start + roundup(sizeof(*rd), ARCH_DMA_MINALIGN);
  4373. flush_dcache_range(flush_start, flush_end);
  4374. E1000_WRITE_REG(hw, RDT, rx_tail);
  4375. }
  4376. /**
  4377. * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
  4378. * @adapter: board private structure
  4379. *
  4380. * Configure the Tx unit of the MAC after a reset.
  4381. **/
  4382. static void
  4383. e1000_configure_tx(struct e1000_hw *hw)
  4384. {
  4385. unsigned long tctl;
  4386. unsigned long tipg, tarc;
  4387. uint32_t ipgr1, ipgr2;
  4388. E1000_WRITE_REG(hw, TDBAL, (unsigned long)tx_base);
  4389. E1000_WRITE_REG(hw, TDBAH, 0);
  4390. E1000_WRITE_REG(hw, TDLEN, 128);
  4391. /* Setup the HW Tx Head and Tail descriptor pointers */
  4392. E1000_WRITE_REG(hw, TDH, 0);
  4393. E1000_WRITE_REG(hw, TDT, 0);
  4394. tx_tail = 0;
  4395. /* Set the default values for the Tx Inter Packet Gap timer */
  4396. if (hw->mac_type <= e1000_82547_rev_2 &&
  4397. (hw->media_type == e1000_media_type_fiber ||
  4398. hw->media_type == e1000_media_type_internal_serdes))
  4399. tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
  4400. else
  4401. tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
  4402. /* Set the default values for the Tx Inter Packet Gap timer */
  4403. switch (hw->mac_type) {
  4404. case e1000_82542_rev2_0:
  4405. case e1000_82542_rev2_1:
  4406. tipg = DEFAULT_82542_TIPG_IPGT;
  4407. ipgr1 = DEFAULT_82542_TIPG_IPGR1;
  4408. ipgr2 = DEFAULT_82542_TIPG_IPGR2;
  4409. break;
  4410. case e1000_80003es2lan:
  4411. ipgr1 = DEFAULT_82543_TIPG_IPGR1;
  4412. ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
  4413. break;
  4414. default:
  4415. ipgr1 = DEFAULT_82543_TIPG_IPGR1;
  4416. ipgr2 = DEFAULT_82543_TIPG_IPGR2;
  4417. break;
  4418. }
  4419. tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
  4420. tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
  4421. E1000_WRITE_REG(hw, TIPG, tipg);
  4422. /* Program the Transmit Control Register */
  4423. tctl = E1000_READ_REG(hw, TCTL);
  4424. tctl &= ~E1000_TCTL_CT;
  4425. tctl |= E1000_TCTL_EN | E1000_TCTL_PSP |
  4426. (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
  4427. if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
  4428. tarc = E1000_READ_REG(hw, TARC0);
  4429. /* set the speed mode bit, we'll clear it if we're not at
  4430. * gigabit link later */
  4431. /* git bit can be set to 1*/
  4432. } else if (hw->mac_type == e1000_80003es2lan) {
  4433. tarc = E1000_READ_REG(hw, TARC0);
  4434. tarc |= 1;
  4435. E1000_WRITE_REG(hw, TARC0, tarc);
  4436. tarc = E1000_READ_REG(hw, TARC1);
  4437. tarc |= 1;
  4438. E1000_WRITE_REG(hw, TARC1, tarc);
  4439. }
  4440. e1000_config_collision_dist(hw);
  4441. /* Setup Transmit Descriptor Settings for eop descriptor */
  4442. hw->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
  4443. /* Need to set up RS bit */
  4444. if (hw->mac_type < e1000_82543)
  4445. hw->txd_cmd |= E1000_TXD_CMD_RPS;
  4446. else
  4447. hw->txd_cmd |= E1000_TXD_CMD_RS;
  4448. if (hw->mac_type == e1000_igb) {
  4449. E1000_WRITE_REG(hw, TCTL_EXT, 0x42 << 10);
  4450. uint32_t reg_txdctl = E1000_READ_REG(hw, TXDCTL);
  4451. reg_txdctl |= 1 << 25;
  4452. E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
  4453. mdelay(20);
  4454. }
  4455. E1000_WRITE_REG(hw, TCTL, tctl);
  4456. }
  4457. /**
  4458. * e1000_setup_rctl - configure the receive control register
  4459. * @adapter: Board private structure
  4460. **/
  4461. static void
  4462. e1000_setup_rctl(struct e1000_hw *hw)
  4463. {
  4464. uint32_t rctl;
  4465. rctl = E1000_READ_REG(hw, RCTL);
  4466. rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
  4467. rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_LBM_NO
  4468. | E1000_RCTL_RDMTS_HALF; /* |
  4469. (hw.mc_filter_type << E1000_RCTL_MO_SHIFT); */
  4470. if (hw->tbi_compatibility_on == 1)
  4471. rctl |= E1000_RCTL_SBP;
  4472. else
  4473. rctl &= ~E1000_RCTL_SBP;
  4474. rctl &= ~(E1000_RCTL_SZ_4096);
  4475. rctl |= E1000_RCTL_SZ_2048;
  4476. rctl &= ~(E1000_RCTL_BSEX | E1000_RCTL_LPE);
  4477. E1000_WRITE_REG(hw, RCTL, rctl);
  4478. }
  4479. /**
  4480. * e1000_configure_rx - Configure 8254x Receive Unit after Reset
  4481. * @adapter: board private structure
  4482. *
  4483. * Configure the Rx unit of the MAC after a reset.
  4484. **/
  4485. static void
  4486. e1000_configure_rx(struct e1000_hw *hw)
  4487. {
  4488. unsigned long rctl, ctrl_ext;
  4489. rx_tail = 0;
  4490. /* make sure receives are disabled while setting up the descriptors */
  4491. rctl = E1000_READ_REG(hw, RCTL);
  4492. E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
  4493. if (hw->mac_type >= e1000_82540) {
  4494. /* Set the interrupt throttling rate. Value is calculated
  4495. * as DEFAULT_ITR = 1/(MAX_INTS_PER_SEC * 256ns) */
  4496. #define MAX_INTS_PER_SEC 8000
  4497. #define DEFAULT_ITR 1000000000/(MAX_INTS_PER_SEC * 256)
  4498. E1000_WRITE_REG(hw, ITR, DEFAULT_ITR);
  4499. }
  4500. if (hw->mac_type >= e1000_82571) {
  4501. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  4502. /* Reset delay timers after every interrupt */
  4503. ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
  4504. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  4505. E1000_WRITE_FLUSH(hw);
  4506. }
  4507. /* Setup the Base and Length of the Rx Descriptor Ring */
  4508. E1000_WRITE_REG(hw, RDBAL, (unsigned long)rx_base);
  4509. E1000_WRITE_REG(hw, RDBAH, 0);
  4510. E1000_WRITE_REG(hw, RDLEN, 128);
  4511. /* Setup the HW Rx Head and Tail Descriptor Pointers */
  4512. E1000_WRITE_REG(hw, RDH, 0);
  4513. E1000_WRITE_REG(hw, RDT, 0);
  4514. /* Enable Receives */
  4515. if (hw->mac_type == e1000_igb) {
  4516. uint32_t reg_rxdctl = E1000_READ_REG(hw, RXDCTL);
  4517. reg_rxdctl |= 1 << 25;
  4518. E1000_WRITE_REG(hw, RXDCTL, reg_rxdctl);
  4519. mdelay(20);
  4520. }
  4521. E1000_WRITE_REG(hw, RCTL, rctl);
  4522. fill_rx(hw);
  4523. }
  4524. /**************************************************************************
  4525. POLL - Wait for a frame
  4526. ***************************************************************************/
  4527. static int
  4528. e1000_poll(struct eth_device *nic)
  4529. {
  4530. struct e1000_hw *hw = nic->priv;
  4531. struct e1000_rx_desc *rd;
  4532. unsigned long inval_start, inval_end;
  4533. uint32_t len;
  4534. /* return true if there's an ethernet packet ready to read */
  4535. rd = rx_base + rx_last;
  4536. /* Re-load the descriptor from RAM. */
  4537. inval_start = ((unsigned long)rd) & ~(ARCH_DMA_MINALIGN - 1);
  4538. inval_end = inval_start + roundup(sizeof(*rd), ARCH_DMA_MINALIGN);
  4539. invalidate_dcache_range(inval_start, inval_end);
  4540. if (!(le32_to_cpu(rd->status)) & E1000_RXD_STAT_DD)
  4541. return 0;
  4542. /* DEBUGOUT("recv: packet len=%d\n", rd->length); */
  4543. /* Packet received, make sure the data are re-loaded from RAM. */
  4544. len = le32_to_cpu(rd->length);
  4545. invalidate_dcache_range((unsigned long)packet,
  4546. (unsigned long)packet +
  4547. roundup(len, ARCH_DMA_MINALIGN));
  4548. net_process_received_packet((uchar *)packet, len);
  4549. fill_rx(hw);
  4550. return 1;
  4551. }
  4552. /**************************************************************************
  4553. TRANSMIT - Transmit a frame
  4554. ***************************************************************************/
  4555. static int e1000_transmit(struct eth_device *nic, void *txpacket, int length)
  4556. {
  4557. void *nv_packet = (void *)txpacket;
  4558. struct e1000_hw *hw = nic->priv;
  4559. struct e1000_tx_desc *txp;
  4560. int i = 0;
  4561. unsigned long flush_start, flush_end;
  4562. txp = tx_base + tx_tail;
  4563. tx_tail = (tx_tail + 1) % 8;
  4564. txp->buffer_addr = cpu_to_le64(virt_to_bus(hw->pdev, nv_packet));
  4565. txp->lower.data = cpu_to_le32(hw->txd_cmd | length);
  4566. txp->upper.data = 0;
  4567. /* Dump the packet into RAM so e1000 can pick them. */
  4568. flush_dcache_range((unsigned long)nv_packet,
  4569. (unsigned long)nv_packet +
  4570. roundup(length, ARCH_DMA_MINALIGN));
  4571. /* Dump the descriptor into RAM as well. */
  4572. flush_start = ((unsigned long)txp) & ~(ARCH_DMA_MINALIGN - 1);
  4573. flush_end = flush_start + roundup(sizeof(*txp), ARCH_DMA_MINALIGN);
  4574. flush_dcache_range(flush_start, flush_end);
  4575. E1000_WRITE_REG(hw, TDT, tx_tail);
  4576. E1000_WRITE_FLUSH(hw);
  4577. while (1) {
  4578. invalidate_dcache_range(flush_start, flush_end);
  4579. if (le32_to_cpu(txp->upper.data) & E1000_TXD_STAT_DD)
  4580. break;
  4581. if (i++ > TOUT_LOOP) {
  4582. DEBUGOUT("e1000: tx timeout\n");
  4583. return 0;
  4584. }
  4585. udelay(10); /* give the nic a chance to write to the register */
  4586. }
  4587. return 1;
  4588. }
  4589. /*reset function*/
  4590. static inline int
  4591. e1000_reset(struct eth_device *nic)
  4592. {
  4593. struct e1000_hw *hw = nic->priv;
  4594. e1000_reset_hw(hw);
  4595. if (hw->mac_type >= e1000_82544) {
  4596. E1000_WRITE_REG(hw, WUC, 0);
  4597. }
  4598. return e1000_init_hw(nic);
  4599. }
  4600. /**************************************************************************
  4601. DISABLE - Turn off ethernet interface
  4602. ***************************************************************************/
  4603. static void
  4604. e1000_disable(struct eth_device *nic)
  4605. {
  4606. struct e1000_hw *hw = nic->priv;
  4607. /* Turn off the ethernet interface */
  4608. E1000_WRITE_REG(hw, RCTL, 0);
  4609. E1000_WRITE_REG(hw, TCTL, 0);
  4610. /* Clear the transmit ring */
  4611. E1000_WRITE_REG(hw, TDH, 0);
  4612. E1000_WRITE_REG(hw, TDT, 0);
  4613. /* Clear the receive ring */
  4614. E1000_WRITE_REG(hw, RDH, 0);
  4615. E1000_WRITE_REG(hw, RDT, 0);
  4616. /* put the card in its initial state */
  4617. #if 0
  4618. E1000_WRITE_REG(hw, CTRL, E1000_CTRL_RST);
  4619. #endif
  4620. mdelay(10);
  4621. }
  4622. /**************************************************************************
  4623. INIT - set up ethernet interface(s)
  4624. ***************************************************************************/
  4625. static int
  4626. e1000_init(struct eth_device *nic, bd_t * bis)
  4627. {
  4628. struct e1000_hw *hw = nic->priv;
  4629. int ret_val = 0;
  4630. ret_val = e1000_reset(nic);
  4631. if (ret_val < 0) {
  4632. if ((ret_val == -E1000_ERR_NOLINK) ||
  4633. (ret_val == -E1000_ERR_TIMEOUT)) {
  4634. E1000_ERR(hw->nic, "Valid Link not detected\n");
  4635. } else {
  4636. E1000_ERR(hw->nic, "Hardware Initialization Failed\n");
  4637. }
  4638. return 0;
  4639. }
  4640. e1000_configure_tx(hw);
  4641. e1000_setup_rctl(hw);
  4642. e1000_configure_rx(hw);
  4643. return 1;
  4644. }
  4645. /******************************************************************************
  4646. * Gets the current PCI bus type of hardware
  4647. *
  4648. * hw - Struct containing variables accessed by shared code
  4649. *****************************************************************************/
  4650. void e1000_get_bus_type(struct e1000_hw *hw)
  4651. {
  4652. uint32_t status;
  4653. switch (hw->mac_type) {
  4654. case e1000_82542_rev2_0:
  4655. case e1000_82542_rev2_1:
  4656. hw->bus_type = e1000_bus_type_pci;
  4657. break;
  4658. case e1000_82571:
  4659. case e1000_82572:
  4660. case e1000_82573:
  4661. case e1000_82574:
  4662. case e1000_80003es2lan:
  4663. case e1000_ich8lan:
  4664. case e1000_igb:
  4665. hw->bus_type = e1000_bus_type_pci_express;
  4666. break;
  4667. default:
  4668. status = E1000_READ_REG(hw, STATUS);
  4669. hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
  4670. e1000_bus_type_pcix : e1000_bus_type_pci;
  4671. break;
  4672. }
  4673. }
  4674. /* A list of all registered e1000 devices */
  4675. static LIST_HEAD(e1000_hw_list);
  4676. /**************************************************************************
  4677. PROBE - Look for an adapter, this routine's visible to the outside
  4678. You should omit the last argument struct pci_device * for a non-PCI NIC
  4679. ***************************************************************************/
  4680. int
  4681. e1000_initialize(bd_t * bis)
  4682. {
  4683. unsigned int i;
  4684. pci_dev_t devno;
  4685. DEBUGFUNC();
  4686. /* Find and probe all the matching PCI devices */
  4687. for (i = 0; (devno = pci_find_devices(e1000_supported, i)) >= 0; i++) {
  4688. u32 val;
  4689. /*
  4690. * These will never get freed due to errors, this allows us to
  4691. * perform SPI EEPROM programming from U-boot, for example.
  4692. */
  4693. struct eth_device *nic = malloc(sizeof(*nic));
  4694. struct e1000_hw *hw = malloc(sizeof(*hw));
  4695. if (!nic || !hw) {
  4696. printf("e1000#%u: Out of Memory!\n", i);
  4697. free(nic);
  4698. free(hw);
  4699. continue;
  4700. }
  4701. /* Make sure all of the fields are initially zeroed */
  4702. memset(nic, 0, sizeof(*nic));
  4703. memset(hw, 0, sizeof(*hw));
  4704. /* Assign the passed-in values */
  4705. hw->cardnum = i;
  4706. hw->pdev = devno;
  4707. hw->nic = nic;
  4708. nic->priv = hw;
  4709. /* Generate a card name */
  4710. sprintf(nic->name, "e1000#%u", hw->cardnum);
  4711. /* Print a debug message with the IO base address */
  4712. pci_read_config_dword(devno, PCI_BASE_ADDRESS_0, &val);
  4713. E1000_DBG(nic, "iobase 0x%08x\n", val & 0xfffffff0);
  4714. /* Try to enable I/O accesses and bus-mastering */
  4715. val = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
  4716. pci_write_config_dword(devno, PCI_COMMAND, val);
  4717. /* Make sure it worked */
  4718. pci_read_config_dword(devno, PCI_COMMAND, &val);
  4719. if (!(val & PCI_COMMAND_MEMORY)) {
  4720. E1000_ERR(nic, "Can't enable I/O memory\n");
  4721. continue;
  4722. }
  4723. if (!(val & PCI_COMMAND_MASTER)) {
  4724. E1000_ERR(nic, "Can't enable bus-mastering\n");
  4725. continue;
  4726. }
  4727. /* Are these variables needed? */
  4728. hw->fc = e1000_fc_default;
  4729. hw->original_fc = e1000_fc_default;
  4730. hw->autoneg_failed = 0;
  4731. hw->autoneg = 1;
  4732. hw->get_link_status = true;
  4733. #ifndef CONFIG_E1000_NO_NVM
  4734. hw->eeprom_semaphore_present = true;
  4735. #endif
  4736. hw->hw_addr = pci_map_bar(devno, PCI_BASE_ADDRESS_0,
  4737. PCI_REGION_MEM);
  4738. hw->mac_type = e1000_undefined;
  4739. /* MAC and Phy settings */
  4740. if (e1000_sw_init(nic) < 0) {
  4741. E1000_ERR(nic, "Software init failed\n");
  4742. continue;
  4743. }
  4744. if (e1000_check_phy_reset_block(hw))
  4745. E1000_ERR(nic, "PHY Reset is blocked!\n");
  4746. /* Basic init was OK, reset the hardware and allow SPI access */
  4747. e1000_reset_hw(hw);
  4748. list_add_tail(&hw->list_node, &e1000_hw_list);
  4749. #ifndef CONFIG_E1000_NO_NVM
  4750. /* Validate the EEPROM and get chipset information */
  4751. #if !defined(CONFIG_MVBC_1G)
  4752. if (e1000_init_eeprom_params(hw)) {
  4753. E1000_ERR(nic, "EEPROM is invalid!\n");
  4754. continue;
  4755. }
  4756. if ((E1000_READ_REG(hw, I210_EECD) & E1000_EECD_FLUPD) &&
  4757. e1000_validate_eeprom_checksum(hw))
  4758. continue;
  4759. #endif
  4760. e1000_read_mac_addr(nic);
  4761. #endif
  4762. e1000_get_bus_type(hw);
  4763. #ifndef CONFIG_E1000_NO_NVM
  4764. printf("e1000: %02x:%02x:%02x:%02x:%02x:%02x\n ",
  4765. nic->enetaddr[0], nic->enetaddr[1], nic->enetaddr[2],
  4766. nic->enetaddr[3], nic->enetaddr[4], nic->enetaddr[5]);
  4767. #else
  4768. memset(nic->enetaddr, 0, 6);
  4769. printf("e1000: no NVM\n");
  4770. #endif
  4771. /* Set up the function pointers and register the device */
  4772. nic->init = e1000_init;
  4773. nic->recv = e1000_poll;
  4774. nic->send = e1000_transmit;
  4775. nic->halt = e1000_disable;
  4776. eth_register(nic);
  4777. }
  4778. return i;
  4779. }
  4780. struct e1000_hw *e1000_find_card(unsigned int cardnum)
  4781. {
  4782. struct e1000_hw *hw;
  4783. list_for_each_entry(hw, &e1000_hw_list, list_node)
  4784. if (hw->cardnum == cardnum)
  4785. return hw;
  4786. return NULL;
  4787. }
  4788. #ifdef CONFIG_CMD_E1000
  4789. static int do_e1000(cmd_tbl_t *cmdtp, int flag,
  4790. int argc, char * const argv[])
  4791. {
  4792. struct e1000_hw *hw;
  4793. if (argc < 3) {
  4794. cmd_usage(cmdtp);
  4795. return 1;
  4796. }
  4797. /* Make sure we can find the requested e1000 card */
  4798. hw = e1000_find_card(simple_strtoul(argv[1], NULL, 10));
  4799. if (!hw) {
  4800. printf("e1000: ERROR: No such device: e1000#%s\n", argv[1]);
  4801. return 1;
  4802. }
  4803. if (!strcmp(argv[2], "print-mac-address")) {
  4804. unsigned char *mac = hw->nic->enetaddr;
  4805. printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
  4806. mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  4807. return 0;
  4808. }
  4809. #ifdef CONFIG_E1000_SPI
  4810. /* Handle the "SPI" subcommand */
  4811. if (!strcmp(argv[2], "spi"))
  4812. return do_e1000_spi(cmdtp, hw, argc - 3, argv + 3);
  4813. #endif
  4814. cmd_usage(cmdtp);
  4815. return 1;
  4816. }
  4817. U_BOOT_CMD(
  4818. e1000, 7, 0, do_e1000,
  4819. "Intel e1000 controller management",
  4820. /* */"<card#> print-mac-address\n"
  4821. #ifdef CONFIG_E1000_SPI
  4822. "e1000 <card#> spi show [<offset> [<length>]]\n"
  4823. "e1000 <card#> spi dump <addr> <offset> <length>\n"
  4824. "e1000 <card#> spi program <addr> <offset> <length>\n"
  4825. "e1000 <card#> spi checksum [update]\n"
  4826. #endif
  4827. " - Manage the Intel E1000 PCI device"
  4828. );
  4829. #endif /* not CONFIG_CMD_E1000 */