e1000.c 155 KB

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