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 ( *(u32*)(nic->enetaddr) == 0 || *(u32*)(nic->enetaddr) == ~0 ) {
  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 icr;
  1200. uint32_t manc;
  1201. uint32_t pba = 0;
  1202. DEBUGFUNC();
  1203. /* get the correct pba value for both PCI and PCIe*/
  1204. if (hw->mac_type < e1000_82571)
  1205. pba = E1000_DEFAULT_PCI_PBA;
  1206. else
  1207. pba = E1000_DEFAULT_PCIE_PBA;
  1208. /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
  1209. if (hw->mac_type == e1000_82542_rev2_0) {
  1210. DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
  1211. pci_write_config_word(hw->pdev, PCI_COMMAND,
  1212. hw->pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
  1213. }
  1214. /* Clear interrupt mask to stop board from generating interrupts */
  1215. DEBUGOUT("Masking off all interrupts\n");
  1216. E1000_WRITE_REG(hw, IMC, 0xffffffff);
  1217. /* Disable the Transmit and Receive units. Then delay to allow
  1218. * any pending transactions to complete before we hit the MAC with
  1219. * the global reset.
  1220. */
  1221. E1000_WRITE_REG(hw, RCTL, 0);
  1222. E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
  1223. E1000_WRITE_FLUSH(hw);
  1224. /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
  1225. hw->tbi_compatibility_on = FALSE;
  1226. /* Delay to allow any outstanding PCI transactions to complete before
  1227. * resetting the device
  1228. */
  1229. mdelay(10);
  1230. /* Issue a global reset to the MAC. This will reset the chip's
  1231. * transmit, receive, DMA, and link units. It will not effect
  1232. * the current PCI configuration. The global reset bit is self-
  1233. * clearing, and should clear within a microsecond.
  1234. */
  1235. DEBUGOUT("Issuing a global reset to MAC\n");
  1236. ctrl = E1000_READ_REG(hw, CTRL);
  1237. E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
  1238. /* Force a reload from the EEPROM if necessary */
  1239. if (hw->mac_type < e1000_82540) {
  1240. /* Wait for reset to complete */
  1241. udelay(10);
  1242. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  1243. ctrl_ext |= E1000_CTRL_EXT_EE_RST;
  1244. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  1245. E1000_WRITE_FLUSH(hw);
  1246. /* Wait for EEPROM reload */
  1247. mdelay(2);
  1248. } else {
  1249. /* Wait for EEPROM reload (it happens automatically) */
  1250. mdelay(4);
  1251. /* Dissable HW ARPs on ASF enabled adapters */
  1252. manc = E1000_READ_REG(hw, MANC);
  1253. manc &= ~(E1000_MANC_ARP_EN);
  1254. E1000_WRITE_REG(hw, MANC, manc);
  1255. }
  1256. /* Clear interrupt mask to stop board from generating interrupts */
  1257. DEBUGOUT("Masking off all interrupts\n");
  1258. E1000_WRITE_REG(hw, IMC, 0xffffffff);
  1259. /* Clear any pending interrupt events. */
  1260. icr = E1000_READ_REG(hw, ICR);
  1261. /* If MWI was previously enabled, reenable it. */
  1262. if (hw->mac_type == e1000_82542_rev2_0) {
  1263. pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
  1264. }
  1265. E1000_WRITE_REG(hw, PBA, pba);
  1266. }
  1267. /******************************************************************************
  1268. *
  1269. * Initialize a number of hardware-dependent bits
  1270. *
  1271. * hw: Struct containing variables accessed by shared code
  1272. *
  1273. * This function contains hardware limitation workarounds for PCI-E adapters
  1274. *
  1275. *****************************************************************************/
  1276. static void
  1277. e1000_initialize_hardware_bits(struct e1000_hw *hw)
  1278. {
  1279. if ((hw->mac_type >= e1000_82571) &&
  1280. (!hw->initialize_hw_bits_disable)) {
  1281. /* Settings common to all PCI-express silicon */
  1282. uint32_t reg_ctrl, reg_ctrl_ext;
  1283. uint32_t reg_tarc0, reg_tarc1;
  1284. uint32_t reg_tctl;
  1285. uint32_t reg_txdctl, reg_txdctl1;
  1286. /* link autonegotiation/sync workarounds */
  1287. reg_tarc0 = E1000_READ_REG(hw, TARC0);
  1288. reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
  1289. /* Enable not-done TX descriptor counting */
  1290. reg_txdctl = E1000_READ_REG(hw, TXDCTL);
  1291. reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
  1292. E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
  1293. reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
  1294. reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
  1295. E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
  1296. switch (hw->mac_type) {
  1297. case e1000_82571:
  1298. case e1000_82572:
  1299. /* Clear PHY TX compatible mode bits */
  1300. reg_tarc1 = E1000_READ_REG(hw, TARC1);
  1301. reg_tarc1 &= ~((1 << 30)|(1 << 29));
  1302. /* link autonegotiation/sync workarounds */
  1303. reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
  1304. /* TX ring control fixes */
  1305. reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
  1306. /* Multiple read bit is reversed polarity */
  1307. reg_tctl = E1000_READ_REG(hw, TCTL);
  1308. if (reg_tctl & E1000_TCTL_MULR)
  1309. reg_tarc1 &= ~(1 << 28);
  1310. else
  1311. reg_tarc1 |= (1 << 28);
  1312. E1000_WRITE_REG(hw, TARC1, reg_tarc1);
  1313. break;
  1314. case e1000_82573:
  1315. case e1000_82574:
  1316. reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  1317. reg_ctrl_ext &= ~(1 << 23);
  1318. reg_ctrl_ext |= (1 << 22);
  1319. /* TX byte count fix */
  1320. reg_ctrl = E1000_READ_REG(hw, CTRL);
  1321. reg_ctrl &= ~(1 << 29);
  1322. E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
  1323. E1000_WRITE_REG(hw, CTRL, reg_ctrl);
  1324. break;
  1325. case e1000_80003es2lan:
  1326. /* improve small packet performace for fiber/serdes */
  1327. if ((hw->media_type == e1000_media_type_fiber)
  1328. || (hw->media_type ==
  1329. e1000_media_type_internal_serdes)) {
  1330. reg_tarc0 &= ~(1 << 20);
  1331. }
  1332. /* Multiple read bit is reversed polarity */
  1333. reg_tctl = E1000_READ_REG(hw, TCTL);
  1334. reg_tarc1 = E1000_READ_REG(hw, TARC1);
  1335. if (reg_tctl & E1000_TCTL_MULR)
  1336. reg_tarc1 &= ~(1 << 28);
  1337. else
  1338. reg_tarc1 |= (1 << 28);
  1339. E1000_WRITE_REG(hw, TARC1, reg_tarc1);
  1340. break;
  1341. case e1000_ich8lan:
  1342. /* Reduce concurrent DMA requests to 3 from 4 */
  1343. if ((hw->revision_id < 3) ||
  1344. ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
  1345. (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
  1346. reg_tarc0 |= ((1 << 29)|(1 << 28));
  1347. reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  1348. reg_ctrl_ext |= (1 << 22);
  1349. E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
  1350. /* workaround TX hang with TSO=on */
  1351. reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
  1352. /* Multiple read bit is reversed polarity */
  1353. reg_tctl = E1000_READ_REG(hw, TCTL);
  1354. reg_tarc1 = E1000_READ_REG(hw, TARC1);
  1355. if (reg_tctl & E1000_TCTL_MULR)
  1356. reg_tarc1 &= ~(1 << 28);
  1357. else
  1358. reg_tarc1 |= (1 << 28);
  1359. /* workaround TX hang with TSO=on */
  1360. reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
  1361. E1000_WRITE_REG(hw, TARC1, reg_tarc1);
  1362. break;
  1363. default:
  1364. break;
  1365. }
  1366. E1000_WRITE_REG(hw, TARC0, reg_tarc0);
  1367. }
  1368. }
  1369. /******************************************************************************
  1370. * Performs basic configuration of the adapter.
  1371. *
  1372. * hw - Struct containing variables accessed by shared code
  1373. *
  1374. * Assumes that the controller has previously been reset and is in a
  1375. * post-reset uninitialized state. Initializes the receive address registers,
  1376. * multicast table, and VLAN filter table. Calls routines to setup link
  1377. * configuration and flow control settings. Clears all on-chip counters. Leaves
  1378. * the transmit and receive units disabled and uninitialized.
  1379. *****************************************************************************/
  1380. static int
  1381. e1000_init_hw(struct eth_device *nic)
  1382. {
  1383. struct e1000_hw *hw = nic->priv;
  1384. uint32_t ctrl;
  1385. uint32_t i;
  1386. int32_t ret_val;
  1387. uint16_t pcix_cmd_word;
  1388. uint16_t pcix_stat_hi_word;
  1389. uint16_t cmd_mmrbc;
  1390. uint16_t stat_mmrbc;
  1391. uint32_t mta_size;
  1392. uint32_t reg_data;
  1393. uint32_t ctrl_ext;
  1394. DEBUGFUNC();
  1395. /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
  1396. if ((hw->mac_type == e1000_ich8lan) &&
  1397. ((hw->revision_id < 3) ||
  1398. ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
  1399. (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
  1400. reg_data = E1000_READ_REG(hw, STATUS);
  1401. reg_data &= ~0x80000000;
  1402. E1000_WRITE_REG(hw, STATUS, reg_data);
  1403. }
  1404. /* Do not need initialize Identification LED */
  1405. /* Set the media type and TBI compatibility */
  1406. e1000_set_media_type(hw);
  1407. /* Must be called after e1000_set_media_type
  1408. * because media_type is used */
  1409. e1000_initialize_hardware_bits(hw);
  1410. /* Disabling VLAN filtering. */
  1411. DEBUGOUT("Initializing the IEEE VLAN\n");
  1412. /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
  1413. if (hw->mac_type != e1000_ich8lan) {
  1414. if (hw->mac_type < e1000_82545_rev_3)
  1415. E1000_WRITE_REG(hw, VET, 0);
  1416. e1000_clear_vfta(hw);
  1417. }
  1418. /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
  1419. if (hw->mac_type == e1000_82542_rev2_0) {
  1420. DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
  1421. pci_write_config_word(hw->pdev, PCI_COMMAND,
  1422. hw->
  1423. pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
  1424. E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
  1425. E1000_WRITE_FLUSH(hw);
  1426. mdelay(5);
  1427. }
  1428. /* Setup the receive address. This involves initializing all of the Receive
  1429. * Address Registers (RARs 0 - 15).
  1430. */
  1431. e1000_init_rx_addrs(nic);
  1432. /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
  1433. if (hw->mac_type == e1000_82542_rev2_0) {
  1434. E1000_WRITE_REG(hw, RCTL, 0);
  1435. E1000_WRITE_FLUSH(hw);
  1436. mdelay(1);
  1437. pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
  1438. }
  1439. /* Zero out the Multicast HASH table */
  1440. DEBUGOUT("Zeroing the MTA\n");
  1441. mta_size = E1000_MC_TBL_SIZE;
  1442. if (hw->mac_type == e1000_ich8lan)
  1443. mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
  1444. for (i = 0; i < mta_size; i++) {
  1445. E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
  1446. /* use write flush to prevent Memory Write Block (MWB) from
  1447. * occuring when accessing our register space */
  1448. E1000_WRITE_FLUSH(hw);
  1449. }
  1450. #if 0
  1451. /* Set the PCI priority bit correctly in the CTRL register. This
  1452. * determines if the adapter gives priority to receives, or if it
  1453. * gives equal priority to transmits and receives. Valid only on
  1454. * 82542 and 82543 silicon.
  1455. */
  1456. if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
  1457. ctrl = E1000_READ_REG(hw, CTRL);
  1458. E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
  1459. }
  1460. #endif
  1461. switch (hw->mac_type) {
  1462. case e1000_82545_rev_3:
  1463. case e1000_82546_rev_3:
  1464. break;
  1465. default:
  1466. /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
  1467. if (hw->bus_type == e1000_bus_type_pcix) {
  1468. pci_read_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
  1469. &pcix_cmd_word);
  1470. pci_read_config_word(hw->pdev, PCIX_STATUS_REGISTER_HI,
  1471. &pcix_stat_hi_word);
  1472. cmd_mmrbc =
  1473. (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
  1474. PCIX_COMMAND_MMRBC_SHIFT;
  1475. stat_mmrbc =
  1476. (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
  1477. PCIX_STATUS_HI_MMRBC_SHIFT;
  1478. if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
  1479. stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
  1480. if (cmd_mmrbc > stat_mmrbc) {
  1481. pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
  1482. pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
  1483. pci_write_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
  1484. pcix_cmd_word);
  1485. }
  1486. }
  1487. break;
  1488. }
  1489. /* More time needed for PHY to initialize */
  1490. if (hw->mac_type == e1000_ich8lan)
  1491. mdelay(15);
  1492. /* Call a subroutine to configure the link and setup flow control. */
  1493. ret_val = e1000_setup_link(nic);
  1494. /* Set the transmit descriptor write-back policy */
  1495. if (hw->mac_type > e1000_82544) {
  1496. ctrl = E1000_READ_REG(hw, TXDCTL);
  1497. ctrl =
  1498. (ctrl & ~E1000_TXDCTL_WTHRESH) |
  1499. E1000_TXDCTL_FULL_TX_DESC_WB;
  1500. E1000_WRITE_REG(hw, TXDCTL, ctrl);
  1501. }
  1502. switch (hw->mac_type) {
  1503. default:
  1504. break;
  1505. case e1000_80003es2lan:
  1506. /* Enable retransmit on late collisions */
  1507. reg_data = E1000_READ_REG(hw, TCTL);
  1508. reg_data |= E1000_TCTL_RTLC;
  1509. E1000_WRITE_REG(hw, TCTL, reg_data);
  1510. /* Configure Gigabit Carry Extend Padding */
  1511. reg_data = E1000_READ_REG(hw, TCTL_EXT);
  1512. reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
  1513. reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
  1514. E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
  1515. /* Configure Transmit Inter-Packet Gap */
  1516. reg_data = E1000_READ_REG(hw, TIPG);
  1517. reg_data &= ~E1000_TIPG_IPGT_MASK;
  1518. reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
  1519. E1000_WRITE_REG(hw, TIPG, reg_data);
  1520. reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
  1521. reg_data &= ~0x00100000;
  1522. E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
  1523. /* Fall through */
  1524. case e1000_82571:
  1525. case e1000_82572:
  1526. case e1000_ich8lan:
  1527. ctrl = E1000_READ_REG(hw, TXDCTL1);
  1528. ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH)
  1529. | E1000_TXDCTL_FULL_TX_DESC_WB;
  1530. E1000_WRITE_REG(hw, TXDCTL1, ctrl);
  1531. break;
  1532. case e1000_82573:
  1533. case e1000_82574:
  1534. reg_data = E1000_READ_REG(hw, GCR);
  1535. reg_data |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
  1536. E1000_WRITE_REG(hw, GCR, reg_data);
  1537. }
  1538. #if 0
  1539. /* Clear all of the statistics registers (clear on read). It is
  1540. * important that we do this after we have tried to establish link
  1541. * because the symbol error count will increment wildly if there
  1542. * is no link.
  1543. */
  1544. e1000_clear_hw_cntrs(hw);
  1545. /* ICH8 No-snoop bits are opposite polarity.
  1546. * Set to snoop by default after reset. */
  1547. if (hw->mac_type == e1000_ich8lan)
  1548. e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
  1549. #endif
  1550. if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
  1551. hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
  1552. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  1553. /* Relaxed ordering must be disabled to avoid a parity
  1554. * error crash in a PCI slot. */
  1555. ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
  1556. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  1557. }
  1558. return ret_val;
  1559. }
  1560. /******************************************************************************
  1561. * Configures flow control and link settings.
  1562. *
  1563. * hw - Struct containing variables accessed by shared code
  1564. *
  1565. * Determines which flow control settings to use. Calls the apropriate media-
  1566. * specific link configuration function. Configures the flow control settings.
  1567. * Assuming the adapter has a valid link partner, a valid link should be
  1568. * established. Assumes the hardware has previously been reset and the
  1569. * transmitter and receiver are not enabled.
  1570. *****************************************************************************/
  1571. static int
  1572. e1000_setup_link(struct eth_device *nic)
  1573. {
  1574. struct e1000_hw *hw = nic->priv;
  1575. uint32_t ctrl_ext;
  1576. int32_t ret_val;
  1577. uint16_t eeprom_data;
  1578. DEBUGFUNC();
  1579. /* In the case of the phy reset being blocked, we already have a link.
  1580. * We do not have to set it up again. */
  1581. if (e1000_check_phy_reset_block(hw))
  1582. return E1000_SUCCESS;
  1583. #ifndef CONFIG_AP1000
  1584. /* Read and store word 0x0F of the EEPROM. This word contains bits
  1585. * that determine the hardware's default PAUSE (flow control) mode,
  1586. * a bit that determines whether the HW defaults to enabling or
  1587. * disabling auto-negotiation, and the direction of the
  1588. * SW defined pins. If there is no SW over-ride of the flow
  1589. * control setting, then the variable hw->fc will
  1590. * be initialized based on a value in the EEPROM.
  1591. */
  1592. if (e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1,
  1593. &eeprom_data) < 0) {
  1594. DEBUGOUT("EEPROM Read Error\n");
  1595. return -E1000_ERR_EEPROM;
  1596. }
  1597. #else
  1598. /* we have to hardcode the proper value for our hardware. */
  1599. /* this value is for the 82540EM pci card used for prototyping, and it works. */
  1600. eeprom_data = 0xb220;
  1601. #endif
  1602. if (hw->fc == e1000_fc_default) {
  1603. switch (hw->mac_type) {
  1604. case e1000_ich8lan:
  1605. case e1000_82573:
  1606. case e1000_82574:
  1607. hw->fc = e1000_fc_full;
  1608. break;
  1609. default:
  1610. #ifndef CONFIG_AP1000
  1611. ret_val = e1000_read_eeprom(hw,
  1612. EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
  1613. if (ret_val) {
  1614. DEBUGOUT("EEPROM Read Error\n");
  1615. return -E1000_ERR_EEPROM;
  1616. }
  1617. #else
  1618. eeprom_data = 0xb220;
  1619. #endif
  1620. if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
  1621. hw->fc = e1000_fc_none;
  1622. else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
  1623. EEPROM_WORD0F_ASM_DIR)
  1624. hw->fc = e1000_fc_tx_pause;
  1625. else
  1626. hw->fc = e1000_fc_full;
  1627. break;
  1628. }
  1629. }
  1630. /* We want to save off the original Flow Control configuration just
  1631. * in case we get disconnected and then reconnected into a different
  1632. * hub or switch with different Flow Control capabilities.
  1633. */
  1634. if (hw->mac_type == e1000_82542_rev2_0)
  1635. hw->fc &= (~e1000_fc_tx_pause);
  1636. if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
  1637. hw->fc &= (~e1000_fc_rx_pause);
  1638. hw->original_fc = hw->fc;
  1639. DEBUGOUT("After fix-ups FlowControl is now = %x\n", hw->fc);
  1640. /* Take the 4 bits from EEPROM word 0x0F that determine the initial
  1641. * polarity value for the SW controlled pins, and setup the
  1642. * Extended Device Control reg with that info.
  1643. * This is needed because one of the SW controlled pins is used for
  1644. * signal detection. So this should be done before e1000_setup_pcs_link()
  1645. * or e1000_phy_setup() is called.
  1646. */
  1647. if (hw->mac_type == e1000_82543) {
  1648. ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
  1649. SWDPIO__EXT_SHIFT);
  1650. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  1651. }
  1652. /* Call the necessary subroutine to configure the link. */
  1653. ret_val = (hw->media_type == e1000_media_type_fiber) ?
  1654. e1000_setup_fiber_link(nic) : e1000_setup_copper_link(nic);
  1655. if (ret_val < 0) {
  1656. return ret_val;
  1657. }
  1658. /* Initialize the flow control address, type, and PAUSE timer
  1659. * registers to their default values. This is done even if flow
  1660. * control is disabled, because it does not hurt anything to
  1661. * initialize these registers.
  1662. */
  1663. DEBUGOUT("Initializing the Flow Control address, type"
  1664. "and timer regs\n");
  1665. /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
  1666. if (hw->mac_type != e1000_ich8lan) {
  1667. E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
  1668. E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
  1669. E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
  1670. }
  1671. E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
  1672. /* Set the flow control receive threshold registers. Normally,
  1673. * these registers will be set to a default threshold that may be
  1674. * adjusted later by the driver's runtime code. However, if the
  1675. * ability to transmit pause frames in not enabled, then these
  1676. * registers will be set to 0.
  1677. */
  1678. if (!(hw->fc & e1000_fc_tx_pause)) {
  1679. E1000_WRITE_REG(hw, FCRTL, 0);
  1680. E1000_WRITE_REG(hw, FCRTH, 0);
  1681. } else {
  1682. /* We need to set up the Receive Threshold high and low water marks
  1683. * as well as (optionally) enabling the transmission of XON frames.
  1684. */
  1685. if (hw->fc_send_xon) {
  1686. E1000_WRITE_REG(hw, FCRTL,
  1687. (hw->fc_low_water | E1000_FCRTL_XONE));
  1688. E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
  1689. } else {
  1690. E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
  1691. E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
  1692. }
  1693. }
  1694. return ret_val;
  1695. }
  1696. /******************************************************************************
  1697. * Sets up link for a fiber based adapter
  1698. *
  1699. * hw - Struct containing variables accessed by shared code
  1700. *
  1701. * Manipulates Physical Coding Sublayer functions in order to configure
  1702. * link. Assumes the hardware has been previously reset and the transmitter
  1703. * and receiver are not enabled.
  1704. *****************************************************************************/
  1705. static int
  1706. e1000_setup_fiber_link(struct eth_device *nic)
  1707. {
  1708. struct e1000_hw *hw = nic->priv;
  1709. uint32_t ctrl;
  1710. uint32_t status;
  1711. uint32_t txcw = 0;
  1712. uint32_t i;
  1713. uint32_t signal;
  1714. int32_t ret_val;
  1715. DEBUGFUNC();
  1716. /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
  1717. * set when the optics detect a signal. On older adapters, it will be
  1718. * cleared when there is a signal
  1719. */
  1720. ctrl = E1000_READ_REG(hw, CTRL);
  1721. if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
  1722. signal = E1000_CTRL_SWDPIN1;
  1723. else
  1724. signal = 0;
  1725. printf("signal for %s is %x (ctrl %08x)!!!!\n", nic->name, signal,
  1726. ctrl);
  1727. /* Take the link out of reset */
  1728. ctrl &= ~(E1000_CTRL_LRST);
  1729. e1000_config_collision_dist(hw);
  1730. /* Check for a software override of the flow control settings, and setup
  1731. * the device accordingly. If auto-negotiation is enabled, then software
  1732. * will have to set the "PAUSE" bits to the correct value in the Tranmsit
  1733. * Config Word Register (TXCW) and re-start auto-negotiation. However, if
  1734. * auto-negotiation is disabled, then software will have to manually
  1735. * configure the two flow control enable bits in the CTRL register.
  1736. *
  1737. * The possible values of the "fc" parameter are:
  1738. * 0: Flow control is completely disabled
  1739. * 1: Rx flow control is enabled (we can receive pause frames, but
  1740. * not send pause frames).
  1741. * 2: Tx flow control is enabled (we can send pause frames but we do
  1742. * not support receiving pause frames).
  1743. * 3: Both Rx and TX flow control (symmetric) are enabled.
  1744. */
  1745. switch (hw->fc) {
  1746. case e1000_fc_none:
  1747. /* Flow control is completely disabled by a software over-ride. */
  1748. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
  1749. break;
  1750. case e1000_fc_rx_pause:
  1751. /* RX Flow control is enabled and TX Flow control is disabled by a
  1752. * software over-ride. Since there really isn't a way to advertise
  1753. * that we are capable of RX Pause ONLY, we will advertise that we
  1754. * support both symmetric and asymmetric RX PAUSE. Later, we will
  1755. * disable the adapter's ability to send PAUSE frames.
  1756. */
  1757. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  1758. break;
  1759. case e1000_fc_tx_pause:
  1760. /* TX Flow control is enabled, and RX Flow control is disabled, by a
  1761. * software over-ride.
  1762. */
  1763. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
  1764. break;
  1765. case e1000_fc_full:
  1766. /* Flow control (both RX and TX) is enabled by a software over-ride. */
  1767. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  1768. break;
  1769. default:
  1770. DEBUGOUT("Flow control param set incorrectly\n");
  1771. return -E1000_ERR_CONFIG;
  1772. break;
  1773. }
  1774. /* Since auto-negotiation is enabled, take the link out of reset (the link
  1775. * will be in reset, because we previously reset the chip). This will
  1776. * restart auto-negotiation. If auto-neogtiation is successful then the
  1777. * link-up status bit will be set and the flow control enable bits (RFCE
  1778. * and TFCE) will be set according to their negotiated value.
  1779. */
  1780. DEBUGOUT("Auto-negotiation enabled (%#x)\n", txcw);
  1781. E1000_WRITE_REG(hw, TXCW, txcw);
  1782. E1000_WRITE_REG(hw, CTRL, ctrl);
  1783. E1000_WRITE_FLUSH(hw);
  1784. hw->txcw = txcw;
  1785. mdelay(1);
  1786. /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
  1787. * indication in the Device Status Register. Time-out if a link isn't
  1788. * seen in 500 milliseconds seconds (Auto-negotiation should complete in
  1789. * less than 500 milliseconds even if the other end is doing it in SW).
  1790. */
  1791. if ((E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
  1792. DEBUGOUT("Looking for Link\n");
  1793. for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
  1794. mdelay(10);
  1795. status = E1000_READ_REG(hw, STATUS);
  1796. if (status & E1000_STATUS_LU)
  1797. break;
  1798. }
  1799. if (i == (LINK_UP_TIMEOUT / 10)) {
  1800. /* AutoNeg failed to achieve a link, so we'll call
  1801. * e1000_check_for_link. This routine will force the link up if we
  1802. * detect a signal. This will allow us to communicate with
  1803. * non-autonegotiating link partners.
  1804. */
  1805. DEBUGOUT("Never got a valid link from auto-neg!!!\n");
  1806. hw->autoneg_failed = 1;
  1807. ret_val = e1000_check_for_link(nic);
  1808. if (ret_val < 0) {
  1809. DEBUGOUT("Error while checking for link\n");
  1810. return ret_val;
  1811. }
  1812. hw->autoneg_failed = 0;
  1813. } else {
  1814. hw->autoneg_failed = 0;
  1815. DEBUGOUT("Valid Link Found\n");
  1816. }
  1817. } else {
  1818. DEBUGOUT("No Signal Detected\n");
  1819. return -E1000_ERR_NOLINK;
  1820. }
  1821. return 0;
  1822. }
  1823. /******************************************************************************
  1824. * Make sure we have a valid PHY and change PHY mode before link setup.
  1825. *
  1826. * hw - Struct containing variables accessed by shared code
  1827. ******************************************************************************/
  1828. static int32_t
  1829. e1000_copper_link_preconfig(struct e1000_hw *hw)
  1830. {
  1831. uint32_t ctrl;
  1832. int32_t ret_val;
  1833. uint16_t phy_data;
  1834. DEBUGFUNC();
  1835. ctrl = E1000_READ_REG(hw, CTRL);
  1836. /* With 82543, we need to force speed and duplex on the MAC equal to what
  1837. * the PHY speed and duplex configuration is. In addition, we need to
  1838. * perform a hardware reset on the PHY to take it out of reset.
  1839. */
  1840. if (hw->mac_type > e1000_82543) {
  1841. ctrl |= E1000_CTRL_SLU;
  1842. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1843. E1000_WRITE_REG(hw, CTRL, ctrl);
  1844. } else {
  1845. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX
  1846. | E1000_CTRL_SLU);
  1847. E1000_WRITE_REG(hw, CTRL, ctrl);
  1848. ret_val = e1000_phy_hw_reset(hw);
  1849. if (ret_val)
  1850. return ret_val;
  1851. }
  1852. /* Make sure we have a valid PHY */
  1853. ret_val = e1000_detect_gig_phy(hw);
  1854. if (ret_val) {
  1855. DEBUGOUT("Error, did not detect valid phy.\n");
  1856. return ret_val;
  1857. }
  1858. DEBUGOUT("Phy ID = %x \n", hw->phy_id);
  1859. #ifndef CONFIG_AP1000
  1860. /* Set PHY to class A mode (if necessary) */
  1861. ret_val = e1000_set_phy_mode(hw);
  1862. if (ret_val)
  1863. return ret_val;
  1864. #endif
  1865. if ((hw->mac_type == e1000_82545_rev_3) ||
  1866. (hw->mac_type == e1000_82546_rev_3)) {
  1867. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
  1868. &phy_data);
  1869. phy_data |= 0x00000008;
  1870. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
  1871. phy_data);
  1872. }
  1873. if (hw->mac_type <= e1000_82543 ||
  1874. hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
  1875. hw->mac_type == e1000_82541_rev_2
  1876. || hw->mac_type == e1000_82547_rev_2)
  1877. hw->phy_reset_disable = FALSE;
  1878. return E1000_SUCCESS;
  1879. }
  1880. /*****************************************************************************
  1881. *
  1882. * This function sets the lplu state according to the active flag. When
  1883. * activating lplu this function also disables smart speed and vise versa.
  1884. * lplu will not be activated unless the device autonegotiation advertisment
  1885. * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
  1886. * hw: Struct containing variables accessed by shared code
  1887. * active - true to enable lplu false to disable lplu.
  1888. *
  1889. * returns: - E1000_ERR_PHY if fail to read/write the PHY
  1890. * E1000_SUCCESS at any other case.
  1891. *
  1892. ****************************************************************************/
  1893. static int32_t
  1894. e1000_set_d3_lplu_state(struct e1000_hw *hw, boolean_t active)
  1895. {
  1896. uint32_t phy_ctrl = 0;
  1897. int32_t ret_val;
  1898. uint16_t phy_data;
  1899. DEBUGFUNC();
  1900. if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
  1901. && hw->phy_type != e1000_phy_igp_3)
  1902. return E1000_SUCCESS;
  1903. /* During driver activity LPLU should not be used or it will attain link
  1904. * from the lowest speeds starting from 10Mbps. The capability is used
  1905. * for Dx transitions and states */
  1906. if (hw->mac_type == e1000_82541_rev_2
  1907. || hw->mac_type == e1000_82547_rev_2) {
  1908. ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
  1909. &phy_data);
  1910. if (ret_val)
  1911. return ret_val;
  1912. } else if (hw->mac_type == e1000_ich8lan) {
  1913. /* MAC writes into PHY register based on the state transition
  1914. * and start auto-negotiation. SW driver can overwrite the
  1915. * settings in CSR PHY power control E1000_PHY_CTRL register. */
  1916. phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
  1917. } else {
  1918. ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  1919. &phy_data);
  1920. if (ret_val)
  1921. return ret_val;
  1922. }
  1923. if (!active) {
  1924. if (hw->mac_type == e1000_82541_rev_2 ||
  1925. hw->mac_type == e1000_82547_rev_2) {
  1926. phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
  1927. ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
  1928. phy_data);
  1929. if (ret_val)
  1930. return ret_val;
  1931. } else {
  1932. if (hw->mac_type == e1000_ich8lan) {
  1933. phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
  1934. E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
  1935. } else {
  1936. phy_data &= ~IGP02E1000_PM_D3_LPLU;
  1937. ret_val = e1000_write_phy_reg(hw,
  1938. IGP02E1000_PHY_POWER_MGMT, phy_data);
  1939. if (ret_val)
  1940. return ret_val;
  1941. }
  1942. }
  1943. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
  1944. * Dx states where the power conservation is most important. During
  1945. * driver activity we should enable SmartSpeed, so performance is
  1946. * maintained. */
  1947. if (hw->smart_speed == e1000_smart_speed_on) {
  1948. ret_val = e1000_read_phy_reg(hw,
  1949. IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  1950. if (ret_val)
  1951. return ret_val;
  1952. phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
  1953. ret_val = e1000_write_phy_reg(hw,
  1954. IGP01E1000_PHY_PORT_CONFIG, phy_data);
  1955. if (ret_val)
  1956. return ret_val;
  1957. } else if (hw->smart_speed == e1000_smart_speed_off) {
  1958. ret_val = e1000_read_phy_reg(hw,
  1959. IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  1960. if (ret_val)
  1961. return ret_val;
  1962. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  1963. ret_val = e1000_write_phy_reg(hw,
  1964. IGP01E1000_PHY_PORT_CONFIG, phy_data);
  1965. if (ret_val)
  1966. return ret_val;
  1967. }
  1968. } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT)
  1969. || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL) ||
  1970. (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
  1971. if (hw->mac_type == e1000_82541_rev_2 ||
  1972. hw->mac_type == e1000_82547_rev_2) {
  1973. phy_data |= IGP01E1000_GMII_FLEX_SPD;
  1974. ret_val = e1000_write_phy_reg(hw,
  1975. IGP01E1000_GMII_FIFO, phy_data);
  1976. if (ret_val)
  1977. return ret_val;
  1978. } else {
  1979. if (hw->mac_type == e1000_ich8lan) {
  1980. phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
  1981. E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
  1982. } else {
  1983. phy_data |= IGP02E1000_PM_D3_LPLU;
  1984. ret_val = e1000_write_phy_reg(hw,
  1985. IGP02E1000_PHY_POWER_MGMT, phy_data);
  1986. if (ret_val)
  1987. return ret_val;
  1988. }
  1989. }
  1990. /* When LPLU is enabled we should disable SmartSpeed */
  1991. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  1992. &phy_data);
  1993. if (ret_val)
  1994. return ret_val;
  1995. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  1996. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  1997. phy_data);
  1998. if (ret_val)
  1999. return ret_val;
  2000. }
  2001. return E1000_SUCCESS;
  2002. }
  2003. /*****************************************************************************
  2004. *
  2005. * This function sets the lplu d0 state according to the active flag. When
  2006. * activating lplu this function also disables smart speed and vise versa.
  2007. * lplu will not be activated unless the device autonegotiation advertisment
  2008. * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
  2009. * hw: Struct containing variables accessed by shared code
  2010. * active - true to enable lplu false to disable lplu.
  2011. *
  2012. * returns: - E1000_ERR_PHY if fail to read/write the PHY
  2013. * E1000_SUCCESS at any other case.
  2014. *
  2015. ****************************************************************************/
  2016. static int32_t
  2017. e1000_set_d0_lplu_state(struct e1000_hw *hw, boolean_t active)
  2018. {
  2019. uint32_t phy_ctrl = 0;
  2020. int32_t ret_val;
  2021. uint16_t phy_data;
  2022. DEBUGFUNC();
  2023. if (hw->mac_type <= e1000_82547_rev_2)
  2024. return E1000_SUCCESS;
  2025. if (hw->mac_type == e1000_ich8lan) {
  2026. phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
  2027. } else {
  2028. ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  2029. &phy_data);
  2030. if (ret_val)
  2031. return ret_val;
  2032. }
  2033. if (!active) {
  2034. if (hw->mac_type == e1000_ich8lan) {
  2035. phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
  2036. E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
  2037. } else {
  2038. phy_data &= ~IGP02E1000_PM_D0_LPLU;
  2039. ret_val = e1000_write_phy_reg(hw,
  2040. IGP02E1000_PHY_POWER_MGMT, phy_data);
  2041. if (ret_val)
  2042. return ret_val;
  2043. }
  2044. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
  2045. * Dx states where the power conservation is most important. During
  2046. * driver activity we should enable SmartSpeed, so performance is
  2047. * maintained. */
  2048. if (hw->smart_speed == e1000_smart_speed_on) {
  2049. ret_val = e1000_read_phy_reg(hw,
  2050. IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  2051. if (ret_val)
  2052. return ret_val;
  2053. phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
  2054. ret_val = e1000_write_phy_reg(hw,
  2055. IGP01E1000_PHY_PORT_CONFIG, phy_data);
  2056. if (ret_val)
  2057. return ret_val;
  2058. } else if (hw->smart_speed == e1000_smart_speed_off) {
  2059. ret_val = e1000_read_phy_reg(hw,
  2060. IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  2061. if (ret_val)
  2062. return ret_val;
  2063. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2064. ret_val = e1000_write_phy_reg(hw,
  2065. IGP01E1000_PHY_PORT_CONFIG, phy_data);
  2066. if (ret_val)
  2067. return ret_val;
  2068. }
  2069. } else {
  2070. if (hw->mac_type == e1000_ich8lan) {
  2071. phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
  2072. E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
  2073. } else {
  2074. phy_data |= IGP02E1000_PM_D0_LPLU;
  2075. ret_val = e1000_write_phy_reg(hw,
  2076. IGP02E1000_PHY_POWER_MGMT, phy_data);
  2077. if (ret_val)
  2078. return ret_val;
  2079. }
  2080. /* When LPLU is enabled we should disable SmartSpeed */
  2081. ret_val = e1000_read_phy_reg(hw,
  2082. IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  2083. if (ret_val)
  2084. return ret_val;
  2085. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2086. ret_val = e1000_write_phy_reg(hw,
  2087. IGP01E1000_PHY_PORT_CONFIG, phy_data);
  2088. if (ret_val)
  2089. return ret_val;
  2090. }
  2091. return E1000_SUCCESS;
  2092. }
  2093. /********************************************************************
  2094. * Copper link setup for e1000_phy_igp series.
  2095. *
  2096. * hw - Struct containing variables accessed by shared code
  2097. *********************************************************************/
  2098. static int32_t
  2099. e1000_copper_link_igp_setup(struct e1000_hw *hw)
  2100. {
  2101. uint32_t led_ctrl;
  2102. int32_t ret_val;
  2103. uint16_t phy_data;
  2104. DEBUGFUNC();
  2105. if (hw->phy_reset_disable)
  2106. return E1000_SUCCESS;
  2107. ret_val = e1000_phy_reset(hw);
  2108. if (ret_val) {
  2109. DEBUGOUT("Error Resetting the PHY\n");
  2110. return ret_val;
  2111. }
  2112. /* Wait 15ms for MAC to configure PHY from eeprom settings */
  2113. mdelay(15);
  2114. if (hw->mac_type != e1000_ich8lan) {
  2115. /* Configure activity LED after PHY reset */
  2116. led_ctrl = E1000_READ_REG(hw, LEDCTL);
  2117. led_ctrl &= IGP_ACTIVITY_LED_MASK;
  2118. led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
  2119. E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
  2120. }
  2121. /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
  2122. if (hw->phy_type == e1000_phy_igp) {
  2123. /* disable lplu d3 during driver init */
  2124. ret_val = e1000_set_d3_lplu_state(hw, FALSE);
  2125. if (ret_val) {
  2126. DEBUGOUT("Error Disabling LPLU D3\n");
  2127. return ret_val;
  2128. }
  2129. }
  2130. /* disable lplu d0 during driver init */
  2131. ret_val = e1000_set_d0_lplu_state(hw, FALSE);
  2132. if (ret_val) {
  2133. DEBUGOUT("Error Disabling LPLU D0\n");
  2134. return ret_val;
  2135. }
  2136. /* Configure mdi-mdix settings */
  2137. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
  2138. if (ret_val)
  2139. return ret_val;
  2140. if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  2141. hw->dsp_config_state = e1000_dsp_config_disabled;
  2142. /* Force MDI for earlier revs of the IGP PHY */
  2143. phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX
  2144. | IGP01E1000_PSCR_FORCE_MDI_MDIX);
  2145. hw->mdix = 1;
  2146. } else {
  2147. hw->dsp_config_state = e1000_dsp_config_enabled;
  2148. phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  2149. switch (hw->mdix) {
  2150. case 1:
  2151. phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  2152. break;
  2153. case 2:
  2154. phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
  2155. break;
  2156. case 0:
  2157. default:
  2158. phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
  2159. break;
  2160. }
  2161. }
  2162. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
  2163. if (ret_val)
  2164. return ret_val;
  2165. /* set auto-master slave resolution settings */
  2166. if (hw->autoneg) {
  2167. e1000_ms_type phy_ms_setting = hw->master_slave;
  2168. if (hw->ffe_config_state == e1000_ffe_config_active)
  2169. hw->ffe_config_state = e1000_ffe_config_enabled;
  2170. if (hw->dsp_config_state == e1000_dsp_config_activated)
  2171. hw->dsp_config_state = e1000_dsp_config_enabled;
  2172. /* when autonegotiation advertisment is only 1000Mbps then we
  2173. * should disable SmartSpeed and enable Auto MasterSlave
  2174. * resolution as hardware default. */
  2175. if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
  2176. /* Disable SmartSpeed */
  2177. ret_val = e1000_read_phy_reg(hw,
  2178. IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  2179. if (ret_val)
  2180. return ret_val;
  2181. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2182. ret_val = e1000_write_phy_reg(hw,
  2183. IGP01E1000_PHY_PORT_CONFIG, phy_data);
  2184. if (ret_val)
  2185. return ret_val;
  2186. /* Set auto Master/Slave resolution process */
  2187. ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
  2188. &phy_data);
  2189. if (ret_val)
  2190. return ret_val;
  2191. phy_data &= ~CR_1000T_MS_ENABLE;
  2192. ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
  2193. phy_data);
  2194. if (ret_val)
  2195. return ret_val;
  2196. }
  2197. ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
  2198. if (ret_val)
  2199. return ret_val;
  2200. /* load defaults for future use */
  2201. hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
  2202. ((phy_data & CR_1000T_MS_VALUE) ?
  2203. e1000_ms_force_master :
  2204. e1000_ms_force_slave) :
  2205. e1000_ms_auto;
  2206. switch (phy_ms_setting) {
  2207. case e1000_ms_force_master:
  2208. phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
  2209. break;
  2210. case e1000_ms_force_slave:
  2211. phy_data |= CR_1000T_MS_ENABLE;
  2212. phy_data &= ~(CR_1000T_MS_VALUE);
  2213. break;
  2214. case e1000_ms_auto:
  2215. phy_data &= ~CR_1000T_MS_ENABLE;
  2216. default:
  2217. break;
  2218. }
  2219. ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
  2220. if (ret_val)
  2221. return ret_val;
  2222. }
  2223. return E1000_SUCCESS;
  2224. }
  2225. /*****************************************************************************
  2226. * This function checks the mode of the firmware.
  2227. *
  2228. * returns - TRUE when the mode is IAMT or FALSE.
  2229. ****************************************************************************/
  2230. boolean_t
  2231. e1000_check_mng_mode(struct e1000_hw *hw)
  2232. {
  2233. uint32_t fwsm;
  2234. DEBUGFUNC();
  2235. fwsm = E1000_READ_REG(hw, FWSM);
  2236. if (hw->mac_type == e1000_ich8lan) {
  2237. if ((fwsm & E1000_FWSM_MODE_MASK) ==
  2238. (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
  2239. return TRUE;
  2240. } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
  2241. (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
  2242. return TRUE;
  2243. return FALSE;
  2244. }
  2245. static int32_t
  2246. e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data)
  2247. {
  2248. uint16_t swfw = E1000_SWFW_PHY0_SM;
  2249. uint32_t reg_val;
  2250. DEBUGFUNC();
  2251. if (e1000_is_second_port(hw))
  2252. swfw = E1000_SWFW_PHY1_SM;
  2253. if (e1000_swfw_sync_acquire(hw, swfw))
  2254. return -E1000_ERR_SWFW_SYNC;
  2255. reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT)
  2256. & E1000_KUMCTRLSTA_OFFSET) | data;
  2257. E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
  2258. udelay(2);
  2259. return E1000_SUCCESS;
  2260. }
  2261. static int32_t
  2262. e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data)
  2263. {
  2264. uint16_t swfw = E1000_SWFW_PHY0_SM;
  2265. uint32_t reg_val;
  2266. DEBUGFUNC();
  2267. if (e1000_is_second_port(hw))
  2268. swfw = E1000_SWFW_PHY1_SM;
  2269. if (e1000_swfw_sync_acquire(hw, swfw))
  2270. return -E1000_ERR_SWFW_SYNC;
  2271. /* Write register address */
  2272. reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
  2273. E1000_KUMCTRLSTA_OFFSET) | E1000_KUMCTRLSTA_REN;
  2274. E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
  2275. udelay(2);
  2276. /* Read the data returned */
  2277. reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
  2278. *data = (uint16_t)reg_val;
  2279. return E1000_SUCCESS;
  2280. }
  2281. /********************************************************************
  2282. * Copper link setup for e1000_phy_gg82563 series.
  2283. *
  2284. * hw - Struct containing variables accessed by shared code
  2285. *********************************************************************/
  2286. static int32_t
  2287. e1000_copper_link_ggp_setup(struct e1000_hw *hw)
  2288. {
  2289. int32_t ret_val;
  2290. uint16_t phy_data;
  2291. uint32_t reg_data;
  2292. DEBUGFUNC();
  2293. if (!hw->phy_reset_disable) {
  2294. /* Enable CRS on TX for half-duplex operation. */
  2295. ret_val = e1000_read_phy_reg(hw,
  2296. GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
  2297. if (ret_val)
  2298. return ret_val;
  2299. phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
  2300. /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
  2301. phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
  2302. ret_val = e1000_write_phy_reg(hw,
  2303. GG82563_PHY_MAC_SPEC_CTRL, phy_data);
  2304. if (ret_val)
  2305. return ret_val;
  2306. /* Options:
  2307. * MDI/MDI-X = 0 (default)
  2308. * 0 - Auto for all speeds
  2309. * 1 - MDI mode
  2310. * 2 - MDI-X mode
  2311. * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
  2312. */
  2313. ret_val = e1000_read_phy_reg(hw,
  2314. GG82563_PHY_SPEC_CTRL, &phy_data);
  2315. if (ret_val)
  2316. return ret_val;
  2317. phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
  2318. switch (hw->mdix) {
  2319. case 1:
  2320. phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
  2321. break;
  2322. case 2:
  2323. phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
  2324. break;
  2325. case 0:
  2326. default:
  2327. phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
  2328. break;
  2329. }
  2330. /* Options:
  2331. * disable_polarity_correction = 0 (default)
  2332. * Automatic Correction for Reversed Cable Polarity
  2333. * 0 - Disabled
  2334. * 1 - Enabled
  2335. */
  2336. phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
  2337. ret_val = e1000_write_phy_reg(hw,
  2338. GG82563_PHY_SPEC_CTRL, phy_data);
  2339. if (ret_val)
  2340. return ret_val;
  2341. /* SW Reset the PHY so all changes take effect */
  2342. ret_val = e1000_phy_reset(hw);
  2343. if (ret_val) {
  2344. DEBUGOUT("Error Resetting the PHY\n");
  2345. return ret_val;
  2346. }
  2347. } /* phy_reset_disable */
  2348. if (hw->mac_type == e1000_80003es2lan) {
  2349. /* Bypass RX and TX FIFO's */
  2350. ret_val = e1000_write_kmrn_reg(hw,
  2351. E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
  2352. E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS
  2353. | E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
  2354. if (ret_val)
  2355. return ret_val;
  2356. ret_val = e1000_read_phy_reg(hw,
  2357. GG82563_PHY_SPEC_CTRL_2, &phy_data);
  2358. if (ret_val)
  2359. return ret_val;
  2360. phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
  2361. ret_val = e1000_write_phy_reg(hw,
  2362. GG82563_PHY_SPEC_CTRL_2, phy_data);
  2363. if (ret_val)
  2364. return ret_val;
  2365. reg_data = E1000_READ_REG(hw, CTRL_EXT);
  2366. reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
  2367. E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
  2368. ret_val = e1000_read_phy_reg(hw,
  2369. GG82563_PHY_PWR_MGMT_CTRL, &phy_data);
  2370. if (ret_val)
  2371. return ret_val;
  2372. /* Do not init these registers when the HW is in IAMT mode, since the
  2373. * firmware will have already initialized them. We only initialize
  2374. * them if the HW is not in IAMT mode.
  2375. */
  2376. if (e1000_check_mng_mode(hw) == FALSE) {
  2377. /* Enable Electrical Idle on the PHY */
  2378. phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
  2379. ret_val = e1000_write_phy_reg(hw,
  2380. GG82563_PHY_PWR_MGMT_CTRL, phy_data);
  2381. if (ret_val)
  2382. return ret_val;
  2383. ret_val = e1000_read_phy_reg(hw,
  2384. GG82563_PHY_KMRN_MODE_CTRL, &phy_data);
  2385. if (ret_val)
  2386. return ret_val;
  2387. phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
  2388. ret_val = e1000_write_phy_reg(hw,
  2389. GG82563_PHY_KMRN_MODE_CTRL, phy_data);
  2390. if (ret_val)
  2391. return ret_val;
  2392. }
  2393. /* Workaround: Disable padding in Kumeran interface in the MAC
  2394. * and in the PHY to avoid CRC errors.
  2395. */
  2396. ret_val = e1000_read_phy_reg(hw,
  2397. GG82563_PHY_INBAND_CTRL, &phy_data);
  2398. if (ret_val)
  2399. return ret_val;
  2400. phy_data |= GG82563_ICR_DIS_PADDING;
  2401. ret_val = e1000_write_phy_reg(hw,
  2402. GG82563_PHY_INBAND_CTRL, phy_data);
  2403. if (ret_val)
  2404. return ret_val;
  2405. }
  2406. return E1000_SUCCESS;
  2407. }
  2408. /********************************************************************
  2409. * Copper link setup for e1000_phy_m88 series.
  2410. *
  2411. * hw - Struct containing variables accessed by shared code
  2412. *********************************************************************/
  2413. static int32_t
  2414. e1000_copper_link_mgp_setup(struct e1000_hw *hw)
  2415. {
  2416. int32_t ret_val;
  2417. uint16_t phy_data;
  2418. DEBUGFUNC();
  2419. if (hw->phy_reset_disable)
  2420. return E1000_SUCCESS;
  2421. /* Enable CRS on TX. This must be set for half-duplex operation. */
  2422. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  2423. if (ret_val)
  2424. return ret_val;
  2425. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  2426. /* Options:
  2427. * MDI/MDI-X = 0 (default)
  2428. * 0 - Auto for all speeds
  2429. * 1 - MDI mode
  2430. * 2 - MDI-X mode
  2431. * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
  2432. */
  2433. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  2434. switch (hw->mdix) {
  2435. case 1:
  2436. phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
  2437. break;
  2438. case 2:
  2439. phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
  2440. break;
  2441. case 3:
  2442. phy_data |= M88E1000_PSCR_AUTO_X_1000T;
  2443. break;
  2444. case 0:
  2445. default:
  2446. phy_data |= M88E1000_PSCR_AUTO_X_MODE;
  2447. break;
  2448. }
  2449. /* Options:
  2450. * disable_polarity_correction = 0 (default)
  2451. * Automatic Correction for Reversed Cable Polarity
  2452. * 0 - Disabled
  2453. * 1 - Enabled
  2454. */
  2455. phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
  2456. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  2457. if (ret_val)
  2458. return ret_val;
  2459. if (hw->phy_revision < M88E1011_I_REV_4) {
  2460. /* Force TX_CLK in the Extended PHY Specific Control Register
  2461. * to 25MHz clock.
  2462. */
  2463. ret_val = e1000_read_phy_reg(hw,
  2464. M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
  2465. if (ret_val)
  2466. return ret_val;
  2467. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  2468. if ((hw->phy_revision == E1000_REVISION_2) &&
  2469. (hw->phy_id == M88E1111_I_PHY_ID)) {
  2470. /* Vidalia Phy, set the downshift counter to 5x */
  2471. phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
  2472. phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
  2473. ret_val = e1000_write_phy_reg(hw,
  2474. M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
  2475. if (ret_val)
  2476. return ret_val;
  2477. } else {
  2478. /* Configure Master and Slave downshift values */
  2479. phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK
  2480. | M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
  2481. phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X
  2482. | M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
  2483. ret_val = e1000_write_phy_reg(hw,
  2484. M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
  2485. if (ret_val)
  2486. return ret_val;
  2487. }
  2488. }
  2489. /* SW Reset the PHY so all changes take effect */
  2490. ret_val = e1000_phy_reset(hw);
  2491. if (ret_val) {
  2492. DEBUGOUT("Error Resetting the PHY\n");
  2493. return ret_val;
  2494. }
  2495. return E1000_SUCCESS;
  2496. }
  2497. /********************************************************************
  2498. * Setup auto-negotiation and flow control advertisements,
  2499. * and then perform auto-negotiation.
  2500. *
  2501. * hw - Struct containing variables accessed by shared code
  2502. *********************************************************************/
  2503. static int32_t
  2504. e1000_copper_link_autoneg(struct e1000_hw *hw)
  2505. {
  2506. int32_t ret_val;
  2507. uint16_t phy_data;
  2508. DEBUGFUNC();
  2509. /* Perform some bounds checking on the hw->autoneg_advertised
  2510. * parameter. If this variable is zero, then set it to the default.
  2511. */
  2512. hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
  2513. /* If autoneg_advertised is zero, we assume it was not defaulted
  2514. * by the calling code so we set to advertise full capability.
  2515. */
  2516. if (hw->autoneg_advertised == 0)
  2517. hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  2518. /* IFE phy only supports 10/100 */
  2519. if (hw->phy_type == e1000_phy_ife)
  2520. hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
  2521. DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
  2522. ret_val = e1000_phy_setup_autoneg(hw);
  2523. if (ret_val) {
  2524. DEBUGOUT("Error Setting up Auto-Negotiation\n");
  2525. return ret_val;
  2526. }
  2527. DEBUGOUT("Restarting Auto-Neg\n");
  2528. /* Restart auto-negotiation by setting the Auto Neg Enable bit and
  2529. * the Auto Neg Restart bit in the PHY control register.
  2530. */
  2531. ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
  2532. if (ret_val)
  2533. return ret_val;
  2534. phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
  2535. ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
  2536. if (ret_val)
  2537. return ret_val;
  2538. /* Does the user want to wait for Auto-Neg to complete here, or
  2539. * check at a later time (for example, callback routine).
  2540. */
  2541. /* If we do not wait for autonegtation to complete I
  2542. * do not see a valid link status.
  2543. * wait_autoneg_complete = 1 .
  2544. */
  2545. if (hw->wait_autoneg_complete) {
  2546. ret_val = e1000_wait_autoneg(hw);
  2547. if (ret_val) {
  2548. DEBUGOUT("Error while waiting for autoneg"
  2549. "to complete\n");
  2550. return ret_val;
  2551. }
  2552. }
  2553. hw->get_link_status = TRUE;
  2554. return E1000_SUCCESS;
  2555. }
  2556. /******************************************************************************
  2557. * Config the MAC and the PHY after link is up.
  2558. * 1) Set up the MAC to the current PHY speed/duplex
  2559. * if we are on 82543. If we
  2560. * are on newer silicon, we only need to configure
  2561. * collision distance in the Transmit Control Register.
  2562. * 2) Set up flow control on the MAC to that established with
  2563. * the link partner.
  2564. * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
  2565. *
  2566. * hw - Struct containing variables accessed by shared code
  2567. ******************************************************************************/
  2568. static int32_t
  2569. e1000_copper_link_postconfig(struct e1000_hw *hw)
  2570. {
  2571. int32_t ret_val;
  2572. DEBUGFUNC();
  2573. if (hw->mac_type >= e1000_82544) {
  2574. e1000_config_collision_dist(hw);
  2575. } else {
  2576. ret_val = e1000_config_mac_to_phy(hw);
  2577. if (ret_val) {
  2578. DEBUGOUT("Error configuring MAC to PHY settings\n");
  2579. return ret_val;
  2580. }
  2581. }
  2582. ret_val = e1000_config_fc_after_link_up(hw);
  2583. if (ret_val) {
  2584. DEBUGOUT("Error Configuring Flow Control\n");
  2585. return ret_val;
  2586. }
  2587. return E1000_SUCCESS;
  2588. }
  2589. /******************************************************************************
  2590. * Detects which PHY is present and setup the speed and duplex
  2591. *
  2592. * hw - Struct containing variables accessed by shared code
  2593. ******************************************************************************/
  2594. static int
  2595. e1000_setup_copper_link(struct eth_device *nic)
  2596. {
  2597. struct e1000_hw *hw = nic->priv;
  2598. int32_t ret_val;
  2599. uint16_t i;
  2600. uint16_t phy_data;
  2601. uint16_t reg_data;
  2602. DEBUGFUNC();
  2603. switch (hw->mac_type) {
  2604. case e1000_80003es2lan:
  2605. case e1000_ich8lan:
  2606. /* Set the mac to wait the maximum time between each
  2607. * iteration and increase the max iterations when
  2608. * polling the phy; this fixes erroneous timeouts at 10Mbps. */
  2609. ret_val = e1000_write_kmrn_reg(hw,
  2610. GG82563_REG(0x34, 4), 0xFFFF);
  2611. if (ret_val)
  2612. return ret_val;
  2613. ret_val = e1000_read_kmrn_reg(hw,
  2614. GG82563_REG(0x34, 9), &reg_data);
  2615. if (ret_val)
  2616. return ret_val;
  2617. reg_data |= 0x3F;
  2618. ret_val = e1000_write_kmrn_reg(hw,
  2619. GG82563_REG(0x34, 9), reg_data);
  2620. if (ret_val)
  2621. return ret_val;
  2622. default:
  2623. break;
  2624. }
  2625. /* Check if it is a valid PHY and set PHY mode if necessary. */
  2626. ret_val = e1000_copper_link_preconfig(hw);
  2627. if (ret_val)
  2628. return ret_val;
  2629. switch (hw->mac_type) {
  2630. case e1000_80003es2lan:
  2631. /* Kumeran registers are written-only */
  2632. reg_data =
  2633. E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
  2634. reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
  2635. ret_val = e1000_write_kmrn_reg(hw,
  2636. E1000_KUMCTRLSTA_OFFSET_INB_CTRL, reg_data);
  2637. if (ret_val)
  2638. return ret_val;
  2639. break;
  2640. default:
  2641. break;
  2642. }
  2643. if (hw->phy_type == e1000_phy_igp ||
  2644. hw->phy_type == e1000_phy_igp_3 ||
  2645. hw->phy_type == e1000_phy_igp_2) {
  2646. ret_val = e1000_copper_link_igp_setup(hw);
  2647. if (ret_val)
  2648. return ret_val;
  2649. } else if (hw->phy_type == e1000_phy_m88) {
  2650. ret_val = e1000_copper_link_mgp_setup(hw);
  2651. if (ret_val)
  2652. return ret_val;
  2653. } else if (hw->phy_type == e1000_phy_gg82563) {
  2654. ret_val = e1000_copper_link_ggp_setup(hw);
  2655. if (ret_val)
  2656. return ret_val;
  2657. }
  2658. /* always auto */
  2659. /* Setup autoneg and flow control advertisement
  2660. * and perform autonegotiation */
  2661. ret_val = e1000_copper_link_autoneg(hw);
  2662. if (ret_val)
  2663. return ret_val;
  2664. /* Check link status. Wait up to 100 microseconds for link to become
  2665. * valid.
  2666. */
  2667. for (i = 0; i < 10; i++) {
  2668. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2669. if (ret_val)
  2670. return ret_val;
  2671. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2672. if (ret_val)
  2673. return ret_val;
  2674. if (phy_data & MII_SR_LINK_STATUS) {
  2675. /* Config the MAC and PHY after link is up */
  2676. ret_val = e1000_copper_link_postconfig(hw);
  2677. if (ret_val)
  2678. return ret_val;
  2679. DEBUGOUT("Valid link established!!!\n");
  2680. return E1000_SUCCESS;
  2681. }
  2682. udelay(10);
  2683. }
  2684. DEBUGOUT("Unable to establish link!!!\n");
  2685. return E1000_SUCCESS;
  2686. }
  2687. /******************************************************************************
  2688. * Configures PHY autoneg and flow control advertisement settings
  2689. *
  2690. * hw - Struct containing variables accessed by shared code
  2691. ******************************************************************************/
  2692. int32_t
  2693. e1000_phy_setup_autoneg(struct e1000_hw *hw)
  2694. {
  2695. int32_t ret_val;
  2696. uint16_t mii_autoneg_adv_reg;
  2697. uint16_t mii_1000t_ctrl_reg;
  2698. DEBUGFUNC();
  2699. /* Read the MII Auto-Neg Advertisement Register (Address 4). */
  2700. ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
  2701. if (ret_val)
  2702. return ret_val;
  2703. if (hw->phy_type != e1000_phy_ife) {
  2704. /* Read the MII 1000Base-T Control Register (Address 9). */
  2705. ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
  2706. &mii_1000t_ctrl_reg);
  2707. if (ret_val)
  2708. return ret_val;
  2709. } else
  2710. mii_1000t_ctrl_reg = 0;
  2711. /* Need to parse both autoneg_advertised and fc and set up
  2712. * the appropriate PHY registers. First we will parse for
  2713. * autoneg_advertised software override. Since we can advertise
  2714. * a plethora of combinations, we need to check each bit
  2715. * individually.
  2716. */
  2717. /* First we clear all the 10/100 mb speed bits in the Auto-Neg
  2718. * Advertisement Register (Address 4) and the 1000 mb speed bits in
  2719. * the 1000Base-T Control Register (Address 9).
  2720. */
  2721. mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
  2722. mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
  2723. DEBUGOUT("autoneg_advertised %x\n", hw->autoneg_advertised);
  2724. /* Do we want to advertise 10 Mb Half Duplex? */
  2725. if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
  2726. DEBUGOUT("Advertise 10mb Half duplex\n");
  2727. mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
  2728. }
  2729. /* Do we want to advertise 10 Mb Full Duplex? */
  2730. if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
  2731. DEBUGOUT("Advertise 10mb Full duplex\n");
  2732. mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
  2733. }
  2734. /* Do we want to advertise 100 Mb Half Duplex? */
  2735. if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
  2736. DEBUGOUT("Advertise 100mb Half duplex\n");
  2737. mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
  2738. }
  2739. /* Do we want to advertise 100 Mb Full Duplex? */
  2740. if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
  2741. DEBUGOUT("Advertise 100mb Full duplex\n");
  2742. mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
  2743. }
  2744. /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
  2745. if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
  2746. DEBUGOUT
  2747. ("Advertise 1000mb Half duplex requested, request denied!\n");
  2748. }
  2749. /* Do we want to advertise 1000 Mb Full Duplex? */
  2750. if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
  2751. DEBUGOUT("Advertise 1000mb Full duplex\n");
  2752. mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
  2753. }
  2754. /* Check for a software override of the flow control settings, and
  2755. * setup the PHY advertisement registers accordingly. If
  2756. * auto-negotiation is enabled, then software will have to set the
  2757. * "PAUSE" bits to the correct value in the Auto-Negotiation
  2758. * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
  2759. *
  2760. * The possible values of the "fc" parameter are:
  2761. * 0: Flow control is completely disabled
  2762. * 1: Rx flow control is enabled (we can receive pause frames
  2763. * but not send pause frames).
  2764. * 2: Tx flow control is enabled (we can send pause frames
  2765. * but we do not support receiving pause frames).
  2766. * 3: Both Rx and TX flow control (symmetric) are enabled.
  2767. * other: No software override. The flow control configuration
  2768. * in the EEPROM is used.
  2769. */
  2770. switch (hw->fc) {
  2771. case e1000_fc_none: /* 0 */
  2772. /* Flow control (RX & TX) is completely disabled by a
  2773. * software over-ride.
  2774. */
  2775. mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  2776. break;
  2777. case e1000_fc_rx_pause: /* 1 */
  2778. /* RX Flow control is enabled, and TX Flow control is
  2779. * disabled, by a software over-ride.
  2780. */
  2781. /* Since there really isn't a way to advertise that we are
  2782. * capable of RX Pause ONLY, we will advertise that we
  2783. * support both symmetric and asymmetric RX PAUSE. Later
  2784. * (in e1000_config_fc_after_link_up) we will disable the
  2785. *hw's ability to send PAUSE frames.
  2786. */
  2787. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  2788. break;
  2789. case e1000_fc_tx_pause: /* 2 */
  2790. /* TX Flow control is enabled, and RX Flow control is
  2791. * disabled, by a software over-ride.
  2792. */
  2793. mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
  2794. mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
  2795. break;
  2796. case e1000_fc_full: /* 3 */
  2797. /* Flow control (both RX and TX) is enabled by a software
  2798. * over-ride.
  2799. */
  2800. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  2801. break;
  2802. default:
  2803. DEBUGOUT("Flow control param set incorrectly\n");
  2804. return -E1000_ERR_CONFIG;
  2805. }
  2806. ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
  2807. if (ret_val)
  2808. return ret_val;
  2809. DEBUGOUT("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
  2810. if (hw->phy_type != e1000_phy_ife) {
  2811. ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
  2812. mii_1000t_ctrl_reg);
  2813. if (ret_val)
  2814. return ret_val;
  2815. }
  2816. return E1000_SUCCESS;
  2817. }
  2818. /******************************************************************************
  2819. * Sets the collision distance in the Transmit Control register
  2820. *
  2821. * hw - Struct containing variables accessed by shared code
  2822. *
  2823. * Link should have been established previously. Reads the speed and duplex
  2824. * information from the Device Status register.
  2825. ******************************************************************************/
  2826. static void
  2827. e1000_config_collision_dist(struct e1000_hw *hw)
  2828. {
  2829. uint32_t tctl, coll_dist;
  2830. DEBUGFUNC();
  2831. if (hw->mac_type < e1000_82543)
  2832. coll_dist = E1000_COLLISION_DISTANCE_82542;
  2833. else
  2834. coll_dist = E1000_COLLISION_DISTANCE;
  2835. tctl = E1000_READ_REG(hw, TCTL);
  2836. tctl &= ~E1000_TCTL_COLD;
  2837. tctl |= coll_dist << E1000_COLD_SHIFT;
  2838. E1000_WRITE_REG(hw, TCTL, tctl);
  2839. E1000_WRITE_FLUSH(hw);
  2840. }
  2841. /******************************************************************************
  2842. * Sets MAC speed and duplex settings to reflect the those in the PHY
  2843. *
  2844. * hw - Struct containing variables accessed by shared code
  2845. * mii_reg - data to write to the MII control register
  2846. *
  2847. * The contents of the PHY register containing the needed information need to
  2848. * be passed in.
  2849. ******************************************************************************/
  2850. static int
  2851. e1000_config_mac_to_phy(struct e1000_hw *hw)
  2852. {
  2853. uint32_t ctrl;
  2854. uint16_t phy_data;
  2855. DEBUGFUNC();
  2856. /* Read the Device Control Register and set the bits to Force Speed
  2857. * and Duplex.
  2858. */
  2859. ctrl = E1000_READ_REG(hw, CTRL);
  2860. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  2861. ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
  2862. /* Set up duplex in the Device Control and Transmit Control
  2863. * registers depending on negotiated values.
  2864. */
  2865. if (e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data) < 0) {
  2866. DEBUGOUT("PHY Read Error\n");
  2867. return -E1000_ERR_PHY;
  2868. }
  2869. if (phy_data & M88E1000_PSSR_DPLX)
  2870. ctrl |= E1000_CTRL_FD;
  2871. else
  2872. ctrl &= ~E1000_CTRL_FD;
  2873. e1000_config_collision_dist(hw);
  2874. /* Set up speed in the Device Control register depending on
  2875. * negotiated values.
  2876. */
  2877. if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
  2878. ctrl |= E1000_CTRL_SPD_1000;
  2879. else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
  2880. ctrl |= E1000_CTRL_SPD_100;
  2881. /* Write the configured values back to the Device Control Reg. */
  2882. E1000_WRITE_REG(hw, CTRL, ctrl);
  2883. return 0;
  2884. }
  2885. /******************************************************************************
  2886. * Forces the MAC's flow control settings.
  2887. *
  2888. * hw - Struct containing variables accessed by shared code
  2889. *
  2890. * Sets the TFCE and RFCE bits in the device control register to reflect
  2891. * the adapter settings. TFCE and RFCE need to be explicitly set by
  2892. * software when a Copper PHY is used because autonegotiation is managed
  2893. * by the PHY rather than the MAC. Software must also configure these
  2894. * bits when link is forced on a fiber connection.
  2895. *****************************************************************************/
  2896. static int
  2897. e1000_force_mac_fc(struct e1000_hw *hw)
  2898. {
  2899. uint32_t ctrl;
  2900. DEBUGFUNC();
  2901. /* Get the current configuration of the Device Control Register */
  2902. ctrl = E1000_READ_REG(hw, CTRL);
  2903. /* Because we didn't get link via the internal auto-negotiation
  2904. * mechanism (we either forced link or we got link via PHY
  2905. * auto-neg), we have to manually enable/disable transmit an
  2906. * receive flow control.
  2907. *
  2908. * The "Case" statement below enables/disable flow control
  2909. * according to the "hw->fc" parameter.
  2910. *
  2911. * The possible values of the "fc" parameter are:
  2912. * 0: Flow control is completely disabled
  2913. * 1: Rx flow control is enabled (we can receive pause
  2914. * frames but not send pause frames).
  2915. * 2: Tx flow control is enabled (we can send pause frames
  2916. * frames but we do not receive pause frames).
  2917. * 3: Both Rx and TX flow control (symmetric) is enabled.
  2918. * other: No other values should be possible at this point.
  2919. */
  2920. switch (hw->fc) {
  2921. case e1000_fc_none:
  2922. ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
  2923. break;
  2924. case e1000_fc_rx_pause:
  2925. ctrl &= (~E1000_CTRL_TFCE);
  2926. ctrl |= E1000_CTRL_RFCE;
  2927. break;
  2928. case e1000_fc_tx_pause:
  2929. ctrl &= (~E1000_CTRL_RFCE);
  2930. ctrl |= E1000_CTRL_TFCE;
  2931. break;
  2932. case e1000_fc_full:
  2933. ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
  2934. break;
  2935. default:
  2936. DEBUGOUT("Flow control param set incorrectly\n");
  2937. return -E1000_ERR_CONFIG;
  2938. }
  2939. /* Disable TX Flow Control for 82542 (rev 2.0) */
  2940. if (hw->mac_type == e1000_82542_rev2_0)
  2941. ctrl &= (~E1000_CTRL_TFCE);
  2942. E1000_WRITE_REG(hw, CTRL, ctrl);
  2943. return 0;
  2944. }
  2945. /******************************************************************************
  2946. * Configures flow control settings after link is established
  2947. *
  2948. * hw - Struct containing variables accessed by shared code
  2949. *
  2950. * Should be called immediately after a valid link has been established.
  2951. * Forces MAC flow control settings if link was forced. When in MII/GMII mode
  2952. * and autonegotiation is enabled, the MAC flow control settings will be set
  2953. * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
  2954. * and RFCE bits will be automaticaly set to the negotiated flow control mode.
  2955. *****************************************************************************/
  2956. static int32_t
  2957. e1000_config_fc_after_link_up(struct e1000_hw *hw)
  2958. {
  2959. int32_t ret_val;
  2960. uint16_t mii_status_reg;
  2961. uint16_t mii_nway_adv_reg;
  2962. uint16_t mii_nway_lp_ability_reg;
  2963. uint16_t speed;
  2964. uint16_t duplex;
  2965. DEBUGFUNC();
  2966. /* Check for the case where we have fiber media and auto-neg failed
  2967. * so we had to force link. In this case, we need to force the
  2968. * configuration of the MAC to match the "fc" parameter.
  2969. */
  2970. if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed))
  2971. || ((hw->media_type == e1000_media_type_internal_serdes)
  2972. && (hw->autoneg_failed))
  2973. || ((hw->media_type == e1000_media_type_copper)
  2974. && (!hw->autoneg))) {
  2975. ret_val = e1000_force_mac_fc(hw);
  2976. if (ret_val < 0) {
  2977. DEBUGOUT("Error forcing flow control settings\n");
  2978. return ret_val;
  2979. }
  2980. }
  2981. /* Check for the case where we have copper media and auto-neg is
  2982. * enabled. In this case, we need to check and see if Auto-Neg
  2983. * has completed, and if so, how the PHY and link partner has
  2984. * flow control configured.
  2985. */
  2986. if (hw->media_type == e1000_media_type_copper) {
  2987. /* Read the MII Status Register and check to see if AutoNeg
  2988. * has completed. We read this twice because this reg has
  2989. * some "sticky" (latched) bits.
  2990. */
  2991. if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
  2992. DEBUGOUT("PHY Read Error \n");
  2993. return -E1000_ERR_PHY;
  2994. }
  2995. if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
  2996. DEBUGOUT("PHY Read Error \n");
  2997. return -E1000_ERR_PHY;
  2998. }
  2999. if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
  3000. /* The AutoNeg process has completed, so we now need to
  3001. * read both the Auto Negotiation Advertisement Register
  3002. * (Address 4) and the Auto_Negotiation Base Page Ability
  3003. * Register (Address 5) to determine how flow control was
  3004. * negotiated.
  3005. */
  3006. if (e1000_read_phy_reg
  3007. (hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg) < 0) {
  3008. DEBUGOUT("PHY Read Error\n");
  3009. return -E1000_ERR_PHY;
  3010. }
  3011. if (e1000_read_phy_reg
  3012. (hw, PHY_LP_ABILITY,
  3013. &mii_nway_lp_ability_reg) < 0) {
  3014. DEBUGOUT("PHY Read Error\n");
  3015. return -E1000_ERR_PHY;
  3016. }
  3017. /* Two bits in the Auto Negotiation Advertisement Register
  3018. * (Address 4) and two bits in the Auto Negotiation Base
  3019. * Page Ability Register (Address 5) determine flow control
  3020. * for both the PHY and the link partner. The following
  3021. * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
  3022. * 1999, describes these PAUSE resolution bits and how flow
  3023. * control is determined based upon these settings.
  3024. * NOTE: DC = Don't Care
  3025. *
  3026. * LOCAL DEVICE | LINK PARTNER
  3027. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
  3028. *-------|---------|-------|---------|--------------------
  3029. * 0 | 0 | DC | DC | e1000_fc_none
  3030. * 0 | 1 | 0 | DC | e1000_fc_none
  3031. * 0 | 1 | 1 | 0 | e1000_fc_none
  3032. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  3033. * 1 | 0 | 0 | DC | e1000_fc_none
  3034. * 1 | DC | 1 | DC | e1000_fc_full
  3035. * 1 | 1 | 0 | 0 | e1000_fc_none
  3036. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  3037. *
  3038. */
  3039. /* Are both PAUSE bits set to 1? If so, this implies
  3040. * Symmetric Flow Control is enabled at both ends. The
  3041. * ASM_DIR bits are irrelevant per the spec.
  3042. *
  3043. * For Symmetric Flow Control:
  3044. *
  3045. * LOCAL DEVICE | LINK PARTNER
  3046. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  3047. *-------|---------|-------|---------|--------------------
  3048. * 1 | DC | 1 | DC | e1000_fc_full
  3049. *
  3050. */
  3051. if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  3052. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
  3053. /* Now we need to check if the user selected RX ONLY
  3054. * of pause frames. In this case, we had to advertise
  3055. * FULL flow control because we could not advertise RX
  3056. * ONLY. Hence, we must now check to see if we need to
  3057. * turn OFF the TRANSMISSION of PAUSE frames.
  3058. */
  3059. if (hw->original_fc == e1000_fc_full) {
  3060. hw->fc = e1000_fc_full;
  3061. DEBUGOUT("Flow Control = FULL.\r\n");
  3062. } else {
  3063. hw->fc = e1000_fc_rx_pause;
  3064. DEBUGOUT
  3065. ("Flow Control = RX PAUSE frames only.\r\n");
  3066. }
  3067. }
  3068. /* For receiving PAUSE frames ONLY.
  3069. *
  3070. * LOCAL DEVICE | LINK PARTNER
  3071. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  3072. *-------|---------|-------|---------|--------------------
  3073. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  3074. *
  3075. */
  3076. else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  3077. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  3078. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  3079. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
  3080. {
  3081. hw->fc = e1000_fc_tx_pause;
  3082. DEBUGOUT
  3083. ("Flow Control = TX PAUSE frames only.\r\n");
  3084. }
  3085. /* For transmitting PAUSE frames ONLY.
  3086. *
  3087. * LOCAL DEVICE | LINK PARTNER
  3088. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  3089. *-------|---------|-------|---------|--------------------
  3090. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  3091. *
  3092. */
  3093. else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  3094. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  3095. !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  3096. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
  3097. {
  3098. hw->fc = e1000_fc_rx_pause;
  3099. DEBUGOUT
  3100. ("Flow Control = RX PAUSE frames only.\r\n");
  3101. }
  3102. /* Per the IEEE spec, at this point flow control should be
  3103. * disabled. However, we want to consider that we could
  3104. * be connected to a legacy switch that doesn't advertise
  3105. * desired flow control, but can be forced on the link
  3106. * partner. So if we advertised no flow control, that is
  3107. * what we will resolve to. If we advertised some kind of
  3108. * receive capability (Rx Pause Only or Full Flow Control)
  3109. * and the link partner advertised none, we will configure
  3110. * ourselves to enable Rx Flow Control only. We can do
  3111. * this safely for two reasons: If the link partner really
  3112. * didn't want flow control enabled, and we enable Rx, no
  3113. * harm done since we won't be receiving any PAUSE frames
  3114. * anyway. If the intent on the link partner was to have
  3115. * flow control enabled, then by us enabling RX only, we
  3116. * can at least receive pause frames and process them.
  3117. * This is a good idea because in most cases, since we are
  3118. * predominantly a server NIC, more times than not we will
  3119. * be asked to delay transmission of packets than asking
  3120. * our link partner to pause transmission of frames.
  3121. */
  3122. else if (hw->original_fc == e1000_fc_none ||
  3123. hw->original_fc == e1000_fc_tx_pause) {
  3124. hw->fc = e1000_fc_none;
  3125. DEBUGOUT("Flow Control = NONE.\r\n");
  3126. } else {
  3127. hw->fc = e1000_fc_rx_pause;
  3128. DEBUGOUT
  3129. ("Flow Control = RX PAUSE frames only.\r\n");
  3130. }
  3131. /* Now we need to do one last check... If we auto-
  3132. * negotiated to HALF DUPLEX, flow control should not be
  3133. * enabled per IEEE 802.3 spec.
  3134. */
  3135. e1000_get_speed_and_duplex(hw, &speed, &duplex);
  3136. if (duplex == HALF_DUPLEX)
  3137. hw->fc = e1000_fc_none;
  3138. /* Now we call a subroutine to actually force the MAC
  3139. * controller to use the correct flow control settings.
  3140. */
  3141. ret_val = e1000_force_mac_fc(hw);
  3142. if (ret_val < 0) {
  3143. DEBUGOUT
  3144. ("Error forcing flow control settings\n");
  3145. return ret_val;
  3146. }
  3147. } else {
  3148. DEBUGOUT
  3149. ("Copper PHY and Auto Neg has not completed.\r\n");
  3150. }
  3151. }
  3152. return E1000_SUCCESS;
  3153. }
  3154. /******************************************************************************
  3155. * Checks to see if the link status of the hardware has changed.
  3156. *
  3157. * hw - Struct containing variables accessed by shared code
  3158. *
  3159. * Called by any function that needs to check the link status of the adapter.
  3160. *****************************************************************************/
  3161. static int
  3162. e1000_check_for_link(struct eth_device *nic)
  3163. {
  3164. struct e1000_hw *hw = nic->priv;
  3165. uint32_t rxcw;
  3166. uint32_t ctrl;
  3167. uint32_t status;
  3168. uint32_t rctl;
  3169. uint32_t signal;
  3170. int32_t ret_val;
  3171. uint16_t phy_data;
  3172. uint16_t lp_capability;
  3173. DEBUGFUNC();
  3174. /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
  3175. * set when the optics detect a signal. On older adapters, it will be
  3176. * cleared when there is a signal
  3177. */
  3178. ctrl = E1000_READ_REG(hw, CTRL);
  3179. if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
  3180. signal = E1000_CTRL_SWDPIN1;
  3181. else
  3182. signal = 0;
  3183. status = E1000_READ_REG(hw, STATUS);
  3184. rxcw = E1000_READ_REG(hw, RXCW);
  3185. DEBUGOUT("ctrl: %#08x status %#08x rxcw %#08x\n", ctrl, status, rxcw);
  3186. /* If we have a copper PHY then we only want to go out to the PHY
  3187. * registers to see if Auto-Neg has completed and/or if our link
  3188. * status has changed. The get_link_status flag will be set if we
  3189. * receive a Link Status Change interrupt or we have Rx Sequence
  3190. * Errors.
  3191. */
  3192. if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
  3193. /* First we want to see if the MII Status Register reports
  3194. * link. If so, then we want to get the current speed/duplex
  3195. * of the PHY.
  3196. * Read the register twice since the link bit is sticky.
  3197. */
  3198. if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
  3199. DEBUGOUT("PHY Read Error\n");
  3200. return -E1000_ERR_PHY;
  3201. }
  3202. if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
  3203. DEBUGOUT("PHY Read Error\n");
  3204. return -E1000_ERR_PHY;
  3205. }
  3206. if (phy_data & MII_SR_LINK_STATUS) {
  3207. hw->get_link_status = FALSE;
  3208. } else {
  3209. /* No link detected */
  3210. return -E1000_ERR_NOLINK;
  3211. }
  3212. /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
  3213. * have Si on board that is 82544 or newer, Auto
  3214. * Speed Detection takes care of MAC speed/duplex
  3215. * configuration. So we only need to configure Collision
  3216. * Distance in the MAC. Otherwise, we need to force
  3217. * speed/duplex on the MAC to the current PHY speed/duplex
  3218. * settings.
  3219. */
  3220. if (hw->mac_type >= e1000_82544)
  3221. e1000_config_collision_dist(hw);
  3222. else {
  3223. ret_val = e1000_config_mac_to_phy(hw);
  3224. if (ret_val < 0) {
  3225. DEBUGOUT
  3226. ("Error configuring MAC to PHY settings\n");
  3227. return ret_val;
  3228. }
  3229. }
  3230. /* Configure Flow Control now that Auto-Neg has completed. First, we
  3231. * need to restore the desired flow control settings because we may
  3232. * have had to re-autoneg with a different link partner.
  3233. */
  3234. ret_val = e1000_config_fc_after_link_up(hw);
  3235. if (ret_val < 0) {
  3236. DEBUGOUT("Error configuring flow control\n");
  3237. return ret_val;
  3238. }
  3239. /* At this point we know that we are on copper and we have
  3240. * auto-negotiated link. These are conditions for checking the link
  3241. * parter capability register. We use the link partner capability to
  3242. * determine if TBI Compatibility needs to be turned on or off. If
  3243. * the link partner advertises any speed in addition to Gigabit, then
  3244. * we assume that they are GMII-based, and TBI compatibility is not
  3245. * needed. If no other speeds are advertised, we assume the link
  3246. * partner is TBI-based, and we turn on TBI Compatibility.
  3247. */
  3248. if (hw->tbi_compatibility_en) {
  3249. if (e1000_read_phy_reg
  3250. (hw, PHY_LP_ABILITY, &lp_capability) < 0) {
  3251. DEBUGOUT("PHY Read Error\n");
  3252. return -E1000_ERR_PHY;
  3253. }
  3254. if (lp_capability & (NWAY_LPAR_10T_HD_CAPS |
  3255. NWAY_LPAR_10T_FD_CAPS |
  3256. NWAY_LPAR_100TX_HD_CAPS |
  3257. NWAY_LPAR_100TX_FD_CAPS |
  3258. NWAY_LPAR_100T4_CAPS)) {
  3259. /* If our link partner advertises anything in addition to
  3260. * gigabit, we do not need to enable TBI compatibility.
  3261. */
  3262. if (hw->tbi_compatibility_on) {
  3263. /* If we previously were in the mode, turn it off. */
  3264. rctl = E1000_READ_REG(hw, RCTL);
  3265. rctl &= ~E1000_RCTL_SBP;
  3266. E1000_WRITE_REG(hw, RCTL, rctl);
  3267. hw->tbi_compatibility_on = FALSE;
  3268. }
  3269. } else {
  3270. /* If TBI compatibility is was previously off, turn it on. For
  3271. * compatibility with a TBI link partner, we will store bad
  3272. * packets. Some frames have an additional byte on the end and
  3273. * will look like CRC errors to to the hardware.
  3274. */
  3275. if (!hw->tbi_compatibility_on) {
  3276. hw->tbi_compatibility_on = TRUE;
  3277. rctl = E1000_READ_REG(hw, RCTL);
  3278. rctl |= E1000_RCTL_SBP;
  3279. E1000_WRITE_REG(hw, RCTL, rctl);
  3280. }
  3281. }
  3282. }
  3283. }
  3284. /* If we don't have link (auto-negotiation failed or link partner cannot
  3285. * auto-negotiate), the cable is plugged in (we have signal), and our
  3286. * link partner is not trying to auto-negotiate with us (we are receiving
  3287. * idles or data), we need to force link up. We also need to give
  3288. * auto-negotiation time to complete, in case the cable was just plugged
  3289. * in. The autoneg_failed flag does this.
  3290. */
  3291. else if ((hw->media_type == e1000_media_type_fiber) &&
  3292. (!(status & E1000_STATUS_LU)) &&
  3293. ((ctrl & E1000_CTRL_SWDPIN1) == signal) &&
  3294. (!(rxcw & E1000_RXCW_C))) {
  3295. if (hw->autoneg_failed == 0) {
  3296. hw->autoneg_failed = 1;
  3297. return 0;
  3298. }
  3299. DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
  3300. /* Disable auto-negotiation in the TXCW register */
  3301. E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
  3302. /* Force link-up and also force full-duplex. */
  3303. ctrl = E1000_READ_REG(hw, CTRL);
  3304. ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
  3305. E1000_WRITE_REG(hw, CTRL, ctrl);
  3306. /* Configure Flow Control after forcing link up. */
  3307. ret_val = e1000_config_fc_after_link_up(hw);
  3308. if (ret_val < 0) {
  3309. DEBUGOUT("Error configuring flow control\n");
  3310. return ret_val;
  3311. }
  3312. }
  3313. /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
  3314. * auto-negotiation in the TXCW register and disable forced link in the
  3315. * Device Control register in an attempt to auto-negotiate with our link
  3316. * partner.
  3317. */
  3318. else if ((hw->media_type == e1000_media_type_fiber) &&
  3319. (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
  3320. DEBUGOUT
  3321. ("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
  3322. E1000_WRITE_REG(hw, TXCW, hw->txcw);
  3323. E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
  3324. }
  3325. return 0;
  3326. }
  3327. /******************************************************************************
  3328. * Configure the MAC-to-PHY interface for 10/100Mbps
  3329. *
  3330. * hw - Struct containing variables accessed by shared code
  3331. ******************************************************************************/
  3332. static int32_t
  3333. e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
  3334. {
  3335. int32_t ret_val = E1000_SUCCESS;
  3336. uint32_t tipg;
  3337. uint16_t reg_data;
  3338. DEBUGFUNC();
  3339. reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
  3340. ret_val = e1000_write_kmrn_reg(hw,
  3341. E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data);
  3342. if (ret_val)
  3343. return ret_val;
  3344. /* Configure Transmit Inter-Packet Gap */
  3345. tipg = E1000_READ_REG(hw, TIPG);
  3346. tipg &= ~E1000_TIPG_IPGT_MASK;
  3347. tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
  3348. E1000_WRITE_REG(hw, TIPG, tipg);
  3349. ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
  3350. if (ret_val)
  3351. return ret_val;
  3352. if (duplex == HALF_DUPLEX)
  3353. reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
  3354. else
  3355. reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
  3356. ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
  3357. return ret_val;
  3358. }
  3359. static int32_t
  3360. e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
  3361. {
  3362. int32_t ret_val = E1000_SUCCESS;
  3363. uint16_t reg_data;
  3364. uint32_t tipg;
  3365. DEBUGFUNC();
  3366. reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
  3367. ret_val = e1000_write_kmrn_reg(hw,
  3368. E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data);
  3369. if (ret_val)
  3370. return ret_val;
  3371. /* Configure Transmit Inter-Packet Gap */
  3372. tipg = E1000_READ_REG(hw, TIPG);
  3373. tipg &= ~E1000_TIPG_IPGT_MASK;
  3374. tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
  3375. E1000_WRITE_REG(hw, TIPG, tipg);
  3376. ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
  3377. if (ret_val)
  3378. return ret_val;
  3379. reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
  3380. ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
  3381. return ret_val;
  3382. }
  3383. /******************************************************************************
  3384. * Detects the current speed and duplex settings of the hardware.
  3385. *
  3386. * hw - Struct containing variables accessed by shared code
  3387. * speed - Speed of the connection
  3388. * duplex - Duplex setting of the connection
  3389. *****************************************************************************/
  3390. static int
  3391. e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t *speed,
  3392. uint16_t *duplex)
  3393. {
  3394. uint32_t status;
  3395. int32_t ret_val;
  3396. uint16_t phy_data;
  3397. DEBUGFUNC();
  3398. if (hw->mac_type >= e1000_82543) {
  3399. status = E1000_READ_REG(hw, STATUS);
  3400. if (status & E1000_STATUS_SPEED_1000) {
  3401. *speed = SPEED_1000;
  3402. DEBUGOUT("1000 Mbs, ");
  3403. } else if (status & E1000_STATUS_SPEED_100) {
  3404. *speed = SPEED_100;
  3405. DEBUGOUT("100 Mbs, ");
  3406. } else {
  3407. *speed = SPEED_10;
  3408. DEBUGOUT("10 Mbs, ");
  3409. }
  3410. if (status & E1000_STATUS_FD) {
  3411. *duplex = FULL_DUPLEX;
  3412. DEBUGOUT("Full Duplex\r\n");
  3413. } else {
  3414. *duplex = HALF_DUPLEX;
  3415. DEBUGOUT(" Half Duplex\r\n");
  3416. }
  3417. } else {
  3418. DEBUGOUT("1000 Mbs, Full Duplex\r\n");
  3419. *speed = SPEED_1000;
  3420. *duplex = FULL_DUPLEX;
  3421. }
  3422. /* IGP01 PHY may advertise full duplex operation after speed downgrade
  3423. * even if it is operating at half duplex. Here we set the duplex
  3424. * settings to match the duplex in the link partner's capabilities.
  3425. */
  3426. if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
  3427. ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
  3428. if (ret_val)
  3429. return ret_val;
  3430. if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
  3431. *duplex = HALF_DUPLEX;
  3432. else {
  3433. ret_val = e1000_read_phy_reg(hw,
  3434. PHY_LP_ABILITY, &phy_data);
  3435. if (ret_val)
  3436. return ret_val;
  3437. if ((*speed == SPEED_100 &&
  3438. !(phy_data & NWAY_LPAR_100TX_FD_CAPS))
  3439. || (*speed == SPEED_10
  3440. && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
  3441. *duplex = HALF_DUPLEX;
  3442. }
  3443. }
  3444. if ((hw->mac_type == e1000_80003es2lan) &&
  3445. (hw->media_type == e1000_media_type_copper)) {
  3446. if (*speed == SPEED_1000)
  3447. ret_val = e1000_configure_kmrn_for_1000(hw);
  3448. else
  3449. ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
  3450. if (ret_val)
  3451. return ret_val;
  3452. }
  3453. return E1000_SUCCESS;
  3454. }
  3455. /******************************************************************************
  3456. * Blocks until autoneg completes or times out (~4.5 seconds)
  3457. *
  3458. * hw - Struct containing variables accessed by shared code
  3459. ******************************************************************************/
  3460. static int
  3461. e1000_wait_autoneg(struct e1000_hw *hw)
  3462. {
  3463. uint16_t i;
  3464. uint16_t phy_data;
  3465. DEBUGFUNC();
  3466. DEBUGOUT("Waiting for Auto-Neg to complete.\n");
  3467. /* We will wait for autoneg to complete or 4.5 seconds to expire. */
  3468. for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
  3469. /* Read the MII Status Register and wait for Auto-Neg
  3470. * Complete bit to be set.
  3471. */
  3472. if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
  3473. DEBUGOUT("PHY Read Error\n");
  3474. return -E1000_ERR_PHY;
  3475. }
  3476. if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
  3477. DEBUGOUT("PHY Read Error\n");
  3478. return -E1000_ERR_PHY;
  3479. }
  3480. if (phy_data & MII_SR_AUTONEG_COMPLETE) {
  3481. DEBUGOUT("Auto-Neg complete.\n");
  3482. return 0;
  3483. }
  3484. mdelay(100);
  3485. }
  3486. DEBUGOUT("Auto-Neg timedout.\n");
  3487. return -E1000_ERR_TIMEOUT;
  3488. }
  3489. /******************************************************************************
  3490. * Raises the Management Data Clock
  3491. *
  3492. * hw - Struct containing variables accessed by shared code
  3493. * ctrl - Device control register's current value
  3494. ******************************************************************************/
  3495. static void
  3496. e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
  3497. {
  3498. /* Raise the clock input to the Management Data Clock (by setting the MDC
  3499. * bit), and then delay 2 microseconds.
  3500. */
  3501. E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
  3502. E1000_WRITE_FLUSH(hw);
  3503. udelay(2);
  3504. }
  3505. /******************************************************************************
  3506. * Lowers the Management Data Clock
  3507. *
  3508. * hw - Struct containing variables accessed by shared code
  3509. * ctrl - Device control register's current value
  3510. ******************************************************************************/
  3511. static void
  3512. e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
  3513. {
  3514. /* Lower the clock input to the Management Data Clock (by clearing the MDC
  3515. * bit), and then delay 2 microseconds.
  3516. */
  3517. E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
  3518. E1000_WRITE_FLUSH(hw);
  3519. udelay(2);
  3520. }
  3521. /******************************************************************************
  3522. * Shifts data bits out to the PHY
  3523. *
  3524. * hw - Struct containing variables accessed by shared code
  3525. * data - Data to send out to the PHY
  3526. * count - Number of bits to shift out
  3527. *
  3528. * Bits are shifted out in MSB to LSB order.
  3529. ******************************************************************************/
  3530. static void
  3531. e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data, uint16_t count)
  3532. {
  3533. uint32_t ctrl;
  3534. uint32_t mask;
  3535. /* We need to shift "count" number of bits out to the PHY. So, the value
  3536. * in the "data" parameter will be shifted out to the PHY one bit at a
  3537. * time. In order to do this, "data" must be broken down into bits.
  3538. */
  3539. mask = 0x01;
  3540. mask <<= (count - 1);
  3541. ctrl = E1000_READ_REG(hw, CTRL);
  3542. /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
  3543. ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
  3544. while (mask) {
  3545. /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
  3546. * then raising and lowering the Management Data Clock. A "0" is
  3547. * shifted out to the PHY by setting the MDIO bit to "0" and then
  3548. * raising and lowering the clock.
  3549. */
  3550. if (data & mask)
  3551. ctrl |= E1000_CTRL_MDIO;
  3552. else
  3553. ctrl &= ~E1000_CTRL_MDIO;
  3554. E1000_WRITE_REG(hw, CTRL, ctrl);
  3555. E1000_WRITE_FLUSH(hw);
  3556. udelay(2);
  3557. e1000_raise_mdi_clk(hw, &ctrl);
  3558. e1000_lower_mdi_clk(hw, &ctrl);
  3559. mask = mask >> 1;
  3560. }
  3561. }
  3562. /******************************************************************************
  3563. * Shifts data bits in from the PHY
  3564. *
  3565. * hw - Struct containing variables accessed by shared code
  3566. *
  3567. * Bits are shifted in in MSB to LSB order.
  3568. ******************************************************************************/
  3569. static uint16_t
  3570. e1000_shift_in_mdi_bits(struct e1000_hw *hw)
  3571. {
  3572. uint32_t ctrl;
  3573. uint16_t data = 0;
  3574. uint8_t i;
  3575. /* In order to read a register from the PHY, we need to shift in a total
  3576. * of 18 bits from the PHY. The first two bit (turnaround) times are used
  3577. * to avoid contention on the MDIO pin when a read operation is performed.
  3578. * These two bits are ignored by us and thrown away. Bits are "shifted in"
  3579. * by raising the input to the Management Data Clock (setting the MDC bit),
  3580. * and then reading the value of the MDIO bit.
  3581. */
  3582. ctrl = E1000_READ_REG(hw, CTRL);
  3583. /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
  3584. ctrl &= ~E1000_CTRL_MDIO_DIR;
  3585. ctrl &= ~E1000_CTRL_MDIO;
  3586. E1000_WRITE_REG(hw, CTRL, ctrl);
  3587. E1000_WRITE_FLUSH(hw);
  3588. /* Raise and Lower the clock before reading in the data. This accounts for
  3589. * the turnaround bits. The first clock occurred when we clocked out the
  3590. * last bit of the Register Address.
  3591. */
  3592. e1000_raise_mdi_clk(hw, &ctrl);
  3593. e1000_lower_mdi_clk(hw, &ctrl);
  3594. for (data = 0, i = 0; i < 16; i++) {
  3595. data = data << 1;
  3596. e1000_raise_mdi_clk(hw, &ctrl);
  3597. ctrl = E1000_READ_REG(hw, CTRL);
  3598. /* Check to see if we shifted in a "1". */
  3599. if (ctrl & E1000_CTRL_MDIO)
  3600. data |= 1;
  3601. e1000_lower_mdi_clk(hw, &ctrl);
  3602. }
  3603. e1000_raise_mdi_clk(hw, &ctrl);
  3604. e1000_lower_mdi_clk(hw, &ctrl);
  3605. return data;
  3606. }
  3607. /*****************************************************************************
  3608. * Reads the value from a PHY register
  3609. *
  3610. * hw - Struct containing variables accessed by shared code
  3611. * reg_addr - address of the PHY register to read
  3612. ******************************************************************************/
  3613. static int
  3614. e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t * phy_data)
  3615. {
  3616. uint32_t i;
  3617. uint32_t mdic = 0;
  3618. const uint32_t phy_addr = 1;
  3619. if (reg_addr > MAX_PHY_REG_ADDRESS) {
  3620. DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
  3621. return -E1000_ERR_PARAM;
  3622. }
  3623. if (hw->mac_type > e1000_82543) {
  3624. /* Set up Op-code, Phy Address, and register address in the MDI
  3625. * Control register. The MAC will take care of interfacing with the
  3626. * PHY to retrieve the desired data.
  3627. */
  3628. mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
  3629. (phy_addr << E1000_MDIC_PHY_SHIFT) |
  3630. (E1000_MDIC_OP_READ));
  3631. E1000_WRITE_REG(hw, MDIC, mdic);
  3632. /* Poll the ready bit to see if the MDI read completed */
  3633. for (i = 0; i < 64; i++) {
  3634. udelay(10);
  3635. mdic = E1000_READ_REG(hw, MDIC);
  3636. if (mdic & E1000_MDIC_READY)
  3637. break;
  3638. }
  3639. if (!(mdic & E1000_MDIC_READY)) {
  3640. DEBUGOUT("MDI Read did not complete\n");
  3641. return -E1000_ERR_PHY;
  3642. }
  3643. if (mdic & E1000_MDIC_ERROR) {
  3644. DEBUGOUT("MDI Error\n");
  3645. return -E1000_ERR_PHY;
  3646. }
  3647. *phy_data = (uint16_t) mdic;
  3648. } else {
  3649. /* We must first send a preamble through the MDIO pin to signal the
  3650. * beginning of an MII instruction. This is done by sending 32
  3651. * consecutive "1" bits.
  3652. */
  3653. e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
  3654. /* Now combine the next few fields that are required for a read
  3655. * operation. We use this method instead of calling the
  3656. * e1000_shift_out_mdi_bits routine five different times. The format of
  3657. * a MII read instruction consists of a shift out of 14 bits and is
  3658. * defined as follows:
  3659. * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
  3660. * followed by a shift in of 18 bits. This first two bits shifted in
  3661. * are TurnAround bits used to avoid contention on the MDIO pin when a
  3662. * READ operation is performed. These two bits are thrown away
  3663. * followed by a shift in of 16 bits which contains the desired data.
  3664. */
  3665. mdic = ((reg_addr) | (phy_addr << 5) |
  3666. (PHY_OP_READ << 10) | (PHY_SOF << 12));
  3667. e1000_shift_out_mdi_bits(hw, mdic, 14);
  3668. /* Now that we've shifted out the read command to the MII, we need to
  3669. * "shift in" the 16-bit value (18 total bits) of the requested PHY
  3670. * register address.
  3671. */
  3672. *phy_data = e1000_shift_in_mdi_bits(hw);
  3673. }
  3674. return 0;
  3675. }
  3676. /******************************************************************************
  3677. * Writes a value to a PHY register
  3678. *
  3679. * hw - Struct containing variables accessed by shared code
  3680. * reg_addr - address of the PHY register to write
  3681. * data - data to write to the PHY
  3682. ******************************************************************************/
  3683. static int
  3684. e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t phy_data)
  3685. {
  3686. uint32_t i;
  3687. uint32_t mdic = 0;
  3688. const uint32_t phy_addr = 1;
  3689. if (reg_addr > MAX_PHY_REG_ADDRESS) {
  3690. DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
  3691. return -E1000_ERR_PARAM;
  3692. }
  3693. if (hw->mac_type > e1000_82543) {
  3694. /* Set up Op-code, Phy Address, register address, and data intended
  3695. * for the PHY register in the MDI Control register. The MAC will take
  3696. * care of interfacing with the PHY to send the desired data.
  3697. */
  3698. mdic = (((uint32_t) phy_data) |
  3699. (reg_addr << E1000_MDIC_REG_SHIFT) |
  3700. (phy_addr << E1000_MDIC_PHY_SHIFT) |
  3701. (E1000_MDIC_OP_WRITE));
  3702. E1000_WRITE_REG(hw, MDIC, mdic);
  3703. /* Poll the ready bit to see if the MDI read completed */
  3704. for (i = 0; i < 64; i++) {
  3705. udelay(10);
  3706. mdic = E1000_READ_REG(hw, MDIC);
  3707. if (mdic & E1000_MDIC_READY)
  3708. break;
  3709. }
  3710. if (!(mdic & E1000_MDIC_READY)) {
  3711. DEBUGOUT("MDI Write did not complete\n");
  3712. return -E1000_ERR_PHY;
  3713. }
  3714. } else {
  3715. /* We'll need to use the SW defined pins to shift the write command
  3716. * out to the PHY. We first send a preamble to the PHY to signal the
  3717. * beginning of the MII instruction. This is done by sending 32
  3718. * consecutive "1" bits.
  3719. */
  3720. e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
  3721. /* Now combine the remaining required fields that will indicate a
  3722. * write operation. We use this method instead of calling the
  3723. * e1000_shift_out_mdi_bits routine for each field in the command. The
  3724. * format of a MII write instruction is as follows:
  3725. * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
  3726. */
  3727. mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
  3728. (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
  3729. mdic <<= 16;
  3730. mdic |= (uint32_t) phy_data;
  3731. e1000_shift_out_mdi_bits(hw, mdic, 32);
  3732. }
  3733. return 0;
  3734. }
  3735. /******************************************************************************
  3736. * Checks if PHY reset is blocked due to SOL/IDER session, for example.
  3737. * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
  3738. * the caller to figure out how to deal with it.
  3739. *
  3740. * hw - Struct containing variables accessed by shared code
  3741. *
  3742. * returns: - E1000_BLK_PHY_RESET
  3743. * E1000_SUCCESS
  3744. *
  3745. *****************************************************************************/
  3746. int32_t
  3747. e1000_check_phy_reset_block(struct e1000_hw *hw)
  3748. {
  3749. uint32_t manc = 0;
  3750. uint32_t fwsm = 0;
  3751. if (hw->mac_type == e1000_ich8lan) {
  3752. fwsm = E1000_READ_REG(hw, FWSM);
  3753. return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
  3754. : E1000_BLK_PHY_RESET;
  3755. }
  3756. if (hw->mac_type > e1000_82547_rev_2)
  3757. manc = E1000_READ_REG(hw, MANC);
  3758. return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
  3759. E1000_BLK_PHY_RESET : E1000_SUCCESS;
  3760. }
  3761. /***************************************************************************
  3762. * Checks if the PHY configuration is done
  3763. *
  3764. * hw: Struct containing variables accessed by shared code
  3765. *
  3766. * returns: - E1000_ERR_RESET if fail to reset MAC
  3767. * E1000_SUCCESS at any other case.
  3768. *
  3769. ***************************************************************************/
  3770. static int32_t
  3771. e1000_get_phy_cfg_done(struct e1000_hw *hw)
  3772. {
  3773. int32_t timeout = PHY_CFG_TIMEOUT;
  3774. uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
  3775. DEBUGFUNC();
  3776. switch (hw->mac_type) {
  3777. default:
  3778. mdelay(10);
  3779. break;
  3780. case e1000_80003es2lan:
  3781. /* Separate *_CFG_DONE_* bit for each port */
  3782. if (e1000_is_second_port(hw))
  3783. cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
  3784. /* Fall Through */
  3785. case e1000_82571:
  3786. case e1000_82572:
  3787. while (timeout) {
  3788. if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
  3789. break;
  3790. else
  3791. mdelay(1);
  3792. timeout--;
  3793. }
  3794. if (!timeout) {
  3795. DEBUGOUT("MNG configuration cycle has not "
  3796. "completed.\n");
  3797. return -E1000_ERR_RESET;
  3798. }
  3799. break;
  3800. }
  3801. return E1000_SUCCESS;
  3802. }
  3803. /******************************************************************************
  3804. * Returns the PHY to the power-on reset state
  3805. *
  3806. * hw - Struct containing variables accessed by shared code
  3807. ******************************************************************************/
  3808. int32_t
  3809. e1000_phy_hw_reset(struct e1000_hw *hw)
  3810. {
  3811. uint16_t swfw = E1000_SWFW_PHY0_SM;
  3812. uint32_t ctrl, ctrl_ext;
  3813. uint32_t led_ctrl;
  3814. int32_t ret_val;
  3815. DEBUGFUNC();
  3816. /* In the case of the phy reset being blocked, it's not an error, we
  3817. * simply return success without performing the reset. */
  3818. ret_val = e1000_check_phy_reset_block(hw);
  3819. if (ret_val)
  3820. return E1000_SUCCESS;
  3821. DEBUGOUT("Resetting Phy...\n");
  3822. if (hw->mac_type > e1000_82543) {
  3823. if (e1000_is_second_port(hw))
  3824. swfw = E1000_SWFW_PHY1_SM;
  3825. if (e1000_swfw_sync_acquire(hw, swfw)) {
  3826. DEBUGOUT("Unable to acquire swfw sync\n");
  3827. return -E1000_ERR_SWFW_SYNC;
  3828. }
  3829. /* Read the device control register and assert the E1000_CTRL_PHY_RST
  3830. * bit. Then, take it out of reset.
  3831. */
  3832. ctrl = E1000_READ_REG(hw, CTRL);
  3833. E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
  3834. E1000_WRITE_FLUSH(hw);
  3835. if (hw->mac_type < e1000_82571)
  3836. udelay(10);
  3837. else
  3838. udelay(100);
  3839. E1000_WRITE_REG(hw, CTRL, ctrl);
  3840. E1000_WRITE_FLUSH(hw);
  3841. if (hw->mac_type >= e1000_82571)
  3842. mdelay(10);
  3843. } else {
  3844. /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
  3845. * bit to put the PHY into reset. Then, take it out of reset.
  3846. */
  3847. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  3848. ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
  3849. ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
  3850. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  3851. E1000_WRITE_FLUSH(hw);
  3852. mdelay(10);
  3853. ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
  3854. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  3855. E1000_WRITE_FLUSH(hw);
  3856. }
  3857. udelay(150);
  3858. if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  3859. /* Configure activity LED after PHY reset */
  3860. led_ctrl = E1000_READ_REG(hw, LEDCTL);
  3861. led_ctrl &= IGP_ACTIVITY_LED_MASK;
  3862. led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
  3863. E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
  3864. }
  3865. /* Wait for FW to finish PHY configuration. */
  3866. ret_val = e1000_get_phy_cfg_done(hw);
  3867. if (ret_val != E1000_SUCCESS)
  3868. return ret_val;
  3869. return ret_val;
  3870. }
  3871. /******************************************************************************
  3872. * IGP phy init script - initializes the GbE PHY
  3873. *
  3874. * hw - Struct containing variables accessed by shared code
  3875. *****************************************************************************/
  3876. static void
  3877. e1000_phy_init_script(struct e1000_hw *hw)
  3878. {
  3879. uint32_t ret_val;
  3880. uint16_t phy_saved_data;
  3881. DEBUGFUNC();
  3882. if (hw->phy_init_script) {
  3883. mdelay(20);
  3884. /* Save off the current value of register 0x2F5B to be
  3885. * restored at the end of this routine. */
  3886. ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
  3887. /* Disabled the PHY transmitter */
  3888. e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
  3889. mdelay(20);
  3890. e1000_write_phy_reg(hw, 0x0000, 0x0140);
  3891. mdelay(5);
  3892. switch (hw->mac_type) {
  3893. case e1000_82541:
  3894. case e1000_82547:
  3895. e1000_write_phy_reg(hw, 0x1F95, 0x0001);
  3896. e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
  3897. e1000_write_phy_reg(hw, 0x1F79, 0x0018);
  3898. e1000_write_phy_reg(hw, 0x1F30, 0x1600);
  3899. e1000_write_phy_reg(hw, 0x1F31, 0x0014);
  3900. e1000_write_phy_reg(hw, 0x1F32, 0x161C);
  3901. e1000_write_phy_reg(hw, 0x1F94, 0x0003);
  3902. e1000_write_phy_reg(hw, 0x1F96, 0x003F);
  3903. e1000_write_phy_reg(hw, 0x2010, 0x0008);
  3904. break;
  3905. case e1000_82541_rev_2:
  3906. case e1000_82547_rev_2:
  3907. e1000_write_phy_reg(hw, 0x1F73, 0x0099);
  3908. break;
  3909. default:
  3910. break;
  3911. }
  3912. e1000_write_phy_reg(hw, 0x0000, 0x3300);
  3913. mdelay(20);
  3914. /* Now enable the transmitter */
  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 */