e1000.c 153 KB

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